> On 17 May 2016, at 08:04, Timo Rumland <[email protected]> wrote:
> 
> Hello,
> 
> after migrating from PDFBox 1.8 to 2.0.0, printing a PDF form via
> 'PrinterJob' and ' PDFPrintable ', in which I filled out the form fields via
> PDFBox, results in a PDF file (or a physical print) with the form fields
> empty.
> 
> With PDFBox 1.8, the following simple code worked:
> 
> 
> ----------
> 
> File sourcePdfForm = new File( "g:/test-form.pdf" );
> File resultPdfForm = new File( "g:/test-form_out.pdf" );
> 
> // Load the source PDF form file
> PDDocument pdDocument = PDDocument.load( sourcePdfForm );
> PDDocumentCatalog pdDocumentCatalog = pdDocument.getDocumentCatalog();
> PDAcroForm pdAcroForm = pdDocumentCatalog.getAcroForm();
> 
> // Setting PDF field content in "textfield01"
> PDField pdField = pdAcroForm.getField( "textfield01" );
> pdField.setValue( "test content" );
> 
> pdDocument.save( resultPdfForm );
> pdDocument.close();
> 
> // Open the resulting PDF file, which shows the content in the PDF field
> "textfield01"
> Desktop.getDesktop().open( resultPdfForm );
> 
> 
> // Now open the resulting file again, printing it with the default printer
> // No matter if the default printer is an PDF printer (like PDFCreator) or
> // an actual physical printer, the content of the field "textfield01" is
> empty
> 
> pdDocument = PDDocument.load( resultPdfForm );
> 
> PrinterJob printerJob = PrinterJob.getPrinterJob();
> printerJob.setJobName( "printerJob" );
> printerJob.setPrintService( PrintServiceLookup.lookupDefaultPrintService()
> );   
> printerJob.setPrintable( new PDFPrintable( pdDocument ) );
> printerJob.print( new HashPrintRequestAttributeSet( MediaSizeName.ISO_A4 )
> );
> 
> pdDocument.close();
> 
> ----------
> 
> -- What this code sample does --
> 
> As you can see, this is a test case where I first load a source PDF form,
> setting the value of a form field and save the resulting PDF file. After
> that I load the resulting PDF file and use a PrinterJob to print it on the
> default printer.
> 
> 
> -- The problem --
> 
> Now using PDFBox 2.0.0: No matter what the default printer is - a PDF
> printer like PDFCreator or a physical printer - the form fields of the
> printed out PDF file are empty
> 
> Interestingly, opening the resulting PDF form 'test-form_out.pdf' (see line
> 'Desktop.getDesktop().open( resultPdfForm );') in any PDF viewer (Adobe
> Acrobat Reader DC, PDF XChange Viewer etc.) shows the correct form field
> content for field 'textfield01', which is 'test content'.
> 
> The test PDF form file I use is a really simple form, containing only a
> label and the form field named "testfield01". If you wish, you can download
> 'test-form.pdf' here:
> 
> * https://goo.gl/VMiohj
> 
> As mentioned, with PDFBox 1.8 I was able to print out PDF forms via a
> 'PrinterJob' with form field contents.
> 
> 
> -- Related posts --
> 
> There are several posts or bug reports regard empty form fields, like these:
> 
> *
> http://stackoverflow.com/questions/14541647/pdfbox-set-visible-when-printing
> (not providing a valid solution in my case)
> *
> http://stackoverflow.com/questions/24149361/form-field-values-set-with-pdfbo
> x-not-visible-in-adobe-reader (my PDF form is a AcroForm and has no XFA
> data)
> * https://issues.apache.org/jira/browse/PDFBOX-71 (setting
> 'pdAcroForm.getCOSObject().setItem( COSName.getPDFName( "NeedAppearances" ),
> COSBoolean.TRUE );' did not help in my case)
> 
> Unfortunately, none of these did help.
> 
> 
> 
> Any advice on this problem is highly appreciated

Definitely a bug. I don’t know of any obvious reason why printing would 
encounter this
problem, it should be using the same code as rendering. Does rendering to an 
image
file work as expected?

If so, you could print with dpi > 0 as a workaround, which will cause PDFBox to 
print as
a raster image.

If not, then it’s a general forms rendering issue, rather than something 
specific to printing.

— John

> 
> Thanks a lot for your help!
> 
> 
> Best regards,
> Timo
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to