Update PDF Forms in PHP SDK
Update all of the form fields from a PDF Document using PHP Cloud SDK
Get StartedHow to update an AcroForms via PHP SDK
The provided PHP code is designed to update form fields in a PDF document using the Aspose PDF Cloud API. It imports necessary modules, reads a local PDF file, uploads it to the cloud, and then updates specific fields in the PDF. The function updateFormFields encapsulates the entire process, handling both file operations and API interactions. It also includes error handling to manage potential issues during file reading and API requests.
In order to update an AcroForm to PDF, we’ll use Aspose.PDF Cloud PHP SDK. This Cloud SDK assists PHP programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using PHP programming language via Aspose.PDF REST API. Simply create an account at Aspose for Cloud and get your application information. Once you have the App SID & key, you are ready to give the Aspose.PDF Cloud PHP SDK.
Package Manager Console Command
composer install
Steps to update AcroForms via Cloud PHP
Aspose.PDF Cloud developers can easily load & update acroforms in PDF in just a few lines of code.
Reads PDF file from local path.
Upload the PDF file to the Aspose.PDF Cloud storage.
Creates a new form field with the name “EMail” and sets its value to “aspose-pdf-cloud@example.com”.
Updates the form fields in the PDF file on the Aspose.PDF Cloud storage.
Download the result if needed it
Download the result if needed it
This sample code shows updating an AcroForms in PDF documents using PHP
<?php
require_once 'vendor/autoload.php';
use Aspose\PDF\Api\PdfApi;
use Aspose\PDF\Model\Field;
use Aspose\PDF\Model\Fields;
use Aspose\PDF\Model\FieldType;
function updateFormField() {
$LOCAL_FILE_NAME = "C:\\Samples\\sample.pdf";
$STORAGE_FILE_NAME = "sample.pdf";
$RESULT_FILE_NAME = "output_sample.pdf";
$FIELD_NAME = "Signature_1";
// Load credentials from JSON file
$credentials = json_decode(file_get_contents('credentials.json'), true);
$pdfApi = new PdfApi($credentials['id'], $credentials['key']);
try {
// Load Pdf file
$fileData = file_get_contents($LOCAL_FILE_NAME);
$uploadResult = $pdfApi->uploadFile($STORAGE_FILE_NAME, $fileData);
echo $uploadResult->getResponseText() . PHP_EOL;
} catch (Exception $e) {
echo 'Error uploading file: ' . $e->getMessage() . PHP_EOL;
}
// Create Text form field object
$field = new Field();
$field->setName("EMail");
$field->setType(FieldType::TEXT);
$field->setValues(['aspose-pdf-cloud@example.com']);
// Create Form Fileds object
$fields = new Fields();
$fields->setList([$field]);
try {
// Update Form fields for PDF in storage
$response = $pdfApi->putUpdateFields($STORAGE_FILE_NAME, $fields);
echo $response->getStatus() . PHP_EOL;
// Download changed PDF file
$downloadRes = $pdfApi->downloadFile($STORAGE_FILE_NAME);
file_put_contents($RESULT_FILE_NAME, $downloadRes->getContents());
} catch (Exception $e) {
echo 'Error processing PDF: ' . $e->getMessage() . PHP_EOL;
}
}
updateFormField();
Work with the AcroForms via PHP SDK
Updating AcroForms in a PDF involves modifying or enhancing existing interactive form fields. Improve field alignment, add tooltips, or adjust tab orders to make the form more intuitive and easier to use. Include additional fields such as checkboxes, dropdowns, or digital signature areas to accommodate new data collection needs. Update AcroForms to comply with accessibility standards, such as adding labels or improving compatibility with assistive technologies. Update AcroForms to ensure compatibility with modern devices, browsers, or software tools. Update the AcroForms into PDF documents with Aspose.PDF Cloud PHP SDK.
With our PHP library you can
- Add PDF document’s header & footer in text or image format.
- Add tables & stamps (text or image) to PDF documents.
- Append multiple PDF documents to an existing file.
- Work with PDF attachments, annotations, & form fields.
- Apply encryption or decryption to PDF documents & set a password.
- Delete all stamps & tables from a page or entire PDF document.
- Delete a specific stamp or table from the PDF document by its ID.
- Replace single or multiple instances of text on a PDF page or from the entire document.
- Extensive support for converting PDF documents to various other file formats.
- Extract various elements of PDF files & make PDF documents optimized.
- You can try out our free App to update the AcroForms into PDF files online and test the functionality.
- Learning Resources
- Documentation
- Source Code
- API References
- Product Support
- Free Support
- Paid Support
- Blog
- Why Aspose.PDF Cloud for PHP?
- Customers List
- Security