28

tcpdf 网站上的这个示例展示了如何使用 A4、A5 等页面格式,但是如何将 tcpdf 设置为使用 175 毫米 x 266 毫米等自定义尺寸?

解决方案赞赏。

4

7 回答 7

51

不需要编辑类... tcpdf 不接受宽度/长度参数,它只接受两个长度并确定哪个使用布局(纵向或横向)

$pageLayout = array($width, $height); //  or array($height, $width) 
$pdf = new TCPDF('p', 'pt', $pageLayout, true, 'UTF-8', false);
于 2011-06-24T12:06:54.423 回答
9

在较新的 TCPDF 版本上,您可以通过多种方式定义页面大小:

  • 所有标准页面格式都已定义(超过 300 种类型)。
  • 您可以通过定义具有 2 个数字的数组来简单地定义页面大小:宽度、高度(无论页面方向)。
  • 或者,您可以定义高级页面详细信息(MediaBox、Cropbox、BleedBox、TrimBox、ArtBox),如http://www.tcpdf.orgsetPageFormat()上的方法文档中所述。

还要检查默认示例编号。28 和 60 在http://www.tcpdf.org

于 2011-09-27T07:09:15.293 回答
9

转到 /config/tcpdf_config.php 并在第 117 行附近,修改该行:

define ('PDF_PAGE_FORMAT', 'A4');

经过

define ('PDF_PAGE_FORMAT', 'LETTER');

将“LETTER”以大写形式输入很重要,您可以在此文件中看到所有可能的值:tcpdf/include/tcpdf_static.php.

于 2014-04-03T16:06:29.673 回答
3

说实话,现在可以这样解决了。

//AddPage [P(PORTRAIT),L(LANDSCAPE)],FORMAT(A4-A5-ETC)

$pdf->AddPage('P','A5');

来源: https ://tcpdf.org/examples/example_028/

于 2016-10-14T09:53:47.913 回答
2

// 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);

于 2022-02-21T03:37:20.083 回答
0

编辑 tcpdf.php 并添加新的页面类型或将现有类型修改为您的页面大小。

于 2010-10-23T12:51:59.547 回答
0

上面的答案对我不起作用,所以我在这里添加我的解决方案 - 从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);
于 2013-09-24T14:55:15.897 回答