Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on Playwright script to generate PDF of a page that requires scrolling (Khan Academy)

Post

Playwright script to generate PDF of a page that requires scrolling (Khan Academy)

+1
−0

Currently I am using One Click Page to PDF to get the job done, although the lack of working open-source tools fit for this task has led me to creating my own; the web page "that won't print" is this Khan Academy article.

It seems as though I have 2 options, both involving Playwright:

A. (Somehow) embed text on a page screenshot

  • pros:
    • I can get the whole page all at once without worrying about bits being cut off
  • cons:
    • positioning text layer in the right place is likely going to be a pain
    • splitting one long 'scroll' into PDF pages will be a fiddly process

B. Generate a single-page PDF of what is currently visible, scroll just enough for the next page and repeat, combining all PDFs into one

  • pros:
    • no awkward image-to-PDF-with-text conversion required (pagination and text layer come out of the box)
  • cons:
    • figuring out just how much to scroll won't be trivial (easy to under/overshoot)
    • page header and footer removal is required (otherwise they would be repeated for every page)

Before I embarked in this quest, I was curious to hear opinions from the more experienced!

I will try to code in Javascript as I understand this gives greater flexibility in Playwright, although if I can I would generally find my way easier in Python - how do you think I should tackle this problem aiming for a simple and effective solution?

Web2PDF is likely the closest base I can work from: it runs directly in browser, so as a program it is simpler to work with and more straightforward to debug.

History

1 comment thread

clarifying the problem (2 comments)
clarifying the problem
ggorlen‭ wrote 3 months ago · edited 3 months ago

What problem are you currently having with your existing code/tooling, exactly? What do you mean by "won't print", and what is your actual/expected outcome?

System‭ wrote 3 months ago

Thread renamed from "What problem are you currently having with your existing code/tooling, exactly? What do you mean by "..." to "clarifying the problem" by ggorlen‭