我用打印的代碼一LocalReport 3英寸收據「Walkthrough: Printing a Local Report without Preview」LocalReport收據打印
某些打印機需要的DeviceInfo頁寬爲8.5in正常工作和一些需要3.0英寸它似乎是報告正在擴大,以填補一個錯誤的大小頁面。我試圖調整報告紙張尺寸和打印機紙張尺寸,但似乎無法獲得正確的組合。
有沒有人遇到過這個?
我用打印的代碼一LocalReport 3英寸收據「Walkthrough: Printing a Local Report without Preview」LocalReport收據打印
某些打印機需要的DeviceInfo頁寬爲8.5in正常工作和一些需要3.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();
}
這爲我工作。我正在從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();
}
工作的?可能不會... – RolandoCC