我正在使用Itext将图像添加到PDF文件中。我添加了图像,但我不希望它处于绝对位置,因为我有很多不同的报告。我想在pdf中添加一个图像并进行更改,但它对我不起作用。
现在这是我的代码,绝对位置:
ByteSource pdfVersion = remoteAccess.loadMultimedia(signature.getIdMultimedia());
// Imagen
Files.createDirectories(Paths.get("src/main/resources/signFolder"));
File img = new File("src/main/resources/signFolder/" + fileName);
img.deleteOnExit();
com.google.common.io.Files.write(file.read(), img);
// Pdf
File pdf = new File("src/main/resources/signFolder/" + signature.getIdMultimedia());
com.google.common.io.Files.write(pdfVersion.read(), pdf);
PdfReader reader = new PdfReader(pdf.getPath());
PdfStamper stamper = new PdfStamper(reader,
new FileOutputStream("src/main/resources/signFolder/with_image.pdf"));
Image image = Image.getInstance(img.getPath());
PdfImage stream = new PdfImage(image, "", null);
stream.put(new PdfName("ITXT_SpecialId"), new PdfName("123456789"));
PdfIndirectObject ref = stamper.getWriter().addToBody(stream);
image.setDirectReference(ref.getIndirectReference());
image.setAbsolutePosition(36, 270);
image.scalePercent(50);
PdfContentByte over = stamper.getOverContent(1);
over.addImage(image);
stamper.close();
reader.close();
我想在PDF文件中搜索一个矩形。你知不知道怎么?提前致谢。