Skip to content

Commit

Permalink
Add key variable for complex calls
Browse files Browse the repository at this point in the history
So that the end user does not have to replace the key in multiple locations
in order to run the sample
  • Loading branch information
datalogics-tsmith committed Dec 12, 2023
1 parent 841b06f commit c61323a
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 49 deletions.
8 changes: 5 additions & 3 deletions DotNET/Complex Flow Examples/decrypt-add-reencrypt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
* lock it up again.
*/

var apiKey = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" // Your API key here

using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") })
{
using (var decryptRequest = new HttpRequestMessage(HttpMethod.Post, "decrypted-pdf"))
{
decryptRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
decryptRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey);
decryptRequest.Headers.Accept.Add(new("application/json"));
var decryptMultipartContent = new MultipartFormDataContent();

Expand All @@ -41,7 +43,7 @@

using (var addImageRequest = new HttpRequestMessage(HttpMethod.Post, "pdf-with-added-image"))
{
addImageRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
addImageRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey);
addImageRequest.Headers.Accept.Add(new("application/json"));
var addImageMultipartContent = new MultipartFormDataContent();

Expand Down Expand Up @@ -74,7 +76,7 @@

using (var encryptRequest = new HttpRequestMessage(HttpMethod.Post, "encrypted-pdf"))
{
encryptRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
encryptRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey);
encryptRequest.Headers.Accept.Add(new("application/json"));
var multipartContent = new MultipartFormDataContent();

Expand Down
8 changes: 5 additions & 3 deletions DotNET/Complex Flow Examples/merge-different-file-types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
* that the /pdf route takes as inputs.
*/

var apiKey = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" // Your API key here

using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") })
{
using (var imageRequest = new HttpRequestMessage(HttpMethod.Post, "pdf"))
{
imageRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); // Your API key here
imageRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey);
imageRequest.Headers.Accept.Add(new("application/json"));
var imageMultipartContent = new MultipartFormDataContent();

Expand All @@ -38,7 +40,7 @@

using (var powerpointRequest = new HttpRequestMessage(HttpMethod.Post, "pdf"))
{
powerpointRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); // Your API key here
powerpointRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey);
powerpointRequest.Headers.Accept.Add(new("application/json"));
var powerpointMultipartContent = new MultipartFormDataContent();

Expand All @@ -59,7 +61,7 @@

using (var request = new HttpRequestMessage(HttpMethod.Post, "merged-pdf"))
{
request.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
request.Headers.TryAddWithoutValidation("Api-Key", apiKey);
request.Headers.Accept.Add(new("application/json"));
var multipartContent = new MultipartFormDataContent();

Expand Down
8 changes: 5 additions & 3 deletions DotNET/Complex Flow Examples/pdfa-3b-with-attachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
* file may be attached and wrapped into the PDF/A conversion.
*/

var apiKey = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" // Your API key here

using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") })
{
using (var attachRequest = new HttpRequestMessage(HttpMethod.Post, "pdf-with-added-attachment"))
{
attachRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); // Your API key here
attachRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey);
attachRequest.Headers.Accept.Add(new("application/json"));
var attachMultipartContent = new MultipartFormDataContent();

Expand All @@ -27,7 +29,7 @@
var byteArray2 = File.ReadAllBytes("/path/to/file.xml");
var byteAryContent2 = new ByteArrayContent(byteArray2);
attachMultipartContent.Add(byteAryContent2, "file_to_attach", "file_name.xml");
byteAryContent2.Headers.TryAddWithoutValidation("Content-Type", "application/xml"); // Update content type
byteAryContent2.Headers.TryAddWithoutValidation("Content-Type", "application/xml");

attachRequest.Content = attachMultipartContent;
var attachResponse = await httpClient.SendAsync(attachRequest);
Expand All @@ -41,7 +43,7 @@

using (var request = new HttpRequestMessage(HttpMethod.Post, "pdfa"))
{
request.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); // Your API key here
request.Headers.TryAddWithoutValidation("Api-Key", apiKey);
request.Headers.Accept.Add(new("application/json"));
var multipartContent = new MultipartFormDataContent();

Expand Down
6 changes: 4 additions & 2 deletions DotNET/Complex Flow Examples/preserve-word-document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
* and convert it to the PDF/A format for long-term storage.
*/

var apiKey = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" // Your API key here

using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") })
{
using (var pdfRequest = new HttpRequestMessage(HttpMethod.Post, "pdf"))
{
pdfRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); // Your API key here
pdfRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey);
pdfRequest.Headers.Accept.Add(new("application/json"));
var pdfMultipartContent = new MultipartFormDataContent();

Expand All @@ -33,7 +35,7 @@

using (var request = new HttpRequestMessage(HttpMethod.Post, "pdfa"))
{
request.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); // Your API key here
request.Headers.TryAddWithoutValidation("Api-Key", apiKey);
request.Headers.Accept.Add(new("application/json"));
var multipartContent = new MultipartFormDataContent();

Expand Down
6 changes: 4 additions & 2 deletions DotNET/Complex Flow Examples/protected-watermark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
* and then /restricted-pdf to lock the watermark in.
*/

var apiKey = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" // Your API key here

using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") })
{
using (var watermarkRequest = new HttpRequestMessage(HttpMethod.Post, "watermarked-pdf"))
{
watermarkRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); // Your API key here
watermarkRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey);
watermarkRequest.Headers.Accept.Add(new("application/json"));
var watermarkMultipartContent = new MultipartFormDataContent();

Expand All @@ -37,7 +39,7 @@

using (var restrictRequest = new HttpRequestMessage(HttpMethod.Post, "restricted-pdf"))
{
restrictRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); // Your API key here
restrictRequest.Headers.TryAddWithoutValidation("Api-Key", apiKey);
restrictRequest.Headers.Accept.Add(new("application/json"));
var restrictMultipartContent = new MultipartFormDataContent();

Expand Down
8 changes: 5 additions & 3 deletions JavaScript/Complex Flow Examples/decrypt-add-reencrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var fs = require("fs");
* lock it up again.
*/

var apiKey = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // Replace with your API key

var decryptRequestData = new FormData();
decryptRequestData.append("file", fs.createReadStream("/path/to/file.pdf"));
decryptRequestData.append("current_open_password", "current_example_pw");
Expand All @@ -20,7 +22,7 @@ var decryptConfig = {
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/decrypted-pdf",
headers: {
"Api-Key": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Api-Key": apiKey,
...decryptRequestData.getHeaders(),
},
data: decryptRequestData,
Expand All @@ -41,7 +43,7 @@ axios(decryptConfig)
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/pdf-with-added-image",
headers: {
"Api-Key": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Api-Key": apiKey,
...data.getHeaders(),
},
data: data,
Expand All @@ -58,7 +60,7 @@ axios(decryptConfig)
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/encrypted-pdf",
headers: {
"Api-Key": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Api-Key": apiKey,
...data.getHeaders(),
},
data: data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ First, we will upload an image file to the /pdf route and capture the output ID.
* that the /pdf route takes as inputs.
*/

var apiKey = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // Replace with your API key

var imageData = new FormData();
imageData.append("file", fs.createReadStream("/path/to/image.png"));

Expand All @@ -22,7 +24,7 @@ var imageConfig = {
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/pdf",
headers: {
"Api-Key": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Api-Key": apiKey,
...imageData.getHeaders(),
},
data: imageData,
Expand All @@ -40,7 +42,7 @@ axios(imageConfig)
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/pdf",
headers: {
"Api-Key": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Api-Key": apiKey,
...pptData.getHeaders(),
},
data: pptData,
Expand All @@ -64,7 +66,7 @@ axios(imageConfig)
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/merged-pdf",
headers: {
"Api-Key": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Api-Key": apiKey,
...mergeData.getHeaders(),
},
data: mergeData,
Expand Down
6 changes: 4 additions & 2 deletions JavaScript/Complex Flow Examples/pdfa-3b-with-attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var fs = require("fs");
* file may be attached and wrapped into the PDF/A conversion.
*/

var apiKey = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // Replace with your API key

var attachData = new FormData();
attachData.append("file", fs.createReadStream("/path/to/file.pdf"));
attachData.append(
Expand All @@ -25,7 +27,7 @@ var attachConfig = {
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/pdf-with-added-attachment",
headers: {
"Api-Key": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Api-Key": apiKey,
...attachData.getHeaders(),
},
data: attachData,
Expand All @@ -45,7 +47,7 @@ axios(attachConfig)
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/pdfa",
headers: {
"Api-Key": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Api-Key": apiKey,
...pdfaData.getHeaders(),
},
data: pdfaData,
Expand Down
6 changes: 4 additions & 2 deletions JavaScript/Complex Flow Examples/preserve-word-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ var fs = require("fs");
* and convert it to the PDF/A format for long-term storage.
*/

var apiKey = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // Replace with your API key

var pdfData = new FormData();
pdfData.append("file", fs.createReadStream("/path/to/word.doc"));

Expand All @@ -17,7 +19,7 @@ var pdfConfig = {
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/pdf",
headers: {
"Api-Key": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Api-Key": apiKey,
...pdfData.getHeaders(),
},
data: pdfData,
Expand All @@ -37,7 +39,7 @@ axios(pdfConfig)
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/pdfa",
headers: {
"Api-Key": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Api-Key": apiKey,
...pdfaData.getHeaders(),
},
data: pdfaData,
Expand Down
6 changes: 4 additions & 2 deletions JavaScript/Complex Flow Examples/protected-watermark.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ var fs = require("fs");
* and then /restricted-pdf to lock the watermark in.
*/

var apiKey = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // Replace with your API key

var watermarkData = new FormData();
watermarkData.append("file", fs.createReadStream("/path/to/file.pdf"));
watermarkData.append("watermark_text", "Watermarked");
Expand All @@ -18,7 +20,7 @@ var watermarkConfig = {
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/watermarked-pdf",
headers: {
"Api-Key": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Api-Key": apiKey,
...watermarkData.getHeaders(),
},
data: watermarkData,
Expand All @@ -40,7 +42,7 @@ axios(watermarkConfig)
maxBodyLength: Infinity,
url: "https://api.pdfrest.com/restricted-pdf",
headers: {
"Api-Key": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key
"Api-Key": apiKey,
...data.getHeaders(),
},
data: data,
Expand Down
8 changes: 5 additions & 3 deletions Python/Complex Flow Examples/decrypt-add-reencrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# and then sending the output with the new image through /encrypted-pdf to
# lock it up again.

api_key = 'xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place your api key here

decrypted_pdf_endpoint_url = 'https://api.pdfrest.com/decrypted-pdf'

mp_encoder_decryptedPdf = MultipartEncoder(
Expand All @@ -22,7 +24,7 @@
decrypt_headers = {
'Accept': 'application/json',
'Content-Type': mp_encoder_decryptedPdf.content_type,
'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place your api key here
'Api-Key': api_key
}

print("Sending POST request to decrypted-pdf endpoint...")
Expand Down Expand Up @@ -50,7 +52,7 @@
add_image_headers = {
'Accept': 'application/json',
'Content-Type': mp_encoder_pdfWithAddedImage.content_type,
'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place your api key here
'Api-Key': api_key
}

print("Sending POST request to pdf-with-added-image endpoint...")
Expand All @@ -75,7 +77,7 @@
encrypt_headers = {
'Accept': 'application/json',
'Content-Type': mp_encoder_encryptedPdf.content_type,
'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place your api key here
'Api-Key': api_key
}

print("Sending POST request to encrypted-pdf endpoint...")
Expand Down
8 changes: 5 additions & 3 deletions Python/Complex Flow Examples/merge-different-file-types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# this sample could be easily used to convert and combine any two file types
# that the /pdf route takes as inputs.

api_key = 'xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place your api key here

pdf_endpoint_url = 'https://api.pdfrest.com/pdf'
mp_encoder_image_pdf = MultipartEncoder(
fields={
Expand All @@ -24,7 +26,7 @@
image_headers = {
'Accept': 'application/json',
'Content-Type': mp_encoder_image_pdf.content_type,
'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place your api key here
'Api-Key': api_key
}

print("Sending POST request to pdf endpoint...")
Expand All @@ -49,7 +51,7 @@
ppt_headers = {
'Accept': 'application/json',
'Content-Type': mp_encoder_ppt_pdf.content_type,
'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place your api key here
'Api-Key': api_key
}

print("Sending POST request to pdf endpoint...")
Expand All @@ -73,7 +75,7 @@
merge_headers = {
'Accept': 'application/json',
'Content-Type': mp_encoder_merge.content_type,
'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place your api key here
'Api-Key': api_key
}

print("Sending POST request to merged-pdf endpoint...")
Expand Down
6 changes: 4 additions & 2 deletions Python/Complex Flow Examples/pdfa-3b-with-attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# Note that there is nothing special about attaching an xml file, and any appropriate
# file may be attached and wrapped into the PDF/A conversion.

api_key = 'xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place your api key here

pdf_with_added_attachment_endpoint_url = 'https://api.pdfrest.com/pdf-with-added-attachment'

mp_encoder_pdfWithAddedAttachment = MultipartEncoder(
Expand All @@ -24,7 +26,7 @@
attachment_headers = {
'Accept': 'application/json',
'Content-Type': mp_encoder_pdfWithAddedAttachment.content_type,
'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place your api key here
'Api-Key': api_key
}

print("Sending POST request to pdf-with-added-attachment endpoint...")
Expand All @@ -50,7 +52,7 @@
headers = {
'Accept': 'application/json',
'Content-Type': mp_encoder_pdfa.content_type,
'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place your api key here
'Api-Key': api_key
}

print("Sending POST request to pdfa endpoint...")
Expand Down
Loading

0 comments on commit c61323a

Please sign in to comment.