Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

new page ()

Status
Not open for further replies.

butthead

Programmer
Feb 24, 2002
545
US
the code below doesnt print a 20 page document. it
just prints the first page and then keeps shooting out
blanks.

any suggestions.

[/CODE]
TPrinter *P;
P = Printer();

int Xpos = 100;
int Ypos = 100;
int LineHeight;
LineHeight = LineHeight = RichEdit1->Font->Size * 5;
P->Canvas->Font = RichEdit1->Font;

P->BeginDoc();

for (int x = 0; x < RichEdit1->Lines->Count; x++)
{
P->Canvas->TextOut(Xpos, Ypos, RichEdit1->Lines->Strings [x]);
Ypos = Ypos + LineHeight;

if (Ypos > P->PageHeight - (LineHeight * 20))
{
Ypos == 100;
P->NewPage();
}
}

P->EndDoc();
Code:
tomcruz.net
 
never mind

I figured out the problem.. I just got to write the code.

post it later.

tomcru.net
 
this is presently printing 96 pages of

*The Project Gutenberg Etext of Inferno/Hell by Dante Aligheri*

The code below does the job but I will need to tweak it a bit. If anyone is interested I plan to make a cpp and header combo to handle all my printing. and I will post this on my web site. I am sure the final code will be quite long. Too long to post here anyway. It will also contain the code for printing bitmaps.


void __fastcall TForm1::Button3Click(TObject *Sender)
{
Printer()->BeginDoc();
char s[256];
char c [25];
int Xpos = 100;
int Ypos = 100;
int LineHeight;
int line;
int pages;
int page = 1;
int lines_per_page;

LineHeight = LineHeight = RichEdit1->Font->Size * 5;
Printer()->Canvas->Font = RichEdit1->Font;
LineHeight = LineHeight = RichEdit1->Font->Size * 5;
lines_per_page = Printer()->PageHeight/LineHeight;
page = 1;
pages = RichEdit1->Lines->Count/lines_per_page;
line = 0;

s[0] = NULL;
strcpy (s, "Total Page Count ");
strcat (s, itoa (pages, c,10));
Printer()->Canvas->TextOut(0, 0, s);

for (int x = 0; x < pages - 1; x++)
{
Ypos = 100;
for (int x = 0; x < (((Printer()->PageHeight - 100)/LineHeight) - 3); x++)
{
s[0] = NULL;
strcpy (s, itoa (line + 1, s,10));
strcat (s, ": ");
strcat (s, RichEdit1->Lines->Strings [line].c_str ());
Printer()->Canvas->TextOut(Xpos, Ypos, s);
Ypos = Ypos + LineHeight;
line++;
}
Ypos = Ypos + LineHeight;
s[0] = NULL;
strcpy (s, "Page ");
strcat (s, itoa (page, c,10));
Printer()->Canvas->TextOut(Xpos + 500, Ypos, s);

page++;
Printer()->NewPage();

//if (x == pages - 1)
// break;
}

Printer()->EndDoc();
}

tomcruz.net
 
Yeah, printing stuff out can be interesting. I had to do something similar for one of my apps. Glad to see you're making a resource that everyone else can use.

Brian Rivers
 
for those of us that have some difficulty
printing I have some code here that could
be of use. it is the beginning of a printing
class that wraps the borland builder stuff
into a neat modular packadge.

Printing can be as easy as this

MHPrint *P;
P = new MHPrint ();
P->Font (RichEdit1->Font);
P->Lines = RichEdit1->Lines;
P->Print();
delete P;

the latest print project zip file is on my website

I would post it here but its 600 lines of code and too
much to post here. I am going to spend some time on this
because I wish to show my gratitude to all of the members
of tek-tips for all the help they have given me the last
couple of years.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top