Convert HTML form data into a PDF file using PHP

前端 未结 4 1217
悲&欢浪女
悲&欢浪女 2021-02-03 11:57

I have been looking and testing this for a couple days now and was wondering if anyone could point me in a different direction. I have a very long job application HTML form (jo

4条回答
  •  猫巷女王i
    2021-02-03 12:28

    I have used fpdf several times to create php-based pdf documents. An example following:

    require('fpdf.php');
    
    $pdf = new FPDF();
    
    $pdf->AddFont('georgia', '', 'georgia.php');
    $pdf->AddFont('georgia', 'B', 'georgiab.php');
    $pdf->AddFont('georgia', 'I', 'georgiai.php');
    
    # Add UTF-8 support (only add a Unicode font)
    $pdf->AddFont('freesans', '', 'freesans.php', true);
    $pdf->SetFont('freesans', '', 12);
    
    $pdf->SetTitle('My title');
    $pdf->SetAuthor('My author');
    $pdf->SetDisplayMode('fullpage', 'single');
    
    $pdf->SetLeftMargin(20);
    $pdf->SetRightMargin(20);
    
    $pdf->AddPage();
    $pdf->Cell(40,10,'Hello World!');
    $pdf->Output();
    

    You can learn very fast with these tutorials from the website itself.


    EDIT: Example to save form data: (yes, is very easy...)

    require('fpdf.php');
    $pdf = new FPDF();
    
    $pdf->AddPage();
    foreach ($_POST as $key =>$data)
    {
        $pdf->Write(5, "$key: $data"); //write
        $pdf->Ln(10); // new line
    }
    $pdf->Output($path_to_file . 'file.txt','F'); // save to file
    

    Look at these pages created with fpdf, really!

    enter image description here

    enter image description here

提交回复
热议问题