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

Invalid attachments #558

gigelu opened this issue Jan 11, 2018 · 4 comments

Invalid attachments #558

gigelu opened this issue Jan 11, 2018 · 4 comments
bug Existing features not working as expected


Copy link

gigelu commented Jan 11, 2018


I am trying to attach a file to the pdf and when I try to save the attached file I am getting a 0 bytes file.
The code is this:

from io import BytesIO
from weasyprint import HTML

html = HTML(string='test')
with open('/tmp/test.pdf', mode='wb') as out_file:
    html.write_pdf(out_file, attachments=[BytesIO(b'attachment')])

The relevant part in the output is:

3 0 obj
<</Filter /FlateDecode /Length 18 /Params
  <</CheckSum <44290cefe42924d04a92d99428a95f27> /Size 10>> /Type

I don't think that the stream should be a python string (b'...').
Any help in what may be the problem?

Thank you.

Copy link

dnezic commented Jan 17, 2018

I have the same problem, so I downgraded to version WeasyPrint==0.40, where the attachments work, at least using <a rel=attachment ... in HTML.

@liZe liZe added bug Existing features not working as expected regression labels Jan 17, 2018
@liZe liZe added this to the 43 milestone Jan 17, 2018
Copy link

gigelu commented Jan 17, 2018

Confirm, downgrading to 0.40 fixes the issue.

Copy link

archatas commented Jan 21, 2018

I can confirm that with WeasyPrint 0.42 <link rel=attachment href="path-to-some-file" /> creates empty attachments.

@liZe liZe closed this as completed in ce84073 Jan 28, 2018
Copy link

liZe commented Jan 28, 2018

Sorry, my mistake… I've added more tests to catch this, but generating and reading the PDF file with the same library makes a perfect garbage-in-garbage-out problem.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Nov 14, 2018
Version 43

Released on 2018-11-09.

Bug fixes:

* `#726 <>`_:
  Make empty strings clear previous values of named strings
* `#729 <>`_:
  Include tools in packaging

This version also includes the changes from unstable rc1 and rc2 versions
listed below.

Version 43rc2

Released on 2018-11-02.

**This version is experimental, don't use it in production. If you find bugs,
please report them!**

Bug fixes:

* `#706 <>`_:
  Fix text-indent at the beginning of a page
* `#687 <>`_:
  Allow query strings in file:// URIs
* `#720 <>`_:
  Optimize minimum size calculation of long inline elements
* `#717 <>`_:
  Display <details> tags as blocks
* `#691 <>`_:
  Don't recalculate max content widths when distributing extra space for tables
* `#722 <>`_:
  Fix bookmarks and strings set on images
* `#723 <>`_:
  Warn users when string() is not used in page margin

Version 43rc1

Released on 2018-10-15.

**This version is experimental, don't use it in production. If you find bugs,
please report them!**


* Python 3.4+ is now needed, Python 2.x is not supported anymore
* Cairo 1.15.4+ is now needed, but 1.10+ should work with missing features
  (such as links, outlines and metadata)
* Pdfrw is not needed anymore

New features:

* `Beautiful website <>`_
* `#579 <>`_:
  Initial support of flexbox
* `#592 <>`_:
  Support @font-face on Windows
* `#306 <>`_:
  Add a timeout parameter to the URL fetcher functions
* `#594 <>`_:
  Split tests using modern pytest features
* `#599 <>`_:
  Make tests pass on Windows
* `#604 <>`_:
  Handle target counters and target texts
* `#631 <>`_:
  Enable counter-increment and counter-reset in page context
* `#622 <>`_:
  Allow pathlib.Path objects for HTML, CSS and Attachment classes
* `#674 <>`_:
  Add extensive installation instructions for Windows

Bug fixes:

* `#558 <>`_:
  Fix attachments
* `#565 <>`_,
  `#596 <>`_,
  `#539 <>`_:
  Fix many PDF rendering, printing and compatibility problems
* `#614 <>`_:
  Avoid crashes and endless loops caused by a Pango bug
* `#662 <>`_:
  Fix warnings and errors when generating documentation
* `#666 <>`_,
  `#685 <>`_:
  Fix many table layout rendering problems
* `#680 <>`_:
  Don't crash when there's no font available
* `#662 <>`_:
  Fix support of some align values in tables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
bug Existing features not working as expected
None yet

No branches or pull requests

4 participants