XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
C# PDF: How to HTML5 Viewer & Editor PDF Create PDF Export File and Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF Viewer & Editor Work with Other SDKs Barcode Read Barcode Create OCR Twain
Data: Auto Fill-in Field Data
  |  
Home ›› XDoc.PDF ›› C# PDF: Auto Fill-in Field Data

C#.NET PDF SDK - Fill-in Field Data Automatically in C#.NET


Online C# Tutorial to Automatically Fill in Field Data to PDF with C#.NET Library




A best PDF document SDK library for .NET framework enable users the ability to fill in PDF forms in Visual C# .NET class


Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint


Robust .NET components and dlls for filling in PDF form online in ASP.NET WebForm application


A professional PDF form filler control able to be integrated in Visual Studio .NET WinForm and fill in PDF form use C# language


Free online C# sample code can help users to fill in PDF form field automatically in .NET


Support to fill in form field in specified position of adobe PDF file


Able to fill out all PDF form field in C#.NET


RasterEdge XDoc.PDF SDK package provides PDF field processing features for your C# project. On this C# tutorial, you will learn how to fill-in field data to PDF automatically in your C#.NET application. Following C# sample code can help you have a quick evaluation of it.





C# fill a field data in the page


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.




String inputFilePath = Program.RootPath + "\\" + "1_AF.pdf";
String outputFilePath = Program.RootPath + "\\" + "output.pdf";

List<BaseFormField> fields = PDFFormHandler.GetFormFields(inputFilePath);

int cnt = 0;
foreach (BaseFormField field in fields)
{
    float x = field.Position.X + field.Size.Width / 2F;
    float y = field.Position.Y + field.Size.Height / 2F;

    if (field is AFCheckBox)
    {   //  fill a CheckBox field, set state to ON
        AFCheckBoxInput input = new AFCheckBoxInput(true);
        PDFFormHandler.FillFormField(inputFilePath, 0, new PointF(x, y), input, outputFilePath + cnt.ToString() + ".pdf");
    }
    else if (field is AFRadioButton)
    {   //  fill a RadioButton field, set state to ON 
        AFRadioButtonInput input = new AFRadioButtonInput(true);
        PDFFormHandler.FillFormField(inputFilePath, 0, new PointF(x, y), input, outputFilePath + cnt.ToString() + ".pdf");
    }
    else if (field is AFTextBox)
    {   //  fill a TextBox field, change content to "Hello World"
        AFTextBoxInput input = new AFTextBoxInput("Hello World");
        PDFFormHandler.FillFormField(inputFilePath, 0, new PointF(x, y), input, outputFilePath + cnt.ToString() + ".pdf");
    }
    else if (field is AFListBox)
    {   //  fill a ListBox field, selete the 3rd item (with index value 2)
        AFListBoxInput input = new AFListBoxInput(new int[1] { 2 });
        PDFFormHandler.FillFormField(inputFilePath, 0, new PointF(x, y), input, outputFilePath + cnt.ToString() + ".pdf");
    }
    else if (field is AFComboBox)
    {   //  fill a BomboBox field, selete the 3rd item (with index value 2)
        AFComboBoxInput input = new AFComboBoxInput(2);
        PDFFormHandler.FillFormField(inputFilePath, 0, new PointF(x, y), input, outputFilePath + cnt.ToString() + ".pdf");
    }

    cnt++;
}



String inputFilePath = Program.RootPath + "\\" + "1_AF.pdf";
String outputFilePath = Program.RootPath + "\\" + "output.pdf";

List<BaseFormField> fields = PDFFormHandler.GetFormFields(inputFilePath);

int cnt = 0;
foreach (BaseFormField field in fields)
{
    if (field is AFCheckBox)
    {   //  fill a CheckBox field, set state to ON
        AFCheckBoxInput input = new AFCheckBoxInput(true);
        PDFFormHandler.FillFormField(inputFilePath, field.Name, input, outputFilePath + cnt.ToString() + ".pdf");
    }
    else if (field is AFRadioButton)
    {   //  fill a RadioButton field, set state to ON 
        AFRadioButtonInput input = new AFRadioButtonInput(true);
        PDFFormHandler.FillFormField(inputFilePath, field.Name, input, outputFilePath + cnt.ToString() + ".pdf");
    }
    else if (field is AFTextBox)
    {   //  fill a TextBox field, change content to "Hello World"
        AFTextBoxInput input = new AFTextBoxInput("Hello World!");
        PDFFormHandler.FillFormField(inputFilePath, field.Name, input, outputFilePath + cnt.ToString() + ".pdf");
    }
    else if (field is AFListBox)
    {   //  fill a ListBox field, selete the 3rd item (with index value 2)
        AFListBoxInput input = new AFListBoxInput(new int[1] { 2 });
        PDFFormHandler.FillFormField(inputFilePath, field.Name, input, outputFilePath + cnt.ToString() + ".pdf");
    }
    else if (field is AFComboBox)
    {   //  fill a BomboBox field, selete the 3rd item (with index value 2)
        AFComboBoxInput input = new AFComboBoxInput(2);
        PDFFormHandler.FillFormField(inputFilePath, field.Name, input, outputFilePath + cnt.ToString() + ".pdf");
    }

    cnt++;
}




C# fill fields data in a document object





String inputFilePath = Program.RootPath + "\\" + "1_AF.pdf";
String outputFilePath = Program.RootPath + "\\" + "output.pdf";

PDFDocument doc = new PDFDocument(inputFilePath);

List<BaseFormField> fields = PDFFormHandler.GetFormFields(doc);

int cnt = 0;
foreach (BaseFormField field in fields)
{
    if (field is AFCheckBox)
    {   //  fill a CheckBox field, set state to ON
        AFCheckBoxInput input = new AFCheckBoxInput(true);
        PDFFormHandler.FillFormField(doc, field.Name, input);
    }
    else if (field is AFRadioButton)
    {   //  fill a RadioButton field, set state to ON 
        AFRadioButtonInput input = new AFRadioButtonInput(true);
        PDFFormHandler.FillFormField(doc, field.Name, input);
    }
    else if (field is AFTextBox)
    {   //  fill a TextBox field, change content to "Hello World"
        AFTextBoxInput input = new AFTextBoxInput("Hello World!");
        PDFFormHandler.FillFormField(doc, field.Name, input);
    }
    else if (field is AFListBox)
    {   //  fill a ListBox field, selete the 3rd item (with index value 2)
        AFListBoxInput input = new AFListBoxInput(new int[1] { 2 });
        PDFFormHandler.FillFormField(doc, field.Name, input);
    }
    else if (field is AFComboBox)
    {   //  fill a BomboBox field, selete the 3rd item (with index value 2)
        AFComboBoxInput input = new AFComboBoxInput(2);
        PDFFormHandler.FillFormField(doc, field.Name, input);
    }

    cnt++;
}

doc.Save(outputFilePath);




.NET Class Namespace Required



Add necessary references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;