Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
746 views
in Technique[技术] by (71.8m points)

php - Creating a new PDF by Merging PDF documents using TCPDF

How can I create a new document using other PDFs that I'm generating?

I have methods to create some documents, and I want to merge them all in a big PDF, how can I do that with TCPDF?

I do not want to use other libs.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

TCPDF has a tcpdf_import class, added in 2011, but it is still "under development". If you don't want to use anything outside of TCPDF, you're out of luck!

But FPDI is an excellent addition to TCPDF: it's like an addon. It's as simple as this:

require_once('tcpdf/tcpdf.php');
require_once('fpdi/fpdi.php'); // the addon

// FPDI extends the TCPDF class, so you keep all TCPDF functionality
$pdf = new FPDI(); 

$pdf->setSourceFile("document.pdf"); // must be pdf version 1.4 or below
// FPDI's importPage returns an object that you can insert with TCPDF's useTemplate
$pdf->useTemplate($pdf->importPage(1)); 

Done!

See also this question: TCPDF and FPDI with multiple pages


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...