TPrintPreview Page x / y

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

TPrintPreview Page x / y

Postby AlphaUniform » 29/08/17 08:33

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
You do not have the required permissions to view the files attached to this post.
AlphaUniform
Member
Member
 
Posts: 2
Joined: 29/08/17 08:00

Re: TPrintPreview Page x / y

Postby MilanL » 20/09/17 08:53

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: 2
Joined: 20/09/17 08:40

Re: TPrintPreview Page x / y

Postby AlphaUniform » 22/09/17 06:13

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: 29/08/17 08:00

Re: TPrintPreview Page x / y

Postby MilanL » 22/09/17 08:29

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: 2
Joined: 20/09/17 08:40


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 2 guests