LocalReport收据打印

时间:2013-04-17 13:41:39

标签: c# reporting-services

我使用LocalReport打印3英寸收据,代码来自“Walkthrough: Printing a Local Report without Preview

某些打印机要求DeviceInfo PageWidth为8.5英寸才能正常工作,有些需要3.0英寸。它似乎正在拉伸报告以填充错误大小的页面。我试图调整报告纸张尺寸和打印机纸张尺寸,但似乎无法获得正确的组合。

有没有人经历过这个?

2 个答案:

答案 0 :(得分:0)

我想出来了。您需要考虑打印机dpi。

获取打印机默认页面设置:

        PrinterSettings ps = new PrinterSettings();
        ps.PrinterName = printerName;
        this.defaultPageSettings = ps.DefaultPageSettings;

使用该信息构建DeviceInfo Xml:

    private string BuildDeviceInfo()
    {
        StringBuilder returnValue;
        System.Xml.XmlWriter writer;

        returnValue = new StringBuilder(1024);
        writer = System.Xml.XmlWriter.Create(returnValue);

        writer.WriteStartElement("DeviceInfo");
        writer.WriteElementString("OutputFormat", "EMF");

        if (defaultPageSettings != null)
        {
            // DPI will keep the output from scaling in weird ways
            writer.WriteElementString("PrintDpiX", defaultPageSettings.PrinterResolution.X.ToString());
            writer.WriteElementString("PrintDpiY", defaultPageSettings.PrinterResolution.Y.ToString());

            writer.WriteElementString("PageWidth", (defaultPageSettings.PaperSize.Width / 100m).ToString("F2") + "in");
            writer.WriteElementString("PageHeight", (defaultPageSettings.PaperSize.Height / 100m).ToString("F2") + "in");
       }
        writer.Close();

        return returnValue.ToString();
    }

答案 1 :(得分:0)

这对我有用。我从WPF应用程序打印到STAR TSP100收据打印机。当我设置边距&页面大小我自己来了很大,但当我计算最小边距和页面大小以及从默认打印机设置设置dpi时,收据打印正确。

我用它来计算最小边距:( H / T http://www.dreamincode.net/forums/topic/135864-printing-with-minimum-margins-specified-by-the-printer/

Dim minimumMarginLeft, minimumMarginRight, minimumMarginTop,
 minimumMarginBottom As Single

minimumMarginLeft = PrintDialog1.PrinterSettings.DefaultPageSettings.PrintableArea.Left

minimumMarginRight = PrintDialog1.PrinterSettings.DefaultPageSettings.PaperSize.Width - _
                                  PrintDialog1.PrinterSettings.DefaultPageSettings.PrintableArea.Right

minimumMarginTop = PrintDialog1.PrinterSettings.DefaultPageSettings.PrintableArea.Top

minimumMarginBottom =  PrintDialog1.PrinterSettings.DefaultPageSettings.PaperSize.Height - _
                                      PrintDialog1.PrinterSettings.DefaultPageSettings.PrintableArea.Bottom


-I figured this out. You need to account for the printer dpi.

-Get the Printer Default Page Settings:

        PrinterSettings ps = new PrinterSettings();
        ps.PrinterName = printerName;
        this.defaultPageSettings = ps.DefaultPageSettings; The Build the DeviceInfo Xml with that info:

    private string BuildDeviceInfo()
    {
        StringBuilder returnValue;
        System.Xml.XmlWriter writer;

        returnValue = new StringBuilder(1024);
        writer = System.Xml.XmlWriter.Create(returnValue);

        writer.WriteStartElement("DeviceInfo");
        writer.WriteElementString("OutputFormat", "EMF");

        if (defaultPageSettings != null)
        {
            // DPI will keep the output from scaling in weird ways
            writer.WriteElementString("PrintDpiX", defaultPageSettings.PrinterResolution.X.ToString());
            writer.WriteElementString("PrintDpiY", defaultPageSettings.PrinterResolution.Y.ToString());

            writer.WriteElementString("PageWidth", (defaultPageSettings.PaperSize.Width / 100m).ToString("F2") + "in");
            writer.WriteElementString("PageHeight", (defaultPageSettings.PaperSize.Height / 100m).ToString("F2") + "in");
       }
        writer.Close();

        return returnValue.ToString();
    }