|
Hello,
I am trying to output the of a JSF page to a pdf file. The converted HTML tags from JSF pages are written to the pdf file instead of the contents. Have been trying to resolve this for a while. Any help is very much appreciated. My intend is to store the byteArray. Just to make sure the bytearray content is good, I am creating this temporay pdf file.
The content written to the pdf file is (Full file is not written, maybe buffer size issue): <form id="form1" name="form1" method="post" action="
My code is String sessionId = null; HttpServletRequest request = (HttpServletRequest) getFacesContext(). getExternalContext().getRequest(); HttpServletResponse response = (HttpServletResponse) getFacesContext(). getExternalContext().getResponse(); Cookie[] cookies = request.getCookies(); for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if ("OFSE_JSESSIONID".equals(cookie.getName())) { sessionId = cookie.getValue(); break; } } StringBuffer url = new StringBuffer(request.getRequestURL()); String host = url.substring(0, url.indexOf("Review.faces")); HttpURLConnection conn = null; InputStream inputStream = null; FileOutputStream os = null; ByteArrayOutputStream bs = null; Document document = null; try { URL printableSummaryPage = new URL(host.concat("PrintableReview.faces")); conn = (HttpURLConnection) printableSummaryPage.openConnection(); conn.setUseCaches(false); conn.setRequestProperty ("Content-Type","application/pdf"); conn.setRequestProperty("Cookie", "OFSE_JSESSIONID="+sessionId); conn.setRequestMethod("POST"); conn.connect(); inputStream = conn.getInputStream(); bs = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int readCount = 0; document = new Document(); os = new FileOutputStream(new File("c:\\PdfTest\\sample.pdf")); PdfWriter w = PdfWriter.getInstance(document, os); document.open(); while ((readCount = inputStream.read(buffer)) != -1) { if (readCount < 1024) { bs.write(buffer, 0, readCount); } else { bs.write(buffer); } document.add(new Paragraph(new String(buffer))); } document.close();
Thank you
Last bumped by Anonymous on 21 Oct 2010, 12:51.
|