How can we get classic xfdf of annotation?

Please give a brief summary of your issue:
Is there any way to get the classic xfdf of annotation in android?

Thanks
Pawan

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi @pawan.verma You can get export XFDF of annotations as described here:

Do note that this function fdfExtract has multiple variants and will allow you to either pass in flag (for all annotations) or a list of annotations based on your requirement. Hope this helps.

Hi Shirley

I tried this sample code-

PDFDoc doc = new PDFDoc(“file:///android_asset/pdf-sample.pdf”);
FDFDoc doc_fields = doc.fdfExtract(PDFDoc.e_both);

doc_fields.saveAsXFDF("/storage/emulated/0/Download/pdf-sample.xfdf");
String classisAnnotation = doc_fields.saveAsXFDF();
}

1 - This saveAsXFDF() is creating a file at my download path but whatever I am getting from classic annotation that is not understandable. As in commandAnnotation , It give us action (add ,delete,modified) and type of annotation like circle,square,line etc. but in classicAnnotation I am getting nothing this type of information.

2- I test it with the creation of 4 annotation but in classic annotation string it return multiple in tag. I am not getting it clearly. I am sharing a text file of classic annotation.

Can we make classic annotation as simple as to command annotation String?
classic_annots.txt (6.0 KB)

Thanks
Pawan

Hi Pawan,

Just to clarify, are you interested in getting XFDF command format?

There are a few options:

  1. if you are interested in getting XFDF of changeset of current session, please look at this guide: PDFTron Systems Inc. | Documentation
  2. if you are interested in getting XFDF from certain annotations, please use the version of fdfExtract with 3 arrays (added/modified/deleted): PDFDoc - PDFTron API Reference | PDFTron Systems Inc.

Thanks.

Hi Shirley

Could you please clarify, is 2nd option (getting XFDF from certain annotation) returns classic annotation? If yes, can you please provide any sample code for getting xfdf string on annotation draw?

Thanks
Pawan

If your definition of “classic annotation” is XFDF command, then you want to use:

doc.fdfExtract(added_annotation_list, null, null) ← for add
doc.fdfExtract(null, modified_annotation_list, null, null) ← for modify
doc.fdfExtract(null, null, deleted_annotation_list) ← for delete

Otherwise please tell us what is a “classic annotation”?

Hi Shirley

I am getting wrong xfdf from “String XFDF_string = doc_fields.saveAsXFDF();”.I want xfdf in android same as window platform return. Please consider both response

Window Response-

<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n

<xfdf
xmlns=“http://ns.adobe.com/xfdf/” xml:space=“preserve”>\n\t
\n\t\t
<line style=“solid” width=“1” color="#FF0000" opacity=“1” creationdate=“D:20220321112208Z” flags=“print” start=“440.531,33.6106” end=“471.066,121.067” date=“D:20220321112208Z” name=“55deac3203673fe3-13b5a1c348e7aa79” page=“0” rect=“440.059,33.4457,471.538,121.231” />\n\t
\n\t
<pdf-info import-version=“3” version=“2”
xmlns=“http://www.pdftron.com/pdfinfo” />\n

Android -

<?xml version="1.0" encoding="UTF-8"?>

Thanks-
Pawan

Please go through with this android response.

xfdf.txt (5.3 KB)

Code Sample -

PDFDoc doc = new PDFDoc(new File("/storage/emulated/0/Android/data/com.example.customtoolsample/files/Download/output.pdf").getPath());
FDFDoc doc_fields = doc.fdfExtract(PDFDoc.e_both);
String XFDF_string = doc_fields.saveAsXFDF();

Thanks
Pawan

Hi Pawan, it is unclear what you mean by classic XFDF, and the result you are getting on Windows does not look like a correctly formatted XFDF to me.

Using doc.fdfExtract(PDFDoc.e_annots_only) should get you XFDF of all the annotations. Using doc.fdfExtract(array_of_annot) should get you XFDF of array of annotations. But if you keep using e_both, you are not going to get the result you need. Please help us understand your requirement by describing a high level use case/user story.

In additional, please kindly provide a sample PDF, as well as sample project on Android, as well as indicating exactly how you are getting the XFDF from Windows so we can proceed.

Thanks.

Hi Shirley

I tried to get XFDF from annots ( doc.fdfExtract(PDFDoc.e_annots_only); ) but still I am getting the same response please check my response and check now what’s wrong with this.

xfdf.txt (5.3 KB)

Thanks
Pawan

Hi Pawan,

We can not proceed in providing you a solution without more information on your end.

Could you answer the following questions?

  1. The XFDF returned by doc.fdfExtract(PDFDoc.e_annots_only) looks correct to me. Could you tell us why you think it’s wrong? Could you describe in detail what you are expecting to see?

  2. From your response here, the XFDF from Windows is not correct (i.e. the annotations should be enclosed in an tag). Could you tell us how you obtained this XFDF from Windows, and what PDFTron API you are calling on Windows to obtain this?

  3. Could you tell us what you mean by “classic xfdf of annotation”? How is this defined?