Xojo Conferences
MBSOct2019CologneDE

DynaPDF Manual - Page 414

Previous Page 413   Index   Next Page 415

Function Reference
Page 414 of 767
end;
// ViewRect holds the current size of the graphic on screen.
procedure TForm1.CreatePDF(const EMF: String; const ViewRect: TRectL)
var pdf: TPDF; r: TRectL; sx, sy: Double; tmp: Integer;
begin
pdf := nil;
try
pdf := pdf.Create;
pdf.CreateNewPDFA('c:\dout.pdf');
pdf.SetDocInfo(diSubject, 'EMF-Files');
pdf.SetDocInfo(diTitle, 'Metafiles');
pdf.SetDocInfo(diCreator, 'Delphi Test Application');
pdf.Append;
pdf.SetPageCoords(pcTopDown);
pdf.GetLogMetafileSize(EMF, r);
// Make sure that the rectangle contains correct values
if (FView.Left > FView.Right) then begin
tmp := FView.Left;
FView.Left := FView.Right;
FView.Right := tmp;
end;
if (FView.Top > FView.Bottom) then begin
tmp := FView.Top;
FView.Top := FView.Bottom;
FView.Bottom := tmp;
end;
// ViewRect is the current size of the EMF graphic in pixel.
sx := (r.Right - r.Left) / (ViewRect.Right - ViewRect.Left);
sy := (r.Bottom - r.Top) / (ViewRect.Bottom - ViewRect.Top);
// See how the rectangle must be calculated:
tmp
:= r.Left;
r.Left
:= Round(r.Left + FView.Left
* sx);
r.Right
:= Round(tmp
+ FView.Right
* sx);
tmp
:= r.Top;
r.Top
:= Round(r.Top
+ FView.Top
* sy);
r.Bottom := Round(tmp
+ FView.Bottom * sy);
// Now we have the unscaled cutting area. We want to output the
// EMF file onto the entire page with a border of 20 units so
// that we must only check whether the width or the height can be
// calculated by DynaPDF to preserve the aspect ratio.
sx := (r.Right - r.Left) / pdf.GetPageWidth;
sy := (r.Bottom - r.Top) / pdf.GetPageHeight;
pdf.SetMetaConvFlags(mfClipView); // we clip the viewport
if (sx > sy) then
pdf.InsertMetafileExt(EMF,
r, 20, 20, pdf.GetPageWidth - 40, 0)
else
pdf.InsertMetafileExt(EMF,
r, 20, 20, 0, pdf.GetPageHeight - 40);
pdf.EndPage;
 

Previous topic: GetLogMetafileSize

Next topic: GetMeasureObj