In either mode of printing, the way in which a page is printed is the same. A suitable transformation must be established between the coordinate system of the output-pane or printer-port object and the physical page being printed. The page is then drawn using normal Graphics Ports operations, which are described in Drawing - Graphics Ports.
The with-page-transform macro can be used to establish a page transform which controls scaling by mapping a rectangular region of the document to the printable area of the page. The scale matches the screen by default. By specifying a large rectangle, you can get finer granularity in the drawing. Any number of invocations of with-page-transform may occur during the printing of a page. For instance, it may be convenient to use a different page transform when printing headers and footers to the page from that used when printing the main body of the page.
A helper function, get-page-area, is provided to simplify the calculation of suitable rectangles for use with with-page-transform. It calculates the width and height of the rectangle in the user's coordinate space that correspond to one printable page, based on the logical resolution of the user's coordinate space in dpi.
For more specific control over the page transform, the printer metrics can be queried using get-printer-metrics and the various printer-metrics accessors such as printer-metrics-height
.
Margins and the printable area can be set using set-printer-metrics.
(example-edit-file "capi/printing/fit-to-page")
CAPI User Guide and Reference Manual (Windows version) - 3 Aug 2017