yoder

Solved ("hacked") FMP17 Cloud Printing of Javascript-Intense-Webviewer

Discussion created by yoder on Jun 21, 2018
Latest reply on Jul 20, 2018 by allardmax

****INTRO*****

This is a bit of a hack that worked for me, and temporarily solves what was a problem for me: Printing Images in the Webviewer that are BIG, downloaded externally, with a bit of added javascript complexity added...

 

****PROBLEM****

My solution uses some webviewers, up to 3 / record, (10-20MB JPEGs x 2, and a GoogleMap) each on its own record, printing up to 4 records / page. Some of the documents were multi-pagers up to 2GB in size.

 

FMP15 printed things "reasonably well".

FMP17 printed the first record's three webviewers just fine, and nothing thereafter - i.e. BLANK webviewers

 

The content of each webviewer was fairly complex including the IMG, as well as some fairly dense Javascript (specifically: calculations to call the IMG from an external resource using signed URL, and also some CANVAS overlay manipulations on the IMG.) NOTE: initially all of my calculations were placed directly in the webviewer.

 

The google-map webviewer however is not very complicated however. Just using Google's static MAP API, with a few custom tags.

 

******SOLUTION*******

Here's what I did.

 

I assumed that the blank webviewers was a latency issue. Many have felt this previously, although it isn't clear to what degree.

 

The first 3 steps were apart of my solution in FMP15.

 

1. My first step to make sure all Webviewers loaded, (which I had actually done back in FMP15), was for my multi-page PDF report to be printed ONE page at a time, and the pages aggregated onto each other. (instead of generating a huge PDF report all at once)

2. My next step is to force FMP to iterate through the pages before 'saving-as-PDF' in a 2-steps-forward-2-steps-back fashion. Therefore the iteration would look like this: GoToPage1->GoToPage2->GoToPage1->SaveAsPDF->GoToPage2->GoToPage3->GoToPage2->SaveAsPDF etc...

3. Adding a small delay between page turns seemed to help. (0.2 seconds for instance).

 

Now the steps below were things I added specifically in FMP17 to make things work:

 

4a. As mentioned above, all of my HTML/JAVASCRIPT was calculated inside the webviewer. I wondered if I placed the calculation into an external calculation field, if this would make a difference. Answer = NOPE. Still broke.

 

4b. Based on a hint seen somewhere else (can't remember where), I decided to generate all of the calculations AHEAD of time into their own text field, specific to each record. This helped tremendously. And I wish I knew exactly why!? It seems some of the heavy lifting was too much for the webviewer to do "live"...

 

5a. Next I wondered if some of the latency had to do with the timing of events within the generation of the webpage. I tried first to add delays to the 'window.onload' event in javascript. This had no effect. Ditto for adding delays to the 'image.onload'

 

5b. Next I hypothesize that FMP waits somehow to make sure that all IMG SRCs have been assigned? One of my previous scripts, would do the following steps 1. download a JPEG 2. assign the IMG SRC to the JPEG 3. overlay some simple things on a CANVAS onto the IMG. This seemed to break things.

 

So -- instead I did this -> 1. download a JPEG 2. Do some canvas manipulation things FIRST. 3. Finally - at the very end assign my IMG SRC to the JPEG.

 

Using these 5 steps I've been able to get almost 100% of the webviewers to load properly.

 

 

******COMMENTS******

1. This is a total hack. Why can't FMP can't get webviewer printing together? All of my calculations work just fine in Safari and Chrome. This has been a problem apparently since atleast FMP16.

 

2. FMP email support was not helpful. Friendly, but not helpful. I wish they could just tell you some workarounds... instead of just referring you to the forums.

 

3. I *wish* I knew which of the steps above was crucial, and exactly why it worked.

 

4. In particular - I want to know why FMP seems to load Webviewers completely, and sometimes not at all. How does it determine that the webviewer is fully loaded? Is it using 'onload' events? Some other criteria?

 

5. (For anyone who cares: This problem occurred whether I loaded the images from my external AWS S3 source, or whether I loaded the same images from my local server. It was slightly better using local images, but not much. It is for this reason that I think it has less to do with the size of the images, and more with the timing of events within the webpage.)

 

(6. BTW - slightly related question: I've been unable to get FMP-Cloud-Server to print any Webviewer content (ie. save-as-PDF). I can get it to save reports in its temporary file, but Webviewers are all blank. Even simple ones. I assume it doesn't process them at all?)

Outcomes