Create PDF Forms via PHP

Create acroforms in PDF programmatically using Aspose.PDF for PHP via Java Library

How to create PDF forms using PHP

In order to create 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 AcroForm in PDF 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. Create a field.
  3. Create decorations (like Border).
  4. Add field to the document and save modified PDF

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();