python pdfkit: increase font size
Asked Answered
R

3

6

I transformed an HTML file into a pdf simply by:

pdfkit.from_file("cpp.html",'cpp.pdf')

Problem is that the font-size is very small.

How to increase the font-size (both of headers and paragraphs) using pdfkit? Obviously I want the headers font to remain bigger than the paragraphs font.

I guess I have to tweak the options, but I can't find how.

Reprimand answered 24/1, 2016 at 17:9 Comment(3)
Did you try what the doc page suggests; passing options? There is a header-font-size parameter you could pass.Colonialism
@Colonialism I'm sorry, but in that page I don't see header-font-size anywhere :/ Anyways, what's the unit of measure I have to use? Because I've tried px and em but they don't workReprimand
Well, I don't know the library. I only go with what I can see from 30 seconds of looking at the doc page. The page I referred to says: "You can specify all wkhtmltopdf options," at which point it links you to the page for the underlying library. From there, it says font size is default 12. There is also a fair chance that mileage may vary, depending on which platform you are on.Colonialism
T
9

In my case manually setting dpi helped.

options = {
    'dpi':96,
}
pdfkit.from_url(url,out_file,options=options)
Theophany answered 3/1, 2017 at 22:52 Comment(0)
T
2

There's also a zoom option, which solved the problem for me. (Takes a Float)

    options = {
    'zoom': 2,
}
pdfkit.from_url(url,out_file,options=options)
Tracheitis answered 1/5, 2020 at 9:6 Comment(0)
M
0

I tried both, zoom and dpi, but the one that worked best for me is

options = {
    'minimum-font-size': "20",
}

or whichever value

additionally you can pass any of these parameters from wkhtml as options to pdfkit - https://wkhtmltopdf.org/usage/wkhtmltopdf.txt

Milepost answered 4/12, 2020 at 19:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.