php - How to convert HTML to PDF using TCPDF? -


how write div (for example, style="postion:absolute; width: 200px; height: 100px; border: solid 1px #000;") , input text it?

make use of writehtml function of tcpdf library.

<?php  require_once('tcpdf_include.php'); $pdf = new tcpdf(pdf_page_orientation, pdf_unit, pdf_page_format, true, 'utf-8', false);  $pdf->setcreator(pdf_creator); $pdf->setauthor('nicola asuni'); $pdf->settitle('tcpdf example 049'); $pdf->setsubject('tcpdf tutorial'); $pdf->setkeywords('tcpdf, pdf, example, test, guide');  $pdf->setheaderdata(pdf_header_logo, pdf_header_logo_width, pdf_header_title.' 049', pdf_header_string);  ]$pdf->setheaderfont(array(pdf_font_name_main, '', pdf_font_size_main)); $pdf->setfooterfont(array(pdf_font_name_data, '', pdf_font_size_data));  $pdf->setdefaultmonospacedfont(pdf_font_monospaced);  $pdf->setmargins(pdf_margin_left, pdf_margin_top, pdf_margin_right); $pdf->setheadermargin(pdf_margin_header); $pdf->setfootermargin(pdf_margin_footer);  $pdf->setautopagebreak(true, pdf_margin_bottom);  $pdf->setimagescale(pdf_image_scale_ratio);  if (@file_exists(dirname(__file__).'/lang/eng.php')) {     require_once(dirname(__file__).'/lang/eng.php');     $pdf->setlanguagearray($l); } $pdf->setfont('helvetica', '', 10);  $pdf->addpage();   $html = '<h1>test tcpdf methods in html</h1> <h2 style="color:red;">important:</h2> <span style="color:red;">if using user-generated content, tcpdf tag can unsafe.<br /> can disable tag setting false <b>k_tcpdf_calls_in_html</b> constant on tcpdf configuration file.</span> <h2>write1dbarcode method in html</h2>';  $params = tcpdf_static::serializetcpdftagparameters(array('code 39', 'c39', '', '', 80, 30, 0.4, array('position'=>'s', 'border'=>true, 'padding'=>4, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>4), 'n')); $html .= '<tcpdf method="write1dbarcode" params="'.$params.'" />';  $params = tcpdf_static::serializetcpdftagparameters(array('code 128', 'c128', '', '', 80, 30, 0.4, array('position'=>'s', 'border'=>true, 'padding'=>4, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>4), 'n')); $html .= '<tcpdf method="write1dbarcode" params="'.$params.'" />';  $html .= '<tcpdf method="addpage" /><h2>graphic functions</h2>';  $params = tcpdf_static::serializetcpdftagparameters(array(0)); $html .= '<tcpdf method="setdrawcolor" params="'.$params.'" />';  $params = tcpdf_static::serializetcpdftagparameters(array(50, 50, 40, 10, 'df', array(), array(0,128,255))); $html .= '<tcpdf method="rect" params="'.$params.'" />'; $pdf->writehtml($html, true, 0, true, 0);  $pdf->lastpage(); $pdf->output('example_049.pdf', 'i');  ?> 

Comments