Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET itextsharp
Hi all i am a beginner programmer, and have a small problem. I have a webpage with a table that gets its information dynamically from the database. I have a export button that exports the data of the table to pdf format (using ITEXTSHARP). The export button works and the PDF file is saved into the solution folder of the project. But how can i get the PDF file to show after the export button is clicked so the user/viewer can see the pdf and then select where to save it. Any help will be much appreciated, thanking you in advance...
Posted 20-Sep-12 2:10am
Ruwaldo733
Edited 20-Sep-12 2:11am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

1) There is a library called PDF.js, PDF JS[^] you could give this a shot as well.
 
2) PDF Object is a library to render your PDF using js as well. http://pdfobject.com/[^]
-Sample code from their site:
<html>
  <head>
    <title>PDFObject example</title>
    <script type="text/javascript" src="pdfobject.js"></script>
    <script type="text/javascript">
      window.onload = function (){
        var success = new PDFObject({ url: "sample.pdf" }).embed();
      };
    </script>
  </head> 
  <body>
    <p>It appears you don't have Adobe Reader or PDF support in this web
    browser. <a href="sample.pdf">Click here to download the PDF</a></p>
  </body>
</html></html>

 
Hope this helps.
 
David
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Thanks for all the responses. But i ended up just using a hyperlink that points to the pdf file that was created when the user clicked the export button.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

When the user clicks the button at the end of the eventhandler you can use
Response.Redirect(urlToPDF);
For this to work you will need the PDF to be in a folder where the user can browse to.
 
If you leave the content-type default the browser will probably open the document like normal, but it might download it if the user has his settings on that.
If you want to force a download, and leave the user on your page, you will have to change the http content-type header to application/octet-stream.
 
To change the http header you can use the following code.
Response.ContentType = "application/octet-stream";
  Permalink  
Comments
Ruwaldo at 21-Sep-12 4:00am
   
I tried the Rsponse.Redirect but nothing is happening. Im not getting any errors, but its not doing anything

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100