c# - iText7 (PdfSweep):System.ArgumentException:CharacterRenderInfo 对象表示单个字符
问题描述
尝试使用 PDFSweep 2.0 (C#) 编辑 PDF 中的一些文本。以下代码适用于我拥有的大多数 PDF 文件,但在某些 PDF 文件上,下面的代码会引发 ArgumentException
String input = "G:/tmp/redact/input.pdf";
String output = "G:/tmp/redact/output.pdf";
CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
strategy.Add(new RegexBasedCleanupStrategy(@"Hello"));
PdfDocument pdf = new PdfDocument(new PdfReader(input), new PdfWriter(output));
PdfAutoSweep autoSweep = new PdfAutoSweep(strategy);
autoSweep.CleanUp(pdf);
pdf.Close();
完整的异常堆栈如下所示:
Unhandled Exception: System.ArgumentException: CharacterRenderInfo objects represent a single character. They should not be made from TextRenderInfo objects containing more than a single character of text.
at iText.Kernel.Pdf.Canvas.Parser.Listener.CharacterRenderInfo..ctor(TextRenderInfo tri)
at iText.Kernel.Pdf.Canvas.Parser.Listener.RegexBasedLocationExtractionStrategy.ToCRI(TextRenderInfo tri)
at iText.Kernel.Pdf.Canvas.Parser.Listener.RegexBasedLocationExtractionStrategy.EventOccurred(IEventData data, EventType type)
at iText.PdfCleanup.Autosweep.CompositeCleanupStrategy.EventOccurred(IEventData data, EventType type)
at iText.Kernel.Pdf.Canvas.Parser.PdfCanvasProcessor.EventOccurred(IEventData data, EventType type)
at iText.Kernel.Pdf.Canvas.Parser.PdfCanvasProcessor.DisplayPdfString(PdfString string)
at iText.Kernel.Pdf.Canvas.Parser.PdfCanvasProcessor.ShowTextOperator.Invoke(PdfCanvasProcessor processor, PdfLiteral operator, IList`1 operands)
at iText.Kernel.Pdf.Canvas.Parser.PdfCanvasProcessor.InvokeOperator(PdfLiteral operator, IList`1 operands)
at iText.Kernel.Pdf.Canvas.Parser.PdfCanvasProcessor.ProcessContent(Byte[] contentBytes, PdfResources resources)
at iText.Kernel.Pdf.Canvas.Parser.PdfCanvasProcessor.ProcessPageContent(PdfPage page)
at iText.Kernel.Pdf.Canvas.Parser.PdfDocumentContentParser.ProcessContent[E](Int32 pageNumber, E renderListener, IDictionary`2 additionalContentOperators)
at iText.Kernel.Pdf.Canvas.Parser.PdfDocumentContentParser.ProcessContent[E](Int32 pageNumber, E renderListener)
at iText.PdfCleanup.Autosweep.PdfAutoSweep.GetPdfCleanUpLocations(PdfDocument doc)
at iText.PdfCleanup.Autosweep.PdfAutoSweep.CleanUp(PdfDocument pdfDocument)
at gp_redactor.Program.Main(String[] args) in G:\prj\gp_redactor\gp_redactor\Program.cs:line 70
我倾向于认为这是 iText 中的一个错误,任何人都可以提出解决方法吗?
解决方案
推荐阅读
- c# - 在 asp.net 中插入 asp 按钮使用 C# 代码隐藏页面中的 HTML
- numpy - 是否可以沿轴为 ndarray 执行 linalg.multi_dot ?
- php - PHP 类属性:传递 id 还是完整对象?
- django - 让 Django 序列化程序返回两个平面列表
- python - 如何访问/操作 keras 模型中的张量元素?
- java - 如何使用继承的实体对 REST API 建模?
- tomcat - Babel 资产管道的 Grails 部署问题
- python - 如何在石墨烯 mongo python 中更新 EmbeddedDocument 的字段
- ebpf - 异常:执行 sudo opensnoop-bpfcc 时无法将 BPF 附加到 kprobe
- apache-spark - 为什么 Databricks Connect 测试无法在 Mac 上运行?