Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Open PDF directly from HTML Article on Android onLoad?

Avatar

Level 2

Hi,

since I don't want to convert PDFs to JPEGs with the Acrobat-Plugin (the builtin PDFViewers are good enough for this) I came up with another solution, that does work on iOS but does not on Android.

  1. Create a HTML-Article
  2. When the body is loaded it executed a JavaScript which points window.document.location.href to the PDF-Location which is in the same folder as the index.html is
  3. This works fine on iOS - when I open up the article it automatically opens up the PDF, the PDF is also beeing downloaded with the article

Is this a limitation of the Android-Viewer, that it won't auto-open files? Right now I have to implement a simple Button in that article that opens the PDF - this works! It does not work when I automatically open up the PDF via JavaScript.

Kind regards

Marcel

6 Replies

Avatar

Employee

Hi,

You can try delaying the script to open the PDF with setTimeout (in milliseconds):

setTimeout(function() {

     window.document.location.href = "path/to/pdf";

}, 100);

- Mike

Avatar

Level 2

Hi Mike-o, thanks for the hint. I tried this and now the Preflight-App  (Android) crashes when I open the HTML-Article.

Avatar

Employee

Confirmed with the engineers that Android doesn't have an embedded PDF viewing capability, like iOS. So you will have to open it externally by using window.open() or linking to it like you did with the button.

This script should work for both cases:

setTimeout(function() {

  var pdfFile = "path/to/file.pdf";

  if(navigator.userAgent.match(/Android/i)) {

    window.open(pdfFile);

  } else {

    window.document.location.href = pdfFile;

  }

}, 100);

You can also use window.open() for iOS, but the experience will be different, as that will open the PDF in the iOS In-App Browser.

- Mike

Avatar

Level 2

Hi Mike,

I tried your script, works fine on iOS and Desktop-Chrome but crashes the DPS Preflight App. When I then reoopen the DPS Preflight app and navigate to a regular HTML-Article the PDF opens. So the timeout somehow got stuck and then reexecutes ones I go back to a HTML-article .I even set the timeout to 2000 miliseconds. I also tried putting the script without the documentReady event. Same behaviour.

I uploaded the Original HTML-Files here: WeTransfer-Link

Avatar

Level 2

Somehow it started working? Did Adobe fix this that quick?

/edit: Somehow now other views trigger the PDF-opening command. I think it is because the whole card-layout thing itself is written HTML and JavaScripts and we have to distinguish the events?

Avatar

Level 2

Any news on this issue? Since everything is in HTML now, especially the "CustomStorefront/CardLayoutThingy" (is there a name for it?) JavaScript in my articles has a direct impact on it, right?