Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

--print-media-type all images not displayed #5284

Open
Rahabib opened this issue Dec 11, 2022 · 2 comments
Open

--print-media-type all images not displayed #5284

Rahabib opened this issue Dec 11, 2022 · 2 comments

Comments

@Rahabib
Copy link

Rahabib commented Dec 11, 2022

wkhtmltopdf version(s) affected: wkhtmltopdf 0.12.6 (with patched qt)

OS information
OSX 12.6.1

Description
when using @media print styles with the flag --print-media-type, all other css loads etc. but all my images do not display in the pdf. If I remove this flag, the images work again. I use @media print to set chapter breaks to new pages etc.

How to reproduce
wkhtmltopdf --print-media-type --enable-local-file-access compiled.html compiled_wkhtml.pdf - no images
wkhtmltopdf --enable-local-file-access compiled.html compiled_wkhtml.pdf - images but now my chapter breaks are not loaded

css:

@media print {
    h1 {
        page-break-before: always;
    }
    .new-page, .pagebreak, .page-break {
        page-break-before: always;
    }
    blockquote{
        page-break-inside: avoid;
    }
    table {
        page-break-inside: avoid;
    }
    .keep-together {
        page-break-inside: avoid;
    }
    img { /* added as experiment */
        display: block !important;
    }
}

Expected behavior
images should be displayed on pdf

Possible Solution
This looks like a css rendering issue. happy to hack css further if needed.

@Rahabib
Copy link
Author

Rahabib commented Dec 11, 2022

FWIW, I took the same HTML in chrome and "printed" it and it works with images. The only issue with this approach is that it doesn't generate the "bookmarks" and I cannot add additional items like cover images, footers, etc. This is the full "ideal" command I want to use:

wkhtmltopdf --print-media-type --enable-local-file-access --dpi 300 --footer-center "- [page] -" --footer-font-size "8" --footer-spacing "2" cover "cover.html" compiled.html compiled_wkhtml.pdf

@Rahabib
Copy link
Author

Rahabib commented Dec 23, 2022

My workaround for now is to remove --print-media-type and add all of my page-break parameters globally.

/* @media print { */
    h1 {
        page-break-before: always;
    }
    .new-page, .pagebreak, .page-break {
        page-break-before: always;
    }
    blockquote{
        page-break-inside: avoid;
    }
    table {
        page-break-inside: avoid;
    }
    .keep-together {
        page-break-inside: avoid;
    }
/* } */

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

No branches or pull requests

1 participant