### Create PDF using Doczilla API Source: https://docs.doczilla.app/quickstart This example demonstrates how to generate a PDF document using the Doczilla API. It sends a POST request to the '/v1/pdf' endpoint with custom HTML content and PDF printing options, requiring an API key for authorization. ```curl curl --request POST 'https://api.doczilla.app/v1/pdf' \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --output doczilla.pdf \ --data '{ \ "page": { \ "html": "PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIFBERjwvZGl2Pg==" \ }, \ "pdf": { \ "printBackground": true \ } \ }' ``` -------------------------------- ### Install Doczilla Node.js SDK Source: https://docs.doczilla.app/libraries/nextjs Install the Doczilla Node.js SDK using npm. After installation, configure the package with your organization's API key, which can be found on your organization's settings page. ```bash npm install @doczilla/node ``` -------------------------------- ### Install Node.js SDK Source: https://docs.doczilla.app/libraries/nodejs Install the Doczilla Node.js SDK using npm. This package is essential for integrating Doczilla's services into your Node.js projects. ```bash npm install @doczilla/node ``` -------------------------------- ### Example JSON Response Source: https://docs.doczilla.app/api-reference/storage-options This is an example JSON response structure that might be received from an API endpoint, likely related to pre-signed URLs for storage. ```json { "preSignedUrl": "" } ``` -------------------------------- ### Generate Invoice PDF with Node.js SDK Source: https://docs.doczilla.app/examples/pdf-html-invoices This snippet demonstrates how to generate an invoice PDF using the Doczilla Node.js SDK. It requires the SDK to be installed and configured with your API token. The example shows how to set up the PDF format and provide an HTML template. ```javascript const doczilla = require('doczilla'); const client = new doczilla.Client(''); client.pdf.create({ pdf: { format: 'a4' }, page: { htmlTemplate: `

Doczilla example

Invoice Detail:

Doczilla example

Fake Street 123

Amsterdam

4321 AA

Billed To

{debtor.name}

{debtor.address}

{debtor.city}

{debtor.zipcode}

Invoice Number

{number}

Date of Issue

{ date }

Terms

{ terms } Days

Due

{dueDate }

{/* Loop through line items here */} {/* Example line item: */} {/* End of example line item */}
Description Amount
{description}
{amount}
` } }).then(response => { console.log('PDF generated successfully:', response); }).catch(error => { console.error('Error generating PDF:', error); }); ``` -------------------------------- ### Create Screenshot API Request Example Source: https://docs.doczilla.app/api-reference/screenshot-options This snippet shows an example JSON payload for creating a screenshot using the Doczilla API. It includes options for device, viewport, image type, and capture settings. ```json { "type": "png", "device": "Macbook Pro 16", "viewport": { "width": 2240, "height": 1260, "deviceScaleFactor": 1, "isMobile": false, "hasTouch": false, "isLandscape": false }, "fullPage": false, "fromSurface": true, "omitBackground": false, "optimizeForSpeed": true, "quality": 50, "captureBeyondViewport": false, "clip": { "scale": 1, "width": 2240, "height": 1260, "x": 123, "y": 123 }, "element": "", "overlay": { "background": "", "filter": "none", "margin": 0.2, "browser": "light", "screenshotBorderRadius": 0 } } ``` -------------------------------- ### Get All Templates Response (JSON) Source: https://docs.doczilla.app/api-reference/endpoint/list-templates Example JSON response for the 'Get all Templates' API call, including pagination information and a list of template objects. ```JSON { "hasNextPage": true, "hasPreviousPage": true, "data": [ { "id": "", "name": "", "output": "PDF", "createdAt": "2023-11-07T05:31:56Z", "updatedAt": "2023-11-07T05:31:56Z" } ] } ``` -------------------------------- ### Install Doczilla Node.js SDK Source: https://docs.doczilla.app/libraries/remix Install the Doczilla Node.js SDK using npm. This package is required to use Doczilla's PDF generation capabilities within your Node.js or Remix application. ```bash npm install @doczilla/node ``` -------------------------------- ### API Response Example (Pending Status) Source: https://docs.doczilla.app/api-reference/endpoint/async-template This is an example of a successful API response when a task, such as creating a screenshot or PDF, has been initiated. It returns a JSON object containing a unique identifier for the task and its current status, which is 'PENDING' in this case, indicating that the process has started but not yet completed. ```JSON { "id": "5KqYNUjbxRJ-rKbIeGsXo", "status": "PENDING" } ``` -------------------------------- ### Doczilla API Request Example Source: https://docs.doczilla.app/api-reference/page-options This JSON object demonstrates a comprehensive example of a request payload for Doczilla's API, likely for generating screenshots or PDFs. It includes parameters for URL, HTML content, template data, waiting conditions, headers, ad blocking, JavaScript execution, cookies, authentication, color scheme, media type, and timezone. ```json { "url": "", "html": "", "htmlTemplate": "", "templateData": {}, "waitUntil": "auto", "waitForMilliseconds": 2500, "waitForSelector": { "selector": "", "options": { "visible": false, "hidden": false, "timeout": 10000 } }, "waitForFunction": { "pageFunction": "window.innerWidth < 100", "options": { "polling": "raf", "timeout": 10000 } }, "headers": { "x-foo": "bar" }, "adblock": true, "javascript": true, "cookies": [ { "name": "", "value": "", "domain": "", "url": "", "path": "", "secure": true, "httpOnly": true, "sameSite": "Strict", "expires": 123 } ], "authentication": { "username": "", "password": "" }, "colorScheme": "", "mediaType": "screen", "timezone": "" } ``` -------------------------------- ### Generate Product Screenshots with cURL Source: https://docs.doczilla.app/examples/product-screenshot This example demonstrates how to use the cURL command-line tool to generate a product screenshot via the Doczilla API. It specifies the target URL, screenshot device, and overlay options for customization. ```cURL curl --request POST 'https://api.doczilla.app/v1/screenshot' \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --output 'doczilla.png' \ --data '{ "page": { "url": "https://doczilla.app", "waitForMilliseconds": 500 }, "screenshot": { "device": "Macbook Pro 13", "overlay": { "background": "linear-gradient(135deg, #17BCE0 0%, #17E286 100%)", "browser": "dark", "margin": 0.2 } } }' ``` -------------------------------- ### Generate Product Screenshots with Node.js SDK Source: https://docs.doczilla.app/examples/product-screenshot This example shows how to use the Doczilla Node.js SDK to programmatically generate product screenshots. It configures the API request with page details and screenshot options, including device and overlay settings. ```javascript const doczilla = require('doczilla-sdk'); doczilla.screenshot({ page: { url: 'https://doczilla.app', waitForMilliseconds: 500 }, screenshot: { device: 'Macbook Pro 13', overlay: { background: 'linear-gradient(135deg, #17BCE0 0%, #17E286 100%)', browser: 'dark', margin: 0.2 } } }).then(response => { // Handle the screenshot response, e.g., save to file }).catch(error => { console.error(error); }); ``` -------------------------------- ### Example API Response Source: https://docs.doczilla.app/api-reference/webhook-event This is a sample JSON response structure from the Doczilla API, detailing job status, file URLs, and metadata. It's commonly seen after initiating a screenshot or PDF generation task. ```json { "id": "ID", "status": "SUCCESS", "signedUrlStatus": "NOT_PROVIDED", "fileUrl": "", "fileBase64": "", "metadata": {} } ``` -------------------------------- ### Generate PDF in Remix Source: https://docs.doczilla.app/libraries/remix Example of generating a PDF directly using the Doczilla Node.js SDK within a Remix API route. It demonstrates how to initialize the Doczilla client and use the `pdf.direct` method to create a PDF from HTML content. ```TypeScript // app/routes/api.pdf.ts -> /api/pdf import { LoaderFunctionArgs } from '@remix-run/node' import Doczilla from '@doczilla/node' const doczilla = new Doczilla('doczilla-...') export async function loader(args: LoaderFunctionArgs) { const pdfBuffer = await doczilla.pdf.direct({ page: { html: '
Your first Doczilla PDF
' } }) return new Response(pdfBuffer, { headers: { 'Content-Type': 'application/pdf' } }) } ``` -------------------------------- ### Doczilla API Headers Example Source: https://docs.doczilla.app/api-reference/page-options This example shows how to define custom HTTP headers for a Doczilla API request. It includes a sample header 'x-foo' with the value 'bar'. These headers are sent with every request made to the API. ```json { "x-foo": "bar" } ``` -------------------------------- ### Handlebars HTML Template Example Source: https://docs.doczilla.app/templating/introduction This snippet demonstrates a basic Handlebars template. It includes a title variable and iterates over an array of items to render a list. This showcases dynamic content rendering and data iteration capabilities of Handlebars. ```HTML

{{title}}

    {{#each items}}
  • {{this}}
  • {{/each}}
``` -------------------------------- ### Create Google Cloud Storage Client (Node.js) Source: https://docs.doczilla.app/examples/use-your-own-bucket This snippet demonstrates how to initialize the Google Cloud Storage client using the Node.js SDK. This client is necessary for interacting with Google Cloud Storage services, including generating signed URLs. ```JavaScript // Imports the Google Cloud client library import { Storage } from '@google-cloud/storage' // Creates a client const storage = new Storage() ``` -------------------------------- ### Get Template by ID using cURL Source: https://docs.doczilla.app/api-reference/endpoint/get-template This snippet demonstrates how to retrieve a specific template using its ID via a cURL GET request. It requires an authorization token. ```cURL curl --request GET \ --url https://api.doczilla.app/v1/templates/{id} \ --header 'Authorization: Bearer ' ``` -------------------------------- ### Queue Template Creation (Async) Source: https://docs.doczilla.app/api-reference/endpoint/async-template This cURL command demonstrates how to asynchronously queue the creation of a template. It includes detailed optional parameters for page content (URL, HTML, template data), screenshot configuration, PDF generation options, storage pre-signed URLs, and webhook details for receiving the result. The request requires an Authorization header with a Bearer token. ```cURL curl --request POST \ --url https://api.doczilla.app/v1/template/{id}/async \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --data '{ \ "page": { \ "url": "", \ "html": "", \ "htmlTemplate": "", \ "templateData": {}, \ "waitUntil": "auto", \ "waitForMilliseconds": 2500, \ "waitForSelector": { \ "selector": "", \ "options": { \ "visible": false, \ "hidden": false, \ "timeout": 10000 \ } \ }, \ "waitForFunction": { \ "pageFunction": "window.innerWidth < 100", \ "options": { \ "polling": "raf", \ "timeout": 10000 \ } \ }, \ "headers": { \ "x-foo": "bar" \ }, \ "adblock": true, \ "javascript": true, \ "cookies": [ \ { \ "name": "", \ "value": "", \ "domain": "", \ "url": "", \ "path": "", \ "secure": true, \ "httpOnly": true, \ "sameSite": "Strict", \ "expires": 123 \ } \ ], \ "authentication": { \ "username": "", \ "password": "" \ }, \ "colorScheme": "", \ "mediaType": "screen", \ "timezone": "" \ }, \ "screenshot": { \ "type": "png", \ "device": "Macbook Pro 16", \ "viewport": { \ "width": 2240, \ "height": 1260, \ "deviceScaleFactor": 1, \ "isMobile": false, \ "hasTouch": false, \ "isLandscape": false \ }, \ "fullPage": false, \ "fromSurface": true, \ "omitBackground": false, \ "optimizeForSpeed": true, \ "quality": 50, \ "captureBeyondViewport": false, \ "clip": { \ "scale": 1, \ "width": 2240, \ "height": 1260, \ "x": 123, \ "y": 123 \ }, \ "element": "", \ "overlay": { \ "background": "", \ "filter": "none", \ "margin": 0.2, \ "browser": "light", \ "screenshotBorderRadius": 0 \ } \ }, \ "pdf": { \ "scale": 1, \ "displayHeaderFooter": false, \ "headerHtml": "", \ "footerHtml": "", \ "printBackground": false, \ "landscape": false, \ "pageRanges": "1-5", \ "format": "letter", \ "width": "", \ "height": "", \ "preferCSSPageSize": false, \ "margin": { \ "top": "", \ "bottom": "", \ "left": "", \ "right": "" \ }, \ "omitBackground": false, \ "outline": false, \ "tagged": false \ }, \ "storage": { \ "preSignedUrl": "" \ }, \ "webhook": { \ "receiveType": "URL", \ "url": "", \ "method": "POST", \ "headers": {}, \ "metadata": {} \ } \ }' ``` -------------------------------- ### Get All Templates (cURL) Source: https://docs.doczilla.app/api-reference/endpoint/list-templates Retrieves a list of all available templates. Requires Bearer token authentication. Supports pagination. ```cURL curl --request GET \ --url https://api.doczilla.app/v1/templates \ --header 'Authorization: Bearer ' ``` -------------------------------- ### Handlebars HTML Output Example Source: https://docs.doczilla.app/templating/introduction This snippet shows the rendered HTML output from the provided Handlebars template. It illustrates how variables like 'title' and iterated list items are dynamically inserted into the HTML structure. ```HTML

Doczilla with Handlebars!

  • Item 1
  • Item 2
  • Item 3
``` -------------------------------- ### API Response - Screenshot Status Source: https://docs.doczilla.app/api-reference/endpoint/async-screenshot This snippet shows a typical JSON response from the Doczilla API indicating the status of a screenshot request. It includes a unique ID for tracking and the current status, which is 'PENDING' in this example. ```JSON { "id": "5KqYNUjbxRJ-rKbIeGsXo", "status": "PENDING" } ``` -------------------------------- ### Doczilla API Endpoints Overview Source: https://docs.doczilla.app/api-reference/introduction This snippet outlines the available Doczilla API endpoints for PDF and screenshot generation. It specifies the HTTP method, the endpoint path, the type of operation (direct, sync, async), and the required body parameters. ```text POST | /v1/pdf | `direct` | page, pdf POST | /v1/pdf/sync | `sync` | page, pdf, storage POST | /v1/pdf/async | `async` | page, pdf, storage, webhook POST | /v1/screenshot | `direct` | page, screenshot POST | /v1/screenshot/sync | `sync` | page, screenshot, storage POST | /v1/screenshot/async | `async` | page, screenshot, storage, webhook POST | /v1/template/:id | `direct` | page, pdf, screenshot, storage, webhook POST | /v1/template/:id/sync | `sync` | page, pdf, screenshot, storage, webhook POST | /v1/template/:id/async | `async` | page, pdf, screenshot, storage, webhook ``` -------------------------------- ### Create Screenshot (POST) Source: https://docs.doczilla.app/api-reference/endpoint/create-template Creates a screenshot using the Doczilla API. This endpoint likely requires template or page configuration as input and returns screenshot data or a URL. ```HTTP POST /screenshot ``` -------------------------------- ### Create Screenshot Async (POST) Source: https://docs.doczilla.app/api-reference/endpoint/create-template Creates a screenshot asynchronously using the Doczilla API. This endpoint likely returns immediately with a job ID or status, with the screenshot delivered later. ```HTTP POST /screenshot/async ``` -------------------------------- ### Manage Templates API Source: https://docs.doczilla.app/api-reference/templates Endpoints for managing templates in Doczilla. Allows for retrieving all templates, creating new ones, getting a specific template by ID, updating, and deleting templates. ```HTTP GET /v1/templates POST /v1/templates GET /v1/templates/:id PUT /v1/templates/:id DEL /v1/templates/:id ``` -------------------------------- ### Create Template Screenshot Source: https://docs.doczilla.app/api-reference/endpoint/template This cURL command demonstrates how to create a screenshot from a specified template. It includes detailed options for page configuration, screenshot settings, and PDF generation parameters. ```cURL curl --request POST \ --url https://api.doczilla.app/v1/template/{id} \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --data '{ \ "page": { \ "url": "", \ "html": "", \ "htmlTemplate": "", \ "templateData": {}, \ "waitUntil": "auto", \ "waitForMilliseconds": 2500, \ "waitForSelector": { \ "selector": "", \ "options": { \ "visible": false, \ "hidden": false, \ "timeout": 10000 \ } \ }, \ "waitForFunction": { \ "pageFunction": "window.innerWidth < 100", \ "options": { \ "polling": "raf", \ "timeout": 10000 \ } \ }, \ "headers": { \ "x-foo": "bar" \ }, \ "adblock": true, \ "javascript": true, \ "cookies": [ \ { \ "name": "", \ "value": "", \ "domain": "", \ "url": "", \ "path": "", \ "secure": true, \ "httpOnly": true, \ "sameSite": "Strict", \ "expires": 123 \ } \ ], \ "authentication": { \ "username": "", \ "password": "" \ }, \ "colorScheme": "", \ "mediaType": "screen", \ "timezone": "" \ }, \ "screenshot": { \ "type": "png", \ "device": "Macbook Pro 16", \ "viewport": { \ "width": 2240, \ "height": 1260, \ "deviceScaleFactor": 1, \ "isMobile": false, \ "hasTouch": false, \ "isLandscape": false \ }, \ "fullPage": false, \ "fromSurface": true, \ "omitBackground": false, \ "optimizeForSpeed": true, \ "quality": 50, \ "captureBeyondViewport": false, \ "clip": { \ "scale": 1, \ "width": 2240, \ "height": 1260, \ "x": 123, \ "y": 123 \ }, \ "element": "", \ "overlay": { \ "background": "", \ "filter": "none", \ "margin": 0.2, \ "browser": "light", \ "screenshotBorderRadius": 0 \ } \ }, \ "pdf": { \ "scale": 1, \ "displayHeaderFooter": false, \ "headerHtml": "", \ "footerHtml": "", \ "printBackground": false, \ "landscape": false, \ "pageRanges": "1-5", \ "format": "letter", \ "width": "", \ "height": "", \ "preferCSSPageSize": false, \ "margin": { \ "top": "", \ "bottom": "", \ "left": "", \ "right": "" \ }, \ "omitBackground": false, \ "outline": false, \ "tagged": false \ } \ }' ``` -------------------------------- ### Generate Image from HTML (cURL) Source: https://docs.doczilla.app/examples/image-from-html This example demonstrates how to generate a basic image from HTML content using a cURL request to the Doczilla API. It specifies the HTML content and the desired viewport dimensions for the output image. ```cURL curl --request POST 'https://api.doczilla.app/v1/screenshot' \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --output 'doczilla.pdf' \ --data '{ \ "page": { \ "html": "PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIGltYWdlPC9kaXY+" \ }, \ "screenshot": { \ "viewport": { \ "width": 400, \ "height": 200 \ } \ } \ }' ``` -------------------------------- ### Generate Invoices with Tailwind CSS using htmlTemplate Source: https://docs.doczilla.app/examples/pdf-html-invoices This example demonstrates how to generate invoice PDFs using the `htmlTemplate` option in Doczilla, specifically integrating with Tailwind CSS. It utilizes Handlebars for templating and requires `templateData` for rendering. ```javascript const doczilla = require('doczilla'); async function generateInvoice() { const htmlTemplate = `

Invoice for {{customerName}}

Amount: ${{amount}}

`; const templateData = { customerName: 'Acme Corp', amount: 1500 }; const pdf = await doczilla.generatePdf({ htmlTemplate: htmlTemplate, templateData: templateData, // Other options like 'format', 'margin', etc. }); // Save or send the PDF console.log('PDF generated successfully!'); } generateInvoice(); ``` -------------------------------- ### Create Screenshot Async Request Source: https://docs.doczilla.app/api-reference/endpoint/async-screenshot This cURL command demonstrates how to queue an asynchronous screenshot creation. It includes the API endpoint, authorization header, content type, and a JSON payload specifying page details, screenshot settings, and webhook configuration. ```cURL curl --request POST \ --url https://api.doczilla.app/v1/screenshot/async \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --data '{ "page": { "url": "", "html": "", "htmlTemplate": "", "templateData": {}, "waitUntil": "auto", "waitForMilliseconds": 2500, "waitForSelector": { "selector": "", "options": { "visible": false, "hidden": false, "timeout": 10000 } }, "waitForFunction": { "pageFunction": "window.innerWidth < 100", "options": { "polling": "raf", "timeout": 10000 } }, "headers": { "x-foo": "bar" }, "adblock": true, "javascript": true, "cookies": [ { "name": "", "value": "", "domain": "", "url": "", "path": "", "secure": true, "httpOnly": true, "sameSite": "Strict", "expires": 123 } ], "authentication": { "username": "", "password": "" }, "colorScheme": "", "mediaType": "screen", "timezone": "" }, "screenshot": { "type": "png", "device": "Macbook Pro 16", "viewport": { "width": 2240, "height": 1260, "deviceScaleFactor": 1, "isMobile": false, "hasTouch": false, "isLandscape": false }, "fullPage": false, "fromSurface": true, "omitBackground": false, "optimizeForSpeed": true, "quality": 50, "captureBeyondViewport": false, "clip": { "scale": 1, "width": 2240, "height": 1260, "x": 123, "y": 123 }, "element": "", "overlay": { "background": "", "filter": "none", "margin": 0.2, "browser": "light", "screenshotBorderRadius": 0 } }, "storage": { "preSignedUrl": "" }, "webhook": { "receiveType": "URL", "url": "", "method": "POST", "headers": {}, "metadata": {} } }' ``` -------------------------------- ### Create PDF Sync (cURL) Source: https://docs.doczilla.app/api-reference/endpoint/sync-pdf This cURL command demonstrates how to create a PDF synchronously using the Doczilla API. It includes options for page configuration (URL, HTML, wait conditions, headers, cookies, etc.), PDF formatting (scale, margins, page size, etc.), and storage options (pre-signed URL). ```cURL curl --request POST \ --url https://api.doczilla.app/v1/pdf/sync \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --data '{ \ "page": { \ "url": "", \ "html": "", \ "htmlTemplate": "", \ "templateData": {}, \ "waitUntil": "auto", \ "waitForMilliseconds": 2500, \ "waitForSelector": { \ "selector": "", \ "options": { \ "visible": false, \ "hidden": false, \ "timeout": 10000 \ } \ }, \ "waitForFunction": { \ "pageFunction": "window.innerWidth < 100", \ "options": { \ "polling": "raf", \ "timeout": 10000 \ } \ }, \ "headers": { \ "x-foo": "bar" \ }, \ "adblock": true, \ "javascript": true, \ "cookies": [ \ { \ "name": "", \ "value": "", \ "domain": "", \ "url": "", \ "path": "", \ "secure": true, \ "httpOnly": true, \ "sameSite": "Strict", \ "expires": 123 \ } \ ], \ "authentication": { \ "username": "", \ "password": "" \ }, \ "colorScheme": "", \ "mediaType": "screen", \ "timezone": "" \ }, \ "pdf": { \ "scale": 1, \ "displayHeaderFooter": false, \ "headerHtml": "", \ "footerHtml": "", \ "printBackground": false, \ "landscape": false, \ "pageRanges": "1-5", \ "format": "letter", \ "width": "", \ "height": "", \ "preferCSSPageSize": false, \ "margin": { \ "top": "", \ "bottom": "", \ "left": "", \ "right": "" \ }, \ "omitBackground": false, \ "outline": false, \ "tagged": false \ }, \ "storage": { \ "preSignedUrl": "" \ } \ }' ``` -------------------------------- ### Generate Reports with Tailwind CSS using htmlTemplate Source: https://docs.doczilla.app/examples/pdf-html-reports This example demonstrates how to generate report PDFs with charts using the `htmlTemplate` option. It leverages Handlebars to render HTML content along with provided `templateData` for dynamic document generation. ```JavaScript const doczilla = require('doczilla'); async function generateReport() { const htmlTemplate = ` Report

{{title}}

Generated on: {{date}}

`; const templateData = { title: 'Sales Report', date: new Date().toLocaleDateString() }; const pdfOptions = { htmlTemplate: htmlTemplate, templateData: templateData, // Add chart rendering logic here if needed, e.g., using a charting library }; try { const pdf = await doczilla.generatePdf(pdfOptions); console.log('PDF generated successfully!'); // You can now save or send the PDF } catch (error) { console.error('Error generating PDF:', error); } } generateReport(); ```