fop 0.20.5

package com.yux;

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

import javax.xml.parsers.SAXParserFactory;

import org.apache.fop.apps.Driver;
import org.apache.fop.apps.Options;
import org.apache.fop.configuration.ConfigurationParser;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
public class Test {

	public  Options options = null;
    public static void main(String[] args) throws Exception {
    	new Test().test("test11.pdf");
//    	new Test().test("test12.pdf");
//    	new Test().test("test13.pdf");
    }
    
    public void test(String fileName) throws Exception {
    	//java -cp build\fop.jar;lib\avalon-framework.jar;lib\xml-apis.jar;lib\xercesImpl.jar;lib\xalan.jar org.apache.fop.fonts.apps.TTFReader D:\fonts\msjh.ttf msjh.xml
    	if(options==null) {
    		InputStream in = new FileInputStream(new File("D:/yux/fop-0.20.5/conf/userconfig.xml")); 
//    		
    		options=new Options(new InputSource(in));
    		in.close();
    		in =null;
    		System.out.println("init..................................................................");
    	}
    	Driver driver = new Driver();
        String folder ="D:/yux/fop-0.20.5/test/";
        FileOutputStream out=new FileOutputStream(folder+fileName);
        driver.setInputSource(new InputSource (folder+"text.xsl"));
        driver.setOutputStream(out);
        driver.setRenderer(Driver.RENDER_PDF);
        //读入配置(在Options的构造函数中完成)
        driver.run();
        out.close();
        driver.reset();
        options =null;
//        Thread.sleep(300000);
        System.out.println("end");
    }

}

userconfig.xml

 <font metrics-file="D:\workspace\fopdemo\conf\fonts\msjhbd.xml" embed-file="D:\workspace\fopdemo\conf\fonts\msjhbd.ttf" kerning="yes">
    <font-triplet name="MicrosoftJhengHei" style="normal" weight="bold"/>
    <font-triplet name="MicrosoftJhengHei" style="italic" weight="bold"/>
 </font>
 <font metrics-file="D:\workspace\fopdemo\conf\fonts\msjh.xml" embed-file="D:\workspace\fopdemo\conf\fonts\msjh.ttf" kerning="yes">
    <font-triplet name="MicrosoftJhengHei" style="normal" weight="normal"/>
    <font-triplet name="MicrosoftJhengHei" style="italic" weight="normal"/>
 </font>

XSL

<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<fo:layout-master-set>
		<fo:simple-page-master master-name="simple" page-height="29.7cm" page-width="21cm" margin-top="1cm" margin-bottom="2cm" margin-left="2.5cm" margin-right="2.5cm">
			<fo:region-body margin-top="3cm" />
			<fo:region-before extent="3cm" />
			<fo:region-after extent="1.5cm" />
		</fo:simple-page-master>
	</fo:layout-master-set>
	<fo:page-sequence master-reference="simple">
		<fo:flow flow-name="xsl-region-body">
			<fo:block font-family="MicrosoftJhengHei">
			 测试123    
			 </fo:block>
			<fo:block font-family="MicrosoftJhengHei" font-weight="bold">
			 测试123455 
			 </fo:block>
			 <fo:block>
			 ABC    
			 </fo:block>
			  <fo:block font-family="SimSun1">
			 teste测试
			 </fo:block>
		</fo:flow>
	</fo:page-sequence>
</fo:root>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值