【问题标题】:Print text vertically垂直打印文本
【发布时间】:2014-01-03 06:08:40
【问题描述】:

我有一张支票,我正在尝试手动打印其数据 - 不允许使用报告工具 - 我的目标是 PDF 打印机和支票纸,我必须使用 A4 打印机。

这是一个插图:

我的步骤是:

  1. 将支票尺寸指定为我的实际纸张尺寸。
  2. 写入数据。
  3. 将结果打印到打印机。

在第 1 步中,我创建了 PrintDocument 实例并设置 DefaultPageSettings.PaperSize 以通过将 RawKind 设置为 120 来匹配输入纸张尺寸,这意味着自定义纸张尺寸,然后我设置了一个 PrintPage 处理程序,然后我打电话给Print

在第 2 步中,将数据写入e.Graphics 没有问题。

在步骤 3 中,当打印到 PDF 打印机时,结果符合预期,并且可以复制字符串,并且支票图像上的手动预览也很好。

当我打印到 A4 打印机 - HP Laserjet 1018 时的问题 - 我将上纸盘的标尺设置在中间,以便它可以容纳我放置的支票垂直,现在打印两个事情发生了:

  1. 水平打印的文本。
  2. 由于打印机标尺设置在中间,打印位置无效(或者我认为是,我实际上没有机会测试该结果)。

如何解决打印机问题?

【问题讨论】:

标签: c# printing


【解决方案1】:
    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        float vlblControlWidth;
        float vlblControlHeight;
        float vlblTransformX;
        float vlblTransformY;

        Color controlBackColor = BackColor;
        Pen labelBorderPen;
        SolidBrush labelBackColorBrush;

        if (_transparentBG)
        {
            labelBorderPen = new Pen(Color.Empty, 0);
            labelBackColorBrush = new SolidBrush(Color.Empty);
            }
            else
            {
               labelBorderPen = new Pen(controlBackColor, 0);
              labelBackColorBrush = new SolidBrush(controlBackColor);
          }

        SolidBrush labelForeColorBrush = new SolidBrush(base.ForeColor);
        base.OnPaint(e);
        vlblControlWidth = this.Size.Width;
        vlblControlHeight = this.Size.Height;
        e.Graphics.DrawRectangle(labelBorderPen, 0, 0, 
                                 vlblControlWidth, vlblControlHeight);
        e.Graphics.FillRectangle(labelBackColorBrush, 0, 0, 
                                 vlblControlWidth, vlblControlHeight);
        e.Graphics.TextRenderingHint = this._renderMode;
        e.Graphics.SmoothingMode = 
                   System.Drawing.Drawing2D.SmoothingMode.HighQuality;

        if (this.TextDrawMode == DrawMode.BottomUp)
        {
            vlblTransformX = 0;
            vlblTransformY = vlblControlHeight;
            e.Graphics.TranslateTransform(vlblTransformX, vlblTransformY);
            e.Graphics.RotateTransform(270);
            e.Graphics.DrawString(labelText, Font, labelForeColorBrush, 0, 0);
        }
        else
        {
                 vlblTransformX = vlblControlWidth;
                 vlblTransformY = vlblControlHeight;
                 e.Graphics.TranslateTransform(vlblControlWidth, 0);
                 e.Graphics.RotateTransform(90);
                 e.Graphics.DrawString(labelText, Font, labelForeColorBrush, 0,
                                     0,StringFormat.GenericTypographic);
            }            
        }

        SetStyle(System.Windows.Forms.ControlStyles.Opaque, true);

  }

protected override CreateParams CreateParams
{
    get
    {
        CreateParams cp = base.CreateParams;
        cp.ExStyle |= 0x20;  // Turn on WS_EX_TRANSPARENT
        return cp;
    }
}

【讨论】:

    猜你喜欢
    • 2013-12-23
    • 2011-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-08
    • 2016-02-24
    • 1970-01-01
    • 2022-01-07
    相关资源
    最近更新 更多