TCPDF 页面大小更改是创建多个页面,而我只想要一个页面

use*_*388 1 php pdf pdf-generation tcpdf

正如你在我的代码中看到的;我只是想创建一个 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);
Run Code Online (Sandbox Code Playgroud)

但是,当我这样做时,我的 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
//============================================================+
Run Code Online (Sandbox Code Playgroud)

use*_*388 6

事实上,这就是答案:

$width = $pdf->pixelsToUnits(400); 
$height = $pdf->pixelsToUnits(300);

$resolution= array($width, $height);
$pdf->AddPage('L', $resolution);
Run Code Online (Sandbox Code Playgroud)

参考号 TCPDF Qr 代码在小尺寸页面上调整大小