
com.ironsoftware.ironpdf.form.FormManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ironpdf Show documentation
Show all versions of ironpdf Show documentation
IronPDF Java library offers an extensive compatibility range, making it a go-to solution for a wide array of developers. It fully supports JVM languages like Java, Scala, and Kotlin, making it incredibly versatile. This Java PDF library is also compatible with Java 8 and above, providing optimum performance across multiple platforms. It's been designed with a wide range of users in mind Here's a look at what it supports: JVM Languages: Java, Scala, Kotlin.Platforms: Java 8 and above.Operating Systems: Microsoft Windows, Linux, Docker, Azure, AWS.IDEs: Jetbrains IntelliJ IDEA, Eclipse. You can deploy IronPDF Java across various platforms, including Microsoft Windows, Linux, Docker, Azure, and AWS. It is also fully compatible with popular IDEs like Jetbrains IntelliJ IDEA and Eclipse, facilitating smooth project development and management. Your pom.xml file is essentially the backbone of your project when you're using Maven. It's here where you introduce new dependencies that you wish to include. To make IronPDF Java package a part of your Maven project, you simply need to add the following snippets to your pom.xml: Remember to replace '20xx.xx.xxxx' with the latest version of IronPDF. IronPDF Java simplifies the process of creating PDF files. Convert HTML files, HTML strings, or URLs directly to new PDF documents in a few lines of code. The variety of file formats it handles is vast, as it can even transform images into PDF documents and vice versa. Need to use base 64 encoding, base URLs, or custom file paths? No problem! IronPDF Java has got you coveredFor more detail about installing and using IronPDF Java. When you run your project for the first time post-integration, IronPDF's engine binaries will automatically be downloaded. The engine starts its journey when you call any IronPDF function for the first time and takes a breather when your application is either closed or enters an idle state. It is not an open source java PDF library but here's the best part - IronPDF Java is offering a 30-day free trial. So, why wait? Give it a go and boost your PDF operations today.
package com.ironsoftware.ironpdf.form;
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.edit.PageSelection;
import com.ironsoftware.ironpdf.font.FontTypes;
import com.ironsoftware.ironpdf.internal.staticapi.Form_Api;
import com.ironsoftware.ironpdf.internal.staticapi.InternalPdfDocument;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* Class used to read and write data to AcroForms in a {@link com.ironsoftware.ironpdf.PdfDocument}.
* See: {@link com.ironsoftware.ironpdf.PdfDocument#getForm()}
*/
public class FormManager {
private final InternalPdfDocument internalPdfDocument;
/**
* Please get FormManager by {@link PdfDocument#getForm()} instead.
*
* @param internalPdfDocument the internal pdf document
*/
public FormManager(InternalPdfDocument internalPdfDocument) {
this.internalPdfDocument = internalPdfDocument;
}
/**
* Flattens a document (make all form fields non-editable).
*/
public final void flatten() {
Form_Api.flattenPdfFrom(internalPdfDocument);
}
/**
* Flattens a document (make all form fields non-editable).
*
* @param pageSelection Selected page indexes. Default is all pages.
*/
public final void flatten(PageSelection pageSelection) {
Form_Api.flattenPdfFrom(internalPdfDocument, internalPdfDocument.getPageList(pageSelection));
}
/**
* Get a collection of the user-editable form fields within a PDF document
* @return FormFieldsSet
*/
public FormFieldsSet getFields() {
List checkBoxFields = new ArrayList<>();
List textFields = new ArrayList<>();
List comboBoxFields = new ArrayList<>();
List unknownFields = new ArrayList<>();
for (FormField anyField : Form_Api.getFields(
internalPdfDocument)) {
if (anyField instanceof CheckBoxField) {
checkBoxFields.add((CheckBoxField) anyField);
} else if (anyField instanceof TextField) {
textFields.add((TextField) anyField);
} else if (anyField instanceof ComboBoxField) {
comboBoxFields.add((ComboBoxField) anyField);
} else {
unknownFields.add(anyField);
}
}
return new FormFieldsSet(checkBoxFields, textFields, comboBoxFields, unknownFields);
}
/**
* Rename a {@link FormField}
*
* @param currentFieldName Current fully qualified field name
* @param newFieldName New partial field name Please use a fully qualified field name for
* CurrentFieldName, and a partial field name for NewFieldName
* @return New fully-qualified field name
*/
public String renameField(String currentFieldName, String newFieldName) {
return Form_Api.renameField(internalPdfDocument, currentFieldName,
newFieldName);
}
/**
* Set the string value of a {@link FormField}
*
* @param fieldName Fully qualified field name
* @param value New value
*/
public void setFieldValue(String fieldName, String value) {
Optional optionalFormField = this.getFields().getAllFields().stream().filter(f->f.getName().equalsIgnoreCase(fieldName)).findFirst();
if(optionalFormField.isPresent())
Form_Api.setFieldValue(internalPdfDocument, optionalFormField.get().getAnnotationIndex(),
value);
else
throw new RuntimeException(String.format("setFieldValue, not found field name: %s", fieldName));
}
/**
* Set the is read only value of a {@link FormField}
*
* @param fieldName Fully qualified field name
* @param value is read only
*/
public void setFieldReadOnly(String fieldName, boolean value) {
Optional optionalFormField = this.getFields().getAllFields().stream().filter(f->f.getName().equalsIgnoreCase(fieldName)).findFirst();
if(optionalFormField.isPresent())
Form_Api.setFormFieldIsReadOnly(internalPdfDocument, optionalFormField.get().getAnnotationIndex(),
value);
else
throw new RuntimeException(String.format("setFieldReadOnly, not found field name: %s", fieldName));
}
/**
* Set the font of a {@link TextField}
*
* @param textFieldName Fully qualified field name
* @param font New font
* @param fontSize New font size
*/
public void setTextFieldFont(String textFieldName, FontTypes font, int fontSize) {
Form_Api.setTextFieldFont(internalPdfDocument, textFieldName,
font, fontSize);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy