Retrieving Form Field Location in PDF
Retrieving form field locations in a PDF using DynamicPDF Core Suite is straightforward.
How to Retrieve Form Fields in C#
The following steps and sample code illustrate retrieving form field locations in a PDF using DynamicPDF Core Suite.
Steps for Retrieving Form Field Location in PDF
- Create a
PdfDocument
object with the desired PDF. - Create a
MergeDocument
object with the desired PDF. - Create a
Page
and add it to theMergeDocument
instance. - Create a
Image
object. - Set the height and width of image with
PdfDocument
form field's height and width respectively. - Add the image to the
Page
instance. - Save the
MergeDocument
instance.
Sample Code - C#
PdfDocument pdfDocument = new PdfDocument("myDocument.pdf");
MergeDocument document = new MergeDocument("output.pdf", MergeOptions.None);
Page page = document.Pages[0];
Image image = new Image("image.gif", 0, 0);
image.X = pdfDocument.Form.Fields["PlaceHolderField"].GetX(page);
image.Y = pdfDocument.Form.Fields["PlaceHolderField"].GetY(page);
image.Height = pdfDocument.Form.Fields["PlaceHolderField"].Height;
image.Width = pdfDocument.Form.Fields["PlaceHolderField"].Width;
page.Elements.Add(image);
document.Draw(@"Output.pdf");
GitHub Project
Clone or view the example project at GitHub. This example code is contained in the Examples/RetrievingFormFieldsExample.cs file.
Getting Started
NuGet Package
DynamicPDF Core Suite is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NET
package. The easiest way to install the package is through the Visual Studio Package Manager. You can also download the package directly from NuGet.
DynamicPDF Core Suite Information
More information can be found on the DynamicPDF Core Suite webpage.
Available on Other Platforms
DynamicPDF Core Suite is available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details.
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX