Printing RTF data

Hi everybody,

I have read a lot about RTF data and StyledText, and how to display RTF data in a TextArea, and in fact this is no more a problem.
But I haven’t found anything about printing RTF data (or maybe I haven’t seen the answer).
In a SQL Server table I have stored RTF data in a field, and it looks like this:
{\rtf1\ansi\ansicpg1252{\fonttbl{\f0\fnil Verdana;}}{\colortbl\red0\green0\blue0;}\uc0 \ql\f0\fs22 This is \b Bold \b0 text.This is \i Italic \i0 text.And this is \ul Underline \ul0 text.This is \b\i Bold+Italic\b0\i0 text.}

Well, I can display it correctly in a TextArea using txtArea.StyledText.RTFData, but I am in trouble when I have to print the same data.

Can anyone help me, please?

Thank you so much.

Nedi

  1. What sort of trouble?

  2. Where are you trying to print the RTF from? Have you looked at:

https://documentation.xojo.com/api/printing/print.htmlerSetup

andthe sample code there?

Thank you, Tim.

The trouble is that I don’t know how to print RTF data; in other words I don’t know how to transform the control chars into, for example, bold, italic, underline words.
I am using the built in report tool and Windows 10.

Why don’t you put the rtf in a TextArea and print that TextArea ?

So you want to print the rendered RTF, not the raw RTF? Your OP talked about printing RTF data so I assumed you had the RTF in a string and wanted to print that. Would this help:

https://documentation.xojo.com/api/deprecated/textarea.html#textarea-styledtextPrinter

Yes, Tim: I want to print the rendered RTF, but I don’t know how to do that from a report object.

Hi Emile: do you mean that I should use a Textarea object inside a Report object?

No: I know nothing about Report.

Did you tried FTC ? I’m sure it can offer you all the tools you need, we are using that for many years and it just does the job. Formatted Text Control – BKeeney Software Inc. I’m not sure still available but for sure it still is.

Hope it helps.

The link that Tim gave you is to the styledtextprinter class. This will take the Styled Text from the Text Area and make it easier to print this out.

https://documentation.xojo.com/api/deprecated/textarea.html#textarea-styledtextPrinter

Thank you Aurelian & Sam: I have no problems with text area, I have problems with Report (I can’t print formatted text).
Aurelian, I think the BKeeney’s Formatted Text Control is for windows and not for printing.

FTC has been sold (given ?) to Rep Plus

and it will be open sourced one day as they say but it’s been a long time now…

With FTC you can print documents too since it uses the normal Graphics Object. You can download the sample App from www.bkeeney.com and try it. Printing is implemented.

Thank you, Martin: I’ll take a look at it.

I am not very good at explaining things, but styledtextprinter is for drawing/printing styled text, it uses a text area as its base.

Ok Sam: I have to print a field from a database table; this field contains text in RTF format like this. {\rtf1\ansi\ansicpg1252{\fonttbl{\f0\fnil Verdana;}}{\colortbl\red0\green0\blue0;}\uc0 \ql\f0\fs22 This is \b Bold \b0 text.This is \i Italic \i0 text.And this is \ul Underline \ul0 text.This is \b\i Bold+Italic\b0\i0 text.}
I have to print the formatted text in a Reportfield. I am using the Report built in object, so I can’t use a TextArea (I think I can’t use, but I’m not sure I’m right).
If I had to display the formatted text in a Textarea it would be quite simple…

If you’re on macOS you could put the RTF data into a hidden text area, size it the same as your printer and then call TextArea1.drawInto(g,0,0)
This only works if there is no scrolling.

You can use a TextArea as an intermediate step. So you fill it from the database and then use the styledtextprinter class to print the styled text.

Thank you, Graham and Sam: I’ll try that as soon as possible.

Graham & Sam: I am using Xojo 2019r1.1 on Windows 10 computer.
Are your suggestions still valid?