Skip to content

Instantly share code, notes, and snippets.

@tzmartin
Last active March 26, 2024 06:33
Star You must be signed in to star a gist
Save tzmartin/1cf85dc3d975f94cfddc04bc0dd399be to your computer and use it in GitHub Desktop.
Embedded File Viewer: Google Drive, OneDrive

Office Web Apps Viewer

('.ppt' '.pptx' '.doc', '.docx', '.xls', '.xlsx')

http://view.officeapps.live.com/op/view.aspx?src=[OFFICE_FILE_URL]

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=[OFFICE_FILE_URL]' width='px' height='px' frameborder='0'>
</iframe>

OneDrive Embed Links

Powerpoint

<iframe src="https://onedrive.live.com/embed?cid=CA582F2BC3AD1590&resid=CA582F2BC3AD1590%2133463&authkey=AFh1O3tkDLAQzzw&em=2" width="402" height="327" frameborder="0" scrolling="no"></iframe>

Excel

<iframe src="https://onedrive.live.com/embed?cid=CA582F2BC3AD1590&resid=CA582F2BC3AD1590%2136277&authkey=AHJ96YRJIbbJcec&em=2" frameborder="0" scrolling="no" width="800" height="346"></iframe>

Google Docs Viewer

Only files under 25 MB can be previewed with the Google Drive viewer.

Google Drive viewer helps you preview over 16 different file types, listed below:

  • Image files (.JPEG, .PNG, .GIF, .TIFF, .BMP)
  • Video files (WebM, .MPEG4, .3GPP, .MOV, .AVI, .MPEGPS, .WMV, .FLV)
  • Text files (.TXT)
  • Markup/Code (.CSS, .HTML, .PHP, .C, .CPP, .H, .HPP, .JS)
  • Microsoft Word (.DOC and .DOCX)
  • Microsoft Excel (.XLS and .XLSX)
  • Microsoft PowerPoint (.PPT and .PPTX)
  • Adobe Portable Document Format (.PDF)
  • Apple Pages (.PAGES)
  • Adobe Illustrator (.AI)
  • Adobe Photoshop (.PSD)
  • Tagged Image File Format (.TIFF)
  • Autodesk AutoCad (.DXF)
  • Scalable Vector Graphics (.SVG)
  • PostScript (.EPS, .PS)
  • TrueType (.TTF)
  • XML Paper Specification (.XPS)
  • Archive file types (.ZIP and .RAR)

Google Docs Viewer (Apps)

https://docs.google.com/a/[DOMINIO]/viewer?url=[FILE_URL]

Google Docs Viewer

https://docs.google.com/a/[DOMINIO]/viewer?url=[FILE_URL]

Google Drive

Sheets

<iframe src="https://docs.google.com/spreadsheets/d/13R8O15c_sZKZT2QRHom1z2SDA3E1O5chUvROnqHCkwE/pubhtml?widget=true&amp;headers=true" style="width:100%;height:100%;"></iframe>

Embedded File Viewer

Google Docs offers an undocumented feature that lets you embed PDF files and PowerPoint presentations in a web page. The files don't have to be uploaded to Google Docs, but they need to be available online.

Google Drive Viewer: Explicit PDF files

<iframe src="https://docs.google.com/viewer?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>
<iframe src="https://drive.google.com/viewerng/viewer?url=http://docs.google.com/fileview?id=0B5ImRpiNhCfGZDVhMGEyYmUtZTdmMy00YWEyLWEyMTQtN2E2YzM3MDg3MTZh&hl=en&pid=explorer&efh=false&a=v&chrome=false&embedded=true" frameborder="0"></iframe>

Google Drive Viewer: Non-PDF files (fileviewer URL)

To view Google Drive docs from fileviewer links, use the file ID as the srcid attribute in the iframe.

The file ID for your PDF (one that is already in Google Drive) can be found in the PDFs web address. When you open a PDF, it’s the garbage-looking piece of the URL (it will be between forward-slashes, “/”).

The file ID is highlighted in yellow.

In this case it’s the 0B3xoQi_oa7_hU2J5S1RQbFdqS3c

Source: http://docs.google.com/fileview?id=0B5ImRpiNhCfGZDVhMGEyYmUtZTdmMy00YWEyLWEyMTQtN2E2YzM3MDg3MTZh&hl=en&pid=explorer&efh=false&a=v&chrome=false&embedded=true

id: 0B5ImRpiNhCfGZDVhMGEyYmUtZTdmMy00YWEyLWEyMTQtN2E2YzM3MDg3MTZh

Or

Source: https://drive.google.com/file/d/0B5ImRpiNhCfGZDVhMGEyYmUtZTdmMy00YWEyLWEyMTQtN2E2YzM3MDg3MTZh/view?ddrp=1&hl=en#

id: 0B5ImRpiNhCfGZDVhMGEyYmUtZTdmMy00YWEyLWEyMTQtN2E2YzM3MDg3MTZh

Result:

<iframe src="https://docs.google.com/viewer?srcid=[put your file id here]&pid=explorer&efh=false&a=v&chrome=false&embedded=true" width="580px" height="480px"></iframe>

Resources

Info: http://www.labnol.org/internet/google-docs-viewer-alternative/

@NaveenDA
Copy link

NaveenDA commented Jan 5, 2023

@NaveenDA: Sure.
To be honest, I don´t think there is a "temporary" when it comes to Google. The just ingest everything we give them and use it for training models, etc. The thing is: there is no T&C for the Google Docs Viewer. You can use it without signing any form of agreement with Google. Means they can do pretty much whatever they want with the documents. At least in the boundaries of the regulation and law they are working under (US law as far as I know). But that doesn´t mean the Docs Viewer can´t be used. I would just mitigate liabilities when it comes to using this for 3rd party documents, eg user content. You can always ask the user before displaying his documents in the Google Viewer. At least here in the EU under the GDPR regulation that would be the safe way to go.

This is a great note - beware of using this solution if your're handling PII in your application. It's a bit concerning, even the widely popular chrome extension uses this server-side data passing to Google. What Google does with the data parsed through this viewer no one knows...

@neilmenon I totally agree, we should beware.

@seanhurwitz
Copy link

seanhurwitz commented Jan 27, 2023

@fabianareisantos: Hi, is there a way to increase the limit of 25mb?

Also wondering. did you get any help here?

@jesseagleboy
Copy link

Since the Labnol link in the document seems to be a 404, I think this new link from Labnol will be a huge help for anyone using the Google Docs: https://www.labnol.org/internet/direct-links-for-google-drive/28356/

@inglesuniversal
Copy link

Thanks for sharing @jesseagleboy we all appreciate any improvements to our knowledge base

@thaotp
Copy link

thaotp commented May 12, 2023

@tzmartin
Thank you for sharing.
Can I use those URLs for commercial purposes?

@perelin
Copy link

perelin commented May 12, 2023

@thaotp A lot of people using these tools, especially Google Docs Viewer, in their commercial applications. Google at least does not offer any dedicates Term&Conditions, which makes it a bit of a legal greyish area. Be aware: using these tools means sending data to the respective companies (Google, Microsoft), so be careful with user-related/-generated data, especially if you are under a privacy legislation such as GDPR.

@1TheMuffinMan
Copy link

Anyone know if there is a way with the google doc viewer to set the language in the url?

@thaotp
Copy link

thaotp commented May 15, 2023

especially Google Docs Viewer, in their commercial applications

@perelin
Thank you for your answer.
But could you show me some commercial applications which you've mentioned above?

@perelin
Copy link

perelin commented May 15, 2023

@thaotp I remember seeing it in a GDPR compliance tool I was using some time ago. These guys also use it: https://wordpress.org/plugins/embed-any-document/

@nakarimi
Copy link

Is there any limitation for embeding a file by google viewer?

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

or

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

randomly stop loading, but after realod again load the iframe.
If you set an iframe and refresh the page for some times, after 2-4-6 any posibility then suddenlty stop from loading the iframe, and again refersh then it is loading.

Is there any limiation or setting to set?

@devsideal
Copy link

devsideal commented Aug 19, 2023

Any one know how to view pdf with multiple pram like:

pdfUrl = "https://sadgh.invoicepdf?id=123&charges=12.4";
completeUrl = "https://docs.google.com/gview?embedded=true&url=${pdfUrl}"

I'm expecting the completeUrl should able to view pdf with requested parameter id and charges, But its not working
However the pdfUrl is able to generate pdf file with given param.

@korenevskiy
Copy link

The file I have saved with the name http://site.com/H8EBCDF How do I set a readable name (and extension) in the viewer? Maybe you need to specify an attribute in the viewer's address?

@LazZiya
Copy link

LazZiya commented Sep 5, 2023

Any idea how to embed the viewer so it switch between multiple files while in full screen mode? same as attachments in gmail...

@panwaranuj01
Copy link

panwaranuj01 commented Oct 23, 2023

I'm getting csp error

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'report-sample' 'nonce-xBproPZJNJgeAtDdKA4_bw' 'unsafe-inline' 'strict-dynamic' https: http: 'unsafe-eval'". Note that 'unsafe-inline' is ignored if either a hash or nonce value is present in the source list.
<iframe src="https://docs.google.com/viewer?url=https://km-test-s3-bucket.s3.amazonaws.com/KOMMUNICATE/APP/test/1ec30c318f5f1b55a74c50843d55398fc/_Attachment/78cc4437-438c-47af-a074-b40bac132df2_42508155ee50569f959f5c00644cbd09d629e7ec_KM_BUCKET_file_example_XLS_10.xls&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>

Can anyone help please

@btambawala
Copy link

I'm getting csp error

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'report-sample' 'nonce-xBproPZJNJgeAtDdKA4_bw' 'unsafe-inline' 'strict-dynamic' https: http: 'unsafe-eval'". Note that 'unsafe-inline' is ignored if either a hash or nonce value is present in the source list.
<iframe src="https://docs.google.com/viewer?url=https://km-test-s3-bucket.s3.amazonaws.com/KOMMUNICATE/APP/test/1ec30c318f5f1b55a74c50843d55398fc/_Attachment/78cc4437-438c-47af-a074-b40bac132df2_42508155ee50569f959f5c00644cbd09d629e7ec_KM_BUCKET_file_example_XLS_10.xls&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>

Can anyone help please

I am also getting the same error, did you find any solution?

@crsedano
Copy link

crsedano commented Jan 7, 2024

I'm getting csp error

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'report-sample' 'nonce-xBproPZJNJgeAtDdKA4_bw' 'unsafe-inline' 'strict-dynamic' https: http: 'unsafe-eval'". Note that 'unsafe-inline' is ignored if either a hash or nonce value is present in the source list.
<iframe src="https://docs.google.com/viewer?url=https://km-test-s3-bucket.s3.amazonaws.com/KOMMUNICATE/APP/test/1ec30c318f5f1b55a74c50843d55398fc/_Attachment/78cc4437-438c-47af-a074-b40bac132df2_42508155ee50569f959f5c00644cbd09d629e7ec_KM_BUCKET_file_example_XLS_10.xls&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>

Can anyone help please

I am also getting the same error, did you find any solution?
hi, did you find any solution?

@saravanapriyanm
Copy link

Lately we are getting a lot of Not Found errors using this:

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=[OFFICE_FILE_URL]' width='px' height='px' frameborder='0'>
</iframe>

It happens randomly and goes away randomly. Any ideas on what might be the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment