0

我目前正在尝试使用 iTextSharp 库编辑 PDF 中的一些信息。我遇到的问题是“编辑”区域内的内容仍然是可选择和可读的,这是一个问题。

我使用了两种方法,第一种是我使用 iTextSharp 的注释功能手动添加编辑然后应用它。

`PdfStamper stamper = new PdfStamper(reader, new FileStream(fileName.Replace(oldFileName, replacementFileName), FileMode.Create, FileAccess.Write));
iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(500, 50, 200, 300); 
PdfAnnotation annotation = new PdfAnnotation(stamper.Writer, rect);
annotation.Title = "WORK PLEASE";
annotation.Put(PdfName.SUBTYPE, new PdfName("Redact"));
annotation.Put(PdfName.IC, new PdfArray(new[] { 0f, 0f, 0f }));
annotation.Put(PdfName.OPEN, PdfBoolean.PDFFALSE);
annotation.Put(PdfName.OC, new PdfArray(new[] { 1f, 0f, 0f }));
annotation.Put(PdfName.CONTENTS, new PdfString(string.Format("Icon: {0}", text)));
annotation.Put(PdfName.QUADPOINTS, new PdfArray (new [] {200,50,500,50,200,300,500,300}));
annotation.Put(PdfName.NAME, new PdfName(text));
stamper.AddAnnotation(annotation, 1);
//Applying the annotations here
DirectoryInfo outDir = new DirectoryInfo(destinationFolder);
if (!outDir.Exists) { 
    outDir.Create(); 
} 
PdfReader Reader = new PdfReader(destinationFolder + "\\WORK.pdf");
string output = destinationFolder + "\\hello.pdf";
Stream fos = new FileStream(output, FileMode.Create);
PdfStamper StamperWork = new PdfStamper(Reader, fos);
PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(StamperWork);
cleaner.CleanUp();
StamperWork.Close();
fos.Close();
Reader.Close();`

我使用的另一种方法是使用清理位置列表:

PdfStamper stamper = new PdfStamper(reader, new FileStream(file.Replace(oldchar, repChar), FileMode.Create, FileAccess.Write));
    List<PdfCleanUpLocation> cleanUpLocations = new List<PdfCleanUpLocation>();
    cleanUpLocations.Add(new PdfCleanUpLocation(1, new iTextSharp.text.Rectangle(0f, 0f, 600f, 115f), iTextSharp.text.BaseColor.WHITE));
    PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
    cleaner.CleanUp();
    stamper.Close();
    reader.Close();

但是,这仍然会导致 PDF 中的可选文本。它基本上看起来像我想要的区域上有白色矩形。奇怪的是,如果我只是使用第一种方法在 PDF 上进行注释,打开它,然后在 Adob​​e Acrobat 上手动应用编辑,它就可以工作。

此外,当我尝试清理已经标记了编辑区域的 pdf 文件时,“编辑”区域内仍然存在可选择/可解析的文本。这可能是与图书馆有关的问题。

有人对这个问题有任何见解吗?

4

0 回答 0