pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wolfgang Ditz <wolfgang.d...@uibk.ac.at>
Subject swapping images no longer working
Date Sun, 10 Mar 2013 19:27:44 GMT
Hello!

I've been using PDFbox 1.5.0 to compress (huge, scanned) images in pdf 
files to get them down to practical sizes.
After updating the library to PDFbox 1.7.1 my method of doing so stopped 
working.

Extracting the image still works flawlessly, but assigning the 
compressed image seems to have no effect.
The "modified" file is equivalent to a file that's just been parsed and 
saved again.
It seemed to me that the getImages() returns a readOnly view now.
So i tried using the COS* datastructures but only managed to trash my files.

compressPDF(final File input, final File output, final int quality) {
     PDFParser parser = new PDFParser(new FileInputStream(input));
     parser.parse();
     PDDocument doc = parser.getPDDocument();
     for (final PDPage p : doc.getDocumentCatalog().getAllPages()) {
         Map<String, PDXObjectImage> images = p.getResources().getImages();
         for (final String s : images.keySet()) {
             PDXObjectImage i = images.get(s);
             File ovImg = new File(tmpDir, s + "." + i.getSuffix());
             i.write2file(ovImg);
             File newImage = ImgUtil.compress(ovImg, quality);
             /*omitting code to handle different image formats, using 
jpg as example*/
             PDJpeg jpg = new PDJpeg(doc, new FileInputStream(newImg));
             images.put(s, jpg);
             }
         }
         doc.save(output.getPath());
         doc.close();
     }

Any hints how to get back on track ?

Thanks in advance!
  wolfgang

Mime
View raw message