打印预览而不将文件保存为pdf [英] Print preview without saving the file into pdf
问题描述
我创建了一个Windows窗体的水晶报表和一个Crystalreportviewer.以下是我的代码.
Hi,
I''ve created one crystal report in windows form and one crystalreportviewer. The following is my code.
//in form1.cs file
try
{
ExportOptions CrExportOptions;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = "c:\\csharp.net-informations.pdf";
CrExportOptions = cryRpt.ExportOptions;
{
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
}
cryRpt.Export();
}
上面的代码将文件保存为pdf到指定的路径.我不想保存文件,我应该直接进行打印预览并可以选择打印.
就像我们在使用Crystal Report Viewer的Web应用程序中所做的一样,单击打印",然后将以pdf格式打开报告,然后单击打印".
我想要与我们在Web应用程序中相同的功能.我正在C#.Net中编写代码
希望上面的解释能清楚理解.
Above code is saving the file into pdf into specified path. I dont want to save a file I should get direct print preview and have a option to print.
As we do in web application using crystal report viewer clicking print and report will be opened in pdf and the click print.
I want the same function as we do in web application. I am writing code in C#.Net
Hope the above explaination will be understood clearly.
推荐答案
您可以在ASP.Net中以这种方式将Crystal报表导出到内存pdf:
You can export a crystal report to a memory pdf this way in ASP.Net:
MemoryStream oStream; // using System.IO
oStream = (MemoryStream)
report.ExportToStream(
CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/pdf";
Response.BinaryWrite(oStream.ToArray());
Response.End();
如果使用Windows窗体,则需要使用Crystal Report Viewer控件.这是有关如何使用该控件的教程:
http://www.aspfree.com/c /a/.NET/Using-CrystalReportViewer-to-Display-Crystal-Reports-in-Net [
If you are using windows forms, you need to use the crystal report viewer control. Here is a tutorial on how to use that control:
http://www.aspfree.com/c/a/.NET/Using-CrystalReportViewer-to-Display-Crystal-Reports-in-Net[^]
这篇关于打印预览而不将文件保存为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!