• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Download PDF

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am developing one web project using Flex/JSP/Java... In my project i have to set two buttons, one for downloading data in excel sheet and other one for downloading data in pdf file..for downloading data in excel sheet i use the following code..




this is working fine...

when i use the same code with some modifications for downloading data in pdf file it is causing problem...
the code which i use is






what type of code i have to use for downloading data in pdf file through jsp...
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HTML is not PDF. Just because you tell the browser that you're sending it PDF, isn't going to transform HTML into PDF. You need to generate a real PDF format. There are a number of 3rd party libraries to do this. Do a google search for them.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And just to make it abundantly clear, a PDF is a binary document rather than a text one.

As such requests for PDF documents should be handled by a servlet rather than a JSP, as the JSP will add whitespace into the response potentially corrupting it.
 
s.palanivel rajan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i wrote the coding with the help of "IText", a free java library which i got from internet....

the code now i am using is...




This is working fine...but while using this code the pdf documnet get created and stored in the location which i specified..

PdfWriter.getInstance(document,new FileOutputStream("C:/palanivelrajan/ValidData.pdf"));

but what my actual need is to create document and to ask user "save or open"....we have to give the option for storing the document where he needs to save..

what to do for that....


 
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
  • The iText version you're using (iText 5) is covered by the GNU Affero license, which makes it non-free for most business uses. Make sure you (and your company's lawyer) understand what that means.
  • You should not use JSPs for doing this kind of stuff; that's what servlets are for. Java code has no place in JSPs.
  • You need to stream the PDF data to the client in order to get the Save/Open option; search for "streaming binary data from a servlet" or some such phrase. This has been discussed multiple times in these forums.
  •  
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi ,

    But i have a complete jsp project...
    Can you please tell me how to do in jsp using itext....
    As i m converting the data to excel and word format...
    i need to do it for pdf also.....only this module is pending in my whole project....
    would please help him me as soon as possible.
    I have the same location problem.......as i want the user to open and save it inline
     
    Rancher
    Posts: 43081
    77
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The advice given by Bear, Stefan and Tim is spot on: 1) Don't use JSPs for stuff like this, because it's really bad design. 2) Don't use JSPs for stuff like this, because it is very likely not to work.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic