import com.ironsoftware.ironpdf.License;import com.ironsoftware.ironpdf.PdfDocument;// Set license key before any rendering callLicense.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");// HTML form with a text field and submit buttonString formHtml = "<h2>Registration Form</h2>" + "<form>" + "<label>Name: <input type='text' name='fullname' placeholder='Enter name'></label><br>" + "<button type='submit'>Submit</button>" + "</form>";// Render HTML to PDF — form fields are preservedPdfDocument pdf = PdfDocument.renderHtmlAsPdf(formHtml);pdf.saveAs("registration-form.pdf");
import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
// Set license key before any rendering call
License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");
// HTML form with a text field and submit button
String formHtml = "<h2>Registration Form</h2>" +
"<form>" +
"<label>Name: <input type='text' name='fullname' placeholder='Enter name'></label><br>" +
"<button type='submit'>Submit</button>" +
"</form>";
// Render HTML to PDF — form fields are preserved
PdfDocument pdf = PdfDocument.renderHtmlAsPdf(formHtml);
pdf.saveAs("registration-form.pdf");
import com.ironsoftware.ironpdf.License;import com.ironsoftware.ironpdf.PdfDocument;// Set the license key for IronPDFLicense.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");// HTML with single-line inputs and a multi-line textareaString htmlContent = """<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> Address: <br> <textarea name='address' rows='4' cols='50'></textarea> </form> </body></html>""";// Render HTML — both <input> and <textarea> become interactive PDF fieldsPdfDocument pdfDoc = PdfDocument.renderHtmlAsPdf(htmlContent);// Save the documentpdfDoc.saveAs("textAreaAndInputForm.pdf");
import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
// Set the license key for IronPDF
License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");
// HTML with single-line inputs and a multi-line textarea
String htmlContent = """
<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>
Address: <br> <textarea name='address' rows='4' cols='50'></textarea>
</form>
</body>
</html>
""";
// Render HTML — both <input> and <textarea> become interactive PDF fields
PdfDocument pdfDoc = PdfDocument.renderHtmlAsPdf(htmlContent);
// Save the document
pdfDoc.saveAs("textAreaAndInputForm.pdf");
コンボボックスフィールドは、<option>要素によって定義されたオプションの固定リストからユーザーが選択することを許可します。 オプションに<optgroup>でグループ化し、CSSを使用してドロップダウンの外観を文書デザインに合わせることができます。 name属性は、結果として得られるPDFのフィールド名になり、フォームデータの抽出を簡単にします。 PDF AcroFormフィールドが選択データをどのように保管するかについては、Apache PDFBoxプロジェクトを参照してください。他のツールでフォームを処理する必要がある場合。
import com.ironsoftware.ironpdf.License;import com.ironsoftware.ironpdf.PdfDocument;// Set the license key for IronPDFLicense.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");// HTML with a checkbox and a select dropdownString htmlContent = """<html> <body> <h2>Editable PDF Form</h2> <h3>Task Completed</h3> <label> <input type='checkbox' id='taskCompleted' name='taskCompleted'> Mark task as completed </label> <h3>Select Priority</h3> <label for='priority'>Choose priority level:</label> <select id='priority' name='priority'> <option value='high'>High</option> <option value='medium' selected>Medium</option> <option value='low'>Low</option> </select> </body></html>""";// Render HTML — checkbox and combobox fields are preserved in the PDFPdfDocument pdfDoc = PdfDocument.renderHtmlAsPdf(htmlContent);// Save the documentpdfDoc.saveAs("checkboxAndComboboxForm.pdf");
import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
// Set the license key for IronPDF
License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");
// HTML with a checkbox and a select dropdown
String htmlContent = """
<html>
<body>
<h2>Editable PDF Form</h2>
<h3>Task Completed</h3>
<label>
<input type='checkbox' id='taskCompleted' name='taskCompleted'> Mark task as completed
</label>
<h3>Select Priority</h3>
<label for='priority'>Choose priority level:</label>
<select id='priority' name='priority'>
<option value='high'>High</option>
<option value='medium' selected>Medium</option>
<option value='low'>Low</option>
</select>
</body>
</html>
""";
// Render HTML — checkbox and combobox fields are preserved in the PDF
PdfDocument pdfDoc = PdfDocument.renderHtmlAsPdf(htmlContent);
// Save the document
pdfDoc.saveAs("checkboxAndComboboxForm.pdf");
import com.ironsoftware.ironpdf.License;import com.ironsoftware.ironpdf.PdfDocument;// Set the license key for IronPDFLicense.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");// HTML with a radio button group — all three share name='traveltype'String htmlContent = """<html> <body> <h2>Editable PDF Form</h2> Choose your preferred travel type: <br> <input type='radio' name='traveltype' value='Bike'> Bike <br> <input type='radio' name='traveltype' value='Car'> Car <br> <input type='radio' name='traveltype' value='Airplane'> Airplane </body></html>""";// Render HTML — all three radio inputs become one grouped field in the PDFPdfDocument pdfDoc = PdfDocument.renderHtmlAsPdf(htmlContent);// Save the documentpdfDoc.saveAs("radioButtonForm.pdf");
import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
// Set the license key for IronPDF
License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");
// HTML with a radio button group — all three share name='traveltype'
String htmlContent = """
<html>
<body>
<h2>Editable PDF Form</h2>
Choose your preferred travel type: <br>
<input type='radio' name='traveltype' value='Bike'> Bike <br>
<input type='radio' name='traveltype' value='Car'> Car <br>
<input type='radio' name='traveltype' value='Airplane'> Airplane
</body>
</html>
""";
// Render HTML — all three radio inputs become one grouped field in the PDF
PdfDocument pdfDoc = PdfDocument.renderHtmlAsPdf(htmlContent);
// Save the document
pdfDoc.saveAs("radioButtonForm.pdf");
IronPDF for Java は、標準の HTML から PDF フォームを作成します。 <input>、 <textarea>、または <select> 要素を含む HTML 文字列を書き、 PdfDocument.renderHtmlAsPdf() に渡し、結果を保存します。各名前付きフィールドは、出力 PDF 内でインタラクティブな AcroForm フィールドになります。
はい。入力済みのPDFを PdfDocument.fromFile() でロードし、その後 getForm().getFields() を呼び出して、すべてのAcroFormフィールドを反復処理して現在の値を読み取ります。フィールド名は、元のHTMLで設定した name 属性に対応します。
What are some best practices for creating PDF forms using IronPDF?
Best practices include assigning `name` attributes to every form element, testing forms on multiple PDF viewers, using HTML5 validation attributes, and securely managing your license key for deployments.
How does IronPDF ensure consistency in PDF form rendering?
IronPDF's rendering engine comes bundled with the library, ensuring that forms render identically across all environments, including development machines, CI servers, and cloud deployments.
What can IronPDF's advanced rendering settings control?
Advanced rendering settings in IronPDF allow you to control paper size, margins, headers, and footers to match specific document requirements, enhancing flexibility in PDF creation.
What is a common issue observed when converting forms with IronPDF and how can it be resolved?
A common issue is losing interactivity in the PDF form due to missing `name` attributes on elements. Always include a `name` so IronPDF can correctly identify each form field in the resulting PDF.