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 692221807B for ; Mon, 21 Sep 2015 22:28:10 +0000 (UTC) Received: (qmail 34283 invoked by uid 500); 21 Sep 2015 22:28:10 -0000 Delivered-To: apmail-pdfbox-users-archive@pdfbox.apache.org Received: (qmail 34259 invoked by uid 500); 21 Sep 2015 22:28:10 -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 34248 invoked by uid 99); 21 Sep 2015 22:28:09 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Sep 2015 22:28:09 +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 6FB39180973 for ; Mon, 21 Sep 2015 22:28:09 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.001 X-Spam-Level: * X-Spam-Status: No, score=1.001 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id XQQJ7g4Buug1 for ; Mon, 21 Sep 2015 22:27:56 +0000 (UTC) Received: from www168.your-server.de (www168.your-server.de [213.133.104.168]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id 88A0023064 for ; Mon, 21 Sep 2015 22:27:56 +0000 (UTC) Received: from [88.198.220.130] (helo=sslproxy01.your-server.de) by www168.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.80.1) (envelope-from ) id 1Ze9Yq-000444-Hs for users@pdfbox.apache.org; Tue, 22 Sep 2015 00:27:48 +0200 Received: from [79.242.102.252] (helo=mbp001.fritz.box) by sslproxy01.your-server.de with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.80) (envelope-from ) id 1Ze9Yn-0007s8-70 for users@pdfbox.apache.org; Tue, 22 Sep 2015 00:27:45 +0200 Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) Subject: Re: How flatten without changing appearance From: Maruan Sahyoun In-Reply-To: Date: Tue, 22 Sep 2015 00:27:41 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: References: <1C86E21B-DE25-415C-B93B-65F07C4C5529@fileaffairs.de> <72CC1C81-4489-4CA1-867E-33DAF15CE655@fileaffairs.de> <55F7B7F6.5010106@t-online.de> <41AFDAF1-E4AF-4057-939A-BC01B67FAC19@fileaffairs.de> <55F7C12E.4080500@t-online.de> <55F7C35C.5030805@t-online.de> <7E7C95A8-615A-4C5F-9CB1-D261987C38F1@fileaffairs.de> To: users@pdfbox.apache.org X-Mailer: Apple Mail (2.2104) X-Authenticated-Sender: sahyoun@fileaffairs.de X-Virus-Scanned: Clear (ClamAV 0.98.7/20930/Mon Sep 21 18:36:37 2015) Hi Kevin, > Am 21.09.2015 um 20:37 schrieb Kevin Ternes : >=20 > Maruan, >=20 > I finally got back around to trying this new flatten method out. It = works fantastic as far as preserving the appearance of the fields. > However, if I flatten before a merge, I am still losing data entered = into fields. could you be a little more specific? Do you have a sample form? Is the = data visible before the form is flattened, in which application? BR Maruan >=20 >=20 > -----Original Message----- > From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de]=20 > Sent: Tuesday, September 15, 2015 4:15 AM > To: users@pdfbox.apache.org > Subject: Re: How flatten without changing appearance >=20 > Hi, >> Am 15.09.2015 um 09:06 schrieb Tilman Hausherr = : >>=20 >> Am 15.09.2015 um 09:02 schrieb Maruan Sahyoun: >>>> Am 15.09.2015 um 08:56 schrieb Tilman Hausherr = : >>>>=20 >>>> Am 15.09.2015 um 08:48 schrieb Maruan Sahyoun: >>>>> Hi Tilman, >>>>>=20 >>>>>> Am 15.09.2015 um 08:17 schrieb Tilman Hausherr = : >>>>>>=20 >>>>>> Am 15.09.2015 um 04:47 schrieb Maruan Sahyoun: >>>>>>> Hi Kevin, >>>>>>>=20 >>>>>>> I've created https://issues.apache.org/jira/browse/PDFBOX-2970 = for that. >>>>>>>=20 >>>>>>> In addition you can start playing with that code based on the = current PDFBox 2.0.0 snapshot. >>>>>>>=20 >>>>>>>=20 >>>>>>>=20 >>>>>>> PDDocument doc =3D PDDocument.load(new File(...)); >>>>>>> PDAcroForm acroForm =3D = doc.getDocumentCatalog().getAcroForm(); >>>>>>> // Iterate over all form fields and their = widgets and create a >>>>>>> // FormXObject at the page content level from that >>>>>>> for (PDField field : acroForm.getFieldTree()) >>>>>>> { >>>>>>> for (PDAnnotationWidget widget : = ((PDTerminalField)field).getWidgets()) >>>>>>> { >>>>>>> PDPage page =3D widget.getPage(); >>>>>>> PDPageContentStream contentStream =3D new=20 >>>>>>> PDPageContentStream(doc, page, true, true); >>>>>> I wasn't 100% sure what was meant with "flatten", but now I get = it! >>>>>>=20 >>>>>> I think the first one of the "new PDPageContentStream" should = have the fifth parameter and be true, in case the existing content = stream isn't included in q...Q. >>>>> thanks for stepping in. >>>>>=20 >>>>> Is that really needed as we are storing/restoring the current = state before the new content is added. Putting a store/restore around = the existing one - assuming there is only one - would store/restore to = the state before there was any content stream. In addition if there are = already multiple streams before the new one would we need to put a = store/restore around each of them? If there wasn't any that would = potentially change the behavior of the old processing? >>>> The constructor identifies if there is already content, and only = then, it inserts a saveGraphicsState() before the first existing stream = and a restoreGraphicsState() at the end of the new one, so it work both = with none, one, and many. >>>>=20 >>>> Only doing it for the first one is to avoid having too many nesting=20= >>>> q...Q >>> looking at how Adobe does it each of the new content streams is = wrapped in a q ...Q - that's why I did the same. >>=20 >> That isn't what I meant. I meant that only the first one should be >>=20 >> PDPageContentStream contentStream =3D new PDPageContentStream(doc, = page,=20 >> true, true, true); >>=20 >> instead of >>=20 >> PDPageContentStream contentStream =3D new PDPageContentStream(doc, = page,=20 >> true, true); >>=20 >> all the rest is fine as it is. >>=20 >=20 > done - thanks for the clarification. > Maruan >=20 >>=20 >> Tilman >>=20 >>=20 >>=20 >>>=20 >>>> What I was thinking of is cases where the existing content = stream(s) modifies the CTM without resetting it. This would have the = effect that the "fields" would appear at the wrong place / wrong size / = outside of the screen. We're having this every few months that somebody = wants to add a stamp to a page, it works for most, except for one = "special" file. >>>>=20 >>>> Tilman >>>>=20 >>>>=20 >>>>> BR >>>>> Maruan >>>>>=20 >>>>>=20 >>>>>=20 >>>>>> Tilman >>>>>>=20 >>>>>>> PDFormXObject fieldObject =3D new = PDFormXObject(widget.getAppearance().getNormalAppearance().getAppearanceSt= ream().getCOSStream()); >>>>>>> Matrix translationMatrix =3D = Matrix.getTranslateInstance(widget.getRectangle().getLowerLeftX(), = widget.getRectangle().getLowerLeftY()); >>>>>>> contentStream.saveGraphicsState(); >>>>>>> contentStream.transform(translationMatrix); >>>>>>> contentStream.drawForm(fieldObject); >>>>>>> contentStream.restoreGraphicsState(); >>>>>>> contentStream.close(); >>>>>>> } >>>>>>> } >>>>>>>=20 >>>>>>> // preserve all non widget annotations >>>>>>> for (PDPage page : doc.getPages()) >>>>>>> { >>>>>>> List annotations =3D new = ArrayList(); >>>>>>> for (PDAnnotation annotation: = page.getAnnotations()) >>>>>>> { >>>>>>> if (!(annotation instanceof PDAnnotationWidget)) >>>>>>> { >>>>>>> annotations.add(annotation); >>>>>>> } >>>>>>> } >>>>>>> page.setAnnotations(annotations); >>>>>>> } >>>>>>> // remove the fields >>>>>>> acroForm.setFields(Collections.emptyList()); >>>>>>> doc.save(...); >>>>>>> doc.close(); >>>>>>>=20 >>>>>>>=20 >>>>>>> BR >>>>>>> Maruan >>>>>>>=20 >>>>>>>=20 >>>>>>>=20 >>>>>>>> Am 14.09.2015 um 17:57 schrieb Maruan Sahyoun = : >>>>>>>>=20 >>>>>>>>=20 >>>>>>>>=20 >>>>>>>>> Am 14.09.2015 um 16:53 schrieb Kevin Ternes = : >>>>>>>>>=20 >>>>>>>>> I am trying to refactor for 2.0.0-SNAPSHOT now. >>>>>>>>>=20 >>>>>>>>> Can someone tell me how to flatten a PDDocument in PDFBox 2 ? >>>>>>>>> All the examples seem to pertain to v1.x >>>>>>>> there are non but I've started to get that into the project >>>>>>>>=20 >>>>>>>>> -----Original Message----- >>>>>>>>> From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de] >>>>>>>>> Sent: Saturday, September 12, 2015 1:55 AM >>>>>>>>> To: users@pdfbox.apache.org >>>>>>>>> Subject: Re: How flatten without changing appearance >>>>>>>>>=20 >>>>>>>>> Hi, >>>>>>>>>=20 >>>>>>>>>> Am 12.09.2015 um 00:08 schrieb Kevin Ternes = : >>>>>>>>>>=20 >>>>>>>>>> Maruan, >>>>>>>>>> That would be great. Please have a look at: >>>>>>>>>> = https://onedrive.live.com/redir?resid=3D9CCA324BE57ADA7!76929&au >>>>>>>>>> thkey=3D!A KE0x0fh5QDkIIw&ithint=3Dfile%2czip This should=20 >>>>>>>>>> demonstrate the problem by processing several files. >>>>>>>>> I took a quick look. Which version of PDFBox are you using? = Would it be possible to go to (the yet to be released) 2.0.0 version? >>>>>>>>>=20 >>>>>>>>> BR >>>>>>>>> Maruan >>>>>>>>>=20 >>>>>>>>>=20 >>>>>>>>>> The users complaint is: Boxes are being greyed out and font = sizes are being changed by the flatten. >>>>>>>>>> My flatten is done by the PDFBoxUtils.flatten() method. >>>>>>>>>>=20 >>>>>>>>>> Thanks, >>>>>>>>>> -Kevin >>>>>>>>>>=20 >>>>>>>>>> -----Original Message----- >>>>>>>>>> From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de] >>>>>>>>>> Sent: Friday, September 11, 2015 12:17 PM >>>>>>>>>> To: users@pdfbox.apache.org >>>>>>>>>> Subject: Re: How to merge forms where there is >>>>>>>>>>=20 >>>>>>>>>> how urgent is it for you? If you could share a sample file = and your code for flattening I could take a look. >>>>>>>>>>=20 >>>>>>>>>> BR >>>>>>>>>> Maruan >>>>>>>>>>=20 >>>>>>>>>>> Am 11.09.2015 um 18:23 schrieb Kevin Ternes = : >>>>>>>>>>>=20 >>>>>>>>>>> I have not been able to successfully flatten a document = without affecting the formatting of the field. >>>>>>>>>>> There are some example codes out there but none of them work = correctly for me. >>>>>>>>>>>=20 >>>>>>>>>>> -----Original Message----- >>>>>>>>>>> From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de] >>>>>>>>>>> Sent: Friday, September 11, 2015 3:15 AM >>>>>>>>>>> To: users@pdfbox.apache.org >>>>>>>>>>> Subject: Re: How to merge forms where there is >>>>>>>>>>>=20 >>>>>>>>>>> Hi Kevin >>>>>>>>>>> None of these field values will need to be changed afterward = the merge. They are set to read-only. >>>>>>>>>>>> I tried flattening the source fields but most of these = documents rely on field annotation for the field value formatting and = this is not to be changed. >>>>>>>>>>> when a field is flattened correctly the formatting of the = annotations visually representing the field become part of the page = content stream. So if you don't need the fields at all - as there is no = further input - you could flatten the source documents prior to merging = them. >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org > For additional commands, e-mail: users-help@pdfbox.apache.org >=20 --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org For additional commands, e-mail: users-help@pdfbox.apache.org