简体   繁体   中英

Microsoft Report page orientation (VS 2013, C#)

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!

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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM