How to create an AcroForm via Python SDK
In order to create an AcroForm to PDF, we’ll use Aspose.PDF Cloud Python SDK. This Cloud SDK assists Python programmers in developing cloud-based PDF creator, annotator, editor, converter and acroform apps using Python 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 Python SDK.
Installation from Github
pip install git+https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-python.git
Package Manager Console Command
pip install asposepdfcloud
Steps to create AcroForms via Python
Aspose.PDF Cloud developers can easily load & create acroforms in PDF in just a few lines of code.
- Uploads the PDF file to the Aspose.PDF Cloud service.
- Creates a new text box field with the necessary properties
- Adds the text box field to the PDF file stored in the Aspose.PDF Cloud service.
- Download the result if needed it
This sample code shows creating an AcroForms in PDF documents using Python
import os
import logging
from pathlib import Path
from asposepdfcloud import PdfApi, TextBoxField, Rectangle, Border, Dash
# Configure logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
class PdfAcroforms:
def __init__():
"""Initialize the API client."""
credentials_file = Path(r"..\credentials.json")
with credentials_file.open("r", encoding="utf-8") as file:
credentials = json.load(file)
api_key, app_id = credentials.get("key"), credentials.get("id")
self.pdf_api = PdfApi(ApiClient(api_key, app_id))
def addField(self, documentName: str, outputDocumentName: str, localFolder: Path, remoteFolder: str):
""" Upload a local fileName to the Aspose Cloud server. """
file_path = localFolder / documentName
self.pdf_api.upload_file(os.path.join(remoteFolder, fileName), file_path)
textBox = TextBoxField(
page_index = 1,
partial_name = "EMail",
rect = Rectangle(llx=100, lly=100, urx=180, ury=120),
value = "aspose-pdf-cloud@example.com",
border = Border(
width=5,
dash=Dash(on=1, off=1)
)
)
try:
response = self.pdfApi.put_text_box_field(documentName, "EMail", textBox, folder=remoteFolder)
if response.code == 200:
logging.info("PdfAcroformsAdd(): Form filed 'Email' successfully added to the page #1.")
"""Download the processed PDF document from the Aspose Cloud server."""
temp_file = self.pdf_api.download_file(str(remoteFolder) + '/' + documentName)
local_path = localFolder / outputDocumentName
shutil.move(temp_file, str(local_path))
else:
logging.error(f"PdfAcroformsAdd(): Failed to add filed 'Email' to the page #1. Response code: {response.code}")
except Exception as e:
logging.error(f"PdfAcroforms(): Error while adding form field: {e}")
Work with the AcroForms via Python SDK
AcroForms allows users to interact directly with the PDF by filling out fields, selecting options, or clicking buttons, making the document more dynamic. Interactive forms enable efficient data collection, reducing the need for manual data entry or external tools. This is ideal for surveys, registrations, and application processes. Users can fill in forms electronically without printing, scanning, or using other tools, saving time and effort. Including AcroForms in documents creates a polished and modern presentation, reflecting professionalism and attention to detail. Add the AcroForms into PDF documents with Aspose.PDF Cloud Python SDK.
With our Python 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 add 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 Python?
- Customers List
- Security