导入PDF并用Symfony签名 [英] Import a PDF and sign it with Symfony

查看:72
本文介绍了导入PDF并用Symfony签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要签署一个现有的pdf文件.

I need to sign an existing pdf.

我正在使用Symfony 3.4.12和捆绑包 https://packagist.org/包/whiteoctober/tcpdf-bundle 来签名pdf.

I'm using Symfony 3.4.12 and the bundle https://packagist.org/packages/whiteoctober/tcpdf-bundle to sign pdf's.

在服务中,我添加了此部分:

Inside the services I added this part:

AppBundle\Controller\AController:
    class: AppBundle\Controller\AController
    arguments: ['@white_october.tcpdf']

在控制器内部,我正在使用它;

Inside the Controller I'm using this;

use WhiteOctober\TCPDFBundle\Controller\TCPDFController;

使用此代码,我可以下载正确签名的创建的pdf:

And with this code I can download a created pdf signed correctly:

private $tcpdf;

public function __construct(TCPDFController $tcpdf)
{
    $this->tcpdf = $tcpdf;
}

public function aAction ()
{
    $pdf = $this->tcpdf->create(
        'LANDSCAPE',
        PDF_UNIT,
        PDF_PAGE_FORMAT,
        true,
        'UTF-8',
        false
    );
    $pdf->SetAuthor('qweqwe');
    $pdf->SetTitle('Prueba TCPDF');
    $pdf->SetSubject('Your client');
    $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
    $pdf->setFontSubsetting(true);

    // set additional information
    $info = array(
        'Name' => 'xxx',
        'Location' => 'xxx',
        'Reason' => 'xxx xxxx',
        'ContactInfo' => 'http://www.xxx.xx',
    );

    // set document signature
    $pdf->setSignature('file:///var/www/html/publicCert.pem', 'file:///var/www/html/privateKey_cert.pem', 'xxxx', '', 2, $info, 'A');

    $pdf->SetFont('helvetica', '', 11, '', true);
    $pdf->AddPage();

    $html = '<h1>Working on Symfony</h1>';

    $pdf->writeHTMLCell(
        $w = 0,
        $h = 0,
        $x = '',
        $y = '',
        $html,
        $border = 0,
        $ln = 1,
        $fill = 0,
        $reseth = true,
        $align = '',
        $autopadding = true
    );

    $pdf->Output("example.pdf", 'I');
}

我的目标是尝试对现有的pdf进行签名,所以我尝试使用FPDI导入它,但是我感到困惑,因为我知道我可以使用PDFI导入pdf,但是我无法对其进行签名,而使用TCPDF则相反,我无法导入pdf,但可以对已创建的pdf进行签名.而且显然我不能使用一个函数.

My objective is try to sign an existing pdf, so I tried to use FPDI to import it but I get confused because I know I can import a pdf with PDFI but I can't sign it and the opposite with the TCPDF, I can't import the pdf but I can sign a created one. And apparently I can't use functions from one to the other.

那么,我该如何解决此问题?任何的想法?你能给我举个例子吗?

So, how I should fix this problem? Any idea? Could you show me an example?

推荐答案

最后,我无法使用TCPDF捆绑包解决此问题,但我发现一个不太昂贵的解决方案抛出SetAsign,在此示例中您可以看到可以选择您要签名的pdf文件.我知道它要花钱,但是FPDI和这个库我可以看到pdfs的最新版本存在一些问题,而Setasign与FPDF插件相比是一个更稳定和维护的版本,将为您避免一些问题.

Finally I couldn't solve this problem with the TCPDF bundle but I found a not too much expensive solution throw SetAsign where in this example you can see that you can select the pdf you want to sign it. I know it cost a price but FPDI and this libraries I could see that got some problems with the newest versions from the pdfs and Setasign is a more stable and maintained version compared with FPDF pluggins and will avoid a few problems for you.

我找到的示例和解决方案在下一个链接中说明:

The example and solution I found is explained in the next link:

" https://manuals .setasign.com/setapdf-signer-manual/the-main-class/#index-4-1 "

这篇关于导入PDF并用Symfony签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆