### Install MkDocs Exporter Plugin Source: https://github.com/adrienbrignon/mkdocs-exporter/blob/master/docs/getting-started.md Installs the MkDocs Exporter plugin using pip. This is the primary method for adding the plugin to your MkDocs project. Ensure you have Python and pip installed. ```shell pip install mkdocs-exporter ``` -------------------------------- ### MkDocs Exporter Installation and Setup (Bash) Source: https://context7.com/adrienbrignon/mkdocs-exporter/llms.txt Guides through the installation of MkDocs Exporter using pip and Playwright for browser dependencies. Includes commands for development installation, verification, building, serving, and overriding build configurations. ```bash # Install the plugin pip install mkdocs-exporter # Install Playwright browser (required for PDF generation) playwright install chromium --with-deps # For development installation git clone https://github.com/adrienbrignon/mkdocs-exporter.git cd mkdocs-exporter pip install -e . playwright install chromium --with-deps # Verify installation python -c "import mkdocs_exporter; print('MkDocs Exporter installed successfully')" # Build documentation with PDF generation mkdocs build # Serve with live reload (PDFs regenerate on changes) mkdocs serve # Build with environment variable overrides MKDOCS_EXPORTER_PDF=true MKDOCS_EXPORTER_PDF_AGGREGATOR=true mkdocs build ``` -------------------------------- ### Configure MkDocs Exporter Plugin in mkdocs.yml Source: https://github.com/adrienbrignon/mkdocs-exporter/blob/master/docs/getting-started.md Registers the MkDocs Exporter plugin in your MkDocs configuration file (mkdocs.yml). This enables the plugin's functionality for your documentation site. Requires the plugin to be installed first. ```yaml plugins: - exporter ``` -------------------------------- ### Install MkDocs Exporter (Bash) Source: https://github.com/adrienbrignon/mkdocs-exporter/blob/master/README.md Installs the MkDocs exporter plugin using pip to enable PDF export functionality. Requires Python >= 3.9 and MkDocs >= 1.4 as prerequisites. Outputs the installed plugin ready for configuration. ```bash pip install mkdocs-exporter ``` -------------------------------- ### Install Playwright Dependencies Source: https://github.com/adrienbrignon/mkdocs-exporter/blob/master/docs/configuration/generating-pdf-documents.md Installs the Playwright browser and its required dependencies, specifically Chrome, for PDF generation. This command is essential for the library's PDF generation capabilities. ```bash playwright install chrome --with-deps ``` -------------------------------- ### Convert HTML to PDF using Browser Control (Python) Source: https://context7.com/adrienbrignon/mkdocs-exporter/llms.txt Demonstrates low-level browser control for converting HTML content to PDF. It initializes a browser instance with custom arguments, launches it, converts provided HTML, and saves the resulting PDF. Ensure 'mkdocs-exporter' is installed. ```python import asyncio from mkdocs_exporter.formats.pdf.browser import Browser async def convert_html_to_pdf(): # Initialize browser with custom arguments browser = Browser({ 'headless': True, 'timeout': 60000, 'debug': True, 'args': [ '--disable-gpu', '--font-render-hinting=none' ] }) # Launch the browser (thread-safe) await browser.launch() # HTML content to convert html = """
Content that will be converted to PDF.
""" try: # Convert HTML to PDF pdf_data, pages = await browser.print(html) print(f"Generated {pages} pages") print(f"PDF size: {len(pdf_data)} bytes") # Save PDF with open('output.pdf', 'wb') as f: f.write(pdf_data) finally: # Always close browser await browser.close() asyncio.run(convert_html_to_pdf()) ``` -------------------------------- ### Page-Specific Buttons with Jinja (YAML/HTML) Source: https://github.com/adrienbrignon/mkdocs-exporter/blob/master/docs/configuration/adding-buttons-to-pages.md Example of configuring page-specific buttons using front matter. It utilizes Jinja templating to dynamically render button properties based on the page's metadata. ```yaml --- {% set button = page.meta.buttons[0] -%} buttons: - title: {{ button.title }} icon: {{ button.icon }} attributes: class: {{ button.attributes.class }} href: {{ button.attributes.href }} target: {{ button.attributes.target }} --- # {{ page.title }} ``` -------------------------------- ### Configure MkDocs Exporter (YAML) Source: https://github.com/adrienbrignon/mkdocs-exporter/blob/master/README.md Configures the exporter plugin in mkdocs.yml to enable PDF generation with options for concurrency, stylesheets, cover pages, and document aggregation. Requires MkDocs with the plugin installed; inputs include environment variables and file paths. Generates customized PDF outputs but is limited to supported MkDocs themes like Material and ReadtheDocs. ```yaml plugins: - exporter: formats: pdf: enabled: !ENV [MKDOCS_EXPORTER_PDF, true] concurrency: 8 stylesheets: - resources/stylesheets/pdf.scss covers: front: resources/templates/covers/front.html.j2 back: resources/templates/covers/back.html.j2 aggregator: enabled: true output: .well-known/site.pdf covers: all ``` -------------------------------- ### Enable PDF Export in MkDocs (mkdocs.yml) Source: https://context7.com/adrienbrignon/mkdocs-exporter/llms.txt Minimal MkDocs plugin configuration to enable PDF export. Activate the exporter and specify the 'pdf' format. Useful as a starting point before adding advanced options. ```yaml plugins: - exporter: formats: pdf: enabled: true ``` -------------------------------- ### Aggregate Multiple PDFs with Cover Strategies (Python) Source: https://context7.com/adrienbrignon/mkdocs-exporter/llms.txt Details how to combine multiple PDF documents into a single file using specified cover strategies (e.g., 'front', 'book'). It requires a renderer and aggregator instance, mock page objects, and provides a structure for appending PDFs. Assumes 'mkdocs-exporter' is installed. ```python import asyncio from mkdocs_exporter.formats.pdf.renderer import Renderer from mkdocs_exporter.formats.pdf.aggregator import Aggregator from mkdocs_exporter.page import Page async def aggregate_pdfs(): # Create renderer renderer = Renderer(options={}) # Initialize aggregator with cover strategy aggregator = Aggregator( renderer=renderer, config={ 'output': 'combined.pdf', 'covers': 'front' # Options: all, none, limits, book, front, back } ) # Mock page objects (in real usage, these come from MkDocs) pages = [] for i in range(3): page = Page(title=f"Page {i+1}", file=None) page.index = i page.formats = { 'pdf': { 'pages': 2, 'covers': ['front', 'back'], 'path': f'/tmp/page{i}.pdf', 'skipped_pages': 0 } } pages.append(page) # Set pages for aggregation aggregator.set_pages(pages) # Open output file aggregator.open('combined.pdf') # Append each PDF (would need actual PDF files) for page in pages: # In real usage, render pages and append # html = aggregator.preprocess(page) # pdf_data, _ = await renderer.render(html) # aggregator.append(pdf_path) pass # Save aggregated PDF with metadata aggregator.save(metadata={ '/Title': 'Complete Documentation', '/Author': 'Your Name', '/Subject': 'API Documentation' }) await renderer.dispose() asyncio.run(aggregate_pdfs()) ``` -------------------------------- ### Mermaid Flowchart Diagram Source: https://github.com/adrienbrignon/mkdocs-exporter/blob/master/docs/samples/diagrams.md Defines a flowchart using Mermaid syntax. This diagram visualizes a simple decision-making process with start, decision, and end points. ```mermaid flowchart TD A[Start] --> B{Is it?} B -->|Yes| C[OK] C --> D[Rethink] D --> B B ---->|No| E[End] ``` -------------------------------- ### SCSS for Advanced PDF Styling Source: https://context7.com/adrienbrignon/mkdocs-exporter/llms.txt SCSS code for advanced PDF styling using CSS Paged Media specifications. It includes variable definitions, page setup for headers and footers, and specific styling for headings, code blocks, tables, and links. ```scss // resources/stylesheets/pdf.scss // Variables $primary-color: #EA2027; $font-family: 'Roboto', sans-serif; $code-font: 'Roboto Mono', monospace; // Page setup using CSS Paged Media @page { size: A4; margin: 2cm; @top-center { content: string(doctitle); font-size: 10pt; color: #666; } @bottom-right { content: "Page " counter(page) " of " counter(pages); font-size: 10pt; } } // First page has no header @page :first { @top-center { content: none; } } // Set document title for running header h1 { string-set: doctitle content(); } // Avoid page breaks inside code blocks pre, code { page-break-inside: avoid; font-family: $code-font; background-color: #f5f5f5; padding: 0.5em; } // Ensure headings stay with following content h1, h2, h3, h4, h5, h6 { page-break-after: avoid; color: $primary-color; } // Table styling table { page-break-inside: avoid; width: 100%; border-collapse: collapse; th { background-color: $primary-color; color: white; padding: 0.5em; } td { padding: 0.5em; border: 1px solid #ddd; } } // Links in PDF should show URL a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #666; } // Cover page specific styles .front-cover, .back-cover { page: cover; page-break-after: always; } @page cover { margin: 0; @top-center { content: none; } @bottom-right { content: none; } } ``` -------------------------------- ### Create front cover HTML template Source: https://github.com/adrienbrignon/mkdocs-exporter/blob/master/docs/configuration/generating-pdf-documents.md Defines the structure of the front cover page using HTML and Jinja2 templating. Includes placeholders for site name and page title, with a background image. Requires a background image file at the specified path. ```html
{{ page.meta.description | default('Documentation') }}
This will be converted to PDF.
""" # Render to PDF (returns tuple of bytes and page count) pdf_bytes, page_count = await renderer.render(html_content) print(f"Generated PDF with {page_count} pages") # Save to file with open('output.pdf', 'wb') as f: f.write(pdf_bytes) # Clean up await renderer.dispose() # Run the async function asyncio.run(generate_pdf()) ``` -------------------------------- ### Mermaid Class Diagram Source: https://github.com/adrienbrignon/mkdocs-exporter/blob/master/docs/samples/diagrams.md Represents a class diagram using Mermaid syntax. This diagram visualizes the structure of a system, showing classes, their attributes, methods, and relationships. ```mermaid classDiagram note "From Duck till Zebra" Animal <|-- Duck note for Duck "can fly\ncan swim\ncan dive\ncan help in debugging" Animal <|-- Fish Animal <|-- Zebra Animal : +int age Animal : +String gender Animal: +isMammal() Animal: +mate() class Duck{ +String beakColor +swim() +quack() } class Fish{ -int sizeInFeet -canEat() } class Zebra{ +bool is_wild +run() } ``` -------------------------------- ### Jinja2 Back Cover Template Source: https://context7.com/adrienbrignon/mkdocs-exporter/llms.txt A Jinja2 template for creating a custom back cover page for PDFs. It displays information about the document's origin and provides a link to the website. ```jinja2This document was generated using MkDocs Exporter.
For the latest version, visit: {{ config.site_url }}