-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from datalogics-tsmith/raw-json-calls
PDFCLOUD-2821 Add upload + raw JSON Python samples
- Loading branch information
Showing
37 changed files
with
1,211 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Here you will find DotNET code examples to send calls to each of the individual endpoints supported by the pdfRest Cloud API service. | ||
|
||
Multipart Payload examples show how to send files and parameters directly to an endpoint for processing, using a multipart/form-data payload to separate files and parameters. | ||
|
||
JSON Payload examples show how to upload files with simple binary payloads and send streamlined, single part calls to processing endpoints using a JSON payload to specify resource IDs and parameters. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Here you will find Java code examples to send calls to each of the individual endpoints supported by the pdfRest Cloud API service. | ||
|
||
Multipart Payload examples show how to send files and parameters directly to an endpoint for processing, using a multipart/form-data payload to separate files and parameters. | ||
|
||
JSON Payload examples show how to upload files with simple binary payloads and send streamlined, single part calls to processing endpoints using a JSON payload to specify resource IDs and parameters. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Here you will find JavaScript code examples to send calls to each of the individual endpoints supported by the pdfRest Cloud API service. | ||
|
||
Multipart Payload examples show how to send files and parameters directly to an endpoint for processing, using a multipart/form-data payload to separate files and parameters. | ||
|
||
JSON Payload examples show how to upload files with simple binary payloads and send streamlined, single part calls to processing endpoints using a JSON payload to specify resource IDs and parameters. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Here you will find PHP code examples to send calls to each of the individual endpoints supported by the pdfRest Cloud API service. | ||
|
||
Multipart Payload examples show how to send files and parameters directly to an endpoint for processing, using a multipart/form-data payload to separate files and parameters. | ||
|
||
JSON Payload examples show how to upload files with simple binary payloads and send streamlined, single part calls to processing endpoints using a JSON payload to specify resource IDs and parameters. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
This directory contains examples of how to call each endpoint of the | ||
PdfRest API using Python. Please refer to https://pdfrest.com/documentation.html | ||
for accepted inputs, options, and other specifics about individual endpoints. | ||
|
||
#### How to run Python samples | ||
|
||
Using Python3: | ||
|
||
1. `cd 'Python/Endpoint Examples/JSON Payload/'` | ||
2. `python name-of-sample-program.py` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import requests | ||
import json | ||
|
||
with open('/path/to/file', 'rb') as f: | ||
upload_data = f.read() | ||
|
||
print("Uploading file...") | ||
upload_response = requests.post(url='https://api.pdfrest.com/upload', | ||
data=upload_data, | ||
headers={'Content-Type': 'application/octet-stream', 'Content-Filename': 'file.pdf', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
print("Upload response status code: " + str(upload_response.status_code)) | ||
|
||
if upload_response.ok: | ||
upload_response_json = upload_response.json() | ||
print(json.dumps(upload_response_json, indent = 2)) | ||
|
||
|
||
uploaded_id = upload_response_json['files'][0]['id'] | ||
bmp_data = { "id" : uploaded_id } | ||
print(json.dumps(bmp_data, indent = 2)) | ||
|
||
|
||
print("Processing file...") | ||
bmp_response = requests.post(url='https://api.pdfrest.com/bmp', | ||
data=json.dumps(bmp_data), | ||
headers={'Content-Type': 'application/json', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
|
||
|
||
print("Processing response status code: " + str(bmp_response.status_code)) | ||
if bmp_response.ok: | ||
bmp_response_json = bmp_response.json() | ||
print(json.dumps(bmp_response_json, indent = 2)) | ||
|
||
else: | ||
print(bmp_response.text) | ||
else: | ||
print(upload_response.text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import requests | ||
import json | ||
|
||
with open('/path/to/file', 'rb') as f: | ||
upload_data = f.read() | ||
|
||
print("Uploading file...") | ||
upload_response = requests.post(url='https://api.pdfrest.com/upload', | ||
data=upload_data, | ||
headers={'Content-Type': 'application/octet-stream', 'Content-Filename': 'file.pdf', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
print("Upload response status code: " + str(upload_response.status_code)) | ||
|
||
if upload_response.ok: | ||
upload_response_json = upload_response.json() | ||
print(json.dumps(upload_response_json, indent = 2)) | ||
|
||
|
||
uploaded_id = upload_response_json['files'][0]['id'] | ||
compress_data = { "id" : uploaded_id, "compression_level" : "low" } | ||
print(json.dumps(compress_data, indent = 2)) | ||
|
||
|
||
print("Processing file...") | ||
compress_response = requests.post(url='https://api.pdfrest.com/compressed-pdf', | ||
data=json.dumps(compress_data), | ||
headers={'Content-Type': 'application/json', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
|
||
|
||
print("Processing response status code: " + str(compress_response.status_code)) | ||
if compress_response.ok: | ||
compress_response_json = compress_response.json() | ||
print(json.dumps(compress_response_json, indent = 2)) | ||
|
||
else: | ||
print(compress_response.text) | ||
else: | ||
print(upload_response.text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import requests | ||
import json | ||
|
||
with open('/path/to/file', 'rb') as f: | ||
upload_data = f.read() | ||
|
||
print("Uploading file...") | ||
upload_response = requests.post(url='https://api.pdfrest.com/upload', | ||
data=upload_data, | ||
headers={'Content-Type': 'application/octet-stream', 'Content-Filename': 'file.pdf', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
print("Upload response status code: " + str(upload_response.status_code)) | ||
|
||
if upload_response.ok: | ||
upload_response_json = upload_response.json() | ||
print(json.dumps(upload_response_json, indent = 2)) | ||
|
||
|
||
uploaded_id = upload_response_json['files'][0]['id'] | ||
decrypt_data = { "id" : uploaded_id, 'current_open_password': 'password' } | ||
print(json.dumps(decrypt_data, indent = 2)) | ||
|
||
|
||
print("Processing file...") | ||
decrypt_response = requests.post(url='https://api.pdfrest.com/decrypted-pdf', | ||
data=json.dumps(decrypt_data), | ||
headers={'Content-Type': 'application/json', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
|
||
|
||
print("Processing response status code: " + str(decrypt_response.status_code)) | ||
if decrypt_response.ok: | ||
decrypt_response_json = decrypt_response.json() | ||
print(json.dumps(decrypt_response_json, indent = 2)) | ||
|
||
else: | ||
print(decrypt_response.text) | ||
else: | ||
print(upload_response.text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import requests | ||
import json | ||
|
||
with open('/path/to/file', 'rb') as f: | ||
upload_data = f.read() | ||
|
||
print("Uploading file...") | ||
upload_response = requests.post(url='https://api.pdfrest.com/upload', | ||
data=upload_data, | ||
headers={'Content-Type': 'application/octet-stream', 'Content-Filename': 'file.pdf', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
print("Upload response status code: " + str(upload_response.status_code)) | ||
|
||
if upload_response.ok: | ||
upload_response_json = upload_response.json() | ||
print(json.dumps(upload_response_json, indent = 2)) | ||
|
||
|
||
uploaded_id = upload_response_json['files'][0]['id'] | ||
encrypt_data = { "id" : uploaded_id, 'new_open_password': 'password' } | ||
print(json.dumps(encrypt_data, indent = 2)) | ||
|
||
print("Processing file...") | ||
encrypt_response = requests.post(url='https://api.pdfrest.com/encrypted-pdf', | ||
data=json.dumps(encrypt_data), | ||
headers={'Content-Type': 'application/json', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
|
||
|
||
print("Processing response status code: " + str(encrypt_response.status_code)) | ||
if encrypt_response.ok: | ||
encrypt_response_json = encrypt_response.json() | ||
print(json.dumps(encrypt_response_json, indent = 2)) | ||
|
||
else: | ||
print(encrypt_response.text) | ||
else: | ||
print(upload_response.text) |
39 changes: 39 additions & 0 deletions
39
Python/Endpoint Examples/JSON Payload/exported-form-data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import requests | ||
import json | ||
|
||
with open('/path/to/file', 'rb') as f: | ||
upload_data = f.read() | ||
|
||
print("Uploading file...") | ||
upload_response = requests.post(url='https://api.pdfrest.com/upload', | ||
data=upload_data, | ||
headers={'Content-Type': 'application/octet-stream', 'Content-Filename': 'file.pdf', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
print("Upload response status code: " + str(upload_response.status_code)) | ||
|
||
if upload_response.ok: | ||
upload_response_json = upload_response.json() | ||
print(json.dumps(upload_response_json, indent = 2)) | ||
|
||
|
||
uploaded_id = upload_response_json['files'][0]['id'] | ||
export_data = { "id" : uploaded_id, 'data_format': 'xml' } | ||
print(json.dumps(export_data, indent = 2)) | ||
|
||
|
||
print("Processing file...") | ||
export_response = requests.post(url='https://api.pdfrest.com/exported-form-data', | ||
data=json.dumps(export_data), | ||
headers={'Content-Type': 'application/json', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
|
||
|
||
print("Processing response status code: " + str(export_response.status_code)) | ||
if export_response.ok: | ||
export_response_json = export_response.json() | ||
print(json.dumps(export_response_json, indent = 2)) | ||
|
||
else: | ||
print(export_response.text) | ||
else: | ||
print(upload_response.text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import requests | ||
import json | ||
|
||
with open('/path/to/file', 'rb') as f: | ||
upload_data = f.read() | ||
|
||
print("Uploading file...") | ||
upload_response = requests.post(url='https://api.pdfrest.com/upload', | ||
data=upload_data, | ||
headers={'Content-Type': 'application/octet-stream', 'Content-Filename': 'file.pdf', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
print("Upload response status code: " + str(upload_response.status_code)) | ||
|
||
if upload_response.ok: | ||
upload_response_json = upload_response.json() | ||
print(json.dumps(upload_response_json, indent = 2)) | ||
|
||
|
||
uploaded_id = upload_response_json['files'][0]['id'] | ||
extract_data = { "id" : uploaded_id } | ||
print(json.dumps(extract_data, indent = 2)) | ||
|
||
|
||
print("Processing file...") | ||
extract_response = requests.post(url='https://api.pdfrest.com/extracted-text', | ||
data=json.dumps(extract_data), | ||
headers={'Content-Type': 'application/json', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
|
||
|
||
print("Processing response status code: " + str(extract_response.status_code)) | ||
if extract_response.ok: | ||
extract_response_json = extract_response.json() | ||
print(json.dumps(extract_response_json, indent = 2)) | ||
|
||
else: | ||
print(extract_response.text) | ||
else: | ||
print(upload_response.text) |
39 changes: 39 additions & 0 deletions
39
Python/Endpoint Examples/JSON Payload/flattened-annotations-pdf.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import requests | ||
import json | ||
|
||
with open('/path/to/file', 'rb') as f: | ||
upload_data = f.read() | ||
|
||
print("Uploading file...") | ||
upload_response = requests.post(url='https://api.pdfrest.com/upload', | ||
data=upload_data, | ||
headers={'Content-Type': 'application/octet-stream', 'Content-Filename': 'file.pdf', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
print("Upload response status code: " + str(upload_response.status_code)) | ||
|
||
if upload_response.ok: | ||
upload_response_json = upload_response.json() | ||
print(json.dumps(upload_response_json, indent = 2)) | ||
|
||
|
||
uploaded_id = upload_response_json['files'][0]['id'] | ||
flatten_data = { "id" : uploaded_id } | ||
print(json.dumps(flatten_data, indent = 2)) | ||
|
||
|
||
print("Processing file...") | ||
flatten_response = requests.post(url='https://api.pdfrest.com/flattened-annotations-pdf', | ||
data=json.dumps(flatten_data), | ||
headers={'Content-Type': 'application/json', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
|
||
|
||
print("Processing response status code: " + str(flatten_response.status_code)) | ||
if flatten_response.ok: | ||
flatten_response_json = flatten_response.json() | ||
print(json.dumps(flatten_response_json, indent = 2)) | ||
|
||
else: | ||
print(flatten_response.text) | ||
else: | ||
print(upload_response.text) |
39 changes: 39 additions & 0 deletions
39
Python/Endpoint Examples/JSON Payload/flattened-forms-pdf.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import requests | ||
import json | ||
|
||
with open('/path/to/file', 'rb') as f: | ||
upload_data = f.read() | ||
|
||
print("Uploading file...") | ||
upload_response = requests.post(url='https://api.pdfrest.com/upload', | ||
data=upload_data, | ||
headers={'Content-Type': 'application/octet-stream', 'Content-Filename': 'file.pdf', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
print("Upload response status code: " + str(upload_response.status_code)) | ||
|
||
if upload_response.ok: | ||
upload_response_json = upload_response.json() | ||
print(json.dumps(upload_response_json, indent = 2)) | ||
|
||
|
||
uploaded_id = upload_response_json['files'][0]['id'] | ||
flatten_data = { "id" : uploaded_id } | ||
print(json.dumps(flatten_data, indent = 2)) | ||
|
||
|
||
print("Processing file...") | ||
flatten_response = requests.post(url='https://api.pdfrest.com/flattened-forms-pdf', | ||
data=json.dumps(flatten_data), | ||
headers={'Content-Type': 'application/json', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
|
||
|
||
print("Processing response status code: " + str(flatten_response.status_code)) | ||
if flatten_response.ok: | ||
flatten_response_json = flatten_response.json() | ||
print(json.dumps(flatten_response_json, indent = 2)) | ||
|
||
else: | ||
print(flatten_response.text) | ||
else: | ||
print(upload_response.text) |
39 changes: 39 additions & 0 deletions
39
Python/Endpoint Examples/JSON Payload/flattened-layers-pdf.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import requests | ||
import json | ||
|
||
with open('/path/to/file', 'rb') as f: | ||
upload_data = f.read() | ||
|
||
print("Uploading file...") | ||
upload_response = requests.post(url='https://api.pdfrest.com/upload', | ||
data=upload_data, | ||
headers={'Content-Type': 'application/octet-stream', 'Content-Filename': 'file.pdf', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
print("Upload response status code: " + str(upload_response.status_code)) | ||
|
||
if upload_response.ok: | ||
upload_response_json = upload_response.json() | ||
print(json.dumps(upload_response_json, indent = 2)) | ||
|
||
|
||
uploaded_id = upload_response_json['files'][0]['id'] | ||
flatten_data = { "id" : uploaded_id } | ||
print(json.dumps(flatten_data, indent = 2)) | ||
|
||
|
||
print("Processing file...") | ||
flatten_response = requests.post(url='https://api.pdfrest.com/flattened-layers-pdf', | ||
data=json.dumps(flatten_data), | ||
headers={'Content-Type': 'application/json', "API-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}) | ||
|
||
|
||
|
||
print("Processing response status code: " + str(flatten_response.status_code)) | ||
if flatten_response.ok: | ||
flatten_response_json = flatten_response.json() | ||
print(json.dumps(flatten_response_json, indent = 2)) | ||
|
||
else: | ||
print(flatten_response.text) | ||
else: | ||
print(upload_response.text) |
Oops, something went wrong.