require_once('tcpdf/tcpdf.php'); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('John Smith'); $pdf->SetTitle('My Document'); $pdf->SetSubject('Testing PDF generation'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->AddPage(); $pdf->SetFont('helvetica', '', 10); $pdf->Write(5, 'Hello World'); $pdf->Output('example.pdf', 'I');
require_once('tcpdf/tcpdf.php'); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->setSourceFile('example.pdf'); $template = $pdf->importPage(1); $pdf->AddPage(); $pdf->useTemplate($template, 0, 0); $pdf->SetFont('helvetica', '', 10); $pdf->SetTextColor(255, 0, 0); $pdf->Write(5, 'Modified text'); $pdf->Output('modified.pdf', 'I');This example imports the first page of an existing PDF file, adds a new page to the document, uses the imported template for the page content, changes the font and text color, adds some new text to the page, and outputs the modified document to the browser as a PDF file. The TCPDF library is a package available through Composer.