1

I'm creating a pdf from formdata using fpdf (http://www.fpdf.org/).

Using Jquery I'm able to send the data to the pdf-creating script, and make the pdf appear in browser.

Now I'm trying to return the pdf-data to the formpage using fpdf's option to get the pdf as a string and echoing it.

$pdf_file_contents = $pdf->Output("","S");
echo $pdf_file_contents

My question now is

How do I use this data to preview the pdf under the form?
Do I need to use an pdf-viewer or can I use an <iframe> and am I doing this the correct way by returning the variable in an echo?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
FingeNB
  • 223
  • 2
  • 10

1 Answers1

0

I can think of two options:

  • Embed a PDF viewer and handle that call in JS. (Wait for the response from PHP and display the outputted file inline)
  • Trigger a redirect or load an iframe which displays $pdf->Output($filename,"F") from a temp file.

The result of $pdf->Output() is displayed using the browser's built-in viewer. If there is any output above that in the page FPDF will return an error to say FPDF error: Some data has already been output, can't send PDF.

FPDF error: Some data has already been output, can't send PDF

There might be some other option I'm missing but those would be my first suggestions.

Community
  • 1
  • 1
mimsy
  • 41
  • 6