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");
NuGet 다운로드
PM > Install-Package IronPdf
PDF 양식

PDF 양식

IronPDF를 사용하면 일반 문서처럼 쉽게 편집 가능한 PDF 문서를 만들 수 있습니다. PdfForm 클래스는 PDF 문서 내에서 사용자가 편집할 수 있는 양식 필드의 집합입니다. PDF 렌더링에 이 클래스를 통합하면 양식이나 편집 가능한 문서를 만들 수 있습니다.

이 예제는 IronPDF에서 편집 가능한 PDF 양식을 만드는 방법을 보여줍니다.

편집 가능한 양식이 포함된 PDF는 단순히 문서 부분에 <form>, <input>, <textarea> 태그를 추가하여 HTML에서 생성할 수 있습니다.

PdfDocument.Form.FindFormField 메소드는 모든 양식 필드의 값을 읽고 쓰는 데 사용될 수 있습니다. 필드의 name 속성은 HTML에서 해당 필드에 부여됩니다.

PdfDocument.Form 객체는 두 가지 방식으로 사용할 수 있습니다:

  • 기본값 채우기: 이 방법은 Adobe Reader와 같은 PDF 뷰어에서 표시될 양식 필드의 기본 값을 설정하는 데 사용할 수 있습니다.
  • 사용자 입력 읽기: 사용자가 양식을 작성한 후, 양식 필드에 접근하여 데이터를 다시 애플리케이션에 읽어들일 수 있습니다.

위의 예제에서는 먼저 IronPdf 라이브러리를 가져오고 이름과 성을 입력하는 필드, 성별을 선택하는 라디오 버튼, 질환을 선택하는 체크박스가 포함된 간단한 양식의 HTML 구조를 정의합니다. ChromePdfRenderer를 사용하고 CreatePdfFormsFromHtml을 활성화하여 이 HTML 콘텐츠를 PDF 문서로 변환합니다.

렌더링된 PDF는 먼저 'BasicForm.pdf'로 저장됩니다. 그 후 PdfDocument.Form 객체를 사용하여 양식 필드에 접근하고 값을 조작합니다. 여기서 우리는 이름과 성 필드의 값을 설정합니다. 마지막으로, 채워진 문서는 'FilledForm.pdf'로 저장되어, 편집 가능한 필드가 내장된 상태로 저장하거나 공유할 수 있습니다.

IronPDF 사용법 가이드를 통해 PDF 양식 편집 방법을 배우세요
GitHub에서 보기

시작할 준비 되셨나요?

NuGet 다운로드 수 22,471,552버전:2026.11방금 출시