You are not logged in.
Pages: 1
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
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
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
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
Pages: 1