python package pdfkit: convert HTML to PDF, how to cancel automatic line feed

Viewed 996

I am currently facing a very strange problem when I am applying PDFKIT package to convert an HTML file to the PDF file. The problem is that the HTML contains a table, which inside the table there is a cell named A1191112 1111 12311469 B, shown below.

Cell on html

But when I convert it into pdf, with the following options,

    options = {
    'page-size': 'A1',
    'margin-top': '0.05in',
    'margin-right': '0.05in',
    'margin-bottom': '0.05in',
    'margin-left': '0.05in',
    'encoding': "UTF-8", 
    'custom-header' : [
        ('Accept-Encoding', 'gzip')
    ],
    'cookie': [
        ('cookie-name1', 'cookie-value1'),
        ('cookie-name2', 'cookie-value2'),
    ],
    'no-outline': None
    }

It breaks the term into two lines, see below.

Cell on PDF

I have tried resized the Page-size, but it didn't help at all. If you have any suggestion, it would be appreciated. Thank you.

3 Answers

Try increasing the cell width so that the B that's on the next line will come back up. That might work!

What's about changing the Text size, something like this?

with zoom option:

options = {
    'zoom': 0.9,
}
pdfkit.from_url(url,out_file,options=options)

Or dpi option:

   options = {
        'dpi':110,
    }
    pdfkit.from_url(url,out_file,options=options)

Try adding the CSS below after the table in your html file.

<style>
    table.print-friendly tr td, table.print-friendly tr th {
        page-break-inside: avoid;
    }
</style>

If that doesn't work you can try decreasing the dpi in the options. With the following code (you may have to experiment to get the perfect fit):

options = {
   'dpi': 96,
   # Other options after it
}
Related