Return-Path: X-Original-To: apmail-pdfbox-users-archive@www.apache.org Delivered-To: apmail-pdfbox-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C6FE4E510 for ; Sun, 10 Mar 2013 19:28:12 +0000 (UTC) Received: (qmail 73087 invoked by uid 500); 10 Mar 2013 19:28:12 -0000 Delivered-To: apmail-pdfbox-users-archive@pdfbox.apache.org Received: (qmail 73066 invoked by uid 500); 10 Mar 2013 19:28:12 -0000 Mailing-List: contact users-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@pdfbox.apache.org Delivered-To: mailing list users@pdfbox.apache.org Received: (qmail 73058 invoked by uid 99); 10 Mar 2013 19:28:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Mar 2013 19:28:12 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [138.232.1.140] (HELO smtp.uibk.ac.at) (138.232.1.140) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Mar 2013 19:28:04 +0000 Received: from [138.232.114.221] (c108-dig29.uibk.ac.at [138.232.114.221]) (authenticated bits=0) by smtp.uibk.ac.at (8.13.8/8.13.8/F1) with ESMTP id r2AJRi6x029074 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Sun, 10 Mar 2013 20:27:44 +0100 Message-ID: <513CDEB0.1060503@uibk.ac.at> Date: Sun, 10 Mar 2013 20:27:44 +0100 From: Wolfgang Ditz User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: users@pdfbox.apache.org Subject: swapping images no longer working Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: () -15.0 ALL_TRUSTED,RCV_SMTP_AUTH,RCV_SMTP_UIBK,T_RP_MATCHES_RCVD X-Scanned-By: MIMEDefang 2.61 at uibk.ac.at on 138.232.1.140 X-Virus-Checked: Checked by ClamAV on apache.org 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 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