Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken PDF generation with Weasyprint>57 #144

Open
adelosa opened this issue May 22, 2023 · 1 comment
Open

Broken PDF generation with Weasyprint>57 #144

adelosa opened this issue May 22, 2023 · 1 comment

Comments

@adelosa
Copy link

adelosa commented May 22, 2023

Python 3.11
requirements.txt and installed versions

mkdocs                      1.4.3
mkdocs-awesome-pages-plugin 2.9.1
mkdocs-macros-plugin        0.7.0
mkdocs-material             7.3.6
mkdocs-material-extensions  1.1.1
mkdocs-with-pdf             0.9.3
weasyprint                  59.0

Receiving the following error when generating PDF:

INFO     -  Rendering for PDF.
INFO     -  Output a PDF to "my.pdf".
...
Traceback (most recent call last):
  File "/env/lib64/python3.11/site-packages/mkdocs/__main__.py", line 250, in build_command
    build.build(cfg, dirty=not clean)
  File "/env/lib64/python3.11/site-packages/mkdocs/commands/build.py", line 332, in build
    config.plugins.run_event('post_build', config=config)
  File "/env/lib64/python3.11/site-packages/mkdocs/plugins.py", line 522, in run_event
    result = method(**kwargs)
             ^^^^^^^^^^^^^^^^
  File "/env/lib64/python3.11/site-packages/mkdocs_with_pdf/plugin.py", line 135, in on_post_build
    self.generator.on_post_build(config, self.config['output_path'])
  File "/env/lib64/python3.11/site-packages/mkdocs_with_pdf/generator.py", line 157, in on_post_build
    render.write_pdf(abs_pdf_path)
  File "/env/lib64/python3.11/site-packages/weasyprint/document.py", line 399, in write_pdf
    pdf = generate_pdf(self, target, zoom, **options)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/env/lib64/python3.11/site-packages/weasyprint/pdf/__init__.py", line 261, in generate_pdf
    pdf_fonts = build_fonts_dictionary(
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/env/lib64/python3.11/site-packages/weasyprint/pdf/fonts.py", line 47, in build_fonts_dictionary
    for letter, key in font.ttfont.getBestCmap().items():
                       ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'getBestCmap'

Same run using weasyprint 58.1

INFO     -  Rendering for PDF.
INFO     -  Output a PDF to "my.pdf".
Traceback (most recent call last):
...
  File "/env/lib64/python3.11/site-packages/mkdocs/__main__.py", line 250, in build_command
    build.build(cfg, dirty=not clean)
  File "/env/lib64/python3.11/site-packages/mkdocs/commands/build.py", line 332, in build
    config.plugins.run_event('post_build', config=config)
  File "/env/lib64/python3.11/site-packages/mkdocs/plugins.py", line 522, in run_event
    result = method(**kwargs)
             ^^^^^^^^^^^^^^^^
  File "/env/lib64/python3.11/site-packages/mkdocs_with_pdf/plugin.py", line 135, in on_post_build
    self.generator.on_post_build(config, self.config['output_path'])
  File "/env/lib64/python3.11/site-packages/mkdocs_with_pdf/generator.py", line 157, in on_post_build
    render.write_pdf(abs_pdf_path)
  File "/env/lib64/python3.11/site-packages/weasyprint/document.py", line 360, in write_pdf
    pdf = generate_pdf(
          ^^^^^^^^^^^^^
  File "/env/lib64/python3.11/site-packages/weasyprint/pdf/__init__.py", line 256, in generate_pdf
    pdf_fonts = build_fonts_dictionary(pdf, document.fonts, optimize_size)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/env/lib64/python3.11/site-packages/weasyprint/pdf/fonts.py", line 50, in build_fonts_dictionary
    ratio = 1024 / font.ttfont['head'].unitsPerEm
                   ~~~~~~~~~~~^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

If you revert your weasyprint to latest 57 (57.2) then the generation works.
Here in case others want a quick fix.

@avihaySunny
Copy link

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants