Coder Social home page Coder Social logo

mkdocs-pdf-export-plugin's Introduction

MkDocs PDF Export Plugin Build Status

An MkDocs plugin to export content pages as PDF files

The pdf-export plugin will export all markdown pages in your MkDocs repository as PDF files using WeasyPrint. The exported documents support many advanced features missing in most other PDF exports, such as a PDF Index and support for CSS paged media module.

Requirements

  1. This package requires MkDocs version 1.0 or higher (0.17 works as well)
  2. Python 3.4 3.5 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:
  4. Explicit support for your mkdocs theme is probably required. As of now, the only supported theme is mkdocs-material. A generic version will just generate the PDF files and put the download link into a <link> tag.

If you want to add a new theme, see adding support for new themes for more information.

Installation

Install the package with pip:

pip install mkdocs-pdf-export-plugin

Enable the plugin in your mkdocs.yml:

plugins:
    - search
    - pdf-export

Note: If you have no plugins entry in your config file yet, you'll likely also want to add the search plugin. MkDocs enables it by default if there is no plugins entry set, but now you have to enable it explicitly.

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 17 files to PDF took 15.6s

In your site_dir you should now have a PDF file for every markdown page.

Options

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

plugins:
    - pdf-export:
        verbose: true
        media_type: print
        enabled_if_env: ENABLE_PDF_EXPORT

verbose

Setting this to true will show all WeasyPrint debug messages during the build. Default is false.

media_type

This option allows you to use a different CSS media type (or a custom one like pdf-export) for the PDF export. Default is print.

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 is not set.

combined

Setting this to true will combine all pages into a single PDF file. All download links will point to this file. Default is false.

combined_output_path

This option allows you to use a different destination for the combined PDF file. Has no effect when combined is set to false. Default is pdf/combined.pdf.

theme_handler_path

This option allows you to specify a custom theme handler module. This path must be relative to your project root (See example below). Default is not set.

mkdocs.yml:

plugins:
    - pdf-export:
        theme_handler_path: theme-handler.py
project-root
├── theme-handler.py
├── docs
├── mkdocs.yml
├── site
.
.

Adjusting the output

The resulting PDF can be customized easily by adding a custom stylesheet such as the following:

@page {
    size: a4 portrait;
    margin: 25mm 10mm 25mm 10mm;
    counter-increment: page;
    font-family: "Roboto","Helvetica Neue",Helvetica,Arial,sans-serif;
    white-space: pre;
    color: grey;
    @top-left {
        content: '© 2018 My Company';
    }
    @top-center {
        content: string(chapter);
    }
    @top-right {
        content: 'Page ' counter(page);
    }
}

For this to take effect, use the extra_css directive in mkdocs.yml, as described in the MkDocs user guide.

Adding support for new themes

If you use a mkdocs theme which is currently not supported, check out the themes/material.py file and adjust it according to your requirements. You will have to implement two methods to support a theme:

  1. get_stylesheet should return a CSS which gets applied to fix issues with weasyprint
  2. modify_html should add a link to the PDF download before writing it to disk

If there is no explicit support for your theme, the generic version will just add a <link> tag in the head pointing to the generated PDF.

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

Special thanks go to Stephan Hauser for the original development of this plugin.

Special thanks go to Lukas Geiter for developing the mkdocs-awesome-pages-plugin which was used as a base and for convincing Stephan Hauser to write a plugin for this.

mkdocs-pdf-export-plugin's People

Contributors

dependabot[bot] avatar durera avatar kanaduchi avatar lisongmin avatar lukasgeiter avatar mpilking avatar neroburner avatar shauser avatar timvink avatar ultrabug avatar zhaoterryy 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mkdocs-pdf-export-plugin's Issues

Error when using footnotes extension with combined option

I am trying to export my docs to a single PDF using the combined option while having the footnotes extension enabled:

markdown_extensions:
    - footnotes
    # more config

plugins:
    - pdf-export:
          combined: true

If I disable the combined option everything works fine. But as soon as I enable it I get the following error for every file that I use footnotes in:

":" and "/" characters are banned! /:
Error converting folder/file.md to PDF: Invalid ID found in folder/file/, ID: fnref:linkname

Any help would be appreciated.

ERROR: Failed to load font

Non-fatal error related to loading fonts such as:

Reproducible with or without PDF combined option.

ERROR: Failed to load font at "file:///D:/github-system-modernization/BOK/site/assets/fonts/specimen/MaterialIcons-Regular.woff2"
Converting 15 files to PDF took 21.5s

Rendering LaTeX output with Arithmatex MathJax

I am using the pymdownx.arithmatex extension with the material theme, as described here: https://squidfunk.github.io/mkdocs-material/extensions/pymdown/#arithmatex-mathjax

This works great when rendering HTML, but doesn't translate to PDF when using pdf-export.

mkdocs.yml is configured with the extra_javascript for MathJax. Maybe I'm missing a CSS?

extra_css:
  - 'pdf.css'

extra_javascript:
  - 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML'

Thanks!

Clarity in README.md

I am building a documentation solution using mkdocs and this extension. On the whole it works well for my purpose.

README.md does not explicitly state the capabilities.

I have an mkdocs solution that is extended with mermaid chart. The chart renders correctly as html but the pdf just contains the mermaid source as a single wrapped line of source code.

Does mkdocs-pdf-export-plugin support all of the extensions added to mkdocs?
Are there any additional actions needed to replicate the results in pdf?

This will help me to focus my attention on where to go next.

Steve

Mkdocs rendered mermaid as HTML:

image

Mkdocs rendered mermaid as PDF:

image

ValueError: unknown locale: UTF-8

I get the following error when executing mkdocs build while pdf-export is enabled.

➜ mkdocs-material-master mkdocs build Traceback (most recent call last): File "/usr/local/bin/mkdocs", line 11, in <module> sys.exit(cli()) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 722, in __call__ return self.main(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/mkdocs/__main__.py", line 162, in build_command site_dir=site_dir File "/usr/local/lib/python3.7/site-packages/mkdocs/config/base.py", line 197, in load_config errors, warnings = cfg.validate() File "/usr/local/lib/python3.7/site-packages/mkdocs/config/base.py", line 107, in validate run_failed, run_warnings = self._validate() File "/usr/local/lib/python3.7/site-packages/mkdocs/config/base.py", line 62, in _validate self[key] = config_option.validate(value) File "/usr/local/lib/python3.7/site-packages/mkdocs/config/config_options.py", line 132, in validate return self.run_validation(value) File "/usr/local/lib/python3.7/site-packages/mkdocs/config/config_options.py", line 572, in run_validation plgins[item] = self.load_plugin(item, cfg) File "/usr/local/lib/python3.7/site-packages/mkdocs/config/config_options.py", line 580, in load_plugin Plugin = self.installed_plugins[name].load() File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2325, in load return self.resolve() File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2331, in resolve module = __import__(self.module_name, fromlist=['__name__'], level=0) File "/usr/local/lib/python3.7/site-packages/mkdocs_pdf_export_plugin/plugin.py", line 8, in <module> from weasyprint import HTML, urls File "/usr/local/lib/python3.7/site-packages/weasyprint/__init__.py", line 375, in <module> from .css import preprocess_stylesheet # noqa File "/usr/local/lib/python3.7/site-packages/weasyprint/css/__init__.py", line 30, in <module> from .descriptors import preprocess_descriptors File "/usr/local/lib/python3.7/site-packages/weasyprint/css/descriptors.py", line 20, in <module> from .validation import ( File "/usr/local/lib/python3.7/site-packages/weasyprint/css/validation.py", line 25, in <module> from ..images import LinearGradient, RadialGradient File "/usr/local/lib/python3.7/site-packages/weasyprint/images.py", line 20, in <module> import cairosvg.parser File "/usr/local/lib/python3.7/site-packages/cairosvg/__init__.py", line 29, in <module> from . import surface File "/usr/local/lib/python3.7/site-packages/cairosvg/surface.py", line 27, in <module> from .defs import ( File "/usr/local/lib/python3.7/site-packages/cairosvg/defs.py", line 24, in <module> from .bounding_box import calculate_bounding_box, is_non_empty_bounding_box File "/usr/local/lib/python3.7/site-packages/cairosvg/bounding_box.py", line 26, in <module> from .features import match_features File "/usr/local/lib/python3.7/site-packages/cairosvg/features.py", line 25, in <module> LOCALE = locale.getdefaultlocale()[0] or '' File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/locale.py", line 568, in getdefaultlocale return _parse_localename(localename) File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/locale.py", line 495, in _parse_localename raise ValueError('unknown locale: %s' % localename) ValueError: unknown locale: UTF-8

For reproduction: I used the https://github.com/squidfunk/mkdocs-material Repro for testing purposes.

Improve README to explain how to use a custom stylesheet

Thanks for a great tool!

When I use it on the default mkdocs theme, I get lots of blank pages and spurious "Documentation built with MkDocs" footers. So I thought to try adding a custom stylesheet.

In the README, when you say "The resulting PDF can be customized easily by adding a custom stylesheet such as the following...", can you explain what that means? Where should I put that stylesheet and how do I hook it up?

Error converting markdown to PDF: tuple index out of range

I realized that I should have probably opened a new issue for this. I just commented on #16 with the stack from weasyprint. Stack is:

Traceback (most recent call last):
File "/home/demo/.local/bin/weasyprint", line 11, in
sys.exit(main())
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/main.py", line 212, in main
getattr(html, 'write_' + format_)(output, **kwargs)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/init.py", line 211, in write_pdf
font_config=font_config).write_pdf(
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/init.py", line 168, in render
font_config)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/document.py", line 393, in _render
[Page(page_box, enable_hinting) for page_box in page_boxes],
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/document.py", line 393, in
[Page(page_box, enable_hinting) for page_box in page_boxes],
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/init.py", line 126, in layout_document pages = list(make_all_pages(context, root_box, html, pages))
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/pages.py", line 803, in make_all_pages
page, resume_at = remake_page(i, context, root_box, html)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/pages.py", line 742, in remake_page
page_number, page_state)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/pages.py", line 553, in make_page
positioned_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 73, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/tables.py", line 432, in table_layout
all_groups_layout()
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/tables.py", line 417, in all_groups_layout skip_stack, position_y, max_position_y, page_is_empty))
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/tables.py", line 299, in body_groups_layout group, position_y, max_position_y, page_is_empty, skip_stack)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/tables.py", line 140, in group_layout
fixed_boxes=fixed_boxes)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout absolute_boxes, fixed_boxes, adjoining_margins)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 376, in block_container_layout for line, resume_at in lines_iterator:
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/inlines.py", line 53, in iter_line_boxes absolute_boxes, fixed_boxes, first_letter_style)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/inlines.py", line 70, in get_next_linebox skip_stack = skip_first_whitespace(linebox, skip_stack)
File "/home/demo/.local/lib/python3.6/site-packages/weasyprint/layout/inlines.py", line 210, in skip_first_whitespace result = skip_first_whitespace(box.children[index], next_skip_stack)
IndexError: tuple index out of range

TonyG

Failure to load woff2 fonts on Linux

Hello,

I am using mkdocs with material theme.
I follow documentation and I think install everything as needed.
python -m weasyprint http://weasyprint.org weasyprint.pdf is working properly

$ mkdocs --version
mkdocs, version 1.0.4 from /home/bretif/dev/mkdocs/skinfra-mkdocs/py3/lib/python3.5/site-packages/mkdocs (Python 3.5)

If I try to build my site but I get this error

ERROR: Failed to load font at "file:///home/bretif/dev/mkdocs/skinfra-mkdocs/site/assets/fonts/specimen/MaterialIcons-Regular.woff2"
ERROR: Failed to load font at "file:///home/bretif/dev/mkdocs/skinfra-mkdocs/site/assets/fonts/specimen/FontAwesome.woff2"

However these files exist:

$ ls -l /home/bretif/dev/mkdocs/skinfra-mkdocs/site/assets/fonts/specimen/MaterialIcons-Regular.woff2
-rw-r--r-- 1 bretif psi 44300 sept. 25 11:37 /home/bretif/dev/mkdocs/skinfra-mkdocs/site/assets/fonts/specimen/MaterialIcons-Regular.woff2

$ ls -l /home/bretif/dev/mkdocs/skinfra-mkdocs/site/assets/fonts/specimen/FontAwesome.woff2                                      
-rw-r--r-- 1 bretif psi 77160 sept. 25 11:37 /home/bretif/dev/mkdocs/skinfra-mkdocs/site/assets/fonts/specimen/FontAwesome.woff2

Do you have any clue of what is wrong with my setup.

Regards
Bertrand

Feature: Titlepage & TOC support

Hi there,

Would it be possible to generate a single PDF file, with a title page & TOC based on the site. Similar to the ReadTheDocs PDF automatic generation.

I believe this would curretly be possible if the entire documentation was a single page?
It seems it could be as simple as combining the generated PDF's and generating a TOC page?

Unrecognised configuration name: plugins

Dear developers,

I installed you plugin using pip3 as suggested. While serving mkdocs I am getting the following:

WARNING - Config value: 'plugins'. Warning: Unrecognised configuration name: plugins

Could you guide me to make your plugin work?
Thanks,
Martin

Images do not scale based on attributes

Hello,

I'm trying to scale images I place in index.md, but the width and height attributes seem to be ignored when exporting to a PDF.

I used <img src="img/pic.png" height=50%> and the html displays the scaled image, but the PDF only displays the non-scaled version of the image. Is there another way of scaling images that will be reflected in the pdf?

@page :first does not work in combined mode

Hi,

I would like to style my first page differently. Unfortunately, the css declaration in a @page :first pseudo element affect every page.

I guess it's an issue related to #36 .

Could you do something about it ?

Error with pull request "Fix compatibility with mkdocs-1.0"

I build my source with docker image python:3.6-alpine3.7

docker run -it --rm python:3.6-alpine3.7 /bin/sh
apk add --update --no-cache alpine-sdk python3-dev zlib-dev libffi-dev jpeg-dev tiff-dev freetype cairo-dev pango-dev giflib-dev && \
pip install mkdocs-material && \
pip install git+https://github.com/shauser/mkdocs-pdf-export-plugin.git
git clone <my source url>
mkdocs build

I catched some err:

File "/usr/local/lib/python3.6/site-packages/mkdocs_pdf_export_plugin/plugin.py", line 68, in on_post_page
    print('Error converting {} to PDF: {}'.format(page.input_path, e), file=sys.stderr)
AttributeError: 'Page' object has no attribute 'input_path'

Then I tried fix it with cmd

sed -i 's/page.input_path/page.file.src_path/g' /usr/local/lib/python3.6/site-packages/mkdocs_pdf_export_plugin/plugin.py

And I still catched new error

Error converting index.md to PDF: cannot use string() on <cdata 'unsigned char *' NULL>

Error with new MkDocs 1.0, initial Fix.

Hi i have troubles with new MkDocs 1.0, the error was:

...
result = method(item, **kwargs)
File "/usr/lib/python3.6/site-packages/mkdocs_pdf_export_plugin/plugin.py", line 54, in on_post_page
path = os.path.dirname(page.abs_output_path)
AttributeError: 'Page' object has no attribute 'abs_output_path'

I fixed this lines 'mkdocs_pdf_export_plugin/plugin.py':

53
54 #path = os.path.dirname(page.abs_output_path)
55 path = os.path.dirname(page.file.abs_dest_path)
56 os.makedirs(path, exist_ok=True)
57
58 #filename = os.path.splitext(os.path.basename(page.input_path))[0]
59 filename = os.path.splitext(os.path.basename(page.file.src_path))[0]
60
61 base_url = urls.path2url(os.path.join(path, filename))

Then run ok, but not display PDF to download on html build. Thanks in advance.

Error while building

Hello I'm tryin to build my docs and export some pdf with your plugin but got this error :

 docs master ✗ mkdocs serve    
INFO    -  Building documentation... 
/usr/local/lib/python3.5/dist-packages/weasyprint/document.py:35: UserWarning: There are known rendering problems and missing features with cairo < 1.15.4. WeasyPrint may work with older versions, but please read the note about the needed cairo version on the "Install" page of the documentation before 
reporting bugs. http://weasyprint.readthedocs.io/en/latest/install.html
  'There are known rendering problems and missing features with '
INFO    -  Cleaning site directory 
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/censored/.local/lib/python3.5/site-packages/mkdocs/__main__.py", line 194, in <module>
    cli()
  File "/home/censored/.local/lib/python3.5/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/censored/.local/lib/python3.5/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/censored/.local/lib/python3.5/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/censored/.local/lib/python3.5/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/censored/.local/lib/python3.5/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/censored/.local/lib/python3.5/site-packages/mkdocs/__main__.py", line 127, in serve_command
    livereload=livereload
  File "/home/censored/.local/lib/python3.5/site-packages/mkdocs/commands/serve.py", line 117, in serve
    config = builder()
  File "/home/censored/.local/lib/python3.5/site-packages/mkdocs/commands/serve.py", line 112, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "/home/censored/.local/lib/python3.5/site-packages/mkdocs/commands/build.py", line 282, in build
    build_pages(config, dirty=dirty)
  File "/home/censored/.local/lib/python3.5/site-packages/mkdocs/commands/build.py", line 216, in build_pages
    site_navigation = config['plugins'].run_event('nav', site_navigation, config=config)
  File "/home/censored/.local/lib/python3.5/site-packages/mkdocs/plugins.py", line 94, in run_event
    result = method(item, **kwargs)
TypeError: on_nav() missing 1 required positional argument: 'files'
  • configuration:
docs master ✗ sudo pip3 show mkdocs
Name: mkdocs
Version: 1.0.4
Summary: Project documentation with Markdown.
Home-page: https://www.mkdocs.org
Author: Tom Christie
Author-email: [email protected]
License: BSD
Location: /usr/local/lib/python3.5/dist-packages
Requires: tornado, PyYAML, Markdown, livereload, click, Jinja2
λ  docs master ✗ sudo pip3 --version
sudo pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)
λ  docs master ✗ sudo python --version
Python 3.5.3
λ  docs master ✗ sudo pip3 --version
sudo pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)
λ  docs master ✗ sudo python --version
Python 3.5.3

I tried to follow the readme, and recommandations... it's only workin on my gitlab CI on alpine, but I need to launch it on my debian WSL image to dev.

Thanks you in advance for your help

Can't Install using pip

Im trying to install this plugin following instructions but pip launch an error:

$ sudo pip install -vvvv mkdocs-pdf-export-plugin
The directory '/home/foobar/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/foobar/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting mkdocs-pdf-export-plugin
  1 location(s) to search for versions of mkdocs-pdf-export-plugin:
  * https://pypi.python.org/simple/mkdocs-pdf-export-plugin/
  Getting page https://pypi.python.org/simple/mkdocs-pdf-export-plugin/
  Looking up "https://pypi.python.org/simple/mkdocs-pdf-export-plugin/" in the cache
  No cache entry available
  Starting new HTTPS connection (1): pypi.python.org
  https://pypi.python.org:443 "GET /simple/mkdocs-pdf-export-plugin/ HTTP/1.1" 301 122
  Updating cache with response from "https://pypi.python.org/simple/mkdocs-pdf-export-plugin/"
  Caching permanant redirect
  Looking up "https://pypi.org/simple/mkdocs-pdf-export-plugin/" in the cache
  No cache entry available
  Starting new HTTPS connection (1): pypi.org
  https://pypi.org:443 "GET /simple/mkdocs-pdf-export-plugin/ HTTP/1.1" 404 13
  Status code 404 not in [200, 203, 300, 301]
  Could not fetch URL https://pypi.python.org/simple/mkdocs-pdf-export-plugin/: 404 Client Error: Not Found for url: https://pypi.org/simple/mkdocs-pdf-export-plugin/ - skipping
  Could not find a version that satisfies the requirement mkdocs-pdf-export-plugin (from versions: )
Cleaning up...
No matching distribution found for mkdocs-pdf-export-plugin
Exception information:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 342, in run
    requirement_set.prepare_files(finder)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 554, in _prepare_file
    require_hashes
  File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 278, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 514, in find_requirement
    'No matching distribution found for %s' % req
DistributionNotFound: No matching distribution found for mkdocs-pdf-export-plugin

External Markdown Links are pointing to physical location of HTML

I'm currently using 0.5.0 and I'm having an issue with the PDF generation of a pretty large documentation base. We are using a lot of internal links between our documentation pages and sections and we're seeing something new in our PDF generated file (We are almost certain that this works, at some point...).

When using a link like the following in our documentation [Topic](topic.md), this works nicely in our website but produces a link to the physical generated file (file:///Users/vsts/agent/2.144.0/work/1/s/site/topic/). It does that in our CI/CD environment and does it also in all our local builds.

Anything we should change to make sure the links are clickable through the PDF document?

Thanks!

Can I add logo ?

Hello ! I want add a logo on my pdf doc.

Is-it possible ?

I'm trying this

@page { size: a4 portrait; margin: 25mm 10mm 25mm 10mm; counter-increment: page; font-family: "Raleway",sans-serif; white-space: pre; color: #0C3463; font-weight: bold; @top-left { background-image: url("op-rate-logo.png"); } @bottom-right { content: 'Page ' counter(page); } }

Page links in combined PDF leads to HTML

In the combined PDF, clicking a link to another page of the docs leads to the HTML, which is quite confusing. In the combined PDF the links should lead to the page within the PDF document.

feat: Ability to modify HTML before PDF generation

It would be great if there was a function in the theme handler in which I could modify the HTML before it's converted to PDF, for example to add a title page.

(At the moment, I tried to add a title page by combining the output with a pre-made PDF for the title page using Ghostscript, but the problem is that Ghostscript ruins all the named destinations links, so internal links won't work. Would be better if I could just insert some HTML for the title page and style it with CSS)

Image resizing in pdf generated

Hi, I am trying to export the documentation build using mkdocs - material theme. It has been working smoothly so far. The problem arises when I try to take export in pdf. Every time I do
ENABLE_PDF_EXPORT=1 mkdocs build
I get the error that

Traceback (most recent call last):
  File "/python/miniconda3/bin/mkdocs", line 10, in <module>
    sys.exit(cli())
  File "/python/miniconda3/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/python/miniconda3/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/python/miniconda3/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/python/miniconda3/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/python/miniconda3/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/python/miniconda3/lib/python3.7/site-packages/mkdocs/__main__.py", line 163, in build_command
    ), dirty=not clean)
  File "/python/miniconda3/lib/python3.7/site-packages/mkdocs/commands/build.py", line 298, in build
    config['plugins'].run_event('post_build', config)
  File "/python/miniconda3/lib/python3.7/site-packages/mkdocs/plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "/python/miniconda3/lib/python3.7/site-packages/mkpdfs_mkdocs/mkpdfs.py", line 64, in on_post_build
    self.generator.write()
  File "/python/miniconda3/lib/python3.7/site-packages/mkpdfs_mkdocs/generator.py", line 60, in write
    font_config=font_config)
  File "/python/miniconda3/lib/python3.7/site-packages/weasyprint/__init__.py", line 212, in write_pdf
    target, zoom, attachments)
  File "/python/miniconda3/lib/python3.7/site-packages/weasyprint/document.py", line 696, in write_pdf
    with open(target, 'wb') as fd:
FileNotFoundError: [Errno 2] No such file or directory: '/python/html/data/www/website/mkdocs-project/site/pdf/combined.pdf'

Further, there is some pdf generated but the images are too large. Is there a way to scale image via custom CSS? I have already tried to reseize images using

tags but in pdf generation, it does not reflect.

Any help will be much appreciated. Thanks!

Settings:
mkdocs version -1.0.4
mkdocs-pdf-export-plugin - 0.5.5
python - 3.7.3

mkdocs build with -pdf-export throws errors

Tested on both macOs and windows. Any thought on how to fix? Thx in advance

  1. Python 3.7.1

  2. site_name: My Docs
    theme:
    name: 'material'
    plugins:

    • search
    • pdf-export
  3. Errror:LMHQUCIS245764:system-modernization-BOK erchasin$ mkdocs build
    Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.7/bin/mkdocs", line 11, in
    sys.exit(cli())
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 764, in call
    return self.main(*args, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkdocs/main.py", line 163, in build_command
    ), dirty=not clean)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkdocs/commands/build.py", line 240, in build
    config = config['plugins'].run_event('config', config)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkdocs/plugins.py", line 94, in run_event
    result = method(item, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkdocs_pdf_export_plugin/plugin.py", line 43, in on_config
    from .renderer import Renderer
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mkdocs_pdf_export_plugin/renderer.py", line 4, in
    from weasyprint import HTML, Document
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/weasyprint/init.py", line 393, in
    from .css import preprocess_stylesheet # noqa
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/weasyprint/css/init.py", line 25, in
    from . import computed_values
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/weasyprint/css/computed_values.py", line 17, in
    from .. import text
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/weasyprint/text.py", line 14, in
    import cairocffi as cairo
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cairocffi/init.py", line 41, in
    cairo = dlopen(ffi, 'cairo', 'cairo-2', 'cairo-gobject-2')
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cairocffi/init.py", line 38, in dlopen
    raise OSError("dlopen() failed to load a library: %s" % ' / '.join(names))
    OSError: dlopen() failed to load a library: cairo / cairo-2 / cairo-gobject-2
    LMHQUCIS245764:system-modernization-BOK erchasin$

Allow selection of specific files to be exported

Hi, thanks for your great job!

It would be great to have the chance to select specific files to be exported.

Selection could be based on regular expressions, a specific folders, or even in a session variable.

Material theme admonition icons do not render correctly

When generating PDFs from material-theme style docs with admonition blocks, the material icons do not get rendered correctly. It seems like something goes wrong when adding the font to the pdf.

Example:

image

Looks like

image

Log output:

ERROR: Failed to load font at "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.eot#iefix&v=4.7.0"
ERROR: Failed to load font at "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0"
ERROR: Failed to load font at "file:///tmp/tmpw6mo9adz/assets/fonts/specimen/MaterialIcons-Regular.woff2"
ERROR: Failed to load font at "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.eot#iefix&v=4.7.0"
ERROR: Failed to load font at "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0"
ERROR: Failed to load font at "file:///tmp/tmpw6mo9adz/assets/fonts/specimen/MaterialIcons-Regular.woff2"
ERROR: Failed to load font at "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.eot#iefix&v=4.7.0"
ERROR: Failed to load font at "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0"
ERROR: Failed to load font at "file:///tmp/tmpw6mo9adz/assets/fonts/specimen/MaterialIcons-Regular.woff2"
ERROR: Failed to load font at "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.eot#iefix&v=4.7.0"
ERROR: Failed to load font at "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0"
ERROR: Failed to load font at "file:///tmp/tmpw6mo9adz/assets/fonts/specimen/MaterialIcons-Regular.woff2"
ERROR: Failed to load font at "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.eot#iefix&v=4.7.0"
ERROR: Failed to load font at "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0"
ERROR: Failed to load font at "file:///tmp/tmpw6mo9adz/assets/fonts/specimen/MaterialIcons-Regular.woff2"
ERROR: Failed to load font at "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.eot#iefix&v=4.7.0"
ERROR: Failed to load font at "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0"
ERROR: Failed to load font at "file:///tmp/tmpw6mo9adz/assets/fonts/specimen/MaterialIcons-Regular.woff2"
ERROR: Failed to load font at "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.eot#iefix&v=4.7.0"
ERROR: Failed to load font at "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0"
...

Error when using combined option

Everything works fine when seen individually, but combined I miss certain pages without error. I moved one of those missing pages to be the first one in nav list and then it errored with AttributeError: 'NoneType' object has no attribute 'copy'

/usr/lib/python3.6/site-packages/weasyprint/document.py:34: UserWarning: There are known rendering problems and missing features with cairo < 1.15.4. WeasyPrint may work with older versions, but please read the note about the needed cairo version on the "Install" page of the documentation before reporting bugs. http://weasyprint.readthedocs.io/en/latest/install.html
  'There are known rendering problems and missing features with '
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: /docs/source/site
ERROR: Failed to load font at "file:///docs/source/site/assets/fonts/specimen/MaterialIcons-Regular.woff2"
Error converting demo.md to PDF: Invalid ID found in demo/, ID: fnref:short
ERROR: Failed to load font at "file:///docs/source/site/assets/fonts/specimen/MaterialIcons-Regular.woff2"
Combined PDF export is enabled
":" and "/" characters are banned! /:
Traceback (most recent call last):
  File "/usr/bin/mkdocs", line 10, in <module>
    sys.exit(cli())
  File "/usr/lib/python3.6/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3.6/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/mkdocs/__main__.py", line 163, in build_command
    ), dirty=not clean)
  File "/usr/lib/python3.6/site-packages/mkdocs/commands/build.py", line 298, in build
    config['plugins'].run_event('post_build', config)
  File "/usr/lib/python3.6/site-packages/mkdocs/plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "/usr/lib/python3.6/site-packages/mkdocs_pdf_export_plugin/plugin.py", line 113, in on_post_build
    self.renderer.write_combined_pdf(abs_pdf_path)
  File "/usr/lib/python3.6/site-packages/mkdocs_pdf_export_plugin/renderer.py", line 49, in write_combined_pdf
    self.pages[0].copy(pages).write_pdf(output_path)
AttributeError: 'NoneType' object has no attribute 'copy'
ERROR: 1

Full code is here: https://github.com/majkinetor/mm-docs (page demo.md)

mkdocs build fails with "full_load() takes 1 positional argument but 2 were given" error

Now that I've installed the plugin and enabled it in the mkdocs.yml file, mkdocs build no longer works.

The error being returned is:
TypeError: full_load() takes 1 positional argument but 2 were given

I'm running Python 3.7 on a Windows 10 system (x64, but 32 bit Python). Any suggestions on how I can work around this?

Thanks, Matt

mkdocs build

Traceback (most recent call last):
  File "c:\program files (x86)\python37-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\program files (x86)\python37-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\program files (x86)\python37-32\scripts\mkdocs.exe\__main__.py", line 9, in <module>
  File "c:\program files (x86)\python37-32\lib\site-packages\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "c:\program files (x86)\python37-32\lib\site-packages\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "c:\program files (x86)\python37-32\lib\site-packages\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\program files (x86)\python37-32\lib\site-packages\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\program files (x86)\python37-32\lib\site-packages\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\program files (x86)\python37-32\lib\site-packages\mkdocs\__main__.py", line 162, in build_command
    site_dir=site_dir
  File "c:\program files (x86)\python37-32\lib\site-packages\mkdocs\config\base.py", line 193, in load_config
    cfg.load_file(config_file)
  File "c:\program files (x86)\python37-32\lib\site-packages\mkdocs\config\base.py", line 134, in load_file
    return self.load_dict(utils.yaml_load(config_file))
  File "c:\program files (x86)\python37-32\lib\site-packages\mkdocs\utils\__init__.py", line 78, in yaml_load
    return yaml.full_load(source, Loader)
TypeError: full_load() takes 1 positional argument but 2 were given

Page number restarts

When combined option is set to true and page number is printed somewhere, page number restarts from 1 on every first page of a topic.

For example, if I have chapter_one.md file generating 3 pages and, next in navigation order, chapter_two.md generating 2 pages, printed page number will be:

PDF page:Printed page number:
11
22
33
41
52

Image size behavior different in PDF vs HTML

This may be more of a Weasyprint/CSS issue, but:

image_sizes

Note how the images in the HTML (left) are not scaled up to fit the page width, but in the PDF (right) they are.

It seems the behavior in the HTML is: Scale down pictures if they are too large for the page width (but never scale up).

While the behavior in the PDF output is: Always scale the picture to fit the page width.

Is it possible to get the PDF to have the same behavior as in the HTML?

CSS for output hardcoded in theme_name.py

Looking at the theme files, it looks like the CSS is hardcoded in there and there is no way to override it.

As most of the mkdocs CSS usually resides in ~/css/ it would be nice to be able to drop a CSS file in there and have it pick it up.

ie ~/css/mkdocs-pdf-material.css or something.

Links in combined PDFs are still broken

Running mkdocs-pdf-export-plugin 0.5.3, relative links between pages are still pointing to local file locations:

image

It looks like this was fixed in #28 but may have regressed since then. I've tested this in my existing projects and in a clean test project (as shown in the screenshot above, relative links are all pointing to file:///C:... locations. The links work properly in rendered HTML.

During the build, the same error gets thrown four times (the test project has only 3 pages), which seems like the same thing experienced in #42:

ERROR: No anchor #/.:pdf-export-test for internal URI reference
ERROR: No anchor #/.:pdf-export-test for internal URI reference
ERROR: No anchor #/.:pdf-export-test for internal URI reference
ERROR: No anchor #/.:pdf-export-test for internal URI reference

There is no file called pdf-export-test in the test project, but that is the H1 on the index.md page.

I'd be happy to provide the test project if it would be helpful. I could take a stab at a PR but I'm still learning my way around the code (and know nothing about WeasyPrint, unfortunately).

And lastly, this project is a lifesaver! Thank you so much for your work and active support. It is greatly appreciated.

Long tables get truncated when not fitting on a page

Say you have a chapter called "Chapter about Tables", and you generate a table in it that's longer than the page. The table gets pushed to a new page, causing "Chapter about Tables" to be on it's own page with a lot of whitespace.

The table if longer than a page should continue on a new page, instead it's cut off at the bottom part of the page.

(Rename long-table.txt to .md)
long-table.txt

When combined, resulting PDF is not in correct page order

I have a project that uses sub-folders under the docs folder to organize the markdown files. Could this be throwing off the order of the pages in the resulting PDF? I would expect the PDF to be consistent with the ordering in the mkdocs.yml "nav" entry.

Also when using the custom "@page" stylesheet, the page numbers seem to start over. Perhaps this is also due to the sub-folders being used?

Combined PDF generation fails with `CAIRO_STATUS_NO_MEMORY`

Building single files with combined: false works. Building with combined: true and using more than a handful of pages causes a crash:

Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/mkdocs/__main__.py", line 163, in build_command
    ), dirty=not clean)
  File "/usr/local/lib/python3.5/dist-packages/mkdocs/commands/build.py", line 298, in build
    config['plugins'].run_event('post_build', config)
  File "/usr/local/lib/python3.5/dist-packages/mkdocs/plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/mkdocs_pdf_export_plugin/plugin.py", line 104, in on_post_build
    self.renderer.write_combined_pdf(abs_pdf_path)
  File "/usr/local/lib/python3.5/dist-packages/mkdocs_pdf_export_plugin/renderer.py", line 41, in write_combined_pdf
    self.combined_doc.write_pdf(output_path)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/document.py", line 617, in write_pdf
    surface.finish()
  File "/usr/local/lib/python3.5/dist-packages/cairocffi/surfaces.py", line 630, in finish
    self._check_status()
  File "/usr/local/lib/python3.5/dist-packages/cairocffi/surfaces.py", line 160, in _check_status
    _check_status(cairo.cairo_surface_status(self._pointer))
  File "/usr/local/lib/python3.5/dist-packages/cairocffi/__init__.py", line 79, in _check_status
    raise exception(message, status)
MemoryError: ("cairo returned CAIRO_STATUS_NO_MEMORY: b'out of memory'", 1)

Indenting

Hi,

Thank you for making this great tool! I am running into an issue that the indenting from my md file is not rendering properly in the pdf version. The indents render properly in my md file. Any thoughts are much appreciated!

Thank you!

When using combined PDF, the page number are restarted for every article

We love the new page order as it respects nicely our nav structure, but we're seeing issues with the current page numbers. Page numbers are restarting for every section as it's probably considered to be multiple documents and page numbers are defined per document.

Anything we can do to do the opposite, where if I have 201 pages, I should see Page 1 of 201, 2 of 201, etc...?

Thanks!

List index out of range error when using 'combined' option

Using version 0.5.5 of the plugin I get the following error when using the combined option:

Traceback (most recent call last):
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/bin/mkdocs", line 10, in <module>
    sys.exit(cli())
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs/__main__.py", line 163, in build_command
    ), dirty=not clean)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs/commands/build.py", line 298, in build
    config['plugins'].run_event('post_build', config)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs/plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs_pdf_export_plugin/plugin.py", line 119, in on_post_build
    self.renderer.write_combined_pdf(abs_pdf_path)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs_pdf_export_plugin/renderer.py", line 55, in write_combined_pdf
    render = self.render_doc(p[0], p[1], p[2])
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs_pdf_export_plugin/renderer.py", line 37, in render_doc
    soup = prep_combined(soup, base_url, rel_url)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs_pdf_export_plugin/preprocessor/prep.py", line 16, in get_combined
    a['href'] = transform_href(a['href'], rel_url)
  File "/Users/dcp/.local/share/virtualenvs/myproject-SYVCW_pe/lib/python3.7/site-packages/mkdocs_pdf_export_plugin/preprocessor/links/transform.py", line 17, in transform_href
    id = str.split(ext, '#')[1]
IndexError: list index out of range

Missing support for metadata

When used with markdown-include, the generated page includes metadata as plain text; example:

main.md:

{!page1.md!}
{!page2.md!}

page1.md:

Something

page2.md

---
title: My title
---

Some text

Then the output main.pdf contains the page2.md metadata as plain text.

Failed loading extension

mkdocs 1.0.4, Arch Linux and Windows

plugins:
- search
- pdf-export

Aborted with 1 Configuration Errors!

ERROR - Config value: 'markdown_extensions'. Error: Failed loading extension "search".

Remove "search", result is:
ERROR - Config value: 'markdown_extensions'. Error: Failed loading extension "pdf-export".

Site package is installed as 'mkdocs_pdf_export_plugin'.

Change yaml to 'mkdocs_pdf_export_plugin':

ERROR - Config value: 'markdown_extensions'. Error: Failed to initiate extension 'mkdocs_pdf_export_plugin': module 'mkdocs_pdf_export_plugin' has no attribute 'makeExtension'

Installation Issue!

I installed the plugin using pip install mkdocs-pdf-export-plugin
Python 3.7.2

ERROR   -  Config value: 'plugins'. Error: The "pdf-export" plugin is not installed

Aborted with 1 Configuration Errors!

Thank you

Both single and combined PDF

It would be great to have an option to build both for obvious reason - people may need full docs offline or just particular page.

Currently, you must choose what you want or call a build two times with changing env var in between.

TOC with Material theme

Im not sure how to add a TOC to my PDF. I am using mkdocs-material theme but it appears that the TOC ( .md-nav ) does not show as it is outside of the .md-content__inner block. Is there a way to add this to the PDF export?

Add table of content in combined mode

This is a feature request I think, but I wish I could add the table of content as first page inside combined mode. Is it planned ? An option could be associated with this feature, toc: true.

Issue in installing

pip install mkdocs-pdf-export-plugin

Collecting mkdocs-pdf-export-plugin
  Could not find a version that satisfies the requirement mkdocs-pdf-export-plugin (from versions: )
No matching distribution found for mkdocs-pdf-export-plugin

PDF relative links seem to be broken

Hi,

I have the following mkdocs structure :

nav:  
  - Accueil: index.md 
  - Users stories:
    - Communiqué de presse:
      - Consulter les communiqués: cp/show.md
  - Glossaire: glossaire.md

In cp/show.md file, I have the following content :

En tant que [Charge de communication](../glossaire.md#charge-de-communication)

It seems to follow what is stated in the mkdocs documentation about links

When I launch mkdocs I get the following error :

ERROR: No anchor #cp/show/:charge-de-communication for internal URI reference

Do you know what is happening ?

Thanks in advance

Absolute internal links fail to load

An absolute link to -for example- an image in your markdown document will fail to load due to the following reason I posted here:

Kozea/WeasyPrint#740

A custom url fetcher could help, but as I write myself in the above issue I can't say I like the solution.

Another solution might be modify all absolute links using beautiful soup before passing it to weasyprint.

Error converting doc to PDF: tuple index out of range

Hello,

I am using mkdocs with material theme.
I follow documentation and I think install everything as needed.
python -m weasyprint http://weasyprint.org weasyprint.pdf is working properly

$ mkdocs --version
mkdocs, version 1.0.4 from /home/bretif/dev/mkdocs/skinfra-mkdocs/py3/lib/python3.5/site-packages/mkdocs (Python 3.5)

If I try to build my site but I get this error

Error converting SI/Deployer un nouveau serveur.md to PDF: tuple index out of range

Here is an extract with verbose activated mkdocs-pdf-export-issue15.txt

I get this error on all my documents

Regards
Bertrand

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.