读书人

小弟我和iText的第一次亲密接触

发布时间: 2012-11-04 10:42:41 作者: rapoo

我和iText的第一次亲密接触
要生成pdf文件,在网上查了下资料,首选iText,跟着大家走,我也iText一把。
1:把字型编程A4横向

private void concatenateSummary(String[] args, String finalFile){try {            int pageOffset = 0;            ArrayList master = new ArrayList();            int f = 0;            String outFile = finalFile;            Document document = null;            PdfCopy  writer = null;            while (f < args.length) {                // we create a reader for a certain document                PdfReader reader = new PdfReader(args[f]);                reader.consolidateNamedDestinations();                // we retrieve the total number of pages                int n = reader.getNumberOfPages();                List bookmarks = SimpleBookmark.getBookmark(reader);                if (bookmarks != null) {                    if (pageOffset != 0)                        SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null);                    master.addAll(bookmarks);                }                pageOffset += n;                                if (f == 0) {                    // step 1: creation of a document-object                    document = new Document(reader.getPageSizeWithRotation(1));                    // step 2: we create a writer that listens to the document                    writer = new PdfCopy(document, new FileOutputStream(outFile));                    // step 3: we open the document                    document.open();                }                // step 4: we add content                PdfImportedPage page;                for (int i = 0; i < n; ) {                    ++i;                    page = writer.getImportedPage(reader, i);                    writer.addPage(page);                }                PRAcroForm form = reader.getAcroForm();                if (form != null)                    writer.copyAcroForm(reader);                f++;            }            if (!master.isEmpty())                writer.setOutlines(master);            // step 5: we close the document            document.close();        }        catch(Exception e) {            e.printStackTrace();        }}
1 楼 ddandyy 2007-03-01 收藏了 以后或许用得着.........

嘿嘿.......... 2 楼 IvanLi 2007-03-01 我对这个也是现看的,只是把使用中发现的东西记录下来,避免以后走弯路 3 楼 hgq0011 2007-03-02 这个还是挺好用的,我一直用这来生产pdf格式的报表。 4 楼 hongliang 2007-03-03 中文正常吗? 5 楼 hgq0011 2007-03-05 hongliang 写道中文正常吗?
当然, 6 楼 gw187 2007-03-05 收藏! 7 楼 xmx111 2007-03-05 有读的没,如果文档里有图片是否也可以读出来? 8 楼 hgq0011 2007-03-07 xmx111 写道有读的没,如果文档里有图片是否也可以读出来?
这个到没有试过,一般都是写。
9 楼 hgq0011 2007-03-07 xmx111 写道有读的没,如果文档里有图片是否也可以读出来?
这个到没有试过,一般都是写。
10 楼 hgq0011 2007-03-07 xmx111 写道有读的没,如果文档里有图片是否也可以读出来?
这个到没有试过,一般都是写。
11 楼 hgq0011 2007-03-07 我的网络不好,一刷新又提交了,对不起。 12 楼 loveyeah 2007-03-23 hgq0011 写道xmx111 写道有读的没,如果文档里有图片是否也可以读出来?
这个到没有试过,一般都是写。


图片能读

读书人网 >软件架构设计

热点推荐