tcpdf 网站上的这个示例展示了如何使用 A4、A5 等页面格式,但是如何将 tcpdf 设置为使用 175 毫米 x 266 毫米等自定义尺寸?
解决方案赞赏。
不需要编辑类... tcpdf 不接受宽度/长度参数,它只接受两个长度并确定哪个使用布局(纵向或横向)
$pageLayout = array($width, $height); // or array($height, $width)
$pdf = new TCPDF('p', 'pt', $pageLayout, true, 'UTF-8', false);
在较新的 TCPDF 版本上,您可以通过多种方式定义页面大小:
setPageFormat()
上的方法文档中所述。还要检查默认示例编号。28 和 60 在http://www.tcpdf.org。
转到 /config/tcpdf_config.php 并在第 117 行附近,修改该行:
define ('PDF_PAGE_FORMAT', 'A4');
经过
define ('PDF_PAGE_FORMAT', 'LETTER');
将“LETTER”以大写形式输入很重要,您可以在此文件中看到所有可能的值:tcpdf/include/tcpdf_static.php
.
说实话,现在可以这样解决了。
//AddPage [P(PORTRAIT),L(LANDSCAPE)],FORMAT(A4-A5-ETC)
$pdf->AddPage('P','A5');
// 8.5 X 13 英寸纸 (8.5, 13) // 将英寸转换为毫米 (215.9, 330.2)
$pdf = new Pdf('P', 'mm', array(215.9, 330.2), true, 'UTF-8', false);
编辑 tcpdf.php 并添加新的页面类型或将现有类型修改为您的页面大小。
上面的答案对我不起作用,所以我在这里添加我的解决方案 - 从http://www.tcpdf.org/examples/example_060.phps,更改 urx, ury 为您的目的
// set page format (read source code documentation for further information)
// MediaBox - width = urx - llx 210 (mm), height = ury - lly = 297 (mm) this is A4
$page_format = array(
'MediaBox' => array ('llx' => 0, 'lly' => 0, 'urx' => 210, 'ury' => 297),
//'CropBox' => array ('llx' => 0, 'lly' => 0, 'urx' => 210, 'ury' => 297),
//'BleedBox' => array ('llx' => 5, 'lly' => 5, 'urx' => 205, 'ury' => 292),
//'TrimBox' => array ('llx' => 10, 'lly' => 10, 'urx' => 200, 'ury' => 287),
//'ArtBox' => array ('llx' => 15, 'lly' => 15, 'urx' => 195, 'ury' => 282),
'Dur' => 3,
'trans' => array(
'D' => 1.5,
'S' => 'Split',
'Dm' => 'V',
'M' => 'O'
),
'Rotate' => 90,
'PZ' => 1,
);
// Check the example n. 29 for viewer preferences
// add first page ---
$pdf->AddPage('P', $page_format, false, false);