pdfiframegoogle-document-viewer

Google Document Viewer external URL


Is there a way to supply Google Docs Viewer with a source from a proxy download? Such as from https://www.url.com/download.php?file=fdg46fgd (random download code).

The download script headers look like this:

header("Content-Type: " . $mime);
header("Content-Disposition: attachment; filename=\"$name\"");

header("Content-Length: " . $size);
header("Cache-Control: private");

It prints the contents after the headers are established. This works fine when you enter the link into the browser and works as expected. I have also tried using inline instead of attachment but the Google Doc Viewer always displays "No Preview Available". The document viewer code looks like this:

<iframe src="https://docs.google.com/gview?url=https://www.url.com/download.php?file=fdg46fgd&embedded=true" style="width:800px; height:700px;" frameborder="0"></iframe>

I have tried using different documents such as pdfs, docx, etc.

If I use a direct link it will display properly, but not when using the download script. I have seen people using a download script based URL before and it seemed to work for them. Does this not work with Google Doc Viewer anymore? Any suggestions? Any help appreciated, thanks!


Solution

  • Because the process in your download URL have validation (ex: check login, limit user, ...). Remove this validation code, Google Doc Viewer can be open file you want.