标签: xdocreport

XDocReport使用OSGI将ODT转换为PDF

要开始使用XDocReport,我想将ODT转换为PDF.

我的所有应用程序都是OSGi.所以我安装了以下捆绑包:

fr.opensagres.xdocreport.converter-1.0.5.jar
fr.opensagres.xdocreport.core-1.0.5.jar
fr.opensagres.xdocreport.document-1.0.5.jar
fr.opensagres.xdocreport.itext.extension-1.0.5.jar
fr.opensagres.xdocreport.template-1.0.5.jar
Run Code Online (Sandbox Code Playgroud)

除了类路径我itext-4.2.1.jar(它不是OSGi包),我导出以下包:

  <package name="com.lowagie.text"/>
  <package name="com.lowagie.text.factories"/>
  <package name="com.lowagie.text.pdf"/>
  <package name="com.lowagie.text.pdf.draw"/>
Run Code Online (Sandbox Code Playgroud)

但是,我没有使用以下代码获取转换器:

Options options = Options.getFrom(DocumentKind.ODT).to(ConverterTypeTo.PDF);
IConverter converter = ConverterRegistry.getRegistry().getConverter(options);
in = new FileInputStream(new File("/Temp/Test1.odt"));
OutputStream out = new FileOutputStream(new File("/Temp/Test1.pdf"));
converter.convert(in, out, options); //HERE I GET NullPointerException - converter is null.
Run Code Online (Sandbox Code Playgroud)

试图解决这个问题我添加了以下包:

org.odftoolkit.odfdom.converter.core-1.0.5.jar
org.odftoolkit.odfdom.converter.pdf-1.0.5.jar
Run Code Online (Sandbox Code Playgroud)

但是,我得到:

org.osgi.framework.BundleException:bundle org.odftoolkit.odfdom.converter.core中未解决的约束[43]:无法解析43.0:缺少要求[43.0] osgi.wiring.package; (osgi.wiring.package = org.odftoolkit.odfdom.dom)

为了解决问题org.odftoolkit.odfdom.dom我添加odfdom-java-0.8.7.jar到classpath(它也不是OSGi)并导出以下包:

   <package name="org.odftoolkit.odfdom.doc"/>
   <package name="org.odftoolkit.odfdom.dom"/>
   <package name="org.odftoolkit.odfdom.dom.element.draw"/>
   <package name="org.odftoolkit.odfdom.dom.element.office"/>
   <package name="org.odftoolkit.odfdom.dom.element.style"/>
   <package name="org.odftoolkit.odfdom.dom.element.table"/>
   <package name="org.odftoolkit.odfdom.dom.style"/>
   <package name="org.odftoolkit.odfdom.incubator.doc.office"/> …
Run Code Online (Sandbox Code Playgroud)

java osgi itext odftoolkit xdocreport

17
推荐指数
1
解决办法
1890
查看次数

使用POI从docx生成pdf时出错

我想用apache poi将docx转换为pdf,使用docx4j正确生成docx.使用简单文档转换工作正常,但是当我想转换更风格化的文档时,POI会抛出异常:

org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException:union value'0000FF"> http://schemas.openxmlformats.org/wordprocessingml/2006/main'15:09:20 org.apache.poi.xwpf.converter.core .XWPFConverterException:org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException:union value'0000FF"> http://schemas.openxmlformats.org/wordprocessingml/2006/main'at org.apache.poi.xwpf.converter.pdf. PdfConverter.doConvert(PdfConverter.java:70)〜[org.apache.poi.xwpf.converter.pdf-1.0.6.jar:1.0.6]

有这个例外的原因:

<w:r>
    <w:rPr>
        <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
        <w:color w:val="0000FF"><span style="background-color: rgb(51, 153, 102);"><span style="background-color: rgb(255, 0, 0);"><font color="99CC00"/>
        <w:sz w:val="20"/>
        <w:szCs w:val="20"/>
        <w:highlight w:val="red"/>
    </w:rPr>
    <w:t xml:space="preserve">Juillet-Aout</w:t>
</w:r>
Run Code Online (Sandbox Code Playgroud)

我的文件的屏幕

这是我的代码:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;


import org.apache.poi.xwpf.usermodel.XWPFDocument;

import fr.opensagres.poi.xwpf.converter.pdf.PdfConverter;
import fr.opensagres.poi.xwpf.converter.pdf.PdfOptions;

public class ConvertDocxPdf
{

    public static void main( String[] args )
    {
        long startTime = System.currentTimeMillis();

        try
        {
            // 1) Load docx with POI …
Run Code Online (Sandbox Code Playgroud)

pdf docx docx4j xdocreport

5
推荐指数
0
解决办法
1159
查看次数

使用iText和apache velocity template(.vm)生成PDF文件

在Java中使用iText和Apache Velocity模板文件(.vm)生成PDF的一般工作流程是什么?

我有兴趣知道以下步骤:解析模板文件,将Java对象置于上下文中以及执行生成pdf等的步骤.

我知道这是一个非常基本的问题.但我无法在网上找到这种类型的单一例子.我找到了XDocReport,但我也有兴趣了解其他替代方案.

请帮我一些示例项目链接或至少开始的步骤.

java pdf velocity itext xdocreport

3
推荐指数
2
解决办法
2万
查看次数

XDocReport : XDocConverterException: 找不到来自=DOCX 的转换器

我正在测试来自 XDocReport 的示例代码。我结合起来,基于 docx 模板创建了 docx 和 pdf 报告。但是我不断收到这条消息

Apr 21, 2016 5:39:10 PM fr.opensagres.xdocreport.converter.ConverterRegistry internalFindConverter
SEVERE: Cannot find converters from=DOCX
fr.opensagres.xdocreport.converter.XDocConverterException: Cannot find converters from=DOCX
    at fr.opensagres.xdocreport.converter.ConverterRegistry.internalFindConverter(ConverterRegistry.java:121)
    at fr.opensagres.xdocreport.converter.ConverterRegistry.findConverter(ConverterRegistry.java:74)
    at fr.opensagres.xdocreport.document.AbstractXDocReport.getConverter(AbstractXDocReport.java:667)
    at fr.opensagres.xdocreport.document.AbstractXDocReport.convert(AbstractXDocReport.java:690)
    at fr.opensagres.xdocreport.samples.docxandfreemarker.DocxProjectWithFreemarkerList.main(DocxProjectWithFreemarkerList.java:231)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Run Code Online (Sandbox Code Playgroud)

这是代码:

try
        {
            InputStream in = DocxProjectWithFreemarker.class.getResourceAsStream( "DocxProjectWithFreemarkerList.docx" );
            IXDocReport report = XDocReportRegistry.getRegistry().loadReport( in, TemplateEngineKind.Freemarker );

            FieldsMetadata metadata = report.createFieldsMetadata();

            metadata.load( "developers", Developer.class, true );

            IContext context = report.createContext();
            Project project = new …
Run Code Online (Sandbox Code Playgroud)

xdocreport

3
推荐指数
1
解决办法
2084
查看次数

xDocReport-不可能为输入流创建报告

我无法解决这个问题。来源是:

        try {
        // 1) Load Docx file by filling Velocity template engine and cache it to the registry
        InputStream in = new FileInputStream("/test.docx");
        IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in,TemplateEngineKind.Velocity);

        // 2) Create context Java model
        IContext context = report.createContext();
        context.put("user", variables.get("user"));

        // 3) Generate report by merging Java model with the Docx
        OutputStream out = new FileOutputStream(new File("/test_Out.docx"));
        report.process(context, out);

      } catch (IOException e) {
        e.printStackTrace();
      } catch (XDocReportException e) {
        e.printStackTrace();
      }
Run Code Online (Sandbox Code Playgroud)

当我尝试执行此代码时,出现错误:

09:03:15,608 ERROR [stderr] (http--127.0.0.1-8080-1) fr.opensagres.xdocreport.core.XDocReportException: Impossible to …
Run Code Online (Sandbox Code Playgroud)

java inputstream report seam3 xdocreport

2
推荐指数
1
解决办法
4453
查看次数

使用 docx4j 转换 docx -&gt; pdf 时如何更改字体编码?

当我将 docx 文档转换为 pdf 时,我的国家字符会转换为“#”标记。
有没有办法为pdf文档设置字体编码?

我过去使用过 xdocreport,它可以处理这个问题,但我在图像、页眉和页脚方面遇到了问题。

Docx4j 可以做到这一点,但字体不行。转换后,字体具有 ANSI 编码,而我想要 windows-1250。有一个选项可以设置这个吗?

java pdf docx docx4j xdocreport

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

xdocreport ×6

java ×4

pdf ×3

docx ×2

docx4j ×2

itext ×2

inputstream ×1

odftoolkit ×1

osgi ×1

report ×1

seam3 ×1

velocity ×1