eikek / eikek/docspell

Disable CSS `@page` directives when converting to PDF

Open
#2,400 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Elm
Stars
2.3k
Forks
184
Avg merge
8h 2m
Merged PRs (30d)
4

Description

HTML&CSS files can use `@page` directives to instruct the browser to insert breaks between physical pages, place PDF pages on specific formats of physical paper, e.g. A4 or US Letter, and insert header/footer information.

`weasyprint` honours these directives, which makes it a great too for generating PDFs from webpages.

However, in the Docspell context, this can have unwanted side effects. For instance certain versions of Outlook create HTML emails that are bound to physical paper sizes that are dependent on the UI locale of the sender. That's stupid in and of itself, but that's not the end of the problem.

When converting email, Docspell inserts the email header information before the existing HTML body, before passing the resulting concatenation to the PDF converter. If the existing HTML body is enclosed in e.g. `

` referincing an `@page` directive, then this will force `weasyprint` to insert a hard page break after the email header information, which means that in preview mode, the actual email text isn't visible until the 2nd page, and not at all visible in the preview images.

The following is a potential fix. `weasyprint` takes a `--stylesheet` argument and mixes the stylesheet in with the rest. If the `weasyprint` stanza in `docspell-joex.conf` is extended accordingly to pass such a stylesheet, which the contains:

```
* {
page: inherit !important;
}
```

then all `@page` directives are effectively ignored.

Maybe such a stylesheet could be provided by Docspell, possibly even by default, and something added to the documentation about it?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.