我必须生成一个PDF文档并添加一个"签名字段"。
签名字段是允许第三方服务对文档进行数字签名的字段。
有可能在PHP中使用开源解决方案来实现这一点吗?
我看到了https://manuals.setasign.com/setapdf-signer-manual/create-a-signature-field/.
我尝试使用tcpdf,但没有成功。
谢谢。
正如您已经说过的,您已经在这里完成了seta符号库文档
使用setasign,你可以创建一个pdf文档,或者使用现有的文档在上面创建一个数字签名字段。下面是一个代码示例:-
<?php
require_once('library/SetaPDF/Autoload.php');
// create a writer
$writer = new SetaPDF_Core_Writer_Http('visible-field.pdf', true);
// create a new document instance
$document = new SetaPDF_Core_Document($writer);
// create at least a single page
$document->getCatalog()->getPages()->create(SetaPDF_Core_PageFormats::A4);
// add a field left top with an offset of 10 points
SetaPDF_Signer_SignatureField::add(
$document,
'Signature field 1',
1,
SetaPDF_Signer_SignatureField::POSITION_LEFT_TOP,
array('x' => 10, 'y' => -10),
180,
70
);
// add a field absolutely position on the bottom left with an offset of 10 points
SetaPDF_Signer_SignatureField::add($document, 'Signature field 1', 1, 10, 10, 180, 70);
// save and finish
$document->save()->finish();
注意:-使用Adobe Acrobat Reader打开生成的文档,这样您就可以看到pdf上的数字签名字段。
使用https://www.npmjs.com/package/jspdf
var image = "" // base 64 image
var url = patientSignature; // url of the image
// Initialize the XMLHttpRequest and wait until file is loaded
var xhr = new XMLHttpRequest();
xhr.onload = function () {
// Create a Uint8Array from ArrayBuffer
var codes = new Uint8Array(xhr.response);
// Get binary string from UTF-16 code units
var bin = String.fromCharCode.apply(null, codes);
// Convert binary to Base64
var b64 ="data:image/jpg;base64,"+ btoa(bin);
// console.log(b64); //-> "R0lGODdhAQABAPAAAP8AAAAAACwAAAAAAQABAAACAkQBADs="
var doc = new jsPDF()
doc.addImage(image, "png", 100, 5, 10, 10);
doc.addImage(bin, "png", 140, 205, 40, 40);
// doc.addImage("data:image/png;base64,"+dataUrl, "JPEG", 100, 5, 10, 10);
var specialElementHandlers = {
'#editor': function(element, renderer){
return true;
}
};
// All units are in the set measurement for the document
// This can be changed to "pt" (points), "mm" (Default), "cm", "in"
doc.fromHTML($('#content').get(0), 15, 10, {
'width': 170,
'elementHandlers': specialElementHandlers
});
doc.save(store_data.patientName+'.pdf');
};
// Send HTTP request and fetch file as ArrayBuffer
xhr.open('GET', url);
xhr.responseType = 'arraybuffer';
xhr.send();
})
您没有指示是通过php生成PDF还是创建离线PDF。
如果离线,假设您的软件允许签名,这是一个简单的过程。查看软件手册。
如果通过php代码创建PDF,这是可以做到的。有几种方法可以实现这一点。你需要对你想要的东西做出一些决定;捕获";使用数字签名。在";php创建数字签名";