Creating a new PDF by Merging PDF documents using TCPDF
Merging two PDFs in PHP
What is PDF?
The Portable Document Format.
PDF
stands for "Portable Document Format". Essentially, the format is used when you need to save files that cannot be modified but still need to be easily shared and printed. PDF is one of the most commonly used file types around.
PDFs generally contain shareable data, such as text or photo documents etc., and are accessible to anyone who has a computer or smartphone. Unlike a Word file, which requires Microsoft Word to view or edit, most browsers will open a PDF.
How to merge PDFs?
You can merge several documents into one. In PHP, you have a library called TCPDF which allows you to combine one or more PDF documents to one single document.
In this article, we will create a new PDF by Merging PDF documents using TCPDF.
Download the PDFMerger-tcpdf.zip here.
- Unzip it and copy it to the PHP server.
- Copy the PDF files into the same folder that you want to combine.
- Open the file: merge-pdf-example.php
- Provide PDF filenames and run it in the PHP server.
- TEST.pdf (output) is downloaded.
merge-pdf-example.php
<?php
include 'PDFMerger.php';
use PDFMerger\PDFMerger;
$pdf = new PDFMerger;
// 1 is pageNumber ,'1,2,3' are pdf pagenumbers that you want to include in merge
$pdf->addPDF('pdf1.pdf', '1')
->addPDF('pdf2.pdf', 'all')
->merge('download', 'TEST.pdf');
?>
Demo
Comments
Post a Comment