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.
我有一个Windows c#应用程序,我想在webserver上显示一个pdf文件,该文件添加到我的表单中的acrobat com对象中。
pdf.loadfile(@"http://somewhere.com/nowwhere.pdf")
As my pdf is large, the application seems to hang till the entire file is loaded.
由于我的pdf很大,应用程序似乎一直挂起,直到加载整个文件。
I want to read the large file without the user being under the perception that the application is hung.
我想读取大文件,而用户不会认为应用程序已挂起。
6 个解决方案
#1
3
I would do the following:
我会做以下事情:
- Create another thread to import the pdf.
- Display some kind of a progress bar to the user. perhaps with a cancel button.
创建另一个线程以导入pdf。
向用户显示某种进度条。也许有一个取消按钮。
#2
1
Sorry, don't have any code, but this article on asynchronous file I/O might be of help to you:
抱歉,没有任何代码,但有关异步文件I / O的这篇文章可能对您有所帮助:
http://www.devsource.com/c/a/Using-VS/Making-Asynchronous-File-IO-Work-in-NET-A-Survival-Guide/
#3
1
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.
第一个是打破它并像一些在线书籍一样加载页面。这有点烦人,但会节省你的加载时间。我认为ItextSharp有一些功能可以做到这一点。
Second try compression. again itextsharp has tools that allow for this
第二次尝试压缩。再次,itextsharp提供了允许这样做的工具
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.
我的第三个建议是检查这个帖子。选择一些书呆子加载短语并使用动画gif来分散您的客户从长时间加载的注意力。显然这是最后的手段,但可能有用。
#4
1
Use a Worker Thread. (BackgroundWorker for example)
MSDN Link to BackgroundWorker
使用工作线程。 (例如BackgroundWorker)MSDN链接到BackgroundWorker
#5
1
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.
如果必须从UI线程运行PDF.LoadFile,则可以使用HttpWebRequest在BackgroundWorker中下载该文件,将其保存在本地,然后在Invoke'd(UI线程)函数中调用pdf.loadfile()。
#6
0
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.
可能出现的问题(我从未使用过Acrobat的COM PDF查看器)是PDF对象期望在UI线程上。在这种情况下,你最终会遇到问题。
#1
3
I would do the following:
我会做以下事情:
- Create another thread to import the pdf.
- Display some kind of a progress bar to the user. perhaps with a cancel button.
创建另一个线程以导入pdf。
向用户显示某种进度条。也许有一个取消按钮。
#2
1
Sorry, don't have any code, but this article on asynchronous file I/O might be of help to you:
抱歉,没有任何代码,但有关异步文件I / O的这篇文章可能对您有所帮助:
http://www.devsource.com/c/a/Using-VS/Making-Asynchronous-File-IO-Work-in-NET-A-Survival-Guide/
#3
1
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.
第一个是打破它并像一些在线书籍一样加载页面。这有点烦人,但会节省你的加载时间。我认为ItextSharp有一些功能可以做到这一点。
Second try compression. again itextsharp has tools that allow for this
第二次尝试压缩。再次,itextsharp提供了允许这样做的工具
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.
我的第三个建议是检查这个帖子。选择一些书呆子加载短语并使用动画gif来分散您的客户从长时间加载的注意力。显然这是最后的手段,但可能有用。
#4
1
Use a Worker Thread. (BackgroundWorker for example)
MSDN Link to BackgroundWorker
使用工作线程。 (例如BackgroundWorker)MSDN链接到BackgroundWorker
#5
1
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.
如果必须从UI线程运行PDF.LoadFile,则可以使用HttpWebRequest在BackgroundWorker中下载该文件,将其保存在本地,然后在Invoke'd(UI线程)函数中调用pdf.loadfile()。
#6
0
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.
可能出现的问题(我从未使用过Acrobat的COM PDF查看器)是PDF对象期望在UI线程上。在这种情况下,你最终会遇到问题。