I have following tcpdf code:
<?php
require_once('config/lang/eng.php');
require_once('tcpdf.php');
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
public function Header() {
}
// Page footer
public function Footer() {
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Stimart');
$pdf->SetTitle('test');
$pdf->SetSubject('test');
$pdf->SetKeywords('test');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, 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(40, 40, 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
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
$pdf->SetFont('times', '', 12);
// add a page
$pdf->AddPage();
// set some text to print
$html = '<div style="position: absolute; top:200px; left:300px;">Hi, I am an ABSOLUTE div.</div>';
$pdf->writeHTML($html, true, false, false, false, '');
// ---------------------------------------------------------
$pdf->lastPage();
//Close and output PDF document
$pdf->Output('test.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+
after the line "// set some text to print" I set up the html code to show but it doesn't works as expected. In this case I need to pass a div with absolute position but when the code runs it creates the pdf page showing the div in relative position.
How can I solve this annoying problem??
TCPDF has a very limited CSS support. It doesn't support all attributes.
Currently, only the following CSS attributes are supported:
So try removing the other attributes, and tell if it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With