Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id ABD76200D56 for ; Tue, 12 Dec 2017 19:52:54 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id AA55C160C10; Tue, 12 Dec 2017 18:52:54 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id EFCCB160BE7 for ; Tue, 12 Dec 2017 19:52:53 +0100 (CET) Received: (qmail 55168 invoked by uid 500); 12 Dec 2017 18:52:52 -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 55135 invoked by uid 99); 12 Dec 2017 18:52:52 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Dec 2017 18:52:52 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 223971807A1 for ; Tue, 12 Dec 2017 18:52:52 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.479 X-Spam-Level: *** X-Spam-Status: No, score=3.479 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_BL_SPAMCOP_NET=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id yi84TrVoboim for ; Tue, 12 Dec 2017 18:52:50 +0000 (UTC) Received: from mailout12.t-online.de (mailout12.t-online.de [194.25.134.22]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id A0D595F263 for ; Tue, 12 Dec 2017 18:52:49 +0000 (UTC) Received: from fwd02.aul.t-online.de (fwd02.aul.t-online.de [172.20.26.148]) by mailout12.t-online.de (Postfix) with SMTP id 88A0C41C6C3B for ; Tue, 12 Dec 2017 19:52:42 +0100 (CET) Received: from [192.168.2.105] (XdsJd+ZSohyqb4EK1u34jNvmWEoRGAeiyQbLZzeUF5uybobzDUB6up75lffEaO4gNr@[217.231.129.120]) by fwd02.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1eOpfT-1MZufA0; Tue, 12 Dec 2017 19:52:39 +0100 Subject: Re: How to remove a specific image from PDF? To: users@pdfbox.apache.org References: From: Tilman Hausherr Message-ID: <26f24182-d64d-4432-24fe-d371aec4816a@t-online.de> Date: Tue, 12 Dec 2017 19:55:18 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-ID: XdsJd+ZSohyqb4EK1u34jNvmWEoRGAeiyQbLZzeUF5uybobzDUB6up75lffEaO4gNr X-TOI-MSGID: 5d316eb8-31db-4b45-878d-ef36cb0aa221 archived-at: Tue, 12 Dec 2017 18:52:54 -0000 Somewhat answered in comments in https://stackoverflow.com/questions/47757971/how-to-remove-a-specific-image-from-a-pdf-with-pdfbox Tilman Am 12.12.2017 um 13:29 schrieb Alexander Teut: > I need to remove a specific image from PDF file according its > metadata. Sadly. all examples I can find in Internet are using > discarded methods. > > I draw this image with contentStream.drawImage() method and mark it > with a metadata. I needto allow my soft to remove added images as > well/ > > > I'm using the following code: > > List itemsToRemove = new ArrayList<>(); > > COSDictionary imagesContainer = > (COSDictionary)resources.getCOSObject().getDictionaryObject(COSName.XOBJECT); > > try (PDDocument doc = PDDocument.load(new ByteArrayInputStream(pdf))) { > doc.getPages().forEach(page -> > { > PDResources resources = page.getResources(); > List itemsToRemove = new ArrayList<>(); > > resources.getXObjectNames().forEach(propertyName -> { > if(!resources.isImageXObject(propertyName)) { > return; > } > PDXObject pdxObject = resources.getXObject(propertyName); > PDImageXObject pdImageXObject = (PDImageXObject)pdxObject; > PDMetadata metadata = pdImageXObject.getMetadata(); > if(checkMetadata(metadata)){ > > itemsToRemove.add(propertyName); > > // What should I use here? > } > }); > > itemsToRemove.forEach(imagesContainer::removeItem); > }); > doc.save(baos); > } catch (Exception e) { > //Code here > > } > > It produces a cleared PDF that shows an error when I open it. Looks like I > should remove it from contentStream too. How to do that? > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org For additional commands, e-mail: users-help@pdfbox.apache.org