有没有做过Reprot报表RDLC直接打印的兄弟,遇到点麻烦,进来看一下。。
private void Print3()
{
const string printerName="GP-5890XIII";
if (m_streams == null || m_streams.Count == 0)
return;
PrintDocument printDoc = new PrintDocument();
printDoc.PrinterSettings.PrinterName = printerName;
printDoc.DefaultPageSettings.Landscape = false;
// printDoc.PrinterSettings.DefaultPageSettings.PaperSize = printDoc.PrinterSettings.PaperSizes[0];
foreach (PaperSize ps in printDoc.PrinterSettings.PaperSizes)
{
string myTempID = ps.PaperName;
if (myTempID == "Gprinter 58(48) x 299 mm")
{
printDoc.PrinterSettings.DefaultPageSettings.PaperSize = ps;
printDoc.DefaultPageSettings.PaperSize = ps;
}
}
if (!printDoc.PrinterSettings.IsValid)
{
string msg = string.Format("Can't find printer "{0}".", printerName);
return;
}
printDoc.PrintPage += new PrintPageEventHandler(PrintPage3);
printDoc.Print();
}
private void PrintPage3(object sender, PrintPageEventArgs ev)
{
//Metafile对象用来保存EMF或WMF格式的图形,
//我们在前面将报表的内容输出为EMF图形格式的数据流。
m_streams[m_currentPageIndex].Position = 0;
Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
//指定是否横向打印
ev.PageSettings.Landscape = false;
//这里的Graphics对象实际指向了打印机
ev.Graphics.DrawImage(pageImage, 0, 0);
m_streams[m_currentPageIndex].Close();
m_currentPageIndex++;
//设置是否需要继续打印
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
}