1 year ago

#358390

test-img

ashby

Python webpage output as pdf cut off some values

I need some advice

I wantto save a webpage one time per day from PassMark. This page contains a CPU performance with table form. I wrote a simple python script to reach this goal, but I have a little problem with the wkhtmltopdf and the pdfkit. The output file has a problem with displaying values, for example, the first digits are cut off and not are displaying in the file.

Here is my code

import pdfkit, requests

url = "https://www.cpubenchmark.net/high_end_cpus.html"

options = {
    'page-size': 'A4',
    'viewport-size': '1920x1080',
    'background': True,
    'javascript-delay': 1500,
    'enable-local-file-access': True,
    'print-media-type': True,
    'disable-smart-shrinking': True,
    'custom-header': [
        ("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36")
    ],
    'custom-header-propagation': True,
}

pdfkit.from_url(url, "file.pdf", options=options)

Maybe should I use another tool?

python

wkhtmltopdf

0 Answers

Your Answer

Accepted video resources