### Python Hello World Function Source: https://github.com/hackerbone/mdpdfmake/blob/main/example/test.md A simple Python function that prints 'Hello World!' to the console. This serves as a basic example of Python syntax within the project documentation. ```python def hello(): print("Hello World!") ``` -------------------------------- ### Install mdpdfmake Package Source: https://github.com/hackerbone/mdpdfmake/blob/main/README.md Installs the mdpdfmake package using npm, which is required to use the Markdown to PDFMake conversion functionality. ```bash npm install mdpdfmake ``` -------------------------------- ### Convert Markdown to PDFMake with Custom Options Source: https://context7.com/hackerbone/mdpdfmake/llms.txt Demonstrates the main mdpdfmake function to convert Markdown to a PDFMake document definition. It includes setup for pdfMake, sample Markdown, custom options for headings, and the process of creating and downloading a PDF. Handles potential errors during PDF generation. ```typescript import { mdpdfmake } from "mdpdfmake"; import pdfMake from "pdfmake/build/pdfmake"; import pdfFonts from "pdfmake/build/vfs_fonts"; pdfMake.vfs = pdfFonts.pdfMake.vfs; const markdown = `# Project Report\n\nThis is a comprehensive **project report** with *multiple* sections.\n\n## Features Implemented\n\n- Authentication system with JWT - User profile management - Real-time notifications\n\n## Code Example\n\n```javascript function authenticate(token) { return jwt.verify(token, SECRET_KEY); } ```\n\n> **Note:** All features are production-ready.\n![Logo](https://example.com/logo.png)\n\n---\n\nFor more information, visit [our website](https://example.com).`; const options = { headingFontSizes: [28, 24, 20, 16, 14, 12], headingUnderline: true }; mdpdfmake(markdown, options) .then((docDefinition) => { const pdfDoc = pdfMake.createPdf(docDefinition); pdfDoc.download('report.pdf'); }) .catch((error) => { console.error('PDF generation failed:', error); }); ``` -------------------------------- ### Generate Complete PDF from Markdown with mdpdfmake (TypeScript) Source: https://context7.com/hackerbone/mdpdfmake/llms.txt This comprehensive example illustrates the full integration of mdpdfmake with PDFMake in a Node.js environment to generate and save PDF files from Markdown content. It includes initializing PDFMake with fonts, defining document structure, creating a PDF document, and saving it as a buffer or downloading it. Configuration options for headings are also demonstrated. ```typescript import { mdpdfmake } from "mdpdfmake"; import pdfMake from "pdfmake/build/pdfmake"; import pdfFonts from "pdfmake/build/vfs_fonts"; import fs from "fs"; // Initialize PDFMake with fonts pdfMake.vfs = pdfFonts.pdfMake.vfs; const markdown = `# Technical Documentation ## Overview This document describes the **mdpdfmake** library functionality. ### Key Features 1. Markdown parsing 2. PDF generation 3. Style customization ### Installation ```bash npm install mdpdfmake pdfmake ``` ### Usage Example ```javascript import { mdpdfmake } from "mdpdfmake"; // Your code here ``` > **Note:** Requires Node.js 12 or higher. --- For support, contact [support@example.com](mailto:support@example.com).`; async function generatePDF() { try { const docDefinition = await mdpdfmake(markdown, { headingFontSizes: [32, 26, 22, 18, 16, 14], headingUnderline: true }); const pdfDoc = pdfMake.createPdf(docDefinition); // Browser environment pdfDoc.download('documentation.pdf'); // Node.js environment pdfDoc.getBuffer((buffer) => { fs.writeFileSync('documentation.pdf', buffer); console.log('PDF generated successfully!'); }); // Get as base64 string pdfDoc.getBase64((base64) => { console.log('PDF base64:', base64.substring(0, 50) + '...'); }); } catch (error) { console.error('PDF generation failed:', error); throw error; } } generatePDF(); ``` -------------------------------- ### mdpdfmake Text Formatting Conversion Source: https://context7.com/hackerbone/mdpdfmake/llms.txt Shows how mdpdfmake converts various inline Markdown text formatting like bold, italic, code spans, strikethrough, and links into corresponding PDFMake text styles. The example logs the structured content of the first element in the document definition. ```typescript import { mdpdfmake } from "mdpdfmake"; const markdown = `This paragraph contains **bold text**, *italic text*, `inline code`, ~~strikethrough text~~, and [a link](https://example.com). You can also combine ***bold and italic*** together.`; mdpdfmake(markdown) .then((docDefinition) => { // The content contains properly formatted text fragments console.log(docDefinition.content[0]); /* Output structure: { "text": [ "This paragraph contains ", { "text": "bold text", "bold": true }, ", ", { "text": "italic text", "italics": true }, ", ", { "text": "inline code", "background": "#f0f0f0", "fontSize": 10, "margin": [0, 5, 0, 5] }, ", ", { "text": "strikethrough text", "decoration": "lineThrough" }, ", and ", { "text": "a link", "color": "blue", "decoration": "underline", "link": "https://example.com" }, "." ], "margin": [0, 5, 0, 5] } */ }); ``` -------------------------------- ### Create PDF Horizontal Rules with PDFMake Canvas (TypeScript) Source: https://context7.com/hackerbone/mdpdfmake/llms.txt This example shows how to generate visual separators (horizontal rules) in PDF documents using PDFMake's canvas elements. The mdpdfmake library parses Markdown's horizontal rule syntax ('---' or '***') and converts it into canvas instructions for drawing lines. The output structure for a horizontal rule is also logged. ```typescript import { mdpdfmake } from "mdpdfmake"; const markdown = `## Section One Content for the first section. --- ## Section Two Content for the second section. *** ## Section Three`; mdpdfmake(markdown) .then((docDefinition) => { // Horizontal rules are drawn as canvas lines const hr = docDefinition.content[2]; console.log(hr); /* Output structure: { "canvas": [ { "type": "line", "x1": 0, "y1": 5, "x2": 515, "y2": 5, "lineWidth": 1, "lineColor": "#2c2c2c" } ], "margin": [0, 10, 0, 10] } */ }); ``` -------------------------------- ### mdpdfmake Configuration Options Source: https://context7.com/hackerbone/mdpdfmake/llms.txt Illustrates how to use mdpdfmake with default and custom configuration options to control PDF output. It shows partial overrides for heading font sizes and underline styles, and logs the resulting document definition structure. ```typescript import { mdpdfmake } from "mdpdfmake"; // Default configuration const defaultOptions = { headingFontSizes: [36, 30, 24, 18, 15, 12], // h1 through h6 headingUnderline: true }; // Custom configuration - partial override const customOptions = { headingFontSizes: [32, 28], // Only override h1 and h2 headingUnderline: false }; const markdown = `# Main Title ## Subtitle ### Section Regular text content.`; // Using custom options mdpdfmake(markdown, customOptions) .then((docDefinition) => { // docDefinition.content contains the converted elements console.log(JSON.stringify(docDefinition, null, 2)); /* Output structure: { "content": [ { "text": "Main Title", "fontSize": 32, "bold": true, "margin": [0, 10, 0, 10], "style": {} }, { "text": "Subtitle", "fontSize": 28, "bold": true, "margin": [0, 10, 0, 10], "style": {} }, { "text": "Section", "fontSize": 24, "bold": true, "margin": [0, 5, 0, 5], "style": {} }, { "text": "Regular text content.", "margin": [0, 5, 0, 5] } ], "defaultStyle": { "font": "Roboto" } } */ }); ``` -------------------------------- ### Configuration Options (MOptions) Source: https://context7.com/hackerbone/mdpdfmake/llms.txt Customize the appearance of generated PDFs using the `MOptions` interface. Options include `headingFontSizes` and `headingUnderline`, which can be partially or fully overridden. ```APIDOC ## Configuration Options (MOptions) ### Description Customize the appearance of converted documents through the MOptions interface. Options are optional and fall back to sensible defaults. ### Method `mdpdfmake(markdown: string, options?: MOptions): Promise` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **markdown** (string) - Required - The Markdown text to convert. - **options** (MOptions) - Optional - Configuration options for the conversion. - **headingFontSizes** (number[]) - Optional - An array specifying font sizes for headings h1 through h6. Defaults to `[36, 30, 24, 18, 15, 12]`. - **headingUnderline** (boolean) - Optional - Whether to underline headings. Defaults to `true`. ### Request Example ```typescript import { mdpdfmake } from "mdpdfmake"; // Default configuration const defaultOptions = { headingFontSizes: [36, 30, 24, 18, 15, 12], // h1 through h6 headingUnderline: true }; // Custom configuration - partial override const customOptions = { headingFontSizes: [32, 28], // Only override h1 and h2 headingUnderline: false }; const markdown = `# Main Title ## Subtitle ### Section Regular text content.`; // Using custom options mdpdfmake(markdown, customOptions) .then((docDefinition) => { // docDefinition.content contains the converted elements console.log(JSON.stringify(docDefinition, null, 2)); }); ``` ### Response #### Success Response (Promise resolves with DocumentDefinition) - **docDefinition** (object) - The PDFMake document definition object, including a `content` array with converted elements. #### Response Example ```json { "content": [ { "text": "Main Title", "fontSize": 32, "bold": true, "margin": [0, 10, 0, 10], "style": {} }, { "text": "Subtitle", "fontSize": 28, "bold": true, "margin": [0, 10, 0, 10], "style": {} }, { "text": "Section", "fontSize": 24, "bold": true, "margin": [0, 5, 0, 5], "style": {} }, { "text": "Regular text content.", "margin": [0, 5, 0, 5] } ], "defaultStyle": { "font": "Roboto" } } ``` ``` -------------------------------- ### mdpdfmake() - Main Conversion Function Source: https://context7.com/hackerbone/mdpdfmake/llms.txt The main `mdpdfmake()` function converts Markdown text into a PDFMake document definition. It returns a Promise that resolves with the document structure, ready for PDF generation. ```APIDOC ## mdpdfmake() - Main Conversion Function ### Description Converts Markdown text to a PDFMake document definition asynchronously. Returns a Promise containing the complete document structure ready for PDF generation with PDFMake. ### Method `mdpdfmake(markdown: string, options?: MOptions): Promise` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **markdown** (string) - Required - The Markdown text to convert. - **options** (MOptions) - Optional - Configuration options for the conversion. ### Request Example ```typescript import { mdpdfmake } from "mdpdfmake"; import pdfMake from "pdfmake/build/pdfmake"; import pdfFonts from "pdfmake/build/vfs_fonts"; pdfMake.vfs = pdfFonts.pdfMake.vfs; const markdown = `# Project Report This is a comprehensive **project report** with *multiple* sections. ## Features Implemented - Authentication system with JWT - User profile management - Real-time notifications ## Code Example ```javascript function authenticate(token) { return jwt.verify(token, SECRET_KEY); } ``` > **Note:** All features are production-ready. ![Logo](https://example.com/logo.png) --- For more information, visit [our website](https://example.com).`; const options = { headingFontSizes: [28, 24, 20, 16, 14, 12], headingUnderline: true }; mdpdfmake(markdown, options) .then((docDefinition) => { const pdfDoc = pdfMake.createPdf(docDefinition); pdfDoc.download('report.pdf'); }) .catch((error) => { console.error('PDF generation failed:', error); }); ``` ### Response #### Success Response (Promise resolves with DocumentDefinition) - **docDefinition** (object) - The PDFMake document definition object. #### Response Example (See example output in Configuration Options section for structure of `docDefinition.content`) ``` -------------------------------- ### Text Formatting Conversion Source: https://context7.com/hackerbone/mdpdfmake/llms.txt Demonstrates how mdpdfmake converts various inline Markdown text formatting (bold, italic, code spans, strikethrough, links) into corresponding PDFMake text styles. ```APIDOC ## Text Formatting Conversion ### Description Converts inline Markdown formatting to PDFMake text styles including bold, italic, code spans, strikethrough, and links with proper styling. ### Method `mdpdfmake(markdown: string, options?: MOptions): Promise` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **markdown** (string) - Required - The Markdown text containing inline formatting. - **options** (MOptions) - Optional - Configuration options for the conversion. ### Request Example ```typescript import { mdpdfmake } from "mdpdfmake"; const markdown = `This paragraph contains **bold text**, *italic text*, `inline code`, ~~strikethrough text~~, and [a link](https://example.com). You can also combine ***bold and italic*** together.`; mdpdfmake(markdown) .then((docDefinition) => { console.log(docDefinition.content[0]); }); ``` ### Response #### Success Response (Promise resolves with DocumentDefinition) - **docDefinition.content[0]** (object) - Represents the first content block, which will contain an array of text objects with applied styles. #### Response Example ```json { "text": [ "This paragraph contains ", { "text": "bold text", "bold": true }, ", ", { "text": "italic text", "italics": true }, ", ", { "text": "inline code", "background": "#f0f0f0", "fontSize": 10, "margin": [0, 5, 0, 5] }, ", ", { "text": "strikethrough text", "decoration": "lineThrough" }, ", and ", { "text": "a link", "color": "blue", "decoration": "underline", "link": "https://example.com" }, "." ], "margin": [0, 5, 0, 5] } ``` ``` -------------------------------- ### Handle Images in Markdown to PDFMake with Base64 Encoding Source: https://context7.com/hackerbone/mdpdfmake/llms.txt Fetches remote images from Markdown and encodes them as base64 data URLs for embedding in PDFs. If an image is unreachable, it falls back to displaying a clickable text link with the image URL. ```typescript import { mdpdfmake } from "mdpdfmake"; const markdown = `# Product Showcase ![Product Image](https://cdn.example.com/products/widget-1.jpg) ![Unavailable Image](https://broken-url.com/missing.png)`; mdpdfmake(markdown) .then((docDefinition) => { // Successfully fetched images are base64-encoded console.log(docDefinition.content[1]); /* Output for successful image: { "image": "data:image/jpg;base64,/9j/4AAQSkZJRg...", "width": 150, "margin": [0, 5, 0, 5] } */ // Failed images become clickable links console.log(docDefinition.content[2]); /* Output for failed image: { "text": "[Image: https://broken-url.com/missing.png]", "link": "https://broken-url.com/missing.png", "color": "blue", "decoration": "underline" } */ }) .catch((error) => { console.error('Conversion error:', error); }); ``` -------------------------------- ### Render Code Blocks with Language Labels in PDFMake Source: https://context7.com/hackerbone/mdpdfmake/llms.txt Renders fenced code blocks from Markdown, including optional language labels, into PDFMake document structures. It applies proper formatting and uses bordered containers for visual distinction of code snippets. ```typescript import { mdpdfmake } from "mdpdfmake"; const markdown = `## API Implementation ```typescript interface User { id: number; name: string; email: string; } async function getUser(id: number): Promise { const response = await fetch(`/api/users/${id}`); return response.json(); } ``` ```bash npm install mdpdfmake npm run build ````; mdpdfmake(markdown) .then((docDefinition) => { // Code blocks have language headers and styled containers const codeBlock = docDefinition.content[1]; console.log(codeBlock); /* Output structure: { "stack": [ { "text": "typescript", "color": "#004252", "fontSize": 8, "bold": true, "margin": [0, 5, 0, 2] }, { "table": { "widths": ["*"] "body": [[ { "columns": [{ "width": "90%", "text": "interface User {\n id: number;\n name: string;\n email: string;\n}\n\nasync function getUser(id: number): Promise {\n const response = await fetch(`/api/users/${id}`);\n return response.json();n}", "fontSize": 10, "color": "#333333", "preserveLeadingSpaces": true, "lineHeight": 1.2, "margin": [5, 5, 5, 5] }] } ]] }, "layout": { "hLineColor": "#dddddd", "vLineColor": "#dddddd", "paddingLeft": 0, "paddingRight": 0, "paddingTop": 0, "paddingBottom": 0 } } ], "margin": [0, 5, 0, 5] } */ }); ``` -------------------------------- ### Convert Markdown to PDFMake Document Definition in TypeScript Source: https://github.com/hackerbone/mdpdfmake/blob/main/README.md Demonstrates how to use the mdpdfmake function to convert a Markdown string into a PDFMake document definition. It shows how to import the function, define conversion options, and handle the returned Promise using .then(). ```ts import { mdpdfmake } from "mdpdfmake"; const options = { headingFontSizes: [24, 22, 20], headingUnderline: true, }; const markdown = `# Heading This is a paragraph with **bold** text and *italic* text. - List Item 1 - List Item 2 > Blockquote ![Image](https://cdn.pixabay.com/photo/2018/01/23/23/53/rick-and-morty-3102795_1280.jpg)`; mdpdfmake(markdown, options).then((docDefinition) => { // Use docDefinition with a PDFMake instance to generate a PDF }); ``` -------------------------------- ### Convert Markdown Blockquotes to PDFMake Elements (TypeScript) Source: https://context7.com/hackerbone/mdpdfmake/llms.txt This snippet demonstrates how to convert Markdown blockquotes into styled PDFMake elements, featuring italic text and highlighted backgrounds. It utilizes the mdpdfmake library and shows the expected output structure for blockquote elements within the generated PDF document definition. ```typescript import { mdpdfmake } from "mdpdfmake"; const markdown = `## Documentation Notes > **Important:** Always validate user input before processing. > This prevents security vulnerabilities. Regular paragraph text. > Multi-paragraph blockquotes are supported. > > Each paragraph maintains proper formatting with **bold** and *italic* text.`; mdpdfmake(markdown) .then((docDefinition) => { // Blockquotes have special styling const blockquote = docDefinition.content[1]; console.log(blockquote); /* Output structure: { "text": [ { "text": "Important:", "bold": true }, " Always validate user input before processing." ], "italics": true, "margin": [0, 5, 0, 5], "background": "#eae7f2" } */ }); ``` -------------------------------- ### Process Nested Lists in Markdown to PDFMake Source: https://context7.com/hackerbone/mdpdfmake/llms.txt Converts Markdown with ordered and unordered lists, including nested sublists and formatted text, into PDFMake's list structures. It handles different levels of nesting and text styling within list items. ```typescript import { mdpdfmake } from "mdpdfmake"; const markdown = `## Shopping List 1. Fruits - **Apples** (organic) - *Bananas* - Oranges 2. Vegetables - Carrots - Tomatoes 3. Dairy - Milk - Cheese ## Task Priority - High Priority 1. Complete project documentation 2. Review pull requests - Medium Priority - Update dependencies - Write tests`; mdpdfmake(markdown) .then((docDefinition) => { // Lists are converted to PDFMake ol/ul structures const orderedList = docDefinition.content[1]; console.log(orderedList); /* Output structure: { "ol": [ [ "Fruits", { "ul": [ [{ "text": "Apples", "bold": true }, " (organic)"], [{ "text": "Bananas", "italics": true }], ["Oranges"] ], "margin": [0, 5, 0, 5] } ], ["Vegetables", { "ul": [...], "margin": [0, 5, 0, 5] }], ["Dairy", { "ul": [...], "margin": [0, 5, 0, 5] }] ], "margin": [0, 5, 0, 5] } */ }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.