如题
谢谢各位!

解决方案 »

  1.   

    http://immortals.fake.hu/delphiportal/modules.php?name=News&file=print&sid=1422How to get the names, ID's and sizes for paper formats and bins supported by a printer
    Problem/Question/Abstract:I'm trying to get a list of paper sizes for a given printer. The same list that's in the drop downs in the printer setup dialogs. It appears to be printer dependent. I tried EnumForms (in Win2000) but that gave a very large list (139 items). The printer setup dlg only lists about a dozen for each printer. This list seems to be the same list via Control Panel | Printers | Server Properties | Forms. Also, the names are slightly different in the printer setup dialog. instead of ""Letter"" the dialog has ""Letter 81/2 x 11 in"" (for some of my printers). I also tried DeviceCapabilities with the DC_PAPERNAMES flag, but that only returned the current paper size, though with the more user-friendly dialog paper size name (""Letter 81/2 x 11 in""). Frankly I expected DeviceCapabilities to be the solution. EnumForms is a WinNT call. I assume there's another API for Win9x.Answer:Pick what you need from the unit below:
    {
    PrintUtils:
    This unit collects a number of printer-related helper routines.
    Author: Dr. Peter Below
    Version 1.0 created 26.11.2001
    Current revision: 1.01
    Last modified: 03.12.2001
    }{$BOOLEVAL OFF} {Unit depends on shortcut boolean evaluation}
    unit PrintUtils;interfaceuses
      Windows, Classes, DblRect;type
      TPaperName = array[0..63] of Char;
      TPaperInfo = packed record
        papername: TPapername; { display name of the paper }
        paperID: Word; { DMPAPER_* ID }
        papersize: TPoint; { Size in 0.1 mm }
      end;
      TPaperInfos = array of TPaperInfo;
      TPaperSizes = array of TPoint;
      TPageInfo = record
        width, height: Integer; { physical width and height, in dots }
        offsetX, offsetY: Integer; { nonprintable margin, in dots }
        resX, resY: Integer; { logical resolution, dots per inch }
      end;
      

  2.   

    得到打印机纸张可以用DeviceCapabilities函数,具体用法还是建议参考msdn,一下是例子:
    ......
    var
      sPrinterName, sPort: String;           //打印机的名称,连接端口如LPT1
      lpwPapers: Pointer;      //得到纸张类型名称
      dResult: DWORD;
    begin
      dResult := DeviceCapabilities(PChar(sPrinterName),PChar(sPort),DC_PAPERNAMES, nil, nil);
      if dResult > 0 then begin
        GetMem(lpwPapers, 65);   //分配空间,msdn上注明:每个纸张名都是64个字符
        try
          if DeviceCapabilitiesA(PChar(sPrinterName),PChar(sPort),DC_PAPERNAMES,
          lpwPapers, nil) = - 1 then
            raise Exception.Create('Error');
          ShowMessage(StrPas(lpwPapers));
        finally
          FreeMem(lpwPapers, 65);
        end;
      end;
     
    end;
    ......