使用iText7 PDFSweep,C#实现。
在编辑过程中,iText似乎抛出" System.InvalidOperationException:Nullable对象必须具有值"异常取决于用于编校的正则表达式。
例如,下面的代码抛出异常:
String regex = @"(\s?7-\d\d\d\d)";
CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
strategy.Add(new RegexBasedCleanupStrategy(regex).SetRedactionColor(ColorConstants.RED));
PdfDocument pdf = new PdfDocument(new PdfReader(srcFile), new PdfWriter(outFile));
PdfAutoSweep autoSweep = new PdfAutoSweep(strategy);
autoSweep.CleanUp(pdf);
pdf.Close();
但是,如果我删除了" \ s,那么一切正常吗?"来自正则表达式。
这使我在2个方面感到困惑
编辑(添加堆栈跟踪):
Error Msg = Nullable object must have a value.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at iText.Kernel.Pdf.Canvas.Parser.Listener.RegexBasedLocationExtractionStrategy.GetResultantLocations()
at iText.PdfCleanup.Autosweep.CompositeCleanupStrategy.GetResultantLocations()
at iText.PdfCleanup.Autosweep.PdfAutoSweep.GetPdfCleanUpLocations(PdfDocument doc)
at iText.PdfCleanup.Autosweep.PdfAutoSweep.CleanUp(PdfDocument pdfDocument)
at pdf_redactor.Program.Main(String[] args) in G:\prj\pdf_redactor\pdf_redactor\Program.cs:line 77