Thinkphp Export PDF documents using Tcpdf ____php

Source: Internet
Author: User
Requirements Description

In the actual project requirements, the data needs to be exported as documents

Version Description

thinkpphp 3.2.3

tcpdf6.2.12 ()

Integration Steps

Place the Tcpdf folder in the Vender folder of the thinkphp library and introduce tcpdf in the code to export the PDF file (tcpdf examples)
Export PDF Case

Public Function Export_pdf () {Ob_start ();
		Vendor (' Tcpdf.tcpdf_import ', ' Simplewind/core/library/vendor ', '. php ');
                $pdf = new \tcpdf (pdf_page_orientation, Pdf_unit, Pdf_page_format, True, ' UTF-8 ', false);
		Set font $pdf->setfont (' stsongstdlight ', ', ', 12);
		---------------------------------------------------------$title = $_request[' title '];
		Set Document Information $pdf->setcreator (pdf_creator);
		$pdf->setauthor (' Nicola asuni ');
		$pdf->settitle ("$title");
		$pdf->setsubject (' TCPDF Tutorial ');
		$pdf->setkeywords (' TCPDF, PDF, example, Test, Guide ');
		Set Default header data sets the header $pdf->setheaderdata (', ', $truename. ' Document ', $company _name);
		The Set header and footer fonts set the header font $pdf->setheaderfont (' stsongstdlight ', ', Pdf_font_size_main ');
		$pdf->setfooterfont (Array (' stsongstdlight ', ', ', 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);
		}//Set default font subsetting mode $pdf->setfontsubsetting (TRUE);
		Add a page $pdf->addpage (); Cell ($w, $h =0, $txt = ', $border =0, $ln =0, $align = ', $fill =0, $link = ', $stretch =0, $ignore _min_height=false, $calign =
		' T ', $valign = ' M ') $pdf->setcellpaddings (1, 1, 1, 1);
		Set cell Margins $pdf->setcellmargins (1, 1, 1, 1);
		Set color for background $pdf->setfillcolor (255, 255, 127); $txt = ' Lorem ipsum dolor sit amet, consecteturadipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna. '; Multicell test Cell $pdf->multicell (90, 5, "Name: $truename", 0, ' L ', 0, 0, ', ', true);
		
		->ln (8) for line-wrapping $pdf;
		$pdf->setfont (' stsongstdlight ', ' B ', 16);
		Direct output Text
		$pdf->write (5, "Result:", ", 0,", False, 0, false, False, 0);
		the filename $filename = $truename. --". $telephone." PDF ";
		Output PDF
		$pdf->output ("$filename", ' I ');
		Ob_end_flush (); 
	}

The above code is used to display an online preview of the PDF file, can be printed and downloaded operations, very convenient

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.