1
當使用此代碼(Removing Watermark from PDF iTextSharp)簡單地讀取和重新寫入相同PDF的內容流時,我爲此file獲得了額外的操作添加到內容流。爲什麼數據添加到PDF內容流?
內容碼流
q
q
/I0 Do
Q
Q
q
10 0 0 10 0 0 cm
0.1 0 0 0.1 0 0 cm
/QuickPDFXO6d1c5c37 Do
Q
內容碼流
q
0 -1 1 0 0 1224 cm
q
q
/I0 Do
Q
Q
q
10 0 0 10 0 0 cm
0.1 0 0 0.1 0 0 cm
/QuickPDFXO6d1c5c37 Do
Q
Q
知道爲什麼這被追加到我的內容流之後之前?
q
0 -1 1 0 0 1224 cm
....
Q
我的代碼與鏈接文章類似,只是我試圖從內容流中刪除某些項目。
XObjectRemover editor = new XObjectRemover();
List<List<PdfContentData>> output = editor.EditPageContent(stamper, pgNumber);
PdfContentByte content = stamper.GetUnderContent(pgNumber);
foreach (List<PdfContentData> bracketList in output)
{
foreach (PdfContentData operandList in bracketList)
{
if (operandList.operandToDelete == false)
{
int index = 0;
foreach (PdfObject op in operandList.pdfOperands)
{
op.ToPdf(content.PdfWriter, content.InternalBuffer);
content.InternalBuffer.Append(operandList.pdfOperands.Count > ++index ? (byte)' ' : (byte)'\n');
}
}
}
}
PdfContentData類只是所有內容操作的集合,其中一些標記爲刪除。
public class PdfContentData
{
public int opNumber { get; set; }
public PdfLiteral pdfOperator { get; set; }
public List<PdfObject> pdfOperands { get; set; }
public bool operandToDelete { get; set; }
public PdfContentData(int opNum, PdfLiteral op, List<PdfObject> ops)
{
this.opNumber = opNum;
this.pdfOperator = op;
this.pdfOperands = ops;
}
public override string ToString()
{
return $"Ops: [{string.Join(",", pdfOperands.Select(p => p.ToString()).ToArray())}] Del: [{operandToDelete}]";
}
}
和XObjectRemover僅僅是從PdfContentStreamEditor衍生,就像TransparentGraphicsRemover在@ MKL的例子類。
完美地工作。謝謝@mkl! – Darren