将php输出保存为PDF


Save php output to PDF

我有一个脚本,它打开一个打印对话框,输出一些使用css样式的生成信息。有了这个对话,我可以打印成PDF。是否有一种方法可以将此输出立即转换为PDF?

我已经尝试了一些API web服务,如html2pdf,但这些服务只生成空白页面,因为输出直接发送到打印对话框。有办法解决这个问题吗?(没有样式我的信息完全新的TCPDF/FPDF等)

示例:http://dev.prettynormal.de/index.php?task=productprint& pid = 1480, _wpnonce = 0 f275205f2

使用FPDF,这是非常容易使用的;

require('fpdf.php');
 class PDF extends FPDF{
function header()//create header of the pdf
                {
                    $this->Image('Your Logo url', 10, 6, 90);
                    $this->Ln(30);
                    $this->SetFont('Arial', 'B', 15);
                    // Move to the right
                    $this->Cell(50);
                    // Title
                    // $this->Cell(90, 110, 'User Website Brief', 'C');
                    // Line break
                    $this->Ln(20);
                }
function footer()
                {
                    $this->SetY(-15);
                    // Arial italic 8
                    $this->SetFont('Arial', 'I', 8);
                    // Page number
                    $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
                }
            }
$pdf = new pdf();
$pdf->AliasNbPages();
            $title ='Your PDF Title';
            $pdf->SetTitle($title);
            $pdf->SetAuthor('Your Name');
            $pdf->AddPage();
            $pdf->SetFont('Arial', 'B', 14);
$pdf->cell(20, 10, $YourContent);
$pdf->Output('I',"FileName");//sends PDF output to the browser

你可以在这里下载FPDF如果它给你的问题,请过去你的代码,这样我可以帮助你。