#1 2024-07-04 13:33:30

pjain
Member
Registered: 2024-07-02
Posts: 7

Rendering issue of metafile in TGDIPages.

Hi,

I have a list of metafiles which i need to render in pdf file along with header and footer. for that purpose i am using TGDIPages. below is sample code i have
my meta file's width and height are : 1500 and 1000 respectively. Unfortunately the resolution of graphic in pdf is reduced to a very small size.

LPdfGDI := TGDIPages.Create(Self)
LPdfGDI.BeginDoc;
for I := 0 to AMetaFilesList.Count - 1 do
begin
    R.Left := LPdfGDI.PageMargins.Left;
    R.Right := TMetafile(AMetafilesList[i]).width - LPdfGDI.PageMargins.Right;
    R.Top := LPdfGDI.PageMargins.Top;
    R.Bottom := TMetafile(AMetafilesList[i]).height -LPdfGDI.PageMargins.Top;
    LPdfGDI.DrawMeta(R, TMetafile(AMetafilesList[i]));
    LPdfGDI.NewPage;
end;
LPdfGDI.EndDoc;
LPdfGDI.ExportPDF('f:\gdipdf.pdf',false,false);
LPdfGDI.Free;

Just wondering if anyone has faced similar issue and have any solution or other way to do this.

Thanks.

Last edited by pjain (2024-07-04 13:34:12)

Offline

#2 2024-07-04 15:05:02

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

Re: Rendering issue of metafile in TGDIPages.

Is the resolution reduced, or the size reduced?

In your calculation, you are mixing TGdiPages units (in mm) and TMetaFile units (in pixels).
Just compute R in millimeters.

Offline

#3 2024-07-09 08:57:52

pjain
Member
Registered: 2024-07-02
Posts: 7

Re: Rendering issue of metafile in TGDIPages.

Hi,

thanks for your reply.  I've changed the function a bit to make calculation a bit simpler for now. still the pdf doesnt look good.
It seems like the bitmap is streched a lot inside the rectangle.

would it be possible to change the interface so that DrawMeta accepts R in pixels just to do less calculations.

LPdfGDI := TGDIPages.Create(Self)
LPdfGDI.BeginDoc;
for I := 0 to AMetaFilesList.Count - 1 do
begin
    R.Left := 0;
    R.Right := TMetafile(AMetafilesList[i]).mmwidth ;
    R.Top := 0;
    R.Bottom := TMetafile(AMetafilesList[i]).height;
    LPdfGDI.DrawMeta(R, TMetafile(AMetafilesList[i]));
    LPdfGDI.NewPage;
end;
LPdfGDI.EndDoc;
LPdfGDI.ExportPDF('f:\gdipdf.pdf',false,false);
LPdfGDI.Free;

Offline

#4 2024-07-09 14:02:35

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

Re: Rendering issue of metafile in TGDIPages.

You are still mixing mm and pixels in your code.

Please use dedicated TGdiPages methods to make the conversion between pixels and mm.
TMetaFile has no knowledge of the proper resolution.

We use mm in DrawMeta() as in other methods, on purpose.

Offline

#5 2024-07-10 07:56:36

pjain
Member
Registered: 2024-07-02
Posts: 7

Re: Rendering issue of metafile in TGDIPages.

Could you please suggest which method to use, i tried using PrinterToMM but its giving me pretty small rectangle. Also i can see that inside DrawMeta, there is again mm to printer is used.

procedure TGDIPages.DrawMeta(rec: TRect; meta: TMetafile);
var old: Integer;
begin
  if Self=nil then exit; // avoid GPF
  CheckHeaderDone;
  rec := MmToPrinter(rec);
  old := SaveDC(fCanvas.Handle);   // ensure safe metafile embedding
  PlayEnhMetaFile(fCanvas.Handle, meta.Handle, rec);
  RestoreDC(fCanvas.Handle,old);
end;

Offline

Board footer

Powered by FluxBB