包含java实现itext的词条

博主:adminadmin 2023-01-25 19:57:22 367

今天给各位分享java实现itext的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

如何运用Java组件itext生成pdf

在企业的信息系统中,报表处理一直占比较重要的作用,Java组件——iText可以非常快速的生成PDF报表。iText是着名的开放源码的站点 sourceforge一个项目,是用于生成PDF文档的一个java类库。通过iText不仅可以生成PDF或rtf的文档,而且可以将XML、 ...

跪求java实现对有内容的word文档添加页眉,jacob、poi、itext都没尝试成功,跪求指导!

package com.ray.poi.util;

import java.io.ByteArrayInputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import org.apache.poi.poifs.filesystem.DirectoryEntry;

import org.apache.poi.poifs.filesystem.DocumentEntry;

import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import org.textmining.text.extraction.WordExtractor;

/**

* 读写doc

* @author wangzonghao

*

*/

public class POIWordUtil {

/**

* 读入doc

* @param doc

* @return

* @throws Exception

*/

public static String readDoc(String doc) throws Exception {

// 创建输入流读取DOC文件

FileInputStream in = new FileInputStream(new File(doc));

WordExtractor extractor = null;

String text = null;

// 创建WordExtractor

extractor = new WordExtractor();

// 对DOC文件进行提取

text = extractor.extractText(in);

return text;

}

/**

* 写出doc

* @param path

* @param content

* @return

*/

public static boolean writeDoc(String path, String content) {

boolean w = false;

try {

// byte b[] = content.getBytes("ISO-8859-1");

byte b[] = content.getBytes();

ByteArrayInputStream bais = new ByteArrayInputStream(b);

POIFSFileSystem fs = new POIFSFileSystem();

DirectoryEntry directory = fs.getRoot();

DocumentEntry de = directory.createDocument("WordDocument", bais);

FileOutputStream ostream = new FileOutputStream(path);

fs.writeFilesystem(ostream);

bais.close();

ostream.close();

} catch (IOException e) {

e.printStackTrace();

}

return w;

}

}

测试

package com.ray.poi.util;

import junit.framework.TestCase;

public class POIUtilTest extends TestCase {

public void testReadDoc() {

try{

String text = POIWordUtil.readDoc("E:/work_space/poi/com/ray/poi/util/demo.doc");

System.out.println(text);

}catch(Exception e){

e.printStackTrace();

}

}

public void testWriteDoc() {

String wr;

try {

wr = POIWordUtil.readDoc("E:/work_space/poi/com/ray/poi/util/demo.doc");

boolean b = POIWordUtil.writeDoc("c:\\demo.doc",wr);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

看看取出来的对象有哪些属性

两个jar包

java中怎么利用poi和itext生成pdf文档

生成PDF文档代码如下:

package poi.itext;

import java.io.FileOutputStream;

import java.io.IOException;

import java.awt.Color;

import com.lowagie.text.*;

import com.lowagie.text.pdf.*;

import com.lowagie.text.pdf.BaseFont;

/**

 * 创建Pdf文档

 * @author Administrator

 *

 */

public class HelloPdf

{

    public static void main(String[] args)throws Exception

    {

        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

        Font FontChinese = new Font(bfChinese, 12, Font.NORMAL);

        // 第一步,创建document对象

        Rectangle rectPageSize = new Rectangle(PageSize.A4);

        

        //下面代码设置页面横置

        //rectPageSize = rectPageSize.rotate();

        

        //创建document对象并指定边距

        Document doc = new Document(rectPageSize,50,50,50,50);

        Document document = new Document();

        try

        {

            // 第二步,将Document实例和文件输出流用PdfWriter类绑定在一起

            //从而完成向Document写,即写入PDF文档

            PdfWriter.getInstance(document,new FileOutputStream("src/poi/itext/HelloWorld.pdf"));

            //第3步,打开文档

            document.open();

            //第3步,向文档添加文字. 文档由段组成

            document.add(new Paragraph("Hello World"));

            Paragraph par = new Paragraph("世界你好",FontChinese);

            document.add(par);

            PdfPTable table = new PdfPTable(3);

            for(int i=0;i12;i++)

            {

                if (i == 0)

                {

                    PdfPCell cell = new PdfPCell();

                    cell.setColspan(3);

                    cell.setBackgroundColor(new Color(180,180,180));

                    cell.addElement(new Paragraph("表格头" , FontChinese));

                    table.addCell(cell);

                }

                else

                {

                    PdfPCell cell = new PdfPCell();

                    cell.addElement(new Paragraph("表格内容" , FontChinese));

                    table.addCell(cell);

                }

            }

            document.add(table);

        }

        catch (DocumentException de)

        {

            System.err.println(de.getMessage());

        }

        catch (IOException ioe)

        {

            System.err.println(ioe.getMessage());

        }

        //关闭document

        document.close();

        

        System.out.println("生成HelloPdf成功!");

     }

    

    

}

希望对你有帮助。

java itextpdf找到重复的关键字

在要编辑的文档的PDF文件页面中弹出的查找页面中输入关键字。

1、第一步:通过在打开的PDF编辑器上使用鼠标拖动方法来打开要编辑的文档PDF文件。2、第二步:这样就将要编辑的文档PDF文件打开到PDF编辑器中了。3、第三步:接着点击打开编辑的文档的PDF编辑器菜单中的视图菜单下选择查找。4、第四步:在要编辑的文档的PDF文件页面中弹出的查找页面中输入关键字。5、这样就可以查找关键字了

java创建pdf文件写入不进去

可以用生成PDF报表的Java组件--iText。

具体实现方法如下:1、导入itext-2。1。5。jar跟itextasian-1。5。2。jar两个包到项目里,2、建立一个pdf文件。

一般情况下,iText使用在有以下一个要求的项目中:1。内容无法提前利用:取决于用户的输入或实时的数据库信息。2。由于内容,页面过多,PDF文档不能手动生成。3。文档需在无人参与,批处理模式下自动创建。4。内容被定制或个性化。

java实现itext的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、java实现itext的信息别忘了在本站进行查找喔。