Code Monkey home page Code Monkey logo

mkdocs-with-pdf's Introduction

PDF Generate Plugin for MkDocs

PyPI version PyPI downloads


This plugin will generate a single PDF file from your MkDocs repository. This plugin is inspired by MkDocs PDF Export Plugin.

Features

  • Cover and Table of Contents integrated in the PDF
  • Automatically numbers on heading(h1-h3).
  • Shift down sub-page headings level.
  • using WeasyPrint.

Samples

Requirements

  1. This package requires MkDocs version 1.0 or higher (0.17 works as well)
  2. Python 3.6 or higher
  3. WeasyPrint depends on cairo, Pango and GDK-PixBuf which need to be installed separately. Please follow the installation instructions for your platform carefully:

How to use

Installation

  1. Install the package with pip:

    pip install mkdocs-with-pdf
  2. Enable the plugin in your mkdocs.yml:

    plugins:
        - with-pdf

    More information about plugins in the MkDocs documentation.

Testing

When building your repository with mkdocs build, you should now see the following message at the end of your build output:

Converting 10 articles to PDF took 7.1s

Configuration

You may customize the plugin by passing options in mkdocs.yml:

plugins:
    - with-pdf:
        #author: WHO
        #copyright: ANY TEXT
        #
        #cover: false
        #back_cover: true
        #cover_title: TITLE TEXT
        #cover_subtitle: SUBTITLE TEXT
        #custom_template_path: TEMPLATES PATH
        #
        #toc_title: TOC TITLE TEXT
        #heading_shift: false
        #toc_level: 3
        #ordered_chapter_level: 2
        #excludes_children:
        #    - 'release-notes/:upgrading'
        #    - 'release-notes/:changelog'
        #
        #exclude_pages:
        #    - 'bugs/'
        #    - 'appendix/contribute/'
        #convert_iframe:
        #    - src: IFRAME SRC
        #      img: POSTER IMAGE URL
        #      text: ALTERNATE TEXT
        #    - src: ...
        #two_columns_level: 3
        #
        #render_js: true
        #headless_chrome_path: headless-chromium
        #
        #output_path: any-place/document.pdf
        #enabled_if_env: ENABLE_PDF_EXPORT
        #
        #debug_html: true
        #show_anchors: true
        #verbose: true

Options

for Properties
  • author

    Set the author text.
    default: use site_author in your project mkdocs.yml

  • copyright

    Set the author text.
    default: use copyright in your project mkdocs.yml

author and copyright values are drawn in Cover, and you can use '@page' content.

@page {
  @bottom-left {
    content: string(author) !important;
  }
  @bottom-right {
    content: string(copyright) !important;
  }
}
for Cover
  • cover

    Set the value to false if you don't need a cover page.
    default: true

  • back_cover

    Set the value to true if you need a back cover page.
    default: false
    since: v0.8.0

    You would be better to install the qrcode package:

    pip install qrcode
  • cover_title

    Set the title text in cover page.
    default: use site_name in your project mkdocs.yml

  • cover_subtitle

    Set the subtitle text in cover page.
    default: None

  • cover_logo

    Set the logo image in cover page. This value is URL or simply specify the relative path to the docs directory.
    default: None
    since: v0.8.0

for Heading and TOC
  • toc_title

    Set the title text of Table of Content.
    default: Table of Content
    since: v0.4.0

  • heading_shift

    Set this value to false, disable shift heading in child page.
    default: true

    In this flags enable, heading move down one level in child page.

  • toc_level

    Set the level of Table of Content. This value is enabled in the range of from 1 to 3.
    default: 3

  • ordered_chapter_level

    Set the level of heading number addition. This value is enabled in the range of from 1 to 3.
    default: 3

  • excludes_children

    Set the page id of nav url. If the id matches in this list, it will be excluded from the heading number addition and table of contents.
    default: []

for Page
  • exclude_pages

    Set the page id of nav url. If the id matches in this list, it will be excluded page contents.
    default: []
    since: v0.3.0

  • convert_iframe

    List of iframe to a conversions. Every iframe that matches a src in this list will be replace to a contains each img and/or text. it's using for such as embedded VIDEO.
    default: []
    since: v0.6.0

    @see Sample of MkDocs Material

  • two_columns_level (Experimental)

    Set the heading level of Two Column Layout. Currently only 0(disable) or 3 is valid for this value. So slow processing, but a little nice.

    default: 0
    since: v0.7.0

    @see Sample of MkDocs Material

Renderer for JavaScript
  • render_js

    Set the value to true if you're using 'MathJax', 'Twemoji' or any more.
    Require "Chrome" which has "headless" mode.

    default: false
    since: v0.7.0

  • headless_chrome_path

    Set the "Headless Chrome" program path.
    If render_js is false, this value will be ignored.

    default: chromium-browser

Check on your system:

$ <PROGRAM_PATH> --headless \
   --disable-gpu \
   --dump-dom \
   <ANY_SITE_URL(eg. 'https://google.com')>
... and more
  • output_path

    This option allows you to use a different destination for the PDF file.
    default: pdf/document.pdf

  • custom_template_path

    The path where your custom cover.html and/or styles.scss are located. default: templates
    since: v0.8.0

  • enabled_if_env

    Setting this option will enable the build only if there is an environment variable set to 1. This is useful to disable building the PDF files during development, since it can take a long time to export all files.
    default: None

    PDF generation can take significantly longer than HTML generation which can slow down mkdocs's built-in dev-server.

    Adding enabled_if_env: ENABLE_PDF_EXPORT under - with-pdf: disables PDF generation during development. Run the dev-server normally:

    $ mkdocs serve
    INFO    -  Browser Connected: http://127.0.0.1:8000/
    INFO    -  Running task: builder (delay: None)
    INFO    -  Building documentation...
    WARNING -  without generate PDF(set environment variable ENABLE_PDF_EXPORT to 1 to enable)
    ... 2 seconds later ...
    INFO    -  Reload 1 waiters: /.../index.md

    and to build files to deploy specify ENABLE_PDF_EXPORT=1 at the command line:

    $ ENABLE_PDF_EXPORT=1 mkdocs build
    ...
    INFO    -  Converting 10 articles to PDF took 7.1s
    INFO    -  Documentation built in 8.29 seconds
  • debug_html

    Setting this to true will out HTML to stdout on build time.
    default: false

    You can try this:

    mkdocs build > for_pdf_print.html

    ...and browse output with Google Chrome. Chrome DevTools Into Print Preview Mode will you help.

    Note: WeasyPrint and Google Chrome are not fully compatible.

  • show_anchors

    Setting this to true will list out of anchor points provided during the build as info message.
    default: false
    since: v0.7.4

  • verbose

    Setting this to true will show all WeasyPrint debug messages during the build.
    default: false

Custom cover page and document style

It is possible to create a custom cover page for the document. You can also add a custom style sheet to modify the whole document.

To do so, add a templates folder at the root level of your mkdocs project and place a cover.html and/or a styles.scss inside. Alternatively, you can specify a different location with the custom_template_path option.

Custom cover page

Using jinja2 syntax, you can access all data from your mkdocs.yml. To make template creation easier, you can use plugin_some_plugin to access variables from plugins. E.g. use {{ author }} to get the author from your mkdocs.yml that looks like:

plugins:
    - with-pdf:
        author: WHO

You can use custom variables extra: in your mkdocs.yml And, you can check it in the log if run with verbose or debug_html options.

Custom stylesheet

Since your stylesheet is appended to the default ones, you can override every setting from them.

Tip: setting the debug_html option to true to get the generated html that is passed to weasyprint can help you determine the html tags, classes or identifiers you want to modify in your stylesheet.

Advanced Rendering Hooks (Experimental)

You can hook the PDF rendering process by creating a pdf_event_hook.py(or pdf_event_hook/__init__.py) in your working directory (usually the same directory as mkdocs.yml).
since: v0.8.2

Sample pdf_event_hook.py (or pdf_event_hook/__init__.py)

import logging

from bs4 import BeautifulSoup
from mkdocs.structure.pages import Page


def inject_link(html: str, href: str,
                page: Page, logger: logging) -> str:
    """Adding PDF View button on navigation bar(using material theme)"""

    def _pdf_icon():
        _ICON = '''
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<path d="M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z" fill="#E2E5E7"/>
<path d="m384 128h96l-128-128v96c0 17.6 14.4 32 32 32z" fill="#B0B7BD"/>
<polygon points="480 224 384 128 480 128" fill="#CAD1D8"/>
<path d="M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16  V416z" fill="#F15642"/>
<g fill="#fff">
<path d="m101.74 303.15c0-4.224 3.328-8.832 8.688-8.832h29.552c16.64 0 31.616 11.136 31.616 32.48 0 20.224-14.976 31.488-31.616 31.488h-21.36v16.896c0 5.632-3.584 8.816-8.192 8.816-4.224 0-8.688-3.184-8.688-8.816v-72.032zm16.88 7.28v31.872h21.36c8.576 0 15.36-7.568 15.36-15.504 0-8.944-6.784-16.368-15.36-16.368h-21.36z"/>
<path d="m196.66 384c-4.224 0-8.832-2.304-8.832-7.92v-72.672c0-4.592 4.608-7.936 8.832-7.936h29.296c58.464 0 57.184 88.528 1.152 88.528h-30.448zm8.064-72.912v57.312h21.232c34.544 0 36.08-57.312 0-57.312h-21.232z"/>
<path d="m303.87 312.11v20.336h32.624c4.608 0 9.216 4.608 9.216 9.072 0 4.224-4.608 7.68-9.216 7.68h-32.624v26.864c0 4.48-3.184 7.92-7.664 7.92-5.632 0-9.072-3.44-9.072-7.92v-72.672c0-4.592 3.456-7.936 9.072-7.936h44.912c5.632 0 8.96 3.344 8.96 7.936 0 4.096-3.328 8.704-8.96 8.704h-37.248v0.016z"/>
</g>
<path d="m400 432h-304v16h304c8.8 0 16-7.2 16-16v-16c0 8.8-7.2 16-16 16z" fill="#CAD1D8"/>
</svg>
'''  # noqa: E501
        return BeautifulSoup(_ICON, 'html.parser')

    logger.info(f'(hook on inject_link: {page.title})')
    soup = BeautifulSoup(html, 'html.parser')

    nav = soup.find(class_='md-header-nav')
    if not nav:
        # after 7.x
        nav = soup.find('nav', class_='md-header__inner')
    if nav:
        a = soup.new_tag('a', href=href, title='PDF',
                         **{'class': 'md-header__button md-header-nav__button md-icon'})
        a.append(_pdf_icon())
        nav.append(a)
        return str(soup)

    return html


# def pre_js_render(soup: BeautifulSoup, logger: logging) -> BeautifulSoup:
#     logger.info('(hook on pre_js_render)')
#     return soup


# def pre_pdf_render(soup: BeautifulSoup, logger: logging) -> BeautifulSoup:
#     logger.info('(hook on pre_pdf_render)')
#     tag = soup.find(lambda tag: tag.name ==
#                     'body' and 'data-md-color-scheme' in tag.attrs)
#     if tag:
#         tag['data-md-color-scheme'] = 'print'
#     return soup

... and check log:

$ mkdocs build
INFO    -  Found PDF rendering event hook module.
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: /tmp/sample/site
INFO    -  (hook on inject_link: Home)
   ...

Contributing

From reporting a bug to submitting a pull request: every contribution is appreciated and welcome. Report bugs, ask questions and request features using Github issues. If you want to contribute to the code of this project, please read the Contribution Guidelines.

Special thanks to

mkdocs-with-pdf's People

Contributors

abdealiloko avatar dependabot[bot] avatar ju-mueller avatar mikesamuel avatar orzih avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mkdocs-with-pdf's Issues

Incompatible with awesome-pages

Hi, and thanks for this nice plugin!

I was hoping to be able to auto-detect markdown documents (not specified in the nav) by using mkdocs-awesome-pages and have a PDF generated from such docs, e.g.:

site_name: my docs
theme:
  name: material
plugins:
  - search
  - with-pdf:
      enabled_if_env: ENABLE_PDF_EXPORT
  - awesome-pages
nav:
  - Home: index.md
  - Changelog: changelog.md
  - ...

But this just results in a completely empty PDF.

I have numerous folders with markdown documents inside, which I don't have to add to the nav, as they are added automatically by the - .... Do you have any ideas on if there's any way to fix this or maybe you are aware of another plugin which does something similar?

Links to/from subdirs broken depending on use_directory_urls

Version 0.3.3 + MkDocs 1.1.2
Link to sections from subdirs aren't connected depending on the value of use_directory_urls:

huh.md:

# TEST
## One
- [Link 1: to subdir (file)](subdir/huh.md)
- [Link 2: to subdir (section)](subdir/huh.md#one)

subdir/huh.md:

# SUBDIR TEST
# One
- [Link 3: to parent (file)](../huh.md)
- [Link 4: to parent (section)](../huh.md#one)
  • use_directory_urls: true (default): Links 2 & 4 ok, 1 & 3 broken ('The application can’t be opened.')
  • use_directory_urls: false: Links 1, 2 & 3 ok. Link 4 inactive.

Table with images gets cut

Hi guys, thx very much for this amazing plugin, by far one of the best I tried!

I run into some issues which I hope you can help with. I often put pictures inside tables to have a side by side view and to auto-size the pictures between mobile and desktop. I think what happens is that pictures get in the full resolution which ends up cutting the table and misses content.

On mkdocs website - All OK
image

On PDF output - Only part of the table
image

The markup

## **Install display on your handlebar**

| Measure handlebar | Tighten the screw | Allow slight rotation | Plug-in the connector |
|:-:|:-:|:-:|:-:|
| ![Handlebar measurement][HandlebarMeasurement] | ![EggRider hero][DisplayScrewThightening] | ![Allow slight rotation][DisplaySlightRotation] | ![Plug-in connector][PlugConnectors] |

The HTML

<h2 id="install-display-on-your-handlebar"><strong>Install display on your handlebar</strong><a class="headerlink" href="#install-display-on-your-handlebar" title="Permanent link">Link</a></h2>
<div class="md-typeset__scrollwrap"><div class="md-typeset__table"><table> <thead> <tr> <th align="center">Measure handlebar</th> <th align="center">Tighten the screw</th> <th align="center">Allow slight rotation</th> <th align="center">Plug-in the connector</th> </tr> </thead> <tbody> <tr> <td align="center"><img alt="Handlebar measurement" src="../assets/images/display_instructions/handlebar_measurement.jpg" title="Handlebar measurement"></td> <td align="center"><img alt="EggRider hero" src="../assets/images/display_instructions/eggrider_screw_tightening.jpg" title="EggRider screw thightening"></td> <td align="center"><img alt="Allow slight rotation" src="../assets/images/display_instructions/eggrider_allow_slight_rotation2.jpg" title="EggRider allow slight rotation"></td> <td align="center"><img alt="Plug-in connector" src="../assets/images/display_instructions/plug_connectors.jpg" title="Plug connectors"></td> </tr> </tbody> </table></div></div>

PS: I tried the suggestions in #23 but no success :(

I would really appreciate your help! Keep up with the good work!

Overlapped text in rendered PDF

Current Behavior

This is a piece of rendered PDF file:

imagen

The rendered file text seems to be overlapped.

Context (Environment)

  • Python v3.8.7
  • mkdocs-with-pdf v0.8.3
  • WeasyPrint v52.2

My mkdocs.yml plugins config:

plugins:
  - search
  - mermaid2
  - markdownextradata
  - with-pdf

PDF generation slows down iterative development via `mkdocs serve`

PDF generation takes a while

$ time mkdocs build
...
INFO    -  Converting 14 articles to PDF took 28.5s
INFO    -  Documentation built in 30.59 seconds

real	0m32.552s
user	0m29.004s
sys	0m0.923s

so PDF generation takes about 90% of the total time for my particular build.

This is fine when running mkdocs build, but when using mkdocs serve this means that any edit to any file takes half a minute to show up.

Might it be possible to skip or background PDF generation during mkdocs serve?

custom admonition type in PDF

The custom admonition type in PDF cannot be displayed, only the default style is displayed. Please instruct me how to set it?
image
image

Scaling the images to column-width on PDF

Hi,

I'm trying to export mkdocs website as a PDF however I'm having issues scaling the images to the PDF's column width.

The images look just fine on the website, however, while rendering the PDF they are not scaled to column width as they scaled on the website.

Also, as you see, figure2 is missing on pdf while there is no visible issue regarding that figure. Both the figures are located in the same directory and both of them are called in the same way on markdown.

Website:
image

PDF:
image

Markdown:
image

Document links don't work in pdf

If I include a link to another page in the Markdown using [link description](page.md) syntax the link doesn't not work in the generated PDF - the generated web site works OK.

There is an error output when the mkdocs build command is run, that corresponds to each instance of a page link in the Markdown docs : ERROR - No anchor #page.html: for internal URI reference.

It doesn't matter if the Markdown pages are in the same directory, in the root docs directory or in a subdirectories of the docs directory - none of the internal links work.

I have the recommended toc extension with the permalink: true option set and the use_directory_urls option set to false as specified in the documentation.

Using the debug_html option I can see there is no id attribute on the article tag for a page, so looks like there is no anchor being created for pages, just a data-url tag.

Long tables are rendered on a new page

If you have a table that is longer than a single page, the table is always starting on a separate page even if the content above the table consists only of a single sentence. I know it's not easy to define when a pagebreak makes sense and when it doesn't... Maybe you have an idea on how to improve this.

Admonition rendering

Dear All,
Do you think it's possible to change the default rendering for admonition ?
image

I prefer the read the doc theme ;)

image

Provide some option to fail on errors

Mkdocs provides a --strict flag for the build with

mkdocs build --strict

This fails on all warnings. This is especially useful for pipelines, where you don't want to publish when there are warnings or errors. However when enabled it ignores all errors from mkdocs-with-pdf. It would be great to either directly integrate with the mkdocs flag or to provide a different way to configure mkdocs-with-pdf to fail on errors.

Mermaid diagrams are not rendered in the output PDF

Is your feature request related to a problem? Please describe.
I can't render Mermaid diagrams using Headless Chrome JS renderer.
Everything renders correctly, except Mermaid Diagrams. Do you
have any working example to check this on your side?

Describe the solution you'd like
I would like to have Mermaid Diagrams rendered correctly into the output PDF.

Describe alternatives you've considered
I worked with the code a bit and noticed, that the produced output HTML is
working correctly and when open in the web browser e.g. firefox it
renders Mermaid diagrams fine. But after generating PDF diagrams disappear.

So... I noticed that https://github.com/RelaxedJS/ReLaXed is able to render
PDF correctly, so basically I am taking the output HTML and open a subprocess
with 'relaxed' to do a last step with the PDF processing and I managed to
get the diagrams working.

I am just wondering, why is this not working with Headless Chrome for me?
Maybe I am doing something wrong.

I see that another plugin is working with the diagrams fine:
https://github.com/smaxtec/mkdocs-pdf-with-js-plugin

Otherwise maybe you would consider a PR with additional option for used
the 'relaxed' tool as an alternative to the Headless Chrome?

Additional context
Versions:
mkdocs-with-pdf: 0.7.7
python: 3.7.9
chromedriver: 86.0.4240.22
Chrome: 86.0.4240.111

How to overwrite the scss for pdf.

Hi, I have read the documentation. And it seem the way to change is to add our file to extra_css in config file.

extra_css:
    - css/extra.css

I have done so. On build, the file extra.css wll be addded in site but nothing seem to happen

All images removed from document

Commit ae13433 added _remove_empty_tags functionality, but I think this results in all

<img ...../>

tags being removed from the generated pdf files.

p is in the includes array and a paragraph only containing an image tag has no text in it, so 'if x.name in includes and len(x.get_text(strip=True)) == 0:' at line 109 of generator.py returns true causing the tag to be removed

If I comment out the call to the _remove_empty_tags function the images appear in the generated pdf, if I leave the call in I get no images in the pdf

Links only work when ending in a slash

If I add a markdown Link to a chapter like this

[My Chapter](../../my/chapter)

it is not resolved in the pdf and I get an error on build time that there is no anchor, however the following works:

[My Chapter](../../my/chapter/)

Both are resolved correctly in the web version.

Config Tag where Download link gets appended to (Feature request)

Right now the download link get's appended to md-footer-copyright in the material design and always has "... download PDF".

I might be alone with this issue, but it would be very helpful if the tag for the download link would be available via the config parameters.

footer = soup.select('.md-footer-copyright')

Also, it would be great if the Link-Text would be something that can be adjusted easily.

Thank you for considering. If it doesn't fit your overall roadmap, please just close.

Apostrophe in site_author name causes plugin to crash

An author name specified in the the mkdocs.yaml file containing an apostrophe will cause the pdf generation to crash.
E.g. O'Leary

Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/__main__.py", line 176, in gh_deploy_command
    build.build(cfg, dirty=not clean)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/commands/build.py", line 295, in build
    config['plugins'].run_event('post_build', config=config)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/plugins.py", line 96, in run_event
    result = method(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/mkdocs_with_pdf/plugin.py", line 106, in on_post_build
    self.generator.on_post_build(config, self.config['output_path'])
  File "/usr/local/lib/python3.9/site-packages/mkdocs_with_pdf/generator.py", line 101, in on_post_build
    add_stylesheet(style_for_print(self._options))
  File "/usr/local/lib/python3.9/site-packages/mkdocs_with_pdf/styles/__init__.py", line 17, in style_for_print
    root = sass.compile(string=scss)
  File "/usr/local/lib/python3.9/site-packages/sass.py", line 738, in compile
    raise CompileError(v)
sass.CompileError: Error: Invalid CSS after "...copyright 'None": expected expression (e.g. 1px, bold), was "';"
        on line 4:36 of stdin
>>         string-set: copyright 'None';

The apostrophe can be escaped O\'Leary, which no longer crashes, but the name appears in the pdf with the escaping backslash.

No fonts configured on alpine linux - how to add them

Hi and thank you for your really great work with this plugin.

Unfortunately I got an error when building my documentation and I do not know how to fix it. Maybe you can help me:
/usr/local/lib/python3.8/site-packages/weasyprint/fonts.py:227: UserWarning: FontConfig: No fonts configured. Expect ugly output. warnings.warn(

I have the following fonts set:
font: text: Barlow code: Roboto Mono

is the error I get, when I build my mkdocs-material on docker (alpine). Did I miss a dependency?

Thanks in advance!

How to add image/logo to cover page

I've managed to produce a nice-looking PDF matching our corp ident but can't see how to add an image (Logo) to the cover. Is it possible?

How to exclude pages

First of all, thank you very much for the plugin, it's fantastic.

I'm not sure if I did it right, I was not able to exclude pages from the pdf as described in the documentation. Also in the sample pdf it seems that it did not work?

How to use "excludes_children:" correctly?

Local links on paths with special characters are not working

There still seems to be a problem with links and special characters like ä,& ect. When creating a local link inside a markdown document like this:

[local link](#some-heading)

everything works fine as long as there is no special character in the path. With special characters in the path the link is no longer working in the pdf. However if we use the path explicitly like this:

[local link](../../../path/to/here_ä/#some-heading)

the link works again.

I created a minimal example to show the three different cases I described.
mkdocs_heading_example.zip

Config for theme_handler_path

Hi, first off - amazing project. Ive been struggling with creating PDFs with mkdocs for a few weeks now, and came across this by chance. Worked flawlessly (with material) on the first attempt.

I was trying to customize the location of the "Download PDF" button as we want to keep it in a different location,
and I dug through the code to find the theme_handler_path config where I can define my own inject-html function to do this

I found that the theme_handler_path is being read from the configs twice - and it looked like a bug so, I thought I'd report it.

I created theme/pdf_handler/material.py and copied contents from: https://github.com/orzih/mkdocs-with-pdf/blob/master/mkdocs_with_pdf/themes/pdf_handler.py
To test things out ...

Attempt 1 - in plugins

https://github.com/orzih/mkdocs-with-pdf/blob/v0.7.5/mkdocs_with_pdf/options.py#L57

site_name: MyDocs
theme:
  name: material
plugins:
  - with-pdf:
    cover_title: MyDocs-PDFVersion
    theme_handler_path: theme/pdf_handler.py

This had no effect. I realized that this config is being over written by a global config by the same name

Attempt 2 - global config

https://github.com/orzih/mkdocs-with-pdf/blob/v0.7.5/mkdocs_with_pdf/options.py#L96

site_name: MyDocs
theme:
  name: material
plugins:
  - with-pdf:
    cover_title: MyDocs-PDFVersion
theme_handler_path: theme/pdf_handler.py

I could not use the --strict when I tried this, because it gave the error - WARNING - Config value: 'theme_handler_path'. Warning: Unrecognised configuration name: theme_handler_path
This works find after removing --strict

`exclude_pages` Skips Page Html Generation

Usage of exclude_pages causes whatever pages are excluded to not only be excluded from generated PDF (desired behavior), but also to be skipped when mkdocs generates the site html (undesired behavior).

I have tested this multiple times with both mkdocs build and mkdocs serve as did a colleague of mine on a different mkdocs project. When attempting to navigate to the page on the development server (localhost:8000), when I click the link it changes the browser URL to reflect the target page, but only shows previous pages' content. If I click it again, it updates the URL with additional paths that make the link nonsensical (something like localhost:8000/this/is/a/test/page/ to localhost:8000/this/is/a/test/page/a/test/page/) and I get an error 404. If I attempt to navigate to the page directly by URL, it displays a blank page, with absolutely no content. This is consistent across Chrome and Firefox.

The output file for an excluded site page contains only <!-- skipped 'Page(title='TITLE', url='this/is/a/test/page/')' --> (edited to reflect example used earlier).

I'm using:

  • mkdocs-with-pdf version 0.8.3 from pip
  • Weasyprint version 52.4 from pip
  • mkdocs version 1.1.2 from pip
  • Python 3.8.5

I don't know why it would be intended behavior if a user could simply remove a page from their documentation to the same effect. I don't believe that this is intended behavior, but if it is then it should probably be clearly reflected in the documentation.

Horizontal line is not displayed in PDF

I'm using material for Mkdocs. In markdown a horizontal line can be added with the following code:

---

it looks like this


this is not rendered in the PDF.

Does i18n support multi-language plugin?

  - with-pdf:
      copyright: Copyright &copy; Shanghai LianWei Digits Technology Group Co., Ltd.,All Rights Resevered.
      author: Jes.Xiao
      #cover_title:
      cover_subtitle: LIANWEI EES Technical documentation
      cover_logo: assets/lw-logo.png
      back_cover: true
      toc_level: 3
      # excludes_children:
      #   - 'releases/changelog/:upgrading'
      # convert_iframe:
      #   - src: https://streamable.com/e/zmtb00
      #     img: https://cdn-cf-east.streamable.com/image/zmtb00-screenshot75403.jpg
      # two_columns_level: 3
      output_path: ../document.pdf
      #debug_html: true
      #verbose: true
      #show_anchors: true
      enabled_if_env: ENABLE_PDF_EXPORT
      #  headless chrome using 'MathJax', 'Twemoji' or any more.
      render_js: true
      headless_chrome_path: 'C:\Program Files\Google\Chrome\Application\chrome.exe'
  - i18n:
      default_language: en
      default_language_only: false
      languages:
        en: english
        fr: français
      nav_translations:
        fr:
          Home:  Domicile

The result:

mkdocs.exe build
WARNING -  Language 'fr' is not supported by lunr.js, not setting it in the 'plugins.search.lang' option 
INFO    -  Cleaning site directory 
INFO    -  Building documentation to directory: C:\projects\lianwei\framework\lianwei-doc\contents\site 
Traceback (most recent call last):
  File "c:\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Python39\Scripts\mkdocs.exe\__main__.py", line 7, in <module>
  File "c:\python39\lib\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "c:\python39\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "c:\python39\lib\site-packages\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\python39\lib\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\python39\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "c:\python39\lib\site-packages\mkdocs\__main__.py", line 152, in build_command
    build.build(config.load_config(**kwargs), dirty=not clean)
  File "c:\python39\lib\site-packages\mkdocs\commands\build.py", line 261, in build
    files = config['plugins'].run_event('files', files, config=config)
  File "c:\python39\lib\site-packages\mkdocs\plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "c:\python39\lib\site-packages\mkdocs_static_i18n\plugin.py", line 367, in on_files
    self.i18n_configs[language] = deepcopy(config)
  File "c:\python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "c:\python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "c:\python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "c:\python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "c:\python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "c:\python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "c:\python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "c:\python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "c:\python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "c:\python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "c:\python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "c:\python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "c:\python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "c:\python39\lib\copy.py", line 205, in _deepcopy_list
    append(deepcopy(a, memo))
  File "c:\python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "c:\python39\lib\copy.py", line 237, in _deepcopy_method
    return type(x)(x.__func__, deepcopy(x.__self__, memo))
  File "c:\python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "c:\python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "c:\python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "c:\python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "c:\python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "c:\python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "c:\python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "c:\python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "c:\python39\lib\copy.py", line 161, in deepcopy
    rv = reductor(4)
TypeError: cannot pickle 'module' object

Thanks a lot!

Color of level 1 heading not changeable

I want to change the textcolor from grey to another color for the level1 heading (h1). I was able to do it for h2 to h6 with the help of styles.scss in the template directory introduced in version 0.8.0

$tmag: #0f0;
h1 { color: $tmag;}
article h1,h2,h3,h4,h5,h6 {color: $tmag;}

any hint ?

How to change the title of the table of content

Hi,

When generating a pdf, I would like to change the phrase "table of content" for its French equivalent "Table des matières". I tried to change it with CSS :

article#doc-toc > h1 {
  content:"Table des matières" !important;
}

However it did not change. Please advise.

中文乱码 Chinese is garbled after the generated PDF

Question

My markdown doc contains Chinese, Chinese is garbled after the generated PDF. What should I do? What are the possible problems? I'm a new guy, and I don't have any idea.

Environment

[root@centos7 ~]# python -V
Python 3.7.5
[root@centos7 ~]# pip list
Package                    Version  
-------------------------- ---------
beautifulsoup4             4.9.3    
cairocffi                  1.2.0    
CairoSVG                   2.5.2    
cffi                       1.14.5   
click                      7.1.2    
cssselect2                 0.4.1    
defusedxml                 0.7.1    
future                     0.18.2   
html5lib                   1.1      
importlib-metadata         3.7.3    
Jinja2                     2.11.3   
joblib                     1.0.1    
libsass                    0.20.1   
livereload                 2.6.3    
lunr                       0.5.8    
Markdown                   3.3.4    
MarkupSafe                 1.1.1    
mkdocs                     1.1.2    
mkdocs-material            7.0.6    
mkdocs-material-extensions 1.0.1    
mkdocs-pdf-export-plugin   0.5.8    
mkdocs-with-pdf            0.8.3    
nltk                       3.5      
Pillow                     8.1.2    
pip                        19.2.3   
pycparser                  2.20     
Pygments                   2.8.1    
pymarkdown                 0.1.4    
pymdown-extensions         8.1.1    
Pyphen                     0.10.0   
PyYAML                     5.4.1    
regex                      2021.3.17
setuptools                 41.2.0   
six                        1.15.0   
soupsieve                  2.2.1    
tinycss2                   1.1.0    
toolz                      0.11.1   
tornado                    6.1      
tqdm                       4.59.0   
typing-extensions          3.7.4.3  
WeasyPrint                 52.4     
webencodings               0.5.1    
zipp                       3.4.1    

Repro steps

1. Create a new project.

[root@centos7 ~]# mkdocs new test
[root@centos7 ~]# cd test/

2. Using the plugin.

[root@centos7 test]# cat > mkdocs.yml <<EOF
site_name: 我的测试
dev_addr: 0.0.0.0:8000
plugins:
  - with-pdf:
EOF

3. Rewrite index.md with Chinese

[root@centos7 test]# cat > docs/index.md <<"EOF"
完整文档请访问:[mkdocs.org](https://www.mkdocs.org).


* `mkdocs new [dir-name]` - 创建一个新项目
* `mkdocs serve` - 启动实时重新加载文档服务器
* `mkdocs build` - 建立文档站点
* `mkdocs -h` - 打印这个帮助信息


    mkdocs.yml    # 配置文件、
    docs/
        index.md  # 文档根页面
        ...       # 其他markdown页面, 镜像或其他问题
EOF

4. mkdocs build

[root@centos7 test]# mkdocs build
WARNING -  Config value: 'dev_addr'. Warning: The use of the IP address '0.0.0.0' suggests a production environment or the use of a proxy to connect to the MkDocs server. However, the MkDocs' server is intended for local development purposes only. Please use a third party production-ready server instead. 
INFO    -  Cleaning site directory 
INFO    -  Building documentation to directory: /root/test/site 
INFO    -  Number headings up to level 3. 
INFO    -  Generate a table of contents up to heading level 2. 
INFO    -  Generate a cover page with "default_cover.html.j2". 
INFO    -  Converting <img> alignment(workaround). 
INFO    -  Rendering for PDF. 
INFO    -  Output a PDF to "/root/test/site/pdf/document.pdf". 
INFO    -  Converting 1 articles to PDF took 2.2s 
INFO    -  Documentation built in 2.47 seconds 

5. Download and open the pdf

image

Is there any way to change the style of the output PDF ?

I want to change the PDF footer.

I added extra_css such as the following:

@page {
  @bottom-center {
    font-size: 6pt;
    content: string(copyright);
  }

  @bottom-right {
    font-size: 8pt;
    content: '- 'counter(page)'/'counter(pages)' -';
  }
}

But it didn't change.

Is there any way to change the style of the output PDF ?

debug_html build fails on Windows if output is redirected

Seems related to handling of unicode in Python, except the same repo and configuration successfully builds and outputs to file on Linux

Windows 10 Version 10.0.19042 Build 19042
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)]

mkdocs build
# a bunch of HTML and stuff
INFO    -  Converting 34 articles to PDF took 8.6s
INFO    -  Documentation built in 9.49 seconds
mkdocs build > pdf.html
# a bunch of INFO and WARNING messages
Traceback (most recent call last):
  File "c:\users\rpark\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\rpark\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\rpark\AppData\Local\Programs\Python\Python37\Scripts\mkdocs.exe\__main__.py", line 7, in <module>
  File "c:\users\rpark\appdata\local\programs\python\python37\lib\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\rpark\appdata\local\programs\python\python37\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "c:\users\rpark\appdata\local\programs\python\python37\lib\site-packages\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\users\rpark\appdata\local\programs\python\python37\lib\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\rpark\appdata\local\programs\python\python37\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "c:\users\rpark\appdata\local\programs\python\python37\lib\site-packages\mkdocs\__main__.py", line 152, in build_command
    build.build(config.load_config(**kwargs), dirty=not clean)
  File "c:\users\rpark\appdata\local\programs\python\python37\lib\site-packages\mkdocs\commands\build.py", line 295, in build
    config['plugins'].run_event('post_build', config=config)
  File "c:\users\rpark\appdata\local\programs\python\python37\lib\site-packages\mkdocs\plugins.py", line 96, in run_event
    result = method(**kwargs)
  File "c:\users\rpark\appdata\local\programs\python\python37\lib\site-packages\mkdocs_with_pdf\plugin.py", line 135, in on_post_build
    self.generator.on_post_build(config, self.config['output_path'])
  File "c:\users\rpark\appdata\local\programs\python\python37\lib\site-packages\mkdocs_with_pdf\generator.py", line 132, in on_post_build
    print(html_string)
  File "c:\users\rpark\appdata\local\programs\python\python37\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2190' in position 34939: character maps to <undefined>

Links on second level toc items aren't working

I'm using material for mkdocs. There are two different behaviors. If I don't set a first level heading for a page, mkdocs automatically renders the one that is given by the nav entry in the config file. In this case mkdocs-with-pdf throws the following error:

ERROR   -  Content discarded: target points to undefined anchor "('string', '#')"

The entry in the toc then points to #.

If I set the heading on the page manually by adding

# exampleHeading

to my markdown file I get the following error instead:

ERROR   -  No anchor #example/path/:exampleheading for internal URI reference

The resulting toc entry is then no longer a link meaning it is not clickable.

OSError: no library called "cairo" was found

enviroment: Windows10, Python3.9.5
cmd: mkdocs.exe build
error:

return _process_result(sub_ctx.command.invoke(sub_ctx))

File "d:\hzh_sfq\projects\shenzhen\docs\venv\lib\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "d:\hzh_sfq\projects\shenzhen\docs\venv\lib\site-packages\click\core.py", line 763, in invoke
return callback(*args, **kwargs)
File "d:\hzh_sfq\projects\shenzhen\docs\venv\lib\site-packages\mkdocs_main
.py", line 183, in build_command
build.build(config.load_config(**kwargs), dirty=not clean)
File "d:\hzh_sfq\projects\shenzhen\docs\venv\lib\site-packages\mkdocs\commands\build.py", line 249, in build
config = config['plugins'].run_event('config', config)
File "d:\hzh_sfq\projects\shenzhen\docs\venv\lib\site-packages\mkdocs\plugins.py", line 94, in run_event
result = method(item, **kwargs)
File "d:\hzh_sfq\projects\shenzhen\docs\venv\lib\site-packages\mkdocs_pdf_export_plugin\plugin.py", line 42, in on_config
from .renderer import Renderer
File "d:\hzh_sfq\projects\shenzhen\docs\venv\lib\site-packages\mkdocs_pdf_export_plugin\renderer.py", line 6, in
from weasyprint import HTML
File "d:\hzh_sfq\projects\shenzhen\docs\venv\lib\site-packages\weasyprint_init
.py", line 469, in
from .css import preprocess_stylesheet # noqa isort:skip
File "d:\hzh_sfq\projects\shenzhen\docs\venv\lib\site-packages\weasyprint\css_init_.py", line 27, in
from . import computed_values, counters, media_queries
File "d:\hzh_sfq\projects\shenzhen\docs\venv\lib\site-packages\weasyprint\css\computed_values.py", line 15, in
from .. import text
File "d:\hzh_sfq\projects\shenzhen\docs\venv\lib\site-packages\weasyprint\text.py", line 11, in
import cairocffi as cairo
File "d:\hzh_sfq\projects\shenzhen\docs\venv\lib\site-packages\cairocffi_init_.py", line 48, in
cairo = dlopen(
File "d:\hzh_sfq\projects\shenzhen\docs\venv\lib\site-packages\cairocffi_init_.py", line 45, in dlopen
raise OSError(error_message) # pragma: no cover
OSError: no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so.2': error 0x7e
cannot load library 'libcairo.2.dylib': error 0x7e
cannot load library 'libcairo-2.dll': error 0x7e

Internal refs broken when use_directory_urls=false AND file name != *index.md

Internal links in PDF inactive when use_directory_urls is false and filename does not begin with index.

Example:

# TEST PAGE
- [Internal link to one](#one)
- [Internal link to two](#two)
## One
One
## Two
two
  • Links rendered correctly when file is named index.md, indexnot.md.
  • Links appear but are inactive when file is named notindex.md, not.md.
  • When use_directory_links: true (the default) all links are correct.

Syntax error when running under Python3.5

It looks like the f"..." syntax is not supported in Python3.5.
Running mkdocs build gives:

Traceback (most recent call last):
File "/usr/local/bin/mkdocs", line 11, in
sys.exit(cli())
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/mkdocs/main.py", line 152, in build_command
build.build(config.load_config(**kwargs), dirty=not clean)
File "/usr/local/lib/python3.5/dist-packages/mkdocs/config/base.py", line 197, in load_config
errors, warnings = cfg.validate()
File "/usr/local/lib/python3.5/dist-packages/mkdocs/config/base.py", line 107, in validate
run_failed, run_warnings = self._validate()
File "/usr/local/lib/python3.5/dist-packages/mkdocs/config/base.py", line 62, in _validate
self[key] = config_option.validate(value)
File "/usr/local/lib/python3.5/dist-packages/mkdocs/config/config_options.py", line 131, in validate
return self.run_validation(value)
File "/usr/local/lib/python3.5/dist-packages/mkdocs/config/config_options.py", line 609, in run_validation
plgins[item] = self.load_plugin(item, cfg)
File "/usr/local/lib/python3.5/dist-packages/mkdocs/config/config_options.py", line 617, in load_plugin
Plugin = self.installed_plugins[name].load()
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/init.py", line 2447, in load
return self.resolve()
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/init.py", line 2453, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/usr/local/lib/python3.5/dist-packages/mkdocs_with_pdf/plugin.py", line 68
f'(set environment variable {env_name} to 1 to enable)'
^
SyntaxError: invalid syntax

all numbers title fail to create pdf

With a nav bar like below.

- Logs:
    2020:
      - Something:
          - log/2020/something/somepage.md

Basically any title that is all numbers, it results in:

Traceback (most recent call last):
  File "/home/user/.cache/venv/mobile-sre-docs-3.8.2/bin/mkdocs", line 10, in <module>
    sys.exit(cli())
  File "/home/user/.guix-extra-profiles/extras/extras/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/user/.guix-extra-profiles/extras/extras/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/user/.guix-extra-profiles/extras/extras/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/user/.guix-extra-profiles/extras/extras/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/user/.guix-extra-profiles/extras/extras/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/user/.cache/venv/mobile-sre-docs-3.8.2/lib/python3.8/site-packages/mkdocs/__main__.py", line 183, in build_command
    build.build(config.load_config(**kwargs), dirty=not clean)
  File "/home/user/.cache/venv/mobile-sre-docs-3.8.2/lib/python3.8/site-packages/mkdocs/commands/build.py", line 309, in build
    config['plugins'].run_event('post_build', config=config)
  File "/home/user/.cache/venv/mobile-sre-docs-3.8.2/lib/python3.8/site-packages/mkdocs/plugins.py", line 96, in run_event
    result = method(**kwargs)
  File "/home/user/.cache/venv/mobile-sre-docs-3.8.2/lib/python3.8/site-packages/mkdocs_with_pdf/plugin.py", line 134, in on_post_build
    self.generator.on_post_build(config, self.config['output_path'])
  File "/home/user/.cache/venv/mobile-sre-docs-3.8.2/lib/python3.8/site-packages/mkdocs_with_pdf/generator.py", line 126, in on_post_build
    content = self._get_content(soup, page)
  File "/home/user/.cache/venv/mobile-sre-docs-3.8.2/lib/python3.8/site-packages/mkdocs_with_pdf/generator.py", line 248, in _get_content
    content = self._get_content(soup, c)
  File "/home/user/.cache/venv/mobile-sre-docs-3.8.2/lib/python3.8/site-packages/mkdocs_with_pdf/generator.py", line 248, in _get_content
    content = self._get_content(soup, c)
  File "/home/user/.cache/venv/mobile-sre-docs-3.8.2/lib/python3.8/site-packages/mkdocs_with_pdf/generator.py", line 264, in _get_content
    page_path = self._page_path_for_id(page)
  File "/home/user/.cache/venv/mobile-sre-docs-3.8.2/lib/python3.8/site-packages/mkdocs_with_pdf/generator.py", line 185, in _page_path_for_id
    path = get_section_path(page)
  File "/home/user/.cache/venv/mobile-sre-docs-3.8.2/lib/python3.8/site-packages/mkdocs_with_pdf/utils/section.py", line 11, in get_section_path
    slugs = list(map(lambda sec: _section_slug(sec), section.ancestors))
  File "/home/user/.cache/venv/mobile-sre-docs-3.8.2/lib/python3.8/site-packages/mkdocs_with_pdf/utils/section.py", line 11, in <lambda>
    slugs = list(map(lambda sec: _section_slug(sec), section.ancestors))
  File "/home/user/.cache/venv/mobile-sre-docs-3.8.2/lib/python3.8/site-packages/mkdocs_with_pdf/utils/section.py", line 26, in _section_slug
    title = section.title if len(section.title) else str(uuid4)
TypeError: object of type 'int' has no len()

Exclude a single page?

How to exclude a single page?

For example, i have a landing page in my docs folder with directory docs/index.md.

And i want to exlude that in my generated PDF? How to do that?

The sample only show us how to exclude folder.

Thanks in advance @orzih

customizing via jinja templates

Hi @orzih,

we have an internal fork of this wonderful handy library. We - like it seems other too, judging from the other issue reports - were looking for ways to customize styles, layout etc.

We started to redactor some stuff to make our use case more easy - and moved away from python + beautiful soup for templating and replaced it with jinja. Is this direction something you like us to make merge requests here or should we fork?

exclude_pages compatibility with awesome-pages

I have run into an issue which might be related to #46.

The problem is that I am unable to use exclude_pages together with awesome-pages. Basically, if I use the ... in my mkdocs.yaml file, to have awesome-pages automatically add pages to nav, the exclude_pages functionality stops working.

I have created MWE in this repository: https://github.com/ErikThorsell/mkdocs_with_pdf-exclude_pages-bug. The key thing is Line 26 in the mkdocs.yaml (link), please see the inline comment.

Please let me know if there's anything I can do to assist you further in debugging the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.