Force file name

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for COM/ActiveX (v8)  /  Force file name

DynamicPDF CoreSuite for COM/ActiveX (v8) Forum

 Mar 06 2018 7:32 PM
Hello, when I use DrawToWeb, if a user chooses  to "Download" or "Save As" the pdf, the default file name is always "DynamicPDF.pdf"  Is there a way to change the default save-as file name to something else?
--jim
 Mar 08 2018 11:22 AM
Posted by a ceTe Software moderator
Hello,

When you use DrawToWeb method to send the PDF to a browser, it will be up to the browser to display the PDF using a PDF viewer plug-in. It is not possible to change the default file name when the “SaveAs” or Download button is clicked in the browser. After the PDF is sent to the browser, our API does not have control over the file name that the PDF Viewer plug-in determines.

You can force the browser to download the file to disk and set the desired name for the file. To achieve this you will need to use the Draw() method to write the PDF into a byte array and  then use the BinaryWrite to send the PDF to the browser by setting appropriate headers. Below is the code sample.

            Dim MyDocument, MyPage
            Dim MyStrText
           
            ' Create Document object and set properties
            Set MyDocument = Server.CreateObject( "DynamicPDF.Document" )
            MyDocument.Creator = "HelloWorld.asp"
            MyDocument.Author = "test"
            ' Add a page to the document
            Set MyPage = MyDocument.AddPage()
            ' Add a textarea to the page
            MyStrText = "Hello ASP World..." & vbCrLf & "From DynamicPDF™ Generator for COM/ActiveX" & vbCrLf & "DynamicPDF.com"
            MyPage.AddTextArea MyStrText, 0, 0, 504, 100, DPDF_TextAlign_Center, DPDF_Font_Helvetica, 18
           
            ' use the Draw method of output the PDF as byte array.
            Dim MyDocByte            
               MyDocByte = MyDocument.Draw()
             
            ' Take the PDF byte array and stream it to the browser.
            Response.Clear()
            Response.Addheader "Content-Disposition", "attachment; filename=" & "MyTestDocument.pdf"
            Response.ContentType = "application/pdf"   
            Response.Buffer = True    
            Response.BinaryWrite( MyDocByte )
  
            Set Mypage = Nothing
            Set MyDocument = Nothing      

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 11:56 AM.