我想使用FPDF库从我的PHP页面生成一个签名到pdf。到目前为止我的签名工作正常,我能够将图像签名从画布保存到输入字段siginput1。我已经完成了现在如下面的代码集所示。
<form method="POST" id="delivery" name="delivery" action="<?php echo $_SERVER['PHP_SELF']; ?>" accept-charset="utf-8">
<div id="collected">
<label for="name" style="left: 10px;text-align:left;" >Collected By :
</label>
<input type="text" name="collected_by" class="input-field extralarge-input" style="float:left; text-transform:uppercase;" id="collected_by" required>
<div id="signature-pad" class="signature-pad" style="float: right;">
<div class="signature-pad--body">
<canvas ></canvas>
<input id="siginput1" type="display" name="siginput1" value="" />
</div><!--signature-pad--body-->
<div class="signature-pad--footer">
<div class="description">Sign above</div>
<div class="signature-pad--actions">
<div>
<button type="button" class="button clear" data-action="clear">Clear</button>
<button type="button" class="button" data-action="undo">Undo</button> </div>
<div>
<button type="button" class="button save" data-action="save-png">Save </button>
</div>
</div><!--signature-pad--actions-->
</div><!--signature-pad--footer-->
</div><!--signature-pad-->
<script src="jquery/signature_pad.js"></script>
<script src="jquery/app.js"></script>
其次是javascritpt app.js
var form = document.getElementById("delivery");
var signatureOne = document.getElementById("siginput1");
savePNGButton.addEventListener("click", function (event) {
if (signaturePad.isEmpty())
{
alert("Please provide collected by signature first.");
} else
{
var dataURL = signaturePad.toDataURL();
signatureOne.value=dataURL;
form.submit();
}
});
最重要的是我声明了我的变量如下:
$signature1==$_POST['siginput1'];
if ( $_POST['siginput1'] )
{
file_put_contents("myfile.png", file_get_contents($signature1));
}
最后这是我在PDF中调用它的部分,但没有出现:
require('pdf/fpdf.php');
if(!isset($_SESSION))
{
session_start();
}
$pdf = new FPDF('P','cm',array(11,18));
$pdf->AddPage();
//header
$pdf->Image('images/bwlogo.png',1,.85,-2500);
$pdf->SetFont('Arial','',10);
$pdf->SetTextColor(0,0,0);
$pdf->Ln(2);
$pdf->Cell(9.5,0,'DELIVERY NOTE',0,0,'C');
$pdf->Ln(0.5);
$pdf->SetFont('Arial','',7);
$deldate=date('d / m / Y');
$pdf->ln(1);
$pdf->Cell(4.5,.5,$signature1,0,1,'L');
$pdf->Output("F","DeliveryNotes/test.pdf");