PHP

Convert HTML into PDF using PHP

Convert HTML into PDF using PHP
  • Mohittanwat111

    how to download this file…………….many times i have click download button but it si redirecting to either net love or jabong 

    • After redirected that page,wait 5 seconds and then click “skip ad” button in the top right corner.Then source code would be automatically download.

      • Mohittanwat111

         thanks sumit i have not seen right corner thanks a lot

  • After redirected that page,wait 5 seconds and then click “skip ad” button in the top right corner.Then source code would be automatically download.

  • Rajagonda

    thanks  its working… 

  • Rajagonda Nyalakanti

    thanks 

  • Prasad

    Hi,Its working awesome thanks for sharing the code.

  • Dillibabu K

    Hi, That is working very well. But I tried to convert google chart into pdf. After conversion, i’m getting empty pdf file. So, Will you Please tell me the reason and Solution..?

    Thanks in advance..:-DG)

    • It getting blank page, because of first execute PDF generate process before the generate and display the chart in that page. So you need to check if page is fully loaded or that chart content is fully loaded.Then execute the PDF process.
      Regards…..

  • Sunil Omrey

    not working well??????/plz help

    • This is should be working.First you must check all files exist,paths, config details,…etc.
      Can you send the issues details.

      Regards

  • lokesh

    after skip add This website/URL has been blocked until further notice either pursuant
    to Court orders or on the Directions issued by the Department of
    Telecommunications”

  • Thanks its working.

  • H?nh Phan Ng?c

    How to fit only for one A4 size…

    • Use this code.

      $dompdf->set_paper(“A4”, “portrait”);

      Thanks

      • H?nh Phan Ng?c

        Thanks 🙂

  • hithu

    “Failed to Load pdf document ” this shows the browser when i click the ‘convert’ button…
    i down load your compress file and extract run useing wamp server …!
    plz help me
    thanks

    • Hi,
      If you really do have spaces before your PHP opening tag, they will become part of the PDF file and corrupt it. Load up your “bad” pdf, do a file->save, and opening the file in a text/hex editor (NOT a pdf reader) and see what you’re getting. Any PHP errors/warnings or other output before the actual PDF data will cause the PDF readers to see it as corrupted.

      Thanks

      • Php Dotnet

        hi i m getting the same problem . i just downloaded you file and put it into htdocs folder of xampp . pls help me . i m waiting for ur reply

    • Php Dotnet

      hi i m getting the same problem . i just downloaded you file and put it into htdocs folder of xampp . pls help me

  • suneth

    Hi Sumith,

    I am trying to convert in to pdf which has new line texts. But when i convert it in to pdf all text are in single line. I want the text in same format.

    I am trying this for several hours. please help me to proceed. Thank you.

    • Hi Suneth,
      I updated the post. You can see the working solution at the bottom of the post. Let know is that work or not.

      Thanks

      • Suneth

        Hi Sumith,

        Thank you very mush for the response.

        I changed my code according to your suggestion. But I get following error. And I am using codeigniter for my development.

        Fatal error: Uncaught exception ‘DOMPDF_Exception’ with message
        ‘Frame not found in cellmap’ in
        C:xampphtdocsdurdanslabapplicationthird_partydompdfincludecellmap.cls.php:212
        Stack
        trace:
        #0
        C:xampphtdocsdurdanslabapplicationthird_partydompdfincludetable_cell_renderer.cls.php(51):
        Cellmap->get_spanned_cells(Object(Table_Cell_Frame_Decorator))
        #1
        C:xampphtdocsdurdanslabapplicationthird_partydompdfincluderenderer.cls.php(283):
        Table_Cell_Renderer->render(Object(Table_Cell_Frame_Decorator))
        #2
        C:xampphtdocsdurdanslabapplicationthird_partydompdfincluderenderer.cls.php(117):
        Renderer->_render_frame(‘table-cell’,
        Object(Table_Cell_Frame_Decorator))
        #3
        C:xampphtdocsdurdanslabapplicationthird_partydompdfincluderenderer.cls.php(185):
        Renderer->render(Object(Table_Cell_Frame_Decorator), false)
        #4
        C:xampphtdocsdurdanslabapplicationthird_partydompdfincluderenderer.cls.php(185):
        Renderer->render(Object(Table_Row_Frame_Decorator), false)
        #5 C:xampphtdocsdurdanslabapplicationthird_part in C:xampphtdocsdurdanslabapplicationthird_partydompdfincludecellmap.cls.php on line 212

        • Hi,
          As you did last time undo the changes above. Then put your not worked code back. then change the following lines.
          $dompdf->load_html($_POST[“html”]);

          Replace with,
          $dompdf->load_html(nl2br($_POST[“html”]));

          And add this code before $dompdf->stream(“mypage.pdf”, array(“Attachment” => false));

          $dompdf->output();

          Thanks

          • Suneth

            Hi Sumith,
            below is my changed code according to you. But still give the same error.

            function pdf_create($html, $filename, $stream=TRUE, $orientation=”portrait”)
            {
            require_once APPPATH . ‘third_party/dompdf/dompdf_config.inc.php’;
            $this->load->helper(‘file_helper’);
            $html = stripslashes($html);
            $dompdf = new DOMPDF();
            $dompdf->set_paper(“a4”, $orientation);
            $dompdf->load_html(nl2br($html));
            $dompdf->render();

            if ($stream) {
            $dompdf->stream($filename . “.pdf”);
            } else {
            write_file(“pdf_report/”.$filename.”.pdf”, $dompdf->output());
            }
            exit(0);
            }

          • Try this. Also check correctly added all files paths.

            require_once APPPATH . ‘third_party/dompdf/dompdf_config.inc.php’;

            function pdf_create($html, $filename, $stream=TRUE, $orientation=”portrait”)
            {

            $this->load->helper(‘file_helper’);

            $html = stripslashes($html);
            $dompdf = new DOMPDF();
            $dompdf->load_html(nl2br($html));
            $dompdf->set_paper(“letter”, $orientation); // $size ‘letter’, ‘legal’, ‘A4’, etc , $orientation ‘portrait’ or ‘landscape’
            $dompdf->render();

            $dompdf->stream($filename.”.pdf”, array(“Attachment” => false));
            exit(0);
            }

          • Suneth

            Hi Sumith,

            Your code was working.
            $dompdf->load_html(nl2br($html));

            Thank you very much.

            But the problem is my codeigniter code. Because I load the $html file from several views($this->load-view()). Once I get $html, only from view which generate the is working. But when load other views to $html is not working. I will find out a solution for that issue.

            So thank you again..

          • Glad to hear that. Good luck !

  • subodh

    i have create two form one form name index.php and in that past you program
    ok then dompdf_config,inc.php in that past your code even if inthat one create problem

    Fatal error: Class ‘DOMPDF’ not found in D:AppServwwwpdfdompdf_config.inc.php on line 14

  • Ashu Pandit

    Hello sir,
    How can i convert my whole forms elements into pdf ? in example it is giving value for only a single textarea.

    Thanks