Hello!
I have a web application that generates documents as rtf files. The user can download these files from a webpage by clicking on a link to them.
I would like the files to be automatically downloaded as PDF files and not as RTF files.
How could I do that?
Thank you.
Loading

Rewant ChoudharyRank #4,270 · 354 reputationPosted Sep 7, 2012, 6:12 AM EDT
Kamal RawatRank #567 · 4.3K reputationPosted Sep 7, 2012, 9:37 PM EDT
Dim FileName As String = Path.GetFileName(FullFileName) //Function provides file path
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment; filename=" & FileName)
Response.WriteFile(FullFileName)
Response.[End]()
C# .NET
string FileName = Path.GetFileName(FullFileName); //Function provides file path Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName); Response.WriteFile(FullFileName);
Response.End();
Please mark it as Accept, if it helps..
Cyrille Rey24 reputationPosted Sep 10, 2012, 4:22 AM EDT
Thank you for your answer.
However, the documents are generated as rtf documents. What I want to do is for them to be converted to pdf when the user clicks download.
Is that possible?
How could I do it?
Thank you.
Sharon White50 reputationPosted Sep 13, 2012, 12:53 AM EDT
Pradip PandeyRank #452 · 5.6K reputationPosted Sep 13, 2012, 3:54 AM EDT
This you can do by using this code:
1. Add reference for CrystalDecisions.CrystalReports.Engine.
2. Add assembly in your page like this
<%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
3. Add CrystalReportViewer in you page deign like this
4. Create a Crystal Report by using a view e.g. vw_VendorList.
VB.Net Code:
Dim Rpt As New ReportDocument
Rpt.Load(Server.MapPath("abc.rpt"))
Dim ds As New Data.DataSet
Dim dt As New SqlDataAdapter("Select * from VW_VendorList", ConnString)
dt.Fill(ds, "VW_VendorList")
Rpt.SetDataSource(ds)
CRV.ReportSource = Rpt Rpt.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, True, "Vendor List Report")
After running this code, crystal report file will be exported in the form of Pdf.
Hope it will help.
Sharon Thompson14 reputationPosted Apr 2, 2015, 12:45 AM EDT
For example this is one of the simplest solutions to achieve the required conversion and also export that resulting PDF file to ASP.NET's client:
var document = DocumentModel.Load("Sample.rtf"); document.Save(this.Response, "Sample.pdf");