I would like to generate a pdf file when the user clicks on it, an not before. Then after the doc is generated, ideally, I would like to give the user the option to either view the document or download it. If they choose to download, I’d like to display the Save As file dialog box with an appropriate default file name. If they choose to view, I’d like to view the document in a new window regardless of the users local settings for a PDF extension (I’m not sure if a user can control whether a pdf is opened in a new window or now like they can for MS Office file extensions.)
The following code generates the doc and presents the user with a dialog box to save, but the default dialog is the name of the web page(e.g. WebPageName.pdf) rather than a default file name that I would prefer.
Is there a way to control what the default file name that is used to prefilled the Save As Dialog box?
I’m not sure how to get all this functionality in one link.
Protected Sub imgPdf_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
SessionVariables.ChinaVisaId = New SqlInt32(CType(CType(sender, ImageButton).CommandArgument, Integer))
Dim TargetChinaVisa As ChinaVisa = _Order.ChinaVisas.ItemById(SessionVariables.ChinaVisaId)
Dim DocName As String = TargetChinaVisa.ReferenceNumber & ".pdf"
Dim PdfPath As String = Server.MapPath("~/Files/") & DocName
Dim RelativePath As String = "~/Files/" & DocName
Dim AbsolutePath As String = "http://" & _SiteName & "/Files/" & DocName
Dim MyPDF As New ChinaVisaPdf(TargetChinaVisa)
MyPDF.SaveAsPdf(PdfPath)
Server.Transfer(RelativePath)
End Subs
Side question: When opening a doc in a new window, I assume that that has to be done with client side code and an absolute path?
To set the default file name, you need to pass the suggested filename in the “Content-Disposition” HTTP header, something like this:
That’s in C#, it would be more or less the same syntax in VB (I think!)