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


Java XMLWorkerHelper类代码示例

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


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

示例1: exportInnertion

import com.itextpdf.tool.xml.XMLWorkerHelper; //导入依赖的package包/类
/**
 * 
 */
@Override
public void exportInnertion(OutputStream servletOut, List header, List data)
		throws IOException {
	// step 1
	Document document = new Document();
	// step 2
	PdfWriter writer;
	try {
		writer = PdfWriter.getInstance(document, servletOut);
	} catch (DocumentException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return;
	}
	// step 3
	document.open();
	// step 4
	XMLWorkerHelper.getInstance().parseXHtml(writer, document,
			new java.io.StringReader(
			HtmlExport.createHTML(header, data)));
	// step 5
	document.close();

}
 
开发者ID:fellyvon,项目名称:wasexport,代码行数:28,代码来源:PdfExport.java

示例2: htmlToPdf

import com.itextpdf.tool.xml.XMLWorkerHelper; //导入依赖的package包/类
public void htmlToPdf(String htmlPath, File pdfFile) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
    document.open();
    XMLWorkerHelper.getInstance().parseXHtml(writer, document, new FileInputStream(htmlPath), Charset.forName("UTF-8"));
    document.close();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:8,代码来源:ExportUtilImpl.java

示例3: GetPDFBin

import com.itextpdf.tool.xml.XMLWorkerHelper; //导入依赖的package包/类
public static String GetPDFBin(HttpServletResponse response, String docText) {
    Document document = new Document(PageSize.A4, 36, 36, 36, 36);
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        document.open();
        InputStream is = new ByteArrayInputStream(docText.getBytes());
        XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);
        document.close();
        return(new String(Base64.encodeBase64(baos.toByteArray())));
    }
    catch (Exception e) {
    	logger.error("Unexpected error", e);
    }
    return null;

}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:18,代码来源:Doc2PDF.java

示例4: PrintPDFFromHTMLString

import com.itextpdf.tool.xml.XMLWorkerHelper; //导入依赖的package包/类
public static void PrintPDFFromHTMLString(HttpServletResponse response, String docText) {
    Document document = new Document(PageSize.A4, 36, 36, 36, 36);
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        document.open();
        InputStream is = new ByteArrayInputStream(docText.getBytes());
        XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);
        document.close();
        byte[] binArray = baos.toByteArray();
        PrintPDFFromBytes(response, binArray);
    }
    catch (Exception e) {
    	logger.error("Unexpected error", e);
    }
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:17,代码来源:Doc2PDF.java

示例5: testCreatePdfLikeCasperSlynge

import com.itextpdf.tool.xml.XMLWorkerHelper; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/41743574/itextpdf-creates-unvalid-pdf-document">
 * Itextpdf creates unvalid pdf document
 * </a>
 * <p>
 * CasperSlynge.html
 * </p>
 * <p>
 * Works for me. Admittedly, I replaced the {@link ByteArrayInputStream} by a
 * resource {@link InputStream} and the {@link ByteArrayOutputStream} by a
 * {@link FileOutputStream}.
 * </p>
 * <p>
 * I also added a `Charset` but the test created a valid file without, too.
 * </p>
 */
@Test
public void testCreatePdfLikeCasperSlynge() throws IOException, DocumentException
{
    try (   InputStream resource = getClass().getResourceAsStream("CasperSlynge.html");
            FileOutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "CasperSlynge.pdf")))
    {
        // step 1
        Document document = new Document();
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, result);
        // step 3
        document.open();
        // step 4
        XMLWorkerHelper.getInstance().parseXHtml(writer, document, resource, Charset.forName("UTF8"));
        // step 5
        document.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:35,代码来源:CreatePdf.java

示例6: parseURL2PDFFile

import com.itextpdf.tool.xml.XMLWorkerHelper; //导入依赖的package包/类
/**
 * 直接把网页内容转为PDF文件
 * 
 * @param fileName
 * @throws Exception
 */
public static void parseURL2PDFFile(String pdfFile, String blogURL)
		throws Exception {

	BaseFont bfCN = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H",
			false);
	// 中文字体定义
	Font chFont = new Font(bfCN, 14, Font.NORMAL, BaseColor.BLUE);
	Font secFont = new Font(bfCN, 12, Font.NORMAL, new BaseColor(0, 204,
			255));
	Font textFont = new Font(bfCN, 12, Font.NORMAL, BaseColor.BLACK);

	Document document = new Document();
	PdfWriter pdfwriter = PdfWriter.getInstance(document,
			new FileOutputStream(pdfFile));
	pdfwriter.setViewerPreferences(PdfWriter.HideToolbar);
	document.open();

	String[] blogInfo = extractBlogInfo(blogURL);

	int chNum = 1;
	Chapter chapter = new Chapter(new Paragraph("URL转PDF测试", chFont),
			chNum++);

	Section section = chapter
			.addSection(new Paragraph(blogInfo[0], secFont));
	section.setIndentation(10);
	section.setIndentationLeft(10);
	section.setBookmarkOpen(false);
	section.setNumberStyle(Section.NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT);
	section.add(new Chunk("分类:" + blogInfo[1] + " 日期:" + blogInfo[2],
			textFont));

	LineSeparator line = new LineSeparator(1, 100, new BaseColor(204, 204,
			204), Element.ALIGN_CENTER, -2);
	Paragraph p_line = new Paragraph(" ");
	p_line.add(line);
	section.add(p_line);
	section.add(Chunk.NEWLINE);

	document.add(chapter);

	// html文件
	XMLWorkerHelper.getInstance().parseXHtml(pdfwriter, document,
			parse2Stream(blogInfo[3]));

	document.close();
}
 
开发者ID:wkeyuan,项目名称:DWSurvey,代码行数:54,代码来源:Demo4URL2PDF.java

示例7: createPdf

import com.itextpdf.tool.xml.XMLWorkerHelper; //导入依赖的package包/类
public static void createPdf(String content, String dest) throws IOException, DocumentException {

		Document document = new Document();
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
		document.open();
		XMLWorkerFontProvider fontImp = new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS);
		fontImp.register(FONT);
		XMLWorkerHelper.getInstance().parseXHtml(writer, document, new ByteArrayInputStream(content.getBytes()), null,
				Charset.forName("UTF-8"), fontImp);
		document.close();

	}
 
开发者ID:Sunny0715,项目名称:java_pdf_demo,代码行数:13,代码来源:JavaToPdfHtmlFreeMarker.java

示例8: main

import com.itextpdf.tool.xml.XMLWorkerHelper; //导入依赖的package包/类
public static void main(String[] args) throws IOException, DocumentException {

		Document document = new Document();
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST));
		document.open();
		XMLWorkerFontProvider fontImp = new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS);
		fontImp.register(FONT);
		XMLWorkerHelper.getInstance().parseXHtml(writer, document, new FileInputStream(HTML), null,
				Charset.forName("UTF-8"), fontImp);
		document.close();
	}
 
开发者ID:Sunny0715,项目名称:java_pdf_demo,代码行数:12,代码来源:JavaToPdfHtml.java

示例9: HeaderFooter

import com.itextpdf.tool.xml.XMLWorkerHelper; //导入依赖的package包/类
public HeaderFooter() throws IOException
{
    header = XMLWorkerHelper.parseToElementList(HEADER, null);
    footer = XMLWorkerHelper.parseToElementList(FOOTER, null);
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:6,代码来源:HtmlHeaderFooter.java

示例10: createPdf

import com.itextpdf.tool.xml.XMLWorkerHelper; //导入依赖的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

示例11: testDevelofersScenario

import com.itextpdf.tool.xml.XMLWorkerHelper; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/38989235/itext-html-to-pdf-memory-leak">
 * IText HTML to PDF memory leak
 * </a>
 * <p>
 * The OP's code plus a save-to-file.
 * </p>
 */
public void testDevelofersScenario(String outputName) throws IOException, DocumentException
{
    final String content = "<!--?xml version=\"1.0\" encoding=\"UTF-8\"?-->\n<html>\n <head>\n    <title>Title</title>\n    \n   \n </head>\n"
            + "\n    \n<body>  \n  \n      \nEXAMPLE\n\n</body>\n</html>";

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, baos);        
    document.open();
    InputStream is = new ByteArrayInputStream(content.getBytes());
    XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);

    document.close();
    
    baos.writeTo(new FileOutputStream(new File(RESULT_FOLDER, outputName)));
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:25,代码来源:MemoryConsumption.java

示例12: testAddAnnotationLikeJasonY

import com.itextpdf.tool.xml.XMLWorkerHelper; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/41949253/how-to-add-columntext-as-an-annotation-in-itext-pdf">
 * How to add columnText as an annotation in itext pdf
 * </a>
 * <p>
 * This test demonstrates how to use a columntext in combination with an annotation.
 * </p>
 */
@Test
public void testAddAnnotationLikeJasonY() throws IOException, DocumentException
{
    String html ="<html><h1>Header</h1><p>A paragraph</p><p>Another Paragraph</p></html>";
    String css = "h1 {color: red;}";
    ElementList elementsList = XMLWorkerHelper.parseToElementList(html, css);

    try (   InputStream resource = getClass().getResourceAsStream("/mkl/testarea/itext5/extract/test.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "JasonY.pdf"))   )
    {
        PdfReader reader = new PdfReader(resource);
        PdfStamper stamper = new PdfStamper(reader, result);

        Rectangle cropBox = reader.getCropBox(1);

        PdfAnnotation annotation = stamper.getWriter().createAnnotation(cropBox, PdfName.FREETEXT);
        PdfAppearance appearance = PdfAppearance.createAppearance(stamper.getWriter(), cropBox.getWidth(), cropBox.getHeight());

        ColumnText ct = new ColumnText(appearance);
        ct.setSimpleColumn(new Rectangle(cropBox.getWidth(), cropBox.getHeight()));
        elementsList.forEach(element -> ct.addElement(element));
        ct.go();

        annotation.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, appearance);
        stamper.addAnnotation(annotation, 1);

        stamper.close();
        reader.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:39,代码来源:AddAnnotation.java

示例13: renderMergedOutputModel

import com.itextpdf.tool.xml.XMLWorkerHelper; //导入依赖的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

示例14: postConstruct

import com.itextpdf.tool.xml.XMLWorkerHelper; //导入依赖的package包/类
@PostConstruct
public void postConstruct() {
    xmlWorkerHelper = XMLWorkerHelper.getInstance();
}
 
开发者ID:khipu,项目名称:khpdf,代码行数:5,代码来源:PdfGeneratorImpl.java


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