PDF Forms. Manage via PHP

Manage Acroforms in PDF document using Aspose.PDF for PHP via Java Library

How to Manage PDF Forms Using PHP via Java Library

In order to add PDF Forms (Acroforms) in PDF file, we’ll use Aspose.PDF for PHP via Java API which is a feature-rich, powerful and easy-to-use document manipulation tool in php-java. Install Tomcat 9.0 version on any location, add Aspose.PDF.war, for more details check the GitHub page.

How to Create PDF Forms using PHP

To try the code in your environment, you need Aspose.PDF for PHP via Java.

  1. Load PDF in an instance of Document class.
  2. Access the Page via its index.
  3. Call the Form collection’s Add method.
  4. Create the form field you want to add.
  5. Save the PDF file.

Create PDF Forms in PDF - PHP

This sample code shows how to Create PDF Forms in PDF using PHP

// Open document
$colors = new Color();
$document = new Document($inputFile);
$page = $document->getPages()->get_Item(1);

// Create a field
$textBoxField = new TextBoxField($page, 
    new Rectangle(110, 300, 310, 320));
$textBoxField->setPartialName("textbox1");
$textBoxField->setValue("Some value in Text Box");

$border = new Border($textBoxField);
$border->setWidth(5);
$border->setDash(new Dash(1, 1));
$textBoxField->setBorder($border);
$textBoxField->setColor($colors->getGreen());

// Add field to the document
$document->getForm()->add($textBoxField, 1);

// Save modified PDF
$document->save($outputFile);
$document->close();