HTML to PDF / DOCX / RTF Java converter library › Forums › PD4ML v3 Archived Forums (Read Only) › Troubleshooting › HTML tags from JSF written to pdf file
- This topic has 0 replies, 1 voice, and was last updated Sep 21, 2010
17:11:28 byAnonymous.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
September 21, 2010 at 17:11#26458
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
-
AuthorPosts
Viewing 1 post (of 1 total)
The forum ‘Troubleshooting’ is closed to new topics and replies.
