Solved

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

Posted on 2014-10-26
3
159 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 79

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

813 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