Example usage for com.lowagie.text Document newPage

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

Introduction

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

Prototype


public boolean newPage() 

Source Link

Document

Signals that an new page has to be started.

Usage

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

License:Open Source License

/**
 * export detailed dataCollection/*from ww w . j a va  2  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   w w w.  ja  va 2  s . c  om
 * @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 www . j a  v a 2s. c  om*/
 * 
 * @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
 * //w w w.  ja  va2 s .  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

/**
 * iterates over the collects to set the MXPressO table
 * idem for MXPressI//from  w w  w . j  av a 2  s.co m
 * 
 * @param document
 * @param mRequest
 * @throws Exception
 */
private void setMXPressO(Document document, HttpServletRequest mRequest) throws Exception {
    if (dataCollectionGroupList == null || dataCollectionGroupList.isEmpty()) {
        document.add(new Paragraph("There is no data collection group in this report", FONT_DOC));
    } else {
        int countTables = 0;
        int id = 0;
        for (Iterator<DataCollectionGroup3VO> iterator = dataCollectionGroupList.iterator(); iterator
                .hasNext();) {
            // System.out.println("id: "+id+", countTables= "+countTables);
            DataCollectionGroup3VO dataCollectionGroupVO = (DataCollectionGroup3VO) iterator.next();
            if (dataCollectionGroupVO.getWorkflowVO() != null
                    && dataCollectionGroupVO.getWorkflowVO().isMXPressEOIA()) {
                List<DataCollection3VO> sortedListCollect = ViewSessionSummaryAction
                        .getSortedDataCollectionList(dataCollectionGroupVO.getDataCollectionsList());
                DataCollection3VO lastCollectOSC = null;
                // for MXPressE, we need the collect just before the last,
                // to have EDNA results
                DataCollection3VO nextToLastCollectChar = null;

                if (sortedListCollect != null && sortedListCollect.size() > 0) {
                    lastCollectOSC = sortedListCollect.get(0);
                }
                if (sortedListCollect != null && sortedListCollect.size() > 1 && dataCollectionGroupVO
                        .getWorkflowVO().getWorkflowType().equals(Constants.WORKFLOW_MXPRESSE)) {
                    nextToLastCollectChar = sortedListCollect.get(1);
                }

                // is mxpresse with edna res
                boolean withEDNARes = false;
                if (nextToLastCollectChar != null) {
                    DataCollectionExporter dcExporter = new DataCollectionExporter(df2, df3, proposalCode,
                            proposalNumber, mRequest);
                    DataCollectionInformation dcInfo = dcExporter.getDataCollectionInformation(
                            nextToLastCollectChar,
                            getSampleRankingVO(nextToLastCollectChar.getDataCollectionId()),
                            getAutoProcRankingVO(nextToLastCollectChar.getDataCollectionId()));
                    if (dcInfo.getSpacegroup() != "") {
                        withEDNARes = true;
                    }
                }
                if (id != 0 && withEDNARes) {
                    document.newPage();
                } else {
                    if (countTables > 1) {
                        // System.out.println("page break");
                        document.newPage();
                        countTables = 0;
                    }
                }
                setMXPressOTable(document, dataCollectionGroupVO, mRequest, lastCollectOSC,
                        nextToLastCollectChar);
                countTables++;
                if (withEDNARes) {
                    countTables++;
                }
                id++;
            }

            //
        }
    }
}

From source file:ispyb.common.util.export.PdfExporterSample.java

License:Open Source License

/**
 * Exports the file for viewSample for shipment
 * /*from   ww  w  .ja va2  s.  com*/
 * @return
 * @throws Exception
 */
public ByteArrayOutputStream exportAsPdf() throws Exception {

    // create simple doc and write to a ByteArrayOutputStream
    Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);
    document.addTitle("exportSamplesView");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);
    HeaderFooter header;

    // header + footer
    if (viewName != null)
        header = new HeaderFooter(new Phrase("Samples for Proposal: " + proposalDesc + "  ---  " + viewName),
                false);

    else
        header = new HeaderFooter(new Phrase("Samples for Proposal: " + proposalDesc), false);

    header.setAlignment(Element.ALIGN_CENTER);
    header.setBorderWidth(1);
    header.getBefore().getFont().setSize(8);
    HeaderFooter footer = new HeaderFooter(new Phrase("Page n."), true);
    footer.setAlignment(Element.ALIGN_RIGHT);
    footer.setBorderWidth(1);
    footer.getBefore().getFont().setSize(6);

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

    document.open();

    if (aList.isEmpty()) {
        document.add(new Paragraph("There is no samples in this report"));
        document.close();
        return baos;
    }
    // Create first table for samples

    int NumColumns = 19;
    PdfPTable table = new PdfPTable(NumColumns);
    int headerwidths[] = { 6, 6, 6, 6, 6, 4, 6, 4, 4, 4, 4, 4, 4, 8, 5, 5, 5, 10, 6 }; // percentage
    table.setWidths(headerwidths);

    table.setWidthPercentage(100); // percentage
    table.getDefaultCell().setPadding(3);
    table.getDefaultCell().setBorderWidth(1);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    // header
    PdfPCell cell = new PdfPCell();
    table.addCell(new Paragraph("Protein", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Sample name", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Smp code", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Dewar", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Container", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Loc. in cont.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Space group", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell a", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell b", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell c", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell alpha", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell beta", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell gamma", new Font(Font.HELVETICA, 8)));

    cell = new PdfPCell(new Paragraph("Crystal comments", new Font(Font.HELVETICA, 8)));
    table.addCell(cell);

    table.addCell(new Paragraph("Already observed resol.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Required resol.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Min. resol.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Sample comments", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Sample status", new Font(Font.HELVETICA, 8)));

    table.setHeaderRows(1); // this is the end of the table header

    table.getDefaultCell().setBorderWidth(1);
    DecimalFormat df1 = new DecimalFormat("#####0.0");
    DecimalFormat df2 = new DecimalFormat("#####0.00");

    Iterator it = aList.iterator();
    int i = 1;
    String currentContainer = "next";
    String nextContainer = "next";

    while (it.hasNext()) {
        table.getDefaultCell().setGrayFill(0.99f);
        if (i % 2 == 1) {
            table.getDefaultCell().setGrayFill(0.9f);
        }
        BLSample3VO samplefv = (BLSample3VO) it.next();
        LOG.debug("table of datacollections pdf " + samplefv.getBlSampleId());

        if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getCode() != null)
            nextContainer = samplefv.getContainerVO().getCode();
        else
            nextContainer = "next";

        // in the case of view sorted by dewar/container, we add a page break afetr each container
        if (sortView.equals("2") && !currentContainer.equals(nextContainer)) {
            document.add(table);
            table.deleteBodyRows();
            document.newPage();
        }

        if (samplefv.getCrystalVO().getProteinVO().getAcronym() != null)
            table.addCell(new Paragraph(samplefv.getCrystalVO().getProteinVO().getAcronym(),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getName() != null)
            table.addCell(new Paragraph(samplefv.getName(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCode() != null)
            table.addCell(new Paragraph(samplefv.getCode(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getDewarVO() != null
                && samplefv.getContainerVO().getDewarVO().getCode() != null)
            table.addCell(new Paragraph(samplefv.getContainerVO().getDewarVO().getCode(),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getCode() != null) {
            currentContainer = samplefv.getContainerVO().getCode();
            table.addCell(new Paragraph(currentContainer, new Font(Font.HELVETICA, 8)));
        } else {
            currentContainer = "current";
            table.addCell("");
        }

        if (samplefv.getLocation() != null)
            table.addCell(new Paragraph(samplefv.getLocation(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getSpaceGroup() != null)
            table.addCell(new Paragraph(samplefv.getCrystalVO().getSpaceGroup(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellA() != null)
            table.addCell(
                    new Paragraph(df1.format(samplefv.getCrystalVO().getCellA()), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellB() != null)
            table.addCell(
                    new Paragraph(df1.format(samplefv.getCrystalVO().getCellB()), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellC() != null)
            table.addCell(
                    new Paragraph(df1.format(samplefv.getCrystalVO().getCellC()), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellAlpha() != null)
            table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellAlpha()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellBeta() != null)
            table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellBeta()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellGamma() != null)
            table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellGamma()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getComments() != null)
            table.addCell(new Paragraph(samplefv.getCrystalVO().getComments(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getDiffractionPlanVO() != null
                && samplefv.getDiffractionPlanVO().getObservedResolution() != null) {
            table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getObservedResolution()),
                    new Font(Font.HELVETICA, 8)));
        } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null
                && samplefv.getCrystalVO().getDiffractionPlanVO().getObservedResolution() != null)
            table.addCell(new Paragraph(
                    df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getObservedResolution()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getDiffractionPlanVO() != null
                && samplefv.getDiffractionPlanVO().getRequiredResolution() != null) {
            table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getRequiredResolution()),
                    new Font(Font.HELVETICA, 8)));
        } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null
                && samplefv.getCrystalVO().getDiffractionPlanVO().getRequiredResolution() != null)
            table.addCell(new Paragraph(
                    df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getRequiredResolution()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getDiffractionPlanVO() != null
                && samplefv.getDiffractionPlanVO().getMinimalResolution() != null) {
            table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getMinimalResolution()),
                    new Font(Font.HELVETICA, 8)));
        } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null
                && samplefv.getCrystalVO().getDiffractionPlanVO().getMinimalResolution() != null)
            table.addCell(new Paragraph(
                    df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getMinimalResolution()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getComments() != null && samplefv.getComments() != "")
            table.addCell(new Paragraph(samplefv.getComments(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getBlSampleStatus() != null)
            table.addCell(new Paragraph(samplefv.getBlSampleStatus(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (i % 2 == 1) {
            table.getDefaultCell().setGrayFill(0.0f);
        }

        i++;
    }

    document.add(table);

    document.close();

    return baos;
}

From source file:it.govpay.web.console.pagamenti.gde.exporter.PdfExporter.java

License:Open Source License

public static void exportAsPdf(List<EventoBean> eventi, ByteArrayOutputStream baos,
        IEventiService eventiService) throws DocumentException, UtilsException {

    Document document = new Document();

    PdfWriter.getInstance(document, baos);

    document.open();/*from   w  w w  .  j  a  v  a2  s  .  c  om*/

    addMetaData(document);
    addTitlePage(document);

    // Start a new page
    document.newPage();

    addContent(document, eventi, eventiService);

    document.close();

}

From source file:javaaxp.xps2pdf.service.impl.PDFConverterImpl.java

License:Open Source License

@Override
public void covertToPDF(OutputStream ouput) throws XPSError {
    try {// w w  w  .j  ava  2  s  .co  m
        int firstPage = fPageController.getXPSAccess().getPageAccess(0).getFirstPageNum();
        int lastPage = fPageController.getXPSAccess().getPageAccess(0).getLastPageNum();

        Document document = new Document();
        document.setPageCount(lastPage - firstPage + 1);
        document.setPageSize(PageSize.LETTER);
        PdfWriter writer = PdfWriter.getInstance(document, ouput);
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        for (int i = firstPage; i < 1; i++) {
            System.out.println("Converting page " + i);
            fPageController.setPage(i);
            PdfTemplate tp = cb.createTemplate((float) fPageController.getPage().getWidth(),
                    (float) fPageController.getPage().getHeight());
            Graphics g = tp.createGraphics((float) fPageController.getPage().getWidth(),
                    (float) fPageController.getPage().getHeight());
            JComponent toReturn = fPageViewer.getPageRenderer().getRendererComponent();
            toReturn.paint(g);
            cb.addTemplate(tp, 0, 0);
            document.newPage();
        }
        document.close();
    } catch (DocumentException e) {
        //rethrow
    }
}

From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java

License:Apache License

private int saveSheet(Document document, int listCount, ReportModel model)
        throws DocumentException, IOException, SaveReportException {

    model.updatePages(0);/*from w w  w  .  j  a  v  a  2s.  c  om*/

    ReportPage pageFormat = model.getReportPage();
    Paper paper = pageFormat.getPaper();
    Rectangle pageSize = new Rectangle(Math.round((float) paper.getWidth()),
            Math.round((float) paper.getHeight()));

    if (pageFormat.getOrientation() == ReportPage.LANDSCAPE) {
        pageSize = pageSize.rotate();
    }
    document.setPageSize(pageSize);
    document.setMargins(Math.round((float) pageFormat.getLeftMargin(Units.PT)),
            Math.round((float) pageFormat.getRightMargin(Units.PT)),
            Math.round((float) pageFormat.getTopMargin(Units.PT)),
            Math.round((float) pageFormat.getBottomMargin(Units.PT)));
    Rectangle viewPageSize = new Rectangle(
            document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(),
            document.getPageSize().getHeight() - document.topMargin() - document.bottomMargin());

    if (listCount > 0) {
        document.newPage();
    }
    listCount++;

    //float columnMargin = (float) Units.PT.setXPixels(model.getColumnModel().getColumnMargin());

    ReportPrintable printable = new ReportPrintable(model);
    int pageCount = printable.calcCountPage(model.getReportPage());
    Map<Integer, PageClip> clips = printable.getPageClips();

    int leftCol;
    int topRow;
    int rightCol;
    int bottomRow;

    for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
        PageClip pageClip = clips.get(pageIndex);
        if (pageClip == null)
            break;

        leftCol = pageClip.getLeftCol();
        rightCol = pageClip.getRightCol();

        topRow = pageClip.getTopRow();
        bottomRow = pageClip.getBottomRow();

        int columnCount = rightCol - leftCol;

        float[] widths = new float[columnCount + 1];
        widths[0] = 1;
        for (int c = 0; c < columnCount; c++) {
            ReportColumn column = (ReportColumn) model.getColumnModel().getColumn(leftCol + c);
            widths[c + 1] = (float) Math.round(column.getNativeWidth());
        }

        PdfPTable table = createPdfTable(columnCount + 1, widths, viewPageSize);

        fillTable(model, leftCol, topRow, rightCol, bottomRow, table);

        document.add(table);

        if (pageIndex < clips.size()) {
            document.newPage();
        }

    }
    return listCount;
}

From source file:jdraw.JDrawApplication.java

private void saveAsPDF() {
    JDocumentFrame frame = (JDocumentFrame) jDesktopPane1.getSelectedFrame();
    if (frame == null) {
        return;//from   w w w  . j av a 2 s.  c  om
    }
    JFileChooser chooser = new JFileChooser();
    chooser.setFileFilter(new FileNameExtensionFilter(
            java.util.ResourceBundle.getBundle("main").getString("filter_pdf"), "pdf"));
    chooser.setDialogTitle(java.util.ResourceBundle.getBundle("main").getString("dialog_export_as_pdf"));
    File f = chooser.getCurrentDirectory();
    f = new File(f.getPath(), frame.getDocument().getName() + ".pdf");
    chooser.setSelectedFile(f);
    if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
        return;
    }
    JDocument doc = frame.getDocument();
    f = chooser.getSelectedFile();
    if (f.exists() && JOptionPane.showConfirmDialog(this, f.getName() + java.util.ResourceBundle
            .getBundle("main").getString("msg_is_exist_overwrite")) != JOptionPane.OK_OPTION) {
        return;
    }
    frame.getViewer().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    com.lowagie.text.Document pDoc = new com.lowagie.text.Document();
    try {
        FileOutputStream wt = new FileOutputStream(f);
        BufferedOutputStream bout = new BufferedOutputStream(wt);
        com.lowagie.text.pdf.PdfWriter pwriter = com.lowagie.text.pdf.PdfWriter.getInstance(pDoc, bout);
        pDoc.open();
        FontFactory.registerDirectories();
        Set set = FontFactory.getRegisteredFonts();

        for (int i = 0; i < doc.size(); i++) {
            JPage cPage = doc.get(i);
            PageFormat pFormat = cPage.getPageFormat();
            com.lowagie.text.Rectangle rc = new com.lowagie.text.Rectangle((float) pFormat.getWidth(),
                    (float) pFormat.getHeight());
            float left = (float) (pFormat.getImageableX());
            float right = (float) (pFormat.getWidth() - pFormat.getImageableWidth() - left);
            float top = (float) pFormat.getImageableX();
            float bottom = (float) (pFormat.getHeight() - pFormat.getImageableHeight() - top);
            pDoc.newPage();

            com.lowagie.text.pdf.PdfContentByte cb = pdfContentByte = pwriter.getDirectContent();
            cb.saveState();

            Graphics2D g2 = (com.lowagie.text.pdf.PdfGraphics2D) cb.createGraphics((float) pFormat.getWidth(),
                    (float) pFormat.getHeight());

            boolean vg = cPage.getGuidLayer().isVisible();
            cPage.getGuidLayer().setVisible(false);
            cPage.paint(new Rectangle.Double(0, 0, pFormat.getWidth(), pFormat.getHeight()), g2);
            cPage.getGuidLayer().setVisible(vg);
            g2.dispose();
            cb.restoreState();
        }
        pDoc.close();
    } catch (Exception e) {
        JOptionPane.showConfirmDialog(this, e.getMessage(), "", JOptionPane.OK_OPTION,
                JOptionPane.ERROR_MESSAGE);
    }
    frame.getViewer().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

}