### NodeJS (axios) Authentication Example Source: https://pdfendpoint.com/docs/authentication Example of how to authenticate an API request using NodeJS and axios by including the Authorization header with a Bearer token. ```APIDOC ## POST /v1/convert ### Description This endpoint converts HTML to a PDF document. Authentication is required. ### Method POST ### Endpoint https://api.pdfendpoint.com/v1/convert ### Headers - **Content-Type** (string) - Required - application/json - **Authorization** (string) - Required - Bearer ### Request Body - **html** (string) - Required - The HTML content to convert. ### Request Example ```json { "html": "

Successfully Authenticated

" } ``` ### Response #### Success Response (200) - **data** (object) - The response data from the conversion. ``` -------------------------------- ### Example HTTP Headers JSON Source: https://pdfendpoint.com/docs/misc/http-headers Pass custom headers as a JSON object to the http_headers parameter. This example shows how to set an Authorization header. ```json { "Authorization": "Bearer 1234567890" } ``` -------------------------------- ### Example API Error Response Source: https://pdfendpoint.com/docs/error-codes This is an example of an error response from the API. Use the `error.code` to look up specific error details on this page. ```json { "request_id": "ad67fee1-df63-4453-9dcf-020f457a6178", "success": false, "billed": false, "billed_units": 0, "error": { "code": "PE-A003", "status": 403, "message": "Provided token is invalid or expired", "description": "Make sure you have copied the token correctly from the dashboard.", "link": null, "support_email": "support@pdfendpoint.com" } } ``` -------------------------------- ### Passing Cookies as JSON Source: https://pdfendpoint.com/docs/misc/cookies Example of how to format the http_cookies parameter as a JSON object. ```json { "session_id": "1234567890" } ``` -------------------------------- ### Node.js (axios) Authentication Example Source: https://pdfendpoint.com/docs/authentication Use this Node.js snippet with axios to make authenticated API requests. Ensure your 'Authorization' header contains your Bearer token. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "html": "

Successfully Authenticated

" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Make a POST request to convert HTML to PDF using Node.js (axios) Source: https://pdfendpoint.com/docs Use this snippet to make a POST request to the pdfEndpoint API to convert HTML content to a PDF file. Ensure you replace 'SIGN-UP-FOR-KEY' with your actual API key. This example uses the axios library for making HTTP requests. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "html": "Getting Started

Wohoo this works

You rock :) and thank you for trying pdfEndpoint

" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Inline Delivery Mode Request and Save Source: https://pdfendpoint.com/docs/delivery-mode This Node.js/Javascript example demonstrates how to make a request with the 'inline' delivery mode and save the PDF response as an array buffer file. ```javascript const fs = require("fs"); const axios = require("axios"); const options = { method: "POST", url: "https://api.pdfendpoint.com/v1/convert", headers: { "Content-Type": "application/json", Authorization: "Bearer YOUR_API_KEY", }, data: { url: "https://www.spacejam.com/1996/", orientation: "vertical", page_size: "A4", "use_print_media ": true, wait_for_network: true, delivery_mode: "inline", }, responseType: "arraybuffer", }; let response = await axios(options); fs.writeFileSync( "./test.pdf", response.data ); ``` -------------------------------- ### Set Custom Header and Footer Text Source: https://pdfendpoint.com/docs/misc/header-footer Use header_text and footer_text to add dynamic content like page numbers and titles. Configure alignment and starting page for headers and footers. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "html": "Header & Footer

Header & Footer

Example

", "header_text": "{{title}}", "footer_text": "Page {{pageNum}} of {{totalPages}}", "header_align": "center", "footer_align": "right", "header_start_at": 1, "footer_start_at": 1 }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### NodeJS Axios Request with Custom Headers Source: https://pdfendpoint.com/docs/misc/http-headers This Node.js example demonstrates how to use the axios library to send a POST request to the PDF endpoint API. It includes setting custom HTTP headers for the request and passing additional headers to the website being rendered via the http_headers parameter. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://de.wikipedia.org/wiki/Portable_Document_Format", "http_headers": "{ \"Authorization\": \"Bearer 1234567890\", \"Cache-Control\":\"no-cache\" }" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Encrypt PDF with Node.js (axios) Source: https://pdfendpoint.com/docs/misc/encryption Use this snippet to encrypt a PDF generated from HTML content. It demonstrates setting encryption parameters like owner password, user password, and various rights to none. Ensure you have axios installed and replace 'SIGN-UP-FOR-KEY' with your actual API key. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "html": "PDF Endpoint

Hello World!

", "encrypt": true, "owner_password": "owner_password", "user_password": "user_password", "encryption_print_rights": "none", "encryption_modify_rights": "none", "encryption_copy_rights": "none" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Inject CSS into HTML for PDF Conversion (NodeJS) Source: https://pdfendpoint.com/docs/document/inject-css-js Use the `css` parameter to inject custom styles that modify the appearance of the HTML before PDF conversion. This example hides specific elements on a Wikipedia page. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://de.wikipedia.org/wiki/Portable_Document_Format", "css": ".vector-menu-content{ display:none !important; } .vector-toc-pinned-container{ display:none !important; height:0px; overflow:hidden; } .mw-table-of-contents-container{ display:none !important; } " }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Convert URL to PDF with Image Compression (NodeJS) Source: https://pdfendpoint.com/docs/file-size Use this snippet to convert a webpage to a PDF while applying image compression and resizing. Set `image_compression_quality` to a value between 0 and 100 for compression, and `image_compression_width` to resize images larger than the specified width. Alpha channels are preserved. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://www.spacejam.com/1996/", "image_compression_quality": 30, "image_compression_width": 800 }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### List Created PDFs with Axios (Node.js) Source: https://pdfendpoint.com/docs/endpoints Use this snippet to retrieve a list of your created PDFs. Ensure you replace 'SIGN-UP-FOR-KEY' with your actual API key. The query parameters allow filtering by date range, limit, and page number. ```javascript const axios = require("axios"); const options = { "method": "GET", "url": "https://api.pdfendpoint.com/v1/list?from=2023-01-01&to=2023-01-20&limit=100&page=1", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({}) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Convert HTML with Liquid Templates to PDF using Node.js (Axios) Source: https://pdfendpoint.com/docs/document/html This snippet demonstrates converting HTML with Liquid templates to PDF. Set `parse_liquid` to `true` and provide dynamic data via `liquid_data`. The `liquid_data` parameter must be a JSON string where keys match Liquid placeholders. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "html": "PDF Endpoint

{{title}}

", "parse_liquid": true, "liquid_data": "{\"title\": \"Hello, Liquid World!\"}" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Inject JavaScript to Modify HTML for PDF Conversion (NodeJS) Source: https://pdfendpoint.com/docs/document/inject-css-js Use the `js` parameter to inject JavaScript code that modifies the HTML content before PDF conversion. This example changes the text of an H1 element. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "html": "PDF Endpoint

This will be replaced

", "js": "document.querySelector(\"h1\").textContent=\"Hello World!\";" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### NodeJS Basic HTTP Authentication with Axios Source: https://pdfendpoint.com/docs/misc/web-authentication Use this snippet to perform basic HTTP authentication when converting a URL to PDF. Ensure the website uses basic HTTP authentication and not other methods like OAuth or cookies. The `auth_user` and `auth_password` parameters must be passed as strings. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://authenticationtest.com/HTTPAuth/", "auth_user": "user", "auth_password": "pass" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Enable Print Media Styles Source: https://pdfendpoint.com/docs/document/page-setup Set the 'print_media' parameter to 'true' to apply CSS @media print styles, allowing for customized print layouts. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://www.spacejam.com/1996/", "print_media": "true" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Set Browser Options with Axios in Node.js Source: https://pdfendpoint.com/docs/misc/browser-options Use this snippet to configure browser options such as user agent, accept language, and accept encoding when converting a URL to PDF using the pdfEndpoint API with Axios in Node.js. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://www.spacejam.com/1996/", "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36", "accept_language": "en-US", "accept_encoding": "utf-8" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### PDF Conversion Endpoint Source: https://pdfendpoint.com/docs/endpoints This is the main endpoint for converting documents to PDF. It takes a request and returns the generated PDF. ```APIDOC ## POST /v1/convert ### Description This is the main endpoint you will be using with pdfEndpoint. This endpoint creates the pdf and returns the result. ### Method POST ### Endpoint https://api.pdfendpoint.com/v1/convert ``` -------------------------------- ### Convert HTML with Liquid Templating to PDF Source: https://pdfendpoint.com/docs/document/html This snippet shows how to convert HTML containing Liquid templates to a PDF. It includes enabling Liquid parsing and providing dynamic data to replace template placeholders. ```APIDOC ## POST /v1/convert with Liquid ### Description Converts provided HTML content, including Liquid templates, into a PDF document. Allows dynamic content injection via `liquid_data`. ### Method POST ### Endpoint https://api.pdfendpoint.com/v1/convert ### Parameters #### Request Body - **html** (string) - Required - The HTML content to convert, potentially containing Liquid templates (e.g., `{{ variable }}`). - **parse_liquid** (boolean) - Optional - Defaults to `false`. If `true`, the API will parse Liquid templates in the `html` content. - **liquid_data** (string) - Optional - A JSON string containing data to replace Liquid template placeholders. Requires `parse_liquid` to be `true`. ### Request Example ```json { "html": "PDF Endpoint

{{title}}

", "parse_liquid": true, "liquid_data": "{\"title\": \"Hello, Liquid World!\"}" } ``` ### Response #### Success Response (200) - **data** (string) - The PDF document in base64 encoded format or a URL to the PDF. #### Response Example ```json { "data": "JVBERi0xLjQKJc..." } ``` ``` -------------------------------- ### Configure S3 Bucket Permissions Source: https://pdfendpoint.com/docs/delivery-mode Set IAM permissions for an S3 bucket to allow only writes with bucket owner full control. Ensure the AWS principal ARN matches the delivery@pdfendpoint.com user. ```json { "Version": "2012-10-17", "Statement": [{ "Sid": "Only allow writes to this bucket with bucket owner full control", "Effect": "Allow", "Principal": { "AWS": ["arn:aws:iam::529154080746:user/delivery@pdfendpoint.com"] }, "Action": ["s3:PutObject"], "Resource": "arn:aws:s3:::EXAMPLE-BUCKET-MUST-EDIT/*", "Condition": { "StringEquals": { "s3:x-amz-acl": "bucket-owner-full-control" } } }] } ``` -------------------------------- ### Convert HTML to PDF using Node.js (Axios) Source: https://pdfendpoint.com/docs/document/html Use this snippet to convert a basic HTML string to a PDF. Ensure the HTML includes `head`, `title`, and `body` tags. The HTML content must be UTF-8 encoded and passed as a string. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "html": "PDF Endpoint

Hello World

" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Convert HTML to PDF Source: https://pdfendpoint.com/docs/document/html This snippet demonstrates how to convert basic HTML content to a PDF using the API. The HTML must include head, title, and body tags. Ensure the HTML is UTF-8 encoded and passed as a string. The 'html' parameter is mutually exclusive with the 'url' parameter. ```APIDOC ## POST /v1/convert ### Description Converts provided HTML content into a PDF document. ### Method POST ### Endpoint https://api.pdfendpoint.com/v1/convert ### Parameters #### Request Body - **html** (string) - Required - The HTML content to convert. Must include `head`, `title`, and `body` tags. Must be UTF-8 encoded. ### Request Example ```json { "html": "PDF Endpoint

Hello World

" } ``` ### Response #### Success Response (200) - **data** (string) - The PDF document in base64 encoded format or a URL to the PDF, depending on the API configuration. #### Response Example ```json { "data": "JVBERi0xLjQKJc..." } ``` ``` -------------------------------- ### Health Endpoint Source: https://pdfendpoint.com/docs/endpoints Check the current system status to ensure all services are operational. ```APIDOC ## GET /health ### Description Want to know if our system are all good? Use this endpoint to get the current system status. ### Method GET ### Endpoint https://api.pdfendpoint.com/health ``` -------------------------------- ### Specify Pages to Print Source: https://pdfendpoint.com/docs/document/page-setup Use the 'print_pages' parameter to select specific pages or page ranges for printing. Supports formats like 'x-y' and comma-separated lists. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://www.spacejam.com/1996/", "print_pages": "2-5,7,9-12" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Viewport Configuration Source: https://pdfendpoint.com/docs/document/page-setup Set the dimensions of the viewport used to render the webpage. This affects the rendering size but not the final PDF document size. ```APIDOC ## Viewport Configuration ### Description Set the dimensions of the viewport used to render the webpage. This can be useful to ensure specific elements are visible or hidden, especially on responsive sites. ### Method POST ### Endpoint /v1/convert ### Parameters #### Request Body - **url** (string) - Required - The URL of the webpage to convert. - **viewport** (string) - Optional - The dimensions of the viewport in the format "WIDTHxHEIGHT" (e.g., "1900x900"). ``` -------------------------------- ### Configure PDF Appearance with Axios Source: https://pdfendpoint.com/docs/document/appearance-options Use this configuration with Axios to customize PDF appearance by disabling images, links, backgrounds, JavaScript, blank pages, CSS, ads, and forms. Ensure the API endpoint and authorization are correctly set. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://www.spacejam.com/1996/", "scroll_whole_page": true, "no_images": true, "no_links": true, "no_backgrounds": true, "no_javascript": true, "no_blank_pages": true, "no_css": true, "no_ads": true, "no_forms": true }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Inline Delivery Mode (Direct Download) Source: https://pdfendpoint.com/docs/delivery-mode The PDF data is sent as an array buffer with `Content-Type: application/pdf`. Allows direct server-side saving without intermediate download. ```APIDOC ## Inline Delivery Mode (Direct Download) ### Description The inline delivery mode sends the PDF data as an array buffer with the `Content-Type` header set to `application/pdf`. This allows you to directly store the PDF on your server without first creating the PDF and then downloading it from the storage URL. ### Request Example ```javascript const fs = require("fs"); const axios = require("axios"); const options = { method: "POST", url: "https://api.pdfendpoint.com/v1/convert", headers: { "Content-Type": "application/json", Authorization: "Bearer YOUR_API_KEY", }, data: { url: "https://www.spacejam.com/1996/", orientation: "vertical", page_size: "A4", "use_print_media ": true, wait_for_network: true, delivery_mode: "inline", }, responseType: "arraybuffer", }; let response = await axios(options); fs.writeFileSync( "./test.pdf", response.data ); ``` ``` -------------------------------- ### Upload PDF to S3 using NodeJS (axios) Source: https://pdfendpoint.com/docs/delivery-mode Use the S3 delivery mode to upload generated PDFs directly to an S3 bucket. Provide bucket credentials or rely on an attached IAM role. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://www.spacejam.com/1996/", "delivery_mode": "s3", "s3_bucket_name": "aws-test-bucket", "s3_bucket_key": "aws-test-bucket-key", "s3_bucket_secret": "aws-test-bucket-secret" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Google Storage Delivery Mode Source: https://pdfendpoint.com/docs/delivery-mode Upload the generated PDF to a Google Cloud Storage bucket. Requires service account credentials. ```APIDOC ## POST /v1/convert ### Description Uploads a generated PDF to a Google Cloud Storage bucket. ### Method POST ### Endpoint /v1/convert ### Request Body - **url** (string) - Required - The URL of the webpage to convert. - **delivery_mode** (string) - Required - Set to "google_storage" for Google Storage delivery. - **gcp_project_id** (string) - Required - Your Google Cloud project ID. - **gcp_user_email** (string) - Required - The email address of the service account. - **gcp_private_key** (string) - Required - The private key of the service account. - **gcp_bucket_name** (string) - Required - The name of the Google Cloud Storage bucket. - **filename** (string) - Optional - The desired path and filename for the PDF within the bucket. ### Request Example ```json { "url": "https://www.spacejam.com/1996/", "delivery_mode": "google_storage", "gcp_project_id": "gcp-test-bucket", "gcp_user_email": "gcp-test-bucket-key", "gcp_private_key": "gcp-test-bucket-secret", "gcp_bucket_name": "gcp-test-bucket-secret", "filename": "invoices/invoice.pdf" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. - **delivery_id** (string) - Unique identifier for the delivery task. ``` -------------------------------- ### NodeJS (axios) - Convert URL with Cookies Source: https://pdfendpoint.com/docs/misc/cookies This snippet demonstrates how to use the axios library in NodeJS to make a POST request to the PDF Endpoint API, including custom cookies in the request data. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://de.wikipedia.org/wiki/Portable_Document_Format", "http_cookies": "{ \"session_id\": \"1234567890\", \"token\":\"abcd\" }" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Page Size Configuration Source: https://pdfendpoint.com/docs/document/page-setup Specify the size of the PDF page using standard names or custom dimensions. ```APIDOC ## Page Size Configuration ### Description Set the size of the PDF page. You can use standard paper sizes or define custom dimensions with specified units. ### Method POST ### Endpoint /v1/convert ### Parameters #### Request Body - **url** (string) - Required - The URL of the webpage to convert. - **page_size** (string) - Optional - Standard page size (e.g., "A4", "Letter", "Folio"). - **page_width** (string) - Optional - Custom page width with unit (e.g., "210mm", "8.5in"). - **page_height** (string) - Optional - Custom page height with unit (e.g., "297mm", "11in"). Supported units for custom dimensions: "mm", "cm", "in", "px". ``` -------------------------------- ### Convert URL with Browser Location (Node.js Axios) Source: https://pdfendpoint.com/docs/misc/browser-location Use the Axios library in Node.js to send a POST request to the PDF endpoint, including browser location parameters for accurate rendering. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://www.infobyip.com/browsergeolocation.php", "location_accuracy": 10, "location_lat": "48.210033", "location_lng": "16.363449" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Webhook Delivery Mode Source: https://pdfendpoint.com/docs/delivery-mode Send a POST request to a specified URL when the PDF generation is complete. ```APIDOC ## POST /v1/convert ### Description Sends a POST request to a specified webhook URL once the PDF generation is complete. ### Method POST ### Endpoint /v1/convert ### Request Body - **url** (string) - Required - The URL of the webpage to convert. - **delivery_mode** (string) - Required - Set to "webhook" for webhook delivery. - **webhook_endpoint** (string) - Required - The URL to send the POST request to. ### Request Example ```json { "url": "https://www.spacejam.com/1996/", "delivery_mode": "webhook", "webhook_endpoint": "https://your-webhook-endpoint.com/pdf-ready" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. - **delivery_id** (string) - Unique identifier for the delivery task. ``` -------------------------------- ### Send PDF Completion Notification via Webhook using NodeJS (axios) Source: https://pdfendpoint.com/docs/delivery-mode Configure the webhook delivery mode to receive a POST request at a specified URL when PDF generation is complete. The request will contain a download URL for the generated PDF. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://www.spacejam.com/1996/", "delivery_mode": "webhook", "webhook_endpoint": "https://your-webhook-endpoint.com/pdf-ready" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### List Created PDFs Source: https://pdfendpoint.com/docs/endpoints List your created PDFs, ordered from latest to oldest, with options to filter by date range, limit, and page number. ```APIDOC ## GET /v1/list ### Description This endpoint lists your created PDFs from the latest to the oldest created PDF. ### Method GET ### Endpoint https://api.pdfendpoint.com/v1/list #### Query Parameters - **from** (string) - Optional - The date to start (YYYY-MM-DD) - **to** (string) - Optional - The date to end (YYYY-MM-DD) - **limit** (integer) - Optional - The number of PDFs to return (max 100) - **page** (integer) - Optional - The page number to return ### Request Example ```javascript const axios = require("axios"); const options = { "method": "GET", "url": "https://api.pdfendpoint.com/v1/list?from=2023-01-01&to=2023-01-20&limit=100&page=1", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({}) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` ``` -------------------------------- ### Handle JSONP PDF Data in JavaScript Source: https://pdfendpoint.com/docs/delivery-mode Implement this JavaScript function on your website to process the PDF data received via the JSONP delivery mode. The URL to the generated PDF will be available in `pdfData.data.url`. ```javascript function handlePDF(pdfData) { // Do something with the received pdfData // pdfData.data.url contains the url to the generated PDF } ``` -------------------------------- ### Set Page Margins Source: https://pdfendpoint.com/docs/document/page-setup Configure top, bottom, left, and right margins for the PDF document using numerical values and supported units (e.g., 'mm', 'cm', 'in', 'px'). Ensure values are positive integers. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://www.spacejam.com/1996/", "margin_top": "10mm", "margin_bottom": "10mm", "margin_left": "10mm", "margin_right": "10mm" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Convert HTML to PDF using NodeJS (axios) Source: https://pdfendpoint.com/docs/document/url Use this snippet to convert a publicly accessible HTML page to PDF via the API using NodeJS and the axios library. Ensure your URL is HTTPS and does not redirect. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://de.wikipedia.org/wiki/Portable_Document_Format" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Upload PDF to Google Cloud Storage using NodeJS (axios) Source: https://pdfendpoint.com/docs/delivery-mode Utilize the Google Storage delivery mode to upload PDFs to a Google Cloud Storage bucket. Ensure the service account has 'Storage Object Creator' permissions. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://www.spacejam.com/1996/", "delivery_mode": "google_storage", "gcp_project_id": "gcp-test-bucket", "gcp_user_email": "gcp-test-bucket-key", "gcp_private_key": "gcp-test-bucket-secret", "gcp_bucket_name": "gcp-test-bucket-secret" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Set PDF Metadata with Node.js (axios) Source: https://pdfendpoint.com/docs/misc/pdf-meta-data Use this snippet to set PDF metadata like title, author, creator, producer, subject, and keywords when converting a URL to a PDF using the pdfendpoint API with Node.js and axios. Ensure your API key is correctly set in the Authorization header. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://www.spacejam.com/1996/", "title": "Space Jam", "author": "Michael Jordan", "creator": "Michael Jordan", "producer": "Michael Jordan", "subject": "Space Jam", "keywords": "Space Jam, Michael Jordan" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Send PDF via JSONP with NodeJS (axios) Source: https://pdfendpoint.com/docs/delivery-mode Use the JSONP delivery mode to receive PDF data wrapped in a JavaScript function call. This is useful for cross-domain scenarios. Ensure you have a corresponding callback function on your website to handle the data. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://de.wikipedia.org/wiki/Portable_Document_Format", "delivery_mode": "jsonp", "callback": "handlePDF" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### S3 Delivery Mode Source: https://pdfendpoint.com/docs/delivery-mode Upload the generated PDF directly to an S3 bucket. You can provide credentials or use an IAM role. ```APIDOC ## POST /v1/convert ### Description Uploads a generated PDF to an S3 bucket. ### Method POST ### Endpoint /v1/convert ### Request Body - **url** (string) - Required - The URL of the webpage to convert. - **delivery_mode** (string) - Required - Set to "s3" for S3 delivery. - **s3_bucket_name** (string) - Required - The name of the S3 bucket. - **s3_bucket_key** (string) - Optional - The access key for the S3 bucket. - **s3_bucket_secret** (string) - Optional - The secret key for the S3 bucket. ### Request Example ```json { "url": "https://www.spacejam.com/1996/", "delivery_mode": "s3", "s3_bucket_name": "aws-test-bucket", "s3_bucket_key": "aws-test-bucket-key", "s3_bucket_secret": "aws-test-bucket-secret" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. - **delivery_id** (string) - Unique identifier for the delivery task. ``` -------------------------------- ### Set PDF Page Size Source: https://pdfendpoint.com/docs/document/page-setup Specify the page size for the generated PDF using the page_size parameter. Accepts standard sizes (e.g., 'A4', 'Letter') or custom dimensions with units like 'mm', 'cm', 'in', 'px'. ```javascript const axios = require("axios"); const options = { "method": "POST", "url": "https://api.pdfendpoint.com/v1/convert", "headers": { "Content-Type": "application/json", "Authorization": "Bearer SIGN-UP-FOR-KEY" }, "data": JSON.stringify({ "url": "https://www.spacejam.com/1996/", "page_size": "Folio" }) }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Base URL for PDF Endpoint API Source: https://pdfendpoint.com/docs/endpoints The base URL for all API requests to pdfEndpoint. ```text https://api.pdfendpoint.com/v1/ ```