How to open existing PDF form and fill the form and then save as new PDF file using Bytescout.PDF library for .NET

Filling existing PDF form with values and saving as new PDF document

This example demonstrates how to stamp PDF pages with page numbers using Bytescout.PDF library

PDF form filled using BytescoutPDF library\

Download example source code: bytescoutpdf_fill_pdf_form_text_and_checkboxes.zip (10 KB)

using System;
using System.Collections.Generic;
using System.Text;
using Bytescout.PDF;
using System.Diagnostics;

namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
// Create main PDF Doc Engine
PDFDocEngine engine = new PDFDocEngine("", "");

// Add new document
Document document = engine.AddDocument("InputForm.pdf");

// Append new page to the document
Page page = document.GetPage(0);

// Get control list
ControlList controlList = document.Controls;

// Get indices
uint editBoxNameIndex = controlList.GetIndexByName("editBoxName");
uint editBoxSurnameIndex = controlList.GetIndexByName("editBoxSurname");
uint checkBoxMarried = controlList.GetIndexByName("Married");

// Set values
controlList.SetValueByIndex(editBoxNameIndex, "John");
controlList.SetValueByIndex(editBoxSurnameIndex, "Doe");
controlList.SetValueByIndex(checkBoxMarried, "1");

// Save document
document.Save("FillForm.pdf");

// open generated PDF document in default PDF viewer installed in Windows
Process.Start("FillForm.pdf");
}
}
}

Download example source code: bytescoutpdf_fill_pdf_form_text_and_checkboxes.zip (10 KB)

Filed in: PDF SDK for .NET

Tutorials: