Showing posts with label wkhtmltopdf. Show all posts
Showing posts with label wkhtmltopdf. Show all posts

Wednesday, June 28, 2017

WkHtmlToPdf grey border around images

Leave a Comment

I'm creating a PDF using the Wkhtmltopdf library.

Everything is working fine, except one little detail: I overlap two images with transparent background to another background image.

This is the result:

The background image is the one with the trees and the sky, each character is in a different image with transparent background. So the result is quite perfect except for the grey border around each person.

Is it possible to remove it?

0 Answers

Read More

Wednesday, March 22, 2017

wkhtmltopdf - same configuration different output

Leave a Comment

I'm using wkhtmltopdf through snappy in my project. On my local machine the output is correct: https://www.dropbox.com/s/ml9cp2pa6d8wja5/Zaznaczenie_100.png?dl=0

but when I deploy the project to the server the pdf is looking very different, probably the width of viewport is different: https://www.dropbox.com/s/8g0c29bzaxltyb9/170311_123139_4775.jpg?dl=0

Both systems use exactly the same configuration for generating the pdf.

My questions are:

  • how can I check what is the default configuration of wkhtmltopdf on specific machine?
  • how can I change the viewport size so my output would be exactly the same on different machines?

I set the width and height of output page manually (21 cm and 50 cm respectively). I tried different combinations with DPI parameter, but it seems to have no effect.

I'm using the wkhtmltpdf PHP wrapper - snappy - but I checked and I get the same output in the console, so the problem is wkhtmltopdf-related, not snappy.

2 Answers

Answers 1

One of the main things that appears to be different in your PDF outputs is the font face. wkhtmltopdf requires fonts to be installed on your operating system in the same way a browser would require this. It is possible that differences in the spacing and sizing of fonts are affecting the layout of your page. You should first have a look at what fonts you are trying to use in your source file and install those on your server. A good start is to install Microsoft's core fonts from here, or from your server's distribution's repositories.

An alternative way around this is to use @font-face directives in your source file stylesheets to link to fonts from a URL, without installing them on your server:

@font-face {     font-family: 'Roboto';     font-style: normal;     font-weight: 400;     src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/CWB0XYA8bzo0kSThX0UTuA.woff2) format('woff2');     unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215; } 

In the case of Google's web fonts, you can instead import their stylesheets:

<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" /> 

Another thing to check is the versions of wkhtmltopdf on your workstation and your server. Running wkhtmltopdf --version will tell you your currently installed version. It might be the case that your server is running an outdated version of wkhtmltopdf. The easiest way to install an up to date version of wkhtmltopdf with the features you need is from here, where you can download statically-linked Linux binaries for any distro.

One last thing to try is using different --margin-top, --margin-right, --margin-bottom and --margin-left arguments. There is also a flag called --viewport-size which may help to give better results.

wkhtmltopdf --viewport-size 1024x768 page.html output.pdf 

If you are using the same version of wkhtmltopdf on both your workstation and server, however, these configuration options should not make a difference, as you stated you are using the same configuration on both already.

Answers 2

To back up Candy Gumdrop, we tried the margins, but our answer turned out to be the admin reused a 32-bit copy of wkhtmltopdf on the production server, not the 64-bit version I used. The entire results of "wkhtmltopdf --version" need to match, not just the version number.

Read More

Wednesday, June 22, 2016

Highchart chart chopped on page break

Leave a Comment

I have a simple bar chart with many bars. I take the highcharts result and use wkhtmltopdf to generate a PDF with A4 page size.

The problem is that the page break always chops some results like this (detail of the page break):

enter image description here

How can I avoid it without having to split the data in two or more charts (paginate the chart)?

I thought about setting something like page-break-inside: avoid; to the bar (or even to the svg's rect), but I don't know how to do this in Highcharts.

Any ideas?

0 Answers

Read More

Tuesday, April 19, 2016

WkhtmlToPdf multiple font faces / styles

Leave a Comment

I've read many, many topics about the hassle with multiple font-styles/faces when using wkhtmltopdf.

We are currently experiencing problems when using Nunito (provided by Google webfonts) in regular style and bold style on the same page. We have tried many (possible) solutions, but none of them has given us a solution yet.

We tried the following solutions, but no one succeeded yet:

All the above methods did not work. The browser does render it correctly, but wkhtmltopdf seems to be rendering it different.

We have published a few testcase's on: http://bannes.nl/fonts

If anyone has a suggestion on how to fix this, please let me know. In case you are using mac and have installed wkhtmltopdf, please feel free to test the cases on http://bannes.nl/fonts. I have included the output PDF for every testcase in their directory.

Hope someone has got a suggestion on how to fix this!

Best regards,

Robin

2 Answers

Answers 1

  • Use this similar utility, backed by more developers: https://github.com/plessl/wkpdf
  • if that does not work for you, check that you have the latest version of wkhtmltopdf

If the above does not work at all, you may try a different command line utility, or a robust solution like: "LaTeX": https://www.latex-project.org/

Answers 2

Why not change lib ?

I used wkhtmltopdf but I found the inner peace with TCPDF

I printed an HTML page doing this

// set font $pdf->SetFont('itclegacysansltmedium', '', 12); // add a page $pdf->AddPage();  // set some text to print ob_start(); include('view.php'); $html = ob_get_clean(); $pdf->writeHTML($html, true, false, true, false, ''); 
Read More