private void Export(LocalReport report)
{
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>EMF</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.25in</MarginTop>" +
" <MarginLeft>0.25in</MarginLeft>" +
" <MarginRight>0.25in</MarginRight>" +
" <MarginBottom>0.25in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
m_streams = new List<Stream>();
report.Render("Image", deviceInfo, CreateStream, out warnings);
foreach (Stream stream in m_streams)
stream.Position = 0;
}
private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
{
Stream stream = new FileStream(name + "." + fileNameExtension, FileMode.Create);
m_streams.Add(stream);
return stream;
}
private void Print()
{
const string printerName = "Microsoft XPS Document Writer";
if (m_streams == null || m_streams.Count == 0)
return;
PrintDocument printDoc = new PrintDocument();
printDoc.PrinterSettings.PrinterName = printerName;
if (!printDoc.PrinterSettings.IsValid)
{
string msg = String.Format("Can't find printer \"{0}\".", printerName);
Console.WriteLine(msg);
return;
}
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
printDoc.Print();
}
private void PrintPage(object sender, PrintPageEventArgs ev)
{
Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
ev.Graphics.DrawImage(pageImage, 0, 0);
m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
}
上面一段代码是把rdlc转换成image流,下面一段是打印这个流。但是我打印出来字体很大而且只显示部分,很多都没显示。我想是不是这个图片流在打印的时候没有缩放成纸张的比例。怎么控制打印图片能在固定格式的纸张中打印完全。假设我的纸张是宽21cm,高14.85cm,也就是A4的一半。怎么修改以上代码。求大神~
注:我在网上找了说可以通过ev.Graphics.DrawImage(pageImage, 0, 0)这句话来控制打印图片的比例,我想问下按我这种纸张怎么设置这些参数?
2 个解决方案
#2
很好很强大,完全是我需要的,谢谢~
#1
#2
很好很强大,完全是我需要的,谢谢~