Example usage for com.lowagie.text.pdf PdfReader getAcroForm

List of usage examples for com.lowagie.text.pdf PdfReader getAcroForm

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfReader getAcroForm.

Prototype

public PRAcroForm getAcroForm() 

Source Link

Document

Returns the document's acroform, if it has one.

Usage

From source file:QMSMultiQuoteController.java

License:Open Source License

private byte[] concatPDF(ArrayList pdfFilesList) {
    byte[] buffer = null;
    FileOutputStream filestream = null;
    try {// w ww . j a v  a2s  . co m
        int i = 1;

        Document document = null;
        PdfCopy pdfcopy = null;

        if (pdfFilesList.size() > 1) {
            String s = (String) pdfFilesList.get(0);
            int pdfFilListSize = pdfFilesList.size();
            for (; i < pdfFilListSize; i++) {
                PdfReader pdfreader = new PdfReader((String) pdfFilesList.get(i));
                int j = pdfreader.getNumberOfPages();
                if (i == 1) {
                    document = new Document(pdfreader.getPageSizeWithRotation(1));
                    filestream = new FileOutputStream(s);
                    pdfcopy = new PdfCopy(document, filestream);
                    document.open();
                }
                PdfImportedPage pdfimportedpage = null;
                for (int k = 0; k < j;) {
                    k++;
                    pdfimportedpage = pdfcopy.getImportedPage(pdfreader, k);
                    if (pdfimportedpage != null) {
                        pdfcopy.addPage(pdfimportedpage);
                    }
                }

                com.lowagie.text.pdf.PRAcroForm pracroform = pdfreader.getAcroForm();
                if (pracroform != null)
                    pdfcopy.copyAcroForm(pdfreader);
            }

            if (document != null) {
                document.close();
            }

            FileInputStream inputStream = new FileInputStream(s);
            buffer = new byte[inputStream.available()];
            inputStream.read(buffer);
        }
        // buffer  = pdfcopy.getDirectContent();

    } catch (Exception exception) {
        exception.printStackTrace();
    }
    return buffer;
}

From source file:br.gov.jfrj.itextpdf.Documento.java

License:Open Source License

public static byte[] getDocumento(ExMobil mob, ExMovimentacao mov, boolean completo, boolean estampar,
        String hash, byte[] certificado) throws Exception {
    final ByteArrayOutputStream bo2 = new ByteArrayOutputStream();
    PdfReader reader;
    int n;/*from w  w w  .jav a  2  s  .  c o  m*/
    int pageOffset = 0;
    ArrayList master = new ArrayList();
    int f = 0;
    Document document = null;
    PdfCopy writer = null;
    int nivelInicial = 0;

    // if (request.getRequestURI().indexOf("/completo/") == -1) {
    // return getPdf(docvia, mov != null ? mov : docvia.getExDocumento(),
    // mov != null ? mov.getNumVia() : docvia.getNumVia(), null,
    // null, request);
    // }

    List<ExArquivoNumerado> ans = mob.filtrarArquivosNumerados(mov, completo);

    if (!completo && !estampar && ans.size() == 1) {
        if (certificado != null) {
            CdService cdService = Service.getCdService();
            return cdService.produzPacoteAssinavel(certificado, null, ans.get(0).getArquivo().getPdf(), true,
                    ExDao.getInstance().getServerDateTime());
        } else if (hash != null) {
            // Calcula o hash do documento
            String alg = hash;
            MessageDigest md = MessageDigest.getInstance(alg);
            md.update(ans.get(0).getArquivo().getPdf());
            return md.digest();
        } else {
            return ans.get(0).getArquivo().getPdf();
        }
    }

    try {
        for (ExArquivoNumerado an : ans) {

            // byte[] ab = getPdf(docvia, an.getArquivo(), an.getNumVia(),
            // an
            // .getPaginaInicial(), an.getPaginaFinal(), request);

            String sigla = mob.getSigla();
            if (an.getArquivo() instanceof ExMovimentacao) {
                ExMovimentacao m = (ExMovimentacao) an.getArquivo();
                if (m.getExTipoMovimentacao().getId() == ExTipoMovimentacao.TIPO_MOVIMENTACAO_JUNTADA)
                    sigla = m.getExMobil().getSigla();
            } else {
                sigla = an.getMobil().getSigla();
            }

            byte[] ab = !estampar ? an.getArquivo().getPdf()
                    : stamp(an.getArquivo().getPdf(), sigla, an.getArquivo().isRascunho(),
                            an.getArquivo().isCancelado(), an.getArquivo().isSemEfeito(),
                            an.getArquivo().isInternoProduzido(), an.getArquivo().getQRCode(),
                            an.getArquivo().getMensagem(), an.getPaginaInicial(), an.getPaginaFinal(),
                            an.getOmitirNumeracao(), SigaExProperties.getTextoSuperiorCarimbo(),
                            mob.getExDocumento().getOrgaoUsuario().getDescricao());

            // we create a reader for a certain document

            reader = new PdfReader(ab);
            reader.consolidateNamedDestinations();
            // we retrieve the total number of pages
            n = reader.getNumberOfPages();
            // List bookmarks = SimpleBookmark.getBookmark(reader);
            // master.add(new Bookmark)
            // if (bookmarks != null) {
            // if (pageOffset != 0)
            // SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset,
            // null);
            // master.addAll(bookmarks);
            // }

            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, bo2);
                writer.setFullCompression();

                // writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);

                // step 3: we open the document
                document.open();

                nivelInicial = an.getNivel();
            }

            // PdfOutline root = writer.getDirectContent().getRootOutline();
            // PdfContentByte cb = writer.getDirectContent();
            // PdfDestination destination = new
            // PdfDestination(PdfDestination.FITH, position);
            // step 4: we add content
            PdfImportedPage page;
            for (int j = 0; j < n;) {
                ++j;
                page = writer.getImportedPage(reader, j);
                writer.addPage(page);
                if (j == 1) {
                    // PdfContentByte cb = writer.getDirectContent();
                    // PdfOutline root = cb.getRootOutline();
                    // PdfOutline oline1 = new PdfOutline(root,
                    // PdfAction.gotoLocalPage("1", false),"Chapter 1");

                    HashMap map = new HashMap();
                    map.put("Title", an.getNome());
                    map.put("Action", "GoTo");
                    map.put("Page", j + pageOffset + "");
                    map.put("Kids", new ArrayList());

                    ArrayList mapPai = master;
                    for (int i = 0; i < an.getNivel() - nivelInicial; i++) {
                        mapPai = ((ArrayList) ((HashMap) mapPai.get(mapPai.size() - 1)).get("Kids"));
                    }
                    mapPai.add(map);
                }

            }
            PRAcroForm form = reader.getAcroForm();
            if (form != null)
                writer.copyAcroForm(reader);

            pageOffset += n;
            f++;
        }
        if (!master.isEmpty())
            writer.setOutlines(master);

        // PdfDictionary info = writer.getInfo();
        // info.put(PdfName.MODDATE, null);
        // info.put(PdfName.CREATIONDATE, null);
        // info.put(PdfName.ID, null);

        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bo2.toByteArray();
}

From source file:com.benfante.minimark.blo.AssessmentPdfBuilder.java

License:Apache License

/**
 * Build the contatenated PDF for a list of assessments.
 *
 * @param assessments The assessments//  w  w  w.j a v a  2  s  .  c  o  m
 * @param baseUrl The base URL for retrieving images and resource. If null it will not be set.
 * @param locale The locale for producing the document. Id null, the default locale will be used.
 * @return The PDF document.
 */
public byte[] buildPdf(List<AssessmentFilling> assessments, String baseUrl, Locale locale) throws Exception {
    ByteArrayOutputStream pdfos = new ByteArrayOutputStream();
    List master = new ArrayList();
    Document document = null;
    PdfCopy writer = null;
    PdfOutline rootOutline = null;
    try {
        int f = 0;
        int pageOffset = 0;
        for (AssessmentFilling assessment : assessments) {
            // we create a reader for a certain document
            PdfReader reader = new PdfReader(buildPdf(assessment, baseUrl, locale));
            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, pdfos);
                writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
                // step 3: we open the document
                document.open();
                // initialize rootOutline for assessment bookmarks creation
                PdfContentByte cb = writer.getDirectContent();
                rootOutline = cb.getRootOutline();
            }
            // step 4: we add content
            new PdfOutline(rootOutline, new PdfDestination(PdfDestination.FIT),
                    assessment.getLastName() + " " + assessment.getFirstName());
            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++;
        }
    } finally {
        if (pdfos != null) {
            try {
                pdfos.close();
            } catch (IOException ioe) {
            }
        }
        if (!master.isEmpty()) {
            writer.setOutlines(master);
        }
        // step 5: we close the document
        if (document != null && document.isOpen()) {
            document.close();
        }
    }
    return pdfos.toByteArray();
}

From source file:com.ikon.util.PDFUtils.java

License:Open Source License

/**
 * Fill PDF form/*from w  ww. ja v  a2s  .  com*/
 */
@SuppressWarnings("rawtypes")
public static void fillForm(InputStream input, Map<String, Object> values, OutputStream output)
        throws FileNotFoundException, DocumentException, TemplateException, IOException {
    log.debug("fillForm({}, {}, {})", new Object[] { input, values, output });
    PdfReader reader = new PdfReader(input);
    PdfStamper stamper = new PdfStamper(reader, output);
    AcroFields fields = stamper.getAcroFields();
    PRAcroForm form = reader.getAcroForm();
    boolean formFlattening = false;

    if (form != null) {
        for (Iterator it = form.getFields().iterator(); it.hasNext();) {
            PRAcroForm.FieldInformation field = (PRAcroForm.FieldInformation) it.next();
            String fieldValue = fields.getField(field.getName());
            log.debug("Field: {}, Value: '{}'", field.getName(), fieldValue);

            if (fieldValue != null && !fieldValue.isEmpty()) {
                // if (values.containsKey(field.getName())) {
                String result = TemplateUtils.replace("PDF_FILL_FORM", fieldValue, values);
                log.debug("Field '{}' set to '{}' (by expression)", field.getName(), result);
                fields.setField(field.getName(), result);
                stamper.partialFormFlattening(field.getName());
                formFlattening = true;
                //} else {
                //log.warn("Field '{}' (expression ignored because not included in map)", field.getName());
                //}
            } else {
                Object value = values.get(field.getName());

                if (value != null) {
                    log.debug("Field '{}' set to '{}' (by field name)", field.getName(), value);
                    fields.setField(field.getName(), value.toString());
                    stamper.partialFormFlattening(field.getName());
                    formFlattening = true;
                } else {
                    log.warn("Field '{}' (value ignored because not included in map)", field.getName());
                }
            }
        }
    }

    stamper.setFormFlattening(formFlattening);
    stamper.close();
    reader.close();
}

From source file:com.ikon.util.PDFUtils.java

License:Open Source License

/**
 * List form fields/*  w  w  w.j  a va2  s .co  m*/
 */
@SuppressWarnings("rawtypes")
public static List<String> listFormFields(String input)
        throws FileNotFoundException, DocumentException, IOException {
    log.debug("listFormFields({})", input);
    List<String> formFields = new ArrayList<String>();
    PdfReader reader = new PdfReader(input);
    PRAcroForm form = reader.getAcroForm();

    if (form != null) {
        for (Iterator it = form.getFields().iterator(); it.hasNext();) {
            PRAcroForm.FieldInformation field = (PRAcroForm.FieldInformation) it.next();
            formFields.add(field.getName());
        }
    }

    reader.close();
    log.debug("listFormFields: {}", formFields);
    return formFields;
}

From source file:com.openkm.util.PDFUtils.java

License:Open Source License

/**
 * Fill PDF form//from   w w  w . ja  va2  s.c  o  m
 */
@SuppressWarnings("rawtypes")
public static void fillForm(InputStream input, Map<String, Object> values, OutputStream output)
        throws FileNotFoundException, DocumentException, TemplateException, IOException {
    log.debug("fillForm({}, {}, {})", new Object[] { input, values, output });
    PdfReader reader = new PdfReader(input);
    PdfStamper stamper = new PdfStamper(reader, output);
    AcroFields fields = stamper.getAcroFields();
    PRAcroForm form = reader.getAcroForm();
    boolean formFlattening = false;

    if (form != null) {
        for (Iterator it = form.getFields().iterator(); it.hasNext();) {
            PRAcroForm.FieldInformation field = (PRAcroForm.FieldInformation) it.next();
            String fieldValue = fields.getField(field.getName());
            log.debug("Field: {}, Value: '{}'", field.getName(), fieldValue);

            if (fieldValue != null && !fieldValue.isEmpty()) {
                // if (values.containsKey(field.getName())) {
                String result = TemplateUtils.replace("PDF_FILL_FORM", fieldValue, values);
                log.debug("Field '{}' set to '{}' (by expression)", field.getName(), result);
                fields.setFieldProperty(field.getName(), "textfont", getBaseFont(), null);
                fields.setField(field.getName(), result);
                stamper.partialFormFlattening(field.getName());
                formFlattening = true;
                // } else {
                // log.warn("Field '{}' (expression ignored because not included in map)", field.getName());
                // }
            } else {
                Object value = values.get(field.getName());

                if (value != null) {
                    log.debug("Field '{}' set to '{}' (by field name)", field.getName(), value);
                    fields.setFieldProperty(field.getName(), "textfont", getBaseFont(), null);
                    fields.setField(field.getName(), value.toString());
                    stamper.partialFormFlattening(field.getName());
                    formFlattening = true;
                } else {
                    log.warn("Field '{}' (value ignored because not included in map)", field.getName());
                }
            }
        }
    }

    stamper.setFormFlattening(formFlattening);
    stamper.close();
    reader.close();
}

From source file:com.sapienter.jbilling.server.invoice.PaperInvoiceBatchBL.java

License:Open Source License

/**
 * Takes a list of invoices and replaces the individual PDF files for one
 * single PDF in the destination directory.
 * @param destination//www. j  a  v a  2s. c o m
 * @param prefix
 * @param entityId
 * @param invoices
 * @throws PdfFormatException
 * @throws IOException
 */
public void compileInvoiceFiles(String destination, String prefix, Integer entityId, Integer[] invoices)
        throws DocumentException, IOException {

    String filePrefix = Util.getSysProp("base_dir") + "invoices/" + entityId + "-";
    String outFile = destination + prefix + "-batch.pdf";

    int pageOffset = 0;
    ArrayList master = new ArrayList();
    Document document = null;
    PdfCopy writer = null;
    for (int f = 0; f < invoices.length; f++) {
        // we create a reader for a certain document
        PdfReader reader = new PdfReader(filePrefix + invoices[f] + "-invoice.pdf");
        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 (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 < numberOfPages;) {
            ++i;
            page = writer.getImportedPage(reader, i);
            writer.addPage(page);
        }
        PRAcroForm form = reader.getAcroForm();
        if (form != null)
            writer.copyAcroForm(reader);

        //release and delete 
        writer.freeReader(reader);
        reader.close();
        File file = new File(filePrefix + invoices[f] + "-invoice.pdf");
        file.delete();
    }
    if (!master.isEmpty())
        writer.setOutlines(master);
    // step 5: we close the document
    if (document != null) {
        document.close();
    } else {
        LOG.warn("document == null");
    }

    LOG.debug("PDF batch file is ready " + outFile);
}

From source file:com.servoy.extensions.plugins.pdf_output.PDFProvider.java

License:Open Source License

/**
 * Combine multiple protected PDF docs into one.
 * Note: this function may fail when creating large PDF files due to lack of available heap memory. To compensate, please configure the application server with more heap memory via -Xmx parameter.
 *
 * @sample/*from  www. j a  va 2 s.c  o m*/
 * pdf_blob_column = combineProtectedPDFDocuments(new Array(pdf_blob1,pdf_blob2,pdf_blob3), new Array(pdf_blob1_pass,pdf_blob2_pass,pdf_blob3_pass));
 *
 * @param pdf_docs_bytearrays  the array of documents to combine
 * @param pdf_docs_passwords an array of passwords to use
 */
public byte[] js_combineProtectedPDFDocuments(Object[] pdf_docs_bytearrays, Object[] pdf_docs_passwords) {
    if (pdf_docs_bytearrays == null || pdf_docs_bytearrays.length == 0)
        return null;

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        int pageOffset = 0;
        List master = new ArrayList();
        Document document = null;
        PdfCopy writer = null;
        for (int f = 0; f < pdf_docs_bytearrays.length; f++) {
            if (!(pdf_docs_bytearrays[f] instanceof byte[]))
                continue;
            byte[] pdf_file = (byte[]) pdf_docs_bytearrays[f];

            // we create a reader for a certain document
            byte[] password = null;
            if (pdf_docs_passwords != null && pdf_docs_passwords.length > f && pdf_docs_passwords[f] != null) {
                if (pdf_docs_passwords[f] instanceof String)
                    password = pdf_docs_passwords[f].toString().getBytes();
            }
            PdfReader reader = new PdfReader(pdf_file, password);
            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 (writer == null) {
                // 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, baos);
                // 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);
        }
        if (writer != null && document != null) {
            if (master.size() > 0)
                writer.setOutlines(master);
            // step 5: we close the document
            document.close();
        }
        return baos.toByteArray();
    } catch (Throwable e) {
        Debug.error(e);
        throw new RuntimeException("Error combinding pdf documents: " + e.getMessage(), e); //$NON-NLS-1$
    }
}

From source file:com.silverpeas.importExport.control.ImportExport.java

License:Open Source License

/**
 * @param userDetail/*from   w ww .  jav a  2 s . co m*/
 * @param itemsToExport
 * @return
 * @throws ImportExportException
 */
public ExportPDFReport processExportPDF(UserDetail userDetail, List<WAAttributeValuePair> itemsToExport,
        NodePK rootPK) throws ImportExportException {
    ExportPDFReport report = new ExportPDFReport();
    report.setDateDebut(new Date());

    PublicationsTypeManager pubTypeManager = new PublicationsTypeManager();

    String fileExportName = generateExportDirName(userDetail, "fusion");
    String tempDir = FileRepositoryManager.getTemporaryPath();

    File fileExportDir = new File(tempDir + fileExportName);
    if (!fileExportDir.exists()) {
        try {
            FileFolderManager.createFolder(fileExportDir);
        } catch (UtilException ex) {
            throw new ImportExportException("ImportExport", "importExport.EX_CANT_CREATE_FOLDER", ex);
        }
    }

    File pdfFileName = new File(tempDir + fileExportName + ".pdf");
    try {
        // cration des rpertoires avec le nom des thmes et des publications
        List<AttachmentDetail> pdfList = pubTypeManager.processPDFExport(report, userDetail, itemsToExport,
                fileExportDir.getPath(), true, rootPK);

        try {
            int pageOffset = 0;
            List master = new ArrayList();
            Document document = null;
            PdfCopy writer = null;

            if (!pdfList.isEmpty()) {
                boolean firstPage = true;
                for (AttachmentDetail attDetail : pdfList) {
                    PdfReader reader = null;
                    try {
                        reader = new PdfReader(
                                fileExportDir.getPath() + File.separatorChar + attDetail.getLogicalName());
                    } catch (IOException ioe) {
                        // Attached file is not physically present on disk, ignore it and log event
                        SilverTrace.error("importExport", "PublicationTypeManager.processExportPDF",
                                "CANT_FIND_PDF_FILE",
                                "PDF file '" + attDetail.getLogicalName() + "' is not present on disk", ioe);
                    }
                    if (reader != null) {
                        reader.consolidateNamedDestinations();
                        int nbPages = reader.getNumberOfPages();
                        List bookmarks = SimpleBookmark.getBookmark(reader);
                        if (bookmarks != null) {
                            if (pageOffset != 0) {
                                SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null);
                            }
                            master.addAll(bookmarks);
                        }
                        pageOffset += nbPages;

                        if (firstPage) {
                            document = new Document(reader.getPageSizeWithRotation(1));
                            writer = new PdfCopy(document, new FileOutputStream(pdfFileName));
                            document.open();
                            firstPage = false;
                        }

                        for (int i = 1; i <= nbPages; i++) {
                            try {
                                PdfImportedPage page = writer.getImportedPage(reader, i);
                                writer.addPage(page);
                            } catch (Exception e) {
                                // Can't import PDF file, ignore it and log event
                                SilverTrace.error("importExport", "PublicationTypeManager.processExportPDF",
                                        "CANT_MERGE_PDF_FILE", "PDF file is " + attDetail.getLogicalName(), e);
                            }
                        }

                        PRAcroForm form = reader.getAcroForm();
                        if (form != null) {
                            writer.copyAcroForm(reader);
                        }
                    }
                }

                if (!master.isEmpty()) {
                    writer.setOutlines(master);
                }
                writer.flush();
                document.close();
            } else {
                return null;
            }

        } catch (BadPdfFormatException e) {
            // Erreur lors de la copie
            throw new ImportExportException("ImportExport", "root.EX_CANT_WRITE_FILE", e);
        } catch (DocumentException e) {
            // Impossible de copier le document
            throw new ImportExportException("ImportExport", "root.EX_CANT_WRITE_FILE", e);
        }

    } catch (IOException e) {
        // Pb avec le rpertoire de destination
        throw new ImportExportException("ImportExport", "root.EX_CANT_WRITE_FILE", e);
    }

    report.setPdfFileName(pdfFileName.getName());
    report.setPdfFileSize(pdfFileName.length());
    report.setPdfFilePath(FileServerUtils.getUrlToTempDir(pdfFileName.getName()));

    report.setDateFin(new Date());

    return report;
}

From source file:lucee.runtime.text.pdf.PDFUtil.java

License:Open Source License

/**
 * @param docs/*  ww w.ja v a 2  s . c  o m*/
 * @param os
 * @param removePages if true, pages defined in PDFDocument will be removed, otherwise all other pages will be removed
 * @param version 
 * @throws PageException 
 * @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 != 0)
                    SimpleBookmark.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);
    }
}