Solved

How can I print an RTF document from C#?

Posted on 2008-10-17
7
3,819 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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.

Join & Write a Comment

Lately there has been a variety of news related to U.S. employment.  Stories about worker productivity, automobile and airline unions, low employment and foreign laborers have frequented the news.  Each story has good and bad attributes we might arg…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

707 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

15 Experts available now in Live!

Get 1:1 Help Now