IRONSOFTWAREHOME
Formularze PDF
using IronPdf;
using System;

// Step 1.  Creating a PDF with editable forms from HTML using form and input tags
// Radio Button and Checkbox can also be implemented with input type 'radio' and 'checkbox'
const string formHtml = @"
    <html>
        <body>
            <h2>Editable PDF  Form</h2>
            <form>
              First name: <br> <input type='text' name='firstname' value=''> <br>
              Last name: <br> <input type='text' name='lastname' value=''> <br>
              <br>
              <p>Please specify your gender:</p>
              <input type='radio' id='female' name='gender' value= 'Female'>
                <label for='female'>Female</label> <br>
                <br>
              <input type='radio' id='male' name='gender' value='Male'>
                <label for='male'>Male</label> <br>
                <br>
              <input type='radio' id='non-binary/other' name='gender' value='Non-Binary / Other'>
                <label for='non-binary/other'>Non-Binary / Other</label>
              <br>

              <p>Please select all medical conditions that apply:</p>
              <input type='checkbox' id='condition1' name='Hypertension' value='Hypertension'>
              <label for='condition1'> Hypertension</label><br>
              <input type='checkbox' id='condition2' name='Heart Disease' value='Heart Disease'>
              <label for='condition2'> Heart Disease</label><br>
              <input type='checkbox' id='condition3' name='Stoke' value='Stoke'>
              <label for='condition3'> Stoke</label><br>
              <input type='checkbox' id='condition4' name='Diabetes' value='Diabetes'>
              <label for='condition4'> Diabetes</label><br>
              <input type='checkbox' id='condition5' name='Kidney Disease' value='Kidney Disease'>
              <label for='condition5'> Kidney Disease</label><br>
            </form>
        </body>
    </html>";

// Instantiate Renderer
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
renderer.RenderHtmlAsPdf(formHtml).SaveAs("BasicForm.pdf");

// Step 2. Reading and Writing PDF form values.
var FormDocument = PdfDocument.FromFile("BasicForm.pdf");

// Set and Read the value of the "firstname" field
var FirstNameField = FormDocument.Form.FindFormField("firstname");
FirstNameField.Value = "Minnie";
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value);

// Set and Read the value of the "lastname" field
var LastNameField = FormDocument.Form.FindFormField("lastname");
LastNameField.Value = "Mouse";
Console.WriteLine("LastNameField value: {0}", LastNameField.Value);

FormDocument.SaveAs("FilledForm.pdf");
Imports IronPdf
Imports System

' Step 1.  Creating a PDF with editable forms from HTML using form and input tags
' Radio Button and Checkbox can also be implemented with input type 'radio' and 'checkbox'
Const formHtml As String = "
    <html>
        <body>
            <h2>Editable PDF  Form</h2>
            <form>
              First name: <br> <input type='text' name='firstname' value=''> <br>
              Last name: <br> <input type='text' name='lastname' value=''> <br>
              <br>
              <p>Please specify your gender:</p>
              <input type='radio' id='female' name='gender' value= 'Female'>
                <label for='female'>Female</label> <br>
                <br>
              <input type='radio' id='male' name='gender' value='Male'>
                <label for='male'>Male</label> <br>
                <br>
              <input type='radio' id='non-binary/other' name='gender' value='Non-Binary / Other'>
                <label for='non-binary/other'>Non-Binary / Other</label>
              <br>

              <p>Please select all medical conditions that apply:</p>
              <input type='checkbox' id='condition1' name='Hypertension' value='Hypertension'>
              <label for='condition1'> Hypertension</label><br>
              <input type='checkbox' id='condition2' name='Heart Disease' value='Heart Disease'>
              <label for='condition2'> Heart Disease</label><br>
              <input type='checkbox' id='condition3' name='Stoke' value='Stoke'>
              <label for='condition3'> Stoke</label><br>
              <input type='checkbox' id='condition4' name='Diabetes' value='Diabetes'>
              <label for='condition4'> Diabetes</label><br>
              <input type='checkbox' id='condition5' name='Kidney Disease' value='Kidney Disease'>
              <label for='condition5'> Kidney Disease</label><br>
            </form>
        </body>
    </html>"

' Instantiate Renderer
Dim renderer = New ChromePdfRenderer()
renderer.RenderingOptions.CreatePdfFormsFromHtml = True
renderer.RenderHtmlAsPdf(formHtml).SaveAs("BasicForm.pdf")

' Step 2. Reading and Writing PDF form values.
Dim FormDocument = PdfDocument.FromFile("BasicForm.pdf")

' Set and Read the value of the "firstname" field
Dim FirstNameField = FormDocument.Form.FindFormField("firstname")
FirstNameField.Value = "Minnie"
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value)

' Set and Read the value of the "lastname" field
Dim LastNameField = FormDocument.Form.FindFormField("lastname")
LastNameField.Value = "Mouse"
Console.WriteLine("LastNameField value: {0}", LastNameField.Value)

FormDocument.SaveAs("FilledForm.pdf")
NuGet Download
Install-Package IronPdf
Formularze PDF

Formularze PDF

Za pomocą IronPDF można tworzyć edytowalne dokumenty PDF tak samo łatwo, jak zwykłe dokumenty. Klasa PdfForm to zbiór pól formularza edytowalnych przez użytkownika w dokumencie PDF. Można go wdrożyć w renderowaniu pliku PDF, aby przekształcić go w formularz lub dokument z możliwością edycji.

Ten przykład pokazuje, jak tworzyć edytowalne formularze PDF w IronPDF.

PDFy z edytowalnymi formularzami można stworzyć z HTML, po prostu dodając znaczniki <form>, <input> oraz <textarea> do części dokumentu.

Metoda PdfDocument.Form.FindFormField może być używana do odczytu i zapisu wartości dowolnego pola formularza. Atrybut name pola jest przypisany do tego pola w twoim HTML.

Obiekt PdfDocument.Form może być używany na dwa sposoby:

  • Wypełnianie wartości domyślnych: Funkcja ta może służyć do ustawiania wartości domyślnych dla pól formularzy, które będą wyświetlane w przeglądarkach plików PDF, takich jak Adobe Reader.
  • Odczytywanie danych wprowadzonych przez użytkownika: Po wypełnieniu formularza przez użytkownika można uzyskać dostęp do pól formularza i odczytać dane z powrotem do aplikacji.

W powyższym przykładzie najpierw importujemy bibliotekę IronPdf i definiujemy metodę CreateEditablePdfDocument. Ta metoda zawiera strukturę HTML prostego formularza z polami wprowadzania dla nazwy użytkownika i komentarzy. Korzystając z renderera HtmlToPdf, konwertujemy tę zawartość HTML na dokument PDF.

Następnie, używamy pdfDocument.Form do uzyskania dostępu do formularzy i manipulacji nimi. Ustawiamy wartości domyślne, które pojawią się po otwarciu dokumentu w przeglądarce PDF. Na koniec dokument jest zapisywany pod nazwą "EditableForm.pdf", co pozwala na jego przechowywanie lub udostępnianie z osadzonymi edytowalnymi polami.

Naucz się edytować formularze PDF z przewodnikiem How-To IronPDF
Zobacz na GitHubie

Gotowy, aby rozpocząć?

Nuget Downloads 20,667,543Wersja:2026.7właśnie wydany

Key in blue circle

Uzyskaj natychmiast swój darmowy 30-dniowy Klucz Testowy.

Brak ograniczeń. 100% dostępności. Bez karty kredytowej.

bullet_checkedNie wymaga karty kredytowej ani tworzenia kontaBrak ograniczeń. 100% dostępności. Bez karty kredytowej.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Zarezerwuj swoje darmowe Demo na żywo
Booking Badge

Zaufane przez miliony inżynierów na całym świecie

Logotypy klientów Iron Software
Otrzymaj swoje Konsultacja Bez Zobowiązań
Wypełnij poniższy formularz lub wyślij e-mail na sales@ironsoftware.com
Twoje dane zawsze będą utrzymywane w tajemnicy.
Zaufane przez miliony inżynierów na całym świecie
Logotypy klientów Iron Software
Otrzymaj swój darmowy Klucz Próbny na 30 dni natychmiast.
Nie wymaga karty kredytowej ani tworzenia konta