我有一个用户定义的函数,它返回html内容。所以我只想在PDF文件中打印这个HTML并直接下载为PDF
提前感谢....
答案 0 :(得分:4)
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 manual。
答案 1 :(得分:0)
<?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);
}
?>
答案 2 :(得分:0)