How to Generate PDFs with PHP: New Premium Tutorial
plus

How to Generate PDFs with PHP: New Premium Tutorial

Tutorial Details
  • Premium Exclusive
  • Difficulty: Intermediate
  • Format: Tutorial + Screencast
Share

PDFs may well be the best format for distributing documents on the web. In today’s tutorial and screencast, I’ll show you how you can generated PDFs with PHP. Help give back to Nettuts+ by becoming a Premium member!

Example PDF Created with PHP!

By subscribing and becoming a Premium member, you’ll gain access to the best tutorial, screencasts, and freebies that every Tuts sites has to offer – all for a measly $9 a month.

Join Net Premium

NETTUTS+ Screencasts and Bonus Tutorials

For those unfamiliar, the family of TUTS sites runs a premium membership service. For $9 per month, you gain access to exclusive premium tutorials, screencasts, and freebies from Nettuts+, Psdtuts+, Aetuts+, Audiotuts+, and Vectortuts+! For the price of a pizza, you’ll learn from some of the best minds in the business. Help give back to Nettuts+ by becoming a Premium member!

Related Posts

Add Comment

Discussion 43 Comments

  1. Rohan Mehta says:

    Awesome!! I’ve been waiting for something like this!

  2. Eric says:

    Great Job Andrew this was a wonderful tutorial, eh?

    I grew up in Michigan watching CBC as a kid so it is nice to hear the great canuck accent.

  3. dave says:

    Thanks for tutorial!

    I want to make a note about margin usage. While you do provide a parameter to allow changing the margin amount, you do not compensate for the parameter and effectively hard code your margins.

  4. Arnaud says:

    I’m wondering to get a premium account for this tutorial…May I ask you which way you generate the PDF ? (FPDF,…)
    Thanks a lot !

  5. Nice! I really love tuts like this one!

    Thanks!

  6. Jeff Adams says:

    Okay, so I cancelled my membership about 3-4 months back – nothing to do with the site, more that I had zero time to spend checking out the tuts.

    This is one tut I have been really wanting for so long, I’m going to joiin back this weekend lol

  7. Is this using a library like http://www.fpdf.org/ or is it totally from scratch?

  8. Francesc says:

    lol…. esto es un tutorial premium? si existen un montón de soluciones gratis en la web. En que se diferencia?

    • Braden Keith says:

      Not all the tutorials on the web would cover it from scratch though. They assume a lot of knowledge. It also helps to get it from another person’s perspective with different wording. People following along several tutorials of the same format may not understand until he says something a particular way, and it all clicks.

  9. Chris says:

    Looks awsome, will try it out later.

    Anyway of generating a random code that could be used within the invoice as a Ticket number?

    I was looking for a simple payment system that would allow users to buy a eTicket then once the payment has gone through they get sent a PDF which they can print out and use as a ticket/invoice

  10. Davidmoreen says:

    I was flipping though my php reference book the other day, and I noticed that there were a lot of functions for pdf actions.

    Great tutorial to start off learning how to dynamically make PDFs.

  11. fatih says:

    i am not a plus member yet so i want to ask:
    is it explained in the video how to fill a predefined pdf form from a database using php??
    thanks.

    • dave says:

      Andrew shows how to use the basics of the fpdf library and so does not talk about loading an existing pdf file and writing to it.

  12. Ryan says:

    Cool! Creating a PDF is kinda hard but a lot of clients like to be able to do it. I think this tutorial could be pretty good!

  13. It is really important to know how to generate .pdf files with PHP, even if Adobe Reader has zero day exploits!

  14. Elias says:

    Thank you, This is just what I was looking for.

  15. Mark says:

    Nice and clearly explained tutorial, but seems a painful process to create a pdf, reminds me of the old ‘green screen’ typesetting days!

  16. VladLozM says:

    I like to use mPDF [http://mpdf.bpm1.com/]

    Greetings!

    :D

  17. Jonathan says:

    A much needed tutorial, thanks for your work in this. I actually had to learn this on my own about 2 weeks ago. I opted to use TCPDF (http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf) instead, which I believe is actually a fork off of FPDF. It just seemed a little more maintained.

    Andrew – a little trouble typing that day? ;)

  18. janM says:

    If you want to add things to an existing pdf-file you need fpdi in combination with fpdf – just look on fpdf.org an then search for “partners” oder “links” or something like that – there you’ll find fpdf.
    I’m using this for a long time – it’s much simpler: you can upload an nice designed pdf-file and just add some details dynamicly via php.

  19. Not so great . . . I had fun with the first part but as soon as you started using functions, classes and objects? you lost me,,,

    • I think I may understand it…. is this how the class thing works?

      http://freddygonzalez.me/dev/pdf/aLittleHelp.lasso

      • Those functions that we’re calling within the constructor could be called anywhere within the class or even after you create an instance of the class. In the PDF_reciept class, I wanted to set the page margins when we created the instance; I’m pretty sure you could use those functions again after creating the instance to change the margins. I’ve set a default value for the margins so that you could leave that value out when creating the instance.

        Hope that helps!

  20. Rick says:

    Great tut! Need this to make dynamic reports from a php system. I was just wondering about the method used in this tut (I’m not a plus member…yet…)

    I’ve been investigating in this and what I learned is that php comes with a (few) inbuild pdf functions which you can activate when you have full control of your hosting envoirment (http://php.net/manual/en/book.pdf.php)… something I don’t have… so I need a library or something I can just install on my hosting. If available, maybe one that is a library for codeigniter?

    Anyway, can somebody let me know if this tut uses an inbuild php function or that it uses a library you can easily install on your hosting (without access to the php settings)? If it’s the last then I need to get myself a plus account! :-)

    Thanks!

  21. Nuj says:

    I want to see the tutorial but I’m not a Member can someone send a copy of it on my email junliwanag@ymail.com

    Thanks

  22. Nuno says:

    I actually mentioned with a friend less than 4 hours ago about something like that. Thanks guys…

  23. andrew says:

    So, is this tut better than available examples at homepage of fpdf or any other found on the net?

  24. Mike says:

    Nice.. This is definitly worth for a new subscription. Thx ;)
    Now, I hope a great XML read and write with PHP will be there soon too ;)

  25. Ibad says:

    I use fpdf and fpdi, it’s more simple :D

  26. I have been looking for a script to generate PDF’s forever. Last straw – I’m going to sign up for premium membership.

  27. Ron says:

    Awesome, this is exactly what I’ve been looking to do. Now I just need to know how to automatically email the generated pdf file as an attachment.

  28. blake says:

    Ohh Shizz, nice tutorial Adam. =)

  29. Deoxys says:

    Nice tutorial, but pleeeaase, practice more on your typing. That’s so nasty ;-)

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.