List of usage examples for com.lowagie.text Document setPageCount
public void setPageCount(int pageN)
From source file:is.idega.idegaweb.egov.cases.business.CaseWriter.java
License:Open Source License
protected MemoryFileBuffer writePDF(IWContext iwc) { Font titleFont = new Font(Font.HELVETICA, 14, Font.BOLD); Font labelFont = new Font(Font.HELVETICA, 11, Font.BOLD); Font textFont = new Font(Font.HELVETICA, 11, Font.NORMAL); try {/* w w w . ja v a 2 s . c o m*/ MemoryFileBuffer buffer = new MemoryFileBuffer(); MemoryOutputStream mos = new MemoryOutputStream(buffer); Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter.getInstance(document, mos); document.addAuthor("Idegaweb eGov"); document.addSubject("Case"); document.open(); document.newPage(); String title = iwrb.getLocalizedString("case_overview", "Case overview"); Paragraph cTitle = new Paragraph(title, titleFont); cTitle.setSpacingAfter(24); document.setPageCount(1); document.add(cTitle); int[] widths = { 25, 75 }; PdfPTable table = new PdfPTable(2); table.setWidths(widths); table.getDefaultCell().setBorder(0); table.getDefaultCell().setPaddingBottom(8); CaseCategory category = theCase.getCaseCategory(); CaseCategory parentCategory = category.getParent(); CaseType type = theCase.getCaseType(); User user = theCase.getOwner(); Address address = user != null ? getUserBusiness(iwc).getUsersMainAddress(user) : null; PostalCode postal = null; if (address != null) { postal = address.getPostalCode(); } Phone phone = null; if (user != null) { try { phone = getUserBusiness(iwc).getUsersHomePhone(user); } catch (NoPhoneFoundException e) { //No phone found... } } Email email = null; if (user != null) { try { email = getUserBusiness(iwc).getUsersMainEmail(user); } catch (NoEmailFoundException e) { //No email found... } } IWTimestamp created = new IWTimestamp(theCase.getCreated()); if (user != null) { table.addCell(new Phrase(iwrb.getLocalizedString("name", "Name"), labelFont)); table.addCell(new Phrase( new Name(user.getFirstName(), user.getMiddleName(), user.getLastName()).getName(locale), textFont)); table.addCell(new Phrase(iwrb.getLocalizedString("personal_id", "Personal ID"), labelFont)); table.addCell(new Phrase(PersonalIDFormatter.format(user.getPersonalID(), locale), textFont)); table.addCell(new Phrase(iwrb.getLocalizedString("address", "Address"), labelFont)); table.addCell(new Phrase(address != null ? address.getStreetAddress() : "-", textFont)); table.addCell(new Phrase(iwrb.getLocalizedString("zip_code", "Postal code"), labelFont)); table.addCell(new Phrase(postal != null ? postal.getPostalAddress() : "-", textFont)); table.addCell(new Phrase(iwrb.getLocalizedString("home_phone", "Home phone"), labelFont)); table.addCell(new Phrase(phone != null ? phone.getNumber() : "-", textFont)); table.addCell(new Phrase(iwrb.getLocalizedString("email", "Email"), labelFont)); table.addCell(new Phrase(email != null ? email.getEmailAddress() : "-", textFont)); table.addCell(new Phrase("")); table.addCell(new Phrase("")); table.addCell(new Phrase("")); table.addCell(new Phrase("")); } table.addCell(new Phrase(iwrb.getLocalizedString("case_nr", "Case nr."), labelFont)); table.addCell(new Phrase(theCase.getPrimaryKey().toString(), textFont)); if (getCasesBusiness(iwc).useTypes()) { table.addCell(new Phrase(iwrb.getLocalizedString("case_type", "Case type"), labelFont)); table.addCell(new Phrase(type.getName(), textFont)); } if (parentCategory != null) { table.addCell(new Phrase(iwrb.getLocalizedString("case_category", "Case category"), labelFont)); table.addCell(new Phrase(parentCategory.getLocalizedCategoryName(locale), textFont)); table.addCell(new Phrase(iwrb.getLocalizedString("sub_case_category", "Case category"), labelFont)); table.addCell(new Phrase(category.getLocalizedCategoryName(locale), textFont)); } else { table.addCell(new Phrase(iwrb.getLocalizedString("case_category", "Case category"), labelFont)); table.addCell(new Phrase(category.getLocalizedCategoryName(locale), textFont)); } table.addCell(new Phrase(iwrb.getLocalizedString("created_date", "Created date"), labelFont)); table.addCell(new Phrase(created.getLocaleDateAndTime(locale, IWTimestamp.SHORT, IWTimestamp.SHORT), textFont)); if (theCase.getSubject() != null) { table.addCell(new Phrase(iwrb.getLocalizedString("subject", "Subject"), labelFont)); table.addCell(new Phrase(theCase.getSubject(), textFont)); } table.addCell(new Phrase(iwrb.getLocalizedString("message", "Message"), labelFont)); table.addCell(new Phrase(theCase.getMessage(), textFont)); if (theCase.getReference() != null) { table.addCell(new Phrase(iwrb.getLocalizedString("reference", "Reference"), labelFont)); table.addCell(new Phrase(theCase.getReference(), textFont)); } table.setWidthPercentage(100); document.add(table); document.close(); try { mos.close(); } catch (Exception ex) { ex.printStackTrace(); } buffer.setMimeType("application/pdf"); return buffer; } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:javaaxp.xps2pdf.service.impl.PDFConverterImpl.java
License:Open Source License
@Override public void covertToPDF(OutputStream ouput) throws XPSError { try {/*from w ww.ja v a 2s .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:org.kuali.kfs.module.endow.report.util.TransactionSummaryReportPrint.java
License:Educational Community License
/** * Generates the Transaction Summary report showing all amounts fields. * // ww w . ja v a2 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 ww . j a 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; }