I’m trying to display a PDF file using an iframe with Google’s document viewer service, but I keep running into issues. Here’s the code I’m using:
<iframe width="800" height="600" src="https://docs.google.com/viewer?url=https://example.com/files/documents/manual.pdf&embedded=true" frameborder="0"></iframe>
The problem is that instead of showing the PDF content, I get an error message saying the document cannot be retrieved or I don’t have the right permissions to view it. I thought maybe my internet provider was blocking Google’s viewer, but when I test other websites that use the same Google docs viewer feature, they work just fine. The PDF file exists and is accessible when I visit the URL directly in my browser. Has anyone else experienced this issue? What could be causing this problem and how can I fix it?
Google’s viewer has gotten super unreliable lately. I’ve had the same issues - it works sometimes, then randomly breaks even with files set up correctly. It’ll just refuse to load docs from certain domains for no obvious reason. I switched to PDF.js and it’s way more reliable. You can host it yourself or grab it from a CDN. Mozilla’s PDF.js viewer is another solid option that doesn’t have all the permission drama. Honestly, Google’s viewer was never meant for production sites anyway. You’ll probably save yourself headaches down the road by switching to a proper PDF library now.
Had this exact problem a few months ago. The issue was PDF file headers - my Content-Disposition header was set to ‘attachment’ instead of ‘inline’. Google’s viewer can’t display files unless they’re served inline. Check your server config or .htaccess file to make sure PDFs have the right headers. Also, some hosting providers block external services from accessing files directly. If you’re on shared hosting, that’s probably it. Try uploading the PDF somewhere else temporarily and see if that fixes it.
yeah, sounds like CORS issues. google’s viewer can be picky with domains. maybe try hosting the PDF elsewhere or see if ur server is blocking google’s bots.