Winnovative HTML to PDF Converter

Fill PDF Forms

Winnovative HTML to PDF Converter for .NET Documentation

Winnovative HTML to PDF Converter allows you to fill a PDF document form. You can access the form fields collection using the PdfFormFields property of the DocumentForm object. You can select a field from collection by index or by name.

Code Sample - Fill PDF Forms

protected void fillPdfButton_Click(object sender, EventArgs e)
{
    Document pdfDocument = null;
    try
    {
        // Load the PDF document with a form to fill
        string pdfFileWithForm = Server.MapPath("~/DemoAppFiles/Input/PDF_Files/Fill_PDF_Forms.pdf");
        pdfDocument = new Document(pdfFileWithForm);

        // Set license key received after purchase to use the converter in licensed mode
        // Leave it not set to use the converter in demo mode
        pdfDocument.LicenseKey = "fvDh8eDx4fHg4P/h8eLg/+Dj/+jo6Og=";

        // Get the First Name text box field by name from PDF form fields collection and fill a text value
        PdfFormField firstNameTextBoxField = pdfDocument.Form.Fields["firstName"];
        if (firstNameTextBoxField != null)
            firstNameTextBoxField.Value = firstNameTextBox.Text;

        // Get the Last Name text box field by name from PDF form fields collection and fill a text value
        PdfFormField lastNameTextBoxField = pdfDocument.Form.Fields["lastName"];
        if (lastNameTextBoxField != null)
            lastNameTextBoxField.Value = lastNameTextBox.Text;

        // Get the Password text box field by name from PDF form fields collection and fill a text value
        PdfFormField passwordTextBoxField = pdfDocument.Form.Fields["password"];
        if (passwordTextBoxField != null)
            passwordTextBoxField.Value = passwordTextBox.Text;

        // Get the Gender radio buttons group field by name from form fields collection and set the selected value
        PdfFormField genderRadioGroupField = pdfDocument.Form.Fields["gender"];
        if (genderRadioGroupField != null)
            genderRadioGroupField.Value = maleRadioButton.Checked ? "male" : "female";

        // Get the 'I have a car' check box field by name from form fields collection and set the checked status
        PdfFormField haveCarCheckBoxField = pdfDocument.Form.Fields["haveCar"];
        if (haveCarCheckBoxField != null)
            haveCarCheckBoxField.Value = haveCarCheckBox.Checked;

        // Get the 'Vehicle Type' combo box field by name from form fields collection and set the selected value
        PdfFormField vehicleTypeComboBoxField = pdfDocument.Form.Fields["vehicleType"];
        if (vehicleTypeComboBoxField != null)
            vehicleTypeComboBoxField.Value = carTypeComboBox.SelectedValue;

        // Get the Comments multi line text box field by name from PDF form fields collection and fill a text value
        PdfFormField commentsTextBoxField = pdfDocument.Form.Fields["comments"];
        if (commentsTextBoxField != null)
            commentsTextBoxField.Value = commentsTextBox.Text;

        // Flatten PDF form fields if this was requested
        if (flattenPdfFormCheckBox.Checked)
            pdfDocument.Form.FlattenFields();

        // Save the PDF document in a memory buffer
        byte[] outPdfBuffer = pdfDocument.Save();

        // Set response content type
        Response.AddHeader("Content-Type", "application/pdf");

        // Instruct the browser to open the PDF file as an attachment or inline
        Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Filled_PDF_Form.pdf.pdf; size={0}", outPdfBuffer.Length.ToString()));

        // Write the PDF document buffer to HTTP response
        Response.BinaryWrite(outPdfBuffer);

        // End the HTTP response and stop the current page processing
        Response.End();
    }
    finally
    {
        // Close the document to stamp
        if (pdfDocument != null)
            pdfDocument.Close();
    }
}