在PHP中,可以通过exec()函数来调用wkhtmltopdf命令并设置配置选项。以下是一些常用的wkhtmltopdf配置选项:
--page-size: 设置页面大小,例如A4、Letter等。--orientation: 设置页面方向,可以是Portrait(纵向)或Landscape(横向)。--margin-top, --margin-bottom, --margin-left, --margin-right: 设置页面的上、下、左、右边距。--header-html, --footer-html: 设置页眉和页脚的HTML内容。--header-spacing, --footer-spacing: 设置页眉和页脚与内容之间的距离。--header-font-size, --footer-font-size: 设置页眉和页脚的字体大小。--disable-smart-shrinking: 禁用智能缩放,即不自动调整页面大小以适应内容。--no-images: 禁止加载图片。--no-background: 禁止加载页面背景。--print-media-type: 强制使用打印媒体样式。这些配置选项可以在调用wkhtmltopdf时作为参数传递,例如:
exec('wkhtmltopdf --page-size A4 --margin-top 20mm --margin-bottom 20mm input.html output.pdf');