Can I send custom headers when using Google Docs viewer API?

I’m building an Android application that displays PDF documents from a remote server. I discovered that Google Docs viewer can handle PDF rendering by using their service endpoint. However, my PDF files are hosted on a server that requires authentication headers in the HTTP request to access the documents. I’m wondering if there’s a way to pass these required headers when making the request to Google Docs viewer service. Has anyone figured out how to include custom HTTP headers in this scenario? Any suggestions or workarounds would be helpful.

yea, you can’t send custom headers with Google Docs viewer. I made a small proxy server that manages the auth and sends the pdfs over to Google viewer. It’s a bit of a hassle to set up, but it does the job!

Google Docs viewer API doesn’t support custom headers, which can be challenging when working with protected content. I faced a similar issue last year with authenticated PDFs. What worked for me was to set up a middleware endpoint on my server that fetches the PDF using the necessary authentication and then serves it publicly through a temporary access token or session URL. The viewer can then access this temporary public URL without the need for custom headers. Another option is to download the PDF locally using your auth headers and then display it using a native PDF library like PDFBox or other Android PDF viewers. While this method is more complex, it offers complete control over the authentication flow.

Nope, Google Docs viewer won’t let you pass custom headers through their service. I hit the same wall trying to display docs from our protected file server. The viewer basically acts like a web browser fetching your PDF directly, so any auth requirements will just block it. I solved this by building a temp URL system - my backend generates short-lived public URLs for authenticated users. These URLs skip the auth requirement for a limited time, so Google’s viewer can actually reach the documents. You’ll need some server-side logic to check user permissions before creating these temp links, but it kills the header problem completely.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.