douqiang6448 2019-06-14 08:31
浏览 42

如何用pdf生成照片

I have a problem when creating a pdf in symfony from the dompdf library.

Namely, it converts pictures but only from one photo, ignoring the other.

Checking the parameters of this photo it has 225x225, 8bit and png format.

So, not thinking much I have stuck all the photos in the same format, width and bits. Of course, it does not work.

I am out of ideas and I do not know what to do because the library only sees one picture and ignores the others.

I changed the format of all the pictures and the size of what works

My code:

  <div class="contentImportat">
    <p class="description">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
        Mauris eget accumsan ligula, id vehicula quam. Donec nec efficitur nisi.
        Morbi vel ultricies ligula.
    </p>
    <img class="znak" src="ogien.png">
</div>
<div class="contentCompany">
    <span>company: Lorem ipsum dolor</span>
    <span>street: Lorem ipsum dolor</span>
    <span>country: Lorem ipsum dolor</span>
    <span>phone: 921-123-131</span>
    <span>fax: 921-123-131</span>
</div>
<hr class="line">
<img class="img" src="ogien.png">

<?php
/**
 * @Route("/dom" , name="pdf_dom")
 */
public function domAction()
{
    $pdfOptions = new Options();
    $pdfOptions->set('defaultFont', 'Arial');

    // Instantiate Dompdf with our options
    $dompdf = new Dompdf($pdfOptions);

    $dompdf = new Dompdf(array('enable_remote' => true));

    // Retrieve the HTML generated in our twig file
    $html = $this->renderView('pdf/horismall.html.twig');

    // Load HTML to Dompdf
    $dompdf->loadHtml($html);

    // (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
    $dompdf->setPaper('A4', 'portrait');

    // Render the HTML as PDF
    $dompdf->render();

    // Output the generated PDF to Browser (force download)
    $dompdf->stream("mypdf.pdf", [
        "Attachment" => false
    ]);
}
  • 写回答

1条回答 默认 最新

  • dongpa2000 2019-06-14 21:14
    关注

    For generation of PDF, you can use excellent library WKHTMLTOPDF(Laravel Snappy), currently I'm using this library for generating Highcarts and photos and many more things in PDF.

    There is a wrapper from knp labs for Symfony called KnpSnappy. You can use it in order to generate your PDF. Laravel snappy is based on this package - you can try to use laravel package too.

    Note: Sometimes if you referencing photo with twig or blade(laravel template engine), library could not not render it, so what I'm doing is referencing image with HTML tag(direct link to image), not with (Laravel Blade) or Twig asset option.

    https://github.com/KnpLabs/snappy

    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致