zoukankan      html  css  js  c++  java
  • 打印机的大小设置

    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;

  • 相关阅读:
    sklearn的preprocessing模块--数据预处理
    [系列转载]一.建模前的数据清洗与处理
    2.2 数学科学的数学之矩阵-行列式
    4)函数极限与连续函数
    6)导数
    java编写基于netty的RPC框架
    购买阿里云 实现内网 穿透 仅86元/年,而且
    OAuth 2.0
    java中JVM内存管理(1)
    java实现,使用opencv合成全景图,前端使用krpano展示
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2035706.html
Copyright © 2011-2022 走看看