0
votes

I am printing labels with MS Report (c#/VS2013). The labels are 8 cm wide and 4 cm high. The printer sees and feeds them as portrait (no rotation) but the report viewer prints them landscape because the width is greater than the hight. Printer specific page orientation change before printing are ignored (!), so the labels are always printed in a 90° rotation against the label orientation. printer is an industial thermo transfer printer.

I don't understand why the page orientation is bound to the relation between hight and width and cannot be set indepenently! I already tried to change the orientation right before printing - this caused the labes be printed in several pieces but did not rotate them.

The only thing that helped was changing the paper size to 8 width and 8.1 height. Then the labels print correctly but this leads to a lot of empty pages (labels) and is no good solution.

The only way I see currently is redesigning all the labels rotated by 90° which is quite some effort, so I would be grateful if someone had a solution for this stange behaviour!

1

1 Answers

1
votes

I solved this issue by rendering to an image and printing that through a PrintDocument object. This way I am able to send the landscape-formed label (8cm width, 4cm height) to the printer in portrait.

I am sure this can be done more elegant but due to time pressure I now go with this solution:

String tempDir = Path.GetTempFileName();
File.Delete(tempDir);
Directory.CreateDirectory(tempDir);
tempDir = Utils.addBackslash(tempDir);
ExportToPNG(tempDir);
String imageFile = Utils.FindFirstFile(tempDir, "*.png");
if (imageFile != "")
{
    PrintDocument pd = new PrintDocument();
    try
    {
        pd.DefaultPageSettings.PrinterSettings.PrinterName = DB.Instance.getSetting("label.printername");
    }
    catch
    {
        // This is just a preset, it may fail without consequences
    }

    pd.DefaultPageSettings.Landscape = false; // Now I can do it!
    pd.PrintPage += (sender, args) =>
    {
        Image i = Image.FromFile(imageFile);
        Point p = new Point(100, 100);
        args.Graphics.DrawImage(i, 0, 0, i.Width, i.Height);
    };
    PrintDialog pdi = new PrintDialog();
    pdi.Document = pd;
    if (pdi.ShowDialog() == DialogResult.OK)
        pd.Print();
    pd.Dispose();
}