當前位置: 首頁>>代碼示例>>Java>>正文


Java Tags類代碼示例

本文整理匯總了Java中com.itextpdf.tool.xml.html.Tags的典型用法代碼示例。如果您正苦於以下問題:Java Tags類的具體用法?Java Tags怎麽用?Java Tags使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Tags類屬於com.itextpdf.tool.xml.html包,在下文中一共展示了Tags類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDefaultTagProcessorFactory

import com.itextpdf.tool.xml.html.Tags; //導入依賴的package包/類
private TagProcessorFactory getDefaultTagProcessorFactory() {
    TagProcessorFactory tpf = Tags.getHtmlTagProcessorFactory();
    tpf.addProcessor(new HeaderProcessor(configuration, 1), "h1");
    tpf.addProcessor(new HeaderProcessor(configuration, 2), "h2");
    tpf.addProcessor(new ImageProcessor(), "img");
    tpf.addProcessor(new GralProcessor(writer), "gral");
    tpf.addProcessor(new TableDataHeaderProcessor(configuration), "th");
    tpf.addProcessor(new TableDataContentProcessor(configuration), "td");
    return tpf;
}
 
開發者ID:Arnauld,項目名稱:cucumber-contrib,代碼行數:11,代碼來源:MarkdownEmitter.java

示例2: createPdf

import com.itextpdf.tool.xml.html.Tags; //導入依賴的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.html.Tags; //導入依賴的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: renderMergedOutputModel

import com.itextpdf.tool.xml.html.Tags; //導入依賴的package包/類
@Override
protected void renderMergedOutputModel(Map<String, Object> model,
		HttpServletRequest req, HttpServletResponse res) throws Exception {
   	
   	String ROOT_PATH = System.getProperty("catalina.home");
	
   	// get data model which is passed by the Spring container
       ReportModel reportModel = (ReportModel) model.get("reportModel");
       
	// IE workaround: write into byte array first.
       ByteArrayOutputStream baos = createTemporaryOutputStream();
	
	// step 1
       Document document = new Document(PageSize.A4, 30, 30, 30, 40);
       
       // step 2
       PdfWriter writer = newWriter(document, baos);//PdfWriter.getInstance(document, new FileOutputStream(ROOT_PATH + File.separator +"pdf.pdf"));
       writer.setBoxSize("art", new Rectangle(36, 54, 559, 788));
       writer.setPageEvent(new HeaderFooter());
       writer.setViewerPreferences(getViewerPreferences());
       
       // step 3
       document.open();
       document.add(new Chunk(""));
       
       // step 4
       try {
       	
        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,
						writer)));
		
		XMLWorker worker = new XMLWorker(pipeline, true);
		XMLParser p = new XMLParser(worker);
		p.parse(new InputStreamReader(new FileInputStream(ROOT_PATH + File.separator + "bis.html"), "UTF-8"));
		
		//add mysupport
		addIntroAndMySupport(document);
		
		//add support and other information
		addSupportAndOtherInformation(document, reportModel);
		
		//add other useful sources
		addOtherUsefulSources(document);
		
		//add user data
		addUserData(document, reportModel);
		
		//add footer
		addFooterSection(document);
	}catch(Exception e) {
		logger.error("Exception creating pdf: "+e.getMessage());
	}

       //step 5
       document.close();
       
       // Flush to HTTP response.
       writeToResponse(res, baos);
	
}
 
開發者ID:TransformCore,項目名稱:BIS-BDT-Citizen,代碼行數:68,代碼來源:PdfReportView.java


注:本文中的com.itextpdf.tool.xml.html.Tags類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。