开发者

C# prevent word from printing until the image within the document have fully loaded

开发者 https://www.devze.com 2023-02-27 00:35 出处:网络
This is a follow up question from my previous one found h开发者_如何学Pythonere I need to print a few pages each with images that need to be downloaded to be able to show them. But whenever I start u

This is a follow up question from my previous one found h开发者_如何学Pythonere

I need to print a few pages each with images that need to be downloaded to be able to show them. But whenever I start up the .doc with the assignment to print trough my C# application, it only prints the text because the images have not fully loaded yet.

That's when I made the thread mentioned above to find a solution. A solution was given and it worked just fine until yesterday when they replaced the PC with a newer one. This PC still has the same Word 2007 installed and when I tried to apply the above solution; it did not work anymore. Same result as before and I have no idea why.

I also tried delaying the print parameter by 10 seconds to give word some time to load the images, this works, but 10 seconds might not be enough for larger documents, and what if the connection would time-out?

So I need a solid way of preventing word from printing until after the images have been (down)loaded into the document, either using C# or the build-in Word options. Please help.


Instead of using Process you should use word interop.
refer follwoing links

  • http://www.codeproject.com/KB/printing/WordPrinting.aspx
  • http://www.codeproject.com/KB/office/WordPrint.aspx
  • http://msdn.microsoft.com/en-us/library/b9f0ke7y.aspx


Alright first off, sorry for the extremely late answer, I just found out this was still open.

Apparently all versions of Word (at least from 2003) have the option to load external content before printing built in. This includes Word 2010, only in 2010 it appears as if Word is ignoring the feature. I tested this on 3 machines, I don't know why, but in 2010 it get's ignored.

Now I noticed while testing how if you open a word document that was already running in the background, it will just bring it to the front, which gave me an idea that led me to the solution.

  • Step 1: Open the document you need to print.
  • Step 2: According to the number of external items to load, set up a timer (I gave the application half a second per image to load, this is way more then needed but better safe than sorry)
  • Step 3: Open the document again but this time using the print parameter.

Now the document will only be re-shown to the front and begin to print the already open document.

I do NOT really recommend this solution to anyone, since it's more of a work-around then a reliable fix. But it get's the job done.

0

精彩评论

暂无评论...
验证码 换一张
取 消