Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何使用docx4j在文档中设置字体大小和字体系列_Html_Docx4j - Fatal编程技术网

Html 如何使用docx4j在文档中设置字体大小和字体系列

Html 如何使用docx4j在文档中设置字体大小和字体系列,html,docx4j,Html,Docx4j,这是我的代码从HTML转换为Word文档。如何设置此word文档的字体大小和字体系列。您将HTML内容作为AltChunk实例的集合拉入word文档,这意味着HTML作为单独的文件存在于docx“bundle”中,而不是作为实际word文档流的一部分 如果要将导入的内容作为原生MS Word内容进行操作,则需要导入源XHTML。这意味着docx4j采用标记和一些相关样式,将它们转换为docx文件的各个组成部分,例如表、文本、运行和段落元素。以这种方式导入内容后,您可以将其设置为任何其他docx实

这是我的代码从HTML转换为Word文档。如何设置此word文档的字体大小和字体系列。

您将HTML内容作为AltChunk实例的集合拉入word文档,这意味着HTML作为单独的文件存在于docx“bundle”中,而不是作为实际word文档流的一部分

如果要将导入的内容作为原生MS Word内容进行操作,则需要导入源XHTML。这意味着docx4j采用标记和一些相关样式,将它们转换为docx文件的各个组成部分,例如表、文本、运行和段落元素。以这种方式导入内容后,您可以将其设置为任何其他docx实体的样式

FileReader fr=new FileReader("E://HtmlToDoc//LETTER.html" );
BufferedReader br=new BufferedReader(fr); 
while( (s=br.readLine())!= null ){
    html=html+s;}

html="<html><body>"+html.substring(html.indexOf("<body>"));

/************************ Setting Page Size   **********************************/
Docx4jProperties.getProperties().setProperty("docx4j.PageSize", "B4JIS");
String papersize= Docx4jProperties.getProperties().getProperty("docx4j.PageSize", "B4JIS");

String landscapeString = Docx4jProperties.getProperties().getProperty("docx4j.PageOrientationLandscape", "true");
boolean landscape= Boolean.parseBoolean(landscapeString);

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(PageSizePaper.valueOf(papersize), landscape);

AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/hw.html"));
afiPart.setBinaryData(html.getBytes());
//afiPart.setBinaryData(fileContent);

afiPart.setContentType(new ContentType("text/html"));
Relationship altChunkRel = wordMLPackage.getMainDocumentPart().addTargetPart(afiPart);

// .. the bit in document body
CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
ac.setId(altChunkRel.getId() );
wordMLPackage.getMainDocumentPart().addObject(ac);

// .. content type
wordMLPackage.getContentTypeManager().addDefaultContentType("html", "text/html");
wordMLPackage.save(new java.io.File("E://HtmlToDoc//" + "test.docx"));