当前位置: 首页>>代码示例>>Java>>正文


Java StyleAttrCSSResolver类代码示例

本文整理汇总了Java中com.itextpdf.tool.xml.css.StyleAttrCSSResolver的典型用法代码示例。如果您正苦于以下问题:Java StyleAttrCSSResolver类的具体用法?Java StyleAttrCSSResolver怎么用?Java StyleAttrCSSResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StyleAttrCSSResolver类属于com.itextpdf.tool.xml.css包,在下文中一共展示了StyleAttrCSSResolver类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseXHtml

import com.itextpdf.tool.xml.css.StyleAttrCSSResolver; //导入依赖的package包/类
private void parseXHtml(final ElementHandler d, final Reader in) throws IOException {
    CssFilesImpl cssFiles = new CssFilesImpl();
    cssFiles.add(getDefaultCSS());
    cssFiles.add(getHtmlCSS());
    StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles) {
        @Override
        public void resolveStyles(Tag t) {
            configuration.resolveDefaultStyles(t);
            super.resolveStyles(t);
        }

        @Override
        public CSSResolver clear() throws CssResolverException {
            // prevent css files from being been removed
            return this;
        }
    };
    HtmlPipelineContext hpc = new HtmlPipelineContext(null);
    final String imageRootPath = configuration.getImageRootPath();
    if (imageRootPath != null) {
        hpc.setImageProvider(new AbstractImageProvider() {
            /**
             * @return a rootpath to set before the src attribute
             */
            @Override
            public String getImageRootPath() {
                return imageRootPath;
            }
        });
    }
    hpc.setAcceptUnknown(true).autoBookmark(true).setTagFactory(getDefaultTagProcessorFactory());
    Pipeline<?> pipeline =
            new CssResolverPipeline(cssResolver,
                    new HtmlPipeline(hpc,
                            new ElementHandlerPipeline(d, null)));
    XMLWorker worker = new XMLWorker(pipeline, true);
    XMLParser p = new XMLParser();
    p.addListener(worker);
    p.parse(in);
}
 
开发者ID:Arnauld,项目名称:cucumber-contrib,代码行数:41,代码来源:MarkdownEmitter.java

示例2: createPdf

import com.itextpdf.tool.xml.css.StyleAttrCSSResolver; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/43610868/how-to-add-dynamic-variable-to-footer-without-calling-document-newpage-in-itex">
 * How to add dynamic variable to footer without calling document.newPage() in iText 5
 * </a>
 * <p>
 * generator method of the OP
 * </p>
 * @see #testDynamicFooterLikeAyZagen()
 */
public static void createPdf(ArrayList<String> htmlStrings, FooterTable footerEvt, String destinationPath)
        throws IOException, DocumentException {
    Document document = new Document(PageSize.A4);
    document.setMargins(68, 85, 75, 85);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(destinationPath));
    if (footerEvt != null)
        writer.setPageEvent(footerEvt);
    document.open();

    CSSResolver cssResolver = new StyleAttrCSSResolver();
    CssFile cssFile = XMLWorkerHelper
            .getCSS(new ByteArrayInputStream(/*readCSS("resources/content.min.css").getBytes()*/ "".getBytes()));
    cssResolver.addCss(cssFile);

    XMLWorkerFontProvider fontProvider = new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS);
    fontProvider.register(/*"resources/ARIAL.TTF"*/ "c:/Windows/Fonts/arial.ttf");

    CssAppliers cssAppliers = new CssAppliersImpl(fontProvider);
    HtmlPipelineContext htmlContext = new HtmlPipelineContext(cssAppliers);
    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);
    int i = 0;
    for (String htmlfile : htmlStrings) {
        i++;
        footerEvt.setTitleIndex("" + i);//or FooterTable.setTitleIndex("" + i);
        ByteArrayInputStream stream = new ByteArrayInputStream(htmlfile.getBytes("UTF-8"));
        p.parse(stream, Charset.forName("UTF-8"));
    }
    document.close();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:46,代码来源:DynamicFooter.java

示例3: testParseHtml7Original

import com.itextpdf.tool.xml.css.StyleAttrCSSResolver; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/42412002/xmlworker-itext-doesnt-break-page-in-pdf-result">
 * XMLWorker (iText) doesn't break page in PDF result
 * </a>
 * <br/>
 * <a href="http://developers.itextpdf.com/fr/node/2078#999-parsehtml7.java">
 * ParseHtml7 iText example
 * </a>
 * <p>
 * Indeed, the ParseHtml7 iText example does not respect page-break-before
 * style entries. The cause is that they are only supported when the elements
 * generated by the XML worker are directly added to the Document, not when
 * they are added to a table cell as in your example. Unfortunately RTL is
 * only supported inside table cells.
 * </p>
 * <p>
 * {@link #testParseHtml7Improved()} shows how to explicitly support the
 * page-break-before style entries by recognizing the {@link Chunk#NEWPAGE}
 * elements generated for page-break-before elements and creating a new page
 * then. 
 * </p>
 */
@Test
public void testParseHtml7Original() throws DocumentException, IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("PageBreaks.html")    )
    {
        // step 1
        Document document = new Document();
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "PageBreaks.pdf")));
        // step 3
        document.open();
        // step 4
        // Styles
        CSSResolver cssResolver = new StyleAttrCSSResolver();
        XMLWorkerFontProvider fontProvider = new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS);
        fontProvider.register("src/test/resources/mkl/testarea/itext5/xmlworker/NotoNaskhArabic-Regular.ttf");
        CssAppliers cssAppliers = new CssAppliersImpl(fontProvider);
        // HTML
        HtmlPipelineContext htmlContext = new HtmlPipelineContext(cssAppliers);
        htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
        // Pipelines
        ElementList elements = new ElementList();
        ElementHandlerPipeline pdf = new ElementHandlerPipeline(elements, null);
        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(resource, Charset.forName("UTF-8"));
 
        PdfPTable table = new PdfPTable(1);
        PdfPCell cell = new PdfPCell();
        cell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
        for (Element e : elements) {
            cell.addElement(e);
        }
        table.addCell(cell);
        document.add(table);
        // step 5
        document.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:66,代码来源:PageBreaks.java

示例4: CSSResolver

import com.itextpdf.tool.xml.css.StyleAttrCSSResolver; //导入依赖的package包/类
/**
 * Creates a CSS resolver to modify element attributes based on the corresponding CSS styles
 * @param pCSSFiles The css files that should be used when resolving styles
 * @param pIsDebug If true, the debug class is applied when resolving styles
 */
public CSSResolver(CssFiles pCSSFiles, boolean pIsDebug) {
  mCssPropertyResolver = new StyleAttrCSSResolver(pCSSFiles);
  mIsDebug = pIsDebug;
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:10,代码来源:CSSResolver.java


注:本文中的com.itextpdf.tool.xml.css.StyleAttrCSSResolver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。