我正在使用以下代码。
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文件中丢失了文本。请看截图。
编辑区域为灰色矩形,整个文档中缺少字符。
我该如何解决这个问题?