question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent image size between pdf and screenshots when viewport-relative sizes are used

See original GitHub issue

I’m trying to correctly render in pdf this slide:

guide_10_1440x900

(snapshot generated by decktape)

Its resulting code is:

<section class="present" style="top: 0px; display: block;">
<h2 id="hi-res-default">Hi res, default</h2>
<img src="4k.jpeg" style="
    
    
    max-width: 95vw;
    max-height: 80vh;
    object-fit: contain;
">
</section>

When rendering in pdf, however, the vw/vh units seem to be broken and relative to something different than the page size, and images get rendered much smaller than they should be.

Here is the generated slide pdf.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
DanySKcommented, Sep 7, 2020

@jonathan-g man you really saved my day. I enabled a double generation of my slides in CI, both via decktape and via chromium headless. They seem to work nicely.

1reaction
jonathan-gcommented, Sep 1, 2020

I don’t know enough about the internals of Chromium to know how to make a good bug report for this.

But the good news is that there’s a workaround: Chrome and Chromium seem to do fine at rendering reveal.js slides to pdf from a terminal command prompt, with none of the problems I see with puppeteer and decktape.

Basically you want to serve your slides to localhost:8000 and then execute (you can play around with whether you want to disable the GPU and how large you want to set the maximum time budget for rendering):

chrome --headless --run-all-compositor-stages-before-draw --disable-gpu --virtual-time-budget=10000 --print-to-pdf=my_slides.pdf http://localhost:8000?print-pdf

And it’s easy enough to wrap this command line in a script to make things less cumbersome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

If PDFs or images aren't the correct size in Preview on Mac
In Preview on your Mac, you can set PDFs and images to be displayed at the same size on all screens, regardless of...
Read more >
Minimizing PDF File Size While Maximizing Graphics
The final size of a PDF file is a function of two primary issues related to graphic images used on each page: 1....
Read more >
2023 Social Media Image Sizes for All Networks [CHEATSHEET]
The most recent image size specifications for different social media networks, including Instagram, Twitter, Facebook, LinkedIn, and more.
Read more >
Understanding PDF File Size - Evermap
It is crucial to understand the actual file size allocation between various PDF ... The image resolution (image dimension in pixels) is also...
Read more >
Xcode: Vector images from PDF bad quality - Stack Overflow
I would set the Preserve Vector Data flag on the asset here: enter image description here. This will make it render as a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found