locked
Export to pdf and print directly . RRS feed

  • Question

  • User919362612 posted

    Sir.

    Is there any ways which i can export the document to pdf on local disk .. instead of exporting  Server drive..

    with regard

    Inao

    Monday, June 2, 2014 3:10 AM

Answers

All replies

  • User-760709272 posted

    Not really.  You'll have to generate the pdf server-side and stream it to the client so that they get the "open\save" dialog.  Google "download pdf file to browser" for how to do this, it is one of the most frequently asked questions.

    Monday, June 2, 2014 5:07 AM
  • User919362612 posted

    Thank you sir. for reply,,  i manage the code which . it can convert the pdf file from crystal report. by using

    reportDocument.ExportToHttpResponse method... but i can identify the specify path to save,
    so is used..
    reportDocument.ExportToDisk medthod .... with specified path.. it works fine.. the problem with this is ... it save iis server drive path.. instead . what i wanted is to save local  (client machine) path...
    Thank you

    Monday, June 2, 2014 9:40 AM
  • User1140095199 posted

    Hi,

    reportDocument.ExportToDisk medthod .... with specified path.. it works fine.. the problem with this is ... it save iis server drive path.. instead . what i wanted is to save local (client machine) path...

    This is happening because you might be generating and saving the data in the client side. You have to provide a download link or redirect the client to download page. Download in the client side cannot initiate without user intervention. It is unethical. User must initiate the download by clicking a link, button or any other method.

    On how to provide a download link and prompt the user to save the file. Refer to the following link:

    http://forums.asp.net/t/1981352.aspx?ftp+asp+net+download+files

    Download initiation code:

            string filename = Request["file"].ToString();
            Response.ContentType = "application/jpeg";
            Response.AddHeader("content-disposition", "attachment; filename="+filename+".jpg");
            Response.WriteFile(Server.MapPath("~/Images/"+filename+""));
            Response.End();
    

    First you may generate and save the file into a folder in the server side. Then you may provide user with download link and use above code.

    You may also generate the document and provide download option to the user on the fly. For that use MemoryStream.

    For reference:

    http://stackoverflow.com/questions/3623797/how-to-convert-pdf-byte-array-to-downloadable-file-using-itextsharp

    http://stackoverflow.com/questions/13473777/how-to-download-memorystream-file

    http://www.aspose.com/community/forums/thread/421623/how-to-create-a-pdf-from-memorystream.aspx

    Hope it helps!

    Best Regards!

    Tuesday, June 3, 2014 2:54 AM
  • User919362612 posted

    thank you sir.

    I will be gratefull. if YOU COULD explain me more details using VB. 

    wITH regard

    Tuesday, June 3, 2014 1:18 PM
  • User1728944201 posted

    In the sample below change "Yourfile.pdf"  to the name of your file

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
          Response.ContentType = myReader("ContentType").ToString()
          Response.AddHeader("content-disposition", "attachment;filename=YourFile.pdf") 
          Response.WriteFile("../Yourfile.pdf")  'Put the path to your file here
          Response.Flush()
          Response.End()
    End Sub
    

    Tuesday, June 3, 2014 2:04 PM
  • User919362612 posted

    Sir..

    I am unable to understand.. what is all about even I have tried does not give / compile.. 

    Please Send me detail.. code it will be helpfull

    Wednesday, June 4, 2014 10:26 PM
  • User1140095199 posted

    Hi,

    I am unable to understand.. what is all about even I have tried does not give / compile.. 

    The code provided works in real life. May i know how you are trying to use it?

    You need to download iTextSharp first.

    http://sourceforge.net/projects/itextsharp/

    After you have the DLL. Include the DLL to the ASP Project and use the above code.

    Also refer to the following article:

    Export HTML DIV contents to PDF using iTextSharp in ASP.Net

    Hope it helps!

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 5, 2014 5:16 AM