Results 1 to 2 of 2
  1. #1
    vammpiro is offline Member
    Join Date
    Jul 2010
    Rep Power

    Default pdfbox to overwrite image on a pdf


    I’ve been trying to make some changes on the size of pdfs.
    My first step on my strategy was to extract all images from the pdf and compact them.
    I made it successfully.

    Now, What I need to do is to replace the image ‘I’ with the compressedImage ‘CI’ using the same graphicstate (coordinates and scale basically), so visually the pdf would be the same(or almost), the difference: with lower quality images.
    the thing is that I could not replace the image on the pdfstream.
    what I've tried already:

    to createOutputStream() on the image and read the stream of the compacted one putting it on the image.

    to drawImage() with the contentStream, but it seemed that it printed both images. And besides, I didn’t manage a way to get the graphicstate of the “old” image.

    to set a new Image, which obviously would not work, but I had to try, just in case.

    Now What I’m trying to do:

    Pass the dictionary tree for a new PDDocument and when the COSBase is an image, replace with acompacted one. At the end save this new document.
    I know how I can iterate over each element of this tree, however I could not create a new dictionary and put each new element on it.

    So I was wondering if you guys can give me some light on my strategy or maybe to advice about another way of doing it.

    Thank you.

  2. #2
    kabal is offline Member
    Join Date
    Mar 2012
    Rep Power

    Default Re: pdfbox to overwrite image on a pdf

    Did you ever get anywhere with this?

    We are also looking to downsize the images in pdf documents, and would prefer not to have to licence another pdf library like itext for a closed source project.

Similar Threads

  1. PdfBox and barcode fonts
    By alexre2005 in forum New To Java
    Replies: 5
    Last Post: 12-03-2009, 03:59 PM
  2. import XFDF using PDFBOX
    By jkrishnanvenkat in forum Advanced Java
    Replies: 1
    Last Post: 10-28-2009, 01:13 PM
  3. Replies: 3
    Last Post: 02-16-2009, 10:20 PM
  4. file overwrite method
    By nanaji in forum Advanced Java
    Replies: 5
    Last Post: 11-14-2008, 10:19 AM
  5. Create and overwrite files
    By wmrwl in forum New To Java
    Replies: 7
    Last Post: 10-01-2008, 04:16 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts