使用itext 5对扫描的pdf进行编辑

时间:2017-08-15 12:45:57

标签: itext

我试图使用Itext 5从扫描的PDF中编辑数据,但不知怎的,它对我来说不起作用。我只能创建编辑但不能应用它。我尝试了他们给出的例子,但它只适用于创建编辑

String fileName = "scanned.pdf";
String  dest = "output_scannedPdf.pdf";


PdfReader reader = new PdfReader(SRC + fileName);
int page = 1;
Rectangle rect = new Rectangle(500, 50, 200, 300);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(DEST + dest));
PdfAnnotation annotation = new PdfAnnotation(stamper.getWriter(), rect);

annotation.put(PdfName.SUBTYPE, new PdfName("Redact"));
annotation.setTitle("My author");
annotation.put(new PdfName("Subj"), new PdfName("Redact"));
float[] fillColor = { 0, 0, 0 };
annotation.put(new PdfName("IC"), new PdfArray(fillColor));
float[] fillColorRed = { 1, 0, 0 };
annotation.put(new PdfName("OC"), new PdfArray(fillColorRed));
stamper.addAnnotation(annotation, page);

// manipulatePdf(dest, dest1);

PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(stamper);
cleaner.cleanUp();
stamper.close();
reader.close();

我在extractLocationsFromRedactAnnots()方法PdfName annotSubtype = annotDict.getAsName(PdfName.SUBTYPE);

中收到空指针异常

0 个答案:

没有答案