### Generate PDF from Template using Node.js Client Source: https://markupgo.com/docs/index This Node.js example demonstrates how to generate a PDF from a predefined template using the `markupgo-node` client library. It shows how to pass template ID and context data, configure PDF properties (like print background and landscape orientation), and retrieve the output as a JSON task object or a raw PDF buffer, which can then be saved to a file. ```Node.js import MarkupGo from 'markupgo-node'; import * as fs from 'fs'; const markupGo = new MarkupGo({ API_KEY: 'YOUR_API_KEY' }); const templateData: TemplateData = { id: PODCAST_TEMPLATE_ID, context: { title: 'Episode 1', description: 'We talk about stuff and things, tune in!' } }; const pdfOptions: PdfOptions = { properties: { printBackground: true, landscape: true } }; markupGo.pdf.fromTemplate(templateData, pdfOptions).json().then((task) => { console.log(task); }); markupGo.pdf.fromTemplate(templateData, pdfOptions).buffer().then((buffer) => { fs.writeFileSync('output.pdf', Buffer.from(buffer)); }); ``` -------------------------------- ### Install MarkupGo Node.js Client Source: https://markupgo.com/docs/node-client Instructions to install the `markupgo-node` library using npm or yarn. ```Shell npm install markupgo-node ``` ```Shell yarn add markupgo-node ``` -------------------------------- ### MarkupGo Image Generation API Reference Source: https://markupgo.com/docs/index Reference for the MarkupGo API related to image generation from URLs, including the client initialization and the 'image.fromUrl' method with its parameters and return types. ```APIDOC class MarkupGo: __init__(API_KEY: string) API_KEY: Your MarkupGo API key image: ImageService class ImageService: fromUrl(url: string, options: ImageOptions) url: The URL of the web page to convert to an image options: Configuration options for the image generation interface ImageOptions: format: string (e.g., 'jpeg', 'png', 'webp') width: number (e.g., 800) height: number (e.g., 600) Return Types for fromUrl: .json(): Promise - Returns a promise that resolves to a task object with details about the image generation. .buffer(): Promise - Returns a promise that resolves to a Buffer containing the image data. ``` -------------------------------- ### Example Configuration for Image Generation Options Source: https://markupgo.com/docs/api/image Illustrates a complete configuration object for image generation, demonstrating how to set various image properties, emulation settings, wait conditions, and error handling. This JavaScript example can be used as a template for API requests. ```javascript const ExampleImageOptions = { properties: { format: 'png', quality: 80, omitBackground: false, width: 800, height: 600, clip: false }, emulatedMediaType: 'print', waitDelay: '2s', waitForExpression: 'document.querySelector("h1") !== null', extraHttpHeaders: { 'X-My-Custom-Header': 'My custom value' }, failOnHttpStatusCodes: [404, 500], failOnConsoleExceptions: true, skipNetworkIdleEvent: true, optimizeForSpeed: true }; ``` -------------------------------- ### Generate Image from URL using Node.js Client Source: https://markupgo.com/docs/index This snippet demonstrates how to generate an image from a given URL using the MarkupGo Node.js client library. It shows how to initialize the client with an API key, specify image options like format, width, and height, and then retrieve the image as JSON task details or directly as a buffer to save to a file. ```TypeScript import MarkupGo from 'markupgo-node'; import * as fs from 'fs'; const markupGo = new MarkupGo({ API_KEY: 'YOUR_API_KEY' }); const url: string = 'https://markupgo.com'; const imageOptions: ImageOptions = { format: 'jpeg', width: 800, height: 600 }; markupGo.image.fromUrl(url, imageOptions).json().then((task) => { console.log(task); }); markupGo.image.fromUrl(url, imageOptions).buffer().then((buffer) => { fs.writeFileSync('output.jpg', Buffer.from(buffer)); }); ``` -------------------------------- ### Example Image Generation Task Response JSON Source: https://markupgo.com/docs/api/image An example JSON object representing the task response returned after successfully initiating an image generation request, detailing the generated image's properties and status. ```json { "id": "36a4ebd91745f1755df615ba", "url": "https://files.markupgo.com/66a4ebd91745f1755df615ba/1725057544064.png", "format": "png", "size": 1048576, "width": 800, "height": 600, "createdAt": "2026-06-21T10:00:00Z", "updatedAt": "2026-06-21T10:05:00Z" } ``` -------------------------------- ### MarkupGo API Authentication Header Example Source: https://markupgo.com/docs/api/introduction All API requests to MarkupGo require an API key for authentication. This key must be included in the 'x-api-key' header of each request. Calls made over plain HTTP or without this header will fail. ```HTTP Headers "x-api-key": "YOUR_API_KEY" ``` -------------------------------- ### Fetch API Request for GET /tasks Source: https://markupgo.com/docs/api/task Example of how to make a GET request to the /tasks endpoint using the JavaScript Fetch API. Includes pagination parameters and API key authentication. ```javascript fetch("api/v1/tasks?limit=10&page=1", { method: "GET", headers: { 'Content-Type': 'application/json', 'x-api-key': 'YOUR_API_KEY' } }) ``` -------------------------------- ### Generate Image from URL (Node.js) Source: https://markupgo.com/docs/node-client Example of using `markupgo.image.fromUrl` to generate an image from a given URL. Demonstrates retrieving both JSON task response and direct buffer output, with options for format, dimensions, and clipping. ```Node.js import * as fs from "fs"; const url: string = "https://example.com"; const imageOptions: ImageOptions = { properties: { format: "jpeg", width: 800, height: 600, clip: true, } }; markupgo.image.fromUrl(url, imageOptions).json() .then((task) => { console.log(task); }); markupgo.image.fromUrl(url, imageOptions).buffer() .then((buffer) => { fs.writeFileSync("output.jpg", Buffer.from(buffer)); }); ``` -------------------------------- ### Retrieve All Templates API Endpoint Source: https://markupgo.com/docs/api/templates Documents the API endpoint and provides a JavaScript example for fetching a list of all templates available in the MarkupGo system. This endpoint returns an array of template objects. ```HTTP GET /templates ``` ```JavaScript fetch('/api/v1/templates', { method: 'GET', headers: { 'x-api-key': 'YOUR_API_KEY', 'Content-Type': 'application/json' } }) ``` -------------------------------- ### Generate Image from Template (Node.js) Source: https://markupgo.com/docs/node-client Example of using `markupgo.image.fromTemplate` to generate an image from a template ID and context data. Shows both JSON task response and direct buffer output. ```Node.js import * as fs from "fs"; const templateData: TemplateData = { id: PODCAST_TEMPLATE_ID, context: { title: 'Episode 1', description: 'We talk about stuff and things, tune in!' } }; const imageOptions: ImageOptions = { properties: { format: "png", width: 800, height: 600, } }; markupgo.image.fromTemplate(templateData, imageOptions).json() .then((task) => { console.log(task); }); markupgo.image.fromTemplate(templateData, imageOptions).buffer() .then((buffer) => { fs.writeFileSync("output.png", Buffer.from(buffer)); }); ``` -------------------------------- ### Generate Image from HTML String (Node.js) Source: https://markupgo.com/docs/node-client Example of using `markupgo.image.fromHtml` to generate an image from an HTML string. Shows how to get both the JSON task response and the raw image buffer, with options for format and dimensions. ```Node.js import * as fs from "fs"; const html: string = "Hello World"; const imageOptions: ImageOptions = { properties: { format: "webp", width: 800, height: 600, } }; markupgo.image.fromHtml(html, imageOptions).json() .then((task) => { console.log(task); }); markupgo.image.fromHtml(html, imageOptions).buffer() .then((buffer) => { fs.writeFileSync("output.webp", Buffer.from(buffer)); }); ``` -------------------------------- ### Generate PDF from URL using MarkupGo Node.js Source: https://markupgo.com/docs/node-client This example illustrates generating a PDF from a given URL using `markupgo.pdf.fromUrl`. It includes setting custom PDF properties and handling both JSON task and binary buffer outputs, saving the latter to a file. ```TypeScript import * as fs from "fs"; const url: string = "https://example.com"; const pdfOptions: PdfOptions = { properties: { printBackground: true, landscape: true, }, }; markupgo.pdf.fromUrl(url, pdfOptions).json() .then((task) => { console.log(task); }); markupgo.pdf.fromUrl(url, pdfOptions).buffer() .then((buffer) => { fs.writeFileSync("output.pdf", Buffer.from(buffer)); }); ``` -------------------------------- ### JSON Response for GET /tasks Source: https://markupgo.com/docs/api/task Example of the JSON response structure for the GET /tasks endpoint, including an array of task objects and pagination metadata. ```json { "data": [ { "id": "66f96077bd3eae71a05c9cfb", "url": "https://files.markupgo.com/66923f55c937db8a3d73a1fb/1721135544120.pdf", "format": "pdf", "size": 1048576, "width": 210, "height": 297, "createdAt": "2023-06-21T10:00:00Z", "updatedAt": "2023-06-21T10:05:00Z" } ], "meta": { "total": 2, "skip": 0, "limit": 10 } } ``` -------------------------------- ### JSON: Example PDF Generation Task Response Source: https://markupgo.com/docs/api/pdf Provides an example JSON structure of the task object returned after a successful PDF generation request. It illustrates the typical fields such as id, url to the generated PDF, format, size, and creation/update timestamps. ```JSON { "id": "26a4ebd91745f1755df615ba", "url": "https://files.markupgo.com/tasks/66a4ebd91745f1755df615ba/1725057544064.pdf", "format": "pdf", "size": 1048576, "width": 210, "height": 297, "createdAt": "2026-06-21T10:00:00Z", "updatedAt": "2026-06-21T10:05:00Z" } ``` -------------------------------- ### Generate Image from Markdown (Node.js) Source: https://markupgo.com/docs/node-client Example of using `markupgo.image.fromMarkdown` to generate an image from Markdown content. Demonstrates providing Markdown input, CSS, dark mode, and padding options, and retrieving both JSON task response and image buffer. ```Node.js import * as fs from "fs"; const input: MarkdownInput = { markdown: "# Hello World", css: "h1 { color: #f2f2f2; }", dark: true, padding: 45, } const imageOptions: ImageOptions = { properties: { format: "png", width: 800, height: 600, } }; markupgo.image.fromMarkdown(input, imageOptions).json() .then((task) => { console.log(task); }); markupgo.image.fromMarkdown(input, imageOptions).buffer() .then((buffer) => { fs.writeFileSync("output.png", Buffer.from(buffer)); }); ``` -------------------------------- ### Complete Magic URL for Image Generation Source: https://markupgo.com/docs/magic-template-url This example provides a full Magic URL, combining the base template URL with dynamically generated query parameters. This URL can be directly used in a browser or application to generate an image or PDF based on the specified context and options. ```URL https://render.markupgo.com/template/{YOUR_TEMPLATE_ID}.png?episode=1&title=We talk about stuff and things, tune in!&options[properties][width]=1300&options[properties][omitBackground]=true ``` -------------------------------- ### Generate PDF from Markdown using MarkupGo Node.js Source: https://markupgo.com/docs/node-client This example demonstrates converting Markdown content into a PDF using `markupgo.pdf.fromMarkdown`. It shows how to provide Markdown input with optional CSS, dark mode, and padding, along with specific PDF properties like `singlePage`. ```TypeScript import * as fs from "fs"; const input: MarkdownInput = { markdown: "# Hello World", css: "h1 { color: #f2f2f2; }", dark: true, padding: 45, } const pdfOptions: PdfOptions = { properties: { singlePage: true, // Best way to render all content in a single page }, }; markupgo.pdf.fromMarkdown(input, pdfOptions).json() .then((task) => { console.log(task); }); markupgo.pdf.fromMarkdown(input, pdfOptions).buffer() .then((buffer) => { fs.writeFileSync("output.pdf", Buffer.from(buffer)); }); ``` -------------------------------- ### Template Object API Definition and Example Source: https://markupgo.com/docs/api/templates Defines the structure and properties of the `Template` object used across the MarkupGo API, including its fields, types, and an example JSON representation. This object is central to managing reusable content for PDF and image generation. ```TypeScript type Template = { id: string owner: User name: string html: string css: string width: number height: number lastTask: Task context: string autoHeight: boolean libraries: { js: string[] css: string[] } format: 'pdf' | 'png' | 'jpeg' | 'webp' usage?: number isDeleted?: boolean deletedAt?: string } ``` ```JSON { "id": "666b3561fbaa04f6877e70b5", "name": "My Template", "context": { "name": "John Doe" }, "html": "

Hello, {{name}}!

", "css": "h1 { color: red; }", "libraries": { "js": ["https://cdn.tailwindcss.com"], "css": ["https://example.com/style.css"] }, "autoHeight": false, "createdAt": "2026-06-21T10:00:00Z", "updatedAt": "2026-06-21T10:05:00Z" } ``` ```APIDOC | Key | Description | | --- | --- | | `id` | The unique identifier of the template. | | `name` | The name of the template. | | `format` | The default export format of the template. | | `html` | The HTML content of the template. | | `css` | The CSS content of the template. | | `width` | The width of the template in pixels. | | `height` | The height of the template in pixels. | | `context` | The template context. | | `autoHeight` | Whether to automatically adjust the height of the template. | | `libraries` | The template libraries. | | `libraries.js` | The template JavaScript libraries. | | `libraries.css` | The template CSS libraries. | | `createdAt` | The date and time the template was created. | | `updatedAt` | The date and time the template was last updated. | ``` -------------------------------- ### Convert and Merge Multiple Office Files to Single PDF using MarkupGo Node.js Source: https://markupgo.com/docs/node-client This example illustrates converting multiple Office files into a single merged PDF document using `markupgo.office.convert` with the `merge: true` option. It demonstrates how to pass an array of files and specific conversion options. ```TypeScript import { type PathLikeOrReadStream } from "markupgo-node"; import fs from "fs"; const buffer = fs.readFileSync("./src/playground/test.docx"); const files = [ { data: buffer, ext: "csv", }, "./src/playground/report.xlsx", ] as PathLikeOrReadStream[]; const options: OfficeToPdfOptions = { merge: true, }; markupgo.office.convert(files, options).json().then((task) => { console.log(task); }); // OR markupgo.office.convert(files, options).buffer().then((buffer) => { fs.writeFileSync("output.pdf", Buffer.from(buffer)); }); ``` -------------------------------- ### Example API Request Body for Magic URL Context Source: https://markupgo.com/docs/magic-template-url This JSON object illustrates a typical API request body structure that defines the context and options for generating an image or PDF via the Magic URL. It demonstrates how 'context' and 'options' fields organize the data, with 'context' being the default for top-level fields. ```JSON { "context": { "episode": 1, "title": "We talk about stuff and things, tune in!", }, "options": { "properties": { "width": 1200, "omitBackground": true } } } ``` -------------------------------- ### JavaScript Fetch Request to Generate Image from Markdown Source: https://markupgo.com/docs/api/image Example of making a POST request to the `/api/v1/image` endpoint using JavaScript's `fetch` API to generate an image from markdown content, including headers and request body. ```javascript fetch('/api/v1/image', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': 'YOUR_API_KEY' }, body: JSON.stringify({ source: { type: 'markdown', data: { markdown: '# Hello, World!', padding: 20, css: 'body { background-color: #f0f0f0; }', dark: false } }, options: ImageOptions }) }) ``` -------------------------------- ### API Endpoint: GET /tasks Source: https://markupgo.com/docs/api/task Retrieves a list of API activity tasks. Tasks are created after calling the /pdf or /image endpoints. Supports pagination via limit and page query parameters. ```APIDOC GET /tasks Description: Retrieves a list of API activity tasks. Query Parameters: limit: The number of tasks to return. (Default: 10) page: The page number to return. (Default: 1) Response Fields: id: The unique identifier of the task. url: The URL of the generated document or image. format: The format of the generated document or image. size: The size of the generated document or image in bytes. width: The width of the generated document or image in pixels. height: The height of the generated document or image in pixels. createdAt: The date and time the task was created. updatedAt: The date and time the task was last updated. ``` -------------------------------- ### Set Landscape Orientation for Office to PDF Conversion Source: https://markupgo.com/docs/api/office-to-pdf Example demonstrating how to set the `landscape` page property to `true` within the `properties` field of the `multipart/form-data` request for the Office to PDF API. This ensures the output PDF document is rendered in landscape orientation. ```JavaScript formData.append('properties[landscape]', true); ``` -------------------------------- ### Retrieve Single Template by ID API Endpoint Source: https://markupgo.com/docs/api/templates Documents the API endpoint and provides a JavaScript example for fetching a specific template using its unique identifier. This endpoint returns a single template object. ```HTTP GET /templates/:id ``` ```JavaScript fetch('/api/v1/templates/666b3561fbaa04f6877e70b5', { method: 'GET', headers: { 'x-api-key': 'YOUR_API_KEY', 'Content-Type': 'application/json' } }) ``` -------------------------------- ### HTTP Response for DELETE /tasks/{id} Source: https://markupgo.com/docs/api/task Example of the successful HTTP response for the DELETE /tasks/{id} endpoint, indicating no content is returned upon successful deletion. ```http 204 No Content ``` -------------------------------- ### Example JSON Response for PDF Generation Task Source: https://markupgo.com/docs/api/pdf This JSON object illustrates the structure of the task response returned by the MarkupGo API after a PDF generation request. It includes unique identifiers, the URL to the generated PDF, format, size, dimensions, and creation/update timestamps. ```JSON { "id": "26a4ebd91745f1755df615ba", "url": "https://files.markupgo.com/tasks/66a4ebd91745f1755df615ba/1725057544064.pdf", "format": "pdf", "size": 1048576, "width": 210, "height": 297, "createdAt": "2026-06-21T10:00:00Z", "updatedAt": "2026-06-21T10:05:00Z" } ``` -------------------------------- ### Generate PDF from URL via POST Request Source: https://markupgo.com/docs/api/pdf This JavaScript `fetch` example shows how to make a POST request to the `/pdf` endpoint to generate a PDF from a specified URL. It includes setting content type headers, an API key, and the request body with source URL and PDF options. ```JavaScript fetch('/api/v1/pdf', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': 'YOUR_API_KEY' }, body: JSON.stringify({ source: { type: 'url', data: 'https://example.com' }, options: PdfOptions }) }) ``` -------------------------------- ### Transforming Image with HTML img src Source: https://markupgo.com/docs/image-transformation Demonstrates how to transform an image by specifying its URL and transformation parameters directly within an HTML `` tag's `src` attribute. This example resizes the image to a width of 300 pixels and a height of 200 pixels. ```HTML ``` -------------------------------- ### Example JSON Task Response from Magic URL Source: https://markupgo.com/docs/magic-template-url This JSON object represents a typical response received when a Magic URL is invoked with the `json=true` parameter. It provides a unique task `id` and the `url` where the generated image or PDF can be accessed, enabling developers to handle the file generation process programmatically. ```JSON { "id": "66d301f42d9d3c58d27cdffd", "url": "https://files.markupgo.com/tasks/66923f55c937bb8a3d73a1fb/1725104627341.png", ... } ``` -------------------------------- ### Image Transformation API: Center Play Button Source: https://markupgo.com/docs/image-transformation This example shows how to overlay a play button image onto another image. When no position parameters (like "top", "bottom", "left", "right") are specified for a "draw" entry, the overlay image is automatically centered on the base image. ```APIDOC https://files.markupgo.com/{image-url} ?draw[0][url]=https://example.com/play-button.png ``` -------------------------------- ### Image Transformation API: Add Signature Source: https://markupgo.com/docs/image-transformation This example illustrates how to place a signature image at a specific position on an image using the "draw" parameter. The "bottom" and "right" parameters define the offset in pixels from the respective edges of the base image, allowing precise placement. ```APIDOC https://files.markupgo.com/{image-url} ?draw[0][url]=https://example.com/signature.png &draw[0][bottom]=5 &draw[0][right]=5 ``` -------------------------------- ### Embed Magic URL Images in HTML Source: https://markupgo.com/docs/magic-template-url These HTML snippets demonstrate how to embed images generated by Magic URLs directly into a webpage using the `` tag. Each example showcases the use of different query parameters to dynamically generate unique podcast episode thumbnails from the same template, illustrating the flexibility of the Magic URL. ```HTML ``` ```HTML ``` ```HTML ``` ```HTML ``` -------------------------------- ### Image Transformation API: Apply Photo Watermark Source: https://markupgo.com/docs/image-transformation This example demonstrates how to add a repeating, semi-transparent watermark to an image using the "draw" parameter. The "url" specifies the watermark image, "repeat" enables tiling across the image, and "opacity" controls the transparency level (0.0 to 1.0). ```APIDOC https://files.markupgo.com/{image-url} ?draw[0][url]=https://example.com/watermark.png &draw[0][repeat]=true &draw[0][opacity]=0.2 ``` -------------------------------- ### Image Transformation API: Combine Multiple Drawing Operations Source: https://markupgo.com/docs/image-transformation This comprehensive example demonstrates how to apply multiple distinct drawing operations to a single image using the "draw" array. Each indexed entry in the "draw" array ("draw[0]", "draw[1]", etc.) represents a separate overlay, allowing for complex compositions like watermarks, play buttons, and signatures simultaneously. ```APIDOC https://files.markupgo.com/{image-url} ?draw[0][url]=https://example.com/watermark.png &draw[0][repeat]=true &draw[0][opacity]=0.2 &draw[1][url]=https://example.com/play-button.png &draw[2][url]=https://example.com/signature.png &draw[2][bottom]=5 &draw[2][right]=5 ``` -------------------------------- ### Initialize MarkupGo Node.js Client Source: https://markupgo.com/docs/node-client Demonstrates how to import and initialize the `MarkupGo` client with your API key. ```Node.js import MarkupGo from "markupgo-node"; const markupgo = new MarkupGo({ API_KEY: "your_api_key_here", }); ``` -------------------------------- ### MarkupGo API Introduction and Core Concepts Source: https://markupgo.com/docs/api/introduction This section outlines the fundamental principles of the MarkupGo API, detailing its RESTful architecture, base URL, and authentication methods. It also covers error handling conventions and provides a summary of the primary resources available for interaction, such as templates, tasks, and document generation. ```APIDOC API Overview: Architecture: RESTful Request Bodies: Form-encoded Response Bodies: JSON-encoded HTTP Status Codes: Standard (2xx, 4xx, 5xx) Authentication: API Keys Base URL: URL: https://api.markupgo.com/api/v1 Description: All endpoints are relative to this base URL. Authentication: Method: API Keys Location: MarkupGo dashboard (for viewing/managing keys) Requirement: All requests must be over HTTPS. Header: Name: x-api-key Value: YOUR_API_KEY Description: Include your API key in this header for each request. Error Handling: Convention: Conventional HTTP response codes 2xx Range: Success 4xx Range: Client-side errors (e.g., missing parameters) 5xx Range: Server-side errors Resources: Templates: Description: Reusable HTML, CSS, and JavaScript snippets for generating PDFs or images. Tasks: Description: View status of PDF/image generation tasks and retrieve generated files. Generating PDFs: Description: Generate PDFs from a URL, HTML, or a template with customizable options. Generating Images: Description: Generate images from a URL, HTML, or a template with customizable options. ``` -------------------------------- ### Office to PDF API Overview and Constraints Source: https://markupgo.com/docs/api/office-to-pdf Comprehensive documentation for the Office to PDF API, detailing its purpose, current beta status, and core functionality for converting over 130 document formats to PDF. It highlights the use of `multipart/form-data` for file uploads and the return of a task object for progress monitoring, along with specified limitations. ```APIDOC Office to PDF API: Description: Convert 130+ office documents to PDF. Currently in BETA. Request Format: multipart/form-data (binary file upload) Response: Task object (for monitoring conversion progress) Limitations: Max file size: 5MB per document Max files per request: 10 Supported Formats: Word Processing: .doc, .docx, .dotx, .rtf, .odt, .txt, .abw, ... Spreadsheets: .xls, .xlsx, .csv, .ods, .sdc, ... Presentations: .ppt, .pptx, .odp, .sxi, .pot, ... Graphics & Images: .bmp, .gif, .jpeg, .png, .svg, .tiff, ... ``` -------------------------------- ### MarkupGo Node.js Client Class Overview Source: https://markupgo.com/docs/node-client Overview of the main classes provided by the `markupgo-node` client for image, PDF, and Office document conversion. ```APIDOC ImageConversion: Provides methods to generate images from templates, URLs, or HTML strings. PdfConversion: Provides methods to generate PDFs from templates, URLs, or HTML strings. OfficeConversion: Provides methods to convert over 130 document formats to PDF, including .docx, .xlsx, .pptx, and more. It supports merging multiple files into a single PDF. ``` -------------------------------- ### Convert Single Office File to PDF using MarkupGo Node.js Source: https://markupgo.com/docs/node-client This snippet demonstrates converting a single Office file (e.g., DOCX, XLSX) to PDF using `markupgo.office.convert`. It shows how to provide file data as a buffer or path, and how to handle the output as a JSON task or a binary PDF buffer. ```TypeScript import { type PathLikeOrReadStream } from "markupgo-node"; import fs from "fs"; const buffer = fs.readFileSync("./src/playground/test.docx"); const files = [ { data: buffer, ext: "csv", }, "./src/playground/report.xlsx", ] as PathLikeOrReadStream[]; markupgo.office.convert(files).json().then((task) => { console.log(task); }); // OR markupgo.office.convert(files).buffer().then((buffer) => { fs.writeFileSync("output.pdf", Buffer.from(buffer)); }); ``` -------------------------------- ### Office to PDF API Options (APIDOC) Source: https://markupgo.com/docs/api/office-to-pdf Detailed API documentation for configuring Office to PDF conversions, including image settings, merging behavior, metadata embedding, and the overall request body structure with nested properties. ```APIDOC Images Options: losslessImageCompression: boolean (default: false) Description: Use lossless image compression (like PNG) or lossy compression (like JPEG). quality: number (1-100) (default: 90) Description: Set the JPG export quality between 1 and 100. Higher values produce better quality images. reduceImageResolution: boolean (default: false) Description: Reduce image resolution to the value set by maxImageResolution. maxImageResolution: number (75, 150, 300, 600, 1200) (default: 300) Description: If reduceImageResolution is true, reduce images to the given DPI. Merge Option: merge: boolean (default: false) Description: Merge alphanumerically the resulting PDFs. If sending multiple files, this must be true. Metadata Option: metadata: JSON (default: None) Description: The metadata to write (in JSON format). Body (Request Payload): files: Array (required) Description: The office documents to convert. properties?: PageProperties (optional) Description: Custom page properties for the conversion. pdfUA?: boolean (optional) Description: Enable PDF/UA compliance. merge?: boolean (optional) Description: Merge multiple documents into a single PDF. metadata?: any (optional) Description: Metadata to embed in the PDF. losslessImageCompression?: boolean (optional) Description: Use lossless image compression. reduceImageResolution?: boolean (optional) Description: Reduce image resolution. quality?: number (optional) Description: Set JPG export quality. maxImageResolution?: 75 | 150 | 300 | 600 | 1200 (optional) Description: Maximum image resolution if reduction is enabled. PageProperties (Nested in Body): landscape?: boolean (optional) nativePageRanges?: { from: number; to: number; } (optional) exportFormFields?: boolean (optional) singlePageSheets?: boolean (optional) allowDuplicateFieldNames?: boolean (optional) exportBookmarks?: boolean (optional) exportBookmarksToPdfDestination?: boolean (optional) exportPlaceholders?: boolean (optional) exportNotes?: boolean (optional) exportNotesPages?: boolean (optional) exportOnlyNotesPages?: boolean (optional) exportNotesInMargin?: boolean (optional) convertOooTargetToPdfTarget?: boolean (optional) exportLinksRelativeFsys?: boolean (optional) exportHiddenSlides?: boolean (optional) skipEmptyPages?: boolean (optional) addOriginalDocumentAsStream?: boolean (optional) ``` -------------------------------- ### Create Template (POST /templates) Source: https://markupgo.com/docs/api/templates This endpoint allows creating a new template resource. It requires a JSON request body containing the template's name, context, HTML, CSS, libraries (JS/CSS URLs), and autoHeight setting. A successful request returns a template object. ```APIDOC POST /templates Request Body Schema: name: string - The name of the template. context: object - The template context. html: string - The template HTML content. css: string - The template CSS content. libraries: object - The template libraries. libraries.js: array - The template JavaScript libraries. libraries.css: array - The template CSS libraries. autoHeight: boolean - Whether to automatically adjust the height of the template. ``` ```JavaScript fetch('/api/v1/templates', { method: 'POST', headers: { 'x-api-key': 'YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'My Template', context: { name: 'John Doe' }, html: '

Hello, {{name}}!

', css: 'h1 { color: red; }', libraries: { js: ['https://cdn.tailwindcss.com'], css: ['https://example.com/style.css'] }, autoHeight: false }) }) ``` -------------------------------- ### Supported Presentation Formats Source: https://markupgo.com/docs/api/office-to-pdf This section lists the file extensions for presentation documents that can be converted to PDF using the API. ```APIDOC .fodp .key .odp .otp .pot .potm .potx .pps .ppt .pptm .pptx .sdd .sdp .sti .sxi ``` -------------------------------- ### Generate PDF from Template using MarkupGo Node.js Source: https://markupgo.com/docs/node-client This snippet demonstrates generating a PDF from a predefined template using `markupgo.pdf.fromTemplate`. It shows how to pass template data and PDF options, and how to retrieve the result as a JSON task or a binary buffer for file saving. ```TypeScript import * as fs from "fs"; const templateData: TemplateData = { id: PODCAST_TEMPLATE_ID, context: { title: 'Episode 1', description: 'We talk about stuff and things, tune in!' } }; const pdfOptions: PdfOptions = { properties: { printBackground: true, landscape: true, }, }; markupgo.pdf.fromTemplate(templateData, pdfOptions).json() .then((task) => { console.log(task); }); markupgo.pdf.fromTemplate(templateData, pdfOptions).buffer() .then((buffer) => { fs.writeFileSync("output.pdf", Buffer.from(buffer)); }); ``` -------------------------------- ### Fetch API Request for DELETE /tasks/{id} Source: https://markupgo.com/docs/api/task Example of how to make a DELETE request to remove a specific task using the JavaScript Fetch API. Requires the task ID and API key authentication. ```javascript fetch("api/v1/tasks/66f96077bd3eae71a05c9cfb", { method: "DELETE", headers: { 'Content-Type': 'application/json', 'x-api-key': 'YOUR_API_KEY' } }) ``` -------------------------------- ### Fetch PDF as Buffer from Office to PDF API (JavaScript) Source: https://markupgo.com/docs/api/office-to-pdf This snippet shows how to modify the API endpoint to receive the converted PDF as a binary buffer response, by appending '/buffer' to the conversion URL. ```JavaScript fetch('/api/v1/office/convert/buffer') ``` -------------------------------- ### Convert Office File to PDF with Custom Properties using MarkupGo Node.js Source: https://markupgo.com/docs/node-client This snippet shows how to convert Office files to PDF while applying custom PDF properties like `landscape` and `printBackground`. It uses `markupgo.office.convert` and demonstrates passing an `OfficeToPdfOptions` object. ```TypeScript import { type PathLikeOrReadStream } from "markupgo-node"; import fs from "fs"; const buffer = fs.readFileSync("./src/playground/test.docx"); const files = [ { data: buffer, ext: "csv", }, "./src/playground/report.xlsx", ] as PathLikeOrReadStream[]; const options: OfficeToPdfOptions = { properties: { landscape: true, printBackground: true, } }; markupgo.office.convert(files, options).json().then((task) => { console.log(task); }); // OR markupgo.office.convert(files, options).buffer().then((buffer) => { fs.writeFileSync("output.pdf", Buffer.from(buffer)); }); ``` -------------------------------- ### Create New Template API Endpoint Source: https://markupgo.com/docs/api/templates Documents the API endpoint for creating a new template, including the required request body parameters and their descriptions. This endpoint accepts a JSON payload to define the new template's properties. ```HTTP POST /templates ``` ```APIDOC | Key | Description | | --- | --- | | `name` | The name of the template. | | `context` | The template context. | | `html` | The template HTML content. | | `css` | The template CSS content. | | `libraries` | The template libraries. | | `libraries.js` | The template JavaScript libraries. | | `libraries.css` | The template CSS libraries. | | `autoHeight` | Whether to automatically adjust the height of the template. | ``` -------------------------------- ### TypeScript Type Definitions for Office to PDF API Options Source: https://markupgo.com/docs/api/office-to-pdf Defines the TypeScript interfaces for the available options when converting office documents to PDF. This includes page properties, file handling, and various conversion settings. ```TypeScript type PageProperties = { landscape?: boolean; nativePageRanges?: { from: number; to: number; }; exportFormFields?: boolean; singlePageSheets?: boolean; allowDuplicateFieldNames?: boolean; exportBookmarks?: boolean; exportBookmarksToPdfDestination?: boolean; exportPlaceholders?: boolean; exportNotes?: boolean; exportNotesPages?: boolean; exportOnlyNotesPages?: boolean; exportNotesInMargin?: boolean; convertOooTargetToPdfTarget?: boolean; exportLinksRelativeFsys?: boolean; exportHiddenSlides?: boolean; skipEmptyPages?: boolean; addOriginalDocumentAsStream?: boolean; }; type Body = { files: Array; properties?: PageProperties; pdfUA?: boolean; merge?: boolean; metadata?: any; losslessImageCompression?: boolean; reduceImageResolution?: boolean; quality?: number; maxImageResolution?: 75 | 150 | 300 | 600 | 1200; }; ``` -------------------------------- ### Supported Graphics and Image Formats Source: https://markupgo.com/docs/api/office-to-pdf This section lists the file extensions for graphics and image files that can be converted to PDF using the API. ```APIDOC .bmp .cdr .cgm .cmx .dbf .dxf .emf .eps .fodg .gif .jpeg .jpg .met .pbm .pcd .pct .pcx .pgm .png .ppm .psd .ras .sgl .svg .svm .swf .tga .tif .tiff .vdx .vor .vsd .vsdm .vsdx .wb2 .wks .wmf .xbm .xpm ``` -------------------------------- ### Other Supported Document Formats Source: https://markupgo.com/docs/api/office-to-pdf This section lists various other file extensions that can be converted to PDF using the API. ```APIDOC .bib .epub .htm .html .mml .odd .oth .pdf .pub .pxl .sda .sgl .sxg .uof .uop .uos .vor .xml .xhtml ``` -------------------------------- ### Fetch Image as Buffer from API Endpoint Source: https://markupgo.com/docs/api/image Demonstrates how to make an API call to retrieve an image as a binary buffer by appending `/buffer` to the image endpoint URL. This JavaScript snippet is useful for direct binary data handling. ```javascript fetch('/api/v1/image/buffer') ``` -------------------------------- ### Convert Single DOCX File to PDF using Office to PDF API (JavaScript) Source: https://markupgo.com/docs/api/office-to-pdf Demonstrates how to convert a single .docx file to PDF using the Office to PDF API. It constructs a FormData object with the file and sends a POST request to the conversion endpoint. ```JavaScript const formData = new FormData(); formData.append('files', file); // file is the .docx file fetch('/api/v1/office/convert', { headers: { 'x-api-key': process.env.MARKUPGO_API_KEY }, method: 'POST', body: formData, }).then((response) => response.json()); ``` -------------------------------- ### Supported Spreadsheet Formats Source: https://markupgo.com/docs/api/office-to-pdf This section lists the file extensions for spreadsheet documents that can be converted to PDF using the API. ```APIDOC .csv .dif .fods .numbers .ods .ots .sdc .slk .stc .sxc .xls .xlsb .xlsm .xlsx .xlt .xltm .xltx .xlw ``` -------------------------------- ### Office to PDF Conversion API `convert` Method and Input Types Source: https://markupgo.com/docs/node-client Describes the `convert` API method for transforming office files into PDF, accepting an array of file inputs and optional conversion settings. It outlines the return structure for accessing results as JSON or a buffer. Additionally, it defines `PathLikeOrReadStream`, `FileInfo`, and `FileExtension` types, detailing the supported input file formats and structures. ```TypeScript convert(files: PathLikeOrReadStream[], options?: OfficeToPdfOptions): { json: () => Promise; buffer: () => Promise; } type PathLikeOrReadStream = string | FileInfo; type FileInfo = { data: Buffer | ReadStream; ext: FileExtension; } type FileExtension = '123' | '602' | 'abw' | 'bib' | 'bmp' | 'cdr' | 'cgm' | 'cmx' | 'csv' | 'cwk' | 'dbf' | 'dif' | 'doc' | 'docm' | 'docx' | 'dot' | 'dotm' | 'dotx' | 'dxf' | 'emf' | 'eps' | 'epub' | 'fodg' | 'fodp' | 'fods' | 'fodt' | 'fopd' | 'gif' | 'htm' | 'html' | 'hwp' | 'jpeg' | 'jpg' | 'key' | 'ltx' | 'lwp' | 'mcw' | 'met' | 'mml' | 'mw' | 'numbers' | 'odd' | 'odg' | 'odm' | 'odp' | 'ods' | 'odt' | 'otg' | 'oth' | 'otp' | 'ots' | 'ott' | 'pages' | 'pbm' | 'pcd' | 'pct' | 'pcx' | 'pdb' | 'pdf' | 'pgm' | 'png' | 'pot' | 'potm' | 'potx' | 'ppm' | 'pps' | 'ppt' | 'pptm' | 'pptx' | 'psd' | 'psw' | 'pub' | 'pwp' | 'pxl' | 'ras' | 'rtf' | 'sda' | 'sdc' | 'sdd' | 'sdp' | 'sdw' | 'sgl' | 'slk' | 'smf' | 'stc' | 'std' | 'sti' | 'stw' | 'svg' | 'svm' | 'swf' | 'sxc' | 'sxd' | 'sxg' | 'sxi' | 'sxm' | 'sxw' | 'tga' | 'tif' | 'tiff' | 'txt' | 'uof' | 'uop' | 'uos' | 'uot' | 'vdx' | 'vor' | 'vsd ``` -------------------------------- ### API Reference: POST /image Endpoint (Template Source) Source: https://markupgo.com/docs/api/image This section outlines the request body for generating an image from a template. It specifies `source.type` as `template` and details the `source.data` fields including `id`, `context`, `html`, `css`, and `libraries`. Optional `options` are available. The endpoint returns a task object. ```APIDOC POST /image - From Template Request Body: source.type: string (required) - Must be 'template'. source.data: object (required) - Template data. source.data.id: string (required) - The template ID. source.data.context: object (optional) - The template context. source.data.html: string (optional) - The template HTML content. source.data.css: string (optional) - The template CSS content. source.data.libraries: object (optional) - The template libraries. source.data.libraries.js: array (optional) - The template JavaScript libraries. source.data.libraries.css: array (optional) - The template CSS libraries. options: ImageOptions (optional) - Image generation options. Response: task object (see /docs/api/task) ``` -------------------------------- ### Image API: Generate from Template Source: https://markupgo.com/docs/node-client Provides a method to generate an image using a predefined template. It accepts `TemplateData` for dynamic content and `ImageOptions` for generation settings, returning promises for either task metadata (JSON) or the image binary (ArrayBuffer). ```TypeScript fromTemplate(data: TemplateData, options?: ImageOptions): { json: () => Promise; buffer: () => Promise; } type TemplateData = { id: string; context?: Record; html?: string; css?: string; libraries?: Record[]; autoHeight?: boolean; } ```