• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java HTMLSettings类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: convert

import org.docx4j.convert.out.HTMLSettings; //导入依赖的package包/类
@Override
public InputStream convert(InputStream fromInputSource, String toMimeType) {
	try {
		WordprocessingMLPackage pkg = WordprocessingMLPackage.load(fromInputSource);

		// Refresh the values of DOCPROPERTY fields 
		FieldUpdater updater = new FieldUpdater(pkg);
		updater.update(true);
		
		AbstractHtmlExporter exporter = new HtmlExporterNG2();
		HTMLSettings htmlSettings= Docx4J.createHTMLSettings();
    	htmlSettings.setImageDirPath("/tmp/sample-docx.html_files");
    	htmlSettings.setImageTargetUri("/tmp/_files");
    	htmlSettings.setWmlPackage(pkg);
    	
    	Docx4jProperties.setProperty("docx4j.Convert.Out.HTML.OutputMethodXML", true);
 
		OutputStream os = new FileOutputStream("/tmp/temp.html");
		Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
		IOUtils.closeQuietly(os);

		if (pkg.getMainDocumentPart().getFontTablePart()!=null) {
			pkg.getMainDocumentPart().getFontTablePart().deleteEmbeddedFontTempFiles();
		}		
		// This would also do it, via finalize() methods
		htmlSettings = null;
		pkg = null;

		return new FileInputStream("/tmp/temp.html");
	} catch (Exception e) {
		
	}
	
	return null;
}
 
开发者ID:paulcwarren,项目名称:spring-content,代码行数:36,代码来源:WordToHtmlRenditionProvider.java


示例2: streamDocxAsHtml

import org.docx4j.convert.out.HTMLSettings; //导入依赖的package包/类
protected ResponseBuilder streamDocxAsHtml(final WordprocessingMLPackage wordMLPackage, final HttpSession session, 
			EditorHTML editorHTML, HttpServletResponse response) {
		

		// .. the HtmlSettings object
    	final HTMLSettings htmlSettings = new HTMLSettings();    	
		
    	if (editorHTML.equals(EditorHTML.BARE)) {
	    	htmlSettings.setCustomXsltTemplates(BARE_XSLT);
    	} else if  (editorHTML.equals(EditorHTML.CKEditor3)) {
	    	htmlSettings.setCustomXsltTemplates(CKEditor3_XSLT);    		
    	}

    	
    	htmlSettings.setImageHandler(new SessionImageHandler(session));

    	htmlSettings.setStyleElementHandler(new SessionStyleHandler(session));
    	
//    	htmlSettings.setUserBodyTop("<H1>TOP!</H1>");
//    	htmlSettings.setUserBodyTail("<H1>TAIL!</H1>");
		
		// Sample sdt tag handler (tag handlers insert specific
		// html depending on the contents of an sdt's tag).
		// This will only have an effect if the sdt tag contains
		// the string @class=XXX
//			SdtWriter.registerTagHandler("@class", new TagClass() );
		
//		SdtWriter.registerTagHandler(Containerization.TAG_BORDERS, new TagSingleBox() );
//		SdtWriter.registerTagHandler(Containerization.TAG_SHADING, new TagSingleBox() );

		
    	htmlSettings.setWmlPackage(wordMLPackage);
    	wordMLPackage.setUserData("HttpSession", session);
    	
    	// Since we'll store various stuff on the pkg object (eg images, long tail)
    	// avoid using a clone!
    	htmlSettings.getFeatures().remove(ConversionFeatures.PP_COMMON_DEEP_COPY);

    	// Don't convert w:r/w:br[w:@type="page"] to <w:pageBreakBefore/>
    	// since it seems that should really go on the following paragraph
    	htmlSettings.getFeatures().remove(ConversionFeatures.PP_COMMON_MOVE_PAGEBREAK);
    	
		// We'll store the images associated with this docx in a map:
		HashMap<String, byte[]> imageMap = new HashMap<String, byte[]>();  
		// and store that in the docx 
		// (so each docx has its own collection of available images; these aren't shared across
		//   the user's session, if they have multiple windows open, each with a different editor)
		wordMLPackage.setUserData(APP_KEY + "imageMap", imageMap);
		
		htmlSettings.getSettings().put("ContextPath", getContextPath());
		
		// For extension function
		htmlSettings.getSettings().put("HttpServletResponse", response);
    	
    	
		ResponseBuilder builder = Response.ok(
				
				new StreamingOutput() {				
					public void write(OutputStream output) throws IOException, WebApplicationException {					
				         try {
				     		javax.xml.transform.stream.StreamResult result 
				     			= new javax.xml.transform.stream.StreamResult(output);
				    		
				    		// Docx4J.toHTML(htmlSettings, output, Docx4J.FLAG_NONE);
				    		Exporter<HTMLSettings> exporter = new HTMLExporterXslt(CUSTOM_HTML_WRITER_REGISTRY);
				    		exporter.export(htmlSettings, output);
				    		
						} catch (Exception e) {
							throw new WebApplicationException(e);
						}							
					}
				}
			);
//						builder.header("Content-Disposition", "attachment; filename=output.pdf");
//			builder.type("application/pdf");
			
			return builder;		
	}
 
开发者ID:plutext,项目名称:docx-html-editor,代码行数:79,代码来源:Editor.java


示例3: main

import org.docx4j.convert.out.HTMLSettings; //导入依赖的package包/类
public static void main(String[] args)
            throws Exception {
    	
		try {
			getInputFilePath(args);
		} catch (IllegalArgumentException e) {
		}
		
		// Document loading (required)
		WordprocessingMLPackage wordMLPackage;
		if (inputfilepath==null) {
			// Create a docx
			System.out.println("No input path passed, creating dummy document");
			 wordMLPackage = WordprocessingMLPackage.createPackage();
			SampleDocument.createContent(wordMLPackage.getMainDocumentPart());	
		} else {
			System.out.println("Loading file from " + inputfilepath);
			wordMLPackage = Docx4J.load(new java.io.File(inputfilepath));
		}

		// HTML exporter setup (required)
		// .. the HTMLSettings object
    	HTMLSettings htmlSettings = Docx4J.createHTMLSettings();

    	htmlSettings.setImageDirPath(inputfilepath + "_files");
    	htmlSettings.setImageTargetUri(inputfilepath.substring(inputfilepath.lastIndexOf("/")+1)
    			+ "_files");
    	htmlSettings.setWmlPackage(wordMLPackage);
    	
    	
    	/* CSS reset, see http://itumbcom.blogspot.com.au/2013/06/css-reset-how-complex-it-should-be.html 
    	 * 
    	 * motivated by vertical space in tables in Firefox and Google Chrome.
        
	        If you have unwanted vertical space, in Chrome this may be coming from -webkit-margin-before and -webkit-margin-after
	        (in Firefox, margin-top is set to 1em in html.css)
	        
	        Setting margin: 0 on p is enough to fix it.
	        
	        See further http://www.css-101.org/articles/base-styles-sheet-for-webkit-based-browsers/    	
    	*/
    	String userCSS = "html, body, div, span, h1, h2, h3, h4, h5, h6, p, a, img,  ol, ul, li, table, caption, tbody, tfoot, thead, tr, th, td " +
    			"{ margin: 0; padding: 0; border: 0;}" +
    			"body {line-height: 1;} ";
    	htmlSettings.setUserCSS(userCSS);
    			
		// output to an OutputStream.		
		OutputStream os; 
		os = new FileOutputStream(inputfilepath + ".html");

		// If you want XHTML output
    	Docx4jProperties.setProperty("docx4j.Convert.Out.HTML.OutputMethodXML", true);

		//Don't care what type of exporter you use
//		Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_NONE);
		//Prefer the exporter, that uses a xsl transformation
		Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
		//Prefer the exporter, that doesn't use a xsl transformation (= uses a visitor)
//		Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_EXPORT_PREFER_NONXSL);

		System.out.println("Saved: " + inputfilepath + ".html ");
    }
 
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:63,代码来源:Docx4jConvertOutHtml.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DefaultMessageCodesResolver类代码示例发布时间:2022-05-23
下一篇:
Java NavigationEntry类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap