将 pdf 文档合并为一个 KnpLabs/KnpSnappyBundle

Merge pdfs documents in one KnpLabs/KnpSnappyBundle

我正在尝试使用 KnpLabs/KnpSnappyBundle,我想知道我是否可以:

  1. 合并 pdf 文件
  2. 将图片转换为 pdf
  3. 在本地加载 pdf

我的控制器

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Knp\Snappy\Pdf;
use Symfony\Component\HttpKernel\KernelInterface;

class PdfController extends AbstractController
{
    private $pdf;
    private $kernel;

    public function __construct(Pdf $pdf, KernelInterface $kernel)
    {
        $this->pdf = $pdf;
        $this->kernel = $kernel;
    }

    /**
     * @Route("pdf")
     */
    public function pdfAction()
    {
        $html = "<html><body>hello snappy !</body></html>";
        // trying to merge pdf -> error
        $this->pdf->generate(['http://www.pdf995.com/samples/pdf.pdf', 'http://www.africau.edu/images/default/sample.pdf'], 'merge.pdf');
        //trying to convert jpg to pdf -> it show empty PDF !
        $this->pdf->generate('https://www.cleverfiles.com/howto/wp-content/uploads/2018/03/minion.jpg', 'jpgToPdf.pdf');
    }
}

错误:

The exit status code '1' says something went wrong: stderr: "Loading pages (1/6) [> ] 0% [===> ] 5% [======> ] 10% Error: Failed loading page http://www.pdf995.com/samples/pdf.pdf (sometimes it will work just to ignore this error with --load-error-handling ignore) Error: Failed loading page http://www.africau.edu/images/default/sample.pdf (sometimes it will work just to ignore this error with --load-error-handling ignore) Exit with code 1, due to unknown error. " stdout: "" command: /usr/bin/wkhtmltopdf --lowquality 'http://www.pdf995.com/samples/pdf.pdf' 'http://www.africau.edu/images/default/sample.pdf' 'merge.pdf'.

KnpLabs/KnpSnappyBundle 提供从 HTML 生成 PDF 的工具,以及生成图像的工具。 我们可以寻找其他工具来合并 pdf,例如 clegginabox/pdf-merger 要将图片转换为 PDF,我们可以查找 Setasign/FPDF