I'm trying to print out Page x from y using the TPrintPreview Class.
I'm using it with C++Builder Seattle.
Following I tried:
- Code: Select all
pPrintPreview->BeginDoc()
pPrintPreview->Canvas->Font->Size = 8;
pPrintPreview->Canvas->Font->Style = TFontStyles();
for(int i=0; i<9999;i++)
{
//Insert Textline is just printing a Line of Text using DrawText
iTop = InsertTextLine("Test " + UnicodeString(i), iTop, DT_LEFT, iTopMargin);
}
//now there are 130 pages generated and i want to print out the pagenumbers
//so I tried:
//set page to first
pPrintPreview->CurrentPage = 1;
//goto to all pages and print out pagenumber
for(int i=1; i<=pPrintPreview->TotalPages; i++)
{
//Print out Pagenumber in the lower right corner
UnicodeString asText = "Page " + UnicodeString(i) + " / " + UnicodeString(pPrintPreview->TotalPages);
this->InsertTextAt(asText, pPrintPreview->PageSize.Y - pPrintPreview->Canvas->TextHeight(asText), xPrinterOffset, DT_RIGHT, -1);
++pPrintPreview->CurrentPage;
}
The result is, that the asText is drawn 130 times on the last page. See the image attached.
So my question is, how to use CurrentPage correctly?
Can anybody can give me a hint, what I'm doing wrong?
Thanks in advance,
Alex