构建Laravel API,我有合同PDF文件存储在远程服务器和保存在数据库中的uid,也在线签名文件,这是png.现在当用户点击sign
按钮,我想把这个png图像和地方,让右下角(这可能会改变)在合同PDF.我尝试了它与laravel domPDF和laravel-snappy包,但没有想要的结果.与domPDF的例子:
public function addSignatureToPdf(ContractFile $contractFile)
{
// Path to the existing PDF file
$pdfPath = storage_path($this::PDF_DIRECTORY_PATH . "combined_document{$contractFile->getHash()}.pdf");
$existingPdfContent = file_get_contents($pdfPath);
// Set the path to your signature image
$signatureImagePath = storage_path('app/contract-files/დავით-ხაჩიძე.png');
// Load the HTML content with the image (signature) added
$html = view('pdf.signature', compact('signatureImagePath'))->render();
$htmlWithEncoding = mb_convert_encoding($existingPdfContent . $html, 'HTML-ENTITIES', 'UTF-8');
// Convert HTML to PDF
$pdf = PDF::loadHTML($htmlWithEncoding);
// Save the modified PDF
$outputPdfPath = storage_path($this::PDF_DIRECTORY_PATH . 'modified_contract.pdf');
file_put_contents($outputPdfPath, $pdf->output());
return "PDF with signature added saved at: $outputPdfPath";
}
字符串
这创建了pdf文件,但它与二进制数据,我不知道在哪里,以及如何我追加图像到pdf。任何建议如何做laravel?
1条答案
按热度按时间mkshixfv1#
将图像转换为base64
字符串