Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

problem in getting the html when i hit jsp

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to get the html in string when i hit the hit the jsp in servlets
basically i need to put the output of jsp in pdf file
when i hit one link i need to download that data in pdf file.
Iam using itextpdf.
sample code

pResponse.setContentType("application/pdf");
((HttpServletResponse) pResponse).setHeader("Content-Disposition", "attachment; filename=report.pdf");

//Get the output stream for writing PDF object
OutputStream outStream=pResponse.getOutputStream();
ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();

try {
Document document = new Document();
PdfWriter docWriter =PdfWriter.getInstance(document, baosPDF);
document.open();
String jspPath="C://workingcode//ATG//ATG10.1.1//Mergeingcode//atg//code//src//main//atg//myproj//Storefront//j2ee-apps//Storefront//store.war//myaccount//v2//sampledownload.jsp";
String csspath="C://workingcode//ATG//ATG10.1.1//Mergeingcode//atg//code//src//main//atg//myproj//StaticContent//css//test.css";

File file= new File(jspPath);

/ document.add(new Paragraph(org.apache.commons.io.FileUtils.readFileToString(file)));
// step 4
// XMLWorkerHelper.getInstance().parseXHtml(docWriter, document,new FileInputStream(jspPath),new FileInputStream(csspath) ,null ,new XMLWorkerFontProvider());

System.out.println( "PDF Created!" );

pRequest.getRequestDispatcher(jspPath).include(pRequest, responseWrapper);
String content = responseWrapper.getWriter().toString();

System.out.println("Output : " + content);


document.add(new Paragraph("ssss"));


document.add(new Paragraph(content));




document.close();
docWriter.close();

baosPDF.writeTo(outStream);
outStream.flush();
}
catch (DocumentException exc){
throw new IOException(exc.getMessage());
}
finally {
outStream.close();
}

i need to convert the sample download.jsp to html so that i can parse

// XMLWorkerHelper.getInstance().parseXHtml(docWriter, document,new FileInputStream(jspPath),new FileInputStream(csspath) ,null ,new XMLWorkerFontProvider());

Any help is appreciated
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So there's a button/Link on a web page that essentially says: "create a PDF of this web page"? Wouldn't it be easier if the user installed a print-to-pdf printer driver and saved the page that way?

Regardless, if the page is CSS-styled XHTML, then FlyingSaucer may help: https://github.com/flyingsaucerproject/flyingsaucer
 
trinadh reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
we need to implement through code.not through drivers.iam not able to find anything with the resources provided.Could you please eloborate
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

we need to implement through code.not through drivers.


Why? Please explain the use case so we understand where you're coming from.

iam not able to find anything with the resources provided.Could you please eloborate


Start by running the examples that come with the download, that should make it clear how the library works. Provided you have (or can make it) CSS-styled XHTML; do you?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic