How to save pdf file in the folder using php.

In this article, we learn how to save pdf files in folders by using php. FPDF is a PHP class that allows you to generate PDF files. FPDF does not depend upon the additional PHP libraries. FPDF is open source and can be downloaded from the official webs…


This content originally appeared on DEV Community and was authored by Kodwings

In this article, we learn how to save pdf files in folders by using php. FPDF is a PHP class that allows you to generate PDF files. FPDF does not depend upon the additional PHP libraries. FPDF is open source and can be downloaded from the official website. The download package contains all necessary files, along with some tutorials on how we can FPDF.
Image description
In this tutorial, we will use;

  • save-pdf-in-folder.php
  • fpdf16 folder (PDFlib)
  • pdffile folder Code for save-pdf-in-folder.php:

    <!--?php

    require('fpdf16/fpdf.php');
    class SimpleTable extends FPDF
    {

    function generateTable($no)
    {

    for($i=1;$i<=10;$i++)

    {

    $this--->cell(20,10,$no,1,0,"C");

    $this->cell(20,10," * ".$i,1,0,"C");

    $this->cell(20,10," = ".$i*$no,1,1,"C");

    }

    }

    }

    $pdf=new SimpleTable();

    $pdf->AddPage();

    $pdf->SetFont('Arial','B',16);

    $pdf->generateTable(5);

    $dir='C:/wamp/www/pdf-php-tutorial/pdffile/';     //directory to save the PDF file

    $filename= "filename.pdf";                                       // PDF file name

    $pdf ->Output($dir.$filename);

    echo "Save PDF in the folder";

    ?>

In this file, we create a class SimpleTable that extends the FPDF class and generateTable() function that creates a table with cell content. The generate PDF will save in “C:/wamp/www/pdf-php-tutorial/pdffile/” directory and pdf file name is “filename.php”.

OutPut:
When we run ‘save-pdf-in-folder.php’ file, it will generate PDF and store in “C:/wamp/www/pdf-php-tutorial/pdffile/” directory and display output message as;

`Save PDF in the folder.`

Note:
Upon execution, the PHP script will generate a PDF file in your browser.

Conclusion
In the example above we illustrated how to make a PDF document and save it to the output folder. I hope you enjoyed reading it, please let us know by leaving your comments below.


This content originally appeared on DEV Community and was authored by Kodwings


Print Share Comment Cite Upload Translate Updates
APA

Kodwings | Sciencx (2022-06-23T12:21:57+00:00) How to save pdf file in the folder using php.. Retrieved from https://www.scien.cx/2022/06/23/how-to-save-pdf-file-in-the-folder-using-php/

MLA
" » How to save pdf file in the folder using php.." Kodwings | Sciencx - Thursday June 23, 2022, https://www.scien.cx/2022/06/23/how-to-save-pdf-file-in-the-folder-using-php/
HARVARD
Kodwings | Sciencx Thursday June 23, 2022 » How to save pdf file in the folder using php.., viewed ,<https://www.scien.cx/2022/06/23/how-to-save-pdf-file-in-the-folder-using-php/>
VANCOUVER
Kodwings | Sciencx - » How to save pdf file in the folder using php.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/06/23/how-to-save-pdf-file-in-the-folder-using-php/
CHICAGO
" » How to save pdf file in the folder using php.." Kodwings | Sciencx - Accessed . https://www.scien.cx/2022/06/23/how-to-save-pdf-file-in-the-folder-using-php/
IEEE
" » How to save pdf file in the folder using php.." Kodwings | Sciencx [Online]. Available: https://www.scien.cx/2022/06/23/how-to-save-pdf-file-in-the-folder-using-php/. [Accessed: ]
rf:citation
» How to save pdf file in the folder using php. | Kodwings | Sciencx | https://www.scien.cx/2022/06/23/how-to-save-pdf-file-in-the-folder-using-php/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.