mercredi 25 mars 2015

add dynamically generated image to TCPDF

I am trying to add image signature png to TCPDF,i tried many ways but its not working to me.


Here is the Code.I am using signature js at this moment and converting it to png image using library i gave the path to tcpdf but its not working.



<?php

require_once('tcpdf/tcpdf.php');
//require('sigToSvg.php');
require_once 'lib/save-signature.php';
require_once 'signature-to-image.php';

?><!DOCTYPE html>
<head>
<link rel="stylesheet" href="signature-pad/build/jquery.signaturepad.css">
<script src="http://ift.tt/t0Y3fx"></script>
</head>
<body>
<?php

if ($show_form) {
require_once 'views/accept.php';
} else {
require_once 'views/regenerate.php';
}
?>
<script src="jquery.signaturepad.min.js"></script>
<?php if ($show_form) :?>
<script>
$(document).ready(function () {
$('.sigPad').signaturePad({drawOnly : true});
});
</script>
<?php else : ?>
<script>
$(document).ready(function () {

var sig = <?php echo $output; ?>;
$('.sigPad').signaturePad({displayOnly : true}).regenerate(sig);
});
</script>

<?php

endif; ?>


<?php
if(!empty($_REQUEST['output'])){
$json = $_POST['output'];
$img = sigJsonToImage($json);
imagepng($img, 'signature.png');
imagedestroy($img);



$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 001');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
$pdf->setFooterData(array(0,64,0), array(0,64,128));

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------

// set default font subsetting mode
$pdf->setFontSubsetting(true);

// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('dejavusans', '', 14, '', true);

// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();

// set text shadow effect
$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));

$path=$_SERVER['DOCUMENT_ROOT']."signpad/signature.png";

$toolcopy = ' my content <br>';
$toolcopy .= '<img src='.$path.' width="50" height="50">';
$toolcopy .= '<br> other content';

$pdf->writeHTML($toolcopy, true, 0, true, 0);


// Set some content to print
$html = "<h2>Name: ".$_REQUEST['name']."</h2> <h2>Email: ".$_REQUEST['email']."</h2>

<h2>Signature : <img src=".$path."></h2>";



$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);


$pdf->Output($_SERVER['DOCUMENT_ROOT'].'/signpad/'.'ocpdftesting.pdf', 'F');

echo $path;







}
?>

</body>

Aucun commentaire:

Enregistrer un commentaire