this post was submitted on 10 Jul 2023
4 points (100.0% liked)

Web Development

3437 readers
3 users here now

Welcome to the web development community! This is a place to post, discuss, get help about, etc. anything related to web development

What is web development?

Web development is the process of creating websites or web applications

Rules/Guidelines

Related Communities

Wormhole

Some webdev blogsNot sure what to post in here? Want some web development related things to read?

Heres a couple blogs that have web development related content

CreditsIcon base by Delapouite under CC BY 3.0 with modifications to add a gradient

founded 1 year ago
MODERATORS
 

TLDR; Does anyone know if there's an initiative to use the pdf rendering engines built into most browsers and used while printing a web page in more flexible ways? Ideally from javascript being able to get the pdf as a File.

I've been looking into download as pdf functionality we implemented at work. It's for a single project, relatively small, so we implemented it with html2pdf.js. There seems to be no better way than rendering the webpage as canvas and saving as an image inside PDF. Although I'm thankful that the project exists, with the lack of text selection, poor image quality and/or large file sizes, it feels bad serving it to the customer. Then I started to look into the printed version and I loved it. Learned some new stuff about css, being able to break a page before a specific element. Tables automatically repeat their header across a page break. I can also save this as pdf, better quality, 40x reduction in file size, yay! However, web api to start this is print(), no arguments, no alternatives. Putting this behind a "Download" buttons seems confusing for the end user. I'm amazed we can't use this built in pdf rendering engine in more flexible ways. (See TLDR for question)

top 2 comments
sorted by: hot top controversial new old
[โ€“] Xgamer4@programming.dev 3 points 1 year ago (1 children)

At a prior company I worked at, they had the requirement to allow pretty sophisticated and seamless "download report as pdf" functionality. So exactly what you're asking about, more or less.

The solution they came to was to have the "Print to PDF" button call an endpoint that launched a headless chrome instance that printed the page, and to have a pile of print media css rules. It worked... Far better than it really should have.

[โ€“] take6056@feddit.nl 1 points 1 year ago

Yeah, I fear we might have to go for something like that in the long run as well. Feels bad when the browser is capable enough to handle it but is just missing the interfaces.