How can I print an RTF document from C#?

Posted on 2008-10-17
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.....
Question by:guxiyou
  • 3
  • 3
LVL 70

Accepted Solution

Éric Moreau earned 500 total points
ID: 22742543

Author Comment

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.
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.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

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....
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.
LVL 50

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.


Author Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Name Space error VS2015 1 37
Save json data from URL using SSIS 1 31
Outlook 2010: How to search sub-folders 3 65
parsing question on dynamic concatenation 3 34
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

733 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