Solved

How can I print an RTF document from C#?

Posted on 2008-10-17
7
3,861 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 70

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 70

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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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 70

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article will shed light on the latest trends when it comes to your resume building needs. For far too long, the traditional CV format has monopolized the recruitment market.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

773 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