PHP enables PDF export and print functionality.

Source: Internet
Author: User

Plugin used: TCODF

Export PDF

Public Function export_pdf ($order _sn) {
Require_once (Fcpath. /shared/plugin/tcpdf/tcpdf.php ');

$pdf = new TCPDF (Pdf_page_orientation, "PT", "A4", True, ' UTF-8 ', false);
$pdf->setfootermargin (50);
$pdf->setimagescale (Pdf_image_scale_ratio);
if (@file_exists (Fcpath. /shared/plugin/tcpdf/examples/lang/eng.php ')) {
Require_once (Fcpath. /shared/plugin/tcpdf/examples/lang/eng.php ');
$pdf->setlanguagearray ($l);
}
$pdf->setmargins (20,50,10, true);
$pdf->addpage ();
$pdf->setfont (' stsongstdlight ', ', 12);
$buffer = $this->assign_value ($order _sn);
$startpos = Strpos ($buffer, ' <!--startprint1--> ');
$endpos = Strpos ($buffer, ' <!--endprint1--> ');
$html = substr ($buffer, $startpos, $endpos-$startpos +strlen (' <!--endprint1--> '));
Header ("content-type:text/html; Charset=utf-8 ");
$name = "Customs_declaration";
$export _name = $name. ' _ '. $order _sn;
$pdf->writehtml ($html, True,false,false,false,false);
$pdf->output ($export _name. PDF ', ' d ');
}

Assigns the retrieved page to a value
Public Function Assign_value ($order _sn) {
Ob_start ();
$this->declaration_print ($order _sn);
$buffer = Ob_get_contents ();
Ob_clean ();
return $buffer;
}

With the OB cache, the dynamic page cache is used for export.

JS Print

<script>
Function Preview (oper) {
if (Oper < 10) {
Get_page_info ();
bdhtml=window.document.body.innerhtml;//get the HTML code for the current page
Sprnstr= "<!--startprint" +oper+ "--";//Set Print start area
Eprnstr= "<!--endprint" +oper+ "--";//Set Print End area
Prnhtml=bdhtml.substring (Bdhtml.indexof (SPRNSTR) +18); To take HTML back from the start code

Prnhtml=prnhtml.substring (0,prnhtml.indexof (EPRNSTR));//Fetch HTML from the end code
window.document.body.innerhtml=prnhtml;
Window.print ();
Prnhtml.print ();
window.document.body.innerhtml=bdhtml;
} else {
Window.print ();
}
}
</script>

PHP enables PDF export and print functionality.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.