By clicking Download PDF page

Asked

Viewed 890 times

0

Hello.. is the following: I have a page with fields to be filled ( http://www.sustentare.net/cartoes/autoconhecimento/ ). By clicking on a button I would like him to download this page with the fields filled as PDF ( a kind of "print" of the page ).

I tried a solution as you can check on the link, but this solution is only valid for Chrome, where to choose pdf to download. If using firefox or another browser already popcorn everything.

Would anyone have any solution to my case please??

Thank you.

1 answer

0

You can use a class for example this http://sourceforge.net/projects/tcpdf/files/ and export the data you want from the database to a pdf.

Here’s an example how you can use tcpdf to export what you want.

            <?php

            // Include the main TCPDF library (search for installation path).
            require_once('tcpdf_include.php');

            // create new PDF document
            $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

            // set document information
            $pdf->SetCreator(PDF_CREATOR);
            $pdf->SetAuthor('Nicola Asuni');
            $pdf->SetTitle('TCPDF Example 039');
            $pdf->SetSubject('TCPDF Tutorial');
            $pdf->SetKeywords('TCPDF, PDF, example, test, guide');

            // set default header data
            $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 039', PDF_HEADER_STRING);

            // set header and footer fonts
            $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
            $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

            // set default monospaced font
            $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

            // set margins
            $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
            $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
            $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

            // set auto page breaks
            $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

            // set image scale factor
            $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

            // set some language-dependent strings (optional)
            if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
                require_once(dirname(__FILE__).'/lang/eng.php');
                $pdf->setLanguageArray($l);
            }

            // ---------------------------------------------------------

            // add a page
            $pdf->AddPage();

            // set font
            $pdf->SetFont('helvetica', 'B', 20);

            $pdf->Write(0, 'Example of HTML Justification', '', 0, 'L', true, 0, false, false, 0);

            // Aqui vai os teus dados
            $html = '';

            // set core font
            $pdf->SetFont('helvetica', '', 10);

            // output the HTML content
            $pdf->writeHTML($html, true, 0, true, true);

            $pdf->Ln();

            // set UTF-8 Unicode font
            $pdf->SetFont('dejavusans', '', 10);

            // output the HTML content
            $pdf->writeHTML($html, true, 0, true, true);

            // reset pointer to the last page
            $pdf->lastPage();

            // ---------------------------------------------------------

            //Close and output PDF document
            $pdf->Output('example_039.pdf', 'I');
  • Thank you for the reply Caesar, but I do not have a database. Basically what I want is a "print" of the full page with the fields filled for PDF.

  • Ah ok I’ll rephrase the answer with what you need

  • @Maicon Database is just an example of Caesar, you can use with anything tcpdf :) Just read the documentation.

  • @Césarsousa Please edit your reply and add an example of using TCPDF, so you will probably get some votes :)

  • Cool @Césarsousa , I’ll do a test.. Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.