Wkhtmltopdf + cakepdf - 自定义页面大小
Wkhtmltopdf + cakepdf - Custom page size
我不知道如何使用 CakePDF 和 wkhtmltopdf 启用自定义页面大小。我有以下配置代码:
Configure::write('CakePdf', [
'engine' => [
'className' => 'CakePdf.WkHtmlToPdf',
'binary' => '/usr/local/bin/wkhtmltopdf',
],
'orientation' => 'portrait',
'pageSize' => '', // this line
'download' => true
]);
我想要 150x150mm 的页面。我已经尝试过几种方法,例如传递数组 [150,150],还有“150 150”或“150mm 150mm”之类的方法。这可能吗?
CakePDF pageSize
选项映射到 wkhtmltopdf 的 page-size
选项,它采用 QPrinter::PaperSize
常量名称,例如 A4
、A5
、 B0
、B1
、Legal
、Letter
等,即您无法使用该选项定义自定义尺寸。
如果您需要自定义尺寸,则必须使用 wkhtmltopdf 特定的 page-width
和 page-height
选项,它们默认都采用毫米值。
引自 wkhtmltopdf 文档:
Page sizes:
The default page size of the rendered document is A4, but using this
--page-size option this can be changed to almost anything else, such as: A3,
Letter and Legal. For a full list of supported pages sizes please see
http://qt-project.org/doc/qt-4.8/qprinter.html#PaperSize-enum.
For a more fine grained control over the page size the --page-height and
--page-width options may be used
Configure::write('CakePdf', [
'engine' => [
'className' => 'CakePdf.WkHtmlToPdf',
'binary' => '/usr/local/bin/wkhtmltopdf',
'options' => [
'page-width' => 150,
'page-height' => 150
]
],
'orientation' => 'portrait',
'download' => true
]);
另见
我不知道如何使用 CakePDF 和 wkhtmltopdf 启用自定义页面大小。我有以下配置代码:
Configure::write('CakePdf', [
'engine' => [
'className' => 'CakePdf.WkHtmlToPdf',
'binary' => '/usr/local/bin/wkhtmltopdf',
],
'orientation' => 'portrait',
'pageSize' => '', // this line
'download' => true
]);
我想要 150x150mm 的页面。我已经尝试过几种方法,例如传递数组 [150,150],还有“150 150”或“150mm 150mm”之类的方法。这可能吗?
CakePDF pageSize
选项映射到 wkhtmltopdf 的 page-size
选项,它采用 QPrinter::PaperSize
常量名称,例如 A4
、A5
、 B0
、B1
、Legal
、Letter
等,即您无法使用该选项定义自定义尺寸。
如果您需要自定义尺寸,则必须使用 wkhtmltopdf 特定的 page-width
和 page-height
选项,它们默认都采用毫米值。
引自 wkhtmltopdf 文档:
Page sizes:
The default page size of the rendered document is A4, but using this --page-size option this can be changed to almost anything else, such as: A3, Letter and Legal. For a full list of supported pages sizes please see http://qt-project.org/doc/qt-4.8/qprinter.html#PaperSize-enum.
For a more fine grained control over the page size the --page-height and --page-width options may be used
Configure::write('CakePdf', [
'engine' => [
'className' => 'CakePdf.WkHtmlToPdf',
'binary' => '/usr/local/bin/wkhtmltopdf',
'options' => [
'page-width' => 150,
'page-height' => 150
]
],
'orientation' => 'portrait',
'download' => true
]);
另见