Skip to content

Commit

Permalink
Merge pull request #48 from datalogics-tsmith/add-python-extensions
Browse files Browse the repository at this point in the history
PDFCLOUD-2652 Add filename extensions to the python samples
  • Loading branch information
datalogics-dliang authored Oct 30, 2023
2 parents d86c8f3 + 5b87586 commit 1361d8e
Show file tree
Hide file tree
Showing 28 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Python/Endpoint Examples/Multipart Payload/bmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# This sample takes in a PDF and converts all pages into grayscale BMP files.
mp_encoder_bmp = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'pages': '1-last',
'resolution': '600',
'color_model': 'gray',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# We have preset 'high', 'medium', and 'low' compression levels available for use. These preset levels do not require the 'profile' parameter.
mp_encoder_compressedPdf = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'output' : 'example_compressedPdf_out',
'compression_level': 'medium',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# This sample demonstrates decryption of a PDF with the password 'password'.
mp_encoder_decryptedPdf = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'output' : 'example_decryptedPdf_out',
'current_open_password': 'password',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# This sample demonstrates encryption of a PDF with the password 'password'.
mp_encoder_encryptedPdf = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'output' : 'example_encryptedPdf_out',
'new_open_password': 'password',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# This sample demonstrates encryption of a PDF with the password 'password'.
mp_encoder_exportedFormData = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'output' : 'example_exportedFormData_out',
'data_format': 'xml',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#This sample demonstrates extracting the text from a document to return as JSON
mp_encoder_extractText = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

mp_encoder_flattenedPDF = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'output' : 'example_out'
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

mp_encoder_flattenedPDF = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'output' : 'example_out'
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

mp_encoder_flattenedPDF = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'output' : 'example_out'
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# We have preset 'high', 'medium', and 'low' quality levels available for use. These preset levels do not require the 'profile' parameter.
mp_encoder_flattenTransparenciesPdf = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'output' : 'example_flattenedPdf_out',
'quality': 'medium',
}
Expand Down
2 changes: 1 addition & 1 deletion Python/Endpoint Examples/Multipart Payload/gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# This sample takes in a PDF and converts all pages into grayscale GIF files.
mp_encoder_gif = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'pages': '1-last',
'resolution': '600',
'color_model': 'gray',
Expand Down
2 changes: 1 addition & 1 deletion Python/Endpoint Examples/Multipart Payload/jpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# This sample takes in a PDF and converts all pages into JPEG files.
mp_encoder_jpg = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'pages': '1-last',
'resolution': '600',
'color_model': 'cmyk',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# This sample demonstrates linearizing a PDF file.
mp_encoder_linearizedPdf = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'output' : 'example_linearizedPdf_out',
}
)
Expand Down
4 changes: 2 additions & 2 deletions Python/Endpoint Examples/Multipart Payload/merged-pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

# Array of tuples that contains information about the 2 files that will be merged
files = [
('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
('file_name', open('/path/to/file', 'rb'), 'application/pdf')
('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
('file_name2.pdf', open('/path/to/file', 'rb'), 'application/pdf')
]

# Structure the data that will be sent to POST merge request as an array of tuples
Expand Down
2 changes: 1 addition & 1 deletion Python/Endpoint Examples/Multipart Payload/pdf-info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#This sample demonstrates querying the title, page count, document language and author
mp_encoder_pdfInfo = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'queries': 'title,page_count,doc_language,author',
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

mp_encoder_pdfWithAddedImage = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'image_file': ('file_name', open('/path/to/file', 'rb'), 'image/jpeg'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'image_file': ('file_name.jpg', open('/path/to/file', 'rb'), 'image/jpeg'),
'output' : 'example_out',
'x' : '10',
'y' : '10',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

mp_encoder_importFormData = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'data_file': ('file_name', open('/path/to/datafile', 'rb'), 'application/xml'), # Update for your data file format
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'data_file': ('file_name.xml', open('/path/to/datafile', 'rb'), 'application/xml'), # Update for your data file format
'output' : 'example_out'
}
)
Expand Down
2 changes: 1 addition & 1 deletion Python/Endpoint Examples/Multipart Payload/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Please see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types for more information about MIME types.
mp_encoder_pdf = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'image/tiff'),
'file': ('file_name.tif', open('/path/to/file', 'rb'), 'image/tiff'),
'output' : 'example_pdf_out',
}
)
Expand Down
2 changes: 1 addition & 1 deletion Python/Endpoint Examples/Multipart Payload/pdfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# The /pdfa endpoint can take a single PDF file or id as input.
mp_encoder_pdfa = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'output_type': 'PDF/A-1b',
'rasterize_if_errors_encountered': 'on',
'output' : 'example_pdfa_out',
Expand Down
2 changes: 1 addition & 1 deletion Python/Endpoint Examples/Multipart Payload/pdfx.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# The /pdfx endpoint can take a single PDF file or id as input.
mp_encoder_pdfx = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'output_type': 'PDF/X-4',
'output' : 'example_pdfx_out'
}
Expand Down
2 changes: 1 addition & 1 deletion Python/Endpoint Examples/Multipart Payload/png.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# This sample takes in a PDF and converts all pages into grayscale PNG files.
mp_encoder_png = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'pages': '1-last',
'resolution': '600',
'color_model': 'gray',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# This sample demonstrates setting the permissions password to 'password' and adding restrictions.
mp_encoder_restrictedPdf = MultipartEncoder(
fields=[
('file', ('file_name', open('/path/to/file', 'rb'), 'application/pdf')),
('file', ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf')),
('output', 'example_restrictedPdf_out'),
('new_permissions_password', 'password'),
('restrictions', 'print_high'),
Expand Down
2 changes: 1 addition & 1 deletion Python/Endpoint Examples/Multipart Payload/split-pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# Create a list of tuples for data that will be sent to the request
split_request_data = []
split_request_data.append(('file',('file_name', open('/path/to/file', 'rb'), 'application/pdf')))
split_request_data.append(('file',('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf')))
split_request_data.append(('pages', '1,2,5'))
split_request_data.append(('pages', '3,4'))
split_request_data.append(('output', 'example_splitPdf_out'))
Expand Down
2 changes: 1 addition & 1 deletion Python/Endpoint Examples/Multipart Payload/tif.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# This sample takes in a PDF and converts all pages into grayscale TIFF files.
mp_encoder_tif = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'pages': '1-last',
'resolution': '600',
'color_model': 'gray',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# This sample demonstrates removing security restrictions from a PDF.
mp_encoder_unrestrictedPdf = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'output' : 'example_unrestrictedPdf_out',
'current_permissions_password': 'password'
}
Expand Down
6 changes: 3 additions & 3 deletions Python/Endpoint Examples/Multipart Payload/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# The 'application/pdf' string below is known as a MIME type, which is a label used to identify the type of a file so that it is handled properly by software.
# Please see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types for more information about MIME types.
files = [
('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
('file_name', open('/path/to/file', 'rb'), 'image/jpeg')
('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
('file_name2.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
('file_name.jpg', open('/path/to/file', 'rb'), 'image/jpeg')
]

# Structure the data that will be sent to POST upload request as an array of tuples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

mp_encoder_watermarkedPDF = MultipartEncoder(
fields={
'file': ('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
'file': ('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
'watermark_text': 'watermark',
'output' : 'example_out'
}
Expand Down
6 changes: 3 additions & 3 deletions Python/Endpoint Examples/Multipart Payload/zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# The 'application/pdf' string below is known as a MIME type, which is a label used to identify the type of a file so that it is handled properly by software.
# Please see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types for more information about MIME types.
files = [
('file_name', open('/path/to/file', 'rb'), 'application/pdf'),
('file_name', open('/path/to/file', 'rb'), 'image/tiff'),
('file_name', open('/path/to/file', 'rb'), 'image/bmp')
('file_name.pdf', open('/path/to/file', 'rb'), 'application/pdf'),
('file_name.tif', open('/path/to/file', 'rb'), 'image/tiff'),
('file_name.bmp', open('/path/to/file', 'rb'), 'image/bmp')
]

# Structure the data that will be sent to POST zip request as an array of tuples
Expand Down

0 comments on commit 1361d8e

Please sign in to comment.