Hi,
Why do you think the file has a form? Can you edit the fields? Or does
it only look like a form, but you can't edit anything? If the later,
then it might be a "flattened" form, i.e. the appearances of the field
widgets have been integrated into the main PDF content stream(s) and the
fields removed.
Tilman
On 16.06.2023 00:25, Bruno Jullien wrote:
Hi Tilman,
1/ I have used PDFDebugger with our customer "Forms" and in most of
them (25):
- there is no annotations (confirmed in code with
page.getAnnotations())
- there is no XFA forms (confirmed in code with acroForm.getXFA()
== null)
- there is no acroForm (confirmed in code with getAcroForm() ==
null)
- or acroForm is not null but only contains a digital signature
field
and I have only 2 forms on 25 with non-empty valid acroForm. When I
download a simple form example, everything works: i see the fields and
their values easily. Which means this is a real PDF form. I think our
customers are generating the forms from word or another tool and the
result is kind of "fake forms" with no fields, just the graphical
aspect of a form, but not the structure.
2/ I tried to repair broken forms in code and in Designer => Nothing
happens
3/ getXFA() is always null, so we do not have XFA forms (confirmed
visually in Designer)
Any other suggestion?
I have the feeling we will have analyze the content of the PDF line by
line ...
Best Regards,
Bruno.
On 2023/06/15 19:26:21 Tilman Hausherr wrote:
> On 15.06.2023 19:52, Bruno Jullien wrote:
> > Hi Tilman,
> >
> > Thank you so much for your answer.
> > I cannot send you the pdf as it contains our customer data.
> >
> > Could you please tell me how I can read these field annotations in
java?
>
>
> I recommend you have a look at them with PDFDebugger and then get what
> you think is useful by accessing the annotations and then call
> getCOSObject() to get the dictionary. If it is a text field, then the
> content would be in COSName.X and the local name in COSName.T
>
> To be sure that the field is missing, click "View" and "Show internal
> structure" in PDFDebugger, it should look like this
>
>
> You can also try to fix the problem (if it exists) like this:
>
> document.getDocumentCatalog().getAcroForm(new
> AcroFormDefaultFixup(document));
>
> This tries to "repair" broken forms.
>
> It can also be done in PDFDebugger so that you can see whether it works
>
>
> >
> > Also many times we see a form with PDF reader and when doing
> > PDAcroForm acroForm = docCatalog.getAcroForm(), acroForm is null. How
> > can this happen?
>
>
> These are probably XFA forms. These have been deprecated long ago and
> PDFBox isn't supporting them. You would have to evaluate the XML. Start
> with getXFA().
>
> Tilman
>
>
> >
> > Regards,
> > Bruno.
> >
> >
> > On 2023/06/14 02:50:30 Tilman Hausherr wrote:
> > > Hi,
> > > Please share the PDF. (upload to sharehoster)
> > > I also recommend to use getFieldTree() instead of getFields()
but your
> > > approach is also correct. Maybe your file has only field
annotations
> > and
> > > not the actual fields, this happens sometimes.
> > > Tilman
> > >
> > > On 14.06.2023 01:49, Bruno Jullien wrote:
> > > > Hi,
> > > >
> > > > I am trying to get the form field names and values of some
signed PDF
> > > > (tried with several PDF files) and I cannot see them when using
> > > > getChildren() below.
> > > > I only see the signature field!!!
> > > >
> > > > this is the OUTPUT i get from the code below:
> > > > FullyQualifiedName: ENVELOPEID_47C2241C2E9B492B892DA48C8ED1BE01
> > > > Value:
> > > >
> >
org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature@d041cf
> > > >
> > > > Any suggestion is welcome on how to access the form fields.
> > > >
> > > > Here is my code:
> > > > =========================
> > > > import java.io.File;
> > > > import java.io.IOException;
> > > > import java.util.List;
> > > >
> > > > import org.apache.pdfbox.pdmodel.PDDocument;
> > > > import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
> > > > import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
> > > > import org.apache.pdfbox.pdmodel.interactive.form.PDField;
> > > > import
org.apache.pdfbox.pdmodel.interactive.form.PDNonTerminalField;
> > > >
> > > > public class PdfboxGetFormFields {
> > > > public static void main(String[] args) throws IOException {
> > > > PDDocument document = PDDocument.load(new
> > File("myfile.pdf"));
> > > > PDDocumentCatalog docCatalog =
document.getDocumentCatalog();
> > > > PDAcroForm acroForm = docCatalog.getAcroForm();
> > > >
> > > > List<PDField> fields = acroForm.getFields();
> > > > for (PDField field : fields)
> > > > {
> > > > list(field);
> > > > }
> > > > document.close();
> > > > }
> > > >
> > > > static void list(PDField field)
> > > > {
> > > > System.out.println("FullyQualifiedName:
> > > > "+field.getFullyQualifiedName());
> > > > System.out.println("Value: "+field.getValueAsString());
> > > > if (field instanceof PDNonTerminalField)
> > > > {
> > > > PDNonTerminalField nonTerminalField =
> > (PDNonTerminalField)
> > > > field;
> > > > for (PDField child : nonTerminalField.getChildren())
> > > > {
> > > > list(child);
> > > > }
> > > > }
> > > > }
> > > > }
> > > >
> > >
> > >
> > >
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
> > > For additional commands, e-mail: users-h...@pdfbox.apache.org
> > >
> > >
> >
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org