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;

  • 相关阅读:
    利用数组将九种颜色不重复的显示在九个盒子中
    gulp结合webpack开启多页面模式,配置如下
    parent获取子元素以及自身元素
    利用键值对来找对应值的信息
    Math.random 随机数方法
    常用linux,DOS命令——持续更新
    函数嵌套函数传递this值
    空对象模式
    状态模式(状态机)
    观察者模式
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2035706.html
Copyright © 2011-2022 走看看