本文介绍了从Web服务打印文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨...
我正在使用webservice来打印文档,此代码从visual studio中删除但在iis..PLz帮助中托管之后无效...
这是我的代码:
hi...
I am using webservice to print a document ,this code wroks from visual studio but not works after hosting it in iis..PLz help...
Here is my code:
public void chefOrderPrinting(OrderFromService objOrder)
{
try
{
DataTable dtOrderDetails = new DataTable();
dtOrderDetails = objOrder.OrderDetails.ListToDataTable();
ReportParameter[] arrParams = new ReportParameter[1];
// string PrinterName;
//PrinterName = ApplicationSettings.Default.ChefOrderPrint;
arrParams[0] = new ReportParameter("rpt_TableNo", objOrder.tableName);
ReportPrintClass objReportPrintClass;
objReportPrintClass = new ReportPrintClass("DataSetChefWorkForService_Rpt_ChefWorkForService", dtOrderDetails, @"Report\ChefWorkForService.rdlc", arrParams, 8.27, 11.69, 0.5, 0.5, 0.2, 0.2);
// objReportPrintClass.Print(@"Send To OneNote 2007", 1);
objReportPrintClass.Print(ConfigurationSettings.AppSettings["PrinterName"], 1);
}
catch(Exception ex)
{
}
}
public ReportPrintClass(string _DataSourceName, DataTable _DataSourceValue, string _ReportPath, double pagewidth, double pageheight, double leftmargin, double rightmargin, double topmargin, double bottommargin)
{
this.pageWidth = pagewidth;
this.pageHeight = pageheight;
this.leftMargin = leftmargin;
this.rightMargin = rightmargin;
this.topMargin = topmargin;
this.bottomMargin = bottommargin;
LocalReport report = new LocalReport();
report.ReportPath = _ReportPath;
report.DataSources.Add(new ReportDataSource(_DataSourceName, _DataSourceValue));
Export(report);
m_currentPageIndex = 0;
}
public ReportPrintClass(string _DataSourceName, DataTable _DataSourceValue, string _ReportPath, ReportParameter[] arrParams, double pagewidth, double pageheight, double leftmargin, double rightmargin, double topmargin, double bottommargin)
//{
// public ReportPrintClass(string _DataSourceName, List<productdetails> _DataSourceValue, string _ReportPath, ReportParameter[] arrParams, double pagewidth, double pageheight, double leftmargin, double rightmargin, double topmargin, double bottommargin)
{
//objCommonClass.ErrorLog("Service :: InsertOrders()", "printing ", "reached upto Report Print Class");
this.pageWidth = pagewidth;
this.pageHeight = pageheight;
this.leftMargin = leftmargin;
this.rightMargin = rightmargin;
this.topMargin = topmargin;
this.bottomMargin = bottommargin;
LocalReport report = new LocalReport();
report.ReportPath = _ReportPath;
report.DataSources.Add(new ReportDataSource(_DataSourceName, _DataSourceValue));
report.SetParameters(arrParams);
Export(report);
m_currentPageIndex = 0;
}
// Routine to provide to the report renderer, in order to
// save an image for each page of the report.
private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
{
// objCommonClass.ErrorLog("Service :: InsertOrders()", "printing ", "reached upto Report Print create stream ");
Stream stream = new FileStream(name +
"." + fileNameExtension, FileMode.Create);
m_streams.Add(stream);
return stream;
}
// Export the given report as an EMF (Enhanced Metafile) file.
private void Export(LocalReport report)
{
// objCommonClass.ErrorLog("Service :: InsertOrders()", "printing ", "reached upto Report Print Export function ");
string deviceInfo =
"<deviceinfo>" +
" <outputformat>EMF</outputformat>" +
" <pagewidth>" + pageWidth + "in</pagewidth>" +
" <pageheight>" + pageHeight + "in</pageheight>" +
" <margintop>" + topMargin + "in</margintop>" +
" <marginleft>" + leftMargin + "in</marginleft>" +
" <marginright>" + rightMargin + "in</marginright>" +
" <marginbottom>" + bottomMargin + "in</marginbottom>" +
"</deviceinfo>";
Warning[] warnings;
m_streams = new List<stream>();
try
{
report.Render("Image", deviceInfo, CreateStream, out warnings);
}
catch (LocalProcessingException ex)
{
}
foreach (Stream stream in m_streams)
stream.Position = 0;
}
// Handler for PrintPageEvents
private void PrintPage(object sender, PrintPageEventArgs ev)
{
// objCommonClass.ErrorLog("Service :: InsertOrders()", "printing ", "reached upto Report Print page function ");
Metafile pageImage = new
Metafile(m_streams[m_currentPageIndex]);
ev.Graphics.DrawImage(pageImage, ev.PageBounds);
m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
}
public void Print(string printerName, Int16 noCopy)
{
// objCommonClass.ErrorLog("Service :: InsertOrders()", "printing ", "reached upto Report Print page Print Function ");
if (m_streams == null || m_streams.Count == 0)
return;
PrintDocument printDoc = new PrintDocument();
printDoc.PrinterSettings.Copies = noCopy;
printDoc.PrinterSettings.PrinterName = printerName;
if (!printDoc.PrinterSettings.IsValid)
{
//string msg = String.Format(
// "Can't find printer \"{0}\".", printerName);
//MessageBox.Show(msg, "Print Error");
//return;
}
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
try
{
printDoc.Print();
}
catch (Exception ex)
{
// objCommonClass.ErrorLog("Service :: InsertOrders()", "printing ", "reached upto Report Print page Print Function "+ex.Message+" " +ex.InnerException);
}
}
public void Dispose()
{
// objCommonClass.ErrorLog("Service :: InsertOrders()", "printing ", "reached upto Report Print page Print Dispose ");
{
foreach (Stream stream in m_streams)
stream.Close();
m_streams = null;
}
}
}
}</stream></productdetails>
推荐答案
这篇关于从Web服务打印文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!