使用 PdfCleanUpTool 或 PdfAutoSweep 会导致一些文本变为粗体、线宽增加和双点变为心形

Using PdfCleanUpTool or PdfAutoSweep causes some text to change to bold, line weights increase and double points change to hearts

我在尝试使用 iText 7 时遇到了奇怪的问题。PDF 的某些部分已修改(文本更改为粗体,线宽增加,双点更改为心形)。在 iText 版本 5.4.4 中,这没有发生,但自那以后我尝试过的每个版本都会导致同样的问题(5 或 7)。

有人知道为什么会这样吗?我能做些什么来绕过这个问题吗?如有任何帮助,我们将不胜感激!

如果需要更多信息,我会尽量提供。

下面是我用来测试 iText 7 的简单代码。 Example PDF Files

package javaapplication1;

import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.pdfcleanup.PdfCleanUpLocation;
import com.itextpdf.pdfcleanup.PdfCleanUpTool;
import com.itextpdf.pdfcleanup.autosweep.ICleanupStrategy;
import com.itextpdf.pdfcleanup.autosweep.PdfAutoSweep;
import com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;


public class JavaApplication1 {
    
    public static final String DEST = "D:/TEMP/TEMP/PDF/result/orientation_result.pdf";
    public static final String DEST2 = "D:/TEMP/TEMP/PDF/result/orientation_result2.pdf";
    public static final String DEST3 = "D:/TEMP/TEMP/PDF/result/orientation_result3.pdf";
    public static final String SRC = "D:/TEMP/TEMP/PDF/TEST_PDF.pdf";

    public static void main(String[] args) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();

        new JavaApplication1().manipulatePdf(DEST);
        new JavaApplication1().manipulatePdf2(DEST2);
        
        
        try (PdfDocument pdf = new PdfDocument(new PdfReader(SRC), new PdfWriter(DEST3))) {
            final ICleanupStrategy cleanupStrategy = new RegexBasedCleanupStrategy(Pattern.compile("2019", Pattern.CASE_INSENSITIVE)).setRedactionColor(ColorConstants.PINK);
            final PdfAutoSweep autoSweep = new PdfAutoSweep(cleanupStrategy);
            autoSweep.cleanUp(pdf);
        } catch (Exception e) {
            System.out.println(e.toString());
        }
     
    }

    protected void manipulatePdf(String dest) throws IOException {
        PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));

        List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();

        // The arguments of the PdfCleanUpLocation constructor: the number of page to be cleaned up,
        // a Rectangle defining the area on the page we want to clean up,
        // a color which will be used while filling the cleaned area.
        PdfCleanUpLocation location = new PdfCleanUpLocation(1, new Rectangle(97, 405, 383, 40),
                ColorConstants.GRAY);
        cleanUpLocations.add(location);

        PdfCleanUpTool cleaner = new PdfCleanUpTool(pdfDoc, cleanUpLocations);
        cleaner.cleanUp();

        pdfDoc.close();
    }
    
    protected void manipulatePdf2(String dest) throws IOException {
        PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));

        // If the second argument is true, then regions to be erased are extracted from the redact annotations
        // contained inside the given document. If the second argument is false (that's default behavior),
        // then use PdfCleanUpTool.addCleanupLocation(PdfCleanUpLocation)
        // method to set regions to be erased from the document.
        PdfCleanUpTool cleaner = new PdfCleanUpTool(pdfDoc, true);
        cleaner.cleanUp();

        pdfDoc.close();
    }
    
}

抱歉回复晚了。我现在设法验证更新到最新版本是否解决了这个问题。感谢@mkl 指出这一点。

问题已解决