PDF generator: image at runtime

In my application I need to create a pdf generating images at runtime.

I have a component that draws on  canvas, what is the best way to draw my image on pdf?
How can I set the canvas size in order to have the best results? Are pdf pagewidth and pageheight comparable to canvas width and height?
mydrawer is my custom drawer, img is a TTMSFNCBitmap, cellwidth and cellheight the size of my image on pdf. setting drawer.Height:= cellheight; and drawer.Width:= cellwidth; I set the mydrawer canvas dimensions.

This is my actual code:

    mydrawer.Height:= cellheight;
    mydrawer.Width:= cellwidth;
    img.Bitmap.Height:= cellheight;
    img.Bitmap.Width:= cellwidth;
    pdflib.Graphics.DrawImage(molimg, RectF(0, 0, cellwidth, cellheight));

Is it correct? When I add a lot of images the memory occupancy grows till GB until I save the pdf. 
Am I doing something wrong?

Lazarus 1.6.4, FPC 3.0.2


Saving images can create significant amount of resources. Until the PDF is saved, the image is stored in a JPEG format. The code is correct, the pagewidth/pageheight are in pixels, you can compare the PageWidth/PageHeight with the Canvas Width and Height. You can use functions such as MillimeterToPixel and PixelToMillimeter to have more accurate drawing coordinates.

How should I exactly use MillimeterToPixel and PixelToMillimeter?

    cellwidth:= Trunc(pdflib.PageWidth / ColCount);
    cellheight:= Trunc(pdflib.PageHeight / RowCount);

How should I use MillimeterToPixel and PixelToMillimeter in order to set my canvas correct size?
Since pagewidth/pageheight are in pixels I used:
      img.Bitmap.Height:= Trunc(PixelToMillimeter(cellheight));
      img.Bitmap.Width:= Trunc(PixelToMillimeter(cellwidth));
      MyDrawingControl.Height:= img.Bitmap.Height;
      MyDrawingControl.Width:= img.Bitmap.Width;  

The images drawed on pdf are smaller then expected.
Additionaly, how should I use the ADPI parameter?


The PDF canvas is in pixels, and is set to be a default A4 format, which is 210 mm × 297 mm
If you want to create a grid-like structure on an A4 you can use these dimensions. You can also change the dimensions of the PDF by setting the PageSize to custom and set the PageWidth / PageHeight properties.

Drawing images / graphics is always in pixels, but it depends on the size you need to draw them in millimeters. Please provide more details, or a specific sample on what you want to achieve exactly.

Thanks, I got it.