jpm*_*yob 2 php pdf-generation tcpdf
我有一张空白证书的PDF,我想在用户完成一门课程时填写两行,并显示PDF以便他们打印或下载.
我正在使用TCPDF在现有PDF上写两行.
根据上一篇文章中的建议(使用PHP填写PDF),我使用TCPDF_IMPORT将现有PDF带入对象,并在其上面书写.
但是,原始PDF没有显示在屏幕上,我留下了一个空白文档,只有我创建的文本行.
以下是我对此的看法 - 它只产生"这是我的测试文本"这一行.
<?php
// Include the main TCPDF library (search for installation path).
require_once( '../tcpdf_import.php' );
// create new PDF document
$pdf = new TCPDF_IMPORT( '1_cert.pdf' );
// set document information
$pdf->SetCreator( 'aaa.com' );
$pdf->SetAuthor( 'aaa.com' );
$pdf->SetTitle( 'Certificate Test' );
$pdf->SetSubject( 'In completion of x-module' );
$pdf->SetKeywords( '' );
// set default monospaced font
$pdf->SetDefaultMonospacedFont( PDF_FONT_MONOSPACED );
// set font
$pdf->SetFont( 'times', 'B', 30 );
// display
$pdf->SetDisplayMode( 'fullpage', 'SinglePage', 'UseNone' );
// set margins
$pdf->SetMargins( 10, PDF_MARGIN_TOP, 10 );
// 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 );
}
// -------------------------------------------------------------
// stuff i believe should write test over an existing PDF
// -------------------------------------------------------------
$pdf->StartPage( 'L', '', false );
$pdf->SetY( 50 );
$pdf->Cell( 0, 0, 'test text', 0, 1, 'C' );
$pdf->EndPage( false );
// -------------------------------------------------------------
// end of stuff i believe should write test over an existing PDF
// -------------------------------------------------------------
//Close and output PDF document
$pdf->Output( 'aTest.pdf', 'I' );
?>
Run Code Online (Sandbox Code Playgroud)
好吧,不像我想的那样雄辩,但我发现了一些有用的东西......
<?php
require_once "tcpdf/tcpdf.php";
require_once "FPDI/fpdi.php";
$pdf = new FPDI( 'L', 'mm', 'LETTER' ); //FPDI extends TCPDF
$pdf->AddPage();
$pages = $pdf->setSourceFile( 'test.pdf' );
$page = $pdf->ImportPage( 1 );
$pdf->useTemplate( $page, 0, 0 );
$pdf->Output( 'newTest.pdf', 'F' );
?>
Run Code Online (Sandbox Code Playgroud)
感谢Simon发表于http://sourceforge.net/p/tcpdf/discussion/435311/thread/66272894/
我能够修改它 - 它需要运行两个库 - 但它的工作原理.
| 归档时间: |
|
| 查看次数: |
11011 次 |
| 最近记录: |