1

我有一个代码,用于使用带有 Symfony2 的 KNP Snappy 捆绑软件生成 PDF。这是它的样子:

     $this->container->get('knp_snappy.pdf')->generateFromHtml(
          $this->templating->render(
             $twigInclude,
             array( ,
                 'htmlFiles' => $htmlFiles,
                 'headlines' => $headlines,
             )
         ),
         $folderHistory . '/reports/' . $filename . '.pdf'
     );

我的问题是,我想设置页边距并将页面大小从 A4 更改为 A1。我找到了很多示例,但每次尝试时,似乎 pdf 不再生成。我怎样才能解决这个问题并让它发挥作用。

在此先感谢您的帮助。

4

1 回答 1

1

您可以在选项中设置几个标志:

$options = [
  'page-size' => 'A1',
  'margin-top' => 10,
  'margin-right' => 10,
  'margin-bottom' => 10,
  'margin-left' => 10,
];

$this->container->get('knp_snappy.pdf')->generateFromHtml(
  $this->templating->render(
    $twigInclude,
    [
      'htmlFiles' => $htmlFiles,
      'headlines' => $headlines,
    ]
  ),
  $folderHistory . '/reports/' . $filename . '.pdf',
  $options,
  true // this flag will overwrite existing file
);
于 2021-05-03T12:17:35.163 回答