我有一个用户定义的函数,它返回我的 html 内容。所以我只想在PDF文件中打印这个html并直接下载为PDF
提前致谢....
HTML 2 FPDF 脚本为我完成了它。http://sourceforge.net/projects/html2fpdf/
// If html2pdf folder placed in root directory
require_once($_SERVER['DOCUMENT_ROOT'] . '/html2pdf/html2fpdf.php');
// Create new HTML2PDF class for an A4 page, measurements in mm
$pdf = new HTML2FPDF('P','mm','A4');
// Optional top margin
$pdf->SetTopMargin(1);
$pdf->AddPage();
// Control the x-y position of the html
$pdf->SetXY(0,0);
$pdf->WriteHTML($html);
// The 'D' arg forces the browser to download the file
$pdf->Output('MyFile.pdf','D');
请注意,某些元素可能无法正确呈现(对我来说是图像),在这种情况下,您必须直接编写这些元素。请参阅fpdf 手册。
<?php
include("MPDF56/mpdf.php");
$mpdf=new mPDF('c','A4','','',32,25,27,25,16,13);
$mpdf->SetDisplayMode('fullpage');
$mpdf->showImageErrors = true;
$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
$html='<html><head></head><body>Test</body></html>'; //Assign HTML HERE
$cssPath = base_url('assets/css/voucher.css'); //any CSS File you want to Include
$stylesheet = file_get_contents($cssPath);
$mpdf->WriteHTML($stylesheet,1); // The parameter 1 tells that this is css/style only and no body/html/text
$mpdf->WriteHTML($html,2);
if ( $action == 'view')
{
$mpdf->Output('mpdf.pdf','I');
}
else
{
$file_path = FTP_PATH."testfile".DIRECTORY_SEPARATOR.$filename.".pdf"; //FTP_PATH = Location where you want to right PDF
$mpdf->Output( $file_path,'F');
file_put_contents(FTP_PATH.'testfile\\'.$filename.'.pdf', $output);
}
?>