How to change height and width manually pdf using html2pdf in php

I use html2pdf to convert html to pdf ... actually I have a large html container size like 12x12in (inches). and I first used the A4 format, then my html content did not show completely up to the size (12x12 inches), after which I looked at your site and I found all the paper sizes here. Thanks for this important information ... but now that I used the A3 size that I found, my entire html content is inside the pdf file ... but there is so much space in the bottom of my pdf content ... Therefore I want to know ... Is there a way to reduce this space from PDF or in any other way to convert html to pdf with manually set page height and width ...

Thanks at Advance.

0
source share
2 answers

The constructor of the HTML2PDF class says that the $format parameter is the same as in the tcpdf class. The tcpdf class constructor talks about the $format parameter:

@param mixed $format The format used for pages. It can be either one of the following values ​​(case insensitive), or a custom format in the form of a two-element array containing the width and height (expressed in units specified by the unit) ...

With a few calculations, this allows you to set the page size to 12 '' x 12 ''. The default unit is millimeters.

+3
source

Here is a solution to this problem:

$ html2pdf = new HTML2PDF ('P', array ($ width_in_mm, $ height_in_mm), 'en', true, 'UTF-8', array (0, 0, 0, 0));

Width and height should be in MM. If your used inches convert it to MM.

Formula: $ width_in_mm = $ width_in_inches * 25.4; $ height_in_mm = $ height_in_inches * 25.4;

Do not round it. The exact conversion is used, even if it has a decimal point.

Hope this answer solves your problem.

+2
source

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


All Articles