List of usage examples for com.lowagie.text Document setPageSize
public boolean setPageSize(Rectangle pageSize)
From source file:org.kuali.coeus.s2sgen.impl.print.S2SPrintingServiceImpl.java
License:Educational Community License
/** * @param pdfBytesList List containing the PDF data bytes * @param bookmarksList List of bookmarks corresponding to the PDF bytes. */// www. j a v a2s . c o m protected byte[] mergePdfBytes(List<byte[]> pdfBytesList, List<String> bookmarksList, boolean headerFooterRequired) { Document document = null; PdfWriter writer = null; ByteArrayOutputStream mergedPdfReport = new ByteArrayOutputStream(); int totalNumOfPages = 0; PdfReader[] pdfReaderArr = new PdfReader[pdfBytesList.size()]; int pdfReaderCount = 0; for (byte[] fileBytes : pdfBytesList) { LOG.debug("File Size " + fileBytes.length + " For " + bookmarksList.get(pdfReaderCount)); PdfReader reader = null; try { reader = new PdfReader(fileBytes); pdfReaderArr[pdfReaderCount] = reader; pdfReaderCount = pdfReaderCount + 1; totalNumOfPages += reader.getNumberOfPages(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } HeaderFooter footer = null; if (headerFooterRequired) { Calendar calendar = Calendar.getInstance(); String dateString = formateCalendar(calendar); StringBuilder footerPhStr = new StringBuilder(); footerPhStr.append(" of "); footerPhStr.append(totalNumOfPages); footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_76)); footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_76)); footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_60)); footerPhStr.append(dateString); Font font = FontFactory.getFont(FontFactory.TIMES, 8, Font.NORMAL, Color.BLACK); Phrase beforePhrase = new Phrase("Page ", font); Phrase afterPhrase = new Phrase(footerPhStr.toString(), font); footer = new HeaderFooter(beforePhrase, afterPhrase); footer.setAlignment(Element.ALIGN_BASELINE); footer.setBorderWidth(0f); } for (int count = 0; count < pdfReaderArr.length; count++) { PdfReader reader = pdfReaderArr[count]; int nop; if (reader == null) { LOG.debug("Empty PDF byetes found for " + bookmarksList.get(count)); continue; } else { nop = reader.getNumberOfPages(); } if (count == 0) { document = nop > 0 ? new Document(reader.getPageSizeWithRotation(1)) : new Document(); try { writer = PdfWriter.getInstance(document, mergedPdfReport); } catch (DocumentException e) { LOG.error(e.getMessage(), e); throw new S2SException(e.getMessage(), e); } if (footer != null) { document.setFooter(footer); } document.open(); } PdfContentByte cb = writer.getDirectContent(); int pageCount = 0; while (pageCount < nop) { document.setPageSize(reader.getPageSize(++pageCount)); document.newPage(); if (footer != null) { document.setFooter(footer); } PdfImportedPage page = writer.getImportedPage(reader, pageCount); cb.addTemplate(page, 1, 0, 0, 1, 0, 0); PdfOutline root = cb.getRootOutline(); if (pageCount == 1) { String pageName = bookmarksList.get(count); cb.addOutline(new PdfOutline(root, new PdfDestination(PdfDestination.FITH), pageName), pageName); } } } if (document != null) { try { document.close(); return mergedPdfReport.toByteArray(); } catch (Exception e) { LOG.error("Exception occured because the generated PDF document has no pages", e); } } return null; }
From source file:org.kuali.kfs.module.endow.report.util.AssetStatementReportPrint.java
License:Educational Community License
/** * Creates an endowment total report//from ww w . jav a 2s. c o m * * @param endowmentAssetStatementReportDataHolders * @param reportHeaderDataHolderForEndowment * @param document * @param listKemidsInHeader * @param beginWithNewpage */ protected void generateEndowmentDetailReport( List<AssetStatementReportDataHolder> endowmentAssetStatementReportDataHolders, EndowmentReportHeaderDataHolder reportHeaderDataHolderForEndowment, Document document, String listKemidsInHeader, boolean beginWithNewpage) { document.setPageSize(LETTER_PORTRAIT); if (beginWithNewpage) setNewPage(document); reportHeaderDataHolderForEndowment.setEndowmentOption(EndowConstants.EndowmentReport.ENDOWMENT); reportHeaderDataHolderForEndowment.setReportOption(EndowConstants.EndowmentReport.DETAIL_REPORT); printReportHeaderPage(reportHeaderDataHolderForEndowment, document, listKemidsInHeader); document.setPageSize(LETTER_LANDSCAPE); printAssetStatementReportBodyForEndowmentDetail(endowmentAssetStatementReportDataHolders, document); }
From source file:org.kuali.kfs.module.endow.report.util.AssetStatementReportPrint.java
License:Educational Community License
/** * Creates an endowment detail report/*from ww w . jav a2 s. c om*/ * * @param endowmentAssetStatementReportDataHolders * @param reportHeaderDataHolderForEndowment * @param document * @param listKemidsInHeader * @param beginWithNewpage */ protected void generateEndowmentTotalReport( List<AssetStatementReportDataHolder> endowmentAssetStatementReportDataHolders, EndowmentReportHeaderDataHolder reportHeaderDataHolderForEndowment, Document document, String listKemidsInHeader, boolean beginWithNewpage) { document.setPageSize(LETTER_PORTRAIT); if (beginWithNewpage) setNewPage(document); reportHeaderDataHolderForEndowment.setEndowmentOption(EndowConstants.EndowmentReport.ENDOWMENT); reportHeaderDataHolderForEndowment.setReportOption(EndowConstants.EndowmentReport.TOTAL_REPORT); printReportHeaderPage(reportHeaderDataHolderForEndowment, document, listKemidsInHeader); document.setPageSize(LETTER_LANDSCAPE); printAssetStatementReportBodyForEndowmentTotal(endowmentAssetStatementReportDataHolders, document); }
From source file:org.kuali.kfs.module.endow.report.util.AssetStatementReportPrint.java
License:Educational Community License
/** * Creates a non-endowed detail report/*from w w w. ja v a 2 s.com*/ * * @param nonEndowedAssetStatementReportDataHolders * @param reportHeaderDataHolderForNonEndowed * @param document * @param listKemidsInHeader * @param beginWithNewpage */ protected void generateNonEndowedDetailReport( List<AssetStatementReportDataHolder> nonEndowedAssetStatementReportDataHolders, EndowmentReportHeaderDataHolder reportHeaderDataHolderForNonEndowed, Document document, String listKemidsInHeader, boolean beginWithNewpage) { document.setPageSize(LETTER_PORTRAIT); if (beginWithNewpage) setNewPage(document); reportHeaderDataHolderForNonEndowed.setEndowmentOption(EndowConstants.EndowmentReport.NON_ENDOWED); reportHeaderDataHolderForNonEndowed.setReportOption(EndowConstants.EndowmentReport.DETAIL_REPORT); printReportHeaderPage(reportHeaderDataHolderForNonEndowed, document, listKemidsInHeader); document.setPageSize(LETTER_LANDSCAPE); printAssetStatementReportBodyForNonEndowedDetail(nonEndowedAssetStatementReportDataHolders, document); }
From source file:org.kuali.kfs.module.endow.report.util.AssetStatementReportPrint.java
License:Educational Community License
/** * Creates a non-endowed total report/* w w w.ja va2s. c om*/ * * @param nonEndowedAssetStatementReportDataHolders * @param reportHeaderDataHolderForNonEndowed * @param document * @param listKemidsInHeader * @param beginWithNewpage */ protected void generateNonEndowedTotalReport( List<AssetStatementReportDataHolder> nonEndowedAssetStatementReportDataHolders, EndowmentReportHeaderDataHolder reportHeaderDataHolderForNonEndowed, Document document, String listKemidsInHeader, boolean beginWithNewpage) { document.setPageSize(LETTER_PORTRAIT); if (beginWithNewpage) setNewPage(document); reportHeaderDataHolderForNonEndowed.setEndowmentOption(EndowConstants.EndowmentReport.NON_ENDOWED); reportHeaderDataHolderForNonEndowed.setReportOption(EndowConstants.EndowmentReport.TOTAL_REPORT); printReportHeaderPage(reportHeaderDataHolderForNonEndowed, document, listKemidsInHeader); document.setPageSize(LETTER_LANDSCAPE); printAssetStatementReportBodyForNonEndowedTotal(nonEndowedAssetStatementReportDataHolders, document); }
From source file:org.kuali.kfs.module.endow.report.util.TransactionStatementReportPrint.java
License:Educational Community License
/** * Generates the report in PDF using iText * // ww w . j a v a 2s . c o m * @param reportRequestHeaderDataHolder * @param transactionStatementDataReportHolders * @return */ public ByteArrayOutputStream printTransactionStatementReport( EndowmentReportHeaderDataHolder reportRequestHeaderDataHolder, List<TransactionStatementReportDataHolder> transactionStatementDataReportHolders, String listKemidsInHeader) { final org.apache.log4j.Logger LOG = org.apache.log4j.Logger .getLogger(TransactionStatementReportPrint.class); Document document = new Document(); document.setPageSize(LETTER_PORTRAIT); document.addTitle("Endowment Transaction Statement"); ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); try { PdfWriter.getInstance(document, pdfStream); document.open(); // print the report header if (printReportHeaderPage(reportRequestHeaderDataHolder, document, listKemidsInHeader)) { // and then the body if (transactionStatementDataReportHolders != null && transactionStatementDataReportHolders.size() > 0) { printTransactionStatementReportBody(transactionStatementDataReportHolders, document); } } else { LOG.error("Transaction Statement Report Header Error"); } document.close(); } catch (Exception e) { LOG.error("PDF Error: " + e.getMessage()); return null; } return pdfStream; }
From source file:org.kuali.kfs.module.endow.report.util.TransactionSummaryReportPrint.java
License:Educational Community License
/** * Generates the report in PDF using iText * /*www .jav a 2 s. co m*/ * @param reportRequestHeaderDataHolder * @param transactionStatementDataReportHolders * @return pdfStream */ public ByteArrayOutputStream printTransactionSummaryReport( EndowmentReportHeaderDataHolder reportRequestHeaderDataHolder, List<TransactionSummaryReportDataHolder> transactionSummaryDataReportHolders, String listKemidsInHeader, String reportOption, String summaryTotalsOnly) { Document document = new Document(); document.setPageSize(LETTER_PORTRAIT); document.addTitle("Endowment Transaction Summary"); ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); try { PdfWriter.getInstance(document, pdfStream); document.open(); // page HeaderFooter header = new HeaderFooter(new Phrase(new Date().toString() + " Page: ", headerFont), true); header.setBorder(Rectangle.NO_BORDER); header.setAlignment(Element.ALIGN_RIGHT); header.setPageNumber(0); document.setHeader(header); // print the report header if (printReportHeaderPage(reportRequestHeaderDataHolder, document, listKemidsInHeader)) { if (transactionSummaryDataReportHolders != null && transactionSummaryDataReportHolders.size() > 0) { if ("Y".equalsIgnoreCase(summaryTotalsOnly)) { printReportBodyBySummaryTotals(transactionSummaryDataReportHolders, document, reportOption); } else { printReportBodyByAllTotals(transactionSummaryDataReportHolders, document, reportOption); } } } else { LOG.error("Transaction Summary Report Header Error"); } document.close(); } catch (Exception e) { LOG.error("PDF Error: " + e.getMessage()); return null; } return pdfStream; }
From source file:org.kuali.kfs.module.endow.report.util.TransactionSummaryReportPrint.java
License:Educational Community License
/** * Generates the Transaction Summary report showing all amounts fields. * /*from w ww . j ava 2 s. co m*/ * @param transactionSummaryReports * @param document * @return true if document created else return false */ public boolean printReportBodyByAllTotalsForDetailReportOption( List<TransactionSummaryReportDataHolder> transactionSummaryReportDataHolders, Document document) { document.setPageCount(0); // for each kemid try { Font cellFont = regularFont; for (TransactionSummaryReportDataHolder transactionSummaryReport : transactionSummaryReportDataHolders) { // new page document.setPageSize(LETTER_LANDSCAPE); document.newPage(); // header writeDocumentHeader(document, transactionSummaryReport); // report table column headers PdfPTable table = writeDocumentTitleHeadings(EndowConstants.EndowmentReport.DETAIL); if (ObjectUtils.isNull(table)) { return false; } // write out Beginning Market value row values writeDetailLineRow(table, cellFont, "Beginning Market Value", transactionSummaryReport.getIncomeBeginningMarketValue(), transactionSummaryReport.getPrincipalBeginningMarketValue(), transactionSummaryReport.getTotalBeginningMarketValue()); // contributions rows writeContributionsRecordsForDetailReportOption(table, cellFont, transactionSummaryReport); // expenses rows.... writeExpensesRecordsForDetailReportOption(table, cellFont, transactionSummaryReport); // cash transfer rows... writeCashTransfersRecordsForDetailReportOption(table, cellFont, transactionSummaryReport); // cash transfer rows... writeSecurityTransfersRecordsForDetailReportOption(table, cellFont, transactionSummaryReport); //write change in market value row.... writeDetailLineRow(table, cellFont, "Change in Market Value", transactionSummaryReport.getIncomeChangeInMarketValue(), transactionSummaryReport.getPrincipalChangeInMarketValue(), transactionSummaryReport.getTotalChangeInMarketValue()); //write period end total market value record.... writeDetailLineRow(table, cellFont, "Period End total Market Value (Include Cash)", transactionSummaryReport.getIncomeEndingMarketValue(), transactionSummaryReport.getPrincipalEndingMarketValue(), transactionSummaryReport.getTotalEndingMarketValue()); // write out estimate income row writeDetailsLineWithTotalAmountOnly(table, cellFont, "Next 12 Months Estimated Income", transactionSummaryReport.getNext12MonthsEstimatedIncome(), EndowConstants.EndowmentReport.DETAIL); //write out the remainder FY estimated row... writeDetailsLineWithTotalAmountOnly(table, cellFont, "Remainder of Fiscal Year Estimated Income", transactionSummaryReport.getRemainderOfFYEstimatedIncome(), EndowConstants.EndowmentReport.DETAIL); //write out the next FY estimated row... writeDetailsLineWithTotalAmountOnly(table, cellFont, "Next Fiscal Year Estimated Income", transactionSummaryReport.getNextFYEstimatedIncome(), EndowConstants.EndowmentReport.DETAIL); document.add(table); //print the footer... if (ObjectUtils.isNotNull(transactionSummaryReport.getFooter())) { printFooter(transactionSummaryReport.getFooter(), document); } } } catch (Exception e) { return false; } return true; }
From source file:org.kuali.kfs.module.endow.report.util.TransactionSummaryReportPrint.java
License:Educational Community License
/** * Generates the Transaction Summary report showing only summary amount field. * This report will only show the total amount field for each kemid * @param transactionSummaryReports//from w w w.ja va 2 s . c o m * @param document * @return true if document created else return false */ public boolean printReportBodyForDetailReportOption( List<TransactionSummaryReportDataHolder> transactionSummaryReportDataHolders, Document document) { document.setPageCount(0); try { Font cellFont = regularFont; for (TransactionSummaryReportDataHolder transactionSummaryReport : transactionSummaryReportDataHolders) { // new page document.setPageSize(LETTER_LANDSCAPE); document.newPage(); // header writeDocumentHeader(document, transactionSummaryReport); // report table column headers PdfPTable table = writeDocumentTitleHeadings(EndowConstants.EndowmentReport.TOTAL); if (ObjectUtils.isNull(table)) { return false; } // write out Beginning Market value row values writeDetailLineRow(table, cellFont, "Beginning Market Value", transactionSummaryReport.getTotalBeginningMarketValue()); // contributions rows writeContributionsRecordsForSummaryReportOption(table, cellFont, transactionSummaryReport); // expenses rows.... writeExpensesRecordsForSummaryReportOption(table, cellFont, transactionSummaryReport); //cash transfers rows.. writeCashTransfersRecordsForSummaryReportOption(table, cellFont, transactionSummaryReport); // security transfer rows... writeSecurityTransfersRecordsForSummaryReportOption(table, cellFont, transactionSummaryReport); //write change in market value row.... writeDetailLineRow(table, cellFont, "Change in Market Value", transactionSummaryReport.getTotalChangeInMarketValue()); //write period end total market value record.... writeDetailLineRow(table, cellFont, "Period End total Market Value (Include Cash)", transactionSummaryReport.getTotalEndingMarketValue()); // write out estimate income row writeDetailsLineWithTotalAmountOnly(table, cellFont, "Next 12 Months Estimated Income", transactionSummaryReport.getNext12MonthsEstimatedIncome(), EndowConstants.EndowmentReport.TOTAL); //write out the remainder FY estimated row... writeDetailsLineWithTotalAmountOnly(table, cellFont, "Remainder of Fiscal Year Estimated Income", transactionSummaryReport.getRemainderOfFYEstimatedIncome(), EndowConstants.EndowmentReport.TOTAL); //write out the next FY estimated row... writeDetailsLineWithTotalAmountOnly(table, cellFont, "Next Fiscal Year Estimated Income", transactionSummaryReport.getNextFYEstimatedIncome(), EndowConstants.EndowmentReport.TOTAL); document.add(table); //print the footer... if (ObjectUtils.isNotNull(transactionSummaryReport.getFooter())) { printFooter(transactionSummaryReport.getFooter(), document); } } } catch (Exception e) { return false; } return true; }
From source file:org.kuali.kfs.module.endow.report.util.TrialBalanceReportPrint.java
License:Educational Community License
/** * Generates the report in PDF using iText * /* w w w. j a v a2 s. co m*/ * @param reportRequestHeaderDataHolder * @param trialBalanceDataReportHolders * @return ByteArrayOutputStream */ public ByteArrayOutputStream printTrialBalanceReport( EndowmentReportHeaderDataHolder reportRequestHeaderDataHolder, List<TrialBalanceReportDataHolder> trialBalanceDataReportHolders, String listKemidsInHeader) { final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(TrialBalanceReportPrint.class); Document document = new Document(); document.setPageSize(LETTER_PORTRAIT); document.addTitle("Endowment Trial Balance"); // get the stream for PDF ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); try { PdfWriter.getInstance(document, pdfStream); document.open(); // page HeaderFooter header = new HeaderFooter(new Phrase(new Date().toString() + " Page: ", headerFont), true); header.setBorder(Rectangle.NO_BORDER); header.setAlignment(Element.ALIGN_RIGHT); header.setPageNumber(0); document.setHeader(header); // print the report header if (printReportHeaderPage(reportRequestHeaderDataHolder, document, listKemidsInHeader)) { if (trialBalanceDataReportHolders != null && trialBalanceDataReportHolders.size() > 0) { document.setPageSize(LETTER_LANDSCAPE); document.resetPageCount(); header.setPageNumber(1); document.newPage(); printTrialBalanceReportBody(trialBalanceDataReportHolders, document); } else { LOG.error("Trial Balance Report Header Error"); } } document.close(); } catch (Exception e) { LOG.error("PDF Error: " + e.getMessage()); return null; } return pdfStream; }