Skip to content

Luventas Web Design

A new blog for developers in PHP, Java and mobile Development

  • Home
  • 2011
  • Mai
  • 21
  • PDF creation by PHP

PDF creation by PHP

Posted on 21 Mai 201125 Mai 2011 By luventas 1 Kommentar zu PDF creation by PHP
PHP

I tried a lot to create PDF files by using PHP frameworks. For Java I’m using iText, but there is no interface to use iText by a PHP server. So I googled a lot and there are several frameworks to create these files. I tried them all an my opinion is, that domPDF is the best one, becase it is the easiest of all to use.

To create a PDF by domPDF, I only have to create a normal HTML page. This page I have to give to the renderer of domPDF and this renderer creates a PDF file out of this HTML code which is a one to one copy of the HTML page.

To use the domPDF framework, there are only a few lines of code necessary:

require_once(„dompdf_config.inc.php“);
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$filename =“pdffilename.pdf“;
$pdfoutput = $dompdf->output();
$filenamePath = ‚./path/to/the/savefolder/‘.$filename;
$fp = fopen($filenamePath, „a“);
fwrite($fp, $pdfoutput);
fclose($fp);

This is all. More is not needed. The variable $html is the String which includes the HTML page. It is absolutely necessary, that the HTML code is valid. otherwise the PDF is not rendered correctly.

If you do not want to store the file on server and only stream it to the browser it is already more easier than the code above:

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream(„sample.pdf“);

So have much fun to work with this framework and if you want please comment this post if I was able to help you a little bit. Or maybe click a like button below and post it to your social platform.

Print Friendly, PDF & Email

Beitrags-Navigation

❮ Previous Post: Start of Luventas Web Designs Blog
Next Post: Create Random Password with PHP ❯

You may also like

PHP
Create an Excel document with PHP
3 Juni 2011
Genealogy
Include your family tree in your webpage
28 Mai 2011
Genealogy
Introduction how to use my genealogical scripts
20 Juni 2011
PHP
Upload images by PHP
15 Juni 2011

One thought on “PDF creation by PHP”

  1. hp drivers sagt:
    15 Juni 2011 um 00:07 Uhr

    Very nice post, I surely love this site, keep it up.

    Antworten

Schreibe einen Kommentar Antworten abbrechen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Copyright © 2023 Luventas Web Design.

Theme: Oceanly News by ScriptsTown

Diese Website nutzt Cookies, um bestmögliche Funktionalität bieten zu können. OK, verstanden
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
immer aktiv
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SPEICHERN & AKZEPTIEREN