Big Size streaming cloudfront url is not working in HTML5 webviewer

493 views
Skip to first unread message

Jayaseelan A

unread,
Sep 16, 2014, 6:04:06 AM9/16/14
to pdfnet-w...@googlegroups.com

Hi,

We have created sample application for cloudfront signed URL file Size: 40.9kb, 13mb, 21.1mb to view the web viewer is working in all browsers, but the file size 203.6mb is not working in all browsers.

 I’m working in a C# 4.0 web application project and below is the code snippet that I’m using that is failing.

 

public void ProcessRequest(HttpContext context)

    {

        string MethoodName = context.Request.QueryString["MethodName"].ToString();

        string FileName = context.Request.QueryString["val"].ToString();

        switch (FileName)

        {

            case "1":

                FileName = "https://d22fr6b877098t.cloudfront.net/40.8KB.xod?Expires=1413453081&Signature=AwE9S2WQt~ZjXMygWQIsB~5hQ5CSrdX8hTBQAJHCWd5NDtmNAOZBEpj3Ayv5766KCb4Y7QUFNGXfxOv1eK8efrtDZPKqOIGQLUHpBSK0USMUFdbiRIl0s~J9yH7612VrD6Fnxhegk7TiZGiYg~B27Uo00i7lUy73l32GsJ~6bZeIsIq1xufTvhmoq0XDXbf~S7XGUn7ZkSPYx3e2MoSRIAi~xVu73y3XtldguEX7C9FDiPnUjZY8-xGqlzjA0hyTVw4tn-qLlbMPZl~i~qhCW8Yut0wOnT7op~bbNwff4b6XrOBgfvmnR6gImUp75UI22mylGirley-ZzrvPuNU3hQ__&Key-Pair-Id=APKAIAXTUI3DQN6LEABQ";

                break;

            case "2":

                FileName = "https://d22fr6b877098t.cloudfront.net/21.1MB.xod?Expires=1413453023&Signature=CTIjwkU2r-sVk2ayE3pj4icV7pDv6NL95b1CX6y6vYQ7vMKRXn8d5UfJB-MUvGA78qpINWFjK~r9UGFok0~s1XV1zBzQbTt7aLeaRJdI8wyn44t~APYbtBNsaN5tPwZbZPIm8fGSkvubLyJUgD9HR0TH9rfo-T5uxGx2JZVSWUcSt-AYrMRVlLn6ouy3R9RVNmoLwTnaCiVfTSk7lwT2xgGtFv~jJjqzUMSfiaDWR9e7yLuTz92~PiN8j3HWMK~cRXcEoGcktybofqJcFXubeewJ6D1gkKaaDrgBHbpKxoIvWY~LHEri~qoA2DC~oTMndEoOPHZ85usk0L4KZdpTiQ__&Key-Pair-Id=APKAIAXTUI3DQN6LEABQ";

                break;

            case "3":

                FileName = "https://d22fr6b877098t.cloudfront.net/13MB.xod?Expires=1413452968&Signature=ClsF~PGkmQUdQpznNu8Q0miuJBfkFt-6l1CMaeOMKU8bPZvitGSyzZf8CNOmb0NIT234-sntLELFshGB0aXXCpFcGTNKeKDFdFcdDFJFEN0Ms5f9RTW9sMErhIoU~DntmqFiZ9gS5NDLB2lPx6BAPH-h~8GReZ1Soh42d~6ChWS8nXpa4ymsbPZDCNM5wm9mIevbv9kSKJ59gq0BVoiii13gE99CRFwJe0iTiob268K8nXcga7okhKbbRX9sA7scsXjH~D6Li5ngK147lSNSAwjMmZma9vscxXxsaAB7K7e~2gxXGQ5P~P9gVkxx5i1pL-zqLEQOVkEZBNEC5MhY4g__&Key-Pair-Id=APKAIAXTUI3DQN6LEABQ";

                break;

            case "4":

                FileName = "https://d22fr6b877098t.cloudfront.net/203.6MB.xod?Expires=1413452991&Signature=Jcn3ULVJ1WQXn6YBEYieqccfOtXzQzlotb1cj9b4Df2jixSZwa~lnUv3Zpn3tpM3XObC--s1frKT7l3sRaUWo9B4Tbk5R-DpNrGzbLSife6ciSlZ~THBt6WmeQIZRJMZlMxMtF9bDNWaz1sEETljCNiDMyrshmnNwC2jVroPQ6v9eS2Z1o~~dooR0ugtf7k18V~nknWxhL9iA3px7E3WMd6u4Knp~fZSGqbTW0I00nU2LNOY9xWyc3RVScjCmAWBp7ty4m~5CVShQ2f5q2QlOLN18kH0sdIROV8YtzVpJ9tneAWfZyjxW72uqrBl9IUoKJ5djoEE1ArfSWyLDP~dVQ__&Key-Pair-Id=APKAIAXTUI3DQN6LEABQ";

                break;

            default:

                break;

        }

        if (MethoodName == "BytesURL")

        {

            try

            {

               

                System.Net.WebRequest wreq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(FileName);

                using (System.Net.HttpWebResponse wresp = (System.Net.HttpWebResponse)wreq.GetResponse())

                using (System.IO.Stream mystream = wresp.GetResponseStream())

                {

                    using (System.IO.BinaryReader reader = new System.IO.BinaryReader(mystream))

                    {

                        int length = Convert.ToInt32(wresp.ContentLength);

                        context.Response.Clear();

                        context.Response.Buffer = false;

                        context.Response.BufferOutput = false;

                        context.Response.ContentType = "application/vnd.ms-xpsdocument";

                        context.Response.AddHeader("Content-Length", length.ToString());

                        byte[] buffer = ReadFully(mystream);

                        if (context.Response.IsClientConnected)

                        {

                            context.Response.OutputStream.Write(buffer, 0, buffer.Length);

                            context.Response.OutputStream.Flush();

                        }

                    }

                }

                HttpContext.Current.ApplicationInstance.CompleteRequest();

            }

            catch (Exception ex)

            {

            }

        }

 

    }

 

    public byte[] ReadFully(System.IO.Stream input)

    {

        byte[] buffer = new byte[4 * 1024];

        using (System.IO.MemoryStream ms = new System.IO.MemoryStream())

        {

            int read;

            ms.Flush();

            while ((read = input.Read(buffer, 0, buffer.Length)) > 0)

            {

                ms.Write(buffer, 0, read);

            }

            return ms.ToArray();

        }

    }

 

 

The error message I get is as follows.

 

Firefox: Loading long time.

Chrome: script crashes.

IE: Not loading

System Configuration,

Windows 7 64 bit

Browsers: Firefox 32, IE 11, Chrome 37.0.2062.120

Can you please look at the 204mb URL and reply why the big size URL are not launched in the pdftron web viewer ASAP

Looking forward to your reply.

Matt Parizeau

unread,
Sep 16, 2014, 2:23:05 PM9/16/14
to pdfnet-w...@googlegroups.com
Hi Jayaseelan,

Please do the following:

1. Turn streaming off, as it causes slow performance on large files. (When streaming is on, it can be memory intensive and it is not as efficient in "seeking" or skipping ahead in files).
new PDFTronWebViewer({
...  
 streaming: false
}

2. Make a modification to ReaderControl.js to disable cache hinting. By default, the WebViewer appends a query string to help browsers cache byte range parts. However, CloudFront does not allow extra query parameters, and thus gives an error. You may have noticed it not working and that's why you've implementing a streaming solution (i.e. downloading the entire file). With the fix below you should be able to use the URLs from the initialDoc directly.

The solution is to prevent WebViewer from adding cache hints.
To remove the query string from the URL you'll have to go into ReaderControl.js and MobileReaderControl.js, find theLoadDocument function, and where it says cacheHinting.CACHE, change this to cacheHinting.NO_HINT.
e.g.  partRetriever = new CoreControls.PartRetrievers.HttpPartRetriever(doc, cacheHinting.NO_HINT, decrypt, decryptOptions);

Doing so should make your document work on all browsers, and load significantly faster as well.
Let me know if you run into any other issues.

Matt Parizeau
Software Developer
PDFTron Systems Inc.
<w:LsdException Locke
...

Jayaseelan A

unread,
Sep 17, 2014, 5:07:12 AM9/17/14
to pdfnet-w...@googlegroups.com
Thank you for your reply
<w:LsdException Locke
...

Jayaseelan A

unread,
Jan 13, 2015, 9:16:47 AM1/13/15
to pdfnet-w...@googlegroups.com
Matt,
 My problem is that IE10& IE11 is very slow/not loaded to load big size(more than 300 pages) streaming url document.but the other browsers(Chrome & Firefox) to view first page of the document and other pages load backgroud.
Note:
I Changed the above mentioned your way,
new PDFTronWebViewer({
...  
 streaming: true
}
partRetriever = new CoreControls.PartRetrievers.
HttpPartRetriever(doc, cacheHinting.NO_HINT, decrypt, decryptOptions);

Please fix this issue ASAP.
Am waiting for your reply.

Thanks
jayaseelan
...

Matt Parizeau

unread,
Jan 13, 2015, 8:18:39 PM1/13/15
to pdfnet-w...@googlegroups.com
Hi Jayaseelan,

As I mentioned in my previous response you need to have the streaming option set to false. This streaming option refers to streaming of the XOD conversion directly to the viewer and should not be used if you want good performance on large documents because it causes the entire file to be downloaded.
new PDFTron.WebViewer({
...  
 streaming
: false
}

Matt Parizeau
Software Developer
PDFTron Systems Inc.

jayas...@contentraven.net

unread,
May 16, 2017, 11:38:26 AM5/16/17
to PDFTron WebViewer
Hi all,
We are facing byte range request issue from xod file,using latest webviewer.
As we changed the above mentioned code in our end.
step1:
new PDFTronWebViewer({
...  
 streaming: false
}

step 2: In basereadercontrol.js
partRetriever = new CoreControls.PartRetrievers.HttpPartRetriever(doc, cacheHinting.NO_HINT, decrypt, decryptOptions);

step 3: in Corecontrolutil.js
but the streaming value is changed to true the following code because the byte range status value is 200.
 window.ControlUtils.byteRangeCheck(function (status) {
                            // if the range header is supported then we will receive a status of 206
                            if (status !== 206) {
                               streaming = true;
                                console.warn('HTTP range requests not supported. Switching to streaming mode.');
                            }
how can i usebyte range requests to fetch parts from XOD file?

Thanks

On Tuesday, September 16, 2014 at 3:34:06 PM UTC+5:30, Jayaseelan A wrote:

Justin Jung

unread,
May 16, 2017, 7:58:22 PM5/16/17
to PDFTron WebViewer
Hello,

WebViewer attempts to detect if range-requests are supported on your server by making a range request to ReaderControl.html. If you really want to force range-request to happen for your XOD file and it's expected that the HTML file doesn't support range request, you can change byteRangeCheck function in ControlUtils.js to 

exports.ControlUtils.byteRangeCheck = function(onSuccess, onError) {
  onSuccess(206);
};

However, if your server actually doesn't support range request, than the document won't load at all. In that case, you need to configure your server to support byte range requests.

Justin Jung
Reply all
Reply to author
Forward
0 new messages