1. 跪求iText 中文API
itext api 中文版的
一部分 iText的简单应用
第一章 创建一个Document
利用iText五步创建一个PDF文件:helloword。
第一步,创建一个 iTextSharp.text.Document对象的实例:
Document document = new Document();
第二步,为该Document创建一个Writer实例:
PdfWriter.getInstance(document, new FileStream("Chap0101.pdf", FileMode.Create));
第三步,打开当前Document
document.Open();
第四步,为当前Document添加内容:
document.Add(new Paragraph("Hello World"));
第五步,关闭Document
document.Close();
完整的代码见示例代码
2. 请教iText生成word问题
使用iText生成word,struts2框架,使用iText-2.1.7.jar和iText-rtf-2.1.7.jar 方法如下: import java.io.*; import java.awt.Color; import com.lowagie.text.*; import com.lowagie.text.rtf.RtfWriter2; import com.lowagie.text.rtf.headerfooter.*; import com.lowagie.text.rtf.field.*; import com.lowagie.text.rtf.table.*; import com.lowagie.text.rtf.style.RtfFont; public class RtfClass { public static String rtf() { com.lowagie.text.Document document = new com.lowagie.text.Document(); try {System.out.println("try1"); RtfWriter2.getInstance(document, new FileOutputStream("C:\rhDocs\testRTFdocument.rtf")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } document.open(); try {System.out.println("try2"); document.add(new Paragraph("Hello World!")); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } document.close(); return "ok"; } } 我用这个生成绝对不会有问题。
3. java itext 生成word 如何控制word 横向和分栏,可以实现么
要加一些文本到一个矩形框的内部,希望文本到达右边界时自动换行。超出矩形部分将不显示,可以通过ColumnText类实现。
举个例子:
为显示一个指定的短句在坐标(100, 300)和(200,500)间的矩形内居中,使用下面的代码:
PdfContentByte cb =writer.DirectContent;
ColumnText ct = new ColumnText(cb);
ct.setSimpleColumn(phrase,60, 300, 100, 500, 15, Element.ALIGN_CENTER);
ct.go();
4. itext word 中怎么添加下划线
你好,你可以试试这个行不行。
Font.UNDERLINE
eg:
Font font3 = new Font(bfChinese, 10, Font.UNDERLINE);
String contextString2 = " TECHNICAL INFORMATION ";
Paragraph context2 = new Paragraph(contextString2,font3);
context2.setAlignment(Element.ALIGN_LEFT);
document.add(context2);
5. itext导出Word的问题,能解答的有高分
1: 可以设置字体带下划线,也就是 new Phrase里面带上设置字体下划线 2: 用表格实现,把表格的下边框线显示出来 3: 直接画线也可以 package test; import com.lowagie.text.Cell; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Font; import com.lowagie.text.Image; import com.lowagie.text.PageSize; import com.lowagie.text.Paragraph; import com.lowagie.text.Table; import com.lowagie.text.pdf.BaseFont; import com.lowagie.text.rtf.RtfWriter2; import java.awt.Color; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; import javax.swing.JOptionPane; /** * * @author julycn */ public class RTFCreate { /** * Creates a new instance of RTFCreate */ public RTFCreate() { } public static void main(String[] args){ RTFCreate rtfCreate=new RTFCreate(); try { rtfCreate.createRTF(); JOptionPane.showMessageDialog(null,"表格已经成功创建"); } catch (MalformedURLException ex) { JOptionPane.showMessageDialog(null,"表格导出出错,错误信息:"+ex+"\n错误原因可能是表格已经打开!"); ex.printStackTrace(); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null,"表格导出出错,错误信息:"+ex+"\n错误原因可能是表格已经打开!"); ex.printStackTrace(); } catch (IOException ex) { JOptionPane.showMessageDialog(null,"表格导出出错,错误信息:"+ex+"\n错误原因可能是表格已经打开!"); ex.printStackTrace(); } catch (DocumentException ex) { JOptionPane.showMessageDialog(null,"表格导出出错,错误信息:"+ex+"\n错误原因可能是表格已经打开!"); ex.printStackTrace(); } } public void createRTF() throws FileNotFoundException, DocumentException, MalformedURLException, IOException{ //创建word文档 Document document=new Document(PageSize.A4); //输入word文档 RtfWriter2.getInstance(document,new FileOutputStream("d:\\word.rtf")); document.open(); //中文字体 BaseFont bfChinese=BaseFont.createFont("STSongStd-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED); Font fontChinese=new Font(bfChinese,12,Font.HELVETICA); //创建有3列的表格 Table table=new Table(3); document.add(new Paragraph("生成rft文档!",fontChinese)); table.setBorderWidth(1); table.setBorderColor(new Color(0,0,255)); table.setPadding(5); table.setSpacing(5); //添加表头元素 Cell cell=new Cell("header"); cell.setHeader(true); cell.setColspan(3); table.addCell(cell); table.endHeaders();//表头结束 //表格主体 cell=new Cell("Example cell with colspan 1 and rowspan 2"); cell.setRowspan(2); cell.setBorderColor(new Color(255,0,0)); table.addCell(cell); table.addCell("1.1"); table.addCell("2.1"); table.addCell("1.2"); table.addCell("2.2"); table.addCell(new Paragraph("测试1",fontChinese)); table.addCell("big cell"); cell.setRowspan(2); cell.setColspan(2); table.addCell(cell); table.addCell(new Paragraph("测试2",fontChinese)); document.add(table); //在表格末尾添加图片 Image png=Image.getInstance("d:\\duck.jpg"); document.add(png); document.close(); } } 看看这个有没有帮助.。
6. java解析word文档用什么技术
java读取word文档时,虽然网上介绍了很多插件poi、java2Word、jacob、itext等等,poi无法读取格式(新的API估
计行好像还在处于研发阶段,不太稳定,做项目不太敢用);java2Word、jacob容易报错找不到注册,比较诡异,我曾经在不同的机器上试过,操作
方法完全一致,有的机器不报错,有的报错,去他们论坛找高人解决也说不出原因,项目部署用它有点玄;itxt好像写很方便但是我查了好久资料没有见到过关
于读的好办法。经过一番选择还是折中点采用rtf最好,毕竟rtf是开源格式,不需要借助任何插件,只需基本IO操作外加编码转换即可。rtf格式文件表
面看来和doc没啥区别,都可以用word打开,各种格式都可以设定。
转载请注明出处51数据库 » itextwordapi
丶InMyHeart