Good day!

I need to print short card from RichTextBox. Size of card is 10x14 cm.

Because of customer's printer features we can put card in a printer only this way:

example image

I've tried to set PageSettings two ways:

  1. PageSettings.Width = 10; PageSettings.Height = 14.
  2. PageSettings.Width = 14; PageSettings.Height = 10.

And printable area looks like this:

enter image description here

Here's the code how the printing is released:

btnRotate.CheckedChanged += (s, e) => InitPaperSize();

private void InitPaperSize()
    {
        string name = btnRotate.Checked ? "ShortCard (rotate)" : "ShortCard";
        int width = Centimeters(btnRotate.Checked ? 14 : 10);
        int height = Centimeters(btnRotate.Checked ? 10 : 14);

        System.Drawing.Printing.PaperSize ps = new System.Drawing.Printing.PaperSize(name, width, height);
        printDocument.DefaultPageSettings.PaperSize = ps;
    }

private int Centimeters(int centimeters)
    {
        return (int)((centimeters * 100) / 2.54);
    }

public int PrintRotate(bool rotate, PrintPageEventArgs e, int charFrom, int charTo)
    {
        //Calculate the area to render and print
        RECT rectToPrint;
        rectToPrint.Top = (int)(e.MarginBounds.Top * anInch);
        rectToPrint.Bottom = (int)(e.MarginBounds.Bottom * anInch);
        rectToPrint.Left = (int)(e.MarginBounds.Left * anInch);
        rectToPrint.Right = (int)(e.MarginBounds.Right * anInch);

        //Calculate the size of the page
        RECT rectPage;
        rectPage.Top = (int)(e.PageBounds.Top * anInch);
        rectPage.Bottom = (int)(e.PageBounds.Bottom * anInch);
        rectPage.Left = (int)(e.PageBounds.Left * anInch);
        rectPage.Right = (int)(e.PageBounds.Right * anInch);

        IntPtr hdc = e.Graphics.GetHdc();

        FO
Edit
Report