Load a private Drive Presentation in ifram using url, however same thing is not working for PDF

Viewed 149

I am able to load a private Google Drive Presentation ifram using url, fileid & accesstoken , however same thing is not working for PDF.

fileId : 13zxxxxxxxx-xxxxxxxxx-

accessToken : ya29.xxxx-xxxx

(1) Working : private Google Drive Presentation

var  googleDrivefileUrl1 = "https://docs.google.com/presentation/d/"+fileId+"/embed?rm=minimal&access_token="+**accessToken**
var iframe1  = $('<iframe src="'+googleDrivefileUrl1+'" style="width: 90%; height: 100px">');
$('#previewDiv1').append(testIFrame1);

(2) Not Working: private Google Drive PDF

var  googleDrivefileUrl2 = "https://docs.google.com/file/d/"+fileId+"/embed?rm=minimal&access_token="+accessToken
var iframe2  = $('<iframe src="'+googleDrivefileUrl2+'" style="width: 90%; height: 100px">');
$('#previewDiv2').append(testIFrame2);

Is Google only support presentation, and not supported for PDF ?

Or am I doing some mistake ?

I will highly appreciate help & guidance.

1 Answers

It is possible to embed PDF files on your Google Drive into iframes, you just need to do it differently

The googleDrivefileUrl should be of the form

https://drive.google.com/file/d/XXX/preview

  • Note that https://docs.google.com is only valid for Google documents like Google Sheets, Google Docs etc.
  • For other documents on your drive, the URL begins with https://drive.google.com
  • You can also obtain the embed URL by:
    • Opening the pdf file on your Google Drive as preview
    • Click on the "three dots" and Open in new window
    • Click again on the "three dots" and Embed item...
    • This will direclty give you the correct emebdding code syntax
Related