使用itext5应用编辑后,Pdf内容无法正确呈现

时间:2016-08-24 14:51:22

标签: java itext

我正在使用以下代码。

public class RemoveContentInRectangle {
public static final String SRC = "resources/pdfs/pdffile.pdf";
public static final String DEST = "resources/pdfs/pdfnew.pdf";

public static void main(String[] args) throws IOException, DocumentException {
    File file = new File(SRC);
    file.getParentFile().mkdirs();
    new RemoveContentInRectangle().manipulatePdf(SRC, DEST);
}

public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
    PdfReader reader = new PdfReader(src);
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
    List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
    for(int i=1; i<= reader.getNumberOfPages(); i++){
        Rectangle rect = new Rectangle(144.98572f, 655.74976f, 257.91428f, 670.322f);
        cleanUpLocations.add(new PdfCleanUpLocation(i, rect, BaseColor.GRAY));          
    }
    try{            
        PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
        cleaner.cleanUp();
    } catch(Exception e){
        e.printStackTrace();
    }

    stamper.close();
    reader.close();
}    

}

我在输出pdf文件中丢失了文本。请看截图。

original pdf file screenshot.

output pdf file screenshot.

编辑区域为灰色矩形,整个文档中缺少字符。

我该如何解决这个问题?

0 个答案:

没有答案