Duration 19:17

Generate a PDF with PHP

42 813 watched
0
914
Published 7 Jun 2022

Learn how to generate a PDF file using PHP. PDF files are useful because the formatting is always reliable - its contents will always display in exactly the same way no matter where you are viewing it. Full PHP course: ➤ https://davehollingworth.net/phpy Please consider supporting my channel: ☕ https://ko-fi.com/davehollingworth In this video you'll learn how to: • use the Dompdf library to generate a PDF file • make the browser download the file or open it inline • add styling to the PDF content • insert images • insert user-supplied, dynamic content • use inline, embedded and external CSS for styling • save the generated PDF file locally Also learn how to easily fix the common Dompdf problem when inserting images: "Image not found or type unknown". Code shown in the video: ‣ https://gist.github.com/daveh/88ff8c5e2f99f0a11e9c7ef8e16c3888 Dompdf package: ‣ https://github.com/dompdf/dompdf Sample image: ‣ https://en.wikipedia.org/wiki/Service_mark Thumbnail icon: ‣ https://www.flaticon.com/free-icons/pdf CSS: ‣ https://watercss.kognise.dev/https://github.com/BafS/Gutenberg 00:00 Introduction 00:35 Install Dompdf 01:02 Basic PDF generation 02:49 Change PDF filename 03:25 Display PDF inline 04:21 Styling and layout 05:23 Images 06:14 Setting options 1 06:47 Setting options 2 07:36 Setting page options 08:16 Document metadata 09:08 Create the form 10:11 Classless CSS 10:42 Dynamic data 11:55 HTML template 16:19 Using CSS 17:52 Enable remote resources 18:13 Save PDFs locally 18:59 Summary #PHP #PDF

Category

Show more

Comments - 111
  • @
    @dave-hollingworth2 years ago What other techniques would you like to see a video on? 13
  • @
    @alnahian20032 years ago Not gonna lie, you are the most nicest php instructor i' ve ever met in my life!
    your building rest api, mvc framework in php tuts are still . ...Expand 19
  • @
    @yacoubasawadogo82259 months ago Undoubtedly the best php instructor, making the trickiest php concepts feel as easy as abc when you explain them. 1
  • @
    @collenzaligway44582 years ago Nice video, comprehensible and straight to the point. Please upload more. You really help a lot of junior developer. Cheers. 8
  • @
    @OnyeStephenlast year Please make a tutoprial series on php object oriented programming, i really love the way you explain things. 3
  • @
    @abanwaraphael15262 years ago Thank you dave. You' re very knowledgeable on php. 2
  • @
    @ilyamur8852 years ago Dave, we are still waiting your new frameworks courses.
    you are awesome teacher!
    4
  • @
    @inamrasluzd65242 years ago I wish i can create a million more accounts just to give you the like! You are too awesome, dave. You' re my favourite teacher.
  • @
    @someutubchannel692 years ago Dave,
    your a master of masters.
    2
  • @
    @AliRianiDeO2 years ago Mpdf, emailing a pdf, logging into db, a more complex invoice with a twig/blade template and multiple elements, etc. But at the end of the day you are the best, as always thanks.
  • @
    @gensys2442 years ago Great a clear and easy to understand video thank you so much. Would love to see a more complex form with lots of boxes and lines and shading. 2
  • @
    @codeclassroom2 years ago Hi! You always give us better understanding. Thanks for this video. 1
  • @
    @efbolton34292 years ago Excellent as always! Txs also 4 introducing water & gutenburg css!
  • @
    @giorgiobarone97842 years ago Thank you dave, another great apportation! As always.
  • @
    @mmcool8 months ago Idont get thoes lines, even if i copypase your hole code. I also downloaded gutenberg and linked it localy and no change.
    just wondering why.
  • @
    @batchrocketproject472011 months ago Thanks, really useful and well explained. I' ll be experimenting with this as my case use was not covered. I' d like to batch convert several html . ...Expand
  • @
    @srdjanstankovic4098last year Hi dave, i would like to see spinner on input site while downloading pdf. Spinner should prevent user to input values into fields while downloading.
  • @
    @secret_one2 years ago Nicely done dave.
    i loaded using composer, but it is using an older version as i have to use add_info instead of addinfo.
    i thought that composer gets the latest version?
    1
  • @
    @BaadAsSlast year Hi dave, this is a very intuitive video and is helping me understand a lot more things about generating a pdf, i do have one question though. All of my regards,
    mark
    .
    ...Expand
  • @
    @laughandlivemixedcontentzo3962 years ago Liked you video i am learning at very short time. 1
  • @
    @spifferlasting8 months ago Very good video! One question: how to install dompdf without composer? Very few of the projects i work on use composer or git. Zero. Thanks in advance.
  • @
    @NedumEzelast year Thank you very much, dave.
    just wondering whether you could consider doing another version of this tutorial, showing how clicking a pdf link in a web page can download a pdf version of the html web page.
  • @
    @windows-rdp47365 months ago Hello mate, thanks for this amazing tutorial my question is why after i downloaded the php library via zip im unable to locate autoload file its not included . ...Expand
  • @
    @mahmoudalhussain22912 years ago Thanks for this video, does this library support arabic language and accented letters? And can i use composer autoloader for tcpdf library, am not using any framework would be that a problem?
  • @
    @TheGarageboyzlast year Great video! Thanks! Is it possible to lock and save the pdfs to my server?
  • @
    @HAMOSHE7 months ago Nice video, i have no experience in php so i downloaded the source code and ran it on a php server, it just doesn' t work for some reason when i put . ...Expand
  • @
    @PaulRijke2 years ago Hi dave nice. Why choose dompdf instead of mpdf for example? 1
  • @
    @NedumEze2 years ago Amazing! I have been seeking something like dompdf that will, when a user clicks a button on a web page, will convert the page to pdf and download it to but it seems that dompdf cannot foot the bill.
    since it can convert only html files. Our web pages are mostly. Php files
    .
    ...Expand
    1
  • @
    @rasalas912 years ago Great content as always. I was kinda scared of creating pdfs - the dompdf package seems to make it really easy. Love that it uses html and css - the other thank you!
    - . Do you know any trick toold bad php-code to more readable code?
    i took over code of someone who wasn' t really taught as it seems.
    the whole code consists of:
    < php
    if(isadmin){
    echo" firstname. "
    }else{
    echotraveler! Lt; /h1> "
    }
    ? Gt;
    basically without any real html and indentation is a myth (and no classes and very few imports (obviously no autoload or composer) everything in one file (ok, it' s three, but they' re huge) but that' s another problem)
    i added new stuff - but i' m breaking consistency and since i' m still learning myself, it changes.
    are there any best practices for this? Maybe steps to prevent rewriting the whole thing from the ground up? Should i copy the bad patterns?
    (it' s pretty big - and it' s not 100% clear which pages are still being used regularly)
    .
    ...Expand
  • @
    @marlonrettis5009last year Im getting an error i new options line 12 of your file. Now sure why.
  • @
    @wisdomkalu21302 years ago Wonderful tutorial and easy to follow. I wanted to know how you can work with setchroot( when using the mvc model. In your example, all the files are id="hidden13" in one root directory (vendor) which makes it easy to use __dir__. In my case, my images file and css files are in different directories. How do i set the root so that everything works well?. ...Expand
  • @
    @kikowyntech3442last year Hi sir. Do you have a simple ticketing system atleast running on lan connection only.
  • @
    @shiriajin2 years ago Man, i love your videos and i wish your videos on udemy have the same quality. In udemy, all the steps where you actually add the code are edited out (you . ...Expand
  • @
    @user-up4ld8mt3n5 months ago Error: root packagecannot require itself in its composer. Json what' s the matter pls.
  • @
    @devhenry90542 years ago Can you please make a laravel course like you have made a codeigniter course on udemy. With some real project like blog and admin panel. Thanks. 1
  • @
    @truthteacherslast year Bro, its a great course. I have a problem. At timestamp , the cdn for gutenberg does not seem to work. The pdf is not formatted.
  • @
    @sarabibrahim831211 months ago Can you add a video for downloading pdf file using php myadmin.
  • @
    @craigc58792 years ago Another excellent video. How about a video on something like twig?
  • @
    @samuelsituma8846last year Nice video but how can we use dompdf to print questions that have math equations using mathjax.
  • @
    @petruciucurlast year Excelent tutorial! Is it possible to use dompdf to send the generated pdf in an email?
  • @
    @dragonarc_gaming5 months ago Can i get some help? I was following all the codes written until i reached the image part. The image is not showing at all even after doing the option true)
    but even that doesn' t seem to fix it.
    totally stuck right now
    .
    ...Expand
  • @
    @mahmoudalhussain2291last year How to fill in an existing pdf template, using php? Is there any free libraries for that?
  • @
    @GoodLifeFilms3000last year How would you base64 enocde this pdf without downloading the file first?
  • @
    @ArielClemente-bv2qu10 months ago How could i convert a web page which was created automatically loaded from $_request routine?
  • @
    @ABGTronic_Inc2 years ago What version of php is requirement for this method?
  • @
    @babolokichibane8917last year Hi dave thanks for the video. I am using macos and i get a fatal error warning: failed line 3
    fatal error: require( failed opening required(include_path=#39; /applications/mamp/bin/php/php7. 4. 21/lib/php' inon line 3
    please help
    .
    ...Expand