我正在用dompdf和laravel创建PDF。
PDF正在用专用打印机打印,该打印机仅接受10厘米宽度和20厘米高的文件。
我尝试了以下方法:
$customPaper = array(0,0,720,1440);
$pdf = PDF::loadView('pdf.retourlabel',compact('retour','barcode'))->setPaper($customPaper);
因为11x17是
"11x17" => array(0, 0, 792.00, 1224.00),
我认为10x20是0,0720,1440
但是它不起作用。
任何帮助都将不胜感激。
预先感谢
我如何修复此问题:
更改自定义纸。
下载PDF在Acrobat Reader中打开的PDF现在将鼠标移至左角,您可以看到文档的宽度和高度,我相应地更改了自定义论文。
最终结果是:10cm x 20cm =
$customPaper = array(0,0,567.00,283.80);
$pdf = PDF::loadView('pdf.retourlabel', compact('retour','barcode'))->setPaper($customPaper, 'landscape');
非常有轨的工作,但我确实完成了工作。
谢谢
设置PHP中的纸张尺寸需要了解点(PT)测量,点是本机PDF单元。PDF分辨率(带有DOMPDF)为72pt/英寸。因此,10cm x 20厘米大约等于283 x 566(如您在答案中所述)。
1 inch = 72 point
1 inch = 2.54 cm
10 cm = 10/2.54*72 = 283.464566929
20 cm = 10/2.54*72 = 566.929133858
landscape
是均值对面。因此,我们可以将其设置为:array(0, 0, 566.929133858, 283.464566929 )
,与答案相同,但更精确的值
但是,您可以允许DOMPDF通过指定CSS中的页面尺寸来计算适当的点大小。这是从Dompdf 0.6.2。
开始的。<html>
<head>
<style>
@page { size: 10cm 20cm landscape; }
</style>
</head>
<body>
...
</body>
</html>
Trivia:PDF规格没有提供指示纸取向的方法(尽管有指示旋转的方法)。指定景观方向时,DOMPDF只是翻转宽度/高度。
我认为问题与方向相关,因为setpaper使用'a4'方向为默认值,因此这可能是您的代码不起作用的原因。/p>
/**
* Set the paper size (default A4)
*
* @param string $paper
* @param string $orientation
* @return $this
*/
public function setPaper($paper, $orientation = 'portrait'){
$this->paper = $paper;
$this->orientation = $orientation;
$this->dompdf->setPaper($paper, $orientation);
return $this;
}
尝试使用:
$customPaper = array(0,0,720,1440);
$pdf = PDF::loadView('pdf.retourlabel',compact('retour','barcode'))->setPaper($customPaper,'portrait');
希望对其他选项而不是portrait
。