Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing documents 1

Status
Not open for further replies.

steve1rm

Programmer
Aug 26, 2006
255
GB
Hello,

vs 2005

I have the paths of documents in a datagridview. The documents can be different types, e.g. excel, word, paint, photoshop. However, most will be word documents

e.g. Path - c:\documents\job.doc
c:\documents\task.xsl
c:\documents\schedule.jpg

All these are in a database and are loaded into a datagridview.

The user will want to print all the documents that are contained in the grid.

So they will click a button and all the documents should print out.

Can anyone time me the best way to achieve this.

Many thanks for your time,

Steve
 
Well... This is a can of worms if I ever saw one. LOL!

One thing to keep in mind is compatibility... if say a word document was created in Office 2003 and is then attempted to be opened by a older version of Office then it will break on that older PC.

To get over that hurdle you probably only have a couple of options. One, you will need to make certain that all PCs that are going to be doing the printing are the most up to date (in comparison to the ones creating the documents). Or two, you reference into you project a third party document viewer that has some sort of API for Open, Print and Close(downside here is that it is third party dependent).

Going with Option 1... Create a new form with a webBrowser control and expose (make public or friend subs in the form that expose them through a reference) the webBrowser's methods of Navigate, Print and anything else you might find you need.

From your main form's print event (whatever that is) create a new instance of your new webbrowser form, then loop through your document paths to be printed... each time calling the webbrowser form's Navigate and Print Methods.

Additional Hurdles... be prepared for this to fail in many ways like incorrect software versions, missing installations like Acrobat Reader, Print driver errors, etc. I think you are going to have to play with it to find ways of minimizing human interaction as well. Also, you may want to use things like the webBrowser Navigated event to ensure that the document has been fully loaded prior to printing it.


There are probably many ways to to this, and maybe someone else here will find a better one.

Sounds like awesome fun to me though... Enjoy!


Senior Software Developer
 
Hello

Thanks for your idea, I was playing around with the process start, thinking that might be easier.

But ran into a few problems with the process start.

My code as follows:
Code:
      Try
                      Dim filePath As String = "C:\TestPrint.txt"
                      Dim psi As New ProcessStartInfo(filePath)
                      psi.Verb = "Print"
   
                      psi.UseShellExecute = False
   
                  Catch ex As Exception
   
                      MsgBox(ex.Message)
   
                  End Try

The exeception was "The specified executable is not a valid Win32 application"

Is this because its looking for an exe. instead of a txt file?

Many thanks for any other suggestions would be most helpful,

Steve
 
[tt]psi.UseShellExecute = True
p.StartInfo = psi
p.Start[/tt]


You are trying to "execute" a non-executable file by using "File Associations" (i.e. you exepect Notepad to open and to load and then print your file). This requires UseShellExecute to be set to True.

Also, you don't seem to have a Process.Start instruction so I added that.

Hope this helps.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top