Formularze PDF
import {PdfDocument} from "@ironsoftware/ironpdf";

(async () => {
    // Define the HTML content with editable form fields
    const 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>
    `;

    // Configure render options
    const options = {
        createPdfFormsFromHtml: true,
    };

    // Render HTML content to a PDF with editable forms
    const pdf = await PdfDocument.fromHtml(formHtml, { renderOptions: options });

    // Save the new PDF
    await pdf.saveAs("formField.pdf");
})();
npm i @ironsoftware/ironpdf
Formularze PDF

Formularze PDF

HTML z polami formularzy może być także renderowane do PDF z zachowaniem informacji i funkcji pol formularzy. Tworzenie edytowalnego formularza PDF z zawartości HTML polega na zdefiniowaniu formularza HTML z różnymi polami wejściowymi, takimi jak pola tekstowe, przyciski radiowe i pola wyboru. Te elementy formularza pozwalają użytkownikom na wprowadzanie danych i dokonywanie wyborow.

Aby to osiągnąć, ustaw opcję createPdfFormsFromHtml na true. Ta opcja określa, że formularz HTML powinien być przekształcony w edytowalny formularz PDF.

Następnie, wyrenderuj zawartość HTML do dokumentu PDF za pomocą metody PdfDocument.fromHtml. Przekaż określone opcje renderowania jako parametr obiektu.

Na koniec wyeksportuj edytowalne pole formularza PDF jako nowy plik PDF o nazwie „formField.pdf” za pomocą metody saveAs.

Aby dowiedzieć się więcej o generowaniu formularzy PDF z zawartości HTML, odwiedź Stronę Produktu IronPDF po szczegółowe informacje i przykłady.

<a href="https://github.com/iron-software/IronPdfNode.Examples/tree/main/examples/form-data" class="code_content__related-link__doc-cta-link">Explore Code Examples for Creating PDF Forms from HTML</a>
HTML
Zobacz na GitHub

Gotowy, aby rozpocząć?

Wersja:2026.11właśnie wydane