tags:

views:

233

answers:

6

I have a windows c# application and I want to display a pdf file, located on a webserver, in an acrobat com object added to my form.

pdf.loadfile(@"http://somewhere.com/nowwhere.pdf")

As my pdf is large, the application seems to hang till the entire file is loaded.

I want to read the large file without the user being under the perception that the application is hung.

+1  A: 

Sorry, don't have any code, but this article on asynchronous file I/O might be of help to you:

http://www.devsource.com/c/a/Using-VS/Making-Asynchronous-File-IO-Work-in-NET-A-Survival-Guide/

quickcel
A: 

Three suggestions.

the first would be to break it and load a page at a time like some online books do. This is a bit annoying but would save you the loading time. I think ItextSharp has some functionality to do this.

Second try compression. again itextsharp has tools that allow for this

My third suggestion would be to check out This thread. choose a few nerdy loading phrases and use an animated gif to distract your client from the long loading time. Obviously this is a last resort, but could useful.

WaxEagle
+1  A: 

Use a Worker Thread. (BackgroundWorker for example)
MSDN Link to BackgroundWorker

PersistenceOfVision
+3  A: 

I would do the following:

  1. Create another thread to import the pdf.
  2. Display some kind of a progress bar to the user. perhaps with a cancel button.

RWendi

RWendi
The COM object may require running on the UI thread making #1 not possible and #2 blocking as well.
sixlettervariables
I've never came acrooss of a COM object requires UI thread. In what case will this happen?
RWendi
A: 

Obviously, if you can use a background thread to do the loading - you'd be all set:

Pdf pdf;

void ShowPdf() {
   if (this.InvokeRequired) {
     this.Invoke(() => this.ShowPdf());
   }
   // give pdf a window...
}

void LoadPdf() {
   System.Threading.ThreadPool.QueueUserWorkItem(() => {
      pdf.LoadFile("http://example.com/somelarge.pdf");
      this.ShowPdf();
   });
}

The issue that may come up there (I've never worked with Acrobat's COM PDF viewer) is that the PDF object expects to be on the UI thread. In that case, you'll end up with issues.

Mark Brackett
+1  A: 

If PDF.LoadFile has to run from the UI thread, you can download the file in a BackgroundWorker with HttpWebRequest, save it locally, then call pdf.loadfile() in an Invoke'd (UI thread) function.

Coderer