Long delay before showing large XOD files in WebViewer

55 views
Skip to first unread message

Ryan

unread,
Jun 7, 2016, 9:06:30 PM6/7/16
to PDFTron PDFNet SDK
Question:

What we are doing is when a user open a file for first time using Webviewer, we are converting the file to XOD format and then we are opening the XOD file in Webviewer.
 
How can we solve this problem? Basically we need webviwer to wait until whole conversion process is completed. May be in the webviewer we can show a loading gif saying “file conversion is in progress” once the conversion is done, the file should be loaded. Do you have any solution to implement in this fashion.

Answer:

You can actually stream the XOD to WebViewer as it is being converted. On the WebViewer side you switch to Streaming mode (passed in the WebViewer constructor).

On server side you use the ToXod function that returns a Filter, and connect to a FilterReader. In our .Net SDK see the WebViewerStreamingTest sample project. Here is the important code

pdftron.Filters.Filter filter = pdftron.PDF.Convert.ToXod(file, options);
pdftron.Filters.FilterReader fReader = new pdftron.Filters.FilterReader(filter);
byte[] buffer = new byte[64 * 1024]; //64 KB chunks
int bytesRead = 0;
bytesRead = fReader.Read(buffer);
Response.BufferOutput = false;
int totalBytesSent = 0;
while (bytesRead > 0) {
    // write bytes to the response stream
    Response.OutputStream.Write(buffer, 0, bytesRead); // only write bytesRead amount, as last write will be less than buffer size
    totalBytesSent += bytesRead;
    bytesRead = fReader.Read(buffer);
}

Note, in the sample the converted XOD bytes are not kept server side, but you could certainly do that and retain a local copy of the XOD for future usage.
Reply all
Reply to author
Forward
0 new messages