You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by DJ...@gmx.de on 2016/06/22 08:55:48 UTC

Pdfbox 2.0 Forms


Hello,
 
i have a little problem after update from 1.8 to 2.0.
 
I open a pdf form, witch was created from libreoffice, fillout the form, and show it with pdfrenderer.
After update to 2.0 the fill out form fields was not shown at image.
When i save the document to file, the fill out data are included.
 
Code:
---------------------------
PDDocument doc = PDDocument.load(new File(Client.class.getResource("/resources/pdf/template.pdf").getFile()));
PDAcroForm form = doc.getDocumentCatalog().getAcroForm();
for(int i = 0; i<list.size(); i++) {
String fieldname = "field"+(i+1);
form.getField(fieldname).setValue(((ListObject)list.get(i)).getText());
}
 
PDFRenderer pdfRenderer = new PDFRenderer(doc);
        try {
            ImagePanel panel = new ImagePanel(pdfRenderer.renderImageWithDPI(viewPage, 300, ImageType.RGB),zoom);
            scpanel.setViewportView(panel);
            panel.repaint();
           
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
---------------------------
Anyone has an idea, why the form data not shown but save?
 
Greets
Lars

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Pdfbox 2.0 Forms

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,

> Am 22.06.2016 um 13:21 schrieb Aaron Mulder <am...@gmail.com>:
> 
> So I've had an issue with a third-party PDF with forms where once I
> complete the form the layout of the completed form field text is
> slightly different in Preview on the Mac compared to Acrobat Reader on
> Windows, and also across browsers with built-in pdf rendering.  For
> instance, the text might be offset down and to the left a few pixels
> on one platform, or a font size that fits fine on one platform gets
> cut off on another.

one question there is if the font is embedded or not. If not there will be font substitution. Even if yes there will be slight differences between most renderers.

> 
> I notice that the NeedAppearances flag is set to true.  I'm not really
> familiar with this flag, but it sounds like you're saying it means the
> renderer should make up an appearance to use.

NeedAppearances, which is deprecated for the upcoming PDF 2 spec, tells the PDF application that the appearance stream (the look) for the form field shall be regenerated while rendering. For PDF 2 a form filling application shall generate the appearance stream when the fields value is updated.

> 
> Could that be the problem?  Do I need to just manually specify an
> appearance for each field to make it show exactly the same on each
> platform?

to ensure an as much consistent rendering on different platforms the appearance stream should be available.

> 
> I guess the other question is, some of the fields (both "text boxes"
> and "text areas") can take a somewhat arbitrary amount of text -- is
> part of the purpose of NeedAppearances to allow the renderer to select
> a font or scaling that fits all the text in the available space of the
> field?  Though the form field itself has a font defined (in /DA).  I
> guess I'm a little confused as to what the appearance stream is
> supposed to do for a form field.

A very quick explanation of how that fits together - more details in the PDF spec:

A form field holds information such as the fields value anhas one to many annotations (PDAnnotationWidget in PDFBox) defining the location and the look of the form field together with layout settings. An annotation should have at least  one apperanace streams assigned to it (there can be multiple for different fields states) which combines all the settings and the fields value(s) into what appears on screen or printed.

So without an appearance stream either there is no visual appearance at all or one which is generated by the renderer at runtime.

So one would think that if there is an appearance stream you are fine but:

- renderers are not required to use that appearance stream
- the layout details of the apperance stream are not part of the spec - e.g. is there a padding for the text within the fields box (Acrobat/Reader uses one), line spacing ….


> 
> Here's the example (layout good on Mac/Preview, bad on Windows/Reader,
> in between on Mac/Chrome): http://princecon.org/gnome.pdf  In this
> case the main content is the original empty PDF, and all the field
> values are specified in the revision(s) at the end of the document.

I'll take a look at it later today and might come up with some more details. 

Take a look at the PDF templates in test/resources/org/apache/pdfbox/pdmodel/interactive/form to look at some layout details.

BR
Maruan

> 
> Thanks,
>       Aaron
> 
> 
> On Wed, Jun 22, 2016 at 5:07 AM, Maruan Sahyoun <sa...@fileaffairs.de> wrote:
>> Hi,
>> 
>>> Am 22.06.2016 um 10:55 schrieb DJ.Larry@gmx.de:
>>> 
>>> 
>>> 
>>> Hello,
>>> 
>>> i have a little problem after update from 1.8 to 2.0.
>>> 
>>> I open a pdf form, witch was created from libreoffice, fillout the form, and show it with pdfrenderer.
>>> After update to 2.0 the fill out form fields was not shown at image.
>>> When i save the document to file, the fill out data are included.
>>> 
>>> Code:
>>> ---------------------------
>>> PDDocument doc = PDDocument.load(new File(Client.class.getResource("/resources/pdf/template.pdf").getFile()));
>>> PDAcroForm form = doc.getDocumentCatalog().getAcroForm();
>>> for(int i = 0; i<list.size(); i++) {
>>> String fieldname = "field"+(i+1);
>>> form.getField(fieldname).setValue(((ListObject)list.get(i)).getText());
>>> }
>>> 
>>> PDFRenderer pdfRenderer = new PDFRenderer(doc);
>>>        try {
>>>            ImagePanel panel = new ImagePanel(pdfRenderer.renderImageWithDPI(viewPage, 300, ImageType.RGB),zoom);
>>>            scpanel.setViewportView(panel);
>>>            panel.repaint();
>>> 
>>>        } catch (IOException e) {
>>>            // TODO Auto-generated catch block
>>>            e.printStackTrace();
>>>        }
>>> ---------------------------
>>> Anyone has an idea, why the form data not shown but save?
>> 
>> 
>> without looking at the PDF it's difficult to tell but it might be realted to https://issues.apache.org/jira/browse/PDFBOX-3356
>> 
>> BR
>> Maruan
>> 
>> 
>>> 
>>> Greets
>>> Lars
>>> 
>>> ---------------------------------------------------------------------
>>> 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
>> 
> 
> ---------------------------------------------------------------------
> 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: Pdfbox 2.0 Forms

Posted by Aaron Mulder <am...@gmail.com>.
So I've had an issue with a third-party PDF with forms where once I
complete the form the layout of the completed form field text is
slightly different in Preview on the Mac compared to Acrobat Reader on
Windows, and also across browsers with built-in pdf rendering.  For
instance, the text might be offset down and to the left a few pixels
on one platform, or a font size that fits fine on one platform gets
cut off on another.

I notice that the NeedAppearances flag is set to true.  I'm not really
familiar with this flag, but it sounds like you're saying it means the
renderer should make up an appearance to use.

Could that be the problem?  Do I need to just manually specify an
appearance for each field to make it show exactly the same on each
platform?

I guess the other question is, some of the fields (both "text boxes"
and "text areas") can take a somewhat arbitrary amount of text -- is
part of the purpose of NeedAppearances to allow the renderer to select
a font or scaling that fits all the text in the available space of the
field?  Though the form field itself has a font defined (in /DA).  I
guess I'm a little confused as to what the appearance stream is
supposed to do for a form field.

Here's the example (layout good on Mac/Preview, bad on Windows/Reader,
in between on Mac/Chrome): http://princecon.org/gnome.pdf  In this
case the main content is the original empty PDF, and all the field
values are specified in the revision(s) at the end of the document.

Thanks,
       Aaron


On Wed, Jun 22, 2016 at 5:07 AM, Maruan Sahyoun <sa...@fileaffairs.de> wrote:
> Hi,
>
>> Am 22.06.2016 um 10:55 schrieb DJ.Larry@gmx.de:
>>
>>
>>
>> Hello,
>>
>> i have a little problem after update from 1.8 to 2.0.
>>
>> I open a pdf form, witch was created from libreoffice, fillout the form, and show it with pdfrenderer.
>> After update to 2.0 the fill out form fields was not shown at image.
>> When i save the document to file, the fill out data are included.
>>
>> Code:
>> ---------------------------
>> PDDocument doc = PDDocument.load(new File(Client.class.getResource("/resources/pdf/template.pdf").getFile()));
>> PDAcroForm form = doc.getDocumentCatalog().getAcroForm();
>> for(int i = 0; i<list.size(); i++) {
>> String fieldname = "field"+(i+1);
>> form.getField(fieldname).setValue(((ListObject)list.get(i)).getText());
>> }
>>
>> PDFRenderer pdfRenderer = new PDFRenderer(doc);
>>         try {
>>             ImagePanel panel = new ImagePanel(pdfRenderer.renderImageWithDPI(viewPage, 300, ImageType.RGB),zoom);
>>             scpanel.setViewportView(panel);
>>             panel.repaint();
>>
>>         } catch (IOException e) {
>>             // TODO Auto-generated catch block
>>             e.printStackTrace();
>>         }
>> ---------------------------
>> Anyone has an idea, why the form data not shown but save?
>
>
> without looking at the PDF it's difficult to tell but it might be realted to https://issues.apache.org/jira/browse/PDFBOX-3356
>
> BR
> Maruan
>
>
>>
>> Greets
>> Lars
>>
>> ---------------------------------------------------------------------
>> 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
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Pdfbox 2.0 Forms

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,

> Am 22.06.2016 um 10:55 schrieb DJ.Larry@gmx.de:
> 
> 
> 
> Hello,
>  
> i have a little problem after update from 1.8 to 2.0.
>  
> I open a pdf form, witch was created from libreoffice, fillout the form, and show it with pdfrenderer.
> After update to 2.0 the fill out form fields was not shown at image.
> When i save the document to file, the fill out data are included.
>  
> Code:
> ---------------------------
> PDDocument doc = PDDocument.load(new File(Client.class.getResource("/resources/pdf/template.pdf").getFile()));
> PDAcroForm form = doc.getDocumentCatalog().getAcroForm();
> for(int i = 0; i<list.size(); i++) {
> String fieldname = "field"+(i+1);
> form.getField(fieldname).setValue(((ListObject)list.get(i)).getText());
> }
>  
> PDFRenderer pdfRenderer = new PDFRenderer(doc);
>         try {
>             ImagePanel panel = new ImagePanel(pdfRenderer.renderImageWithDPI(viewPage, 300, ImageType.RGB),zoom);
>             scpanel.setViewportView(panel);
>             panel.repaint();
>            
>         } catch (IOException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         }
> ---------------------------
> Anyone has an idea, why the form data not shown but save?


without looking at the PDF it's difficult to tell but it might be realted to https://issues.apache.org/jira/browse/PDFBOX-3356

BR
Maruan


>  
> Greets
> Lars
> 
> ---------------------------------------------------------------------
> 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: Pdfbox 2.0 Forms

Posted by "dj.larry@gmx.de" <dj...@gmx.de>.
Hello,

i have make some tests. So i thinks its the PDFRenderer. When I open a 
pdf, fill out the form and safe it as png, then the fields are not 
filled out. Save it as pdf, works.

But i have a solution:
//Open the form
doc = PDDocument.load(new 
File(Client.class.getResource("/resources/pdf/document.pdf").getFile()));
PDAcroForm form = doc.getDocumentCatalog().getAcroForm();
form.setNeedAppearances(false); //<-- the importent line
form.getField(fieldname).setValue(something);

So when setNeedAppearances is set to false, the Image-Renderer show the 
fill out fields.

Greets

Lars




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org