Import XML Data to PDF Form using Python

XML to PDF

This article is a continuation of our earlier blog post on how to Export PDF to XML using Python, where we learned the steps on how to export PDF form data to XML format. In this article, we are going to use Aspose.PDF Cloud to import XML to PDF Acro Form using Python.

PDF Manipulation API

As the scope of this article is concentrated on Python language, so we need to first install Aspose.PDF Cloud SDK for Python which is a programming SDK developed around Aspose.PDF Cloud API. This SDK enables you to get all the PDF processing capabilities within your Python application. So, in order to get started with this SDK, the first step is its installation. The SDK is available for free download over PIP and GitHub repository. Simply execute the following command on the terminal/command prompt to install the latest version of SDK on the system.

pip install asposepdfcloud

Account Subscription on Cloud Dashboard

The next major step is a free subscription to our cloud services via Aspose.Cloud dashboard. The purpose of this subscription is to only allow authorized persons to access our file processing services. If you have GitHub or Google account, simply Sign Up or, click on the Create a new Account button and provide the required information. Now login to the dashboard using credentials and expand the Applications section from the dashboard and scroll down towards the Client Credentials section to see Client ID and Client Secret details.

Client credentials
Image 1:- Client Credentials on Aspose.Cloud Dashboard.

How to Import XML Data to PDF Form

Please follow the steps given below to import XML data to PDF form using Python SDK.

  • The first step is to create an instance of ApiClient class while providing Client ID Client Secret as arguments
  • Secondly, create an instance of PdfApi class which takes ApiClient object as input argument
  • Now call the put_import_fields_from_xml_in_storage(..) method to import data form XML file to PDF form and save resultant file to Cloud storage
Image 2:- Preview of XML data imported to PDF Form.

The sample files used in above example can be downloaded from followlink links

Import FDF to PDF Form using Python

In this section, we are going to discuss the steps and details on how to import data from the FDF file to PDF Form using Python SDK.

  • Create an instance of ApiClient class while providing Client ID Client Secret as arguments
  • Now, create an object of PdfApi class which takes ApiClient object as input argument
  • Finally, call the put_import_fields_from_fdf_in_storage(..) method to import data form FDF file to PDF form and save resultant file to Cloud storage

Import XFDF Data to PDF Form using Python

Please follow the instructions given below to import data from the XFDF file to PDF form and save the resultant file to cloud storage.

  • First of all, please create an instance of ApiClient class while providing Client ID Client Secret as arguments
  • Secondly, create an object of PdfApi class which takes ApiClient object as input argument
  • Now, call the put_import_fields_from_xfdf_in_storage(..) method to import data form XFDF file to PDF form and save resultant file to Cloud storage

How to Import XML Data to PDF Form using cURL Command

The cURL commands provide a convenient mechanism to access REST APIs through command prompt and these commands can be used on any platform. Since Aspose.PDF Cloud is developed as per REST architecture, so we can also use the cURL command to perform PDF processing operations. Similarly, we can also use the cURL commands to import data into PDF forms. But before performing any operation, we need to generate a JSON Web Token (JWT) based on your individual client credentials specified over Aspose.Cloud dashboard. It is mandatory because our APIs are only accessible to registered users. Please execute the following command to generate the JWT token.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bbf94a2c-6d7e-4020-b4d2-b9809741374e&client_secret=1c9379bb7d701c26cc87e741a29987bb" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Once the JWT access token has been generated, please execute the following cURL command to import XML data to PDF form and save the output in the same cloud storage.

curl -v -X PUT "https://api.aspose.cloud/v3.0/pdf/FormData.pdf/import/xml?xmlFilePath=FormDataExported.xml" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-d{}

Conclusion

In this article, we have explored the details on how to import data from XML, FDF, and XFDF to PDF forms. We have learned how to accomplish these requirements using Python code snippets as well as through cURL commands. We also recommend exploring the Developer Guide to learn about other exciting features offered by the API. Furthermore, the complete source code of Apsose.PDF Cloud SDK for Python has been made available for download over GitHub. In case you encounter any issues while using the API or you have any further queries, please feel free to contact us via the Free product support forum.

Related Articles

We also recommend visiting the following links to learn more about