Click here to Skip to main content
15,885,875 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi Team,
VB newbie here.
I have created a form in VB.Net (VS 2013).
In this form I have a Listview object.
This object contains a list of office documents of different types.
eg Work, Excel, Visio etc

A print button has been added to the form.
What I am now missing is the "print" code.

Is there a way that I can print these files to the default printer?

I have tried following some of the examples, but I am finding them a little confusing.

cheers,
dg
Posted
Updated 23-Feb-14 12:51pm
v2
Comments
Sergey Alexandrovich Kryukov 23-Feb-14 19:49pm    
Not quite clear: "print a list of documents" means printing a list, not documents themselves... What exactly do you want to print? Or are you talking about silent printing of the documents from list?
—SA
dgoogle 24-Feb-14 20:54pm    
Sergey,
thanks for you input.
What I am trying to do is print all of the documents in the list.

So this is what I have:
1. form with a Listview object
2. I am able to drag files from explorer to the list.
3. Now I would like to create a "Print" button that will print each document.

cheers,
dg
Sergey Alexandrovich Kryukov 24-Feb-14 21:18pm    
I see, thank you. I think Solution 1 answers your question; see also my comment.
—SA

1 solution

Well, you HAVE to run the Office applications to print the documents. What else are you going to use to open the documents, parse them to render the page and printer them?? Without Office, you have no code that knows how to interpret and render the documents!

You don't neccessarily need Office, but you will need some library that knows the Office document formats and knows how to render them correctly.
 
Share this answer
 
Comments
dgoogle 24-Feb-14 20:59pm    
Hi Dave,
you are spot on, I need to use some library that has Office render functions.
So the question now is;
1. Does such a library already exist ?
2. If it does, what is it and what are the functions ?

I guess, something like Process.Start() that will print out a document.

Actually, it would be like the way you can print a document from Windows Explorer;
You right click on a document and it will 'launch' the associated application, print the document and then close the application.


cheers,
dg
Dave Kreskowiak 24-Feb-14 23:13pm    
Windows explorer uses command line switches to tell the registered "document handler", in this case Word or Excel or Visio or PowerPoint, ..., to print the document and quit.

I don't know of any 3rd party libraries. That is an exercise left to you. I just used Office.
Sergey Alexandrovich Kryukov 24-Feb-14 21:17pm    
Agree, a 5.
Actually, Open Office SDK can help, but this is not enough, because some code should also render the document on the page (using the PrintDocument class).
—SA
dgoogle 25-Feb-14 4:46am    
So, am i on the right track to say I need to use the PrintDocument clas and some other MS Office class such as
Imports Microsoft.Office.Core
Imports Microsoft.Office.Interop
Imports System.Data

dg
Dave Kreskowiak 25-Feb-14 7:20am    
Nope. You just need Office. You tell Office what document to load and then tell it to print it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900