package tst.word;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Iterator;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.FormattingResults;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.apps.PageSequenceResults;
import org.xml.sax.InputSource;
public class PDFWithFOP {
public static void main(String[] args) throws Exception{
new PDFWithFOP().run();
System.out.println("success");
}
public void run() throws Exception{
File fo=new File("D:\\newtst\\helloworld.fo");
File pdf=new File("D:\\newtst\\helloworld.pdf");
convertFO2PDF(fo,pdf);
}
public void convertFO2PDF(File fo, File pdf) throws Exception {
//Construct driver
FopFactory factory=FopFactory.newInstance();
FOUserAgent userAgent=factory.newFOUserAgent();
OutputStream out=null;
out=new FileOutputStream(pdf);
out=new BufferedOutputStream(out);
Fop fop=factory.newFop(MimeConstants.MIME_PDF,userAgent,out);
TransformerFactory transformerFactory=TransformerFactory.newInstance();
Transformer transformer=transformerFactory.newTransformer();
Source source=new StreamSource(fo);
Result res=new SAXResult(fop.getDefaultHandler());
transformer.transform(source,res);
out.close();
}
}
关键在于XML-FO对XML的描述。可通过XSTL转换的方式生成FO,也可通过自己的程序去生成FO。
通过FOP可最终产生PDF、RTF等等各种文档类型。
新博客地址
分享到:
相关推荐
XML-项目使用 Apache FOP(XML、SQL、XSL、XSL-FO、XSLT)的 RRC XML 最终项目
Apache FOP (Formatting Objects Processor) is a print formatter driven by XSL formatting objects (XSL-FO) and an output independent formatter. It is a Java application that reads a formatting object ...
Apache FOP (Formatting Objects Processor) is a print formatter driven by XSL formatting objects (XSL-FO) and an output independent formatter. It is a Java application that reads a formatting object ...
样本pdf 示例 XML 到 FO 到 PDF spring-boot 应用程序。 示例 spring-boot 项目使用 xslt 样式将 xml 数据转换为 fo: 然后使用 apache FOP 将其转换为 pdf 文件
带有6种常见中文字体(微软雅黑、宋体、黑体、楷体、仿宋、隶书)支持的 Apache fop-2.4。
此存储库提供的功能包含在 OSGi 和 Eclipse 中使用 FOP 所需的捆绑包集合。 #Licence 此功能提供的捆绑包基于 eclipse 更新端 ( ) 和 Orbit P2 存储库 ( )。 因此,它们在 EPL ( ) 下发布或兼容。 以下捆绑包...
另一方面,FOPLaboratory使您可以快速交换XSL工作表,以从一个相同的XML内容生成不同的PDF文件。 已发布的项目文件包含该程序的C ++ / Qt源代码。 我接受捐款。 这笔钱将用于翻修农舍和谷仓,以及建设我们的家庭...
XSL-FO格式标记所见即所得编辑器和PDF树书签。 XML文档,最常用作PDF或RTF生成器。 它可以从Apache fop示例中读取和编辑95%的内容。 导出到fo,pdf,rtf,tif传真,页面,导入fo,html,页面,odt OpenOffice 1-2
包含在目录“ sample-upn”中的示例代表xsl格式设置对象样式表(使用XML2pdfprint以外的其他术语版权所有,有关详细信息,请参见copyright.txt)作为电子发票打印输出的示例,例如在项目e-中指定的XML。向...
这是来自 Apache Group 的流行 XML ... 它使用 Xerces 进行 XML 验证,使用 Xalan 进行 XSLT,使用 FOP 进行 XML 到 PDF,以及使用 iText 向 PDF 添加安全功能。 可以制作 FO、HTML 和 PDF。 我个人将它用于我的 DocBo
为了生成PDF文档,首先将报告,报价,发票或常规文档XML转换为XSL-FO(XSL格式对象),然后使用Apache FOP将其转换为PDF。结构这些目录的用法如下: chatops:包含可以与Hubot(chatOps)一起使用的bash和Python...
Visual xsltproc是一个工具,可帮助编写xslt文件并对其进行调试以查找错误。 它编写xml,并生成xml(XML和行号的语法高亮显示)。 最后,如果结果是XSL-FO,它将在Apache FOP java上生成pdf。 建立在QT4.2之上。
生成的 URL 中包含这个 member 的唯一名称,这个标签必须要在一个 table 或一个 query 的标签里嵌套使用。 这个动作还依赖于该标签的 sessionParam 属性,如果该属性存在,那么参数值将在页面显示之前写到 ...
denature 是一个将 HTML 文件转换为 PDF 文件的 perl 程序。 它通过转换为 XSL-FO 来实现这一点,然后将其从 xml.apache.org 传递给 FOP 程序。
NFop 是 XSL-FO 的格式化对象处理器 (FOP),在 .NET Framework 上运行。 它是从 Apache XML 项目的 FOP Java 源代码到 .NET 的 Visual J# 的端口。 这使得它非常适合纯 .NET 报告模块。