Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDFCLOUD-2821 Add upload + raw JSON Python samples #47

Merged
merged 8 commits into from
Oct 31, 2023
5 changes: 5 additions & 0 deletions DotNET/Endpoint Examples/README.md
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.
5 changes: 5 additions & 0 deletions Java/Endpoint Examples/README.md
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.
5 changes: 5 additions & 0 deletions JavaScript/Endpoint Examples/README.md
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.
5 changes: 5 additions & 0 deletions PHP/Endpoint Examples/README.md
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.
10 changes: 10 additions & 0 deletions Python/Endpoint Examples/JSON Payload/README.md
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`
39 changes: 39 additions & 0 deletions Python/Endpoint Examples/JSON Payload/bmp.py
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)
39 changes: 39 additions & 0 deletions Python/Endpoint Examples/JSON Payload/compressed-pdf.py
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)
39 changes: 39 additions & 0 deletions Python/Endpoint Examples/JSON Payload/decrypted-pdf.py
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)
38 changes: 38 additions & 0 deletions Python/Endpoint Examples/JSON Payload/encrypted-pdf.py
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 Python/Endpoint Examples/JSON Payload/exported-form-data.py
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)
39 changes: 39 additions & 0 deletions Python/Endpoint Examples/JSON Payload/extracted-text.py
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 Python/Endpoint Examples/JSON Payload/flattened-annotations-pdf.py
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 Python/Endpoint Examples/JSON Payload/flattened-forms-pdf.py
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 Python/Endpoint Examples/JSON Payload/flattened-layers-pdf.py
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)
Loading