0

I would like to make a web app using Google Apps Script where users get pages of a pdf shown one by one.

Using a pdf library I can get the base64 data of each page of the pdf. But using none of these ways for displaying it works:

<object type="application/pdf" data="data:application/pdf;base64,...">

<embed src="data:application/pdf;base64,...">

<iframe src="data:application/pdf;base64,...">

Displaying an image using <img src="data:image/png;base64,..."> does work.

All mentioned methods do display the single pdf page when putting it in an html-document.

I thought it had to do with the https requirement mentioned on https://developers.google.com/apps-script/guides/html/restrictions, but looking at How can I refer to a Data URI in https? I learned the data URI should be https (since the Google web app is served over https).

Any suggestion, like forcing the data URI to be 'interpreted' as an https-URI OR converting the pdf page to an image (not prefered, since I figure it would produce unnecessary overhead), is welcome. Since the single page pdfs aren't needed to be saved like that, saving each page on Google Drive and using its file-URL would also produce overhead (and is thus not prefered either).

SVerlinden
  • 13
  • 5
  • I found an alternative: I add and use pdf-js to render the page, circumventing the use of iframes (and built-in pdf-renderers). – SVerlinden Jun 11 '21 at 10:10

1 Answers1

0

If your pdf is located on your Google Drive, you can embed it with the preview link:

<iframe src="https://drive.google.com/file/d/XXX/preview"></iframe>

Whereby XXX is to be replaced with the file id.

Make sure to share the pdf as Anyone on the Internet with this link can view.

ziganotschka
  • 25,866
  • 2
  • 16
  • 33
  • I can't use that: it does not allow me to control which page of the pdf is shown. Unless you know how to manipulate the pdf once it it shown using that link? – SVerlinden Jun 09 '21 at 11:50
  • I believe that with` – ziganotschka Jun 09 '21 at 12:05
  • Well, using the pdf library I can create single page pdfs, so that would allow me to control which page is shown. But saving these first on Drive takes more overhead than just using its base64 data. – SVerlinden Jun 10 '21 at 06:13