#1 2013-11-28 05:24:15

Yuri
Member
Registered: 2013-11-28
Posts: 1

How to switch between pages?

I used the following code to select the previous page to continue drawing on it.
But it resets all previous drawing on that page. What do I do wrong?
Thank you!

procedure TForm1.btnTestClick(Sender: TObject);
var
  doc : TPdfDocumentGdi;
  page, page1 : TPdfPage;
  text : string;
begin
    text := 'Sample text';
    doc := TPdfDocumentGdi.Create();

  try
    doc.Info.Author := 'Author';
    doc.Info.CreationDate := Now;
    doc.Info.Creator := 'Creator';
    doc.DefaultPaperSize := TPdfPaperSize.psA4;

    page := doc.AddPage();
    doc.Canvas.SetPage(page);
    doc.VCLCanvas.TextOut(300, 300, text);  // Will be lost

    page1 := doc.AddPage();
    doc.Canvas.SetPage(page1);
    doc.VCLCanvas.TextOut(300, 300, text);  // Ok

    doc.Canvas.SetPage(page);
    doc.VCLCanvas.TextOut(500, 500, text);  // Ok

    doc.SaveToFile('test.pdf');
  finally
    doc.Free;
  end;
end;

Offline

Board footer

Powered by FluxBB