1
我使用下面的代碼來填充在PDF領域如下:灌裝與iTextSharp的PDF文件,然後隱藏在基層
string fileNameExisting = @"C:\Old.pdf";
string fileNameNew = @"C:\New.pdf";
using (FileStream existingFileStream = new FileStream(fileNameExisting, FileMode.Open))
{
using (FileStream newFileStream = new FileStream(fileNameNew, FileMode.Create))
{
Font font = FontFactory.GetFont(FontFactory.COURIER, 6f, Font.BOLD);
PdfReader pdfReader = new PdfReader(existingFileStream);
PdfStamper stamper = new PdfStamper(pdfReader, newFileStream);
AcroFields form = stamper.AcroFields;
ICollection fieldKeys = form.Fields.Keys;
foreach (string fieldKey in fieldKeys)
{
stamper.AcroFields.SetFieldProperty(fieldKey, "textsize", 6f, null);
stamper.AcroFields.AddSubstitutionFont(font.BaseFont);
form.SetField(fieldKey, fieldKey); //Just for testing
}
stamper.Close();
}
}
它工作得很好,很好,但我的最終目標是有一個傳遞給此方法的布爾將決定是否呈現文檔的基礎層。 (即)如果用戶只需要渲染字段內容並隱藏「Old.pdf」的實際內容。
我查看了文檔,但它從來沒有涉及特別是這樣做,它甚至有可能嗎?
感謝您的回答!我使用的行'PdfDictionary pageDictionary = pdfReader.GetPageN(page); Dictonary.Remove(PdfName.CONTENTS);' 它完美的工作! – Bitz
雖然,我注意到沒有尺寸變化 - 無論如何! – Bitz
不,沒有尺寸變化。爲什麼要有一個?我們刪除了內容,而不是尺寸。 – mkl