Original sample PDF file (1).pdf (272.0 KB)
code snippet:
Document doc = new Document(“C:\OCMobile\a.pdf”);
PdfAnnotationEditor annotationEditor = new PdfAnnotationEditor(doc);
com.aspose.pdf.facades.Form pdfForm = new com.aspose.pdf.facades.Form(doc);
String[] fieldNames = pdfForm.getFieldNames();
// This fieldnames is coming empty always but form field is there so any solution on this
@SUBHAROOP
We checked the PDF shared by you and noticed that it does not have any editable form fields. It is a flattened PDF document which is why API was unable to detect any form field in it. Please try the same code snippet with a document having valid AcroForms in it and let us know in case you still face any issues.
is there any way to work in this pdf to read form filed like is it possible ?
@SUBHAROOP
This PDF also does not have form fields in it. Instead it has annotation that can be retrieved using the example give in the below article:
//code snippet
String in=“C:\OCMobile\a.pdf”;
Document doc = new Document(in);
PdfAnnotationEditor annotationEditor = new PdfAnnotationEditor(doc);
Form pdfForm = new Form(doc);
annotationEditor.bindPdf(doc);
int[] annotTypes = new int[]{AnnotationType.Text, AnnotationType.Highlight};
List annotList = annotationEditor.extractAnnotations(1, 2 , annotTypes);
I have used this below code and getting exception from extractAnnotations method can you tell me what change I need to do provide me the final snippet to retrieve the annotation .
Use this pdf file:noPHI sample PDF file (1).pdf (277.2 KB)
@SUBHAROOP
Please try to use the below code snippet in order to extract the Annotations and their content:
Document doc = new Document(dataDir + "noPHI sample PDF file (1).pdf");
foreach (Aspose.Pdf.Page page in doc.Pages)
{
Console.WriteLine(page.Annotations.Count());
foreach(var annotation in page.Annotations)
{
Console.WriteLine($"Annotation Type is {annotation.AnnotationType}");
Console.WriteLine($"Annotation Text is {annotation.Contents}");
}
}