如何使用CakePDF和Dompdf将外部图像嵌入到PDF文件中?

如何使用CakePDF和Dompdf将外部图像嵌入到PDF文件中?,pdf,cakephp,dompdf,cakephp-3.4,Pdf,Cakephp,Dompdf,Cakephp 3.4,我正在使用cakephp3.4和CakePdf使用domPdf插件生成pdf文件 还可以使用QrCode插件随时随地生成QrCode 我想在我的pdf文件中使用生成的二维码,而不将其保存在磁盘上 这就是我所做的 FileDownloadController.php public function view($username = null) { $this->loadModel('Users'); $user = $this->Users->find()

我正在使用
cakephp3.4
CakePdf
使用
domPdf
插件生成pdf文件

还可以使用
QrCode
插件随时随地生成QrCode

我想在我的pdf文件中使用生成的二维码,而不将其保存在磁盘上

这就是我所做的

FileDownloadController.php

public function view($username = null)
{
    $this->loadModel('Users');

    $user = $this->Users->find()
        ->where(['Users.username' => $username])
        ->contain([])
        ->first();

    $this->viewBuilder()->options([
        'pdfConfig' => [
            'filename' => 'profplus_file_'.$user->id.'.pdf',
        ]
    ]);

    $this->set('user', $user);
}

public function generateQR($user_id)
{
    $this->autoRender = false;

    $this->loadModel('Users');

    $user = $this->Users->get($user_id);

    $string = Router::url('/', true) . 'q' . DS . $user->id;;
    $qrCode = new QrCode($string);
    $qrCode
    ->setSize(100);

    // Create a response object
    $response = $this->response;
    $response = $response->withType($qrCode->getContentType(PngWriter::class))
    ->withStringBody($qrCode->writeString(PngWriter::class));

    return $response;
}
并在pdf的视图中
pdf/view.ctp

<table>
    <tr>
        <td class="left-section">
            <table>
                <tr>
                    <td class="top-name">
                        <?= $user->first_name .' '. $user->last_name ?>
                    </td>
                </tr>
                <tr>
                    <td class="top-address">
                        <i class="fa3 fa-phone"></i> <?= $user->mobile ?> | <i class="fa fa-envelope"></i>: <?= $user->email ?>
                    </td>
                </tr>
            </table>
        </td>
        <td class="right-section">
            <img src="<?= $this->Url->build(['prefix' => false, 'controller' => 'ResumeDownload', 'action' => 'generateQR', $user->id], true) ?>" />
        </td>
    </tr>
</table>

你有没有检查过你是否需要?
allow\u url\u fopen
设置为
on
我正在添加从同一服务器生成的图像。它是否会被称为外部映像,正如您编辑了问题的标题一样?是的,从Dompdf的角度来看,所有非本地文件系统路径都是外部/远程内容。您是否检查了关于上下文的第二个链接?您是否也启用了
启用远程
是否启用远程
选项?是的,因为我使用的是
CakePdf
插件,它进一步使用了
DomPdf
引擎。我已在配置中包括
isRemoteEnabled
设置为
true
。请参见
编辑2
Configure::write('CakePdf', [
    'engine' => 'CakePdf.DomPdf',
    'margin' => [
        'bottom' => 15,
        'left' => 50,
        'right' => 30,
        'top' => 45
    ],
    'orientation' => 'potrait',
    'download' => false,
    'options' => [
        'isRemoteEnabled' => true,
    ],
]);