diff --git a/src/pages/overview/pdf-accessibility-auto-tag-api/gettingstarted.md b/src/pages/overview/pdf-accessibility-auto-tag-api/gettingstarted.md index 0578dccfc..810e79e97 100644 --- a/src/pages/overview/pdf-accessibility-auto-tag-api/gettingstarted.md +++ b/src/pages/overview/pdf-accessibility-auto-tag-api/gettingstarted.md @@ -637,14 +637,14 @@ For security reasons you may wish to confirm the installer's authenticity. To do 1. After downloading the package zip, run following command ``` -pip hash /pdfservices-sdk-4.1.1.tar.gz +pip hash /pdfservices-sdk-4.2.0.tar.gz ``` 1. Above command will return the hash of downloaded package. 2. Verify the hash matches the value published here. ``` -a7592acd8c93eac52e0d8eae24cf2b8eee331f8704172a7b91ab7891fac5585d +378afa7d3b22683264a1817393932a649b98e4d4b3913816f839de240f7132d5 ``` ###### To generate tagged PDF from the sample file diff --git a/src/pages/overview/pdf-extract-api/gettingstarted.md b/src/pages/overview/pdf-extract-api/gettingstarted.md index 0fdc53ecf..47887b8d0 100644 --- a/src/pages/overview/pdf-extract-api/gettingstarted.md +++ b/src/pages/overview/pdf-extract-api/gettingstarted.md @@ -637,14 +637,14 @@ For security reasons you may wish to confirm the installer's authenticity. To do 1. After downloading the package zip, run following command ``` -pip hash /pdfservices-sdk-4.1.1.tar.gz +pip hash /pdfservices-sdk-4.2.0.tar.gz ``` 1. Above command will return the hash of downloaded package. 2. Verify the hash matches the value published here. ``` -a7592acd8c93eac52e0d8eae24cf2b8eee331f8704172a7b91ab7891fac5585d +378afa7d3b22683264a1817393932a649b98e4d4b3913816f839de240f7132d5 ``` ###### To extract data from the sample PDF file diff --git a/src/pages/overview/pdf-services-api/gettingstarted.md b/src/pages/overview/pdf-services-api/gettingstarted.md index 99224d09e..45d10c206 100644 --- a/src/pages/overview/pdf-services-api/gettingstarted.md +++ b/src/pages/overview/pdf-services-api/gettingstarted.md @@ -636,14 +636,14 @@ For security reasons you may wish to confirm the installer's authenticity. To do 1. After downloading the package zip, run following command ``` -pip hash /pdfservices-sdk-4.1.1.tar.gz +pip hash /pdfservices-sdk-4.2.0.tar.gz ``` 2. Above command will return the hash of downloaded package. 3. Verify the hash matches the value published here. ``` -a7592acd8c93eac52e0d8eae24cf2b8eee331f8704172a7b91ab7891fac5585d +378afa7d3b22683264a1817393932a649b98e4d4b3913816f839de240f7132d5 ``` ## Public API diff --git a/src/pages/overview/pdf-services-api/howtos/export-pdf-form-data.md b/src/pages/overview/pdf-services-api/howtos/export-pdf-form-data.md index 187e0f415..64ae33ab5 100644 --- a/src/pages/overview/pdf-services-api/howtos/export-pdf-form-data.md +++ b/src/pages/overview/pdf-services-api/howtos/export-pdf-form-data.md @@ -33,7 +33,7 @@ The sample below exports PDF form data and returns it as a JSON file. Please refer to the [API usage guide](../api-usage.md) to understand how to use our APIs. - + #### Java @@ -80,6 +80,68 @@ public class ExportPDFFormData { } ``` +#### Python + +```python +# Get the samples https://github.com/adobe/pdfservices-python-sdk-samples +# Run the sample: +# python src/exportpdfformdata/export_pdf_form_data.py + +# Initialize the logger +logging.basicConfig(level=logging.INFO) + +class ExportPDFFormData: + def __init__(self): + try: + file = open('../resources/exportPdfFormDataInput.pdf', 'rb') + input_stream = file.read() + file.close() + + # Initial setup, create credentials instance + credentials = ServicePrincipalCredentials( + client_id=os.getenv('PDF_SERVICES_CLIENT_ID'), + client_secret=os.getenv('PDF_SERVICES_CLIENT_SECRET') + ) + + # Creates a PDF Services instance + pdf_services = PDFServices(credentials=credentials) + + # Creates an asset(s) from source file(s) and upload + input_asset = pdf_services.upload(input_stream=input_stream, + mime_type=PDFServicesMediaType.PDF) + + # Creates a new job instance + export_pdf_form_data_job = ExportPDFFormDataJob(input_asset=input_asset) + + # Submit the job and gets the job result + location = pdf_services.submit(export_pdf_form_data_job) + pdf_services_response = pdf_services.get_job_result(location, ExportPDFFormDataResult) + + # Get content from the resulting asset(s) + result_asset = pdf_services_response.get_result().get_asset() + stream_asset = pdf_services.get_content(result_asset) + + # Creates an output stream and copy stream asset's content to it + output_file_path = self.create_output_file_path() + with open(output_file_path, "wb") as file: + file.write(stream_asset.get_input_stream()) + + except (ServiceApiException, ServiceUsageException, SdkException) as e: + logging.exception(f'Exception encountered while executing operation: {e}') + + # Generates a string containing a directory structure and file name for the output file + @staticmethod + def create_output_file_path() -> str: + now = datetime.now() + time_stamp = now.strftime("%Y-%m-%dT%H-%M-%S") + os.makedirs("../../output/ExportPDFFormData", exist_ok=True) + return f"../../output/ExportPDFFormData/export{time_stamp}.json" + + +if __name__ == "__main__": + ExportPDFFormData() +``` + #### REST API ```javascript diff --git a/src/pages/overview/pdf-services-api/howtos/import-pdf-form-data.md b/src/pages/overview/pdf-services-api/howtos/import-pdf-form-data.md index 049317ae7..867cc4f94 100644 --- a/src/pages/overview/pdf-services-api/howtos/import-pdf-form-data.md +++ b/src/pages/overview/pdf-services-api/howtos/import-pdf-form-data.md @@ -33,7 +33,7 @@ The sample below demonstrates how to import form data from a JSON into PDF and g Please refer to the [API usage guide](../api-usage.md) to understand how to use our APIs. - + #### Java @@ -95,6 +95,84 @@ public class ImportPdfFormData { } ``` +#### Python + +```python +# Get the samples https://github.com/adobe/pdfservices-python-sdk-samples +# Run the sample: +# python src/exportpdfformdata/export_pdf_form_data.py + +# Initialize the logger +logging.basicConfig(level=logging.INFO) + +class ImportPDFFormData: + def __init__(self): + try: + file = open('../resources/importPdfFormDataInput.pdf', 'rb') + input_stream = file.read() + file.close() + + # Initial setup, create credentials instance + credentials = ServicePrincipalCredentials( + client_id=os.getenv('PDF_SERVICES_CLIENT_ID'), + client_secret=os.getenv('PDF_SERVICES_CLIENT_SECRET') + ) + + # Creates a PDF Services instance + pdf_services = PDFServices(credentials=credentials) + + # Creates an asset(s) from source file(s) and upload + input_asset = pdf_services.upload(input_stream=input_stream, + mime_type=PDFServicesMediaType.PDF) + + # Form data to be imported + form_data = { + "option_two": "Yes", + "option_one": "Yes", + "name": "garvit", + "option_three": "Off", + "age": "24", + "favorite_movie": "Star Wars Again", + } + + # Create parameters for the job + import_pdf_form_data_params = ImportPDFFormDataParams(json_form_fields_data=form_data) + + # Creates a new job instance + import_pdf_form_data_job = ImportPDFFormDataJob(input_asset=input_asset) + + # Set the parameters for the job + import_pdf_form_data_job.set_params(import_pdf_form_data_params) + + # Submit the job and gets the job result + location = pdf_services.submit(import_pdf_form_data_job) + pdf_services_response = pdf_services.get_job_result(location, ImportPDFFormDataResult) + + # Get content from the resulting asset(s) + result_asset = pdf_services_response.get_result().get_asset() + stream_asset = pdf_services.get_content(result_asset) + + # Creates an output stream and copy stream asset's content to it + output_file_path = self.create_output_file_path() + with open(output_file_path, "wb") as file: + file.write(stream_asset.get_input_stream()) + + except (ServiceApiException, ServiceUsageException, SdkException) as e: + logging.exception(f'Exception encountered while executing operation: {e}') + + # Generates a string containing a directory structure and file name for the output file + @staticmethod + def create_output_file_path() -> str: + now = datetime.now() + time_stamp = now.strftime("%Y-%m-%dT%H-%M-%S") + os.makedirs("../../output/ImportPDFFormData", exist_ok=True) + return f"../../output/ImportPDFFormData/import{time_stamp}.pdf" + + +if __name__ == "__main__": + ImportPDFFormData() +``` + #### REST API ```javascript diff --git a/src/pages/overview/releasenotes.md b/src/pages/overview/releasenotes.md index 487e7b446..e9f51e363 100644 --- a/src/pages/overview/releasenotes.md +++ b/src/pages/overview/releasenotes.md @@ -180,6 +180,10 @@ Upgrading to the latest SDK should not break existing applications. ## Change history +### July 10, 2025; Python SDK 4.2.0 Release + +- Added support for [Export PDF Form Data](../pdf-services-api/howtos/export-pdf-form-data/) and [Import PDF Form Data](../pdf-services-api/howtos/import-pdf-form-data/) operations in PDF Services Python SDK, enabling users to extract and populate form Data. + ### May 22, 2025; .NET SDK 4.3.0 Release - Added support for [Export PDF Form Data](../pdf-services-api/howtos/export-pdf-form-data/) and [Import PDF Form Data](../pdf-services-api/howtos/import-pdf-form-data/) operations in PDF Services .NET SDK, enabling users to extract and populate form Data.