0

We have a program that modifies a pdf for mailing. We noticed an issue with docusign envelope fields and signatures. They do not stay on the pdf when we modify. I tried everything i can think of in pdfbox.

The only workaround i found is foxit flatten signature when printing and adobe save as pdf do create a flattened pdf that works. I cannot render the whole pdf to an image because i need the pdf text fields to be evaluated programatically.

Anyway to create the same flatten that foxit and adobe to with pdfbox. I am so stumped:(

Not sure if this helps but I am able to access the item in the document this way.

          PDDocument doc = PDDocument.load( myFile );

      PDPageTree allPages = doc.getDocumentCatalog().getPages();

      PDPage page1 = allPages.get(1);
      COSDictionary pageDict = page1.getCOSObject();
      COSDictionary newPageDict = new COSDictionary(pageDict);
      COSDictionary test = newPageDict.getCOSDictionary(COSName.RESOURCES);
      test = test.getCOSDictionary(COSName.XOBJECT);
      test = test.getCOSDictionary(COSName.F);
      test = test.getCOSDictionary(COSName.RESOURCES);
      test = test.getCOSDictionary(COSName.XOBJECT);

The item exists in a COSName{X0}, but it does not appear pdfbox can access this so I cannot flatten it. I'd like to itterate through entire document for any non identifiable COSNames and render it to an image because that does work then use that image? Anyway to do this?

VinnieS
  • 85
  • 2
  • 12
  • So essentially you are asking how to flatten the signature fields (and only them) of a pdf using pdfbox? – mkl May 18 '20 at 04:53
  • Not really, trying to figure out how to flatten everything in the pdf. Foxit and adobe flatten and preserve everything. Acroform/non acroform, fields, objects, etc. that is what i am looking to accomplish. The fields in reference are not included when i iterate through all form fields. I was only able to access them via dictionary. They were tagged cosname{x0}. Basically i want to “flatten” that field so it does not get discarded – VinnieS May 18 '20 at 05:01
  • But you had some working code here? https://stackoverflow.com/questions/61112832/pdfbox-2-0-java-flatten-annotations-freetext-created-by-foxit – Tilman Hausherr May 18 '20 at 11:18
  • Working code is for annotations and form fields. This is neither. This is a digital signature that does not make it to the final print document. I want code that preserves all aspects of the document. I know it is possible bc foxit and adobe print to pdf feature do handle this properly. – VinnieS May 18 '20 at 14:14
  • I just confirmed what foxit and adobe do is it actually renders those parts in an image then replaces the objec twith an image. SO basically I think I need code that itterates all parts and if it is not a valid cosname pdfbox has, I want to render that part to an image. Is this possible? – VinnieS May 18 '20 at 14:40
  • A work around was i used Ghostscript to convert to another pdf and that then worked. – VinnieS May 19 '20 at 00:52
  • A visible signature has a visible widget annotation. So a flattening should preserve it, although the actual signature would no longer work so it would be worthless. No it is not easily possible to render an annotation to an image. – Tilman Hausherr May 19 '20 at 08:25
  • I still have not pinpointed why, but when i flatten the layers via Ghostscript all works and the items are text based and work perfect. Anyway to recreate this in pdfbox gs -sDEVICE=pdfwrite -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -sOutputFile= – VinnieS May 20 '20 at 03:32

0 Answers0