Example usage for com.lowagie.text Document open

List of usage examples for com.lowagie.text Document open

Introduction

In this page you can find the example usage for com.lowagie.text Document open.

Prototype

boolean open

To view the source code for com.lowagie.text Document open.

Click Source Link

Document

Is the document open or not?

Usage

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

public int writeBulkPDF(Collection messages, User performer, String fileName, Locale locale, String type,
        boolean areAddressMessages, boolean flagMessages, boolean registerBulkData) {
    int fileId = -1;
    try {/*ww  w .j a v a2 s  .  co  m*/
        Iterator iter = messages.iterator();
        PrintMessage msg = null;
        PdfTemplate template = null;
        if (registerBulkData) {
            MemoryFileBuffer outerBuf = new MemoryFileBuffer();
            OutputStream outerDocOS = new MemoryOutputStream(outerBuf);
            InputStream outerDocIS = new MemoryInputStream(outerBuf);
            Document outerDocument = getLetterDocumentTemplate();
            PdfWriter writer = PdfWriter.getInstance(outerDocument, outerDocOS);
            outerDocument.open();

            ICFile bulkFile = getICFileHome().create();
            bulkFile.store();

            if (!areAddressMessages) {
                template = getLetterTemplate(type, writer);
            }
            int contentReturn = 0;
            int lettersProcessed = 0;
            DocumentPrintContext dpc = new DocumentPrintContext();
            dpc.setLocale(locale);
            dpc.setDocument(outerDocument);
            dpc.setPdfWriter(writer);
            dpc.setIWApplicationContext(getIWApplicationContext());
            while (iter.hasNext()) {
                msg = (PrintMessage) iter.next();
                dpc.setMessage(msg);
                if (!areAddressMessages) {
                    addTemplateToPage(template, writer, type);
                }
                // contentReturn = createContent(outerDocument, msg,
                // performer,writer,locale);
                // contentReturn = createContent(dpc);
                createHandlerContent(dpc);

                // System.err.println("letter content returns : "+contentReturn+" for
                // msg: "+msg.getPrimaryKey().toString());
                if (contentReturn != ADDRESS_ERROR) {
                    outerDocument.newPage();
                    try {
                        // System.err.println("bulk id =
                        // "+bulkFile.getPrimaryKey().toString());
                        msg.setMessageBulkData(bulkFile);

                        if (areAddressMessages) {
                            writePDF(msg, performer, fileName, locale, flagMessages);
                        } else if (flagMessages) {
                            getMessageBusiness().flagMessageAsPrinted(performer, msg);
                        } else {
                            msg.store();
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                    lettersProcessed++;
                }
            }

            outerDocument.close();
            if (lettersProcessed > 0) {
                if (registerBulkData) {
                    bulkFile.setFileValue(outerDocIS);
                    bulkFile.setMimeType(MimeTypeUtil.MIME_TYPE_PDF_2);
                    bulkFile.setName(fileName + ".pdf");
                    bulkFile.setFileSize(outerBuf.length());
                    bulkFile.store();
                    PrintDocuments pdocs = getPrintDocumentsHome().create();
                    pdocs.setDocument(bulkFile);
                    pdocs.setNumberOfSubDocuments(lettersProcessed);
                    pdocs.setCreator(performer);
                    pdocs.setType(type);
                    pdocs.store();
                    fileId = pdocs.getDocumentFileID();
                }
            }
            try {
                outerDocOS.close();
                outerDocIS.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else {
            while (iter.hasNext()) {
                msg = (PrintMessage) iter.next();
                writePDF(msg, performer, fileName, locale, flagMessages);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return fileId;
}

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

public int writePDF(PrintMessage msg, User performer, String fileName, Locale locale, boolean flagPrinted)
        throws Exception {
    MemoryFileBuffer buffer = new MemoryFileBuffer();
    OutputStream mos = new MemoryOutputStream(buffer);
    InputStream mis = new MemoryInputStream(buffer);
    Document document = getLetterDocumentTemplate();

    PdfWriter writer = PdfWriter.getInstance(document, mos);

    document.open();
    document.newPage();/* ww  w .j  a  v a2s. co  m*/

    DocumentPrintContext dpc = new DocumentPrintContext();
    dpc.setDocument(document);
    dpc.setPdfWriter(writer);
    dpc.setUser(performer);
    dpc.setLocale(locale);
    dpc.setMessage(msg);
    dpc.setIWApplicationContext(getIWApplicationContext());

    // int contentReturn = createContent(document, msg,
    // performer,writer,locale);

    // int contentReturn = createContent(dpc);
    createHandlerContent(dpc);

    /*
     * if(contentReturn==ADDRESS_ERROR){ document.close(); try { mos.close(); mis.close(); } catch (Exception ex) { } return -1; }
     */
    document.close();
    ICFile file = getICFileHome().create();

    if (!fileName.endsWith(".pdf") && !fileName.endsWith(".PDF")) {
        fileName += ".pdf";
    }

    /* *** writing pdf to cachefolder manually */
    String folder = getIWApplicationContext().getIWMainApplication()
            .getRealPath(getIWApplicationContext().getIWMainApplication().getCacheDirectoryURI() + "/prints");
    java.io.File tfile = com.idega.util.FileUtil.getFileAndCreateIfNotExists(folder, fileName);
    java.io.FileOutputStream fos = new java.io.FileOutputStream(tfile);
    java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
    while (mis.available() > 0) {
        baos.write(mis.read());
    }
    baos.writeTo(fos);
    baos.flush();
    baos.close();
    mis.reset();

    file.setFileValue(mis);
    file.setMimeType(MimeTypeUtil.MIME_TYPE_PDF_2);
    file.setName(fileName);
    file.setFileSize(buffer.length());
    file.store();
    msg.setMessageData(file);
    try {
        if (flagPrinted) {
            getMessageBusiness().flagMessageAsPrinted(performer, msg);
        } else {
            msg.store();
        }
        return msg.getMessageDataFileID();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    try {
        mos.close();
        mis.close();
    } catch (Exception ex) {
    }
    return -1;

}

From source file:is.idega.idegaweb.egov.printing.business.DocumentServiceBean.java

License:Open Source License

/**
 * Creates a pdf letter from a template which is chosen from the message type. Returns a primaryKey to a file in database
 *//*from   w w w .ja  va  2s  . c om*/
public Integer createPDF(IWUserContext iwuc, Collection msgs, String type, String fileName,
        boolean flagPrinted) {
    OutputStream outerOs = null;
    InputStream outerIs = null;
    try {
        MemoryFileBuffer outerBuf = new MemoryFileBuffer();
        outerOs = new MemoryOutputStream(outerBuf);
        outerIs = new MemoryInputStream(outerBuf);

        //
        // step 1: creation of a document-object
        Document document = new Document();
        // step 2: we create a writer that listens to the document
        PdfCopy writer = new PdfCopy(document, outerOs);
        // step 3: we open the document
        document.open();

        ICFile bulkFile = getICFileHome().create();
        bulkFile.store();

        PrintingService pserv = getPrintingService();

        CommuneMessageBusiness msgBuiz = getMessageService();
        int lettersProcessed = 0;
        for (Iterator iter = msgs.iterator(); iter.hasNext();) {
            PrintMessage msg = (PrintMessage) iter.next();
            MemoryFileBuffer buffer = new MemoryFileBuffer();
            OutputStream mos = new MemoryOutputStream(buffer);
            InputStream mis = new MemoryInputStream(buffer);

            PrintingContext pcx = getPrintingContext(iwuc, msg);
            if (pcx != null) {
                pcx.setDocumentStream(mos);
                pserv.printDocument(pcx);

                PdfReader reader = new PdfReader(buffer.buffer());
                PdfImportedPage page;
                int n = reader.getNumberOfPages();
                for (int i = 0; i < n;) {
                    ++i;
                    page = writer.getImportedPage(reader, i);
                    writer.addPage(page);
                }
                lettersProcessed++;
                storeStreamToICFile(iwuc, msgBuiz, msg, mis, fileName, buffer.length(), flagPrinted);
                msg.setMessageBulkData(bulkFile);
                msg.store();
            }
        }
        document.close();
        bulkFile = createFile(bulkFile, fileName, outerIs, outerBuf.length());

        PrintDocuments pdocs = getPrintDocumentsHome().create();
        pdocs.setDocument(bulkFile);
        pdocs.setNumberOfSubDocuments(lettersProcessed);
        pdocs.setCreator(iwuc.getCurrentUser());
        pdocs.setType(type);
        pdocs.store();

        return (Integer) bulkFile.getPrimaryKey();
    } catch (Exception e) {
        e.printStackTrace();
        throw new ContentCreationException(e);
    } finally {
        try {
            outerOs.close();
            outerIs.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

From source file:ispyb.client.biosaxs.pdf.DataAcquisitionPDFReport.java

License:Open Source License

private ByteArrayOutputStream exportAsPdf(Experiment3VO experiment, List<Buffer3VO> buffers,
        Proposal3VO proposal) throws Exception {
    Document document = new Document(PageSize.A4.rotate(), 10, 10, 20, 20);

    document.addTitle("exportSamplesView");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);
    HeaderFooter header = new HeaderFooter(
            new Phrase(proposal.getTitle() + " " + proposal.getCode() + proposal.getNumber()), false);

    header.setAlignment(Element.ALIGN_CENTER);
    header.getBefore().getFont().setSize(8);
    HeaderFooter footer = new HeaderFooter(new Phrase("Page n."), true);
    footer.setAlignment(Element.ALIGN_RIGHT);
    footer.setBorderWidth(1);/*from  w  ww. ja va2 s  .com*/
    footer.getBefore().getFont().setSize(6);

    document.setHeader(header);
    document.setFooter(footer);

    document.open();

    BaseFont bf = BaseFont.createFont(FONTS[0][0], FONTS[0][1], BaseFont.EMBEDDED);
    Font font = new Font(bf, 6);
    document.add(new Paragraph("Data Acquisition: " + experiment.getName(), font));
    document.add(new Paragraph("Type: " + experiment.getType(), font));
    document.add(new Paragraph("Date: " + experiment.getCreationDate(), font));
    document.add(new Paragraph("Proposal: " + proposal.getCode() + proposal.getNumber(), font));
    document.add(new Paragraph("Title: " + proposal.getTitle(), font));

    document.add(new Paragraph(" "));
    document.add(new Paragraph("Measurements", PdfRtfExporter.FONT_DOC_BOLD));
    document.add(new Paragraph(" "));
    document.add(this.getMeasurementTable(experiment, buffers));
    document.newPage();
    document.add(new Paragraph(" "));
    document.add(new Paragraph("Analysis", PdfRtfExporter.FONT_DOC_BOLD));
    document.add(new Paragraph(" "));
    document.add(this.getAnalysis(experiment, buffers));
    document.newPage();
    document.add(this.getImageTable(experiment, buffers));

    document.close();
    return baos;
}

From source file:ispyb.client.mx.collection.PdfRtfExporter.java

License:Open Source License

/**
 * export datacollection report//from  w w w. ja v  a2s.  c o  m
 * 
 * @param rtfFormat
 * @return
 * @throws Exception
 */
public ByteArrayOutputStream exportDataCollectionReport(boolean rtfFormat) throws Exception {
    // create simple doc and write to a ByteArrayOutputStream
    Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if (!rtfFormat) {
        PdfWriter.getInstance(document, baos);
    } else {
        RtfWriter2.getInstance(document, baos);
    }

    // =============================
    // Header + footer
    // =============================

    setHeader(document);
    setFooter(document);
    document.open();

    // ===============================
    // Body
    // ===============================
    // Crystallographer added only for IFX proposal in case of MXPress
    // experiment
    setCrystallographer(document);
    // Session comments
    setSessionComments(document);
    // session title& info
    setSessionTable(document);

    // ======================
    // Data Collection table
    // ======================
    document.add(new Paragraph(" "));
    setDataCollectionTable(document);

    // ======================
    // Energy scans
    // ======================
    document.add(new Paragraph(" "));
    setEnergyScansTable(document);

    // ======================
    // XRF Spectra
    // ======================
    document.add(new Paragraph(" "));
    setXfrSpectraTable(document);

    // ======================
    // Summary
    // ======================
    setSummary(document);

    // ======================
    // End of file
    // ======================
    document.close();
    return baos;

}

From source file:ispyb.client.mx.collection.PdfRtfExporter.java

License:Open Source License

/**
 * export detailed dataCollection//from   w  w  w  .j av  a2  s .co  m
 * 
 * @return
 * @throws Exception
 */
public ByteArrayOutputStream exportScreeningAsPDF(boolean rtfFormat, HttpServletRequest mRequest)
        throws Exception {
    // create simple doc and write to a ByteArrayOutputStream
    Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if (!rtfFormat) {
        PdfWriter.getInstance(document, baos);
    } else {
        RtfWriter2.getInstance(document, baos);
    }

    // =============================
    // Header + footer
    // =============================

    setHeader(document);
    setFooter(document);
    document.open();

    // ===============================
    // Body
    // ===============================
    // Session comments
    setSessionComments(document);
    document.add(new Paragraph(" "));
    if (dataCollectionList.isEmpty()) {
        document.add(new Paragraph("There is no data collection in this report", PdfRtfExporter.FONT_DOC));
    } else {
        Iterator<DataCollection3VO> it = dataCollectionList.iterator();
        Session3Service sessionService = (Session3Service) ejb3ServiceLocator
                .getLocalService(Session3Service.class);
        AutoProc3VO[] autoProcs = wrapper.getAutoProcs();
        AutoProcScalingStatistics3VO[] autoProcsOverall = wrapper.getScalingStatsOverall();
        AutoProcScalingStatistics3VO[] autoProcsInner = wrapper.getScalingStatsInner();
        AutoProcScalingStatistics3VO[] autoProcsOuter = wrapper.getScalingStatsOuter();
        int i = 0;
        // int mNbDataCollectionOnPage = 0;
        boolean firstPage = true;
        while (it.hasNext()) {
            if (firstPage) {
                firstPage = false;
            } else {
                document.newPage();
            }
            DataCollection3VO dcValue = it.next();
            DataCollectionExporter dcExporter = new DataCollectionExporter(df2, df3, proposalCode,
                    proposalNumber, mRequest);
            DataCollectionInformation dcInfo = dcExporter.getDataCollectionInformation(dcValue,
                    getSampleRankingVO(dcValue.getDataCollectionId()),
                    getAutoProcRankingVO(dcValue.getDataCollectionId()));
            // dataCollection general info: Date, screen/Collect, indexing
            // status
            setDataCollectionGeneralInfo(document, dcValue, dcInfo);
            Table table = new Table(NB_COL_DATACOLLECTION);
            table.setCellsFitPage(true);
            // dataCollection table - one row
            table = setDataCollectionHeader(document, table, true);
            setDataCollectionData(document, table, dcValue, sessionService, autoProcs[i], autoProcsOverall[i],
                    autoProcsInner[i], autoProcsOuter[i], true, false, null, null);
            document.add(table);
            i++;
            document.add(new Paragraph(" ", VERY_SMALL_FONT));
            // Images
            setImagesTable(document, dcInfo);
            setEDNATable(document, dcInfo);
            setStrategyTable(document, dcInfo);
            // End of the page?
            // mNbDataCollectionOnPage++;
            // if (mNbDataCollectionOnPage ==
            // NB_DATA_COLLECTION_PER_PAGE){// New Page
            // document.newPage();
            // mNbDataCollectionOnPage = 0;
            // } else{ // Same Page
            // document.add(new Paragraph(" ", VERY_SMALL_FONT));
            // }
        }
    }

    // ======================
    // End of file
    // ======================
    document.close();
    return baos;
}

From source file:ispyb.client.mx.collection.PdfRtfExporter.java

License:Open Source License

/**
 * export detailed dataCollection report: new screening report
 * /*from www . j  a  v a2  s. co m*/
 * @return
 * @throws Exception
 */
public ByteArrayOutputStream exportDetails(boolean rtfFormat, HttpServletRequest mRequest) throws Exception {
    // create simple doc and write to a ByteArrayOutputStream
    Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if (!rtfFormat) {
        PdfWriter.getInstance(document, baos);
    } else {
        RtfWriter2.getInstance(document, baos);
    }

    // =============================
    // Header + footer
    // =============================

    setHeaderForDetails(document);
    setFooter(document);
    document.open();

    // ===============================
    // Body
    // ===============================
    // Session comments
    setSessionComments(document);
    document.add(new Paragraph(" "));
    // build the list with the collect and collects group by workflow +
    // energyScan+ XRFSpectra
    // this list is sorted by time
    List<SessionDataObjectInformation> listSessionDataObject = sessionDataObjectList;
    if (listSessionDataObject.isEmpty()) {
        document.add(new Paragraph("There is no data in this report", PdfRtfExporter.FONT_DOC));
    } else {
        // for each object, we will display a different table
        int countTables = 0;
        for (Iterator<SessionDataObjectInformation> iterator = listSessionDataObject.iterator(); iterator
                .hasNext();) {
            SessionDataObjectInformation sessionDataObject = (SessionDataObjectInformation) iterator.next();
            if (countTables > 1) {
                // System.out.println("page break");
                document.newPage();
                countTables = 0;
            }
            setDetailSessionObjectTable(document, sessionDataObject, mRequest);
            countTables++;
        }
    }

    // ======================
    // End of file
    // ======================
    document.close();
    return baos;
}

From source file:ispyb.client.mx.collection.PdfRtfExporter.java

License:Open Source License

/**
 * export ranking dataCollection//from   w ww.  ja  va2 s.  c  o m
 * 
 * @return
 * @throws Exception
 */
public ByteArrayOutputStream exportRankingAsPDF(boolean rtfFormat, HttpServletRequest mRequest)
        throws Exception {
    // create simple doc and write to a ByteArrayOutputStream
    Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);
    // Document document = new Document(PageSize.A4);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if (!rtfFormat) {
        PdfWriter.getInstance(document, baos);
    } else {
        RtfWriter2.getInstance(document, baos);
    }

    // =============================
    // Header + footer
    // =============================

    setHeader(document);
    setFooter(document);
    document.open();

    // ===============================
    // Body
    // ===============================
    // Session comments
    setSessionComments(document);
    document.add(new Paragraph(" "));
    if (dataCollectionList.isEmpty()) {
        document.add(new Paragraph("There is no data collection in this report", PdfRtfExporter.FONT_DOC));
    } else {
        Iterator<DataCollection3VO> it = dataCollectionList.iterator();
        Session3Service sessionService = (Session3Service) ejb3ServiceLocator
                .getLocalService(Session3Service.class);
        AutoProc3VO[] autoProcs = wrapper.getAutoProcs();
        AutoProcScalingStatistics3VO[] autoProcsOverall = wrapper.getScalingStatsOverall();
        AutoProcScalingStatistics3VO[] autoProcsInner = wrapper.getScalingStatsInner();
        AutoProcScalingStatistics3VO[] autoProcsOuter = wrapper.getScalingStatsOuter();
        int i = 0;
        boolean firstPage = true;
        while (it.hasNext()) {
            if (firstPage) {
                firstPage = false;
            } else {
                document.newPage();
            }
            DataCollection3VO dcValue = it.next();
            DataCollectionExporter dcExporter = new DataCollectionExporter(df2, df3, proposalCode,
                    proposalNumber, mRequest);
            DataCollectionInformation dcInfo = dcExporter.getDataCollectionInformation(dcValue,
                    getSampleRankingVO(dcValue.getDataCollectionId()),
                    getAutoProcRankingVO(dcValue.getDataCollectionId()));
            // dataCollection general info: Date, screen/Collect, indexing
            // status
            setDataCollectionGeneralInfo(document, dcValue, dcInfo);
            Table table = new Table(NB_COL_DATACOLLECTION);
            table.setCellsFitPage(true);
            // dataCollection table - one row
            table = setDataCollectionHeader(document, table, false);
            setDataCollectionData(document, table, dcValue, sessionService, autoProcs[i], autoProcsOverall[i],
                    autoProcsInner[i], autoProcsOuter[i], false, false, null, null);
            document.add(table);
            i++;
            document.add(new Paragraph(" ", VERY_SMALL_FONT));
            setRankingTable(document, dcInfo);
            // Images
            setImagesTable(document, dcInfo);
            setEDNATable(document, dcInfo);
            setStrategyTable(document, dcInfo);
        }
    }

    // ======================
    // End of file
    // ======================
    document.close();
    return baos;
}

From source file:ispyb.client.mx.collection.PdfRtfExporter.java

License:Open Source License

/**
 * export auto proc ranking dataCollection
 * //from  ww w  .  j  a  v a2s.c  o m
 * @return
 * @throws Exception
 */
public ByteArrayOutputStream exportAutoProcRankingAsPDF(boolean rtfFormat, HttpServletRequest mRequest)
        throws Exception {
    // create simple doc and write to a ByteArrayOutputStream
    Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);
    // Document document = new Document(PageSize.A4);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if (!rtfFormat) {
        PdfWriter.getInstance(document, baos);
    } else {
        RtfWriter2.getInstance(document, baos);
    }

    // =============================
    // Header + footer
    // =============================

    setHeader(document);
    setFooter(document);
    document.open();

    // ===============================
    // Body
    // ===============================
    // Session comments
    setSessionComments(document);
    document.add(new Paragraph(" "));
    if (dataCollectionList.isEmpty()) {
        document.add(new Paragraph("There is no data collection in this report", PdfRtfExporter.FONT_DOC));
    } else {
        Iterator<DataCollection3VO> it = dataCollectionList.iterator();
        Session3Service sessionService = (Session3Service) ejb3ServiceLocator
                .getLocalService(Session3Service.class);
        AutoProc3VO[] autoProcs = wrapper.getAutoProcs();
        AutoProcScalingStatistics3VO[] autoProcsOverall = wrapper.getScalingStatsOverall();
        AutoProcScalingStatistics3VO[] autoProcsInner = wrapper.getScalingStatsInner();
        AutoProcScalingStatistics3VO[] autoProcsOuter = wrapper.getScalingStatsOuter();
        int i = 0;
        boolean firstPage = true;
        while (it.hasNext()) {
            if (firstPage) {
                firstPage = false;
            } else {
                document.newPage();
            }
            DataCollection3VO dcValue = it.next();
            DataCollectionExporter dcExporter = new DataCollectionExporter(df2, df3, proposalCode,
                    proposalNumber, mRequest);
            DataCollectionInformation dcInfo = dcExporter.getDataCollectionInformation(dcValue,
                    getSampleRankingVO(dcValue.getDataCollectionId()),
                    getAutoProcRankingVO(dcValue.getDataCollectionId()));
            // dataCollection general info: Date, screen/Collect, indexing
            // status
            setDataCollectionGeneralInfo(document, dcValue, dcInfo);
            Table table = new Table(NB_COL_DATACOLLECTION);
            table.setCellsFitPage(true);
            // dataCollection table - one row
            table = setDataCollectionHeader(document, table, false);
            setDataCollectionData(document, table, dcValue, sessionService, autoProcs[i], autoProcsOverall[i],
                    autoProcsInner[i], autoProcsOuter[i], false, false, null, null);
            document.add(table);
            i++;
            document.add(new Paragraph(" ", VERY_SMALL_FONT));
            setAutoProcRankingTable(document, dcInfo);
            // Images
            setImagesTable(document, dcInfo);
            setEDNATable(document, dcInfo);
            setStrategyTable(document, dcInfo);
        }
    }

    // ======================
    // End of file
    // ======================
    document.close();
    return baos;
}

From source file:ispyb.client.mx.collection.PdfRtfExporter.java

License:Open Source License

/**
 * export the MXPressO /MXpressE report/*  w  w w  .  ja va 2s.c  om*/
 * 
 * @param rtfFormat
 * @param mRequest
 * @return
 * @throws Exception
 */
public ByteArrayOutputStream exportMXPressOWorkflowReport(boolean rtfFormat, HttpServletRequest mRequest)
        throws Exception {
    // create simple doc and write to a ByteArrayOutputStream
    Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if (!rtfFormat) {
        PdfWriter.getInstance(document, baos);
    } else {
        RtfWriter2.getInstance(document, baos);
    }

    // =============================
    // Header + footer
    // =============================

    setHeaderMXPressO(document);
    setFooter(document);
    document.open();

    // ===============================
    // Body
    // ===============================
    // For each MXPressO workflow, display snapshot, results and
    // autoprocessingResults
    setMXPressO(document, mRequest);

    // ======================
    // End of file
    // ======================
    document.close();
    return baos;

}