You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Neus Arbó <ne...@gmail.com> on 2016/11/21 09:40:08 UTC
Fwd: Printing PDF with Acroform don't work
---------- Forwarded message ----------
From: Neus Arbó <ne...@gmail.com>
Date: 2016-11-21 10:27 GMT+01:00
Subject: Printing PDF with Acroform don't work
To: users-help@pdfbox.apache.org
Hi,
I need help with an issue.
I'm filling an Acroform using Java and then I need to print it.
Using pdfbox 1.8.12 it all works as expected (when printing the pdf with
the Acroform, all the information filled using Java was printed too).
I upgrade to pdfbox 2.0.3 because I had problems with some fonts and it was
solved in the new version. But now, when I print the acroform it only
prints the static text, not the fields filled in java!
Next is the code I'm using:
PDDocument pdfDocument;
try {
pdfDocument = PDDocument.load(PrintUtils.class.getClassLoader().
getResourceAsStream("\\application\\vistes\\clients\\contractes\\informes\\
CONTRACTE.pdf"));
PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
PDAcroForm acroForm = docCatalog.getAcroForm();
AcroForm.omplirCamp(acroForm, "num_contracte", contracte.getId());
AcroForm.omplirCamp(acroForm, "identificacio_caldera",
(contracte.getMarca() + " " + contracte.getAparell() + " " +
contracte.getNumero_fabricacio()).trim());
AcroForm.omplirCamp(acroForm, "data_instalacio",
dataFormatter.format(contracte.getDataInstalacio()));
AcroForm.omplirCamp(acroForm, "nom_usuari",
contracte.getNom_usuari());
AcroForm.omplirCamp(acroForm, "nom_usuari2",
contracte.getNom_usuari());
AcroForm.omplirCamp(acroForm, "nif", contracte.getNif());
AcroForm.omplirCamp(acroForm, "carrer", contracte.getDireccio());
AcroForm.omplirCamp(acroForm, "num_casa", contracte.getNumeroCasa());
AcroForm.omplirCamp(acroForm, "telefon", contracte.getTelefon());
AcroForm.omplirCamp(acroForm, "municipi", contracte.getPoblacio());
AcroForm.omplirCamp(acroForm, "euros", decimalFormatter.format(
contracte.getCost_anual()));
//Create AttributeSet
PrintRequestAttributeSet pset = new
HashPrintRequestAttributeSet();
//Add Duplex Option to AttributeSet
pset.add(Sides.DUPLEX);
PrinterJob job = PrinterJob.getPrinterJob();
job.setJobName("Contracte " + (contracte.getId() != null ?
contracte.getId() : "nou"));
PageFormat format = job.getPageFormat(pset);
format.setOrientation(PageFormat.PORTRAIT);
Paper paper = new Paper();
paper.setSize(20, 14.5);
format.setPaper(paper);
job.defaultPage(format);
job.setPageable(new PDFPageable(pdfDocument));
if (job.printDialog(pset)) {
job.print(pset);
}
pdfDocument.close();
} catch (IOException e) {
e.printStackTrace();
} catch (PrinterException e) {
e.printStackTrace();
}
public static void omplirCamp(PDAcroForm acroForm, String nomCamp, String
valor) throws IOException{
PDField field = acroForm.getField(nomCamp);
if( field != null ) {
field.setValue(valor != null ? valor : "");
}
else {
System.err.println( "No s'ha trobat el camp "+nomCamp+"!");
}
}
I tried also to save the file and print it using FIle. It is saved ok, with
all fields filled. But when I print it, it is not printing the fields
neither.
The PDF I'm using is attached in this mail.
Am I doing something wrong or it is a bug???
Thank you!
Neus
Re: Printing PDF with Acroform don't work
Posted by Neus Arbó <ne...@gmail.com>.
That worked. Thank you very much!
2016-11-23 9:41 GMT+01:00 Maruan Sahyoun <sa...@fileaffairs.de>:
> Hi,
>
>
>
> > Am 23.11.2016 um 09:28 schrieb Neus Arbó <ne...@gmail.com>:
> >
> > I tried to save the document, and then read it again with pdfbox and
> print
> > it. The document is saved with all the fields filled, but when I read it
> > and print it, the fields are printed empty
> >
>
> that's because the NeedAppearances flag for the form is set to true which
> PDFBox 2.0.x treats as not to generate an appearance stream for the form
> fields as this is interpreted as an indication that the appearance will be
> generated by a viewing application. See https://issues.apache.org/
> jira/browse/PDFBOX-3356.
>
> As this was not intuitive for most users we've changed that so that from
> 2.1.x on - which has yet to be released - PDFBox will always generate an
> appearance stream regardless of that setting. This is also to reflect a
> change in the upcoming PDF 2.0 specification which is deprecating that flag
> and requires filling applications to generate the appearance stream.
>
> The workaround for 2.0.x is to set the NeedApparances flag to false prior
> to filling the form using PDAcroForm.setNeedAppearances(Boolean value).
>
> BR
> Maruan
>
>
>
> > 2016-11-23 9:24 GMT+01:00 Neus Arbó <ne...@gmail.com>:
> >
> >> Yes, because I fill them from Java. And I'm sending the document to
> >> printer using Java. You can see the code I'm using to fill the fields
> and
> >> to print the document in the first email I send...
> >> Is practically the same code I was using with pdfbox 1.8.12 (Except some
> >> lines like the way I print it using PDFPageable, that it's the way I
> have
> >> to print it according the Migration guide). And in pdfbox 1.8.12 the
> fields
> >> where printing correctly, and in pdfbox 2.0.3 the fields are not
> printing
> >> anymore.
> >>
> >> 2016-11-22 19:10 GMT+01:00 Tilman Hausherr <TH...@t-online.de>:
> >>
> >>> Am 22.11.2016 um 09:47 schrieb Neus Arbó:
> >>>
> >>>> This is the pdf document
> >>>> https://drive.google.com/file/d/0B1_3_sVPnBolbjc3U21LTUFTeDg
> >>>> /view?usp=sharing
> >>>>
> >>>
> >>> The fields do not have any content.
> >>>
> >>>
> >>> Tilman
> >>>
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> >>> For additional commands, e-mail: users-help@pdfbox.apache.org
> >>>
> >>>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
Re: Printing PDF with Acroform don't work
Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,
> Am 23.11.2016 um 09:28 schrieb Neus Arbó <ne...@gmail.com>:
>
> I tried to save the document, and then read it again with pdfbox and print
> it. The document is saved with all the fields filled, but when I read it
> and print it, the fields are printed empty
>
that's because the NeedAppearances flag for the form is set to true which PDFBox 2.0.x treats as not to generate an appearance stream for the form fields as this is interpreted as an indication that the appearance will be generated by a viewing application. See https://issues.apache.org/jira/browse/PDFBOX-3356.
As this was not intuitive for most users we've changed that so that from 2.1.x on - which has yet to be released - PDFBox will always generate an appearance stream regardless of that setting. This is also to reflect a change in the upcoming PDF 2.0 specification which is deprecating that flag and requires filling applications to generate the appearance stream.
The workaround for 2.0.x is to set the NeedApparances flag to false prior to filling the form using PDAcroForm.setNeedAppearances(Boolean value).
BR
Maruan
> 2016-11-23 9:24 GMT+01:00 Neus Arbó <ne...@gmail.com>:
>
>> Yes, because I fill them from Java. And I'm sending the document to
>> printer using Java. You can see the code I'm using to fill the fields and
>> to print the document in the first email I send...
>> Is practically the same code I was using with pdfbox 1.8.12 (Except some
>> lines like the way I print it using PDFPageable, that it's the way I have
>> to print it according the Migration guide). And in pdfbox 1.8.12 the fields
>> where printing correctly, and in pdfbox 2.0.3 the fields are not printing
>> anymore.
>>
>> 2016-11-22 19:10 GMT+01:00 Tilman Hausherr <TH...@t-online.de>:
>>
>>> Am 22.11.2016 um 09:47 schrieb Neus Arbó:
>>>
>>>> This is the pdf document
>>>> https://drive.google.com/file/d/0B1_3_sVPnBolbjc3U21LTUFTeDg
>>>> /view?usp=sharing
>>>>
>>>
>>> The fields do not have any content.
>>>
>>>
>>> Tilman
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>
>>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Fwd: Printing PDF with Acroform don't work
Posted by Neus Arbó <ne...@gmail.com>.
I tried to save the document, and then read it again with pdfbox and print
it. The document is saved with all the fields filled, but when I read it
and print it, the fields are printed empty
2016-11-23 9:24 GMT+01:00 Neus Arbó <ne...@gmail.com>:
> Yes, because I fill them from Java. And I'm sending the document to
> printer using Java. You can see the code I'm using to fill the fields and
> to print the document in the first email I send...
> Is practically the same code I was using with pdfbox 1.8.12 (Except some
> lines like the way I print it using PDFPageable, that it's the way I have
> to print it according the Migration guide). And in pdfbox 1.8.12 the fields
> where printing correctly, and in pdfbox 2.0.3 the fields are not printing
> anymore.
>
> 2016-11-22 19:10 GMT+01:00 Tilman Hausherr <TH...@t-online.de>:
>
>> Am 22.11.2016 um 09:47 schrieb Neus Arbó:
>>
>>> This is the pdf document
>>> https://drive.google.com/file/d/0B1_3_sVPnBolbjc3U21LTUFTeDg
>>> /view?usp=sharing
>>>
>>
>> The fields do not have any content.
>>
>>
>> Tilman
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>>
>
Re: Fwd: Printing PDF with Acroform don't work
Posted by Neus Arbó <ne...@gmail.com>.
Yes, because I fill them from Java. And I'm sending the document to printer
using Java. You can see the code I'm using to fill the fields and to print
the document in the first email I send...
Is practically the same code I was using with pdfbox 1.8.12 (Except some
lines like the way I print it using PDFPageable, that it's the way I have
to print it according the Migration guide). And in pdfbox 1.8.12 the fields
where printing correctly, and in pdfbox 2.0.3 the fields are not printing
anymore.
2016-11-22 19:10 GMT+01:00 Tilman Hausherr <TH...@t-online.de>:
> Am 22.11.2016 um 09:47 schrieb Neus Arbó:
>
>> This is the pdf document
>> https://drive.google.com/file/d/0B1_3_sVPnBolbjc3U21LTUFTeDg
>> /view?usp=sharing
>>
>
> The fields do not have any content.
>
>
> Tilman
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
Re: Fwd: Printing PDF with Acroform don't work
Posted by Tilman Hausherr <TH...@t-online.de>.
Am 22.11.2016 um 09:47 schrieb Neus Arb�:
> This is the pdf document
> https://drive.google.com/file/d/0B1_3_sVPnBolbjc3U21LTUFTeDg/view?usp=sharing
The fields do not have any content.
Tilman
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Fwd: Printing PDF with Acroform don't work
Posted by Neus Arbó <ne...@gmail.com>.
This is the pdf document
https://drive.google.com/file/d/0B1_3_sVPnBolbjc3U21LTUFTeDg/view?usp=sharing
2016-11-21 21:40 GMT+01:00 Tilman Hausherr <TH...@t-online.de>:
> Am 21.11.2016 um 10:40 schrieb Neus Arbó:
>
>>
>> The PDF I'm using is attached in this mail.
>>
>
>
> No it's not, please upload it somewhere.
>
>
> Tilman
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
Re: Fwd: Printing PDF with Acroform don't work
Posted by Tilman Hausherr <TH...@t-online.de>.
Am 21.11.2016 um 10:40 schrieb Neus Arb:
>
> The PDF I'm using is attached in this mail.
No it's not, please upload it somewhere.
Tilman
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org