linux下使用itext输出pdf

这篇博客介绍了如何在Redhat EL5环境下,利用Tomcat5和jsp,结合iText库来生成包含日文的PDF文件。通过将必要的jar包放入Tomcat的lib目录,然后在jsp中设置相应代码,成功输出PDF文档。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
还不错的open的pdf生成包,我用redhat EL5, tomcat5做到的试验
把下载来的 iTextAsian.jar 和 itext-2.0.4.jar放到tomcat的ROOT/WEB-INF/lib/下
然后用下面的jsp测试。就可以成功了输出日文的pdf了。
<%@
page import="java.io.*,
    com.lowagie.text.*,
    com.lowagie.text.pdf.*,
    java.io.RandomAccessFile,
    com.lowagie.text.Image"
%><%
//
// Template JSP file for iText
// by Tal Liron
//
response.setContentType( "application/pdf" );
// step 1: creation of a document-object
Document document = new Document();
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a temporary buffer
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
PdfWriter.getInstance( document, buffer );
// step 3: we open the document
document.open();
// step 4: we add a paragraph to the document
String japanese = "/u5317/u672c/u3078/u884c/u304d/u307e/u3059/uff01";
BaseFont bfjapanese = BaseFont.createFont("HeiseiMin-W3","UniJIS-UCS2-H",BaseFont.NOT_EMBEDDED);
Font Fontjapanese = new Font(bfjapanese,12,Font.NORMAL);
Paragraph p = new Paragraph(japanese,Fontjapanese);
document.add(p);
// step 5: we close the document
document.close();
// step 6: we output the writer as bytes to the response output
DataOutput output = new DataOutputStream( response.getOutputStream() );
byte[] bytes = buffer.toByteArray();
response.setContentLength(bytes.length);
for( int i = 0; i < bytes.length; i++ ) { output.writeByte( bytes[i] ); }
out.clear();
out = pageContext.pushBody();
%>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值