TPrintPreview Page x / y

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

TPrintPreview Page x / y

Postby AlphaUniform » August 29th, 2017, 8:33 am

Hi all,
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
Attachments
PageCount.png
PageCount.png (11.49 KiB) Viewed 3404 times
AlphaUniform
Member
Member
 
Posts: 2
Joined: August 29th, 2017, 8:00 am

Re: TPrintPreview Page x / y

Postby MilanL » September 20th, 2017, 8:53 am

Hi,
I have solved a similar problem.
SOLUTION in Delphi:

Code: Select all
     
with pPreview do
begin
    BeginDoc;
    ...fill data procedure
    EndDoc;

    for I := 1 to TotalPages do
    begin
      CurrentPage := I;
      if BeginEdit(CurrentPage) then
      begin
        with canvas do
        begin
          try
            Font.Name := 'Times New Roman';
            Font.Size := 12;
            Font.Style := [fsBold];
            Font.color := clBlack;
            txt := 'Page ' + inttostr(CurrentPage) + ' / ' + inttostr(TotalPages);
            aArea := aPrintArea;                                // full print Area "page / pages" in Right Top corner
            aArea.Left := aArea.Right-textwidth(txt);
            aArea.Top := aArea.Top + 20;
            TextRect(aArea,txt);
          finally
            EndEdit(false);               //argument is cancel => false=applying changes, true=canceling changes
          end;    //try
        end;      //canvas
      end;        //if
    end;          //for
end;              //pPreview
MilanL
Member
Member
 
Posts: 3
Joined: September 20th, 2017, 8:40 am

Re: TPrintPreview Page x / y

Postby AlphaUniform » September 22nd, 2017, 6:13 am

Hi,
thank you very very much.
This one worked.
I would have never tried to edit the canvas after EndDoc() :-k

Best regards
Alex
AlphaUniform
Member
Member
 
Posts: 2
Joined: August 29th, 2017, 8:00 am

Re: TPrintPreview Page x / y

Postby MilanL » September 22nd, 2017, 8:29 am

I've been bumping for about ten days, I was inspired by the printpreview demo, the "add random shapes this page" feature, I just struggled with the argument for EndEdit, I still stuck true.
MilanL
Member
Member
 
Posts: 3
Joined: September 20th, 2017, 8:40 am


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 0 guests

cron