正如您在我的代码中看到的那样;我只是想创建一个4英寸宽,3英寸高的PDF文档。
// create new PDF document
$pagelayout = array(3, 4); // or array($height, $width)
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, 'in', $pagelayout, true, 'UTF-8', false);
然而,当我这样做时,我的PDF呈现重复页面(完整代码如下):
我想要实现的目标是:
如何让TCPDF像我上面那样只创建一个4“x 3”图像?
以下是我的TCPDF完整代码:
<?php
// Include the main TCPDF library (search for installation path).
require_once('../library/tcpdf/config/tcpdf_config.php');
require_once('../library/tcpdf/tcpdf.php');
// create new PDF document
$pagelayout = array(3, 4); // or array($height, $width)
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, 'in', $pagelayout, true, 'UTF-8', false);
/*
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 001');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
*/
// set default header data
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();
// 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('../library/tcpdf/examples/lang/eng.php')) {
require_once('../library/tcpdf/examples/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set default font subsetting mode
$pdf->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('dejavusans', '', 14, '', true);
// set text shadow effect
$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
// Set some content to print
$html = <<<EOD
<p>test</p>
EOD;
// Print text using writeHTMLCell()
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
// ---------------------------------------------------------
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$pdf->Output('example_001.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+
答案 0 :(得分:2)
事实上,这就是答案:
$width = $pdf->pixelsToUnits(400);
$height = $pdf->pixelsToUnits(300);
$resolution= array($width, $height);
$pdf->AddPage('L', $resolution);