Playwright - One long pdf page generation

1 week ago 16
ARTICLE AD BOX

I can't calculate right height for pdf page for it to be one long page without page breaks. In result there a bit of page on second page whatever the lenght of html really is. Different JS methods give the same height and problem most likely not in evaluation.

Also exactly the same problem appears when I use nbconvert webpdf exporter to convert jupyter notebook to pdf without pagination (paginate=False) because webpdf use playwright too: https://github.com/jupyter/nbconvert/blob/216550b2aae4c329f4dab597a96ae7cac30de79a/nbconvert/exporters/webpdf.py#L132C1-L132C17

with sync_playwright() as p: browser = p.chromium.launch() page = browser.new_page() page.goto(f"file://{path.absolute()}", wait_until="networkidle") height = page.evaluate("() => Math.ceil(document.body.getBoundingClientRect().height) + 1") page.pdf( path=".\\"+str(new_path), width="210mm", height=f"{height}px", print_background=True, margin={"top": "0px", "bottom": "0px", "left": "0px", "right": "0px"} ) browser.close()

pdf-example

Read Entire Article