DrawPDF Internal API Reference

This document lists every single class, method, and utility function found in the DrawPDF source code. Use the sidebar to navigate or search.

DrawPDF.js Main Entry Point

create(element, options) STATIC
Factory method to initialize a new DrawPDF instance and attach it to a DOM element.
constructor()
Creates a new instance. Does not initialize the editor until init() is called.
init(elementOrSelector, options)
Initializes CKEditor, loads fonts, and sets up the renderer.
parseHtml(html) STATIC
Converts raw HTML string into a Blueprint object using CKEditorParser.
renderBlueprint(blueprint, data) STATIC
Render a PDF directly from a Blueprint object (Headless mode). Returns Data URL.
downloadBlueprint(blueprint, filename, data) STATIC
Render and download a PDF directly from a Blueprint object.
getData()
Syncs editor content to internal blueprint. Returns the Blueprint object.
setData(blueprint)
Sets the editor content from a Blueprint object (using blueprint.sourceHtml).
render(data)
Generates the PDF from current state. Returns Data URL string.
download(filename, data)
Generates and triggers download of the PDF file.
getBlob(data)
Returns the generated PDF as a Blob object.
preview(data)
Opens the generated PDF in a new browser tab.
registerFont(fontUrl)
Dynamically loads a JS font file.
destroy()
Destroys the CKEditor instance and cleans up resources.

PDFRenderer.js Layout Engine

constructor(fontConfig)
Initializes the renderer with optional font configuration.
render(blueprint, data)
Main entry point. Iterates over pages and elements in the blueprint.
renderPage(page, data)
Renders a single page from the blueprint.
renderText(element, data)
Renders a standard text block.
renderRichText(element, data)
Renders complex text with mixed styles (bold, italic) using `JsPdfService.addMixedParagraph`.
renderTable(element, data)
Renders a table using `jspdf-autotable`. Supports data binding.
renderImage(element, data)
Renders an image element.
renderEvalBlock(element, data)
Executes raw JavaScript code found in `// eval` blocks within the PDF context.
calculateX(element)
Calculates X position based on alignment, indents, and margins.
replaceVariables(text, data)
Uses `TemplateEngine` to process `{{variable}}` placeholders.

CKEditorParser.js HTML to JSON

parse(html)
Parses HTML string into Blueprint JSON.
processNode(node)
Recursive function to process DOM nodes. Dispatches to specific handlers.
processParagraph(node)
Handlers <p> tags. Detects if it should be RichText or CodeBlock.
processTable(tableNode)
Extracts headers, rows, and styles from HTML tables.
processImage(imgNode)
Extracts src, width, height from <img> tags.
extractStyles(node)
Parses CSS style string into an object (bold, color, align, etc.).

JsPdfService.js Low Level Rendering

This service contains over 80 methods for granular PDF control.

Core & Setup

constructor(options)
Initializes jsPDF instance, loads fonts, sets up page size.
savePDF(filename)
previewPDF()
uploadPDFToServer(url, filename, options)
Uploads the generated PDF to a remote server endpoint via POST.

Drawing Primitives

addText(text, x, y, options)
Draws text with word wrapping and decoding.
drawJustifiedText(text, x, y, maxWidth, options)
Draws text fully justified to both margins.
addHorizontalLine(options)
addImage(imageData, x, y, w, h, options)

Layout Control

addNewPage()
Adds a new page and resets currentY.
checkPageBreak(heightNeeded)
Automatically adds a new page if the required height exceeds remaining space.
addSpace(height)
Moves currentY down by specified height.

Complex Elements (Lists, Menus, Tables)

addTable(headers, rows, options)
Wrapper for autoTable plugin.
addTableOfContents(items, options)
Generates a TOC with leader dots (e.g., "Chapter 1 .......... 5").
addPriceList(items, options)
addMenu(sections, options)
Creates a restaurant-style menu layout.
addMultiLevelList(items, options)
Creates nested lists (I. -> A. -> 1. -> a.).
addOutline(items, options)
Creates a numbered outline (1.1, 1.1.2) with page references.

Active Forms & Signatures

addFillInLine(label, options)
Creates a line for user input (e.g., "Name: ________________").
addFillInForm(fields, options)
Generates a full form with multiple fill-in lines.
addSignature(name, title, date, options)
Standard signature block with Title, Date, and Name.
addSignatureWithImage(name, title, image, date, options)
Signature block that includes a signature image.
addSecondarySignature(options)
Adds "flash" signatures (small signatures) to the corner of every page.

Styled Text Builders

addMixedText(parts, options)
Draws a single line containing multiple styles (e.g., normal + bold + red).
addMixedParagraph(parts, options)
Draws a wrapping paragraph with mixed styles.
bold(text)
Helper to create a bold text part object.
italic(text)
Helper to create an italic text part object.

Utilities

TemplateEngine.js

process(text, data)
Processes Handlebars-like syntax: {{#if}}, {{#each}}, {{val}}.

RichTextTokenizer.js

tokenize(html)
Splits HTML string into styled segments for `addMixedParagraph`.

helpers.js

mmToPx(mm)
generateId()