1
votes

I've a Cheque and I'm trying to print its data manually - report tools aren't permitted - and my target is a PDF printer and Cheque paper and I must use an A4 printer.

Here is an illustration:

My steps are:

  1. Specify cheque size as my actual paper size.
  2. write the data.
  3. Print result to the printer.

In step 1, I've created PrintDocument instance and set DefaultPageSettings.PaperSize to match the input paper dimensions by setting RawKind to 120 which means custom paper size, then I setup a PrintPage handler, Then I call Print.

In Step 2, that data written to the e.Graphics without problem.

In Step 3, when print to a PDF printer the result is as expected, and the strings can be copied, also the manual preview on a a cheque image is good.

The problem when I print to the A4 printer - HP Laserjet 1018 - I set the ruler of upper paper tray to the middle so it can hold the cheque which I put vertically, Now when printing two thing happened:

  1. the text printed horizontally.
  2. because printer ruler is set to the middle, the print location is invalid (or i think so, i didn't actually get the chance to test that result).

How can I fix the printer problems?

1
I have edited your title. Please see, "Should questions include “tags” in their titles?", where the consensus is "no, they should not". - John Saunders
got it, won't forget it again, thanks - Muhammad

1 Answers

0
votes
    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;
    }
}