Create PDF PDF A3, A4 and A5

I am looking for creating PDF files to output various types of documents, A3, A4, A5, using PHP.

I currently have a div that has various divs in this area that are absolutely located.

What I want to do is to have this size a fixed height width, but when I save the contents, it can be used for print sizes A4, A3 and A5.

What is the best way to achieve this?

thanks

EDIT:

Am I also trying to add a full width background image for each type?

In addition, to create each document, you need to have a specific height / width?

I would like to have an 'area' where I can view the HTML document. So, if I choose A3, it will save the PDF as A3, with the full width of the background image and all the divs being positioned in the right places.

0
source share
4 answers

use MPDF

mPDF is a PHP class that generates PDF files from UTF-8 encoded HTML code. It is based on FPDF and HTML2FPDF , with a number of improvements.

I wrote mPDF to output PDF files on the fly from my site, processing different languages. This is slower than the source scripts, for example. HTML2FPDF also creates large files when using Unicode fonts, but support for CSS styles, etc. Significantly improved - see features .

Please view examples and feel free to download it. There is a fairly extensive online reference guide for mPDF.

Here is a list of arguments that you can pass to the default constructor.

$mpdf = new mPDF('', // mode - default '' '', // format - A4, for example, default '' 0, // font size - default 0 '', // default font family 15, // margin_left 15, // margin right 16, // margin top 16, // margin bottom 9, // margin header 9, // margin footer 'L'); // L - landscape, P - portrait 
+2
source

A good way to do this is the FPDF class and its extension TFPDF , which support UTF8.

Fpdf Homepage

Tfpdf script

I used it sometimes and it works great.

-one
source

You can use the API, for example, from htm2pdf.co.uk

-one
source

Try using wkhtmltopdf from Google, I think it works with WebKit, so it has huge html compatibility and also has an option for specific page size output, including A4, A3, etc. or a specific user size, the problem is that it is an executable application, which means that you need to run it on Linux / Windows and in some cases for the archive, which you need to ask the hosting provider to give you permission to run for this application

another option http://pdfcrowd.com/html-to-pdf-api/ , is an API that allows you to create PDF files, and also has great compatibility with HTML, Paid service, I think they have a free account but you have a very limited amount of pdf you can create

i highly recommend wkhtmltopdf, html conversion is almost perfect and free

-one
source

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


All Articles