Skip to content

Commit ed952aa

Browse files
authored
Merge pull request #1009 from helewrer3/main
Marketing Docs for Python SDK 4.2.0
2 parents 3095eef + ed3c059 commit ed952aa

File tree

3 files changed

+146
-2
lines changed

3 files changed

+146
-2
lines changed

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 3, 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)