这是我使用的代码:
private static int m_currentPageIndex;
report.DataSources.Add(new ReportDataSource(“ dsReceiptInfor”,ReceiptInfor)); ReportParameter [] param = new ReportParameter [2];
param [0] = new ReportParameter(“ imgPath”,FilePath); param [1] = new ReportParameter(“ BaseCurrencyFormat”,BaseCurrencyFormat);
report.SetParameters(param);
导出(报告);
Print();
-导出
private static void Export(LocalReport report)
{
string deviceInfo =
@"<DeviceInfo>
<OutputFormat>EMF</OutputFormat>
<PageWidth>8.5in</PageWidth>
<PageHeight>11in</PageHeight>
<MarginTop>0in</MarginTop>
<MarginLeft>0in</MarginLeft>
<MarginRight>0in</MarginRight>
<MarginBottom>0in</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 static void Print()
{
if (m_streams == null || m_streams.Count == 0)
throw new Exception("Error: no stream to print.");
PrintDocument PrintBill = new PrintDocument();
PrintBill.PrintPage += new PrintPageEventHandler(PrintPage);
PrintBill.PrinterSettings.PrinterName = PrinterName;
PrintBill.PrintController = new StandardPrintController();
m_currentPageIndex = 0;
PrintBill.Print();
}
-PrintPage
private static void PrintPage(object sender, PrintPageEventArgs ev)
{
try
{
Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
//Adjust rectangular area with printer margins.
Rectangle adjustedRect = new Rectangle(
0,
0,
765,
ev.PageBounds.Height);
//Draw a white background for the report
ev.Graphics.FillRectangle(Brushes.White, adjustedRect);
// Draw the report content
ev.Graphics.DrawImage(pageImage, adjustedRect);
// Prepare for the next page. Make sure we haven't hit the end.
m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
}
catch (Exception ex)
{
}
}
当打印数据(PageHeight> 11英寸)时,它将被剪切。你能告诉我如何打印与纸张一样长的纸张。 感谢您的关注:)
答案 0 :(得分:0)
长时间后,我一直在寻找答案,但仍然找不到。所以我找到了一种无需编码的解决方案。 在打印机设置中,我们可以更改打印机首选项:
纸张来源->文档(剪切)。完成