• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generate PDF

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,

I want to generate a pdf document from any html or jsp please give me a sample code.

and it will be more helpful if any one gives me a sample code how to draw a table of labels(html) and that i want to generate in pdf.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no Java code available to create a PDF file from an HTML file, and it would be quite a task to write one (essentially you'd be duplicating an HTML renderer, only that it doesn't draw on the screen but creates PDF).

If your HTML originates from XML, you might have a chance to use FOP for this. If the HTML is generated directly by Java code, you could use iText to create both the HTML and the PDF. Both methods have drawbacks, though, and can't be used if the HTML is generated by JSP. (Links to FOP and iText are here.)
[ December 06, 2006: Message edited by: Ulf Dittmer ]
 
Njk Naresh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
___________________
|first |second|third |
|fourth |fifth |sixth |
|seventh| eight| nine |
|_______|______|______|


Hi,
i want to generate a pdf as like this i,e it mean i want to draw borders as the above table shows and any header and footers
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
iText has extensive support for tables , and headers and footers are quite easy to achieve as well.
[ December 06, 2006: Message edited by: Ulf Dittmer ]
 
Greenhorn
Posts: 12
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
You can download this jar file (search in google) or you may get it on ibm site.

itext-1.4.4.jar

This is the sample code which will help to create PDF file. Apply your logic to make a design inside code document.add();Implement this in your action.

///Sample Code
Document document = new Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, baos);
document.open();
BaseFont bf;
Font font;
//bf =
// BaseFont.createFont("c:/windows/fonts/msgothic.ttc,0",BaseFont.IDENTITY_H,BaseFont.EMBEDDED);
bf = BaseFont.createFont(path, BaseFont.IDENTITY_H,BaseFont.EMBEDDED);
font = new Font(bf, 12);
document.add(new Paragraph("Your text may be html also ..", font));


document.close();
response.setContentType("application/pdf");
response.setContentLength(baos.size());
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();

Hope this will help you.
Regards
Ashish Tahasildar
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic