Checking progress of PDFs in viewport with Scroll PDF

75 views
Skip to first unread message

Alex Yasurek

unread,
Aug 18, 2016, 10:59:16 AM8/18/16
to Scroll Viewport Developers
Hi,

I have some links in my viewport theme that calls Scroll PDF to create a PDF. The link works fine and it creates the PDF as expected.

The problem is that there is no message telling the user that the PDF is being created, which could take a bit if the page is very big. Only indication is the browser tab spinning while it works to create the PDF

I know I can just call an alert or dialog when the link is clicked telling them to please wait while the PDF is created, but I would also like to make it disappear when the PDF is done. I am not sure how to do that though using javascript.

Is there a way to tell when the PDF creation and download has finished using javascript/jquery/ajax? 

Here is an example of the href of one of the links:

Jens Rutschmann (K15t Software)

unread,
Aug 18, 2016, 11:18:18 AM8/18/16
to scroll-vi...@googlegroups.com
Hi Alex,

I guess the best way to display the export status would be to display a
progress bar similar to our main export UI.

You can use the asynchronous REST interface for that. See the
asynchronous section in our docs here for an example script:
https://help.k15t.com/scroll-pdf-exporter/creating-an-export-using-the-rest-api-75367868.html
You can use the JSON data returned by the request made in the
'getStatusCode' function to retrieve the progress percentage.

Ultimately we want to provide a ready solution for a simple export
dialog, but we haven't implemented it so far.


Hope that helps a bit,
Jens

Alex Yasurek

unread,
Aug 18, 2016, 11:57:51 AM8/18/16
to Scroll Viewport Developers
Hi,

Is this able to be implemented in Javascript? I tried using AJAX to make the get call but that runs into the issue that it streams the data back but doesn't create the PDF.


Here is what I tried:

 $.ajax({
    type: 'GET',
    url: pdfURL,
    beforeSend: function() {
     console.log("Creating PDF")
    },
    success: function(data){
      console.log(data)
      console.log("Success with PDF")
    },
    error: function() {
      console.log("PDF could not be created");
    },
    complete: function(){
      console.log("PDF finished");
    }
  });


---------------------------------------------------

Then in the console i see:

Creating PDF

%PDF-1.4
%����
3 0 obj
<</BS<</S/S/W 0>>/A<</S/URI/URI(https://testlearn.mdsol.com/display/BALANCEprd/Balance+Glossary#BalanceGlossary-lot)>>/Subtype/Link/C[0 0 1]/Border[0 0 0]/Rect[274.61 693.6 291.71 706.31]>>
endobj
4 0 obj
<</BS<</S/S/W 0>>/A<</S/URI/URI(https://testlearn.mdsol.com/display/BALANCEprd/Creating+and+Managing+Lots#CreatingandManagingLots-creating_lots)>>/Subtype/Link/C[0 0 1]/Border[0 0 0]/Rect[89.66 602.33 146.48 615.04]>>
endobj
5 0 obj
<</BS<</S/S/W 0>>/A<</S/URI/URI(https://testlearn.mdsol.com/display/BALANCEprd/Creating+and+Managing+Lots#CreatingandManagingLots-editing_lot_properties)>>/Subtype/Link/C[0 0 1]/Border[0 0 0]/Rect[89.66 580.65 180.11 593.36]>>
endobj
6 0 obj
<</BS<</S/S/W 0>>/A<</S/URI/URI(https://testlearn.mdsol.com/display/BALANCEprd/Creating+and+Managing+Lots#CreatingandManagingLots-adding_items_to_lots)>>/Subtype/Link/C[0 0 1]/Border[0 0 0]/Rect[89.66 558.97 175.2 571.69]>>
endobj
7 0 obj
<</BS<</S/S/W 0>>/A<</S/URI/URI(https://testlearn.mdsol.com/display/BALANCEprd/Releasing+and+Revoking+Lots#ReleasingandRevokingLots-releasing_and_revoking)>>/Subtype/Link/C[0 0 1]/Border[0 0 0]/Rect[89.66 537.3 264.45 550.01]>>
endobj
8 0 obj
....
....( a bunch of more text
....
0000002034 00000 n 
0000003912 00000 n 
0000003976 00000 n 
0000004023 00000 n 
trailer
<</Info 15 0 R/ID [<21385e36916f0efff4b490122c2878be><59903f3e2b99e42f1222891d49846501>]/Root 14 0 R/Size 16>>
startxref
4238
%%EOF

Success with PDF

PDF finished


Jens Rutschmann (K15t Software)

unread,
Aug 18, 2016, 7:38:28 PM8/18/16
to scroll-vi...@googlegroups.com
Hi Alex,

instead of loading the PDF stream using AJAX, you should simply point
the browser to it.
Since we set application/octet-stream as content type, browsers open the
download prompt (or start downloading) automatically.

We're using this:
window.setTimeout(function() {
window.location.href = downloadUrl;
}, 500);

With the 'downlodUrl' coming from the JSON data you get when polling the
status.


Cheers,
Jens

Alex Yasurek

unread,
Aug 19, 2016, 12:21:44 PM8/19/16
to Scroll Viewport Developers
Hi,

I am a little confused on how I poll the status from javascript? 

When a user clicks REST url now, it will automatically either save it on their system or as them to save one the server is done creating it. From within the viewport theme, how would I poll the status of this?

Thanks

Jens Rutschmann (K15t Software)

unread,
Aug 24, 2016, 4:15:38 AM8/24/16
to scroll-vi...@googlegroups.com
Hi Alex,

you're probably using the synchronous REST API, which directly returns
the PDF stream.
The script I mentioned before uses the asynchronous API, that means you
do an AJAX request to initiate the request and get an export job ID
back, which you may use to poll for the export status.
Once the status is at 100% you get a download URL. Point the browser
using window.location to that URL to initiate the download.


We plan to publish a template recipe soon (hopefully by end of this
week) that shows how to get a simple progress dialog when exporting from
a viewport.


Hope that helps,
Jens

Alex Yasurek

unread,
Aug 24, 2016, 9:35:11 AM8/24/16
to Scroll Viewport Developers
Hi,

That sounds great. I will just wait for that template recipe then. Please let me know when you have added it to the documentation site.

Thanks

Jens Rutschmann (K15t Software)

unread,
Aug 29, 2016, 4:28:51 AM8/29/16
to scroll-vi...@googlegroups.com
Hi,

we've published a recipe here for using our exporters in viewports here:
https://help.k15t.com/scroll-viewport/exporting-with-scroll-exporters-from-a-vewport-115247277.html

Let us know if you're missing anything and how it worked for you.


Cheers,
Jens
Reply all
Reply to author
Forward
0 new messages