### Basic Usage Example Source: https://github.com/restpackio/restpack-node/blob/master/README.md A basic example demonstrating how to initialize the Restpack client and use the html2pdf and screenshot services. ```javascript var restpack = require("@restpack/client"); var html2pdf = restpack.html2pdf(""); var screenshot = restpack.screenshot(""); html2pdf .convert("http://google.com", { pdf_page: "A4" }) .then(function success(document) { console.log(document); }) .catch(function fail(error) { console.error(error); }); ``` -------------------------------- ### Install Restpack Node.JS Client Source: https://github.com/restpackio/restpack-node/blob/master/README.md Instructions for installing the Restpack Node.JS client library using npm or Yarn. ```sh npm install @restpack/client --save ``` ```sh yarn add @restpack/client ``` -------------------------------- ### Client Class API Documentation Source: https://github.com/restpackio/restpack-node/blob/master/docs/classes/lib_client.client.md Provides detailed API documentation for the Client class, including its constructor, properties, and methods. This documentation outlines the parameters, return types, and usage of each component of the Client class. ```APIDOC Client: constructor(baseURL: String, accessToken: String) Parameters: baseURL: String accessToken: String Returns: Client Properties: accessToken: String baseURL: String Methods: request(path: String, options?: CoreOptions): Promise Parameters: path: String options: CoreOptions (optional, defaults to {}) Returns: Promise ``` -------------------------------- ### Client Constructor Source: https://github.com/restpackio/restpack-node/blob/master/docs/classes/screenshot.default.md Initializes a new Restpack Node client. It accepts a path and optional core options. This constructor inherits from the base Client class. ```APIDOC Client: __init__(path: String, options: CoreOptions = {}) Parameters: path: String - The path for the client. options: CoreOptions - Optional core options for the client, defaults to an empty object. Returns: Promise - A promise representing the client initialization. Inherited from: Client Defined in: lib/client.ts:12 ``` -------------------------------- ### Screenshot Capture Methods Source: https://github.com/restpackio/restpack-node/blob/master/README.md Demonstrates various methods for capturing screenshots of URLs or HTML content using the Restpack client. Includes options for returning document details or the image buffer. ```javascript var restpack = require("@restpack/client"); var screenshot = restpack.screenshot(""); // Convert given URL to PDF. Return the document details and CDN url of PDF // Check Available Options link above for all options. var promise = screenshot.capture("http://google.com", { pdf_page: "A4" /* , other options */, }); promise.then(function (doc) { console.log(doc); }); // Convert given html content to PDF. Return the document details and CDN url of PDF screenshot.captureHTML("

Bold text etc

", { pdf_page: "A4" /* , other options */, }); // Convert given URL to PDF. Return the PDF document as Buffer screenshot.captureToImage("http://google.com", { pdf_page: "A4" /* , other options */, }); // Convert given html content to PDF. Return the PDF document as Buffer screenshot.captureHTMLToImage("

Bold text etc

", { pdf_page: "A4" /* , other options */, }); ``` -------------------------------- ### HTML to PDF Conversion Methods Source: https://github.com/restpackio/restpack-node/blob/master/README.md Demonstrates various methods for converting HTML content or URLs to PDF using the Restpack client. Includes options for returning document details or the PDF buffer. ```javascript var restpack = require("@restpack/client"); var html2pdf = restpack.html2pdf(""); // Convert given URL to PDF. Return the document details and CDN url of PDF // Check Available Options link above for all options. var promise = html2pdf.convert("http://google.com", { pdf_page: "A4" /* , other options */, }); promise.then(function (doc) { console.log(doc); }); // Convert given html content to PDF. Return the document details and CDN url of PDF html2pdf.convertHTML("

Bold text etc

", { pdf_page: "A4" /* , other options */, }); // Convert given URL to PDF. Return the PDF document as Buffer html2pdf.convertToPDF("http://google.com", { pdf_page: "A4" /* , other options */, }); // Convert given html content to PDF. Return the PDF document as Buffer html2pdf.convertHTMLToPDF("

Bold text etc

", { pdf_page: "A4" /* , other options */, }); ``` -------------------------------- ### Restpack Node Screenshot API Documentation Source: https://github.com/restpackio/restpack-node/blob/master/docs/classes/screenshot.default.md Provides a comprehensive overview of the Restpack Node.js screenshot client, including its constructor, properties, and methods for capturing web pages and HTML content to various formats. ```APIDOC screenshot.default: __constructor(accessToken: String) accessToken: User access token Returns: screenshot.default Description: Create a new HTML to PDF conversion API client accessToken: String Inherited from: Client.accessToken Description: User access token baseURL: String Inherited from: Client.baseURL Description: Base URL for API requests capture(url: string, options?: Partial): Promise url: URL of the target website to be converted to PDF options: API options Returns: Promise Description: Capture a web page accessible by the given URL and return the resulting document information captureHTML(html: string, options?: Partial): Promise html: HTML content to capture options: API options Returns: Promise Description: Capture an HTML snippet to and return the resulting document information captureHTMLToImage(html: string, options?: Partial): Promise html: HTML content to capture options: API options Returns: Promise Description: Capture an HTML snippet and return the resulting PDF document as Buffer captureToImage(url: string, options?: Partial): Promise url: URL of the target website to be converted to PDF options: API options Returns: Promise Description: Capture a web page accessible by the given URL and return the resulting PDF document as Buffer request(path: String, options?: CoreOptions): Promise path: API endpoint path options: Request options Returns: Promise Description: Makes a request to the Restpack API ``` -------------------------------- ### Index Module Exports Source: https://github.com/restpackio/restpack-node/blob/master/docs/modules/index.md This section details the main exports from the index module. It includes references to the HTML2PDF and Screenshot functionalities, which are exposed as default objects. The 'default' property itself is an object containing methods to initialize these services. ```APIDOC Module: index References: - HTML2PDF: Exports the default class for HTML to PDF conversion. - Screenshot: Exports the default class for taking screenshots. Properties: - default: An object containing initialization functions for the exported services. - html2pdf: (accessToken: String) => default Initializes the HTML2PDF service with the provided access token. - screenshot: (accessToken: String) => default Initializes the Screenshot service with the provided access token. ``` -------------------------------- ### Client Class Source: https://github.com/restpackio/restpack-node/blob/master/docs/modules/lib_client.md The main Client class for the Restpack Node.js SDK. It handles authentication, request building, and response parsing for interacting with the Restpack API. ```javascript import { Client } from '@restpack/client'; // Example usage: const client = new Client({ apiKey: 'YOUR_API_KEY', apiSecret: 'YOUR_API_SECRET' }); // Make a request (example) client.get('/users').then(response => { console.log(response.data); }).catch(error => { console.error('Error fetching users:', error); }); ``` -------------------------------- ### Screenshot Capture Options Interface Source: https://github.com/restpackio/restpack-node/blob/master/docs/modules/screenshot.md Defines the configuration options for capturing a screenshot. This interface specifies parameters like viewport size, element selectors, and delay. ```APIDOC ScreenshotCaptureOptions: url: string The URL to capture. selector?: string A CSS selector for a specific element to capture. If not provided, the entire page is captured. delay?: number A delay in milliseconds before capturing the screenshot. Useful for pages with dynamic content loading. viewport?: { width: number height: number } The viewport size for the screenshot. If not provided, the default viewport size is used. ``` -------------------------------- ### Screenshot Options Source: https://github.com/restpackio/restpack-node/blob/master/docs/interfaces/screenshot.screenshotcaptureoptions.md Defines the available options for configuring screenshot captures, including viewport dimensions, capture modes, image processing, and loading strategies. ```APIDOC height: type: number description: Preferred viewport height in pixels. js: type: string description: Additional JS string to be injected into the page before render. mode: type: "fullpage" | "viewport" | "element" description: Capturing mode. omit_background: type: boolean description: Do not render with default white background. You can use this option to generate transparent PNG images. privacy: type: boolean description: Ensure that the captured document does not get cached / stored for further use. You can not use json mode with this setting as it would not be possible to provide a CDN URL. retina: type: boolean description: Generate retina sized screen capture (2x device pixel ratio). shutter: type: string description: Wait until a DOM element matching the provided css selector becomes present on the page. thumbnail_height: type: number description: Preferred thumbnail height, requires thumbnail_width to be set, unbounded if omitted. thumbnail_width: type: number description: In case you want a thumbnail image, provide a preferred width. user_agent: type: string description: Custom user-agent header string for the web request. wait: type: "load" | "network" | "dom" description: Wait until window load event fires or network becomes idle before capturing the page. width: type: number description: Preferred viewport width in pixels. ``` -------------------------------- ### Screenshot Capture Options Source: https://github.com/restpackio/restpack-node/blob/master/docs/interfaces/screenshot.screenshotcaptureoptions.md Defines the configuration options for capturing screenshots using the Restpack API. These options control various aspects of the capture process, such as output format, dimensions, delays, and specific rendering behaviors like blocking ads or cookie warnings. ```APIDOC ScreenshotCaptureOptions: filename?: string If specified, ensures that the resulting file is saved with the given name. format?: "jpg" | "png" | "pdf" | "html" Preferred image output format. If you need a raw html string you can pass html as format. delay?: number Time in milliseconds to delay capture after page load. cache_ttl?: number Time in seconds for the resulting image to be cached for further requests. element_selector?: string A CSS selector to be used with element rendering mode. headers?: string Additional headers separated with newline. emulate_media?: "screen" | "print" Force CSS media emulation for print or screen. allow_failed?: boolean By default, any response from remote server outside http 200-299 status codes generates an error. If you wish to capture error pages, pass true. block_ads?: boolean Block / hide ads on the page. block_cookie_warnings?: boolean Block / hide European Union cookie warnings before capture. grayscale?: boolean Render document with grayscale filter. css?: string Additional CSS string to be injected into the page before render. width?: number The width of the viewport in pixels. height?: number The height of the viewport in pixels. retina?: boolean If set to true, capture at a 2x resolution. shutter?: boolean If set to true, capture the page as a screenshot. mode?: "manual" | "auto" Capture mode. "auto" is default, "manual" requires you to call page.screenshot(). privacy?: boolean If set to true, capture the page without any user information. omit_background?: boolean If set to true, capture the page without background. thumbnail_width?: number The width of the thumbnail in pixels. thumbnail_height?: number The height of the thumbnail in pixels. user_agent?: string The user agent string to use for the request. wait?: number Time in milliseconds to wait for the page to load before capturing. ``` -------------------------------- ### HTML to PDF Conversion API Source: https://github.com/restpackio/restpack-node/blob/master/docs/classes/html2pdf.default.md Provides methods to convert web pages or HTML content into PDF documents using the Restpack API. It inherits from a base Client class and requires an access token for authentication. ```APIDOC html2pdf.default: constructor(accessToken: String) accessToken: User access token Returns: default convert(url: string, options?: Partial): Promise url: URL of the target website to be converted to PDF options: API options Returns: Promise convertHTML(html: string, options?: Partial): Promise html: HTML snippet to convert options: API options Returns: Promise convertToPDF(url: string, options?: Partial): Promise url: URL of the target website to be converted to PDF options: API options Returns: Promise convertHTMLToPDF(url: string, options?: Partial): Promise url: URL of the target website to be converted to PDF options: API options Returns: Promise request(path: String, options?: CoreOptions): Promise path: Request path options: Request options Returns: Promise ``` -------------------------------- ### PDFConvertOptions Interface Source: https://github.com/restpackio/restpack-node/blob/master/docs/modules/html2pdf.md This APIDOC entry describes the `PDFConvertOptions` interface, which allows customization of the PDF conversion process. It details various parameters that can be passed to control aspects like page format, orientation, and margins. ```APIDOC PDFConvertOptions: format?: 'A4' | 'Letter' | 'Legal' | string; // Specifies the page format. Defaults to 'A4'. landscape?: boolean; // Sets the page orientation to landscape. Defaults to false (portrait). margin?: { top?: string | number; right?: string | number; bottom?: string | number; left?: string | number; }; // Defines the page margins. Values can be strings (e.g., '1cm') or numbers (in points). headerTemplate?: string; // HTML template for the page header. footerTemplate?: string; // HTML template for the page footer. displayHeaderFooter?: boolean; // Whether to display the header and footer. Defaults to false. printBackground?: boolean; // Whether to print the background graphics. Defaults to false. width?: string | number; // Specifies the width of the page. height?: string | number; // Specifies the height of the page. scale?: number; // Scales the rendering of the PDF. Defaults to 1. pageRanges?: string; // Specifies the page ranges to print (e.g., '1-5', '1,3,5'). preferCSSPageSize?: boolean; // Whether to prefer CSS page size over `width` and `height` options. Defaults to false. timeout?: number; // Timeout for the PDF generation in milliseconds. Defaults to 0 (no timeout). waitUntil?: 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'; // When to consider the page as loaded. Defaults to 'load'. ``` -------------------------------- ### Default Screenshot Class Source: https://github.com/restpackio/restpack-node/blob/master/docs/modules/screenshot.md The main class for performing screenshot operations. It likely utilizes the ScreenshotCaptureOptions interface for its methods. ```APIDOC default: constructor(options?: ScreenshotCaptureOptions) Initializes the screenshot capture class with optional configuration. capture(options: ScreenshotCaptureOptions): Promise Captures a screenshot based on the provided options. - options: ScreenshotCaptureOptions - Configuration for the screenshot capture. - Returns: A Promise that resolves with the screenshot data (e.g., base64 encoded string). ``` -------------------------------- ### PDFConvertOptions Interface Source: https://github.com/restpackio/restpack-node/blob/master/docs/interfaces/html2pdf.pdfconvertoptions.md Defines the structure for options passed to the Restpack API for HTML to PDF conversion. These options control various aspects of the conversion process, including styling, security, and page layout. ```APIDOC PDFConvertOptions: allow_failed: boolean By default, any response from remote server outside http 200-299 status codes generates an error. If you wish to capture error pages, pass true. block_cookie_warnings: boolean Block / hide European Union cookie warnings before capture. cache_ttl: number Time in seconds for the resulting image to be cached for further requests. css: string Additional CSS string to be injected into the page before render. delay: number Time in milliseconds to delay capture after page load emulate_media: "screen" | "print" Force CSS media emulation for print or screen. filename: string If specified, ensures that the resulting file is saved with the given name. headers: string Additional headers seperated with newline js: string Additional JS string to be injected into the page before render. owner_password: string Secure PDF document with a owner password. pdf_encryption: "40" | "128" Enable document encryption pdf_footer: string HTML template for page footer. Please check pdf_header information for details. pdf_header: string HTML template for page header. Please check pdf_footer information for details. pdf_height: string Set the page height. Example: "11in", "27cm", "1000px". pdf_margins: string Set the page margins. Example: "1in", "2.5cm". pdf_orientation: "landscape" | "portrait" Set the page orientation. pdf_page: string Set the page size. Example: "A4", "Letter". pdf_page_ranges: string Set the page ranges to print. Example: "1-3,5,7-10". pdf_width: string Set the page width. Example: "8.5in", "21cm", "800px". privacy: string Set the PDF document privacy. shutter: string Set the shutter for the PDF. user_agent: string Set the user agent for the request. user_password: string Secure PDF document with a user password. ``` -------------------------------- ### PDF Page Range and Wait Strategy Source: https://github.com/restpackio/restpack-node/blob/master/docs/interfaces/html2pdf.pdfconvertoptions.md Control which pages are included in the generated PDF and specify when the page capture should occur. You can select specific page ranges or wait for events like 'load', 'network idle', or 'dom ready'. ```APIDOC pdf_page_ranges: string Returns only specified pages of the PDF document wait: "load" | "network" | "dom" Wait until window load event fires or network becomes idle before capturing the page. ``` -------------------------------- ### HTML to PDF Conversion Source: https://github.com/restpackio/restpack-node/blob/master/docs/modules/html2pdf.md This snippet demonstrates the basic usage of the html2pdf module to convert HTML content to a PDF document. It utilizes the default export class for the conversion process. ```javascript import html2pdf from '@restpack/client/html2pdf'; async function convertHtmlToPdf(htmlContent) { try { const pdfBuffer = await html2pdf.generatePdf(htmlContent, { // Optional: Add PDF conversion options here // format: 'A4', // landscape: false, }); console.log('PDF generated successfully!'); // You can now save or send the pdfBuffer return pdfBuffer; } catch (error) { console.error('Error generating PDF:', error); throw error; } } // Example usage: // const html = '

Hello, World!

This is a PDF document.

'; // convertHtmlToPdf(html).then(buffer => console.log(buffer)); ``` -------------------------------- ### Privacy and Shutter Options Source: https://github.com/restpackio/restpack-node/blob/master/docs/interfaces/html2pdf.pdfconvertoptions.md Configure privacy settings to prevent caching and storage of captured documents. The 'shutter' option allows waiting for a specific DOM element to appear before capturing the page. ```APIDOC privacy: boolean Ensure that the captured document does not get cached / stored for further use. You can not use json mode with this setting as it would not be possible to provide a CDN URL. shutter: string Wait until a DOM element matching the provided css selector becomes present on the page. ``` -------------------------------- ### PDF Page Size and Orientation Source: https://github.com/restpackio/restpack-node/blob/master/docs/interfaces/html2pdf.pdfconvertoptions.md Configure the page size and orientation for PDF generation. Options include standard sizes like A4, Letter, and Legal, as well as custom width and height. Page orientation can be set to 'portrait' or 'landscape'. ```APIDOC pdf_page: "A0" | "A1" | "A2" | "A3" | "A4" | "A5" | "Legal" | "Letter" | "Tabloid" | "Ledger" | "Full" Custom page size for created document pdf_orientation: "portrait" | "landscape" Page orientation pdf_width: string Custom pdf page width. Must be used together with pdf_height. Prefer pdf_page if you don't have an exact page size requirement.. Unit can be either px for pixels, in for inches. pdf_height: string Custom pdf page height. Check pdf_width for details. ``` -------------------------------- ### PDF Security and User Agent Source: https://github.com/restpackio/restpack-node/blob/master/docs/interfaces/html2pdf.pdfconvertoptions.md Enhance PDF security by setting a user password, which restricts viewing and operations. Additionally, customize the user-agent header for web requests. ```APIDOC user_password: string Secure PDF document with a user password. With user password person can only view the document and allowed operations user_agent: string Custom user-agent header string for the web request. ``` -------------------------------- ### PDF Header and Margins Source: https://github.com/restpackio/restpack-node/blob/master/docs/interfaces/html2pdf.pdfconvertoptions.md Customize the page header and margins for PDF documents. The header can be an HTML template with specific elements like page numbers and titles. Margins are defined using CSS style strings and are crucial for the header to be visible. ```APIDOC pdf_header: string HTML template for page header. It should have a valid markup and can contain elements with classes 'pageNumber', 'totalPages', 'url', 'title' or 'date'. Header is automatically added to all pages. Note that you need to have top margins on your documents in order to have the header show up. Please add margins using pdf_margins. pdf_margins: string CSS style margin sizes. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.