List of usage examples for com.lowagie.text.html SAXmyHtmlHandler SAXmyHtmlHandler
public SAXmyHtmlHandler(DocListener document)
Document
-object. From source file:oscar.util.Doc2PDF.java
License:Open Source License
public static String GetPDFBin(HttpServletResponse response, String docText) { // step 1: creation of a document-object Document document = new Document(PageSize.A4, 36, 36, 36, 36); // Document document = new Document(PageSize.A4.rotate()); try {/*from ww w . j a v a 2s .c o m*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // step 3: we create a parser and set the document handler SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); // step 4: we parse the document // use input stream parser.parse(new ByteArrayInputStream(docText.getBytes()), new SAXmyHtmlHandler(document)); document.close(); return (new String(Base64.encodeBase64(baos.toByteArray()))); } catch (Exception e) { logger.error("Unexpected error", e); } return null; }
From source file:oscar.util.Doc2PDF.java
License:Open Source License
public static void PrintPDFFromHTMLString(HttpServletResponse response, String docText) { // step 1: creation of a document-object Document document = new Document(PageSize.A4, 36, 36, 36, 36); //Document document = new Document(PageSize.A4.rotate()); try {//from www . jav a 2 s .c o m ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // step 3: we create a parser and set the document handler SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); // step 4: we parse the document // use input stream parser.parse(new ByteArrayInputStream(docText.getBytes()), new SAXmyHtmlHandler(document)); document.close(); // String yourString = new String(theBytesOfYourString, "UTF-8"); // byte[] theBytesOfYourString = yourString.getBytes("UTF-8"); byte[] binArray = baos.toByteArray(); PrintPDFFromBytes(response, binArray); } catch (Exception e) { logger.error("Unexpected error", e); } }