Hi,
I have a requirement for extracting bookmark values from a PDF document in JAVA.
Am using aspose.pdf-11.6.0.jar and the below code snippet, however no values get printed.
Please find attached the PDF file with bookmarks used for reading. Please refer the Bookmark Example field for bookmark.
Code Snippet:
_ _ _ _ _ _ _ _
com.aspose.pdf.Document newPdfDoc= new com.aspose.pdf.Document(inputStream);
//inputStream is java.io.InputStream object of the pdf file
com.aspose.pdf.facades.PdfBookmarkEditor bookmarkEditor = new com.aspose.pdf.facades.PdfBookmark(newPdfDoc);
Bookmarks bookmarks= bookmarkEditor.extractBookmarks();
for(Bookmark bookmark: (Iterable) bookmarks){
String strLevelSeprator = “”;
for (int i = 1; i
{
strLevelSeprator += "---- ";
}
System.out.println("Title :- " + strLevelSeprator + bookmark.getTitle());
System.out.println("Page Number :- " + strLevelSeprator + bookmark.getPageNumber());
System.out.println("Page Action :- " + strLevelSeprator + bookmark.getAction());
}
-------------------------------------
Please advise on how can the Bookmarks and Dynamic Content Control Values be retrieved from this PDF.
Hi Pexy,
Thanks for using our API’s.
I have tested the scenario and have observed that source/input PDF file does not include any bookmark and therefore, no information is being retrieved. Please take a look over attached image file.
[Java]
// Create PdfBookmarkEditor
com.aspose.pdf.facades.PdfBookmarkEditor bookmarkEditor = new com.aspose.pdf.facades.PdfBookmarkEditor();
// Open PDF file
bookmarkEditor.bindPdf("c:/pdftest/Test+PDF+Self+Assessment+Audit+Tool.pdf");
// Extract bookmarks
com.aspose.pdf.facades.Bookmarks bookmarks = bookmarkEditor.extractBookmarks();
for (com.aspose.pdf.facades.Bookmark bookmark : (Iterable) bookmarks) {
String strLevelSeprator = "";
for (int i = 1; i < bookmark.getLevel(); i++) {
strLevelSeprator += "---- ";
}
System.out.println("Title :- " + strLevelSeprator + bookmark.getTitle());
System.out.println("Page Number :- " + strLevelSeprator + bookmark.getPageNumber());
System.out.println("Page Action :- " + strLevelSeprator + bookmark.getAction());
}
Thanks.
This document was provided by a user who has used Adobe Life Cycle to fill in Dynamic and Static fields in the PDF.
I have requested the user now to fill in the bookmark values so that the below API code can be tested.
However, I need to know the API code which can be used to retrieve values from the below Static and Dynamic fields. Please find attached the screenshot with highlighted Static and Dynamic values which are already filled in the PDF.
Static fields:
TemplateType
TemplateVersion
Field_1
Dynamic fields:
ShortName_SAA001_1.01.01
FullName_SAA001_1.01.01
Guidance_SAA001_1.01.01
AttainmentRisk_SAA001_1.01.01
Hi Aspose PDF Team,
Please advise on this as it is quite urgent.
Thanks,
Pexy
Hi Pexy,
Thanks for sharing the details.
In order to get the values from XFA form field, please try using following code snippet.
[Java]
// Load XFA form
com.aspose.pdf.Document doc = new com.aspose.pdf.Document("c:/pdftest/Test+PDF+Self+Assessment+Audit+Tool.pdf");
String[] fields = doc.getForm().get_xfa().getFieldNames();
for (int i = 0; i < fields.length; i++) {
System.out.println("XFA form field: " + fields[i]);
}
Thanks. However it only extracts the field names. How can we get the values? Please advise.
Hi Pexy,
As the input document is XFA form, so in order to get field values, you need to first convert Form type to Standard AcroForm. Please try using following code snippet.
[Java]
// Load XFA form
com.aspose.pdf.Document doc = new com.aspose.pdf.Document("c:/pdftest/Test+PDF+Self+Assessment+Audit+Tool (1).pdf");
// convert form type from XFA to Standard AcroForm
doc.getForm().setType(com.aspose.pdf.FormType.Standard);
// get fields from PDF file
for (com.aspose.pdf.Field field : doc.getForm().getFields()) {
// get the value of individual field
System.out.println(field.getValue());
}
Thanks.
So the values can only be retrieved in Standard Acro Form? Is there a way to retrieve the field names in this same loop used after converting to Standard Acro form.
I tried using the methods field.getMappingName(), field.getName(), however these print “null” values.
Please advise on how to retrieve the field-value mapping in a single loop.
Thanks
Hi Pexy,
Hi,
I advised the user to make the PDF in Standard Acro Form and they have done it.
Now I can read the field and values from the form itself without conversion. So this issue is resolved.
Thanks a lot for your help.
Hi Pexy,