我有一个 base64Encoded 字符串中的 XML。我的要求是将base64Encoded xml附加到pdf中。我使用以下示例,该示例从文件中获取 XML,但我需要首先解码 base64Encoded xml,然后将其附加到 pdf
$mpdf = new \Mpdf\Mpdf([
'PDFA' => true,
'PDFAauto' => true,
]);
$mpdf->SetAssociatedFiles([[
'name' => 'phpunit.xml',
'mime' => 'text/xml',
'description' => 'some description',
'AFRelationship' => 'Alternative',
'path' => base_path() . '/phpunit.xml'
]]);
$mpdf->WriteHTML('<h1>Hello world 1!</h1>');
return $mpdf->Output();
如果我们传递 XML 文件路径,上面的示例可以正常工作,但我有 Base64 编码字符串中的 XML。我们如何使用
Mpdf
中的Laravel/PHP
库将base64Encoded xml附加到pdf中?
您可以使用 Mpdf 库将 Base64 编码的 XML 字符串作为 PDF 中的文件附加,如下所示。
$base64EncodedXml = "a_base64_encoded_xml_string";
$decodedXml = base64_decode($base64EncodedXml);
$associatedFile = [
'name' => 'your_xml_file.xml',
'mime' => 'text/xml',
'description' => 'XML File Description',
'AFRelationship' => 'Alternative',
'data' => $decodedXml, // Attach the decoded XML content
];
$mpdf = new \Mpdf\Mpdf([
'PDFA' => true,
'PDFAauto' => true,
]);
$mpdf->SetAssociatedFiles([$associatedFile]);
$mpdf->WriteHTML('<h1>Hello world 1!</h1>');
return $mpdf->Output();