打印机的大小设置

procedure SetPrinterPaper(APaperNo: Integer; APaperWidth,

  APaperHeight: Double);

//设置当前打印机的纸张大小

//纸张号 9 A4 13 B5

//页宽和页高,单位mm

var

  Device: array[0..255] of char;

  Driver: array[0..255] of char;

  Port: array[0..255] of char;

  hDMode: THandle;

  PDMode: PDEVMODE;

begin

  Printer.PrinterIndex := Printer.PrinterIndex;

  Printer.GetPrinter(Device, Driver, Port, hDMode);

  if hDMode <> 0 then

  begin

    pDMode := GlobalLock(hDMode);

    if pDMode <> nil then

    begin

      if (APaperNo > 0) and (APaperNo <> DMPAPER_USER) then

      begin

        {设置合法的纸张大小}

        pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;

        pDMode^.dmPaperSize := APaperNo; //DMPAPER_A4  // 合法的纸张大小标示

      end

      else

      begin

        {设置用户自定义纸张}

        pDMode^.dmFields := pDMode^.dmFields or DM_PAPERSIZE or DM_PAPERWIDTH or DM_PAPERLENGTH;

        pDMode^.dmPaperSize := DMPAPER_USER; // 设置为用户自定义纸张标示

        pDMode^.dmPaperWidth := Round(APaperWidth * 10); // 纸张宽度

        pDMode^.dmPaperLength := Round(APaperHeight * 10); // 纸张长度

      end;

      {设定纸张来源}

      pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;

      pDMode^.dmDefaultSource := DMBIN_MANUAL;

      GlobalUnlock(hDMode);

    end;

  end;

end;

procedure SetImagePaper(Img: TImage;APageWidth,APageHeight:Double);

const

  C_InchToMM = 25.38888; //1英寸=25.3888毫米

var

  wnd, hDMode: THandle;

  dc: HDC;

  FPixelX: Integer;

  FPixelY: Integer;

  FXmm: Single;

  FYmm: Single;

  B5Height: Integer;

  B5Width: Integer;

begin

  wnd := GetDesktopWindow;

  dc := GetDC(wnd);

  FPixelX := GetDeviceCaps(dc, LOGPIXELSX);

  FPixelY := GetDeviceCaps(dc, LOGPIXELSY);

  FXmm := FPixelX / C_InchToMM;

  FYmm := FPixelY / C_InchToMM;

  ReleaseDC(wnd, dc);

  Img.Picture.Assign(nil);

  Img.Height := Trunc(FYmm * APageHeight);

  Img.Width := Trunc(FXmm * APageWidth);

end;

上一篇:云计算使存储容量达到顶峰


下一篇:centos6下配置nfs