Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generating PDF for printing without exporting to disk?

Status
Not open for further replies.

glyph1

Programmer
Jun 15, 2007
26
0
0
Using: Visual Studio.NET Crystal Reports, ASP.NET, C#

The following code takes my parameters into the report, exports to a pdf on the client side and redirects the client to the PDF file. I need to load the pdf without leaving a file on the client or server. My basis for comparison is the way the CrystalReportViewer handles the PDF before printing. I have not been able to see where the PDF file goes though once you click on the "OK" button and the PDF generates, but that is my goal if it can run in memory somehow.

1 protected void Page_Load(object sender, EventArgs e)
2 {
3 Session["Var"] = 9;
4
5 ParameterField pf1 = new ParameterField();
6 ParameterDiscreteValue pd1 = new ParameterDiscreteValue();
7 ParameterValues pv1 = new ParameterValues();
8
9 pf1.Name = "SelectParameter";
10 pd1.Value = Int32.Parse(Session["Var"].ToString());
11 pf1.CurrentValues.Add(pd1);
12
13 string path = "c:\\windows\\temp\\";
14 string strFileName = path + "GenForm.pdf";
15
16 ReportDocument rptDoc = new ReportDocument();
17 rptDoc.Load(Server.MapPath(@"GenForm.rpt"));
18
19 ExportOptions exportOpts = new ExportOptions();
20 PdfRtfWordFormatOptions pdfopts = new PdfRtfWordFormatOptions();
21 DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();
22 exportOpts = rptDoc.ExportOptions;
23 exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
24 exportOpts.FormatOptions = pdfopts;
25 exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
26 // diskOpts.DiskFileName = Server.MapPath(strFileName);
27 diskOpts.DiskFileName = path + strFileName;
28 exportOpts.DestinationOptions = diskOpts;
29 rptDoc.SetParameterValue("SelectParameter", pd1);
30 rptDoc.SetParameterValue("SubReportParameter", pd1);
31 rptDoc.ExportToDisk(ExportFormatType.PortableDocFormat, (strFileName));
32 Response.ClearContent();
33 Response.ClearHeaders();
34 Response.ContentType = "application/pdf";
35 Response.WriteFile(strFileName);
36 Response.Flush();
37 Response.Close();
38 // rptDoc.Export();
39 // rptDoc.PrintToPrinter(1, false, 0, 0);
40 System.IO.File.Delete(path + strFileName);
41 Response.Redirect((path + strFileName));
42 }


Anyone who has any resources that can help would be greatly appreciated. Thank you in advance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top