diff --git a/CPlusPlus/Endpoint Examples/JSON Payload/CMakeLists.txt b/CPlusPlus/Endpoint Examples/JSON Payload/CMakeLists.txt index 5a1c4b5..70d17b4 100644 --- a/CPlusPlus/Endpoint Examples/JSON Payload/CMakeLists.txt +++ b/CPlusPlus/Endpoint Examples/JSON Payload/CMakeLists.txt @@ -19,4 +19,8 @@ if (cpr_FOUND AND nlohmann_json_FOUND) add_executable(translated_pdf_text_json translated_pdf_text.cpp) target_link_libraries(translated_pdf_text_json PRIVATE cpr::cpr nlohmann_json::nlohmann_json) target_compile_features(translated_pdf_text_json PRIVATE cxx_std_20) + + add_executable(blank_pdf_json blank_pdf.cpp) + target_link_libraries(blank_pdf_json PRIVATE cpr::cpr nlohmann_json::nlohmann_json) + target_compile_features(blank_pdf_json PRIVATE cxx_std_20) endif() diff --git a/CPlusPlus/Endpoint Examples/JSON Payload/blank_pdf.cpp b/CPlusPlus/Endpoint Examples/JSON Payload/blank_pdf.cpp new file mode 100644 index 0000000..efe3f9b --- /dev/null +++ b/CPlusPlus/Endpoint Examples/JSON Payload/blank_pdf.cpp @@ -0,0 +1,115 @@ +/* + * What this sample does: + * - Calls /blank-pdf with a JSON payload to create an empty three-page PDF. + * + * Setup (environment): + * - Set PDFREST_API_KEY=your_api_key_here + * - Optional: set PDFREST_URL to override the API region. For EU/GDPR, use: + * PDFREST_URL=https://eu-api.pdfrest.com + * More info: https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work + * + * Usage: + * ./blank_pdf_json + * + * Output: + * - Prints the JSON response. Non-2xx responses exit non-zero. + */ + +#include +#include + +#include +#include +#include +#include +#include + +namespace fs = std::filesystem; +using json = nlohmann::json; + +static std::string rtrim_slashes(std::string s) { + while (!s.empty() && (s.back() == '/' || s.back() == '\\')) { + s.pop_back(); + } + return s; +} + +static void load_dotenv_if_present(const fs::path &path) { + std::ifstream f(path); + if (!f.is_open()) return; + std::string line; + while (std::getline(f, line)) { + if (line.empty() || line[0] == '#') continue; + auto pos = line.find('='); + if (pos == std::string::npos) continue; + std::string key = line.substr(0, pos); + std::string val = line.substr(pos + 1); + auto trim = [](std::string &s) { + size_t start = s.find_first_not_of(" \t\r\n"); + size_t end = s.find_last_not_of(" \t\r\n"); + if (start == std::string::npos) { s.clear(); return; } + s = s.substr(start, end - start + 1); + }; + trim(key); + trim(val); + if (key.empty()) continue; + if (std::getenv(key.c_str()) == nullptr) { +#ifdef _WIN32 + _putenv_s(key.c_str(), val.c_str()); +#else + setenv(key.c_str(), val.c_str(), 0); +#endif + } + } +} + +static void load_env() { + const fs::path here = fs::current_path(); + load_dotenv_if_present(here / ".env"); + if (fs::exists(here.parent_path())) { + load_dotenv_if_present(here.parent_path() / ".env"); + } +} + +int main() { + load_env(); + + const char *api_key_c = std::getenv("PDFREST_API_KEY"); + if (api_key_c == nullptr || std::string(api_key_c).empty()) { + std::cerr << "Missing required environment variable: PDFREST_API_KEY\n"; + return 1; + } + + const char *base_url_c = std::getenv("PDFREST_URL"); + std::string base_url = base_url_c && std::string(base_url_c).size() + ? base_url_c + : std::string("https://api.pdfrest.com"); + base_url = rtrim_slashes(base_url); + + json payload = { + {"page_size", "letter"}, + {"page_count", 3}, + {"page_orientation", "portrait"} + }; + + cpr::Header headers{ + {"Api-Key", api_key_c}, + {"Accept", "application/json"}, + {"Content-Type", "application/json"} + }; + + auto res = cpr::Post( + cpr::Url{base_url + "/blank-pdf"}, + headers, + cpr::Body{payload.dump()} + ); + + if (res.error || res.status_code < 200 || res.status_code >= 300) { + std::cerr << "blank-pdf failed (status " << res.status_code << "): " + << res.error.message << "\n" << res.text << "\n"; + return 1; + } + + std::cout << res.text << "\n"; + return 0; +} diff --git a/CPlusPlus/Endpoint Examples/Multipart Payload/CMakeLists.txt b/CPlusPlus/Endpoint Examples/Multipart Payload/CMakeLists.txt index 077fce8..21ad0e2 100644 --- a/CPlusPlus/Endpoint Examples/Multipart Payload/CMakeLists.txt +++ b/CPlusPlus/Endpoint Examples/Multipart Payload/CMakeLists.txt @@ -18,4 +18,8 @@ if (cpr_FOUND) add_executable(translated_pdf_text_multipart translated_pdf_text.cpp) target_link_libraries(translated_pdf_text_multipart PRIVATE cpr::cpr) target_compile_features(translated_pdf_text_multipart PRIVATE cxx_std_20) + + add_executable(blank_pdf_multipart blank_pdf.cpp) + target_link_libraries(blank_pdf_multipart PRIVATE cpr::cpr) + target_compile_features(blank_pdf_multipart PRIVATE cxx_std_20) endif() diff --git a/CPlusPlus/Endpoint Examples/Multipart Payload/blank_pdf.cpp b/CPlusPlus/Endpoint Examples/Multipart Payload/blank_pdf.cpp new file mode 100644 index 0000000..6f2f8ca --- /dev/null +++ b/CPlusPlus/Endpoint Examples/Multipart Payload/blank_pdf.cpp @@ -0,0 +1,94 @@ +/* + * What this sample does: + * - Calls /blank-pdf via multipart/form-data to create a blank three-page PDF. + * + * Setup (environment): + * - Copy .env.example to .env + * - Set PDFREST_API_KEY=your_api_key_here + * - Optional: set PDFREST_URL to override the API region. For EU/GDPR compliance and proximity, use: + * PDFREST_URL=https://eu-api.pdfrest.com + * For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work + * + * Usage: + * ./blank_pdf_multipart + * + * Output: + * - Prints the JSON response to stdout; non-2xx exits with concise error. + */ + +#include + +#include +#include +#include +#include +#include + +namespace fs = std::filesystem; + +static std::string rtrim_slashes(std::string s) { + while (!s.empty() && (s.back() == '/' || s.back() == '\\')) s.pop_back(); + return s; +} + +static void load_dotenv_if_present(const fs::path &path) { + std::ifstream f(path); + if (!f.is_open()) return; + std::string line; + while (std::getline(f, line)) { + if (line.empty() || line[0] == '#') continue; + auto p = line.find('='); + if (p == std::string::npos) continue; + std::string k = line.substr(0, p); + std::string v = line.substr(p + 1); + auto trim = [](std::string &s) { + size_t b = s.find_first_not_of(" \t\r\n"), e = s.find_last_not_of(" \t\r\n"); + if (b == std::string::npos) { s.clear(); return; } + s = s.substr(b, e - b + 1); + }; + trim(k); trim(v); + if (k.empty()) continue; + if (!std::getenv(k.c_str())) { +#ifdef _WIN32 + _putenv_s(k.c_str(), v.c_str()); +#else + setenv(k.c_str(), v.c_str(), 0); +#endif + } + } +} + +static void load_env() { + auto here = fs::current_path(); + load_dotenv_if_present(here / ".env"); + if (fs::exists(here.parent_path())) { + load_dotenv_if_present(here.parent_path() / ".env"); + } +} + +int main() { + load_env(); + const char *key = getenv("PDFREST_API_KEY"); + if (!key || !*key) { + std::cerr << "Missing PDFREST_API_KEY\n"; + return 1; + } + std::string base = getenv("PDFREST_URL") ? getenv("PDFREST_URL") : "https://api.pdfrest.com"; + base = rtrim_slashes(base); + + cpr::Header hdr{{"Api-Key", key}, {"Accept", "application/json"}}; + cpr::Multipart mp{ + {"page_size", "letter"}, + {"page_count", "3"}, + {"page_orientation", "portrait"} + }; + + auto res = cpr::Post(cpr::Url{base + "/blank-pdf"}, hdr, mp); + if (res.error || res.status_code < 200 || res.status_code >= 300) { + std::cerr << "blank-pdf failed (" << res.status_code << ")\n" + << res.error.message << "\n" << res.text << "\n"; + return 1; + } + std::cout << res.text << "\n"; + return 0; +} diff --git a/DotNET/Endpoint Examples/JSON Payload/blank-pdf.cs b/DotNET/Endpoint Examples/JSON Payload/blank-pdf.cs new file mode 100644 index 0000000..3021cf4 --- /dev/null +++ b/DotNET/Endpoint Examples/JSON Payload/blank-pdf.cs @@ -0,0 +1,65 @@ +/* + * What this sample does: + * - Requests a new blank PDF using the JSON payload route. + * + * Setup (environment): + * - Copy .env.example to .env + * - Set PDFREST_API_KEY=your_api_key_here + * - Optional: set PDFREST_URL to override the API region. For EU/GDPR compliance and proximity, use: + * PDFREST_URL=https://eu-api.pdfrest.com + * For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work + * + * Usage: + * dotnet run -- blank-pdf + * + * Output: + * - Prints JSON response for the generated blank document. + */ +using Newtonsoft.Json.Linq; +using System.Text; + +namespace Samples.EndpointExamples.JsonPayload +{ + public static class BlankPdf + { + public static async Task Execute(string[] args) + { + var apiKey = Environment.GetEnvironmentVariable("PDFREST_API_KEY"); + if (string.IsNullOrWhiteSpace(apiKey)) + { + Console.Error.WriteLine("Missing required environment variable: PDFREST_API_KEY"); + Environment.Exit(1); + return; + } + + var baseUrl = Environment.GetEnvironmentVariable("PDFREST_URL") ?? "https://api.pdfrest.com"; + + using (var httpClient = new HttpClient { BaseAddress = new Uri(baseUrl) }) + using (var request = new HttpRequestMessage(HttpMethod.Post, "blank-pdf")) + { + request.Headers.TryAddWithoutValidation("Api-Key", apiKey); + request.Headers.Accept.Add(new("application/json")); + + var payload = new JObject + { + ["page_size"] = "letter", + ["page_count"] = 3, + ["page_orientation"] = "portrait" + }; + + request.Content = new StringContent(payload.ToString(), Encoding.UTF8, "application/json"); + + var response = await httpClient.SendAsync(request); + var result = await response.Content.ReadAsStringAsync(); + + Console.WriteLine("Blank PDF response received."); + Console.WriteLine(result); + + if (!response.IsSuccessStatusCode) + { + Environment.ExitCode = 1; + } + } + } + } +} diff --git a/DotNET/Endpoint Examples/Multipart Payload/blank-pdf.cs b/DotNET/Endpoint Examples/Multipart Payload/blank-pdf.cs new file mode 100644 index 0000000..b48679d --- /dev/null +++ b/DotNET/Endpoint Examples/Multipart Payload/blank-pdf.cs @@ -0,0 +1,63 @@ +/* + * What this sample does: + * - Calls /blank-pdf via multipart/form-data to create a three-page blank PDF. + * - Routed from Program.cs as: `dotnet run -- blank-pdf-multipart`. + * + * Setup (environment): + * - Copy .env.example to .env + * - Set PDFREST_API_KEY=your_api_key_here + * - Optional: set PDFREST_URL to override the API region. For EU/GDPR compliance and proximity, use: + * PDFREST_URL=https://eu-api.pdfrest.com + * For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work + * + * Usage: + * dotnet run -- blank-pdf-multipart + * + * Output: + * - Prints the JSON response. Validation errors (args/env) exit non-zero. + */ + +namespace Samples.EndpointExamples.MultipartPayload +{ + public static class BlankPdf + { + public static async Task Execute(string[] args) + { + var apiKey = Environment.GetEnvironmentVariable("PDFREST_API_KEY"); + if (string.IsNullOrWhiteSpace(apiKey)) + { + Console.Error.WriteLine("Missing required environment variable: PDFREST_API_KEY"); + Environment.Exit(1); + return; + } + + var baseUrl = Environment.GetEnvironmentVariable("PDFREST_URL") ?? "https://api.pdfrest.com"; + + using (var httpClient = new HttpClient { BaseAddress = new Uri(baseUrl) }) + using (var request = new HttpRequestMessage(HttpMethod.Post, "blank-pdf")) + { + request.Headers.TryAddWithoutValidation("Api-Key", apiKey); + request.Headers.Accept.Add(new("application/json")); + + var multipartContent = new MultipartFormDataContent + { + { new StringContent("letter"), "page_size" }, + { new StringContent("3"), "page_count" }, + { new StringContent("portrait"), "page_orientation" } + }; + + request.Content = multipartContent; + var response = await httpClient.SendAsync(request); + var apiResult = await response.Content.ReadAsStringAsync(); + + Console.WriteLine("blank-pdf response received."); + Console.WriteLine(apiResult); + + if (!response.IsSuccessStatusCode) + { + Environment.ExitCode = 1; + } + } + } + } +} diff --git a/DotNET/Program.cs b/DotNET/Program.cs index c92fd79..c87fc39 100644 --- a/DotNET/Program.cs +++ b/DotNET/Program.cs @@ -46,6 +46,7 @@ static void PrintUsage() Console.Error.WriteLine(" pdf-with-redacted-text-preview Preview redactions"); Console.Error.WriteLine(" pdf-with-redacted-text-applied Apply redactions"); Console.Error.WriteLine(" Page / Files:"); + Console.Error.WriteLine(" blank-pdf Generate an empty PDF"); Console.Error.WriteLine(" split-pdf Split by page ranges"); Console.Error.WriteLine(" merged-pdf Merge two PDFs by id"); Console.Error.WriteLine(" Resources / Packaging / Signing:"); @@ -95,6 +96,7 @@ static void PrintUsage() Console.Error.WriteLine(" pdf-with-redacted-text-preview-multipart Preview redactions"); Console.Error.WriteLine(" pdf-with-redacted-text-applied-multipart Apply redactions"); Console.Error.WriteLine(" Page / Files:"); + Console.Error.WriteLine(" blank-pdf-multipart Generate an empty PDF"); Console.Error.WriteLine(" split-pdf-multipart Split by page ranges"); Console.Error.WriteLine(" merged-pdf-multipart Merge two files"); Console.Error.WriteLine(" Resources / Packaging / Signing:"); @@ -149,6 +151,9 @@ static void PrintUsage() case "rasterized-pdf": await Samples.EndpointExamples.JsonPayload.RasterizedPdf.Execute(rest); break; + case "blank-pdf": + await Samples.EndpointExamples.JsonPayload.BlankPdf.Execute(rest); + break; case "pdf-multipart": await Samples.EndpointExamples.MultipartPayload.Pdf.Execute(rest); break; @@ -306,6 +311,9 @@ static void PrintUsage() case "rasterized-pdf-multipart": await Samples.EndpointExamples.MultipartPayload.RasterizedPdf.Execute(rest); break; + case "blank-pdf-multipart": + await Samples.EndpointExamples.MultipartPayload.BlankPdf.Execute(rest); + break; case "compressed-pdf": await Samples.EndpointExamples.JsonPayload.CompressedPdf.Execute(rest); break; diff --git a/Java/Endpoint Examples/JSON Payload/BlankPDF.java b/Java/Endpoint Examples/JSON Payload/BlankPDF.java new file mode 100644 index 0000000..d846a24 --- /dev/null +++ b/Java/Endpoint Examples/JSON Payload/BlankPDF.java @@ -0,0 +1,60 @@ +import io.github.cdimascio.dotenv.Dotenv; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import okhttp3.*; +import org.json.JSONObject; + +public class BlankPDF { + + // By default, we use the US-based API service. This is the primary endpoint for global use. + private static final String API_URL = "https://api.pdfrest.com"; + + /* For GDPR compliance and enhanced performance for European users, you can switch to the EU-based + * service by commenting out the URL above and uncommenting the URL below. + * For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work + */ + // private static final String API_URL = "https://eu-api.pdfrest.com"; + + // Specify your API key here, or in the environment variable PDFREST_API_KEY. + // You can also put the environment variable in a .env file. + private static final String DEFAULT_API_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; + + public static void main(String[] args) { + final Dotenv dotenv = Dotenv.configure().ignoreIfMalformed().ignoreIfMissing().load(); + String apiKey = dotenv.get("PDFREST_API_KEY", DEFAULT_API_KEY); + String apiBase = dotenv.get("PDFREST_URL", API_URL); + if (apiBase == null || apiBase.isBlank()) { + apiBase = API_URL; + } + apiBase = apiBase.replaceAll("/+$", ""); + + JSONObject payload = new JSONObject(); + payload.put("page_size", "letter"); + payload.put("page_count", 3); + payload.put("page_orientation", "portrait"); + + RequestBody requestBody = + RequestBody.create(payload.toString(), MediaType.parse("application/json")); + + Request request = + new Request.Builder() + .header("Api-Key", apiKey) + .header("Content-Type", "application/json") + .url(apiBase + "/blank-pdf") + .post(requestBody) + .build(); + + try { + OkHttpClient client = + new OkHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build(); + + Response response = client.newCall(request).execute(); + System.out.println("blank-pdf Result code " + response.code()); + if (response.body() != null) { + System.out.println(response.body().string()); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/Java/Endpoint Examples/Multipart Payload/BlankPDF.java b/Java/Endpoint Examples/Multipart Payload/BlankPDF.java new file mode 100644 index 0000000..053be21 --- /dev/null +++ b/Java/Endpoint Examples/Multipart Payload/BlankPDF.java @@ -0,0 +1,58 @@ +import io.github.cdimascio.dotenv.Dotenv; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import okhttp3.MultipartBody; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import org.json.JSONObject; + +public class BlankPDF { + + // By default, we use the US-based API service. This is the primary endpoint for global use. + private static final String API_URL = "https://api.pdfrest.com"; + + /* For GDPR compliance and enhanced performance for European users, you can switch to the EU-based + * service by commenting out the URL above and uncommenting the URL below. + * For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work + */ + // private static final String API_URL = "https://eu-api.pdfrest.com"; + + // Specify your API key here, or in the environment variable PDFREST_API_KEY. + // You can also put the environment variable in a .env file. + private static final String DEFAULT_API_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; + + public static void main(String[] args) { + final Dotenv dotenv = Dotenv.configure().ignoreIfMalformed().ignoreIfMissing().load(); + + MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM); + builder.addFormDataPart("page_size", "letter"); + builder.addFormDataPart("page_count", "3"); + builder.addFormDataPart("page_orientation", "portrait"); + + RequestBody requestBody = builder.build(); + + Request request = + new Request.Builder() + .header("Api-Key", dotenv.get("PDFREST_API_KEY", DEFAULT_API_KEY)) + .url(API_URL + "/blank-pdf") + .post(requestBody) + .build(); + try { + OkHttpClient client = + new OkHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build(); + Response response = client.newCall(request).execute(); + System.out.println("blank-pdf Result code " + response.code()); + if (response.body() != null) { + System.out.println(prettyJson(response.body().string())); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private static String prettyJson(String json) { + return new JSONObject(json).toString(4); + } +} diff --git a/JavaScript/Endpoint Examples/JSON Payload/blank-pdf.js b/JavaScript/Endpoint Examples/JSON Payload/blank-pdf.js new file mode 100644 index 0000000..33b990a --- /dev/null +++ b/JavaScript/Endpoint Examples/JSON Payload/blank-pdf.js @@ -0,0 +1,32 @@ +var axios = require("axios"); + +// By default, we use the US-based API service. This is the primary endpoint for global use. +var apiUrl = "https://api.pdfrest.com"; + +/* For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below. + * For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work + */ +//var apiUrl = "https://eu-api.pdfrest.com"; + +var config = { + method: "post", + maxBodyLength: Infinity, + url: apiUrl + "/blank-pdf", + headers: { + "Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Replace with your API key + "Content-Type": "application/json", + }, + data: { + page_size: "letter", + page_count: 3, + page_orientation: "portrait", + }, +}; + +axios(config) + .then(function (response) { + console.log(JSON.stringify(response.data)); + }) + .catch(function (error) { + console.log(error); + }); diff --git a/JavaScript/Endpoint Examples/Multipart Payload/blank-pdf.js b/JavaScript/Endpoint Examples/Multipart Payload/blank-pdf.js new file mode 100644 index 0000000..460588e --- /dev/null +++ b/JavaScript/Endpoint Examples/Multipart Payload/blank-pdf.js @@ -0,0 +1,40 @@ +// This request demonstrates how to generate a blank PDF. +var axios = require('axios'); +var FormData = require('form-data'); + +// By default, we use the US-based API service. This is the primary endpoint for global use. +var apiUrl = "https://api.pdfrest.com"; + +/* For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below. + * For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work + */ +//var apiUrl = "https://eu-api.pdfrest.com"; + +// Create a new form data instance and append the required parameters to it +var data = new FormData(); +data.append('page_size', 'letter'); +data.append('page_count', '3'); +data.append('page_orientation', 'portrait'); + +// define configuration options for axios request +var config = { + method: 'post', + maxBodyLength: Infinity, + url: apiUrl + '/blank-pdf', + headers: { + 'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // Replace with your API key + ...data.getHeaders() // set headers for the request + }, + data : data // set the data to be sent with the request +}; + +// send request and handle response or error +axios(config) +.then(function (response) { + console.log(JSON.stringify(response.data)); +}) +.catch(function (error) { + console.log(error); +}); + +// If you would like to download the file instead of getting the JSON response, please see the 'get-resource-id-endpoint.js' sample. diff --git a/PHP/Endpoint Examples/JSON Payload/blank-pdf.php b/PHP/Endpoint Examples/JSON Payload/blank-pdf.php new file mode 100644 index 0000000..8d0ddb8 --- /dev/null +++ b/PHP/Endpoint Examples/JSON Payload/blank-pdf.php @@ -0,0 +1,29 @@ + false]); +$headers = [ + 'api-key' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', + 'Content-Type' => 'application/json' +]; +$body = json_encode([ + 'page_size' => 'letter', + 'page_count' => 3, + 'page_orientation' => 'portrait' +]); + +$request = new Request('POST', $apiUrl.'/blank-pdf', $headers, $body); +$response = $client->sendAsync($request)->wait(); + +echo $response->getBody() . PHP_EOL; diff --git a/PHP/Endpoint Examples/Multipart Payload/blank-pdf.php b/PHP/Endpoint Examples/Multipart Payload/blank-pdf.php new file mode 100644 index 0000000..09aeef1 --- /dev/null +++ b/PHP/Endpoint Examples/Multipart Payload/blank-pdf.php @@ -0,0 +1,42 @@ + 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' // Set the API key in the headers for authentication. +]; + +$options = [ + 'multipart' => [ + [ + 'name' => 'page_size', + 'contents' => 'letter' + ], + [ + 'name' => 'page_count', + 'contents' => '3' + ], + [ + 'name' => 'page_orientation', + 'contents' => 'portrait' + ] + ] +]; + +$request = new Request('POST', $apiUrl.'/blank-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 JSON metadata for the blank PDF. diff --git a/Perl/Endpoint Examples/JSON Payload/blank-pdf.pl b/Perl/Endpoint Examples/JSON Payload/blank-pdf.pl new file mode 100644 index 0000000..ff5ab58 --- /dev/null +++ b/Perl/Endpoint Examples/JSON Payload/blank-pdf.pl @@ -0,0 +1,66 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use utf8; +use FindBin qw($Bin); +use JSON::PP qw(encode_json); +use LWP::UserAgent; +use HTTP::Request; +use Dotenv; + +#! +# What this sample does: +# - Requests a three-page blank PDF using a JSON payload. +# +# Setup (.env): +# - Copy .env.example to .env (Perl folder root) +# - Set PDFREST_API_KEY=your_api_key_here +# - Optional: set PDFREST_URL to override the API region. For EU/GDPR compliance and proximity, use: +# PDFREST_URL=https://eu-api.pdfrest.com +# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work +# +# Usage: +# perl "Endpoint Examples/JSON Payload/blank-pdf.pl" +# +# Output: +# - Prints the API JSON response to stdout. Non-2xx responses exit non-zero. + +binmode STDOUT, ':raw'; +binmode STDERR, ':encoding(UTF-8)'; + +my $env_path = "$Bin/../../.env"; +-e $env_path and Dotenv->load($env_path); + +my $api_key = $ENV{PDFREST_API_KEY} // ''; +if (!$api_key || $api_key =~ /^\s*$/) { + print STDERR "Missing PDFREST_API_KEY in .env or environment\n"; + exit 1; +} + +my $api_base = $ENV{PDFREST_URL} // $ENV{PDFREST_API} // 'https://api.pdfrest.com'; +$api_base =~ s{/+$}{}; + +my $ua = LWP::UserAgent->new( timeout => 60 ); + +my $payload = encode_json({ + page_size => 'letter', + page_count => 3, + page_orientation => 'portrait', +}); + +my $request = HTTP::Request->new('POST', "$api_base/blank-pdf"); +$request->header('api-key' => $api_key); +$request->header('Content-Type' => 'application/json'); +$request->content($payload); + +my $response = $ua->request($request); +print STDOUT $response->decoded_content // ''; + +unless ($response->is_success) { + print STDERR "\nblank-pdf request failed with status " . $response->code . "\n"; + exit 1; +} + +exit 0; + +__END__ diff --git a/Perl/Endpoint Examples/Multipart Payload/blank-pdf.pl b/Perl/Endpoint Examples/Multipart Payload/blank-pdf.pl new file mode 100644 index 0000000..de9c38c --- /dev/null +++ b/Perl/Endpoint Examples/Multipart Payload/blank-pdf.pl @@ -0,0 +1,70 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use utf8; +use FindBin qw($Bin); +use LWP::UserAgent; +use HTTP::Request::Common qw(POST); +use Dotenv; + +#! +# What this sample does: +# - Calls /blank-pdf with multipart/form-data to create a three-page blank PDF. +# +# Setup (.env): +# - Copy .env.example to .env (Perl folder root) +# - Set PDFREST_API_KEY=your_api_key_here +# - Optional: set PDFREST_URL to override the API region. For EU/GDPR compliance and proximity, use: +# PDFREST_URL=https://eu-api.pdfrest.com +# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work +# +# Usage: +# perl "Endpoint Examples/Multipart Payload/blank-pdf.pl" +# +# Output: +# - Prints the API JSON response to stdout. Non-2xx responses exit with a concise message. + +binmode STDOUT, ':raw'; +binmode STDERR, ':encoding(UTF-8)'; + +my $env_path = "$Bin/../../.env"; +-e $env_path and Dotenv->load($env_path); + +my $api_key = $ENV{PDFREST_API_KEY} // ''; +if (!$api_key || $api_key =~ /^\s*$/) { + print STDERR "Missing PDFREST_API_KEY in .env or environment\n"; + exit 1; +} + +my $api_base = $ENV{PDFREST_URL} // $ENV{PDFREST_API} // 'https://api.pdfrest.com'; +$api_base =~ s{/+$}{}; + +my $ua = LWP::UserAgent->new( timeout => 60 ); + +eval { + my $req = POST( + "$api_base/blank-pdf", + 'Content_Type' => 'form-data', + 'Content' => [ + page_size => 'letter', + page_count => '3', + page_orientation => 'portrait', + ] + ); + $req->header('api-key' => $api_key); + + my $resp = $ua->request($req); + print STDOUT $resp->decoded_content // ''; + if (!$resp->is_success) { + print STDERR "\nblank-pdf request failed with status " . $resp->code . "\n"; + exit 1; + } + 1; +} or do { + my $err = $@ || 'Unknown error'; + $err =~ s/\s+$//; + print STDERR "Error: $err\n"; + exit 1; +}; + +__END__ diff --git a/Python/Endpoint Examples/JSON Payload/blank-pdf.py b/Python/Endpoint Examples/JSON Payload/blank-pdf.py new file mode 100644 index 0000000..7afc90c --- /dev/null +++ b/Python/Endpoint Examples/JSON Payload/blank-pdf.py @@ -0,0 +1,35 @@ +import requests +import json + +# By default, we use the US-based API service. This is the primary endpoint for global use. +api_url = "https://api.pdfrest.com" + +# For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below. +# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work +#api_url = "https://eu-api.pdfrest.com" + +blank_pdf_data = { + "page_size": "letter", + "page_count": 3, + "page_orientation": "portrait" +} + +print("Requesting blank PDF...") +response = requests.post( + url=api_url + '/blank-pdf', + data=json.dumps(blank_pdf_data), + headers={ + 'Content-Type': 'application/json', + 'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place your api key here + } +) + +print("Response status code: " + str(response.status_code)) + +if response.ok: + response_json = response.json() + print(json.dumps(response_json, indent=2)) +else: + print(response.text) + +# If you would like to download the file instead of getting the JSON response, please see the 'get-resource.py' sample. diff --git a/Python/Endpoint Examples/Multipart Payload/blank-pdf.py b/Python/Endpoint Examples/Multipart Payload/blank-pdf.py new file mode 100644 index 0000000..fee4633 --- /dev/null +++ b/Python/Endpoint Examples/Multipart Payload/blank-pdf.py @@ -0,0 +1,41 @@ +from requests_toolbelt import MultipartEncoder +import requests +import json + +# By default, we use the US-based API service. This is the primary endpoint for global use. +api_url = "https://api.pdfrest.com" + +# For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below. +# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work +#api_url = "https://eu-api.pdfrest.com" + +blank_pdf_endpoint_url = api_url + '/blank-pdf' + +# The /blank-pdf endpoint generates an empty PDF, so no file upload is required. +mp_encoder_blank_pdf = MultipartEncoder( + fields={ + 'page_size': 'letter', + 'page_count': '3', + 'page_orientation': 'portrait', + } +) + +# Let's set the headers that the blank-pdf endpoint expects. +headers = { + 'Accept': 'application/json', + 'Content-Type': mp_encoder_blank_pdf.content_type, + 'Api-Key': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # place your api key here +} + +print("Sending POST request to blank-pdf endpoint...") +response = requests.post(blank_pdf_endpoint_url, data=mp_encoder_blank_pdf, headers=headers) + +print("Response status code: " + str(response.status_code)) + +if response.ok: + response_json = response.json() + print(json.dumps(response_json, indent=2)) +else: + print(response.text) + +# If you would like to download the file instead of getting the JSON response, please see the 'get-resource-multipart.py' sample. diff --git a/R/Endpoint Examples/JSON Payload/blank-pdf.R b/R/Endpoint Examples/JSON Payload/blank-pdf.R new file mode 100644 index 0000000..2345bad --- /dev/null +++ b/R/Endpoint Examples/JSON Payload/blank-pdf.R @@ -0,0 +1,53 @@ +#! +# What this sample does: +# - Calls /blank-pdf with a JSON payload to create an empty three-page PDF. +# +# Setup (.Renviron): +# - Copy .Renviron.example to .Renviron (R folder root) +# - Set PDFREST_API_KEY=your_api_key_here +# - Optional: set PDFREST_URL to override the API region. For EU/GDPR compliance and proximity, use: +# PDFREST_URL=https://eu-api.pdfrest.com +# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work +# +# Usage: +# Rscript "Endpoint Examples/JSON Payload/blank-pdf.R" +# +# Output: +# - Prints the API JSON response to stdout. Non-2xx responses quit with a concise message. + +suppressWarnings(suppressMessages({ + if (!requireNamespace("httr", quietly = TRUE)) stop("Please install 'httr' package") + if (!requireNamespace("jsonlite", quietly = TRUE)) stop("Please install 'jsonlite' package") +})) + +stderrf <- function(...) cat(sprintf(...), file = stderr()) + +api_key <- Sys.getenv("PDFREST_API_KEY", unset = "") +if (identical(api_key, "")) { + stderrf("Missing PDFREST_API_KEY in environment (.Renviron or shell)\n") + quit(status = 1) +} + +api_base <- sub("/+$", "", Sys.getenv("PDFREST_URL", unset = "https://api.pdfrest.com")) + +payload <- jsonlite::toJSON( + list(page_size = "letter", page_count = 3, page_orientation = "portrait"), + auto_unbox = TRUE +) + +resp <- httr::POST( + paste0(api_base, "/blank-pdf"), + httr::add_headers( + "api-key" = api_key, + "Content-Type" = "application/json" + ), + body = payload +) + +body_text <- httr::content(resp, as = "text", encoding = "UTF-8") +cat(body_text) + +if (httr::http_error(resp)) { + stderrf("\nblank-pdf request failed with status %s\n", httr::status_code(resp)) + quit(status = 1) +} diff --git a/R/Endpoint Examples/Multipart Payload/blank-pdf.R b/R/Endpoint Examples/Multipart Payload/blank-pdf.R new file mode 100644 index 0000000..e07016e --- /dev/null +++ b/R/Endpoint Examples/Multipart Payload/blank-pdf.R @@ -0,0 +1,51 @@ +#! +# What this sample does: +# - Calls /blank-pdf via multipart/form-data to create a blank three-page PDF. +# +# Setup (.Renviron): +# - Copy .Renviron.example to .Renviron (R folder root) +# - Set PDFREST_API_KEY=your_api_key_here +# - Optional: set PDFREST_URL to override the API region. For EU/GDPR compliance and proximity, use: +# PDFREST_URL=https://eu-api.pdfrest.com +# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work +# +# Usage: +# Rscript "Endpoint Examples/Multipart Payload/blank-pdf.R" +# +# Output: +# - Prints the API JSON response to stdout. Non-2xx responses quit with a concise message. + +suppressWarnings(suppressMessages({ + if (!requireNamespace("httr", quietly = TRUE)) stop("Please install 'httr' package") +})) + +stderrf <- function(...) cat(sprintf(...), file = stderr()) + +api_key <- Sys.getenv("PDFREST_API_KEY", unset = "") +if (identical(api_key, "")) { + stderrf("Missing PDFREST_API_KEY in environment (.Renviron or shell)\n") + quit(status = 1) +} + +api_base <- sub("/+$", "", Sys.getenv("PDFREST_URL", unset = "https://api.pdfrest.com")) + +body <- list( + page_size = "letter", + page_count = "3", + page_orientation = "portrait" +) + +resp <- httr::POST( + paste0(api_base, "/blank-pdf"), + httr::add_headers("api-key" = api_key), + body = body, + encode = "multipart" +) + +txt <- httr::content(resp, as = "text", encoding = "UTF-8") +cat(txt) + +if (httr::http_error(resp)) { + stderrf("\nblank-pdf request failed with status %s\n", httr::status_code(resp)) + quit(status = 1) +} diff --git a/Ruby/Endpoint Examples/JSON Payload/blank-pdf.rb b/Ruby/Endpoint Examples/JSON Payload/blank-pdf.rb new file mode 100644 index 0000000..1ca05c0 --- /dev/null +++ b/Ruby/Endpoint Examples/JSON Payload/blank-pdf.rb @@ -0,0 +1,44 @@ +#! +# What this sample does: +# - Requests a blank three-page PDF using a JSON payload. +# +# Setup (.env): +# - Copy .env.example to .env +# - Set PDFREST_API_KEY=your_api_key_here +# - Optional: set PDFREST_URL to override the API region. For EU/GDPR compliance and proximity, use: +# PDFREST_URL=https://eu-api.pdfrest.com +# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work +# +# Usage: +# ruby "Endpoint Examples/JSON Payload/blank-pdf.rb" +# +# Output: +# - Prints the API JSON response to stdout. Non-2xx responses abort with a concise message. + +require "json" +require "faraday" +require "faraday/retry" +require "dotenv" + +Dotenv.load + +API_KEY = ENV["PDFREST_API_KEY"] +abort("Missing PDFREST_API_KEY in .env") if API_KEY.nil? || API_KEY.strip.empty? + +API_BASE = (ENV["PDFREST_URL"] || ENV["PDFREST_API"] || "https://api.pdfrest.com").sub(%r{/+$}, "") + +conn = Faraday.new(url: API_BASE) do |f| + f.request :retry, max: 2, interval: 0.2 + f.adapter Faraday.default_adapter +end + +payload = { page_size: "letter", page_count: 3, page_orientation: "portrait" }.to_json + +response = conn.post("/blank-pdf") do |req| + req.headers["api-key"] = API_KEY + req.headers["Content-Type"] = "application/json" + req.body = payload +end + +puts response.body +abort("blank-pdf request failed with status #{response.status}") unless response.success? diff --git a/VB.NET/Endpoint Examples/JSON Payload/blank-pdf.vb b/VB.NET/Endpoint Examples/JSON Payload/blank-pdf.vb new file mode 100644 index 0000000..55f2f8d --- /dev/null +++ b/VB.NET/Endpoint Examples/JSON Payload/blank-pdf.vb @@ -0,0 +1,78 @@ +''' +' What this sample does: +' - Calls /blank-pdf with a JSON payload to create a three-page blank PDF. +' +' Setup (environment): +' - Copy .env.example to .env +' - Set PDFREST_API_KEY=your_api_key_here +' - Optional: set PDFREST_URL to override the API region. For EU/GDPR compliance and proximity, use: +' PDFREST_URL=https://eu-api.pdfrest.com +' For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work +' +' Usage (via dispatcher): +' dotnet run -- blank-pdf +' +' Output: +' - Prints the API JSON response to stdout. Non-2xx responses write a concise message to stderr and exit non-zero. +''' + +Option Strict On +Option Explicit On + +Imports System +Imports System.Net.Http +Imports System.Net.Http.Headers +Imports System.Text +Imports System.Text.Json +Imports System.Threading.Tasks + +Namespace VBNetSamples.Endpoint_Examples.JSON_Payload + Module BlankPdf + Public Async Function Execute(args As String()) As Task + Dim apiKey As String = Environment.GetEnvironmentVariable("PDFREST_API_KEY") + If String.IsNullOrWhiteSpace(apiKey) Then + Console.Error.WriteLine("Missing environment variable PDFREST_API_KEY.") + Environment.Exit(1) + End If + + Dim baseUrl As String = Environment.GetEnvironmentVariable("PDFREST_URL") + If String.IsNullOrWhiteSpace(baseUrl) Then baseUrl = "https://api.pdfrest.com" + + Dim baseUri As Uri + Try + baseUri = New Uri(baseUrl) + Catch ex As Exception + Console.Error.WriteLine($"Invalid PDFREST_URL: {baseUrl}") + Environment.Exit(1) + Return + End Try + + Using httpClient As New HttpClient() + httpClient.BaseAddress = baseUri + + Dim request As New HttpRequestMessage(HttpMethod.Post, "blank-pdf") + request.Headers.TryAddWithoutValidation("Api-Key", apiKey) + request.Headers.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json")) + + Dim payload = New With { + .page_size = "letter", + .page_count = 3, + .page_orientation = "portrait" + } + Dim payloadJson As String = JsonSerializer.Serialize(payload) + request.Content = New StringContent(payloadJson, Encoding.UTF8, "application/json") + + Dim response As HttpResponseMessage = Await httpClient.SendAsync(request) + Dim responseBody As String = Await response.Content.ReadAsStringAsync() + + If Not response.IsSuccessStatusCode Then + Console.Error.WriteLine($"blank-pdf request failed: {CInt(response.StatusCode)} {response.ReasonPhrase}") + Console.Error.WriteLine(responseBody) + Environment.Exit(1) + End If + + Console.WriteLine(responseBody) + End Using + End Function + End Module +End Namespace diff --git a/VB.NET/Endpoint Examples/Multipart Payload/blank-pdf.vb b/VB.NET/Endpoint Examples/Multipart Payload/blank-pdf.vb new file mode 100644 index 0000000..5425820 --- /dev/null +++ b/VB.NET/Endpoint Examples/Multipart Payload/blank-pdf.vb @@ -0,0 +1,74 @@ +''' +' What this sample does: +' - Calls /blank-pdf with multipart/form-data to create a three-page blank PDF. +' +' Setup (environment): +' - Copy .env.example to .env +' - Set PDFREST_API_KEY=your_api_key_here +' - Optional: set PDFREST_URL to override the API region. For EU/GDPR compliance and proximity, use: +' PDFREST_URL=https://eu-api.pdfrest.com +' For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work +' +' Usage (via dispatcher): +' dotnet run -- blank-pdf-multipart +' +' Output: +' - Prints the API JSON response to stdout. Non-2xx responses write a concise message to stderr and exit non-zero. +''' + +Option Strict On +Option Explicit On + +Imports System +Imports System.Net.Http +Imports System.Net.Http.Headers +Imports System.Text +Imports System.Threading.Tasks + +Namespace VBNetSamples.Endpoint_Examples.Multipart_Payload + Module BlankPdf + Public Async Function Execute(args As String()) As Task + Dim apiKey As String = Environment.GetEnvironmentVariable("PDFREST_API_KEY") + If String.IsNullOrWhiteSpace(apiKey) Then + Console.Error.WriteLine("Missing environment variable PDFREST_API_KEY.") + Environment.Exit(1) + End If + + Dim baseUrl As String = Environment.GetEnvironmentVariable("PDFREST_URL") + If String.IsNullOrWhiteSpace(baseUrl) Then baseUrl = "https://api.pdfrest.com" + + Dim baseUri As Uri + Try + baseUri = New Uri(baseUrl) + Catch ex As Exception + Console.Error.WriteLine($"Invalid PDFREST_URL: {baseUrl}") + Environment.Exit(1) + Return + End Try + + Using httpClient As New HttpClient() + httpClient.BaseAddress = baseUri + + Dim multipart As New MultipartFormDataContent() + multipart.Add(New StringContent("letter", Encoding.UTF8), "page_size") + multipart.Add(New StringContent("3", Encoding.UTF8), "page_count") + multipart.Add(New StringContent("portrait", Encoding.UTF8), "page_orientation") + + Dim req As New HttpRequestMessage(HttpMethod.Post, "blank-pdf") + req.Headers.TryAddWithoutValidation("Api-Key", apiKey) + req.Headers.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json")) + req.Content = multipart + + Dim resp As HttpResponseMessage = Await httpClient.SendAsync(req) + Dim body As String = Await resp.Content.ReadAsStringAsync() + If Not resp.IsSuccessStatusCode Then + Console.Error.WriteLine($"blank-pdf (multipart) failed: {CInt(resp.StatusCode)} {resp.ReasonPhrase}") + Console.Error.WriteLine(body) + Environment.Exit(1) + End If + + Console.WriteLine(body) + End Using + End Function + End Module +End Namespace diff --git a/VB.NET/Program.vb b/VB.NET/Program.vb index 00c23bd..f35b4e4 100644 --- a/VB.NET/Program.vb +++ b/VB.NET/Program.vb @@ -52,6 +52,8 @@ Module Program Await VBNetSamples.Endpoint_Examples.JSON_Payload.Markdown.Execute(rest) Case "rasterized-pdf", "rasterize-json" Await VBNetSamples.Endpoint_Examples.JSON_Payload.RasterizedPdf.Execute(rest) + Case "blank-pdf" + Await VBNetSamples.Endpoint_Examples.JSON_Payload.BlankPdf.Execute(rest) Case "summarized-pdf-text" Await VBNetSamples.Endpoint_Examples.JSON_Payload.SummarizedPdfText.Execute(rest) Case "translated-pdf-text" @@ -60,6 +62,8 @@ Module Program Await VBNetSamples.Endpoint_Examples.Multipart_Payload.Markdown.Execute(rest) Case "rasterized-pdf-multipart", "rasterize-multipart" Await VBNetSamples.Endpoint_Examples.Multipart_Payload.RasterizedPdf.Execute(rest) + Case "blank-pdf-multipart" + Await VBNetSamples.Endpoint_Examples.Multipart_Payload.BlankPdf.Execute(rest) Case "summarized-pdf-text-multipart" Await VBNetSamples.Endpoint_Examples.Multipart_Payload.SummarizedPdfText.Execute(rest) Case "translated-pdf-text-multipart" @@ -81,10 +85,12 @@ Module Program Console.Error.WriteLine("Commands:") Console.Error.WriteLine(" markdown | markdown-json Upload then convert to Markdown (JSON two-step)") Console.Error.WriteLine(" rasterized-pdf | rasterize-json Upload then rasterize PDF (JSON two-step)") + Console.Error.WriteLine(" blank-pdf Generate an empty PDF (JSON request)") Console.Error.WriteLine(" summarized-pdf-text Upload then summarize text (JSON two-step)") Console.Error.WriteLine(" translated-pdf-text Upload then translate text (JSON two-step)") Console.Error.WriteLine(" markdown-multipart Convert to Markdown (single multipart request)") Console.Error.WriteLine(" rasterized-pdf-multipart Rasterize PDF (single multipart request)") + Console.Error.WriteLine(" blank-pdf-multipart Generate an empty PDF (multipart request)") Console.Error.WriteLine(" summarized-pdf-text-multipart Summarize text (single multipart request)") Console.Error.WriteLine(" translated-pdf-text-multipart Translate text (single multipart request)") Console.Error.WriteLine(" merge-different-file-types|merge Merge PDFs and non-PDFs into one PDF") diff --git a/cURL/Endpoint Examples/JSON Payload/blank-pdf.sh b/cURL/Endpoint Examples/JSON Payload/blank-pdf.sh new file mode 100755 index 0000000..1e67460 --- /dev/null +++ b/cURL/Endpoint Examples/JSON Payload/blank-pdf.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# By default, we use the US-based API service. This is the primary endpoint for global use. +API_URL="https://api.pdfrest.com" + +# For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below. +# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work +# API_URL="https://eu-api.pdfrest.com" + +curl "$API_URL/blank-pdf" \ +--header 'Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' \ +--header 'Content-Type: application/json' \ +--data-raw '{ "page_size": "letter", "page_count": 3, "page_orientation": "portrait" }' | jq -r '.' diff --git a/cURL/Endpoint Examples/Multipart Payload/blank-pdf.sh b/cURL/Endpoint Examples/Multipart Payload/blank-pdf.sh new file mode 100755 index 0000000..ce2a400 --- /dev/null +++ b/cURL/Endpoint Examples/Multipart Payload/blank-pdf.sh @@ -0,0 +1,13 @@ +# By default, we use the US-based API service. This is the primary endpoint for global use. +API_URL="https://api.pdfrest.com" + +# For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below. +# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work +# API_URL="https://eu-api.pdfrest.com" + +curl -X POST "$API_URL/blank-pdf" \ + -H "Accept: application/json" \ + -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ + -F "page_size=letter" \ + -F "page_count=3" \ + -F "page_orientation=portrait"