Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfCopy$IndirectReferences


      if (getValue("destfile") == null) throw new InstantiationException("You need to choose a destination file");
      File pdf_file = (File)getValue("destfile");
            int pageOffset = 0;
            List<HashMap<String, Object>> master = new ArrayList<HashMap<String, Object>>();
            Document document = null;
            PdfCopy  writer = null;
            for (int i = 0; i < 2; i++) {
              // we create a reader for a certain document
                PdfReader reader = new PdfReader(files[i]);
                reader.consolidateNamedDestinations();
                // we retrieve the total number of pages
                int n = reader.getNumberOfPages();
                List<HashMap<String, Object>> bookmarks = SimpleBookmark.getBookmark(reader);
                if (bookmarks != null) {
                    if (pageOffset != 0)
                        SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null);
                    master.addAll(bookmarks);
                }
                pageOffset += n;
                System.out.println("There are " + n + " pages in " + files[i]);
                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, new FileOutputStream(pdf_file));
                    // step 3: we open the document
                    document.open();
                }
                // step 4: we add content
                PdfImportedPage page;
                for (int p = 0; p < n; ) {
                    ++p;
                    page = writer.getImportedPage(reader, p);
                    writer.addPage(page);
                    System.out.println("Processed page " + p);
                }
            }
            if (!master.isEmpty())
                writer.setOutlines(master);
            // step 5: we close the document
            document.close();
    }
    catch(Exception e) {
            e.printStackTrace();
View Full Code Here


      System.out.println("The original file had " + reader.getNumberOfPages() + " pages.");
      reader.selectPages(selection);
      int pages = reader.getNumberOfPages();
      System.err.println("The new file has " + pages + " pages.");
      Document document = new Document(reader.getPageSizeWithRotation(1));
      PdfCopy copy = new PdfCopy(document, new FileOutputStream(dest.getAbsolutePath()));
      document.open();
            PdfImportedPage page;
            for (int i = 0; i < pages; ) {
                ++i;
                System.out.println("Processed page " + i);
                page = copy.getImportedPage(reader, i);
                copy.addPage(page);
            }
            PRAcroForm form = reader.getAcroForm();
      if (form != null)
                copy.copyAcroForm(reader);
      document.close();
        }
        catch(Exception e) {
            e.printStackTrace();
        }
View Full Code Here

            }
            File pdf_file = (File) getValue("destfile");
            int pageOffset = 0;
            ArrayList<HashMap<String, Object>> master = new ArrayList<HashMap<String, Object>>();
            Document document = null;
            PdfCopy writer = null;
            for (int i = 0; i < files.length; i++) {
                // we create a reader for a certain document
                PdfReader reader = new PdfReader(files[i].getAbsolutePath());
                reader.consolidateNamedDestinations();
                // we retrieve the total number of pages
                int n = reader.getNumberOfPages();
                List<HashMap<String, Object>> bookmarks = SimpleBookmark.getBookmark(reader);
                if (bookmarks != null) {
                    if (pageOffset != 0) {
                        SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null);
                    }
                    master.addAll(bookmarks);
                }
                pageOffset += n;
                System.out.println("There are " + n + " pages in " + files[i]);
                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,
                                         new FileOutputStream(pdf_file));
                    // step 3: we open the document
                    document.open();
                }
                // step 4: we add content
                PdfImportedPage page;
                for (int p = 0; p < n; ) {
                    ++p;
                    page = writer.getImportedPage(reader, p);
                    writer.addPage(page);
                    System.out.println("Processed page " + p);
                }
            }
            if (!master.isEmpty()) {
                writer.setOutlines(master);
            }
            // step 5: we close the document
            document.close();
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

                int pageOffset = 0;
                ArrayList master = new ArrayList();
                int f = 0;
                String outFile = args[args.length-1];
                Document document = null;
                PdfCopy  writer = null;
                while (f < args.length-1) {
                    // 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;
                    System.out.println("There are " + n + " pages in " + args[f]);
                   
                    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);
                        System.out.println("Processed page " + i);
                    }
                    writer.freeReader(reader);
                    f++;
                }
                if (!master.isEmpty())
                    writer.setOutlines(master);
                // step 5: we close the document
                document.close();
            }
            catch(Exception e) {
                e.printStackTrace();
View Full Code Here

     
      // collect together
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      com.lowagie.text.Document document =
        new com.lowagie.text.Document(pdfReaders[0].getPageSizeWithRotation(1));
      PdfCopy copy = new PdfCopy(document,baos);
      document.open();
      String name;
      ArrayList bookmarks=doBookmarks?new ArrayList():null;
      try {
        int size,totalPage=0;
        Map parent;
        for(int doc=0;doc<pdfReaders.length;doc++) {
          size=pdfReaders[doc].getNumberOfPages();
         
          PdfImportedPage ip;
         
          // bookmarks
          if(doBookmarks) {
            name=pdfDocs[doc].getName();
            if(!StringUtil.isEmpty(name)) {
              bookmarks.add(parent=PDFUtil.generateGoToBookMark(name, totalPage+1));
            }
            else parent=null;
           
            if(doHtmlBookmarks) {
              java.util.List pageBM = SimpleBookmark.getBookmark(pdfReaders[doc]);
              if(pageBM!=null) {
                if(totalPage>0)SimpleBookmark.shiftPageNumbers(pageBM, totalPage, null);
                if(parent!=null)PDFUtil.setChildBookmarks(parent,pageBM);
                else bookmarks.addAll(pageBM);
              }
            }
          }
         
          totalPage++;
          for(int page=1;page<=size;page++) {
            if(page>1)totalPage++;
            ip = copy.getImportedPage(pdfReaders[doc], page);
           
            //ip.getPdfDocument().setHeader(arg0);
            //ip.getPdfDocument().setFooter(arg0);
            copy.addPage(ip);
          }
        }
        if (doBookmarks && !bookmarks.isEmpty())copy.setOutlines(bookmarks);
      }
      finally {
        document.close();
      }
      pdf=baos.toByteArray();
    }
    else if(documents.size()==1){
      pdf=(documents.get(0)).render(getDimension(),unitFactor,pageContext,doHtmlBookmarks);
    }
    else {
      pdf=getDocument().render(getDimension(),unitFactor,pageContext,doHtmlBookmarks);
    }
   
    // permission/encryption
    if(PDFDocument.ENC_NONE!=encryption) {
      PdfReader reader = new PdfReader(pdf);
      com.lowagie.text.Document document = new com.lowagie.text.Document(reader.getPageSize(1));
      document.addCreator("Railo "+Info.getVersionAsString()+" "+Info.getStateAsString());
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      PdfCopy copy = new PdfCopy(document,baos);
      //PdfWriter writer = PdfWriter.getInstance(document, pdfOut);
      copy.setEncryption(PDFDocument.ENC_128BIT==encryption , userpassword , ownerpassword , permissions);
      document.open();
      int size=reader.getNumberOfPages();
      for(int page=1;page<=size;page++) {
        copy.addPage(copy.getImportedPage(reader, page));
      }
      document.close();
      pdf=baos.toByteArray();
    }
   
View Full Code Here

                int pageOffset = 0;
                ArrayList master = new ArrayList();
                int f = 0;
                String outFile = args[args.length-1];
                Document document = null;
                PdfCopy  writer = null;
                while (f < args.length-1) {
                    // 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;
                    System.out.println("There are " + n + " pages in " + args[f]);
                   
                    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);
                        System.out.println("Processed page " + i);
                    }
                    writer.freeReader(reader);
                    f++;
                }
                if (!master.isEmpty())
                    writer.setOutlines(master);
                // step 5: we close the document
                document.close();
            }
            catch(Exception e) {
                e.printStackTrace();
View Full Code Here

   * @throws IOException
   * @throws DocumentException
   */
  public static void concat(PDFDocument[] docs,OutputStream os, boolean keepBookmark,boolean removePages, boolean stopOnError, char version) throws PageException, IOException, DocumentException {
    Document document = null;
    PdfCopy  writer = null;
    PdfReader reader;
    Set pages;
    boolean isInit=false;
    PdfImportedPage page;
    try {
      int pageOffset = 0;
      ArrayList master = new ArrayList();
     
      for(int i=0;i<docs.length;i++) {
        // we create a reader for a certain document
        pages = docs[i].getPages();
        try {
          reader = docs[i].getPdfReader();
        }
        catch(Throwable t) {
          if(!stopOnError)continue;
          throw Caster.toPageException(t);
        }
        reader.consolidateNamedDestinations();
       
        // we retrieve the total number of pages
        int n = reader.getNumberOfPages();
        List bookmarks = keepBookmark?SimpleBookmark.getBookmark(reader):null;
        if (bookmarks != null) {
          removeBookmarks(bookmarks,pages,removePages);
          if (pageOffset != 0SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null)
          master.addAll(bookmarks);
        }
       
        if (!isInit) {
          isInit=true;
          document = new Document(reader.getPageSizeWithRotation(1));
          writer = new PdfCopy(document, os);
         
          if(version!=0)writer.setPdfVersion(version);
         
         
          document.open();
        }
       
       
        for (int y = 1; y <= n; y++) {
          if(pages!=null && removePages==pages.contains(Integer.valueOf(y))){
            continue;
          }
          pageOffset++;
          page = writer.getImportedPage(reader, y);
          writer.addPage(page);
        }
        PRAcroForm form = reader.getAcroForm();
        if (form != null)
          writer.copyAcroForm(reader);
      }
      if (master.size() > 0)
        writer.setOutlines(master);
     
    }
    finally {
      IOUtil.closeEL(document);
    }
View Full Code Here

    PdfReader pr = doc.getPdfReader();
    List bookmarks = SimpleBookmark.getBookmark(pr);
    int n = pr.getNumberOfPages();
   
    Document document = new Document(pr.getPageSizeWithRotation(1));
    PdfCopy writer = new PdfCopy(document, os);
    if(encryption!=ENCRYPT_NONE)writer.setEncryption(user, owner, permissions, encryption);
    document.open();
   
   
    PdfImportedPage page;
    for (int i = 1; i <= n; i++) {
      page = writer.getImportedPage(pr, i);
      writer.addPage(page);
    }
    PRAcroForm form = pr.getAcroForm();
    if (form != null)writer.copyAcroForm(pr);
    if (bookmarks!=null)writer.setOutlines(bookmarks);
    document.close();
  }
View Full Code Here

      String filename = "";
      Report outFile = null;
      if (reports.length == 1)
        filename = reports[0].getFilename();
      Document document = null;
      PdfCopy writer = null;
      while (f < reports.length) {
        if (filename == null || filename.equals("")) {
          outFile = reports[f];
          if (multiReports) {
            filename = outFile.getTemplateInfo().getReportFilename();
            filename = filename.replaceAll("@our_ref@", "");
            filename = filename.replaceAll("@cus_ref@", "");
            filename = filename.replaceAll(" ", "_");
            filename = filename.replaceAll("-", "");
            filename = filename + ".pdf";
          } else {
            filename = outFile.getFilename();
          }
        }
        response.setHeader("Content-disposition", "attachment" + "; filename=" + filename);
        // we create a reader for a certain document
        PdfReader reader = new PdfReader(reports[f].getTargetLocation());
        reader.consolidateNamedDestinations();
        // we retrieve the total number of pages
        int n = reader.getNumberOfPages();
        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, response.getOutputStream());
          // 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);
        }
        if (reports[f].isDeleteable()) {
          File file = new File(reports[f].getTargetLocation());
          if (file.exists() && !file.isDirectory()) {
            file.delete();
View Full Code Here

                int pageOffset = 0;
                ArrayList master = new ArrayList();
                int f = 0;
                String outFile = args[args.length-1];
                Document document = null;
                PdfCopy  writer = null;
                while (f < args.length-1) {
                    // 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();
View Full Code Here

TOP

Related Classes of com.lowagie.text.pdf.PdfCopy$IndirectReferences

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.