Solved

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

Posted on 2014-10-26
3
151 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
  • 2
3 Comments
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 0 total points
Comment Utility
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)
Comment Utility
Finally ended up interpreting the RTF myself in the PrintPage event of a PrintDocument.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

743 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

16 Experts available now in Live!

Get 1:1 Help Now