Page 1 of 2
testing components
Posted: Fri Aug 01, 2014 10:00 am
by Lucian
Hi,
We are testing the component TRichViewEdit and I have a question regarding print/printpreview. We have our own printing and previewing code. What's the best example (from demo) I should work on that will help me understand how I could print/printpreview the content of the control in our sourcecode. Currently using Delphi 7 and for printing something called ReportPrinter Pro Component Suite. This is something from '95-'96 years, so, yeah, it's old ... don't ask
Or, what's your take on this, how easy would be to print/preview the content in our custom code (probably we will have to paginate ourselves, etc)
TIA,
Lucian
Posted: Fri Aug 01, 2014 6:53 pm
by Sergey Tkachenko
To answer the question, I need to understand why do you need to use your own print and preview code for TRichViewEdit?
There are two ways to print TRichViewEdit:
- TRVPrint (with preview in TRVPrintPreview component)
- TRVReportHelper.
TRVPrint requires minimal code, because it uses the current printer settings, handles headers, footers, footnotes, endnotes (and text boxes in the new version, that will be released soon). For previewing, there is a special component TRVPrintPreview. A function for drawing TRVPrint's page on the specific canvas exists, but it's undocumented.
TRVReportHelper is useful if you want to implement a non-standard page layout, or draw TRichView document as a part of more complex document drawn by other tools. In TRVReportHelper, you just specify canvas and document width, then height for specific "pages". In TRVReportHelper, "page" is not necessary equal to paper size, it's just a rectangle. There is a function allowing to draw "page" at the specified coordinates. It does not support notes, boxes, headers and footers.
Posted: Fri Aug 01, 2014 8:19 pm
by Lucian
Hi, and thanks for answering this. The application I am working on is huge and very complex. It has tons of reporting. Some functionality involves sending emails. Currently the emails are plain text. The emails are not only sent out, but also stored in the application database for reviewing, deleting, whatever. The thing is, there's a print button everywhere
, and in this case, for an email, the application would print some info at the top of the page (From, To, Subject, datetime, etc) and then the body of the email (which as of now is plain text as I said).
Now ... people want RTF and HTML in their email. That's why we think using this component we could do that. I'm the guy testing the components and most probably implementing the changes. So, I need to know the best way to print the content of the richview component. I believe all I have to communicate with the component is a DC, a device context (but I am not sure, I have to investigate more). Also, I am not sure about paginating. I believe I am going to code page breaking myself... or not, I don't know yet. Or perhaps you're right, we could try to fully use the print and preview that comes with the component, but than we have to be able to print additional stuff, eventually company logo, headers, footers, the whole nine yards.
That's about it. Let me know what you think and thanks.
Posted: Fri Aug 01, 2014 8:36 pm
by Sergey Tkachenko
I suggest using TRVPrint and TRVPrintPreview components.
As for printing additional stuff. If you want to print something at very beginning or very end of the document, it's simpler to add this additional content to TRichViewEdit before printing (for example, by combining two documents together).
Also, you can assign another documents as a header or a footer (RVPrint.SetHeader/SetFooter). Special headers for the first page and odd/even pages are supported.
Also (in the new version, public trials are not available yet) you can print additional stuff in text boxes positioned at the specified coordinates on the page. Textboxes can be inserted in headers (but positioned everywhere on a page) to repeat on every page.
Finally, you can use OnPagePrepaint and OnPagePostpaint events to draw something yourself.
As for custom paginations, I am not sure what you mean. I suggest to control pagination using document features: keep-lines-together and keep-with-next paragraphs, and inserting pagebreaks in certain places.
Posted: Sat Aug 02, 2014 6:53 am
by Lucian
Ok, I'll have a look. With pagination, what I meant is, even when printing for example a TRichEdit, the developer must measure and split the content of the control, it's a classic 20-30 lines piece of code you can find in many places (where you send some startpos in the buffer plus some TRect bounds and get back some endpos in the RTF, you repeat this in a loop until you print the whole content). Don't know how you do it.
One other question, if we buy the component, does it come with 100% full source code?
Posted: Sat Aug 02, 2014 7:28 pm
by Sergey Tkachenko
Yes, the full version includes full source code.
The analog of RichEdit's EM_FORMATRANGE is TRVReportHelper component.
TRVPrint component has a higher level programming interface: you specify page margins and other properties, and it does all the work for you.
In TRVReportHelper, you format like this:
Code: Select all
helper.Init(Canvas, Width);
while not helper.FormatNextPage(Height) do;
I.e. you can define width and height for each page (width must be the same, heights may be different).
Then you can draw the helper's page at the specified coordinates using helper.DrawPageAt.
Examples of using TRVReportHelper:
- Demos\*\Assorted\Printing\ReportHelper - printing documents in two columns
-
http://www.trichview.com/forums/viewtopic.php?t=327 (please note that this is an old topic, it contains obsolete information about TRVPrint: it now supports special headers for the first and odd/even pages (can be found already in the trial version) and page number fields (currently in the version available only for registered users)).
Posted: Sun Aug 03, 2014 5:49 am
by Lucian
Great, thank you.
Lucian
plain text
Posted: Mon Aug 04, 2014 9:31 am
by Lucian
Hi Serghey,
Does the component have something like "PlainText" functionality, where I can extract the "Text" as plain text (string)?
Posted: Mon Aug 04, 2014 1:41 pm
by Sergey Tkachenko
Posted: Mon Aug 04, 2014 6:32 pm
by Lucian
One last thing. Can this component load HTML? This is our main request. We want to be able to answer back to emails that have html, so we want to see the original stuff. (No, this is not yet another email application
, email is probably 5% of the application).
regards
Lucian
Posted: Tue Aug 05, 2014 1:35 pm
by Sergey Tkachenko
Currently - only with help of additional components.
They are free with source code.
The best solution is TrvHtmlViewImporter:
http://www.trichview.com/resources/ that uses THTMLViewer (also free with source code)
Posted: Tue Aug 05, 2014 1:43 pm
by Sergey Tkachenko
Note that HTML emails are not simple HTML, but mime-encoded documents that may contain HTML, its text alternative, images, attached files.
You need to decode this mime-document and extract HTML and images in order to load them.
Some examples:
-
http://www.trichview.com/forums/viewtopic.php?t=4123 - contains functions and examples using CleverComponents, including full functional email client
-
http://www.trichview.com/forums/viewtopic.php?t=11 - examples for sending HTML email using Indy
-
http://www.trichview.com/forums/viewtopic.php?t=6133 - example for sending HTML email using Synapse (not tested by me)
The last two example are only for saving. However, I believe, if these components support MIME-encoding, they support decoding as well.
Posted: Tue Aug 05, 2014 1:46 pm
by Lucian
Thanks Serghey,
We're using Indy 10, I think Indy can handle html emails. I will see if we are allowed to use open source stuff and than test the html importer/viewer.
Oops
Posted: Tue Aug 05, 2014 1:48 pm
by Lucian
Now I noticed I was spelling wrong your name, sorry about that.
Printing from preview
Posted: Mon Aug 11, 2014 1:17 pm
by Lucian
Hi,
One other question... is it possible to print from the preview itself. Like for example "Print current page" / "Print all" ?
Thx