• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem in getting the html when i hit jsp

 
trinadh reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • 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
  • 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: 42970
73
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!