Mega Code Archive

 
Categories / Delphi / Examples
 

Obtaining list of paper names and paper sizes

Title: Obtaining list of paper names and paper sizes. Question: How to obtain a list of paper names and sizes for current printer? Answer: In order to obtain list of paper names and sizes for curent printer you should to call DeviceCapabilities routine. This is an example of listing paper name strings in PaperNames array, paper sizes in PaperSizes array and corresponding paper identifiers in Papers array: type TPointArray = array[0..8191] of TPoint; PPointArray = ^TPointArray; ... procedure ListPapers; var i: integer; Buffer: array[0..65535] of byte; PrinterName: PChar; PaperCount: integer; PaperSizeArray: PPointArray; PaperNames: array of string; PaperSizes: array of TPoint; Papers: array of SHORT; begin with Printer do begin PrinterName := PChar(Printers[PrinterIndex]); PaperCount := DeviceCapabilities(PrinterName, '', DC_PAPERNAMES, @Buffer, nil); SetLength(PaperNames, PaperCount); SetLength(PaperSizes, PaperCount); SetLength(Papers, PaperCount); for i := 0 to PaperCount - 1 do PaperNames[I] := PChar(@Buffer[I * 64]); DeviceCapabilities(PrinterName, '', DC_PAPERSIZE, @Buffer, nil); PaperSizeArray := @Buffer; for i := 0 to PaperCount - 1 do PaperSizes[I] := PaperSizeArray^[I]; DeviceCapabilities(PrinterName, '', DC_PAPERS, @Buffer, nil); for i := 0 to PaperCount - 1 do Papers[I] := PWordArray(@Buffer)^[I]; end; end;