itext pdf 分页

            String filePath = "D:/test.pdf"

            int pageOffset = 0;
            ArrayList master = new ArrayList();
            Document document = null;
            PdfCopy writer = null;
           
            File file = new File(filePath);     
            FileOutputStream out = new FileOutputStream(file);
           
            for (int i = 0; i < receivingNo.size(); i++) {
             InventoryOrderListReport report = new InventoryOrderListReport();
             
             //start set report title values
          List<String> titleValue=new ArrayList<String>();
          if(searchBean.getTermianId()!=null&&!searchBean.getTermianId().trim().equals("")){
              SecuOptUnitBean optUnitBean=systemLocalService.getSecuOptUnitBean(searchBean.getTermianId());
              titleValue.add(optUnitBean==null?termialBlank:optUnitBean.getOptUnitName());
              titleValue.add(searchBean.getTermianId());
          }else{
           titleValue.add("ALL");
           titleValue.add("ALL");
          }
          
          if(searchBean.getClientCode().split(",").length>1){   
           titleValue.add("ALL");
          }else{
           String clientName=systemLocalService.getClientCompanyName(
             searchBean.getTermianId(), searchBean.getClientCode());
           titleValue.add(clientName);
          }
             
             titleValue.add(receivingNo.get(i));
          report.setTitleValue(titleValue);
          report.setTableValue(result);
          
                // we create a reader for a certain document
                byte[] resultPdf = report.runReport();
               
                PdfReader reader = new PdfReader(resultPdf);
                reader.consolidateNamedDestinations();
                // we retrieve the total number of pages
                int numberOfPages = reader.getNumberOfPages();
                List bookmarks = SimpleBookmark.getBookmark(reader);
                if (bookmarks != null) {
                    if (pageOffset != 0) {
                        SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null);
                    }
                    master.addAll(bookmarks);
                }
                pageOffset += numberOfPages;
                if (i == 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, out);
                    // step 3: we open the document
                    document.open();
                }
                // step 4: we add content
                PdfImportedPage page;
                for (int index = 1; index <= numberOfPages; index++) {
                    page = writer.getImportedPage(reader, index);
                    writer.addPage(page);
                }
                writer.freeReader(reader);
            }
            if (master.size() > 0) {
                writer.setOutlines(master);
            }
            // step 5: we close the document
            document.close();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值