====== PHP FPDF ====== ====== PHP FPDI ====== iniciar FPDI sin composer: [[https://stackoverflow.com/questions/47292751/fpdf-fpdi-error-fatal-error-class-setasign-fpdi-fpdftpl-not-found-in]] [[https://stackoverflow.com/questions/46792713/php-class-fpdi-not-found-but-the-file-defining-it-is-included]] require_once("libs/fpdf182/fpdf.php"); require_once("libs/FPDI-master/src/autoload.php"); $pdf = new \setasign\Fpdi\Fpdi(); Juntar dos pdf en un solo pdf [[https://stackoverflow.com/questions/28744300/fpdf-mergin-2-pdf-files-into-1-pdf-with-1-page]] require_once('fpdf.php'); require_once('fpdi.php'); $pdf = new FPDI(); $pdf->setSourceFile("Fantastic-Speaker.pdf"); $tplIdxA = $pdf->importPage(1, '/MediaBox'); $pdf->setSourceFile("Another-Fantastic-Speaker.pdf"); $tplIdxB = $pdf->importPage(1, '/MediaBox'); $pdf->addPage(); // place the imported page of the first document: $pdf->useTemplate($tplIdxA, 10, 10, 90); // place the imported page of the snd document: $pdf->useTemplate($tplIdxB, 100, 10, 90); $pdf->Output(); Ejemplos: $pdf = new \setasign\Fpdi\Fpdi(); //En pageCount se guarda la cantidad de hojas. $pageCount = $pdf->setSourceFile("facturas/202010/121_3341_20201019-0.pdf"); Importa y Rota segun el caso [[https://manuals.setasign.com/fpdi-manual/v1/the-fpdi-class/examples/]] setSourceFile('Laboratory-Report.pdf'); // iterate through all pages for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) { // import a page $templateId = $pdf->importPage($pageNo); // get the size of the imported page $size = $pdf->getTemplateSize($templateId); // create a page (landscape or portrait depending on the imported page size) if ($size['w'] > $size['h']) { $pdf->AddPage('L', array($size['w'], $size['h'])); } else { $pdf->AddPage('P', array($size['w'], $size['h'])); } // use the imported page $pdf->useTemplate($templateId); $pdf->SetFont('Helvetica'); $pdf->SetXY(5, 5); $pdf->Write(8, 'A complete document imported with FPDI'); } // Output the new PDF $pdf->Output(); ===== problemas con FPDI version de comprension ===== * [[https://stackoverflow.com/questions/12154190/fpdf-error-this-document-testcopy-pdf-probably-uses-a-compression-technique-w]] Usando Ghostscript: shell_exec( "gswin32 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=".$new_pdf." ".$old_pdf.""); Para solucionar el problema: 'This PDF document probably uses a compression technique which is not supported by the free parser shipped with FPDI. (See https://www.setasign.com/fpdi-pdf-parser for more details) * [[https://es.coredump.biz/questions/12154190/fpdf-error-this-document-testcopypdf-probably-uses-a-compression-technique-which-is-not-supported-by-the-free-parser-shipped-with-fpdi]] * [[https://www.ghostscript.com/download/gsdnld.html]] shell_exec( "gswin32 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=".$new_pdf." ".$old_pdf.""); * [[https://stackoverflow.com/questions/12154190/fpdf-error-this-document-testcopy-pdf-probably-uses-a-compression-technique-w/35407470]] $PDF = new Fpdi(); try { $PDF->setSourceFile('./pdf.pdf'); } catch (\Exception $exception) { if (aBoolFunctionToDetectThisParticularException($exception)) { exec('pdftk ./pdf.pdf output ./pdf_expanded.pdf uncompress'); $PDF->setSourceFile('./pdf_expanded.pdf'); } else { throw $exception; } } * [[https://stackoverflow.com/questions/17101747/fpdi-free-parser-that-supports-pdf-version-higher-than-1-4]] ====== DOM PDF ====== GitHUB: * [[https://github.com/dompdf/dompdf]] Cabecera y Pie de página: * [[https://ourcodeworld.co/articulos/leer/687/como-configurar-un-encabezado-y-pie-de-pagina-en-dompdf]] Paginas: * [[https://foro.noticias3d.com/vbulletin/showthread.php?t=394300]] require_once("dompdf/dompdf/autoload.inc.php"); use Dompdf\Dompdf; class Pdfgenerator { public function generate($html, $filename='', $stream=TRUE, $paper = 'A4', $orientation = "portrait") { $dompdf = new DOMPDF(); $dompdf->loadHtml($html); $dompdf->setPaper($paper, $orientation); $dompdf->render(); if ($stream) { $dompdf->stream($filename.".pdf", array("Attachment" => 0)); } else { return $dompdf->output(); } } } Ejemplo usando ob_start() y ob_get_clean()
abc abc abc abc
generate($html, "Liquidacion.pdf"); ?>