我尝试根据输入数据创建一个新表,并将其插入docx文档.以下导致输出文件损坏:
private Tbl getSampleTable(WordprocessingMLPackage wPMLpackage) {
ObjectFactory factory = Context.getWmlObjectFactory();
int writableWidthTwips = wPMLpackage.getDocumentModel().getSections().get(0).getPageDimensions().getWritableWidthTwips();
List<Map<String, String>> data = getSampleTableData();
TableDefinition tableDef = getSampleTableDef();
int cols = tableDef.getColumns().size();
int cellWidthTwips = new Double(Math.floor((writableWidthTwips / cols))).intValue();
Tbl table = TblFactory.createTable((data.size() + 1), cols, cellWidthTwips);
Tr headerRow = (Tr) table.getContent().get(0);
int f = 0;
for (Column column : tableDef.getColumns()) {
Tc column = (Tc) headerRow.getContent().get(f);
f++;
Text text = factory.createText();
text.setValue(column.getName());
R run = factory.createR();
run.getContent().add(text);
column.getContent().add(run);
headerRow.getContent().add(column);
}
int i = 1; …Run Code Online (Sandbox Code Playgroud) 当我在 jboss as7 上部署 maven/spring 应用程序并尝试上传 docx 文件时,我收到以下消息。当我在应用程序的所见即所得编辑器中查看上传文件时,该消息显示在上传文件的正文中。当我在码头上本地运行该应用程序时,该消息不会显示。我包含了 log4j 和 docx4j 属性文件。我不确定什么属性允许我切换错误中提到的 docx4j 类的调试日志记录,到目前为止,我在网络搜索中发现的是空的。顺便说一句,我的应用程序没有使用 log4j/docx4j xml 文件,从我读到的内容来看,它是一个或一个设置。如果我应该切换到 xml,请告诉我并告知我需要调整哪个属性,以便我可以清除此消息。
泰
要隐藏这些消息,请关闭 org.docx4j.convert.out.html.HtmlExporterNG2 的 log4j 调试级别日志记录
log4j.属性
log4j.rootLogger=ERROR,stdout
#Console Appender
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%5p] [%t %d{hh:mm:ss}] (%F:%M:%L) %m%n
#Custom assignments
log4j.logger.Controllers=DEBUG,stdout
log4j.logger.Entities=DEBUG,stdout
log4j.logger.Models=DEBUG,stdout
#Disable additivity
log4j.additivity.Controllers=false
log4j.additivity.Entities=false
log4j.additivity.Models=false
Run Code Online (Sandbox Code Playgroud)
docx4j.属性
# Page size: use a value from org.docx4j.model.structure.PageSizePaper enum
# eg A4, LETTER
docx4j.PageSize=LETTER
# Page size: use a value from org.docx4j.model.structure.MarginsWellKnown enum
docx4j.PageMargins=NORMAL
docx4j.PageOrientationLandscape=false
# Page size: use a value from org.pptx4j.model.SlideSizesWellKnown enum …Run Code Online (Sandbox Code Playgroud) 当我将 docx 文档转换为 pdf 时,我的国家字符会转换为“#”标记。
有没有办法为pdf文档设置字体编码?
我过去使用过 xdocreport,它可以处理这个问题,但我在图像、页眉和页脚方面遇到了问题。
Docx4j 可以做到这一点,但字体不行。转换后,字体具有 ANSI 编码,而我想要 windows-1250。有一个选项可以设置这个吗?
我正在使用 docx4j 3.1.0 将数据从 xml 转换为 word。如果某一字段没有内容(空),则导出文件中会生成“单击此处输入文本”。我怎样才能摆脱它?
我的问题非常具体,我希望有人完成了从HTML到DOCX的转换.
为此,我从github中获取了一个示例代码,并在我的本地Eclipse安装程序中进行了尝试.
import java.io.File;
import java.io.FileNotFoundException;
import javax.xml.bind.JAXBException;
import org.docx4j.convert.in.xhtml.XHTMLImporterImpl;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.exceptions.InvalidFormatException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart;
public class HtmlToDocConvert {
/**
* @param args
* @throws FileNotFoundException
* @throws JAXBException
* @throws Docx4JException
*/
public static void main(String[] args) throws FileNotFoundException,
JAXBException, Docx4JException {
// TODO Auto-generated method stub
// File file = new File("C:\\TestWordToHtml\\html\\Test.html");
String inputfilepath = "C:\\TestWordToHtml\\html\\Test.html";
try {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
.createPackage();
NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
ndp.unmarshalDefaultNumbering();
XHTMLImporterImpl xHTMLImporter = new XHTMLImporterImpl( …Run Code Online (Sandbox Code Playgroud) 我正在我的软件中使用 docx4j 将 docx 文件转换为 html。我正在基于 Windows 的系统中进行开发,我的产品是 AWS 中的 Ubuntu Linux 14.04。在 Windows 中一切正常,但是当涉及到 Ubuntu 时,它向我抛出一个异常,如下所示。
\n\n\n\n\n2015-11-19 07:33:36 错误 AbstractExporter:108 - 导出\n 包 java.lang.NullPointerException 时出现异常,位于\n org.docx4j.openpackaging.parts.WordprocessingML.ObfuscatedFontPart.deleteEmbeddedFontTempFiles(ObfuscatedFontPart.java:263)\n在\n org.docx4j.openpackaging.parts.WordprocessingML.FontTablePart.deleteEmbeddedFontTempFiles(FontTablePart.java:161)\n 在\n org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:91)\n在 org.docx4j.Docx4J.toHTML(Docx4J.java:511) 在\n com.testbudha.document.impl.WordDocumentExtractor.toHtml(WordDocumentExtractor.java:31)\n 在\n com.testbudha.document.impl.DocXExtractor .getText(DocXExtractor.java:31)\n 位于\n com.testbudha.document.impl.DocumentServiceImpl.getFileText(DocumentServiceImpl.java:18)\n 位于\n com.testbudha.server.controller.StudentHomeController.getResumeText(StudentHomeController .java:120)
\n
我知道这是一个与字体相关的问题,我尝试安装
\n\n\n\n\nttf-mscorefonts-安装程序
\n
但它并没有改变任何东西我也尝试使用这个脚本安装vista字体。然后我也遇到了同样的异常
\n\n\n\nprotected String toHtml(WordprocessingMLPackage wordMLPackage, String path, HttpServletRequest request)\n throws Docx4JException {\n try {\n\n HTMLSettings htmlSettings = Docx4J.createHTMLSettings();\n htmlSettings.setImageDirPath(path + "/_files");\n htmlSettings.setImageTargetUri(request.getContextPath() + "/getfile/");\n htmlSettings.setWmlPackage(wordMLPackage);\n\n …Run Code Online (Sandbox Code Playgroud) 我想使用正则表达式 (java RegEx)在MS Word ( .docx ) 文档中进行替换:
\n\nExample: \n \x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\xbc: \xe2\x80\xa6\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试使用Apache POI - XWPF获取文本模板(如%SOME_TEXT%) 并替换文本,但不能保证替换,因为 POI 分隔运行 => 我得到类似这样的内容():System.out.println(run.getText(0))
\xe2\x80\xa6\n, \xd1\x81 \xd0\xbe\xd0\xb4\xd0\xbd\xd0\xbe\xd0\xb9 \xd1\x81\xd1\x82\xd0\xbe\xd1\x80\xd0\xbe\xd0\xbd\xd1\x8b, \xd0\xb8 \n%\nSOME_TEXT\n%\n\n\xd0\xb8\xd0\xbc\xd0\xb5\xd0\xbd\xd1\x83\xd0\xb5\xd0\xbc\xd0\xbe\xd0\xb5 \n\xd0\xb2 \xd0\xb4\xd0\xb0\xd0\xbb\xd1\x8c\xd0\xbd\xd0\xb5\xd0\xb9\xd1\x88\xd0\xb5\xd0\xbc \xc2\xab\xd0\x97\xd0\xb0\xd0\xba\xd0\xb0\xd0\xb7\xd1\x87\xd0\xb8\xd0\xba\xc2\xbb, \xd0\xb2 \xd0\xbb\xd0\xb8\xd1\x86\xd0\xb5\n\n%\nSOME\n_\nTEXT\n%\nRun Code Online (Sandbox Code Playgroud)\n\n代码示例:
\n\nFileInputStream fis = new FileInputStream(new File("document.docx"));\nXWPFDocument document = new XWPFDocument(fis);\nList<XWPFParagraph> …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用 docx4j 库将文件从 html 转换为 docx。
我已经设法使用 itext5 将 html 转换为 pdf,但现在由于 jaxb,我正面临尝试转换为 docx 的异常。
我的项目使用 maven,所以我试图导入很多库......徒劳......
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-ImportXHTML</artifactId>
<version>8.0.0</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>xhtmlrenderer</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-jxc</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>com.googlecode.jaxb-namespaceprefixmapper-interfaces</groupId>
<artifactId>JAXBNamespacePrefixMapper</artifactId> …Run Code Online (Sandbox Code Playgroud)