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;

  • 相关阅读:
    漫谈C语言结构体
    如何理解c和c++的复杂类型声明
    STM32 时钟系统
    STM32 系统架构
    运放参数的详细解释和分析-part1,输入偏置电流和输入失调电流【转】
    ROM、RAM、DRAM、SRAM、FLASH的区别?
    FATFS模块应用笔记
    关于I2C和SPI总线协议【转】
    USB编程概念
    Ubuntu手机识别
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2035706.html
Copyright © 2011-2022 走看看