#1 2014-10-07 20:08:54

RalfS
Member
Registered: 2011-07-11
Posts: 57

SynPDF is working internally with wrong scale

The code below should produce a PDF file in A4 size with an ellipse inside touching the borders of A4 sheet.But it does not. A scale of 1.333 is needed instead of 1.0 to reach that.


procedure SaveAsPdf;
var
  MetaFile: TMetafile;
  MetaFileCanvas: TMetafileCanvas;
  Pdf: TPdfDocument; //TPdfDocumentGDI ???
begin
  Pdf := TPdfDocument.Create;
  try
    //psA4, psA5, psA3, psLetter, psLegal, psUserDefined
    Pdf.DefaultPaperSize := psA4;

    Log('DefaultPageWidth: %d', [Pdf.DefaultPageWidth]);     
    Log('DefaultPageHeight: %d', [Pdf.DefaultPageHeight]);
    // 595 =  210 mm * 72 dpi
    // 842 =  297 mm * 72 dpi

    Metafile := TMetafile.Create;
    MetaFileCanvas := TMetaFileCanvas.Create(Metafile, 0);
    try
      MetaFileCanvas.Ellipse(Rect(0, 0, 594, 841));
    finally
      MetaFileCanvas.Free;
    end;

    Pdf.NewDoc;
    Pdf.AddPage;
    Pdf.Canvas.RenderMetaFile(Metafile, 1.3333333, 0, 0);
    Pdf.SaveToFile('c:\test1.pdf');
  finally
    Pdf.Free;
  end;
end;

Last edited by RalfS (2014-10-07 20:21:16)

Offline

#2 2014-10-08 05:55:39

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: SynPDF is working internally with wrong scale

You are confusing pdf size units and metafile pixel scale, which follows the registered DPI.

Both values do have a diverse context so do not have the same DPI, by design. For instance, pdf coordinates are floats whereas they are integers in metafile.

Offline

#3 2014-10-08 08:33:02

RalfS
Member
Registered: 2011-07-11
Posts: 57

Re: SynPDF is working internally with wrong scale

You mean pdf has 72 dpi and metafile 100dpmm=2540dpi?

Offline

#4 2014-10-08 08:59:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: SynPDF is working internally with wrong scale

Yes, it would depend on your settings for metafile, and will be fixed for pdf.
See http://blogs.datalogics.com/2012/09/13/ … e-systems/
and https://www.leadtools.com/help/leadtool … ystem.html

Offline

#5 2014-10-08 12:11:36

RalfS
Member
Registered: 2011-07-11
Posts: 57

Re: SynPDF is working internally with wrong scale

Thank you for pointing that out!

Offline

Board footer

Powered by FluxBB