function TPrintPreview.PageSize : TPoint;
{Physical size of page including the non-printable border area}
begin
//Escape(Printer.Handle, GETPHYSPAGESIZE, 0, nil, @Result);
Escape(Printer.XDPI, GETPHYSPAGESIZE, 0, nil, @Result);
procedure TPrintPreview.DisplayPage(Page : Integer);
var
p : TPoint;
Sc : Single;
r : TRect;
i : integer;
begin
if (Page > 0) AND (Page <= PageCount) then
begin
Sc := PaintBox1.Width / PageSize.X;
PaintBox1.Canvas.Rectangle(0,0,PaintBox1.Width, PaintBox1.Height);
PaintBox1.Canvas.FillRect(Rect(1,1,PaintBox1.Width-2,PaintBox1.Height-2));
// Escape(Printer.Handle, GETPRINTINGOFFSET, 0, nil, @p);
Escape(Printer.XDPI, GETPRINTINGOFFSET, 0, nil, @p);
r.Left := Trunc(p.X * Sc);
r.Top := Trunc(p.Y * Sc);
r.Right := r.Left + Trunc(Printer.PageWidth * Sc);
r.Bottom := r.Top + Trunc(Printer.PageHeight * Sc);
if ShowgridBtn.Caption[1] = 'H' then
begin
with PaintBox1.Canvas do
begin
Pen.Style := psDash;
Rectangle(r.Left, r.Top, r.Right, r.Bottom);
for i := 1 to Self.PageSize.X div Self.pXppi do
begin
MoveTo(Trunc(i * Self.pXppi * Sc), 0);
LineTo(Trunc(i * Self.pXppi * Sc), Trunc(PageSize.Y * Sc));
end;
for i := 1 to Self.PageSize.Y div Self.pYppi do
begin
MoveTo(0, Trunc(i * Self.pYppi * Sc));
LineTo(Trunc(PageSize.X * Sc), Trunc(i * Self.pYppi * Sc));
end;
Pen.Style := psSolid;
end;
end;
PaintBox1.Canvas.StretchDraw(r, Metafiles[Page]);
Panel2.Caption := Format('Page %d of %d', [Page, PageCount]);
PageDisplaying := Page;
if Page = 1 then
begin
FirstBtn.Enabled := False;
PriorBtn.Enabled := False;
end else
begin
FirstBtn.Enabled := True;
PriorBtn.Enabled := True;
end;
if PageCount > Page then
begin
NextBtn.Enabled := True;
LastBtn.Enabled := True;
end else
begin
NextBtn.Enabled := False;
LastBtn.Enabled := False;
end;
end;
end;
procedure TPrintPreview.NewJob;
var
i : Integer;
p : TPoint;
XOff : Integer;
YOff : Integer;
begin
for i := FMetafiles.Count - 1 downto 0 do
begin
TMetafile(FMetafiles[i]).Free;
end;
FCanvases.Clear;
FMetafiles.Clear;
FCurrentPage := 0;
FDonePrinting := False;
// Escape(Printer.Handle, GETPRINTINGOFFSET, 0, nil, @p);
Escape(Printer.XDPI, GETPRINTINGOFFSET, 0, nil, @p);
XOff := p.X;
YOff := p.Y;
// pXppi := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
// pYppi := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
pXppi := GetDeviceCaps(Printer.XDPI, LOGPIXELSX);
pYppi := GetDeviceCaps(Printer.YDPI, LOGPIXELSY);
if printer.printing then printer.abort;
Printer.BeginDoc;
NewPage;
end;