本文整理汇总了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;
}
示例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();
}
示例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();
}
}
示例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);
}