Example usage for com.itextpdf.tool.xml.html Tags getHtmlTagProcessorFactory

List of usage examples for com.itextpdf.tool.xml.html Tags getHtmlTagProcessorFactory

Introduction

In this page you can find the example usage for com.itextpdf.tool.xml.html Tags getHtmlTagProcessorFactory.

Prototype

public static final TagProcessorFactory getHtmlTagProcessorFactory() 

Source Link

Document

Returns a new DefaultTagProcessorFactory

Usage

From source file:com.algoboss.erp.util.report.PDFExporter2.java

License:Apache License

public void export(FacesContext context, String cssstring, String htmlstring, String filename)
        throws IOException {
    try {//ww w. j av  a  2s . co  m
        InputStream is = new ByteArrayInputStream(htmlstring.getBytes());
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        // step 1
        Document document = new Document();

        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, baos);

        writer.setInitialLeading(12.5f);

        // step 3
        document.open();

        HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);

        htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());

        // CSS
        CSSResolver cssResolver = new StyleAttrCSSResolver();
        String[] cssstringArray = cssstring.split(";");
        FacesContext aFacesContext = FacesContext.getCurrentInstance();
        ServletContext context2 = (ServletContext) aFacesContext.getExternalContext().getContext();
        String realPath = context2.getRealPath("/");
        System.out.println(realPath);
        System.out.println(context2.getContextPath());
        //System.out.println(context2.getResource(""));  
        System.out.println(aFacesContext.getExternalContext().getContextName());
        System.out.println(aFacesContext.getExternalContext().getRequestContextPath()
                + aFacesContext.getExternalContext().getRequestServletPath());
        //System.out.println(aFacesContext.getExternalContext().getRequestServletPath());
        //System.out.println(aFacesContext.getExternalContext().getRequestPathInfo());
        //System.out.println(aFacesContext.getExternalContext().getRequestScheme());
        //System.out.println(aFacesContext.getExternalContext().getRequestScheme());
        //System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));
        for (int i = 0; i < cssstringArray.length; i++) {
            String cssHref = cssstringArray[i];
            try {
                URL url = new URL(aFacesContext.getExternalContext().getRequestScheme(),
                        aFacesContext.getExternalContext().getRequestServerName(),
                        aFacesContext.getExternalContext().getRequestServerPort(), cssHref);
                InputStream csspathtest = url.openStream();
                CssFile cssfiletest = XMLWorkerHelper.getCSS(csspathtest);
                cssResolver.addCss(cssfiletest);
            } catch (IOException ex) {
                Logger.getLogger(PDFExporter2.class.getName()).log(Level.SEVERE, null, ex);
            }
            //String realPath2 = context2.getRealPath(cssHref);

            //InputStream csspathtest2 = aFacesContext.getExternalContext().getResourceAsStream(realPath2);
            //System.out.println(cssfiletest);
        }

        Pipeline<?> pipeline = new CssResolverPipeline(cssResolver,
                new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer)));

        XMLWorker worker = new XMLWorker(pipeline, true);
        XMLParser p = new XMLParser(worker);
        p.parse(is, Charset.forName("iso-8859-1"));//new FileInputStream("results/demo2/walden.html"));

        // step
        document.close();

        // post back...
        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
        response.setContentType("application/pdf");
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Content-Type", "application/pdf");
        response.setHeader("Content-disposition", "inline;filename=\"" + filename + "\";");
        response.setContentLength(baos.size());
        OutputStream os = response.getOutputStream();
        baos.writeTo(os);
        os.flush();
        os.close();
        context.responseComplete();

    } catch (IOException e) {
        throw new IOException(e.getMessage());
    } catch (Exception ex) {
        Logger.getLogger(PDFExporter2.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.apcb.utils.utils.PdfCreator.java

public static String createPdfWStyles(String fileName, String innerHTML, Document document, String CSS,
        String imagesSourcesPath) throws IOException, DocumentException {

    log.info("Creando HTML nombre: " + fileName);
    File fileHTML = new File(fileName);
    fileHTML.getParentFile().mkdirs();/*www  .  j  a  v a2  s.  c  o  m*/
    PrintWriter writerHTML = new PrintWriter(fileHTML, "UTF-8");
    writerHTML.println(innerHTML);
    writerHTML.flush();
    writerHTML.close();
    log.info("Creado HTML ruta: " + fileHTML.getAbsolutePath());

    log.info("Creando PDF nombre: " + fileName + ".pdf");
    File filePDF = new File(fileName + ".pdf");

    //File file = new File(fileName);
    filePDF.getParentFile().mkdirs();

    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileName + ".pdf"));
    document.open();

    CSSResolver cssResolver = new StyleAttrCSSResolver();
    CssFile cssFile = XMLWorkerHelper.getCSS(new ByteArrayInputStream(CSS.getBytes()));
    cssResolver.addCss(cssFile);

    // HTML
    HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
    htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());

    htmlContext.setImageProvider(new AbstractImageProvider() {
        @Override
        public String getImageRootPath() {
            return imagesSourcesPath;
        }
    });

    // Pipelines
    PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);
    HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
    CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);

    // XML Worker
    XMLWorker worker = new XMLWorker(css, true);
    XMLParser p = new XMLParser(worker);
    p.parse(new ByteArrayInputStream(innerHTML.getBytes()));

    document.close();
    log.info("Creado PDF ruta: " + filePDF.getAbsolutePath());
    log.info("filePDF.getName() " + filePDF.getName());
    return filePDF.getName();
}

From source file:com.propelics.pdfcreator.PdfcreatorModule.java

License:Open Source License

/**
 * @method generatePDFWithHTML//from  w ww  .jav a 2 s  .c om
 * Generates a PDF with the given file name, based on a HTML file
 * @param {String} filename Name of the PDF file
 * @param {String} html String with the HTML
 * @param {String} [author] Author for metadata
 * Fires a "complete" event when the PDF is generated
 * Fires a "error" event when a error is presented
 */
@Kroll.method(runOnUiThread = true)
public void generatePDFWithHTML(final HashMap args) {
    Log.d(PROXY_NAME, "generatePDFWithHTML()");

    String html = "";
    String author = "";
    String filename = "";
    final float marginPt = 28.35f;//1cm == 28.35pt

    try {
        if (args.containsKey("filename")) {
            filename = (String) args.get("filename");
            Log.d(PROXY_NAME, "filename: " + filename);
        } else
            return;

        if (args.containsKey("html")) {
            html = (String) args.get("html");
            Log.d(PROXY_NAME, "html: " + html);
        } else
            return;

        if (args.containsKey("author")) {
            author = (String) args.get("author");
            Log.d(PROXY_NAME, "author: " + author);
        }

        //create a new document
        Document document = new Document(PageSize.LETTER, marginPt, marginPt, marginPt, 0);
        TiBaseFile file = TiFileFactory.createTitaniumFile(filename, true);

        // Parse to XHTML
        StringWriter xhtmlWriter = new StringWriter();
        Tidy tidy = new Tidy();

        // tidy.setXHTML(true);
        tidy.setXmlOut(true);
        tidy.parse(new StringReader(html), xhtmlWriter);
        String xhtml = xhtmlWriter.toString();

        //get Instance of the PDFWriter
        PdfWriter pdfWriter = PdfWriter.getInstance(document, file.getOutputStream());

        //document header attributes
        document.addAuthor(author);
        document.addCreationDate();
        document.setPageSize(PageSize.LETTER);

        //open document
        document.open();

        // From Stack Overflow lol

        MyFontFactory fontFactory = new MyFontFactory();
        FontFactory.setFontImp(fontFactory);

        // HtmlPipelineContext htmlContext = new HtmlPipelineContext(new CssAppliersImpl(fontFactory));
        HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
        htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
        CSSResolver cssResolver = XMLWorkerHelper.getInstance().getDefaultCssResolver(true);
        Pipeline<?> pipeline = new CssResolverPipeline(cssResolver,
                new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, pdfWriter)));
        XMLWorker worker = new XMLWorker(pipeline, true);
        XMLParser p = new XMLParser(worker);
        p.parse(new StringReader(xhtml));

        // Finish SO c&P

        // Older code
        /*
        // Font Provider creation
        MyFontFactory fontProvider = new MyFontFactory();
        // fontProvider.register("/DroidSans.ttf");
                
        //get the XMLWorkerHelper Instance
        XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
        //convert to PDF
        worker.parseXHtml(pdfWriter, document, new ByteArrayInputStream(xhtml.getBytes("UTF-8")), null, fontProvider); //Load xhtml
        */

        //close the document
        document.close();
        //close the writer
        pdfWriter.close();

        sendCompleteEvent(filename);

    } catch (Exception e) {
        sendErrorEvent(e);
    }
}

From source file:com.sarav.donormgmttool.SendMail.java

public void writePdf(OutputStream outputStream, float ramount, java.sql.Date rdate, int rnum, String rname,
        String rmode) throws Exception {

    Document document = new Document();

    //step2 http://developers.itextpdf.com/examples/xml-worker-itext5/html-tables
    PdfWriter writer = PdfWriter.getInstance(document, outputStream);

    String PDFContent = "<center>\n" + "        <table style=\"text-align:center\">\n" + "            <tr>\n"
            + "                <td>\n"
            + "                    <img src=\"Images/Small - Team Everest Logo.png\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n"
            + "                </td>\n" + "                <td>\n"
            + "                    <h1 style=\"font-family: Arial\"><b><u>Team Everest</u></b></h1><b>(Regd No: 2292/09)</b>\n"
            + "                    <p style=\"font-family: Times\"> 5/1B, Magaveerar Street, Arnipalayam, Arni  632301<br>\n"
            + "                        Tiruvannamalai Dt, Tamilnadu, India Phone: +91 89399 12365<br>\n"
            + "                        Email: info@teameverestindia.org   Website: www.teameverestindia.org</p>\n"
            + "                </td>\n" + "            </tr>\n"
            + "            <tr><td><br><br><br><br></td></tr>\n" + "            <tr>\n"
            + "                <td>\n" + "                    <b>Reciept No:</b>*********\n"
            + "                </td>\n" + "                <td>\n"
            + "                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n"
            + "                </td>\n" + "                <td>\n"
            + "                    <b>Date:</b>********\n" + "                </td>\n" + "            </tr>\n"
            + "            <tr><td><br><br><br><br></td></tr>\n" + "            <tr>\n"
            + "                <td></td>\n" + "                <td>\n"
            + "                    <p style=\"font-family: Times\">Received the sum of Rs. <b>*****/- (*******)</b>, with thanks from\n"
            + "                        <b>*******</b>  as donation for Team Everest.</p>\n"
            + "                </td>\n" + "            </tr>\n"
            + "            <tr><td><br><br><br><br></td></tr>\n" + "            <tr>\n"
            + "                <td></td>\n" + "                <td>\n"
            + "                    <p style=\"text-align:left\"><b>Amount:</b> Rs.********&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Mode of Donation:</b>********</p>\n"
            + "                </td>\n" + "            </tr>\n"
            + "            <tr><td><br><br><br><br></td></tr>\n" + "            <tr><td><br><br><br><br></td>\n"
            + "                <td style=\"text-align:right\">\n"
            + "                    <p>For Team Everest&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>\n"
            + "                    <img src =\"Images/Signature.JPG\">\n" + "                </td>\n"
            + "            </tr>\n" + "            <tr><td><br><br><br><br></td></tr>\n" + "            <tr>\n"
            + "                <td></td>\n" + "                <td>\n"
            + "                    <p>*Donations are exempted under 80G of Income Tax Act<br>\n"
            + "                       1961 C, No. DIT (E) No. 2 (19) 1011. Pan No: AABTT6850G.</p>\n"
            + "                </td>\n" + "            </tr>\n" + "        </table>\n" + "        </center>";
    document.open();/* w  ww. ja v a  2 s.c om*/

    document.addTitle("EReceipt");
    document.addSubject("EreceiptPDF");
    document.addKeywords("iText, email");
    document.addAuthor("AKSarav");
    document.addCreator("AkSarav");

    //HTMLWorker htmlworker = new HTMLWorker(document);

    StringBuilder contentBuilder = new StringBuilder();
    Paragraph paragraph = new Paragraph();

    //System.out.println("PDFCONTENT"+PDFContent);
    contentBuilder.append(PDFContent);

    //HTML Processor
    HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
    htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
    // Pipelines
    PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);
    HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);

    //XMLWorker
    XMLWorker worker = new XMLWorker(html, true);
    XMLParser p = new XMLParser(worker);
    p.parse(new ByteArrayInputStream(contentBuilder.toString().getBytes()));

    // Closing the document

    document.close();
}

From source file:com.semfapp.adamdilger.semf.Pdf.java

License:Open Source License

private void createPDFNew(String filePath, String htmlString, @Nullable ArrayList<ImageFile> images) {

    File file = null;/*from www .  j  a v a2 s .  c o  m*/
    try {
        file = new File(filePath);

        // step 1
        Document document = new Document();

        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        writer.setInitialLeading(12.5f);

        // step 3
        document.open();

        // step 4

        // CSS
        CSSResolver cssResolver = new StyleAttrCSSResolver();
        CssFile cssFile = XMLWorkerHelper.getCSS(activity.getAssets().open("styles.css"));
        cssResolver.addCss(cssFile);

        // HTML
        HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
        htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());

        // Pipelines

        PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);
        HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
        CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);

        // XML Worker
        XMLWorker worker = new XMLWorker(css, true);
        XMLParser p = new XMLParser(worker);

        Drawable d = activity.getResources().getDrawable(R.drawable.logo_icon);
        Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byte[] bitmapData = stream.toByteArray();

        Image image = Image.getInstance(bitmapData);
        image.setAbsolutePosition(35, 763);
        image.scalePercent(12);
        document.add(image);

        p.parse(new ByteArrayInputStream(htmlString.getBytes(StandardCharsets.UTF_8)));

        if (images != null) {
            System.out.println("Adding IMage");

            for (int x = 0; x < images.size(); x++) {
                Image cursor = images.get(x).getImage();

                float ratio = cursor.getPlainHeight() / cursor.getPlainWidth();

                float imgWidth = document.getPageSize().getWidth() - 100;
                float imgHeight = document.getPageSize().getHeight() - 100;

                cursor.scaleToFit(new Rectangle(imgWidth, imgHeight));

                document.add(cursor);
            }
        }

        // step 5
        document.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:it.digitalhumanities.dhcpublisher.DHCPublisher.java

private void convertFile(final File subDir) throws DocumentException, IOException {

    File[] htmlFiles = subDir.listFiles(new FilenameFilter() {

        @Override// w  ww  .j a va2 s . co  m
        public boolean accept(File dir, String name) {
            return name.endsWith(".html");
        }
    });

    if (htmlFiles.length > 0) {
        File htmlFile = htmlFiles[0];
        String targetName = htmlFile.getName().substring(0, htmlFile.getName().length() - 4) + "pdf";

        Document document = new Document();
        File targetFile = new File(subDir, targetName);
        if (targetFile.exists()) {
            targetFile.delete();
        }

        try (FileOutputStream fos = new FileOutputStream(targetFile)) {
            PdfWriter writer = PdfWriter.getInstance(document, fos);
            writer.getAcroForm().setNeedAppearances(true);
            document.open();

            HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
            htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
            htmlContext.setImageProvider(new AbstractImageProvider() {
                public String getImageRootPath() {
                    return subDir.getAbsolutePath();
                }
            });

            CSSResolver cssResolver = XMLWorkerHelper.getInstance().getDefaultCssResolver(true);

            Pipeline<?> pipeline = new CssResolverPipeline(cssResolver,
                    new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer)));

            XMLWorker worker = new XMLWorker(pipeline, true);
            XMLParser p = new XMLParser(worker);

            try (FileInputStream fis = new FileInputStream(htmlFile)) {
                p.parse(fis);
            } finally {
                document.close();
            }
        }
    } else {
        throw new IllegalArgumentException(subDir + " does not contain HTML files!");
    }
}

From source file:net.algem.edition.PdfHandler.java

License:Open Source License

public XMLParser createParser(Document document, PdfWriter writer) {
    CSSResolver cssResolver = new StyleAttrCSSResolver();
    XMLWorkerFontProvider fontProvider = new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS);
    //    fontProvider.register("resources/fonts/Cardo-Regular.ttf");
    //    fontProvider.register("resources/fonts/Cardo-Bold.ttf");
    //    fontProvider.register("resources/fonts/Cardo-Italic.ttf");
    //    fontProvider.addFontSubstitute("lowagie", "cardo");
    CssAppliers cssAppliers = new CssAppliersImpl(fontProvider);
    HtmlPipelineContext htmlContext = new HtmlPipelineContext(cssAppliers);
    htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
    // Pipelines// ww w .  j a v  a2 s.  c  om
    PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);
    HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
    CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);
    // XML Worker
    XMLWorker worker = new XMLWorker(css, true);
    return new XMLParser(worker);
}

From source file:org.freelancertech.poc.itext.ParseHtmlTable1.java

public static byte[] createPdf() throws DocumentException, IOException {

    try (ByteArrayOutputStream os = new ByteArrayOutputStream();) {
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, os);

        document.open();//from ww  w . j a  v  a2s . c o  m
        ClassLoader classLoader = ParseHtmlTable1.class.getClassLoader();

        CSSResolver cssResolver = new StyleAttrCSSResolver();
        CssFile cssFile = XMLWorkerHelper.getCSS(classLoader.getResourceAsStream(STYLE_FILE_NAME));
        cssResolver.addCss(cssFile);

        HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
        htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
        PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);

        HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
        CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);

        XMLWorker worker = new XMLWorker(css, true);
        XMLParser p = new XMLParser(worker);
        InputStream is = classLoader.getResourceAsStream(HTML_FILE_NAME);
        p.parse(is);
        document.close();
        return os.toByteArray();
    }
}

From source file:org.freelancertech.poc.itext.ParseHtmlTable1.java

public static byte[] createPdf(String content) throws DocumentException, IOException {

    try (ByteArrayOutputStream os = new ByteArrayOutputStream();) {
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, os);

        document.open();//from   w w  w  . jav a2s  .  c  om
        ClassLoader classLoader = ParseHtmlTable1.class.getClassLoader();

        CSSResolver cssResolver = new StyleAttrCSSResolver();
        CssFile cssFile = XMLWorkerHelper.getCSS(classLoader.getResourceAsStream(STYLE_FILE_NAME));
        cssResolver.addCss(cssFile);

        HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
        htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
        PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);

        HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
        CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);

        XMLWorker worker = new XMLWorker(css, true);
        XMLParser p = new XMLParser(worker);
        InputStream is = new ByteArrayInputStream(content.getBytes());
        p.parse(is);
        document.close();
        return os.toByteArray();
    }
}

From source file:org.freelancertech.poc.itext.ParseHtmlTable1.java

public static byte[] convertHtmlToPdf(String content) throws IOException, DocumentException {
    final ClassLoader classLoader = ParseHtmlTable1.class.getClassLoader();
    try (ByteArrayOutputStream file = new ByteArrayOutputStream();
            InputStream is = new ByteArrayInputStream(content.getBytes());) {
        final Document document = new Document();
        final PdfWriter writer = PdfWriter.getInstance(document, file);
        document.open();//from   w  w  w.  ja v  a 2 s  .  c om
        final TagProcessorFactory tagProcessorFactory = Tags.getHtmlTagProcessorFactory();
        tagProcessorFactory.removeProcessor(HTML.Tag.IMG);
        tagProcessorFactory.addProcessor(new ImageTagProcessor(), HTML.Tag.IMG);
        final CssFile cssFile = XMLWorkerHelper.getCSS(classLoader.getResourceAsStream(STYLE_FILE_NAME));
        final CssFilesImpl cssFiles = new CssFilesImpl(cssFile);
        //cssFiles.add(XMLWorkerHelper.getInstance().getDefaultCSS());
        final StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles);
        final HtmlPipelineContext hpc = new HtmlPipelineContext(
                new CssAppliersImpl(new XMLWorkerFontProvider()));
        hpc.setAcceptUnknown(true).autoBookmark(true).setTagFactory(tagProcessorFactory);
        final HtmlPipeline htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(document, writer));
        final Pipeline<?> pipeline = new CssResolverPipeline(cssResolver, htmlPipeline);
        final XMLWorker worker = new XMLWorker(pipeline, true);
        final Charset charset = Charset.forName("UTF-8");
        final XMLParser xmlParser = new XMLParser(true, worker, charset);

        xmlParser.parse(is, charset);
        document.close();
        return file.toByteArray();
    }
}