Package org.xhtmlrenderer.pdf

Examples of org.xhtmlrenderer.pdf.ITextRenderer


  public static byte[] XHTML2PDF(String xhtml) throws IOException {
    byte[] pdf = null;
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    try {
      ITextRenderer itextRenderer = new ITextRenderer();
      itextRenderer.setDocumentFromString(xhtml);
      itextRenderer.layout();
      itextRenderer.createPDF(byteArrayOutputStream);
      pdf = byteArrayOutputStream.toByteArray();
    }
    catch (Exception e) {
      logger.error(e.getMessage(), e);
      logger.error("vvv--- Offending XHTML ---vvv");
View Full Code Here


public class FormPdfUtil {
    private static ITextRenderer renderer;
   
    public static ITextRenderer getRenderer() {
        if (renderer == null) {
            renderer = new ITextRenderer();
            SharedContext sharedContext = renderer.getSharedContext();
            sharedContext.setFontResolver(new ITextCustomFontResolver(sharedContext));
        }
        return renderer;
    }
View Full Code Here

        return null;
    }
   
    public static byte[] createPdf(String html, String header, String footer, String css, Boolean showAllSelectOptions, Boolean repeatHeader, Boolean repeatFooter) {
        try {
            ITextRenderer r = getRenderer();
            synchronized (r) {
                html = formatHtml(html, header, footer, css, showAllSelectOptions, repeatHeader, repeatFooter);
           
                final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
                documentBuilderFactory.setValidating(false);
                DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
                builder.setEntityResolver(FSEntityResolver.instance());
                org.w3c.dom.Document xmlDoc = builder.parse(new ByteArrayInputStream(html.getBytes("UTF-8")));

                r.setDocument(xmlDoc, null);

                ByteArrayOutputStream os = new ByteArrayOutputStream();
                r.layout();
                r.createPDF(os);
                byte[] output = os.toByteArray();
                os.close();
                return output;
            }
        } catch (Exception e) {
View Full Code Here

   * @throws IOException error closing file
   */
  public static void exportHtmlToPdf(Document document, ReportWriter reportWriter, List<String> fontPaths)
      throws DocumentException, IOException {

    ITextRenderer renderer = new ITextRenderer();

    // Adding fonts for PDF generation
    if (fontPaths != null) {
      for(String font : fontPaths) {
        renderer.getFontResolver().addFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
      }
    }

    renderer.getSharedContext().setReplacedElementFactory(
        new MediaReplacedElementFactory(renderer.getSharedContext().getReplacedElementFactory()));
    renderer.setDocument(document, null);   
    renderer.layout();

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    renderer.createPDF(outputStream, true);
    ByteArrayInputStream is = new ByteArrayInputStream(outputStream.toByteArray());
    reportWriter.write(is);

    outputStream.flush();
    outputStream.close();
View Full Code Here

TOP

Related Classes of org.xhtmlrenderer.pdf.ITextRenderer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.