pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Haggai <stephenhag...@gmail.com>
Subject Replacing an image in a PDF file using PDFBox
Date Fri, 08 May 2015 00:06:50 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message