0

I'm able to generate a PDF with PHP using FPDF, but I'm trying to create an on-screen preview of the generated PDF rather than jumping straight to the online PDF viewer.

<?php

 use setasign\Fpdi\Fpdi;
 use setasign\Fpdi\PdfReader;

 require_once('fpdf/fpdf.php');
 require_once('fpdi2/src/autoload.php');

 $pdf = new Fpdi();

 $pageCount = $pdf->setSourceFile('pdf1.pdf');

 for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++)
 {
    $tplIdx = $pdf->importPage($pageNo);

    // add a page
    $pdf->AddPage();
    $pdf->useTemplate($tplIdx, 0, 30);

    $src = $target_file;
    $pdf->Image($src,170,0, 30, 30);

 }

 $pdf->Output();

?>

The below code is what I've got at the moment, but i'm stuck on trying to generate it on the same page.

$pdf->Output();

The above segment seems to generate the PDF automatically onto a new page (opens online PDF viewer). I've searched through documentation and forums but can't seem to find anything.

Any help would be greatly appreciated. Thanks!

TJDev
  • 133
  • 3
  • 13

1 Answers1

0

FPDF creates a PDF file. A PDF file needs a viewer or reader application, which renders the content of the PDF document. You cannot just output it e.g. between some HTML fragments on a website.

So your question is not related to FPDF or FPDI at all but you're asking for a PDF viewer/render which you can use on your website.

The most popular solution for such task would be pdf.js. For other possible canditates you may try "html5 pdf viewer" on google.

Jan Slabon
  • 4,736
  • 2
  • 14
  • 29
  • Ah I see. But the same logic still applies. How would I output the generated pdf to be used via that pdf viewer? – TJDev Oct 18 '17 at 08:21
  • As any other PDF document. It doesn't make any difference if the PDF is generated dynamically or if it is a static one. – Jan Slabon Oct 18 '17 at 10:03