### Install WeasyPrint Dependencies for Wheels (Fedora) Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Install necessary packages on Fedora to enable WeasyPrint installation using wheels within a virtual environment. ```bash dnf install python-pip pango ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://doc.courtbouillon.org/weasyprint/stable/contribute.html Clone the WeasyPrint repository, create a virtual environment, and install development and documentation dependencies. ```bash git clone https://github.com/Kozea/WeasyPrint.git cd WeasyPrint python -m venv venv venv/bin/pip install -e '.[doc,test]' ``` -------------------------------- ### Install WeasyPrint using Pacman (Archlinux) Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Install WeasyPrint directly using the pacman command on Archlinux distributions. ```bash pacman -S python-weasyprint ``` -------------------------------- ### Install WeasyPrint using Apt (Debian/Ubuntu) Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Install WeasyPrint directly using the apt command on Debian (11+) or Ubuntu (20.04+) distributions. ```bash apt install weasyprint ``` -------------------------------- ### Install WeasyPrint on Windows using pip Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Installs WeasyPrint in a virtual environment on Windows using pip after setting up Python and Pango dependencies. ```bash python -m venv venv virtualenv\Scripts\activate.bat python -m pip install weasyprint python -m weasyprint --info ``` -------------------------------- ### Install WeasyPrint in a Virtual Environment (Linux) Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Create a virtual environment, activate it, and install WeasyPrint using pip. This is the recommended method for most Linux systems. ```bash python3 -m venv venv source venv/bin/activate pip install weasyprint weasyprint --info ``` -------------------------------- ### Install WeasyPrint using Homebrew (macOS) Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Install WeasyPrint on macOS using the Homebrew package manager. ```bash brew install weasyprint ``` -------------------------------- ### Install WeasyPrint Dependencies for Wheels (Debian/Ubuntu) Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Install necessary packages on Debian/Ubuntu to enable WeasyPrint installation using wheels within a virtual environment. ```bash apt install python3-pip libpango-1.0-0 libpangoft2-1.0-0 libharfbuzz-subset0 ``` -------------------------------- ### Install WeasyPrint Dependencies for Wheels (Archlinux) Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Install necessary packages on Archlinux to enable WeasyPrint installation using wheels within a virtual environment. ```bash pacman -S python-pip pango ``` -------------------------------- ### Install WeasyPrint on macOS using pip Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Installs WeasyPrint in a virtual environment on macOS using pip after installing dependencies. ```bash python3 -m venv venv source venv/bin/activate pip install weasyprint weasyprint --info ``` -------------------------------- ### Convert URL to PDF using WeasyPrint Python API Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Generates a PDF file from a given URL using the WeasyPrint Python library's quickstart example. ```python from weasyprint import HTML HTML('https://weasyprint.org/').write_pdf('/tmp/weasyprint-website.pdf') ``` -------------------------------- ### Install WeasyPrint Dependencies for Wheels (Alpine) Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Install necessary packages on Alpine Linux to enable WeasyPrint installation using wheels within a virtual environment. ```bash apk add py3-pip so:libgobject-2.0.so.0 so:libpango-1.0.so.0 so:libharfbuzz.so.0 so:libharfbuzz-subset.so.0 so:libfontconfig.so.1 so:libpangoft2-1.0.so.0 ``` -------------------------------- ### Install WeasyPrint using DNF (Fedora) Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Install WeasyPrint directly using the dnf command on Fedora distributions (version 39 and later). ```bash dnf install weasyprint ``` -------------------------------- ### Run WeasyPrint from Command Line Source: https://doc.courtbouillon.org/weasyprint/stable/contribute.html Execute WeasyPrint to convert an HTML file to PDF using the installed package. ```bash venv/bin/python -m weasyprint example.html example.pdf ``` -------------------------------- ### Install WeasyPrint Dependencies without Wheels (Archlinux) Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Install necessary development packages on Archlinux for compiling WeasyPrint from source within a virtual environment. ```bash pacman -S python-pip pango gcc libjpeg-turbo openjpeg2 ``` -------------------------------- ### Install WeasyPrint Dependencies without Wheels (Debian/Ubuntu) Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Install necessary development packages on Debian/Ubuntu for compiling WeasyPrint from source within a virtual environment. ```bash apt install python3-pip libpango-1.0-0 libpangoft2-1.0-0 libharfbuzz-subset0 libjpeg-dev libopenjp2-7-dev libffi-dev ``` -------------------------------- ### Install WeasyPrint Dependencies without Wheels (Fedora) Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Install necessary development packages on Fedora for compiling WeasyPrint from source within a virtual environment. ```bash dnf install python3-pip pango gcc python3-devel gcc-c++ zlib-devel libjpeg-devel openjpeg2-devel libffi-devel ``` -------------------------------- ### Install WeasyPrint dependencies on macOS using Macports Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Installs pip and Pango dependencies for WeasyPrint on macOS using Macports. ```bash sudo port install py-pip pango libffi ``` -------------------------------- ### Verify Python and Pango Versions Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Check if Python and Pango are installed and meet the minimum version requirements. This is a prerequisite for installing WeasyPrint. ```bash python3 --version pango-view --version ``` -------------------------------- ### Install WeasyPrint Dependencies without Wheels (Alpine) Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Install necessary development packages on Alpine Linux for compiling WeasyPrint from source within a virtual environment. ```bash apk add py3-pip so:libgobject-2.0.so.0 so:libpango-1.0.so.0 so:libharfbuzz.so.0 so:libharfbuzz-subset.so.0 so:libfontconfig.so.1 so:libpangoft2-1.0.so.0 apk add gcc musl-dev python3-dev zlib-dev jpeg-dev openjpeg-dev libwebp-dev g++ libffi-dev ``` -------------------------------- ### Launch Python Interpreter Source: https://doc.courtbouillon.org/weasyprint/stable/contribute.html Start a Python interactive session within the virtual environment for testing changes. ```bash venv/bin/python ``` -------------------------------- ### Install WeasyPrint using Alpine Package Manager Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Install WeasyPrint directly using the apk command on Alpine Linux distributions (version 3.17 and later). ```bash apk add weasyprint ``` -------------------------------- ### Build Documentation with Sphinx Source: https://doc.courtbouillon.org/weasyprint/stable/contribute.html Build the project documentation using Sphinx. The output will be in the docs/_build directory. ```bash venv/bin/sphinx-build docs docs/_build ``` -------------------------------- ### Factur-X/ZUGFeRD XML Structure Example Source: https://doc.courtbouillon.org/weasyprint/stable/common_use_cases.html This is an example of the XML structure for a Factur-X/ZUGFeRD invoice. It defines seller, buyer, and settlement details. ```xml urn:cen.eu:en16931:2017#compliant:basic urn:factur-x.eu:1.0:basic 456 Seller Corp 12345 Seller City FR FR11123456782 Buyer Corp 987654324 456 EUR 100.00 20.00 120.00 120.00 ``` -------------------------------- ### WeasyPrint Presentational Hints Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Option to follow HTML presentational hints during rendering. ```bash weasyprint -p ``` -------------------------------- ### Command-line API: main() Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html The main entry point for the WeasyPrint command-line interface. This function is used to process HTML and CSS to generate PDF documents. ```APIDOC ## Command-line API: main() ### Description This is the primary function for using WeasyPrint from the command line. It takes input files and options to render them into a PDF document. ### Method Command-line execution ### Endpoint `weasyprint [OPTIONS] ` ### Parameters #### Command-line Arguments - `[OPTIONS]` - Optional flags to control the rendering process (e.g., `--base-url`, `--encoding`). - `` - The HTML file to process. - `` - The name for the generated PDF file. ``` -------------------------------- ### Generate PDF with Factur-X Attachment (Command-line) Source: https://doc.courtbouillon.org/weasyprint/stable/common_use_cases.html Use the WeasyPrint command-line interface to generate a PDF invoice with an attached Factur-X XML file and XMP metadata. ```bash weasyprint invoice.html invoice.pdf --attachment=factur-x.xml --attachment-relationship=Data --xmp-metadata=rdf.xml --pdf-variant=pdf/a-3a ``` -------------------------------- ### Run Pytest Tests Source: https://doc.courtbouillon.org/weasyprint/stable/contribute.html Execute all tests using pytest within the virtual environment. Ensure Ghostscript is installed and DejaVu fonts are available on Linux. ```bash venv/bin/python -m pytest ``` -------------------------------- ### Disable Automatic Hyphenation Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Automatic hyphenation can be disabled using `hyphens: manual`. This example also shows how to append linked URLs with their href attribute, also disabling hyphenation for the appended content. ```css html { hyphens: auto } a[href]::after { content: ' [' attr(href) ']'; hyphens: manual } ``` -------------------------------- ### weasyprint.__main__.main Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html The main entry point for the WeasyPrint command-line program. It takes input and output arguments along with various options to control rendering and PDF generation. ```APIDOC ## weasyprint.__main__.main ### Description This is the main function for the `weasyprint` command-line tool. It processes input HTML and generates output, typically a PDF file, with various configurable options. ### Method Command-line execution ### Endpoint `weasyprint [options] ` ### Parameters #### Path Parameters - **input** (URL or filename) - Required - URL or filename of the HTML input, or '-' for stdin. - **output** (filename) - Required - Filename where output is written, or '-' for stdout. #### Query Parameters - **-i, --info** - Print system information and exit. - **--version** - Print WeasyPrint’s version number and exit. ### Rendering options - **-s , --stylesheet ** - URL or filename for a user CSS stylesheet. Can be passed multiple times. - **-a , --attachment ** - URL or filename of a file to attach to the PDF document. Can be passed multiple times. - **--attachment-relationship ** - Relationship of the attachment file to attach to the PDF. Can be passed multiple times. - **--pdf-identifier ** - PDF file identifier. - **--pdf-variant ** - PDF variant to generate. Possible choices include pdf/a-1b, pdf/a-2b, pdf/a-3b, etc. - **--pdf-version ** - PDF version number. - **--pdf-forms** - Include PDF forms. - **--pdf-tags** - Tag PDF for accessibility. - **--uncompressed-pdf** - Do not compress PDF content, mainly for debugging purposes. - **--xmp-metadata ** - URL or filename of a file to include into the XMP metadata. Can be passed multiple times. - **--custom-metadata** - Include custom HTML meta tags in PDF metadata. - **--output-intent ** - Srgb, device-cmyk, or CSS identifier of the output intent color space. - **-p, --presentational-hints** - Follow HTML presentational hints. - **--optimize-images** - Optimize size of embedded images with no quality loss. - **-j , --jpeg-quality ** - JPEG quality between 0 (worst) to 95 (best). - **-D , --dpi ** - Set maximum resolution of images embedded in the PDF. - **--full-fonts** - Embed unmodified font files when possible. - **--hinting** - Keep hinting information in embedded fonts. - **-c , --cache-folder ** - Store cache on disk instead of memory. Folder is created if needed and cleaned after the PDF is generated. ### HTML options - **-e , --encoding ** - Force the input character encoding. - **-m , --media-type ** - Media type to use for @media, defaults to print. - **-u , --base-url ** - Base for relative URLs in the HTML input, defaults to the input’s own filename or URL or the current directory for stdin. ### URL fetcher options - **-t , --timeout ** - Set timeout in seconds for HTTP requests. - **--allowed-protocols ** - Only authorize comma-separated list of protocols for fetching URLs. - **--no-http-redirects** - Do not follow HTTP redirects. - **--fail-on-http-errors** - Abort document rendering on any HTTP error. ``` -------------------------------- ### WeasyPrint Command-Line Usage Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Basic syntax for using the WeasyPrint command-line tool. Specify options, input HTML file/URL, and output PDF file/stdout. ```bash weasyprint [options] ``` -------------------------------- ### Enable PDF Forms via CLI Source: https://doc.courtbouillon.org/weasyprint/stable/common_use_cases.html Use the `--pdf-forms` command-line option to generate PDF documents with interactive form fields. ```bash $ weasyprint document.html --pdf-forms document.pdf ``` -------------------------------- ### Instantiate HTML and CSS from String Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Create HTML and CSS objects directly from string content using the `string` named argument. This is useful for dynamic content or small snippets. ```python from weasyprint import HTML, CSS # HTML('

foo') would be filename HTML(string='''

The title

Content goes here ''') CSS(string='@page { size: A3; margin: 1cm }') ``` -------------------------------- ### Convert URL to PDF with inline stylesheet using WeasyPrint CLI Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Converts a URL to PDF using WeasyPrint CLI, applying an inline stylesheet for font family. ```bash weasyprint https://weasyprint.org /tmp/weasyprint-website.pdf \ -s <(echo 'body { font-family: serif !important }') ``` -------------------------------- ### Instantiate HTML from Filename, URL, or File Object Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Create an HTML object by passing a filename, absolute URL, or a readable file object. You can also use named arguments like `filename`, `url`, or `file_obj` for explicit control. ```python from weasyprint import HTML HTML('../foo.html') # Same as … HTML(filename='../foo.html') HTML('https://weasyprint.org') # Same as … HTML(url='https://weasyprint.org') HTML(sys.stdin) # Same as … HTML(file_obj=sys.stdin) ``` -------------------------------- ### Convert URL to PDF using WeasyPrint CLI Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Converts a given URL to a PDF file using the WeasyPrint command-line interface. ```bash weasyprint https://weasyprint.org /tmp/weasyprint-website.pdf ``` -------------------------------- ### Generate PDF/UA Variant via Command Line Source: https://doc.courtbouillon.org/weasyprint/stable/common_use_cases.html This command demonstrates how to generate a PDF document with the PDF/UA (Universal Accessibility) variant using the WeasyPrint command-line interface. This is useful for creating accessible PDFs that meet international standards. ```bash $ weasyprint document.html --pdf-variant="pdf/ua-1" document.pdf ``` -------------------------------- ### Attach Files via Python with WeasyPrint.Attachment Source: https://doc.courtbouillon.org/weasyprint/stable/common_use_cases.html Instantiate `weasyprint.Attachment` objects for each file and pass them as a list to the `attachments` parameter in `write_pdf`. ```python from weasyprint import Attachment, HTML attachments = [Attachment("note.txt"), Attachment("photo.jpg")] HTML(string="

PDF with attachments

").write_pdf("recipe.pdf", attachments=attachments) ``` -------------------------------- ### WeasyPrint System Information Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Command-line option to print system information and exit. ```bash weasyprint -i ``` -------------------------------- ### WeasyPrint Allowed Protocols Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Restrict URL fetching to a comma-separated list of allowed protocols. ```bash weasyprint --allowed-protocols http,https ``` -------------------------------- ### Python API: URLFetcher.fetch() Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Fetches a resource from a given URL. ```APIDOC ## Python API: URLFetcher.fetch() ### Description This method is responsible for fetching resources (like stylesheets or images) from specified URLs during the rendering process. ### Method `URLFetcher.fetch(url)` ### Parameters - `url` (str): The URL of the resource to fetch. ### Response - Returns a `URLFetcherResponse` object containing the fetched resource data and metadata, or raises a `FatalURLFetchingError` on failure. ``` -------------------------------- ### Enable PDF Forms via Python Source: https://doc.courtbouillon.org/weasyprint/stable/common_use_cases.html Use the `pdf_forms=True` parameter in the `write_pdf` method to convert HTML form fields into interactive PDF forms. ```python from weasyprint import HTML HTML(string="").write_pdf("test.pdf", pdf_forms=True) ``` -------------------------------- ### WeasyPrint Version Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Command-line option to print WeasyPrint's version number and exit. ```bash weasyprint --version ``` -------------------------------- ### Apply CSS @page Rule via Command Line Source: https://doc.courtbouillon.org/weasyprint/stable/common_use_cases.html This command shows how to apply CSS `@page` rules directly from the command line using shell process substitution. This is useful for applying custom page sizes and margins without creating a separate CSS file. ```bash $ weasyprint input.html output.pdf -s <(echo "@page { size: A3 landscape; margin: 3cm }") ``` -------------------------------- ### Generate PDF with Factur-X Attachment (Python API) Source: https://doc.courtbouillon.org/weasyprint/stable/common_use_cases.html Utilize the WeasyPrint Python API to render an HTML invoice and attach Factur-X XML data and XMP metadata, specifying the PDF/A-3b variant. ```python from weasyprint import Attachment, HTML document = HTML("invoice.html").render() factur_x_xml = Path("factur-x.xml").read_text() attachment = Attachment(string=factur_x_xml, name="factur-x.xml", relationship="Data") document.metadata.attachments = [attachment] xmp_metadata = Path("rdf.xml").read_text().encode() document.metadata.xmp_metadata = [xmp_metadata] document.write_pdf("invoice.pdf", pdf_variant="pdf/a-3b") ``` -------------------------------- ### Implement Custom URL Fetcher for Specific Schemes Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Create a custom URLFetcher to handle specific URL schemes, such as 'graph:'. This allows WeasyPrint to process non-standard resource types by delegating to a custom logic while falling back to the default fetcher for others. ```python from weasyprint import HTML from weasyprint.urls import URLFetcher, URLFetcherResponse class MyFetcher(URLFetcher): def fetch(self, url, headers=None): if url.startswith('graph:'): graph_data = [float(value) for value in url[6:].split(',')] string = generate_graph(graph_data) return URLFetcherResponse(url, string, {'Content-Type': 'image/png'}) return super().fetch(url, headers) source = '' HTML(string=source, url_fetcher=MyFetcher()).write_pdf('out.pdf') ``` -------------------------------- ### WeasyPrint Optimize Images Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Optimize the size of embedded images without quality loss. ```bash weasyprint --optimize-images ``` -------------------------------- ### Python API: HTML Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html The `HTML` class is the main entry point for using WeasyPrint in Python. It allows you to load HTML content and render it to PDF. ```APIDOC ## Python API: HTML Class ### Description Represents an HTML document that can be rendered to PDF. You can initialize it with a URL, a file path, or a string containing HTML. ### Usage ```python from weasyprint import HTML # From a URL html = HTML(url='http://example.com/page.html') # From a file path html = HTML(filename='my_document.html') # From a string html = HTML(string='

Hello World

') ``` ``` -------------------------------- ### WeasyPrint Tag PDF for Accessibility Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Enable PDF tagging for improved accessibility. ```bash weasyprint --pdf-tags ``` -------------------------------- ### WeasyPrint User Stylesheet Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Specify a user CSS stylesheet for rendering. This option can be used multiple times. ```bash weasyprint -s ``` -------------------------------- ### Check Coding Style with Ruff Source: https://doc.courtbouillon.org/weasyprint/stable/contribute.html Use ruff to check the project's coding style. ```bash venv/bin/python -m ruff check ``` -------------------------------- ### weasyprint.HTML.write_pdf Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Renders the document to a PDF file. This is a shortcut for calling `render()` then `Document.write_pdf()`. The PDF can be saved to a file, written to a file object, or returned as bytes. ```APIDOC ## Method: weasyprint.HTML.write_pdf ### Description Render the document to a PDF file. This is a shortcut for calling `render()` then `Document.write_pdf()`. ### Parameters * **target** (str, pathlib.Path or file object) - A filename where the PDF file is generated, a file object, or `None`. * **zoom** (float) - The zoom factor in PDF units per CSS units. Defaults to 1. * **finisher** (callable) - A finisher function or callable that accepts the document and a `pydyf.PDF` object as parameters. Can be passed to perform post-processing on the PDF right before the trailer is written. * **font_config** (text.fonts.FontConfiguration) - A font configuration handling `@font-face` rules. * **counter_style** (css.counters.CounterStyle) - A dictionary storing `@counter-style` rules. * **color_profiles** - Color profiles to use. * **options** - Additional rendering options. ### Returns The PDF as `bytes` if `target` is not provided or `None`, otherwise `None` (the PDF is written to `target`). ``` -------------------------------- ### Write Document to PDF Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Generate a PDF file from a WeasyPrint document. The `target` can be a filename, file object, or `None` to return PDF bytes. The `zoom` parameter controls the scaling of content. ```python document.write_pdf('output.pdf', zoom=1.5) ``` -------------------------------- ### Python API: HTML.write_pdf() Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Renders the HTML document and writes the output to a PDF file. ```APIDOC ## Python API: HTML.write_pdf() ### Description This method directly renders the HTML content and saves it as a PDF file to the specified path or file-like object. ### Method `HTML.write_pdf(target=None, **options)` ### Parameters - `target` (str or file-like object, optional): The path or file-like object to write the PDF to. If None, a file-like object is returned. - `**options`: Additional keyword arguments to control PDF generation (e.g., `base_url`, `encoding`). ### Response - If `target` is provided, returns None. - If `target` is None, returns a file-like object containing the PDF data. ``` -------------------------------- ### Set WEASYPRINT_DLL_DIRECTORIES on Windows Source: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html Sets the WEASYPRINT_DLL_DIRECTORIES environment variable in cmd.exe to help WeasyPrint find DLL files. ```bash set WEASYPRINT_DLL_DIRECTORIES=C:\msys64\mingw64\bin ``` -------------------------------- ### WeasyPrint XMP Metadata Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Include XMP metadata from an external file into the PDF. This option can be used multiple times. ```bash weasyprint --xmp-metadata ``` -------------------------------- ### Attach Files via CLI Source: https://doc.courtbouillon.org/weasyprint/stable/common_use_cases.html Utilize the `--attachment` command-line option, which can be specified multiple times, to include files as attachments in the generated PDF. ```bash $ weasyprint document.html --attachment note.txt --attachment photo.jpg document.pdf ``` -------------------------------- ### Default Rendering Options Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Displays the default options used for rendering with the command-line and Python API. These options control various aspects of PDF generation. ```python weasyprint.DEFAULT_OPTIONS = { 'attachment_relationships': None, 'attachments': None, 'cache': None, 'custom_metadata': False, 'dpi': None, 'full_fonts': False, 'hinting': False, 'jpeg_quality': None, 'optimize_images': False, 'output_intent': None, 'pdf_forms': None, 'pdf_identifier': None, 'pdf_tags': False, 'pdf_variant': None, 'pdf_version': None, 'presentational_hints': False, 'stylesheets': None, 'uncompressed_pdf': False, 'xmp_metadata': None, } ``` -------------------------------- ### Trust Self-Signed SSL Certificates and Update CA Bundle Source: https://doc.courtbouillon.org/weasyprint/stable/common_use_cases.html This snippet shows how to copy your self-signed SSL certificate and key to the trusted CA certificates directory, update the system's trusted certificates, and export the updated CA bundle. This ensures that requests made by your server, including those for images, will trust the self-signed certificate. ```bash sudo cp /etc/ssl/certs/localhost.crt /usr/local/share/ca-certificates/localhost.crt sudo cp /etc/ssl/private/localhost.key /usr/local/share/ca-certificates/localhost.key # Update the certificate authority trusted certificates. sudo update-ca-certificates # Export your newly updated Certificate Authority Bundle file. # If using Django, it will use the newly signed certificate authority as # valid and images will load properly. sudo tee -a /etc/environment <<< 'export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt' ``` -------------------------------- ### Include Custom Metadata via CLI Source: https://doc.courtbouillon.org/weasyprint/stable/common_use_cases.html Employ the `--custom-metadata` command-line option to embed custom HTML metadata into the PDF's info dictionary. ```bash $ weasyprint document.html --custom-metadata document.pdf ``` -------------------------------- ### Document Copy with Page Subset Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Demonstrates how to create a new Document object containing only a subset of pages from an existing document. This is useful for generating separate PDFs for specific page ranges. ```python # Write two PDF files for odd-numbered and even-numbered pages: # document.copy(pages=document.pages[::2]).write_pdf('odd.pdf') # document.copy(pages=document.pages[1::2]).write_pdf('even.pdf') ``` -------------------------------- ### WeasyPrint Include PDF Forms Source: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html Option to include PDF forms in the generated document. ```bash weasyprint --pdf-forms ```