我正在尝试使用PHP制作动态PDF生成器,但是到目前为止,我遇到的一个问题是,我尝试以PDF生成的页面具有使用画布通过flot生成的条形图。
有没有人有这方面的经验或知道如何将画布打印为pdf?
我也很愿意让客户加载一个页面,该页面使用CSS设置分页符的样式,并使用内置的“打印到PDF”打印机,使报告的每个图形都被(打印)页面打断。
php参考方案
//Here is the way to generate html into canvas into PDF
1 add can js files
jquery.js
JS/html2canvas.js
JS/jquery.plugin.html2canvas.js
2.get the html content to convert into canvas
$('.hideDivs').hide();
$('.formdrop').hide();
$('.block').html2canvas({
onrendered: function (canvas) {
//Set hidden field's value to image data (base-64 string)
$('#img_val').val(canvas.toDataURL("image/jpg"));
$('#img_val3').val($('.block').html()); //html of div
//Submit the form manualy
}
});
3. PHP back end with TC PDF
if(isset($_REQUEST['img_val'])):
//Get the base-64 string from data
$filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1);
//Decode the string
$unencodedData=base64_decode($filteredData);
//Save the image
$imgfile=FCPATH.'images/submsnimage_'.$this->session->userdata('admin_id').'.jpg';
$imagegerated=file_put_contents($imgfile, $unencodedData);
chmod($imgfile, 0777);
$pdfImageFile=site_url()."images/submsnimage_".$this->session->userdata('admin_id').'.jpg';
endif;
4 PDF generation
ini_set('max_execution_time',300);
require_once (FCPATH.'tcpdf/config/lang/eng.php');
require_once (FCPATH.'tcpdf/tcpdf.php');
$exa = new TCPDF ();
$exa->SetCreator ( PDF_CREATOR );
$exa->SetAuthor ( 'Clay County Admin' );
$exa->SetTitle ( 'Clay County Form' );
$exa->SetSubject ( 'Example of TCPDF' );
$exa->SetKeywords ( 'TCPDF, PDF, PHP' );
$exa->SetFont ( 'times', '', 18 );
$exa->AddPage ();
$exa->Image ($pdfImageFile, 15, 10, 430,630);
$exa->AddPage ();
$exa->Image ($pdfImageFile2, 15, 10, 430,630);
$exa->AddPage ();
$exa->Image ($pdfImageFile3, 15, 10, 430,630);
$exa->setImageScale(PDF_IMAGE_SCALE_RATIO);
$exa->setJPEGQuality (100);
$root=site_url();
$exa->setImageScale(1.53);
$txt ="";
$exa->WriteHTML ($txt, true, false, true, false, '');
$exa->Output (FCPATH.'uploads/pdf/clayCommunityBullyReport.pdf', 'F' ); // downloads the pdf
php:是否有充分的理由引用所有数组键/索引? - php我正在遍历别人的代码,他们总是避免转义其数组键。例如:$ row_rsCatalogsItems [名称]代替$ row_rsCatalogsItems ['名称']因此,我不断地对自己接触的所有事物进行微小的更改,以应对这些惰性。但是现在我想知道这样做是否有很多好处。我得到它会在默认为字符串之前检查常量(我在处理常量时会讨厌php中的行为,因为即使未定义,…
PHP数组可以这样做吗? - php可以说;我有一个$ friends数组,其中有2,000个不同的friendID号+我有一个带有10,000 bulletinID号的$ bulletins数组,该$ bulletins数组还将具有另一个值,该ID的用户ID是发布公告条目的用户现在可以获取所有具有与FriendsID数组中的userID匹配的userID的bulletinID号吗?甚至有可能…
哪个更好的做法?从Jquery响应获取HTML - php这只是一个问题,以了解人们如何以及如何做到这一点,但是假设用户向列表中添加了一些内容,完成后,它将运行下面的ajax并更新.user-stream-list$.ajax({ url: "user-stream-list.php", success: function(data){ $(".user-stream-list…
PHP标头功能不起作用 - php我曾经使用此功能从一个PHP页面重定向到另一个:header( 'Location: student.php?cnp='.$_REQUEST['name']) ; 在我的本地主机中,它确实可以工作,但是如果在Internet中对其进行测试,则不会重定向。我也尝试给出完整的路径(如http://.../student.p…
使用PHP从sqlite3数据库检索表名称 - php我有此代码的工作版本,如下所示,结果为can be seen here。<?php // Display all sqlite tables $db = new SQLite3('data.db'); $tablesquery = $db->query("SELECT name FROM sqlite_master …