### Install MkDocs Exporter Plugin Source: https://adrienbrignon.github.io/mkdocs-exporter/getting-started Installs the MkDocs Exporter plugin using pip. This is the first step to enable PDF export functionality for your MkDocs project. ```bash pip install mkdocs-exporter ``` -------------------------------- ### Register MkDocs Exporter Plugin Source: https://adrienbrignon.github.io/mkdocs-exporter/getting-started Registers the MkDocs Exporter plugin in the MkDocs configuration file (mkdocs.yml). This enables the plugin's features for your documentation site. ```yaml plugins: - exporter ``` -------------------------------- ### Install Playwright for PDF Generation Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/generating-pdf-documents Installs the Playwright browser and its dependencies required for PDF generation. This command ensures that the necessary components are available for the MkDocs Exporter plugin to function correctly. ```bash playwright install chrome --with-deps ``` -------------------------------- ### Front Cover Page Template (HTML/Jinja2) Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/generating-pdf-documents An example HTML template using Jinja2 syntax for a front cover page. It displays the site name and page title, and expects a background image to be present. ```html
{{ config.site_name }}
{{ page.title }}
``` -------------------------------- ### Back Cover Page Template (HTML/Jinja2) Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/generating-pdf-documents An example HTML template using Jinja2 syntax for a back cover page. It displays the site name. ```html
{{ config.site_name }}
``` -------------------------------- ### Configure Per-Page Cover Page (Markdown Front Matter) Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/generating-pdf-documents Example of overriding the global cover page configuration for a specific Markdown page using front matter. Specifies a custom front cover template. ```markdown --- covers: front: ./resources/templates/covers/special.html.j2 --- # My special page This configuration specifies a custom front cover page template located at `./resources/templates/covers/special.html.j2` for this page. You can follow the same operation to specify a custom back cover page. ``` -------------------------------- ### Add page-specific buttons via front matter Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/adding-buttons-to-pages Defines custom buttons directly in a page's front matter metadata. This allows per-page button customization without modifying the global configuration. The example shows a 'Feeling Lucky' button that opens a YouTube video in a new tab with custom CSS classes and attributes. ```yaml --- buttons: - title: I'm Feeling Lucky icon: material-star-outline attributes: class: md-content__button md-icon md-icon-spin href: https://www.youtube.com/watch?v=dQw4w9WgXcQ target: _blank --- # Adding buttons to pages ``` -------------------------------- ### Configure Global Cover Pages (mkdocs.yml) Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/generating-pdf-documents Defines global front and back cover page templates for all PDF documents generated by the MkDocs Exporter plugin. Requires specifying paths to Jinja2 template files and SCSS stylesheets. ```yaml plugins: - exporter: formats: pdf: stylesheets: - resources/stylesheets/pdf.scss covers: front: resources/templates/covers/front.html.j2 back: resources/templates/covers/back.html.j2 ``` -------------------------------- ### Configure PDF Export Settings Source: https://adrienbrignon.github.io/mkdocs-exporter/reference/configuration/formats/pdf Defines the main configuration for PDF generation. It includes options for enabling the generator, explicit rendering, concurrency, stylesheets, scripts, cover pages, browser settings, base URL, and an aggregator. ```python class Config(BaseConfig): """The plugin's configuration.""" enabled = c.Type(bool, default=True) """Is the generator enabled?""" explicit = c.Type(bool, default=False) """Should pages specify explicitly that they should be rendered as PDF?""" concurrency = c.Type(int, default=4) """The maximum number of concurrent PDF generation tasks.""" stylesheets = c.ListOfItems(c.File(exists=True), default=[]) """A list of custom stylesheets to apply before rendering documents.""" scripts = c.ListOfItems(c.File(exists=True), default=[]) """A list of custom scripts to inject before rendering documents.""" covers = c.SubConfig(CoversConfig) """The document's cover pages.""" browser = c.SubConfig(BrowserConfig) """The browser's configuration.""" url = c.Optional(c.Type(str)) """The base URL that'll be prefixed to links with a relative path.""" aggregator = c.SubConfig(AggregatorConfig) """The aggregator's configuration.""" ``` -------------------------------- ### Configure PDF Cover Pages Source: https://adrienbrignon.github.io/mkdocs-exporter/reference/configuration/formats/pdf Specifies configuration for cover pages in PDF documents. It allows defining separate templates for the front and back covers. ```python class CoversConfig(BaseConfig): """The cover's configuration.""" front = c.Optional(c.File(exists=True)) """The front cover template location.""" back = c.Optional(c.File(exists=True)) """The back cover template location.""" ``` -------------------------------- ### Configure download button with PDF support Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/adding-buttons-to-pages Adds a download button to pages that have PDF documents. The button uses material icons and dynamically resolves its enabled state and attributes through Python function references. This configuration integrates with the mkdocs-exporter PDF format plugin. ```yaml plugins: - exporter: buttons: - title: Download as PDF icon: material-file-download-outline enabled: !!python/name:mkdocs_exporter.formats.pdf.buttons.download.enabled attributes: !!python/name:mkdocs_exporter.formats.pdf.buttons.download.attributes ``` -------------------------------- ### Configure Download Button (mkdocs.yml) Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/generating-pdf-documents Enables and configures a 'Download as PDF' button in the documentation. Requires specifying the button title, icon, and enabling/attribute functions from the exporter plugin. ```yaml plugins: - exporter: buttons: - title: Download as PDF icon: material-file-download-outline enabled: !!python/name:mkdocs_exporter.formats.pdf.buttons.download.enabled attributes: !!python/name:mkdocs_exporter.formats.pdf.buttons.download.attributes ``` -------------------------------- ### Configure PDF Browser Settings Source: https://adrienbrignon.github.io/mkdocs-exporter/reference/configuration/formats/pdf Defines configuration options for the browser used in PDF generation. This includes settings for debugging, headless mode, timeout, and additional browser arguments. ```python class BrowserConfig(BaseConfig): """The browser's configuration.""" debug = c.Type(bool, default=False) """Should console messages sent to the browser be logged?""" headless = c.Type(bool, default=True) """Should the browser start in headless mode?""" timeout = c.Type(int, default=60_000) """The timeout when waiting for the PDF to render.""" args = c.ListOfItems(c.Type(str), default=[]) """Extra arguments to pass to the browser.""" ``` -------------------------------- ### Define Formats Configuration in Python Source: https://adrienbrignon.github.io/mkdocs-exporter/reference/configuration The FormatsConfig class is a simple configuration for output formats in the MkDocs Exporter, currently supporting PDF format configuration. ```python class FormatsConfig(BaseConfig): pdf = c.SubConfig(PDFFormatConfig) """The PDF format configuration.""" ``` -------------------------------- ### Define MkDocs Exporter Config Class in Python Source: https://adrienbrignon.github.io/mkdocs-exporter/reference/configuration The Config class defines the plugin's configuration including theme override, formats, buttons, and logging. It uses BaseConfig as a parent class and includes optional and sub-configuration fields. ```python class Config(BaseConfig): """The plugin's configuration.""" theme = c.Optional(c.Theme(default=None)) """Override the theme used by your MkDocs instance.""" formats = c.SubConfig(FormatsConfig) """The formats to generate.""" buttons = c.ListOfItems(c.SubConfig(ButtonConfig), default=[]) """The buttons to add.""" logging = c.SubConfig(LoggingConfig) """The logging configuration.""" ``` -------------------------------- ### Enable PDF Aggregation (mkdocs.yml) Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/generating-pdf-documents Configures the MkDocs Exporter plugin to combine multiple PDF documents into a single output file. Includes options for enabling aggregation, specifying the output filename, and managing cover pages. ```yaml plugins: - exporter: formats: pdf: aggregator: enabled: true output: documentation.pdf covers: all ``` -------------------------------- ### Create dynamic button with Python function resolver Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/adding-buttons-to-pages Implements a dynamic button that generates Google search URLs using the current page's title as the search query. The Python function takes a Page object and returns the href attribute. The button configuration references this function using Python name resolution. The function uses urllib.parse for URL encoding. ```python from urllib.parse import urlencode from mkdocs_exporter.page import Page def href(page: Page, **kwargs) -> str: """The button's 'href' attribute.""" return 'https://google.com/search?' + urlencode({'q': page.title}) ``` ```yaml plugins: - exporter: buttons: - title: Download as PDF icon: material-file-download-outline attributes: href: !!python/name:my_module.button.href ``` -------------------------------- ### Define Button Configuration in Python Source: https://adrienbrignon.github.io/mkdocs-exporter/reference/configuration The ButtonConfig class specifies the configuration for buttons in the MkDocs Exporter, including enabled status, title, icon, and additional attributes. It supports dynamic values via Callable types. ```python class ButtonConfig(BaseConfig): """The configuration of a button.""" enabled = c.Type((bool, Callable), default=True) """Is the button enabled?""" title = c.Type((str, Callable)) """The button's title.""" icon = c.Type((str, Callable)) """The button's icon (typically, an SVG element).""" attributes = c.Type((dict, Callable), default={}) """Some extra attributes to add to the button.""" ``` -------------------------------- ### Define Logging Configuration in Python Source: https://adrienbrignon.github.io/mkdocs-exporter/reference/configuration The LoggingConfig class sets the logging level for the MkDocs Exporter plugin, with options ranging from debug to critical, defaulting to info. ```python class LoggingConfig(BaseConfig): """The logging configuration.""" level = c.Choice(['debug', 'info', 'warning', 'error', 'critical'], default='info') """The log level.""" ``` -------------------------------- ### Configure Concurrent PDF Generation Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/generating-pdf-documents Sets the number of concurrent threads for PDF generation to enhance performance. This configuration option is beneficial for large documentation projects, allowing up to 16 PDFs to be generated simultaneously. ```yaml plugins: - exporter: formats: pdf: concurrency: 16 ``` -------------------------------- ### PDF Stylesheet (SCSS) Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/generating-pdf-documents Basic SCSS (Sass) configuration for PDF page size and margins using CSS `@page` rules. This defines the layout dimensions for each page. ```scss @page { size: A4; margin: 1.20cm; } ``` -------------------------------- ### Explicitly Enable PDF Generation for a Page Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/generating-pdf-documents Demonstrates how to explicitly enable PDF generation for a specific Markdown file using front matter. This is used when the `explicit: true` option is set in the mkdocs.yml configuration. ```markdown --- pdf: true --- ``` -------------------------------- ### Configure PDF Aggregation Settings Source: https://adrienbrignon.github.io/mkdocs-exporter/reference/configuration/formats/pdf Controls the aggregation of multiple PDF documents into a single file. Options include enabling/disabling the aggregator, specifying the output file, metadata, and cover page behavior. ```python class AggregatorConfig(BaseConfig): """The aggregator's configuration.""" enabled = c.Type(bool, default=False) """Is the aggregator enabled?""" output = c.Type(str, default='combined.pdf') """The aggregated PDF document output file path.""" metadata = c.Type(dict, default={}) """Some metadata to append to the PDF document.""" covers = c.Choice(['all', 'none', 'limits', 'book', 'front', 'back'], default='all') """The behavior of cover pages.""" ``` -------------------------------- ### Enable Explicit PDF Export Mode Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/generating-pdf-documents Enables explicit mode for PDF generation, requiring pages to be individually marked for inclusion. When `explicit: true` is set, only pages with `pdf: true` in their front matter will be exported. ```yaml plugins: - exporter: formats: pdf: explicit: true ``` -------------------------------- ### Enable PDF Export in mkdocs.yml Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/generating-pdf-documents Configures the MkDocs Exporter plugin to enable PDF document generation. This snippet shows how to set the PDF format as enabled within the mkdocs.yml file. ```yaml plugins: - exporter: formats: pdf: enabled: !ENV [MKDOCS_EXPORTER_PDF_ENABLED, true] ``` -------------------------------- ### Hide Cover Pages Per Page (Markdown Front Matter) Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/generating-pdf-documents Demonstrates how to hide all cover pages for a specific Markdown document using front matter. This prevents cover pages from being generated for designated sections. ```markdown --- hidden: - covers --- # Appendix A This appendix contains supplementary information but wont have cover pages... ``` -------------------------------- ### Disable PDF Generation for a Page Source: https://adrienbrignon.github.io/mkdocs-exporter/configuration/generating-pdf-documents Shows how to exclude a specific Markdown file from PDF generation using front matter. Setting `pdf: false` in the file's front matter prevents it from being included in the exported PDF. ```markdown --- pdf: false --- ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.