Solved

How can I print an RTF document from C#?

Posted on 2008-10-17
7
3,842 Views
Last Modified: 2012-05-05
How can I print an RTF document from C#? I need to be able to print out the document with all the correct formating, including colors, margins.....
0
Comment
Question by:guxiyou
  • 3
  • 3
7 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 22742543
0
 

Author Comment

by:guxiyou
ID: 22742908
Is there a way to do this without relying on having an external program that is setup to handle the file type? The reason I ask is that I really need this to work with batching.... and I don't want to have word (for example) open and close a hundred times in order to accomplish this.
0
 
LVL 69

Assisted Solution

by:Éric Moreau
Éric Moreau earned 500 total points
ID: 22743123
The Process component hides this complexity for you.

For example, if the Process components handles a .xls file, it will automatically be associated with Excel. So if you launch the Print command on this file, Excel will handle the Print command. It act exactly has if you right-click a file in Windows Explorer and select the Print menu command.

If you don't want to have the application opened and closed for you, you will need to use Automation to load documents yourself, print them, and close the application when you are done.
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 

Author Comment

by:guxiyou
ID: 22743502
I guess the root of my question is, how can I do this without using the application? It seems like there should be a control or class in .Net (or that someone has done) that would let you print RTF files directly, without the need of having another application installed.  I know there is plenty of code that will allow you to print the contents of a RichTextBox, which is very similar, but does not preserve stuff like margins....
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 22743954
>>I guess the root of my question is, how can I do this without using the application?

There isn't. Each application requires a special formatting (you don't print a Word document like you print a Visio document).

There are probably some third party components out there (I think of Aspose) but are you ready to buy them?

All other utility you will find will surely use Word Automation in the background.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 22745577
You could call (shell out to) WordPad (which exists on any Windows machine) like this:

wordpad /p d:\path\yourfile.rft

to print directly to the default printer.

/gustav
0
 

Author Comment

by:guxiyou
ID: 22790823
Is it possible to use the process method to print from a webservice?
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today companies are subjected to more-and-more data, and it won't stop any time soon.  But there are obvious opportunities for reducing data, particularly data duplicated among companies.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now