Skip to content

Commit 040c67b

Browse files
authored
Merge pull request #1017 from AdobeDocs/main
Sync with main
2 parents 5bb1a00 + 9b43137 commit 040c67b

File tree

6 files changed

+152
-8
lines changed

6 files changed

+152
-8
lines changed

src/pages/overview/pdf-accessibility-auto-tag-api/gettingstarted.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,14 +637,14 @@ For security reasons you may wish to confirm the installer's authenticity. To do
637637
1. After downloading the package zip, run following command
638638

639639
```
640-
pip hash <download_dir>/pdfservices-sdk-4.1.1.tar.gz
640+
pip hash <download_dir>/pdfservices-sdk-4.2.0.tar.gz
641641
```
642642

643643
1. Above command will return the hash of downloaded package.
644644
2. Verify the hash matches the value published here.
645645

646646
```
647-
a7592acd8c93eac52e0d8eae24cf2b8eee331f8704172a7b91ab7891fac5585d
647+
378afa7d3b22683264a1817393932a649b98e4d4b3913816f839de240f7132d5
648648
```
649649

650650
###### To generate tagged PDF from the sample file

src/pages/overview/pdf-extract-api/gettingstarted.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,14 +637,14 @@ For security reasons you may wish to confirm the installer's authenticity. To do
637637
1. After downloading the package zip, run following command
638638

639639
```
640-
pip hash <download_dir>/pdfservices-sdk-4.1.1.tar.gz
640+
pip hash <download_dir>/pdfservices-sdk-4.2.0.tar.gz
641641
```
642642

643643
1. Above command will return the hash of downloaded package.
644644
2. Verify the hash matches the value published here.
645645

646646
```
647-
a7592acd8c93eac52e0d8eae24cf2b8eee331f8704172a7b91ab7891fac5585d
647+
378afa7d3b22683264a1817393932a649b98e4d4b3913816f839de240f7132d5
648648
```
649649

650650
###### To extract data from the sample PDF file

src/pages/overview/pdf-services-api/gettingstarted.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,14 +636,14 @@ For security reasons you may wish to confirm the installer's authenticity. To do
636636
1. After downloading the package zip, run following command
637637

638638
```
639-
pip hash <download_dir>/pdfservices-sdk-4.1.1.tar.gz
639+
pip hash <download_dir>/pdfservices-sdk-4.2.0.tar.gz
640640
```
641641

642642
2. Above command will return the hash of downloaded package.
643643
3. Verify the hash matches the value published here.
644644

645645
```
646-
a7592acd8c93eac52e0d8eae24cf2b8eee331f8704172a7b91ab7891fac5585d
646+
378afa7d3b22683264a1817393932a649b98e4d4b3913816f839de240f7132d5
647647
```
648648

649649
## Public API

src/pages/overview/pdf-services-api/howtos/export-pdf-form-data.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The sample below exports PDF form data and returns it as a JSON file.
3333

3434
Please refer to the [API usage guide](../api-usage.md) to understand how to use our APIs.
3535

36-
<CodeBlock slots="heading, code" repeat="2" languages="Java, REST API" />
36+
<CodeBlock slots="heading, code" repeat="3" languages="Java, Python, REST API" />
3737

3838
#### Java
3939

@@ -80,6 +80,68 @@ public class ExportPDFFormData {
8080
}
8181
```
8282

83+
#### Python
84+
85+
```python
86+
# Get the samples https://github.com/adobe/pdfservices-python-sdk-samples
87+
# Run the sample:
88+
# python src/exportpdfformdata/export_pdf_form_data.py
89+
90+
# Initialize the logger
91+
logging.basicConfig(level=logging.INFO)
92+
93+
class ExportPDFFormData:
94+
def __init__(self):
95+
try:
96+
file = open('../resources/exportPdfFormDataInput.pdf', 'rb')
97+
input_stream = file.read()
98+
file.close()
99+
100+
# Initial setup, create credentials instance
101+
credentials = ServicePrincipalCredentials(
102+
client_id=os.getenv('PDF_SERVICES_CLIENT_ID'),
103+
client_secret=os.getenv('PDF_SERVICES_CLIENT_SECRET')
104+
)
105+
106+
# Creates a PDF Services instance
107+
pdf_services = PDFServices(credentials=credentials)
108+
109+
# Creates an asset(s) from source file(s) and upload
110+
input_asset = pdf_services.upload(input_stream=input_stream,
111+
mime_type=PDFServicesMediaType.PDF)
112+
113+
# Creates a new job instance
114+
export_pdf_form_data_job = ExportPDFFormDataJob(input_asset=input_asset)
115+
116+
# Submit the job and gets the job result
117+
location = pdf_services.submit(export_pdf_form_data_job)
118+
pdf_services_response = pdf_services.get_job_result(location, ExportPDFFormDataResult)
119+
120+
# Get content from the resulting asset(s)
121+
result_asset = pdf_services_response.get_result().get_asset()
122+
stream_asset = pdf_services.get_content(result_asset)
123+
124+
# Creates an output stream and copy stream asset's content to it
125+
output_file_path = self.create_output_file_path()
126+
with open(output_file_path, "wb") as file:
127+
file.write(stream_asset.get_input_stream())
128+
129+
except (ServiceApiException, ServiceUsageException, SdkException) as e:
130+
logging.exception(f'Exception encountered while executing operation: {e}')
131+
132+
# Generates a string containing a directory structure and file name for the output file
133+
@staticmethod
134+
def create_output_file_path() -> str:
135+
now = datetime.now()
136+
time_stamp = now.strftime("%Y-%m-%dT%H-%M-%S")
137+
os.makedirs("../../output/ExportPDFFormData", exist_ok=True)
138+
return f"../../output/ExportPDFFormData/export{time_stamp}.json"
139+
140+
141+
if __name__ == "__main__":
142+
ExportPDFFormData()
143+
```
144+
83145
#### REST API
84146

85147
```javascript

src/pages/overview/pdf-services-api/howtos/import-pdf-form-data.md

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The sample below demonstrates how to import form data from a JSON into PDF and g
3333

3434
Please refer to the [API usage guide](../api-usage.md) to understand how to use our APIs.
3535

36-
<CodeBlock slots="heading, code" repeat="2" languages="Java, REST API" />
36+
<CodeBlock slots="heading, code" repeat="3" languages="Java, Python, REST API" />
3737

3838
#### Java
3939

@@ -95,6 +95,84 @@ public class ImportPdfFormData {
9595
}
9696
```
9797

98+
#### Python
99+
100+
```python
101+
# Get the samples https://github.com/adobe/pdfservices-python-sdk-samples
102+
# Run the sample:
103+
# python src/exportpdfformdata/export_pdf_form_data.py
104+
105+
# Initialize the logger
106+
logging.basicConfig(level=logging.INFO)
107+
108+
class ImportPDFFormData:
109+
def __init__(self):
110+
try:
111+
file = open('../resources/importPdfFormDataInput.pdf', 'rb')
112+
input_stream = file.read()
113+
file.close()
114+
115+
# Initial setup, create credentials instance
116+
credentials = ServicePrincipalCredentials(
117+
client_id=os.getenv('PDF_SERVICES_CLIENT_ID'),
118+
client_secret=os.getenv('PDF_SERVICES_CLIENT_SECRET')
119+
)
120+
121+
# Creates a PDF Services instance
122+
pdf_services = PDFServices(credentials=credentials)
123+
124+
# Creates an asset(s) from source file(s) and upload
125+
input_asset = pdf_services.upload(input_stream=input_stream,
126+
mime_type=PDFServicesMediaType.PDF)
127+
128+
# Form data to be imported
129+
form_data = {
130+
"option_two": "Yes",
131+
"option_one": "Yes",
132+
"name": "garvit",
133+
"option_three": "Off",
134+
"age": "24",
135+
"favorite_movie": "Star Wars Again",
136+
}
137+
138+
# Create parameters for the job
139+
import_pdf_form_data_params = ImportPDFFormDataParams(json_form_fields_data=form_data)
140+
141+
# Creates a new job instance
142+
import_pdf_form_data_job = ImportPDFFormDataJob(input_asset=input_asset)
143+
144+
# Set the parameters for the job
145+
import_pdf_form_data_job.set_params(import_pdf_form_data_params)
146+
147+
# Submit the job and gets the job result
148+
location = pdf_services.submit(import_pdf_form_data_job)
149+
pdf_services_response = pdf_services.get_job_result(location, ImportPDFFormDataResult)
150+
151+
# Get content from the resulting asset(s)
152+
result_asset = pdf_services_response.get_result().get_asset()
153+
stream_asset = pdf_services.get_content(result_asset)
154+
155+
# Creates an output stream and copy stream asset's content to it
156+
output_file_path = self.create_output_file_path()
157+
with open(output_file_path, "wb") as file:
158+
file.write(stream_asset.get_input_stream())
159+
160+
except (ServiceApiException, ServiceUsageException, SdkException) as e:
161+
logging.exception(f'Exception encountered while executing operation: {e}')
162+
163+
# Generates a string containing a directory structure and file name for the output file
164+
@staticmethod
165+
def create_output_file_path() -> str:
166+
now = datetime.now()
167+
time_stamp = now.strftime("%Y-%m-%dT%H-%M-%S")
168+
os.makedirs("../../output/ImportPDFFormData", exist_ok=True)
169+
return f"../../output/ImportPDFFormData/import{time_stamp}.pdf"
170+
171+
172+
if __name__ == "__main__":
173+
ImportPDFFormData()
174+
```
175+
98176
#### REST API
99177

100178
```javascript

src/pages/overview/releasenotes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ Upgrading to the latest SDK should not break existing applications.
180180

181181
## Change history
182182

183+
### July 10, 2025; Python SDK 4.2.0 Release
184+
185+
- 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.
186+
183187
### May 22, 2025; .NET SDK 4.3.0 Release
184188

185189
- 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.

0 commit comments

Comments
 (0)