Kozea/WeasyPrint — pull request #177 by cleitner (2014-03-30 14:30:10+00:00)
Title: Added support for PDF attachments.

This commit adds support for PDF (global) attachments, which can be used from the command line tool with the `-a` option, the `HTML` constructor and `` elements.

The attachment's data is compressed and a MD5 checksum included in the object stream. The implementation avoids seeking in the PDF stream and copies the data directly without reading the whole resource into memory.

I have tested the feature to work with evince and Adobe Reader 9 on Linux.

Things that need testing include
* python2 support
* correct documentation (I'm not used to Sphinx)
* more readers

TODOs:
* I couldn't figure out a way to construct file names for `data:` URLs. Unfortunately `data-` attributes are reserved for document authors and `` has no other suitable attribute. This is of course an obscure use case.
* It may suffice to use the basename of the path component for hierarchical URLs like `http:` and `file:`. If the filename can be deduced from the URL, the attachment tuples could be simplified to `(url, description)`. This should probably be changed.
* There might be a better way to pass the `url_fetcher` to the PDF writer.
* The checksum feature couldn't be tested because either the implementation is wrong and both readers ignore the entry or they just ignore invalid MD5 sums altogether (which renders this feature kind of useless).
* It would be great to also support `` and `` elements. This would require some bookkeeping and special handling inside the post fixup of links, but shouldn't be too hard to do. I'll probably take a shot at it if this feature is accepted.
* The command line option doesn't support a description. Probably not worth the effort.
* The command line currently only works with file names, not URLs. This would be fixed with the second TODO.