Hi,
I am trying to replace an image in a PDF file using PDFBox and I am unable
to find any examples. The only example that I found on
http://stackoverflow.com/questions/17423665/replace-image-in-pdf-with-another-image-pdf-box
uses COSStream's replaceWithStream(COSStream stream) that has been
deprecated. Are there any alternatives to this method or is there another
process that I can use.
private static void changeImage(COSObject obj, PDDocument doc) {
PDXObjectImage imageInPdf =
(PDXObjectImage) PDXObject.createXObject(
(COSStream) obj.getObject());
File inputFile = new File("C:\\temp\\SIGNATURE.jpg");
PDXObjectImage newImage = new PDJpeg(
doc, new FileInputStream(inputFile));
imageInPdf.getCOSStream().replaceWithStream(newImage.getCOSStream());
Thanks,
Stephen