How to create a PDF stream in PHP?

Asked

Viewed 2,060 times

5

Is there any alternative to implement a stream of Pdfs files that are on the server?

I would like the browser to download the pdf as it is viewed.

Same as the preview of google books

  • I am looking for some implementation that allows stream PDF files, viewing in the browser. As well as the preview of google books

  • I don’t know enough about the subject to try to give an answer, but I found this link that can be of some help: http://www.techper.net/2008/02/27/4-ways-to-stream-pdf-and-some-tips/

  • 1

    I know it’s not exactly what you’re looking for, but a solution client-side able to load Pdfs progressively from the server does not solve? If yes of a look at flexpaper and in the pdf.js (the second is an open source Mozilla project and works very well)

  • The ideal of this idea is that you do not need to copy the PDF to your devices. Leave it in one place and access from anywhere. As if it were a googledrive

4 answers

3

I don’t know if that would help you, but could an embed of PDF help you? Just put the PDF embed from Google itself, look at the code below

<iframe src="http://docs.google.com/gview?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>

See an example on Jsfiddle

  • I will not provide the google documents, I will provide pdfs from my data server

  • You could quietly switch the google documents link to your documents from your server.

  • Just change the Google pdf url to your file link

  • I think I’ve tried that, but the production environment is intranet. If I’m not mistaken, it didn’t work, but I’ll try again.

  • To my knowledge PDF does not support streaming, nor is it meant to work if it is incomplete. This tool from Google Docs is interpreting the PDF file and generating a resulting HTML, thanks to this it is possible for them to make the snot they want with the PDF, nor need to have PDF reader in the user’s machine. You can try to elaborate something similar, however you said it is an Intranet site and certainly the fast local network traffic eliminates any need to optimize the use of band, I do not understand what is the sense of doing this in your context.

1

Use the framework PDF.js is very simple and easy.

0

I’m afraid there’s no way to control through the server since it’s the browser that "pulls" the PDF file. It is the browser that gradually downloads the file.

  • But there is some alternative that allows the browser to receive this PDF data and render it?

  • To my knowledge there is no way to control it. But because I would like to have control?

  • I have PDF files in an application of electronic documents, but they are too heavy to download the complete file for viewing. It would be better to stream the pages of the PDF as it is viewed.

  • I believe that Chrome already downloads the file gradually, and shows without waiting to reach the end, but does not lock the download. Anyway, wouldn’t it be better to break the files into several in this case? Applications like Ghostscript serve to break the PDF files by pages.

0

Adapting this answer: Suppose you want to stream the link "http://bar.com/foo.pdf"

$data = file_get_contents("http://bar.com/foo.pdf");
header("Content-type: application/octet-stream");
header("Content-disposition: attachment;filename=YOURFILE.pdf");

echo $data;

Not exactly what you need, but it’s a great start.

  • file_get_contents not a good idea in this case. Load all to variable and then give one echo will waste memory for nothing. You could use the function readfile instead...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.