?
Solved

How can I insert a RTF portion in the middle of a PrintDocument Page

Posted on 2014-10-26
3
Medium Priority
?
176 Views
Last Modified: 2015-04-15
The included .jpg shows a page that was created with a PrintDocument object. My problem is that some words in the portion that is marked with a red rectangle needs to be formatted with Bold, Italic and Underline characters.

Since the formatting is simple, I first tried using my own formatting tags and work from there. Not as easy as I thought.

I chose that recipe because I tried it last weekend, and it is a very good one for your taste buds (at least mine). So those of you who understand French can try it :-). Unfortunately most of the recipes used by the application have paragraphs that takes more than one line, and I need to handle word wrapping of the text so that it fits in the width of the page.

While word wrapping is quite easy to handle when all the text uses the same font, things get a lot more complicated when italic text is slightly larger, and bold text is about 30% wider than the same text in normal font.

To summarize, it can be done, but with pain that I would prefer not to endure. In my opinion, a good programmer is a lazy programmer. He does not work less than another one, but he does more during the same number of work hours. Since I see myself as a decent programmer, I am a bit lazy.

I then tried implementing the formatting in rtf, but found out that the PrintDocument cannot handle rtf by itself.

I tried displaying the rtf in a RichTextBox and insert a snapshot of that RichTextBox in the PrintDocument, but the quality is not good enough compared to the text in the rest of the document.

Did anybody ever had to format rtf text inside of a PrintDocument Page, or have an idea on an easy way to do it?

Thank you all.
Image2.jpg
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

Expert Comment

by:David Johnson, CD, MVP
ID: 40405621
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 0 total points
ID: 40405732
Hi David

Doing the whole thing in RTF was my first thought, but I threw that idea away quite fast. Have you ever tried generating RTF through code? What a mess. Already overloaded for simple text, but even more so when you need to add photos, bitmaps and lines.

So I went for the PrintDocument, a control I know, and that is relatively easy to use for a document of the type I need to produce. The only hiccup was that center portion, that is typed by the user and can be manually formatted. The input for that section thus do come from a RichTextBox with a few buttons to add the formatting. This is the only section that requires RTF.

I did test the code you are referring to, as well as a couple other printing routines for the RichTextBox Control that I found somewhere else. They all suffer from the same problem: they handle only very simple text. Some cannot handle formatting such as bold on a single word (they work on lines only). Some do not handle French characters at all, and those who do often do it improperly. I haven't seen one that supports the whole Unicode character set, and I need characters such as ½, °F and °C. Some generate RTF that will read back OK in Word, but not in the RichTextBox.

None of them is useful.

So I am still looking for a way to interpret RTF text with simple formatting in the context of a PrintDocument, with automatic WordWrap. This is something I can do, but I expect a couple of days on something like that, and I would rather spend that time on something else if somebody has done properly before.

Thanks for your input anyway.
0
 
LVL 40

Author Closing Comment

by:Jacques Bourgeois (James Burger)
ID: 40724611
Finally ended up interpreting the RTF myself in the PrintPage event of a PrintDocument.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

770 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