Hi there,
Document doc = new
Document(myDir + “TestFile.pdf”);<o:p></o:p>
// Get values from all fields
foreach (Aspose.Pdf.InteractiveFeatures.Forms.Field formField in doc.Form.Fields)
{
if (formField.Count > 1)
{
foreach (Aspose.Pdf.InteractiveFeatures.Annotations.Annotation annot in formField)
{
System.Console.WriteLine(annot.FullName);
System.Console.WriteLine(annot.Rect);
}
}
else
{
System.Console.WriteLine(formField.FullName);
System.Console.WriteLine(formField.Rect);
}
}
Using your code sample I changed mine to the below but each of the annotations that it loops through all have the exact same properties and what I’ve also noticed is that the coordinates are the combined coordinates of all the fields with the same name. So, that means if I have one small text field named “TestField1” at the top right of the page and another small text field named “TestField1” at the bottom left of the page, the reported coordinates provided are one giant field that covers the entire page. I’m not able to get the unique position and pageIndex for each duplicate field.
Hi there,
Sure well, let’s just use your own code you provided against the TestFile.pdf file in my initial post. If you run your own code and list out all of the fields with their coordinates, you’ll see that there are two fields with the same name that also have the exact same Rect properties when they should not because they are in different locations on the page. Also, what I noticed is that the Rect properties are combined into one giant Rect covering both field locations.
Document doc = new Document(myDir + “TestFile.pdf”);<o:p></o:p>
// Get values from all fields<o:p></o:p>
foreach (Aspose.Pdf.InteractiveFeatures.Forms.Field formField in doc.Form.Fields)<o:p></o:p>
{<o:p></o:p>
if (formField.Count > 1)<o:p></o:p>
{<o:p></o:p>
foreach (Aspose.Pdf.InteractiveFeatures.Annotations.Annotation annot in formField)<o:p></o:p>
{<o:p></o:p>
System.Console.WriteLine(annot.FullName);<o:p></o:p>
System.Console.WriteLine(annot.Rect);<o:p></o:p>
}<o:p></o:p>
}<o:p></o:p>
else<o:p></o:p>
{<o:p></o:p>
System.Console.WriteLine(formField.FullName);<o:p></o:p>
System.Console.WriteLine(formField.Rect);<o:p></o:p>
}<o:p></o:p>
}
Hi there,
Document doc = new
Document(myDir + “TestFile.pdf”);<o:p></o:p>
var editor = new PdfContentEditor(doc);
// Get values from all fields
foreach (Aspose.Pdf.InteractiveFeatures.Forms.Field formField in doc.Form.Fields)
{
if (formField.Count > 1)
{
foreach (Aspose.Pdf.InteractiveFeatures.Annotations.Annotation annot in formField)
{
System.Console.WriteLine(annot.FullName);
System.Console.WriteLine(annot.Rect);
DrawBox(editor, 1, annot.Rect, System.Drawing.Color.Red);
}
}
else
{
System.Console.WriteLine(formField.FullName);
System.Console.WriteLine(formField.Rect);
DrawBox(editor, 1, formField.Rect, System.Drawing.Color.Red);
}
}
doc.Save(myDir+"TestFile_out.pdf");
private static void DrawBox(PdfContentEditor editor, int page, Aspose.Pdf.Rectangle rect, System.Drawing.Color color)
{
var lineInfo = new LineInfo();
lineInfo.VerticeCoordinate = new[] {
(float)rect.LLX, (float)rect.LLY,
(float)rect.LLX, (float)rect.URY,
(float)rect.URX, (float)rect.URY,
(float)rect.URX, (float)rect.LLY
};
lineInfo.Visibility = true;
lineInfo.LineColor = color;
editor.CreatePolygon(lineInfo, page, new System.Drawing.Rectangle(0, 0, 0, 0), null);
}
Please feel free to contact us for any further assistance.
Best Regards,
Ah - that helped. I wasn’t passing my “annot” into my function when there were more than one field. I was accidentally passing in the field in either condition result. It’s working for me now. Thanks for all your assistance!
Hi there,