Click here to Skip to main content
15,867,762 members
Articles / Desktop Programming / MFC

Example of How to Print a Long CString across Multiple Pages of Output using the MFC Print Architecture

Rate me:
Please Sign up or sign in to vote.
4.50/5 (10 votes)
19 Jun 2002CPOL 126.6K   2.4K   26   21
An example project of how to break up a long string that you want to print across multiple pages

Sample Image - Preview.jpg

Introduction

A common question in the forums in the past has been how do I break up a long string and print it using the standard MFC architecture. Above is an example project that does just that. You can enter a long string to print in a MultiLine edit control. To see what the output would be like for your printer, you can select the Print Preview option from the file menu.

There are some drawbacks in the example in that it doesn't handle tabs correctly as it only uses CDC::TextOut() when printing, and CDC::GetTextExtent() when measuring whether the currently selected line will fit in one line, or needs to be broken up across multiple lines. This can be changed by yourselves as a programming exercise using the CDC::DrawText() function.

I hope this example will help out beginners at printing.

Enjoy!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Sirius Analytical Instruments
United Kingdom United Kingdom
A research and development programmer working for a pharmaceutical instrument company for the past 17 years.

I am one of those lucky people who enjoys his work and spends more time than he should either doing work or reseaching new stuff. I can also be found on playing DDO on the Cannith server (Send a tell to "Maetrim" who is my current main)

I am also a keep fit fanatic, doing cross country running and am seriously into [url]http://www.ryushinkan.co.uk/[/url] Karate at this time of my life, training from 4-6 times a week and recently achieved my 1st Dan after 6 years.

Comments and Discussions

 
QuestionThank u! Pin
sally899821-Jun-11 22:38
sally899821-Jun-11 22:38 
GeneralTechnical adaptation to a CEditView derived SDI application Pin
Raymond_Gimilio8-Feb-10 20:35
Raymond_Gimilio8-Feb-10 20:35 
GeneralPage setup Pin
TariqZ5-Jun-07 19:33
TariqZ5-Jun-07 19:33 
GeneralFaster method (Great article Btw) Pin
Y_R1-Feb-07 9:55
Y_R1-Feb-07 9:55 
Hello,

my CString is quite big (around 1MB), and contains UNICODE control characters (LRM).

When I used this method (or something very similar), loading the print preview of the pages too took very long time(minutes).
However when I didnt tried to clip the text (GetTextExtent) it worked MUCH faster (around 2 secs).

I have tried doing print preview to my text in word and it worked much quicker!

Is there any way to speed things up?

P.S
Great article.





Sincerely yours
Y.R.

QuestionPage Breaks Using MFC 6.0+ Pin
omar6314-Nov-06 9:27
omar6314-Nov-06 9:27 
GeneralMultiple print job Pin
vivadot12-Aug-04 11:59
vivadot12-Aug-04 11:59 
Generalconstructing long string... Pin
vivadot8-Jul-04 6:01
vivadot8-Jul-04 6:01 
GeneralRe: constructing long string... Pin
Atewa22-Jul-04 10:44
Atewa22-Jul-04 10:44 
GeneralRe: constructing long string... Pin
vivadot31-Jul-04 12:00
vivadot31-Jul-04 12:00 
GeneralCEditView and CString Pin
The_Inventor21-Jun-04 20:14
The_Inventor21-Jun-04 20:14 
GeneralRe: CEditView and CString Pin
tom-kaltofen30-Jan-06 23:37
tom-kaltofen30-Jan-06 23:37 
GeneralWord Wrap Pin
Gerard Lim31-May-04 3:00
Gerard Lim31-May-04 3:00 
Generalthanks a lot Pin
abicer27-Apr-04 22:06
abicer27-Apr-04 22:06 
GeneralPrint question Pin
nikoladsp13-Jan-04 6:19
nikoladsp13-Jan-04 6:19 
GeneralPrinting to a Printer/Help Pin
melshehu16-Oct-02 5:58
melshehu16-Oct-02 5:58 
GeneralRe: Printing to a Printer/Help Pin
Roger Allen17-Oct-02 2:37
Roger Allen17-Oct-02 2:37 
GeneralRe: Printing to a Printer/Help Pin
melshehu17-Oct-02 5:54
melshehu17-Oct-02 5:54 
GeneralJust what I was looking for Pin
-Dy24-Jul-02 1:17
-Dy24-Jul-02 1:17 
GeneralRe: Just what I was looking for Pin
Roger Allen24-Jul-02 3:06
Roger Allen24-Jul-02 3:06 
GeneralGood job. Pin
Shog920-Jun-02 17:59
sitebuilderShog920-Jun-02 17:59 
GeneralRe: Good job. Pin
Roger Allen20-Jun-02 22:47
Roger Allen20-Jun-02 22:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.