The content of this article or any related information is under the Creative Commons license BY, you can republish this content freely but you must mention the author of this article: Kernel and indicate the URL of this page: https://www.exabyteinformatica.com/tienda/foro/how-to-convert-html-file-to-pdf-with-dompdf-library-t1368.html
Download at: https://github.com/dompdf/dompdf
On every occasion we work on massive Hypertext Preprocessor application, then we generally require to generate PDF of invoice, facts, tips, subscription and so forth. if you use any personal home page framework like laravel, codeigniter and so on then you have choice to other kit for generate HTML file into PDF. But if you are working on Code php then you definately fetch problem to the way to do it. But in this tutorial i am going to provide you with very simple illustration to html to pdf convert using DomPDF library.
DomPDF library via we are able to comfortably render html layout into PDF file. DomPDF library through us will use write exterior stylesheets, inline style tags, font measurement, font color etc. DomPDF will aid to do personalize PDF file. Dompdf library is purchasable on composer kit so when you are working with composer then additionally that you can use it.
So, today I am going to share with you example of a way to generate PDF file from HTML layout using DomPDF library, if you do not know a way to implement it then no fret as a result of i am doing from scratch and you can also free down load whole script code from right here.
During this example i will be able to do main three issues like as bellow:
1) Setup dompdf library
2) index.Hypertext Preprocessor file
3) pdf_generate.Hypertext Preprocessor file
Ok, so that you have to just following bellow step and you'll get source code of html to pdf the use of php dompdf library. So let's follow bellow step.
Step 1: Setting up & setup
In first step we have to down load one library and two dependency of dompdf so observe bellow things.
1) Dompdf: we have to download dompdf library from GitHub, So first let's down load from right here: click on right here to download dompdf. After down load extract it to your root folder and rename it to "dompdf".
2) php-font-lib: good enough, now download Hypertext Preprocessor-font-lib from GitHub, So first let's download from right here: click on right here to download php-font-lib. After download extract it to "dompdf/lib/" folder and rename it to "personal home page-font-lib".
3) php-svg-lib: ultimate download personal home page-svg-lib from GitHub, So first let's down load from here: click on here to down load Hypertext Preprocessor-svg-lib. After download extract it to "dompdf/lib/" folder and rename it to "php-svg-lib".
Step 2: Create index.personal home page file
During this step i am going to create index.personal home page file to your root listing, during this file i created effortlessly form the use of bootstrap, this manner you need to just suppose this form and click to "Generate PDF" button. you will without difficulty download pdf with stuffed particulars.
So, let's create index.php file and put bellow code on it.
Código: Seleccionar todo
<title>personal home page - Convert HTML to PDF the usage of DomPDF Library</title>
<hyperlink rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/three.3.7/css/bootstrap.min.css">
<h2>information kind For Generate PDF</h2>
<kind action="pdf_generate.Hypertext Preprocessor" components="put up">
<enter classification="text" name="name" class="kind-control" placeholder="Enter identify" required>
<enter classification="e-mail" name="email" category="form-handle" placeholder="Enter electronic mail" required>
<input category="url" identify="url" category="form-control" placeholder="Enter URL" required>
<textarea name="say" classification="form-handle" placeholder="Say whatever">
<button category="btn btn-success">Generate PDF</button></div>
Step 3: Create pdf_generate.php file
In final step we are able to create "pdf_generate.Hypertext Preprocessor" file, in this file i will be able to get put up records and generate pdf file for download. So, let's create "pdf_generate.personal home page" file and put bellow code on it.
Código: Seleccionar todo
<?personal home page/* include autoloader */require_once 'dompdf/autoload.inc.personal home page';
/* reference the Dompdf namespace */use Dompdf\Dompdf;
/* instantiate and use the dompdf type */$dompdf = new Dompdf();
$html = '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/three.three.7/css/bootstrap.min.css">
<h1>Welcome to ItSolutionStuff.com</h1>
<table classification="desk table-bordered">
<th colspan="2">tips kind</th>
<th>Say some thing</th><td>'.nl2br($_POST['say']).'</td></tr></desk>';
/* Render the HTML as PDF */$dompdf->render();
/* Output the generated PDF to Browser */$dompdf->circulation();?>
Good enough, now you are ready to use and determine it. In case you want to down load supply code script then that you can down load it.
I’m hoping might be it might aid you...
No te pierdas el tema anterior: Curso completo GRATIS de seguridad en PHP
Salta al siguiente tema: Styling HTML with PHP
Quizás también te interese: