我是从html页面生成的pdf,我想设置一个特定的宽度和高度的每个页面的pdf,我在网上什么也没有发现,但在捆绑有一个pdf.php与
protected function configure() 其中这些配置是:
'page-height' => null,
'page-size' => null,
'page-width' => null,所以我不知道哪个单元是预期的
所以如果我将它设置为
'page-height' => 600,
'page-width' => 1000,在我生成pdf的地方,它变得太大了,所以它不能是像素,也许它与任何其他选项有关?这是我的电话:
$pdfString=$this->knp_snappy->getOutputFromHtml($html, array(
'orientation' => 'landscape',
'enable-javascript' => true,
'javascript-delay' => 1000,
'no-stop-slow-scripts' => true,
'no-background' => false,
'lowquality' => false,
'page-height' => 600,
'page-width' => 1000,
'encoding' => 'utf-8',
'images' => true,
'cookie' => array(),
'dpi' => 300,
'image-dpi' => 300,
'enable-external-links' => true,
'enable-internal-links' => true
));我需要有一个特定的高度,因为现在我绘制的图表是剪切的,因为我不知道生成的pdf的确切高度
如有任何帮助,请提前感谢!
发布于 2014-05-14 17:36:43
--page-width和--page-height采用真实世界的单位(如厘米,而不是像素)
--page-size接受"A4“、"A5”、"Letter“等值。
虽然不接触这些值而只是玩玩你正在使用的布局,或者使用--zoom,可能会更容易,但我肯定会调整布局(可能有一个布局或CSS文件专门用于生成PDF)
发布于 2016-03-27 00:06:05
您不必仅在控制器中接触捆绑包中的类Pdf,而必须在调用方法时添加选项
$response->setContent($this->get('knp_snappy.pdf')->getOutputFromHtml($html,array('page-height' => 200,'page-width' => 50)));这是球洞控制员协会
/**
* Displays a form to create a new Delivery entity.
*
* @Route("/generate/pdf/ticket/{id}", name="delivery_show_pdf_ticket")
* @Method("GET")
* @Template("ShippiesServiceWebAppBundle:Delivery:ticket.html.twig")
*/
public function generatePDFTicketAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ShippiesCoreBundle:Delivery')->find($id);
$info = array(
$entity ->getClient()->getCustomerNumber(),
);
$infoText = implode('|', $info);
$options = array(
'code' => $infoText,
'type' => 'datamatrix',
'format' => 'png',
'width' => 3,
'height' => 3,
'color' => array(0, 0, 0),
);
$barcode =
$this->get('sgk_barcode.generator')->generate($options);
$request = $this->getRequest();
$html = $this->render('ShippiesServiceWebAppBundle:Delivery:ticket.html.twig', array('entity' => $entity,'info'=>$infoText,'barcode'=>$barcode,'base_dir' => $this->get('kernel')->getRootDir() . '/../web' . $request->getBasePath()));
$response = new Response();
$response->setContent($this->get('knp_snappy.pdf')->getOutputFromHtml($html,array('page-height' => 200,'page-width' => 50)));
$response->headers->set('Content-Type', 'application/pdf');
$response->headers->set('Content-disposition', 'filename=1.pdf');
return $response;
}https://stackoverflow.com/questions/23650539
复制相似问题