Solved

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

Posted on 2014-10-26
3
167 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 81

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
API v SOA 8 60
ado.net AddWithValue when using IN condition 7 42
Run tasks synchronously in background thread 19 78
AJAX Create / Update Not working MVC 5 55
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 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