C#以编程方式打印pdf文件?
C# Print pdf file programmatically?
下面给出了我的打印代码
void SaveReport(Telerik.Reporting.Report report, string fileName)
{
ReportProcessor reportProcessor = new ReportProcessor();
Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
instanceReportSource.ReportDocument = report;
RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);
using (FileStream fs = new FileStream(fileName, FileMode.Create))
{
fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
}
// initialize PrintDocument object
PrintDocument doc = new PrintDocument()
{
PrinterSettings = new PrinterSettings()
{
// set the printer to 'Microsoft Print to PDF'
PrinterName = "Canon LBP3000",
// tell the object this document will print to file
// PrintToFile = true,
// set the filename to whatever you like (full path)
PrintFileName = fileName,
}
};
doc.DocumentName = "My";
doc.Print();
}
然后我调用函数
SaveReport(new ThermalPrint(), Server.MapPath(@"~\Report3.pdf"));
函数执行无误,但打印机不打印 pdf 文件。
打印机打印对话框如
我无法理解这个问题。
如果要打印报表,请调用reportProcessor.PrintReport(typeReportSource, printerSettings)
but make sure you provide a valid PrinterSettings
实例。
下面给出了我的打印代码
void SaveReport(Telerik.Reporting.Report report, string fileName)
{
ReportProcessor reportProcessor = new ReportProcessor();
Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
instanceReportSource.ReportDocument = report;
RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);
using (FileStream fs = new FileStream(fileName, FileMode.Create))
{
fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
}
// initialize PrintDocument object
PrintDocument doc = new PrintDocument()
{
PrinterSettings = new PrinterSettings()
{
// set the printer to 'Microsoft Print to PDF'
PrinterName = "Canon LBP3000",
// tell the object this document will print to file
// PrintToFile = true,
// set the filename to whatever you like (full path)
PrintFileName = fileName,
}
};
doc.DocumentName = "My";
doc.Print();
}
然后我调用函数
SaveReport(new ThermalPrint(), Server.MapPath(@"~\Report3.pdf"));
函数执行无误,但打印机不打印 pdf 文件。
打印机打印对话框如
我无法理解这个问题。
如果要打印报表,请调用reportProcessor.PrintReport(typeReportSource, printerSettings)
but make sure you provide a valid PrinterSettings
实例。