Skip to content

Commit

Permalink
Merge pull request #55 from datalogics-tsmith/fix-comments
Browse files Browse the repository at this point in the history
Touch up samples
  • Loading branch information
datalogics-jacksonm authored Nov 9, 2023
2 parents 3ee4fa9 + 3c1f9ff commit 2b83fa7
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This request demonstrates how to flatten transparencies in a PDF.
var axios = require('axios');
var FormData = require('form-data');
var fs = require('fs');
// This request demonstrates how to liearize a PDF for fast web viewing.

// Create a new form data instance and append the PDF file and parameters to it
var data = new FormData();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* This request demonstrates how to apply a file watermark to a PDF. This kind of watermark uses another PDF (using either watermark_file or watermark_file_id as a form-data parameter) and applies it as a watermark to the primary input document (file or id).
* Horizontal and vertical offsets of the watermark are measured in PDF units. (1 inch = 72 PDF units)
* This request demonstrates how to add a file attachment to a PDF.
*/
var axios = require('axios');
var FormData = require('form-data');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* This request demonstrates how to apply a file watermark to a PDF. This kind of watermark uses another PDF (using either watermark_file or watermark_file_id as a form-data parameter) and applies it as a watermark to the primary input document (file or id).
* Horizontal and vertical offsets of the watermark are measured in PDF units. (1 inch = 72 PDF units)
* This request demonstrates how to apply an image to a PDF. Horizontal and vertical offsets of the image are measured in PDF units. (1 inch = 72 PDF units)
*/
var axios = require('axios');
var FormData = require('form-data');
Expand Down
2 changes: 1 addition & 1 deletion JavaScript/Endpoint Examples/Multipart Payload/upload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This request demonstrates how to upload .
var axios = require('axios');
var FormData = require('form-data');
var fs = require('fs');
// This request demonstrates how to upload a document to the service.

// Create a new form data object and append the PDF file and parameters to it
var data = new FormData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],
[
'name' => 'output',
'contents' => '' // Specify the output type (e.g., 'pdfrest_flattened_form', 'pdfrest_flattened_annotations', etc.)
'contents' => 'pdfrest_flattened_pdf' // Specify the output name for the file
]
]];

Expand Down
64 changes: 16 additions & 48 deletions PHP/Endpoint Examples/Multipart Payload/flattened-layers-pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,28 @@
$client = new Client(); // Create a new instance of the Guzzle HTTP client.

$headers = [
'Api-Key' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' // Set the API key in the headers for authentication.
'Api-Key' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' // Set the API key in the headers for authentication.
];

$options = [
'multipart' => [
[
'name' => 'file',
'contents' => Utils::tryFopen('/path/to/file', 'r'), // Provide the path to the PDF file to be watermarked.
'filename' => '/path/to/file',
'headers' => [
'Content-Type' => '<Content-type header>' // Specify the Content-Type header for the PDF file.
]
],
[
'name' => 'watermark_text',
'contents' => 'Hello, watermarked world!' // Specify the text to be used as the watermark.
],
[
'name' => 'font',
'contents' => 'Arial' // Specify the font to be used for the watermark text.
],
[
'name' => 'text_size',
'contents' => '72' // Specify the font size of the watermark text.
],
[
'name' => 'text_color_rgb',
'contents' => '255,0,0' // Specify the RGB color (red, green, blue) of the watermark text.
],
[
'name' => 'opacity',
'contents' => '0.5' // Specify the opacity of the watermark (0.0 to 1.0).
],
[
'name' => 'x',
'contents' => '0' // Specify the x-coordinate of the watermark's position.
],
[
'name' => 'y',
'contents' => '0' // Specify the y-coordinate of the watermark's position.
],
[
'name' => 'rotation',
'contents' => '0' // Specify the rotation angle of the watermark (in degrees).
],
[
'name' => 'output',
'contents' => 'pdfrest_watermarked_pdf' // Specify the desired output format for the watermarked PDF.
]
'multipart' => [
[
'name' => 'file', // Specify the field name for the file.
'contents' => Utils::tryFopen('/path/to/file', 'r'), // Open the file specified by the '/path/to/file' for reading.
'filename' => '/path/to/file', // Set the filename for the file to be processed, in this case, '/path/to/file'.
'headers' => [
'Content-Type' => '<Content-type header>' // Set the Content-Type header for the file.
]
],
[
'name' => 'output', // Specify the field name for the output option.
'contents' => 'pdfrest_flattened_pdf' // Set the value for the output option (in this case, 'pdfrest_flattened_pdf').
]
]
];

$request = new Request('POST', 'https://api.pdfrest.com/watermarked-pdf', $headers); // Create a new HTTP POST request with the API endpoint and headers.
$request = new Request('POST', 'https://api.pdfrest.com/flattened-layers-pdf', $headers); // Create a new HTTP POST request with the API endpoint and headers.

$res = $client->sendAsync($request, $options)->wait(); // Send the asynchronous request and wait for the response.

echo $res->getBody(); // Output the response body, which contains the watermarked PDF.
echo $res->getBody(); // Output the response body, which contains the flattened layers PDF content.
10 changes: 7 additions & 3 deletions PHP/Endpoint Examples/Multipart Payload/watermarked-pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@
'Content-Type' => '<Content-type header>' // Set the Content-Type header for the file.
]
],
[
'name' => 'watermark_text', // Specify the field name for the output option.
'contents' => 'TEXT' // Set the value for the watermark_text option (in this case, 'TEXT').
]
[
'name' => 'output', // Specify the field name for the output option.
'contents' => 'pdfrest_flattened_pdf' // Set the value for the output option (in this case, 'pdfrest_flattened_pdf').
'contents' => 'pdfrest_watermarked_pdf' // Set the value for the output option (in this case, 'pdfrest_watermarked_pdf').
]
]
];

$request = new Request('POST', 'https://api.pdfrest.com/flattened-layers-pdf', $headers); // Create a new HTTP POST request with the API endpoint and headers.
$request = new Request('POST', 'https://api.pdfrest.com/watermarked-pdf', $headers); // Create a new HTTP POST request with the API endpoint and headers.

$res = $client->sendAsync($request, $options)->wait(); // Send the asynchronous request and wait for the response.

echo $res->getBody(); // Output the response body, which contains the flattened layers PDF content.
echo $res->getBody(); // Output the response body, which contains the watermarked PDF content.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
)

# Let's set the headers that the encrypted-pdf endpoint expects.
# Let's set the headers that the exported-form-data endpoint expects.
# Since MultipartEncoder is used, the 'Content-Type' header gets set to 'multipart/form-data' via the content_type attribute below.
headers = {
'Accept': 'application/json',
Expand Down

0 comments on commit 2b83fa7

Please sign in to comment.