How to start creating pdf with the mpdf library?

0

Hello everyone I tried to create files with this library and I could not appreciate your help.

<?php

    require_once('mpdf/mpdf/vendor/autoload.php');

    $mpdf = new mPDF();



    $mpdf->WriteHTML('<p>Your first taste of creating PDF from HTML</p>');

    $mpdf->Output();

    exit;

Download the library here: link and upload my files directly to my host.

    
asked by Daniel Treviño 22.08.2017 в 23:12
source

2 answers

0

I think you need to declare the function of adding a new page

$mpdf = new mPDF('utf-8', 'A4-L');
$mpdf-> Addpage('L');
$mpdf->SetFont('Arial', 'B', '16');
    
answered by 23.08.2017 в 02:46
0

First of all, you should download the library of here and host it on your server, I recommend you save all the files in a folder Call mpdf .

Once installed, you can test its operation with the following code.

<?php
include_once("mpdf/mpdf.php");
$mpdf = new mPDF('R','A4', 11,'Arial');
$mpdf -> SetTitle('Ejemplo de generación de PDF');
$mpdf -> WriteHTML('<body>');
$mpdf -> WriteHTML('Aquí puedes poner todas las etiquetas HTML que mpdf te permite utilizar.');
$mpdf -> WriteHTML('</body>');
$mpdf -> Output('NombreDeTuArchivo.pdf', 'I');
exit;
?>

I explain roughly, you include the library through its main file with include_once , you create a new PDF with the function new mPDF there you can assign the type of paper to use and the source, the function SetTitle(); allows you to change the title of the document that is seen in the browser, everything else is simple HTML, the last function Output(); allows you to assign the default name with which the user can save the file if desired. As you are new to the library, I recommend using only HTML tags to format your pdf, which you can add in the WriteHTML(); function.

If it is installed correctly, the result will be the following:

To make a more elaborate design you can use tables within the WriteHTML(); functions, you know, with the <table> tags and all that. I show you an example of how you can make a clean design through HTML tags and tables.

    
answered by 31.08.2017 в 03:30