Scale HTML proportionally accurately for PDF A4

I am using PHP, Mysql, jQuery. I have a webpage that needs to be converted to A4 with high resolution PDF: http://optisolbusiness.com/funeral_site/sample/index/id/255 .

I converted HTML to PDF using wkhtmltopdf , which works great.

Here is the generated PDF http://optisolbusiness.com/Guru/Gurupdf/optisol.pdf . But HTML doesn't exactly fit the size of the PDF; PDF has spaces around HTML. How to scale HTML to fit A4 PDF 100%? It is important that the content inside the text size (i.e.), the Width and height of the images, background images also scale proportionally.

+6
source share
3 answers

Your background image does not match high resolutions; it will not look great in print. A.

I do not know wkhtmltopdf itself, but your body already has absolute dimensions (in inches). This is probably a problem. Your body has a maximum size, the content also has an absolute size (due to the pixel sizes of the background image).

This is not a good starting point for html-to-print conversions, and PDF is essentially printable.

what to do (intermediate)

  • remove size limits from the body
  • wkhtml ... has a switch called zoom , 1.5 should be a suitable value to fill the page
  • use page size a4

what to do (the "right" way)

  • remove size limits from the body
  • create background borders (black) with html elements and css style
    • refrain from defining rules for "width" for them. You will only need to determine the "width" once, all other widths should be set to "auto". Height
    • will prove difficult, as divs reach a level sufficient for their content. But installation height: 100% does not take into account the size of borders and fields.
  • that the yellow cross can also be designed in css or in higher resolution png / jpeg
  • Use only "real" sizes. This means that you are not using pixels, use dots, inches or mm. You can use% values, but make sure that they are% of real size values ​​(this means that at some point the parent element has a real size)
+7
source

I would say that you will always fight to make it perfect. In my opinion, you are better off writing PDF directly, rather than relying on a third-party tool.

Take a look at FPDF , the open source PHP PDF email library. Be careful, the site looks outdated, but the functionality works great.

+2
source

You can set the body size to page size .. in the case of A4, which is 210x297 mm.

Btw: you should use width only in percent, otherwise wkhtmltopdf will have to try and convert it.

So make sure you use width: 100%; if you want him to fill the whole room .;)

BTW: If you need real high-quality PDF files, you will need to create them at least in PDF / X-3 format . I do not think wkhtmltopdf does this.

0
source

Source: https://habr.com/ru/post/927554/


All Articles