List of usage examples for com.lowagie.text.pdf PdfPTable setTotalWidth
public void setTotalWidth(float columnWidth[]) throws DocumentException
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
/** * Entering the project outputs in the summary *///from ww w. j av a2s. c o m private void addProjectOutputs(String number) { // ********************************************************************************** // *************************** Overview By Mog ************************************* // ********************************************************************************** try { Paragraph overview_title = new Paragraph(); overview_title.setFont(HEADING2_FONT); overview_title.add(number + ". " + this.getText("summaries.project.projectOutput")); overview_title.add(Chunk.NEWLINE); overview_title.add(Chunk.NEWLINE); document.newPage(); document.add(overview_title); overview_title = new Paragraph(); overview_title.setFont(HEADING3_FONT); overview_title.add(number + ".1 " + this.getText("summaries.project.overviewbymogs")); document.add(overview_title); } catch (DocumentException e) { LOG.error("There was an error trying to add the project title to the project summary pdf", e); } int[] years = { midOutcomeYear, project.isReporting() ? this.currentReportingYear - 1 : this.currentReportingYear - 1, project.isReporting() ? this.currentReportingYear : this.currentPlanningYear, project.isReporting() ? this.currentReportingYear + 1 : this.currentReportingYear + 1 }; Paragraph paragraph = new Paragraph(); List<IPElement> mogs = project.getOutputs(); try { if (mogs.isEmpty()) { paragraph.add(this.getText("summaries.project.empty")); document.add(paragraph); } else { // year PdfPTable table; for (int a = 0; a < years.length; a++) { paragraph = new Paragraph(); paragraph.setFont(TABLE_HEADER_FONT); paragraph.add(this.getText("summaries.project.overviewbymogs.text") + "- " + years[a]); table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(480); this.addTableHeaderCell(table, paragraph); // Mog for (int b = 0; b < mogs.size(); b++) { this.addOverview(table, mogs.get(b), years[a]); } paragraph = new Paragraph(); paragraph.add(Chunk.NEWLINE); document.add(paragraph); document.add(table); } // Leason regardins paragraph = new Paragraph(); paragraph.add(Chunk.NEWLINE); paragraph.setAlignment(Element.ALIGN_JUSTIFIED); paragraph.setFont(BODY_TEXT_BOLD_FONT); if (!project.isReporting()) { paragraph.add(this.getText("summaries.project.output.lessonRegarding")); } else { paragraph.add(this.getText("summaries.project.overviewbymogs.reporting.lesson")); } paragraph.setFont(BODY_TEXT_FONT); if (project.getComponentLesson("outputs") != null) { paragraph.add(this.messageReturn(project.getComponentLesson("outputs").getLessons())); } else { paragraph.add(this.messageReturn(null)); } paragraph.add(Chunk.NEWLINE); paragraph.add(Chunk.NEWLINE); document.add(paragraph); } } catch (DocumentException e) { LOG.error("There was an error trying to add the project title to the project summary pdf", e); } // ********************************************************************************** // *************************** Deliverables.**************************************** // ********************************************************************************** int counter = 1; try { document.newPage(); paragraph = new Paragraph(); paragraph.setFont(HEADING3_FONT); paragraph.add(number + ".2 " + this.getText("summaries.project.deliverable.title")); document.add(paragraph); paragraph = new Paragraph(); List<Deliverable> listDeliverables = project.getDeliverables(); if (listDeliverables.isEmpty()) { paragraph.add(this.getText("summaries.project.empty")); document.add(paragraph); } else { paragraph.add(Chunk.NEWLINE); document.add(paragraph); for (Deliverable deliverable : listDeliverables) { if (!project.isReporting()) { if (deliverable.getYear() == config.getPlanningCurrentYear()) { this.addDelivable(deliverable, counter); counter++; } } } } // ********************************************************************************** // *************************** Next users.**************************************** // ********************************************************************************** if (project.isReporting()) { counter = 1; document.newPage(); paragraph = new Paragraph(); paragraph.setFont(HEADING3_FONT); paragraph.add(number + ".3 " + this.getText("summaries.project.reporting.nextuser.title")); document.add(paragraph); PdfPTable table; if (project.getNextUsers().isEmpty()) { paragraph = new Paragraph(); paragraph.add(this.messageReturn(null)); paragraph.add(Chunk.NEWLINE); document.add(paragraph); } else { paragraph = new Paragraph(); paragraph.add(Chunk.NEWLINE); document.add(paragraph); for (ProjectNextUser projectNextUser : project.getNextUsers()) { paragraph = new Paragraph(); paragraph.setFont(TABLE_HEADER_FONT); paragraph.setAlignment(Element.ALIGN_LEFT); table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(480); paragraph.add(this.getText("summaries.project.reporting.nextuser", new String[] { String.valueOf(counter) })); this.addTableHeaderCell(table, paragraph); // Next users key paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.nextuser.currentPeriod")); paragraph.setFont(TABLE_BODY_FONT); if (projectNextUser != null) { paragraph.add(this.messageReturn(projectNextUser.getKeyNextUser())); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // Strategies paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.nextuser.strategies")); paragraph.setFont(TABLE_BODY_FONT); if (projectNextUser != null) { paragraph.add(this.messageReturn(projectNextUser.getStrategies())); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // reported paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.nextuser.reported")); paragraph.setFont(TABLE_BODY_FONT); if (projectNextUser != null) { paragraph.add(this.messageReturn(projectNextUser.getReportedDeliverables())); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // lessons paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.nextuser.lessons")); paragraph.setFont(TABLE_BODY_FONT); if (projectNextUser != null) { paragraph.add(this.messageReturn(projectNextUser.getLessonsImplications())); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); counter++; document.add(table); paragraph = new Paragraph(); paragraph.add(Chunk.NEWLINE); document.add(paragraph); } } // ********************************************************************************** // *************************** Project HighLights**************************************** // ********************************************************************************** counter = 1; document.newPage(); paragraph = new Paragraph(); paragraph.setFont(HEADING3_FONT); paragraph.add(number + ".4 " + this.getText("summaries.project.reporting.highlight.principal")); document.add(paragraph); paragraph = new Paragraph(); paragraph.add(Chunk.NEWLINE); document.add(paragraph); for (ProjectHighligths projectHighLigth : project.getHighlights()) { table = new PdfPTable(2); table.setLockedWidth(true); table.setTotalWidth(480); paragraph = new Paragraph(); paragraph.setFont(TABLE_HEADER_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight", new String[] { String.valueOf(counter) })); this.addTableHeaderCellColspan(table, paragraph, 2); // title paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.title")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getTitle())); } else { paragraph.add(this.messageReturn(null)); } this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); // author paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.author")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getAuthor())); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // subject paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.subject")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getSubject())); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // publisher paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.publisher")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getPublisher())); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // year paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.year")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(String.valueOf(projectHighLigth.getYear()))); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // project highlight types paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.types")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { for (ProjectHighligthsTypes projectHighLigthTypes : projectHighLigth .getProjectHighligthsTypeses()) { paragraph.add(this.messageReturn("\n" + ProjectHighlightsType .getEnum(String.valueOf(projectHighLigthTypes.getIdType())).getDescription())); } } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // project images paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add("Image"); if (projectHighLigth != null) { Image global; try { if (projectHighLigth.getPhoto() != null) { String urlImage = config.getDownloadURL() + "/" + this.getHighlightsImagesUrlPath() + projectHighLigth.getPhoto(); urlImage = urlImage.replace(" ", "%20"); global = Image.getInstance(urlImage); } else { global = null; } if (global != null) { float documentWidth = document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(); float documentHeight = document.getPageSize().getHeight() - document.topMargin() - document.bottomMargin(); global.scaleToFit((float) (documentWidth * 0.4), global.getHeight()); global.setAlignment(Element.ALIGN_CENTER); this.addTableBodyCell(table, global, Element.ALIGN_LEFT, 1); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { paragraph.add(this.messageReturn(null)); } // project start date paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.startDate")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(String.valueOf(projectHighLigth.getStartDate()))); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // project end date paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.endDate")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(String.valueOf(projectHighLigth.getEndDate()))); } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); // Its Global paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.itsglobal")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { if (projectHighLigth.isIsGlobal()) { paragraph.add("Yes"); } else { paragraph.add("No"); } ; } else { paragraph.add(this.messageReturn(null)); } this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); // Country paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.country")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null && projectHighLigth.getProjectHighligthsCountries() != null) { for (ProjectHighligthsCountry country : projectHighLigth.getProjectHighligthsCountries()) { paragraph.add(locationManager.getCountry(country.getIdCountry()).getName() + "\n"); } } else { paragraph.add(this.messageReturn(null)); } this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1); paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.keywords")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getKeywords())); } else { paragraph.add(this.messageReturn(null)); } this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); // description paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.description")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getDescription())); } else { paragraph.add(this.messageReturn(null)); } this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); // Introduction / Objectives paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.introduction")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getObjectives())); } else { paragraph.add(this.messageReturn(null)); } this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); // Results paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.results")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getResults())); } else { paragraph.add(this.messageReturn(null)); } this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); // Partners paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.partners")); paragraph.setFont(TABLE_BODY_FONT); if (projectHighLigth != null) { paragraph.add(this.messageReturn(projectHighLigth.getPartners())); } else { paragraph.add(this.messageReturn(null)); } this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); // Links paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_BOLD_FONT); paragraph.add(this.getText("summaries.project.reporting.highlight.links")); paragraph.setFont(TABLE_BODY_FONT); paragraph.add(this.messageReturn(projectHighLigth.getLinks())); this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2); document.add(table); document.newPage(); } } } catch (DocumentException e) { LOG.error("There was an error trying to add the project title to the project summary pdf", e); } }
From source file:org.cyberoam.iview.charts.Chart.java
License:Open Source License
/** * This Event handler Method adds Header and Footer in PDF File *//*from w w w . j a va2s . c o m*/ public void onEndPage(PdfWriter writer, Document document) { try { if (document.getPageNumber() > 1) { String seperator = System.getProperty("file.separator"); //String path=System.getProperty("catalina.home") +seperator+"webapps" +seperator+"ROOT" + seperator + "images" + seperator; String path = InitServlet.contextPath + seperator + "images" + seperator; Image imgHead = Image.getInstance(path + "iViewPDFHeader.JPG"); Image imgFoot = Image.getInstance(path + "iViewPDFFooter.JPG"); Rectangle page = document.getPageSize(); PdfPTable head = new PdfPTable(1); head.addCell(imgHead); head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin() - 10, page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent()); PdfPTable foot = new PdfPTable(1); foot.addCell(imgFoot); foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); foot.writeSelectedRows(0, -1, document.leftMargin() - 10, document.bottomMargin() + 24, writer.getDirectContent()); } } catch (Exception e) { throw new ExceptionConverter(e); } }
From source file:org.drools.verifier.doc.DroolsDocsComponentFactory.java
License:Apache License
public void onEndPage(PdfWriter writer, Document document) { try {/*from w w w . j a v a 2 s . co m*/ Image image = Image.getInstance(DroolsDocsBuilder.class.getResource("guvnor-webapp.png")); // TODO this image never existed image.setAlignment(Image.RIGHT); image.scaleAbsolute(100, 30); Rectangle page = document.getPageSize(); PdfPTable head = new PdfPTable(2); PdfPCell cell1 = new PdfPCell(image); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setBorder(0); head.addCell(cell1); PdfPCell cell2 = new PdfPCell(new Phrase(currentDate, DroolsDocsComponentFactory.HEADER_FOOTER_TEXT)); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); cell2.setBorder(0); head.addCell(cell2); head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent()); } catch (Exception e) { throw new ExceptionConverter(e); } }
From source file:org.kuali.kfs.module.ar.report.service.impl.ContractsGrantsInvoiceReportServiceImpl.java
License:Open Source License
/** * this method generated the actual pdf for the Contracts & Grants LOC Review Document. * * @param os// www . java 2s. c o m * @param LOCDocument */ protected void generateLOCReviewInPdf(OutputStream os, ContractsGrantsLetterOfCreditReviewDocument locDocument) { try { Document document = new Document( new Rectangle(ArConstants.LOCReviewPdf.LENGTH, ArConstants.LOCReviewPdf.WIDTH)); PdfWriter.getInstance(document, os); document.open(); Paragraph header = new Paragraph(); Paragraph text = new Paragraph(); Paragraph title = new Paragraph(); // Lets write the header header.add(new Paragraph(configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_TITLE), ArConstants.PdfReportFonts.LOC_REVIEW_TITLE_FONT)); if (StringUtils.isNotEmpty(locDocument.getLetterOfCreditFundGroupCode())) { header.add(new Paragraph( configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_HEADER_FUND_GROUP_CODE) + locDocument.getLetterOfCreditFundGroupCode(), ArConstants.PdfReportFonts.LOC_REVIEW_TITLE_FONT)); } if (StringUtils.isNotEmpty(locDocument.getLetterOfCreditFundCode())) { header.add(new Paragraph( configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_HEADER_FUND_CODE) + locDocument.getLetterOfCreditFundCode(), ArConstants.PdfReportFonts.LOC_REVIEW_TITLE_FONT)); } header.add(new Paragraph(KFSConstants.BLANK_SPACE)); header.setAlignment(Element.ALIGN_CENTER); title.add(new Paragraph( configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_HEADER_DOCUMENT_NUMBER) + locDocument.getDocumentNumber(), ArConstants.PdfReportFonts.LOC_REVIEW_HEADER_FONT)); Person person = getPersonService() .getPerson(locDocument.getFinancialSystemDocumentHeader().getInitiatorPrincipalId()); // writing the Document details title.add(new Paragraph( configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_HEADER_APP_DOC_STATUS) + locDocument.getFinancialSystemDocumentHeader().getApplicationDocumentStatus(), ArConstants.PdfReportFonts.LOC_REVIEW_HEADER_FONT)); title.add( new Paragraph( configService.getPropertyValueAsString( ArKeyConstants.LOC_REVIEW_PDF_HEADER_DOCUMENT_INITIATOR) + person.getName(), ArConstants.PdfReportFonts.LOC_REVIEW_HEADER_FONT)); title.add(new Paragraph( configService .getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_HEADER_DOCUMENT_CREATE_DATE) + getDateTimeService().toDateString( locDocument.getFinancialSystemDocumentHeader().getWorkflowCreateDate()), ArConstants.PdfReportFonts.LOC_REVIEW_HEADER_FONT)); title.add(new Paragraph(KFSConstants.BLANK_SPACE)); title.setAlignment(Element.ALIGN_RIGHT); text.add(new Paragraph( configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_SUBHEADER_AWARDS), ArConstants.PdfReportFonts.LOC_REVIEW_SMALL_BOLD)); text.add(new Paragraph(KFSConstants.BLANK_SPACE)); document.add(header); document.add(title); document.add(text); PdfPTable table = new PdfPTable(11); table.setTotalWidth(ArConstants.LOCReviewPdf.RESULTS_TABLE_WIDTH); // fix the absolute width of the table table.setLockedWidth(true); // relative col widths in proportions - 1/11 float[] widths = new float[] { 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f }; table.setWidths(widths); table.setHorizontalAlignment(0); addAwardHeaders(table); if (CollectionUtils.isNotEmpty(locDocument.getHeaderReviewDetails()) && CollectionUtils.isNotEmpty(locDocument.getAccountReviewDetails())) { for (ContractsGrantsLetterOfCreditReviewDetail item : locDocument.getHeaderReviewDetails()) { table.addCell(Long.toString(item.getProposalNumber())); table.addCell(item.getAwardDocumentNumber()); table.addCell(item.getAgencyNumber()); table.addCell(item.getCustomerNumber()); table.addCell(getDateTimeService().toDateString(item.getAwardBeginningDate())); table.addCell(getDateTimeService().toDateString(item.getAwardEndingDate())); table.addCell( contractsGrantsBillingUtilityService.formatForCurrency(item.getAwardBudgetAmount())); table.addCell( contractsGrantsBillingUtilityService.formatForCurrency(item.getLetterOfCreditAmount())); table.addCell( contractsGrantsBillingUtilityService.formatForCurrency(item.getClaimOnCashBalance())); table.addCell(contractsGrantsBillingUtilityService.formatForCurrency(item.getAmountToDraw())); table.addCell(contractsGrantsBillingUtilityService .formatForCurrency(item.getAmountAvailableToDraw())); PdfPCell cell = new PdfPCell(); cell.setPadding(ArConstants.LOCReviewPdf.RESULTS_TABLE_CELL_PADDING); cell.setColspan(ArConstants.LOCReviewPdf.RESULTS_TABLE_COLSPAN); PdfPTable newTable = new PdfPTable(ArConstants.LOCReviewPdf.INNER_TABLE_COLUMNS); newTable.setTotalWidth(ArConstants.LOCReviewPdf.INNER_TABLE_WIDTH); // fix the absolute width of the newTable newTable.setLockedWidth(true); // relative col widths in proportions - 1/8 float[] newWidths = new float[] { 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f }; newTable.setWidths(newWidths); newTable.setHorizontalAlignment(0); addAccountsHeaders(newTable); for (ContractsGrantsLetterOfCreditReviewDetail newItem : locDocument .getAccountReviewDetails()) { if (item.getProposalNumber().equals(newItem.getProposalNumber())) { newTable.addCell(newItem.getAccountDescription()); newTable.addCell(newItem.getChartOfAccountsCode()); newTable.addCell(newItem.getAccountNumber()); String accountExpirationDate = KFSConstants.EMPTY_STRING; if (!ObjectUtils.isNull(newItem.getAccountExpirationDate())) { accountExpirationDate = getDateTimeService() .toDateString(newItem.getAccountExpirationDate()); } newTable.addCell(accountExpirationDate); newTable.addCell(contractsGrantsBillingUtilityService .formatForCurrency(newItem.getAwardBudgetAmount())); newTable.addCell(contractsGrantsBillingUtilityService .formatForCurrency(newItem.getClaimOnCashBalance())); newTable.addCell(contractsGrantsBillingUtilityService .formatForCurrency(newItem.getAmountToDraw())); newTable.addCell(contractsGrantsBillingUtilityService .formatForCurrency(newItem.getFundsNotDrawn())); } } cell.addElement(newTable); table.addCell(cell); } document.add(table); } document.close(); } catch (DocumentException e) { LOG.error("problem during ContractsGrantsInvoiceReportServiceImpl.generateInvoiceInPdf()", e); } }
From source file:org.mapfish.print.config.layout.ColumnsBlock.java
License:Open Source License
public void render(final PJsonObject params, PdfElement target, final RenderingContext context) throws DocumentException { if (isAbsolute()) { context.getCustomBlocks().addAbsoluteDrawer(new PDFCustomBlocks.AbsoluteDrawer() { public void render(PdfContentByte dc) throws DocumentException { final PdfPTable table = PDFUtils.buildTable(items, params, context, nbColumns, config); if (table != null) { table.setTotalWidth(width); table.setLockedWidth(true); if (widths != null) { table.setWidths(widths); }/*ww w . j av a2s . c om*/ table.writeSelectedRows(0, -1, absoluteX, absoluteY, dc); } } }); } else { final PdfPTable table = PDFUtils.buildTable(items, params, context, nbColumns, config); if (table != null) { if (widths != null) { table.setWidths(widths); } table.setSpacingAfter((float) spacingAfter); target.add(table); } } }
From source file:org.mapfish.print.config.layout.HeaderFooter.java
License:Open Source License
public void render(final Rectangle rectangle, PdfContentByte dc, PJsonObject params, RenderingContext context) { try {/*from ww w .j a v a 2s . c o m*/ final PdfPTable table = PDFUtils.buildTable(items, params, context, 1/*multiple items are arranged by lines*/, null); if (table != null) { table.setTotalWidth(rectangle.getWidth()); table.writeSelectedRows(0, -1, rectangle.getLeft(), rectangle.getTop(), dc); } } catch (DocumentException e) { context.addError(e); } }
From source file:org.mapfish.print.config.layout.PivotTableBlock.java
License:Open Source License
public void render(final PJsonObject params, PdfElement target, final RenderingContext context) throws DocumentException { if (isAbsolute()) { context.getCustomBlocks().addAbsoluteDrawer(new PDFCustomBlocks.AbsoluteDrawer() { public void render(PdfContentByte dc) throws DocumentException { final PdfPTable table = buildPivotTable(params, context, tableConfig); if (table != null) { table.setTotalWidth(width); table.setLockedWidth(true); if (widths != null) { table.setWidths(widths); }/*from w w w . ja v a 2s . co m*/ table.writeSelectedRows(0, -1, absoluteX, absoluteY, dc); } } }); } else { final PdfPTable table = buildPivotTable(params, context, tableConfig); if (table != null) { if (widths != null) { table.setWidths(widths); } table.setSpacingAfter((float) spacingAfter); target.add(table); } } }
From source file:org.mapfish.print.PDFUtils.java
License:Open Source License
/** * When we have to do some custom drawing in a block that is layed out by * iText, we first give an empty table with the good dimensions to iText, * then iText will call a callback with the actual position. When that * happens, we use the given drawer to do the actual drawing. *//*from w w w .ja v a 2 s.co m*/ public static PdfPTable createPlaceholderTable(double width, double height, double spacingAfter, ChunkDrawer drawer, HorizontalAlign align, PDFCustomBlocks customBlocks) { PdfPTable placeHolderTable = new PdfPTable(1); placeHolderTable.setLockedWidth(true); placeHolderTable.setTotalWidth((float) width); final PdfPCell placeHolderCell = new PdfPCell(); placeHolderCell.setMinimumHeight((float) height); placeHolderCell.setPadding(0f); placeHolderCell.setBorder(PdfPCell.NO_BORDER); placeHolderTable.addCell(placeHolderCell); customBlocks.addChunkDrawer(drawer); placeHolderTable.setTableEvent(drawer); placeHolderTable.setComplete(true); final PdfPCell surroundingCell = new PdfPCell(placeHolderTable); surroundingCell.setPadding(0f); surroundingCell.setBorder(PdfPCell.NO_BORDER); if (align != null) { placeHolderTable.setHorizontalAlignment(align.getCode()); surroundingCell.setHorizontalAlignment(align.getCode()); } PdfPTable surroundingTable = new PdfPTable(1); surroundingTable.setSpacingAfter((float) spacingAfter); surroundingTable.addCell(surroundingCell); surroundingTable.setComplete(true); return surroundingTable; }
From source file:org.oscarehr.common.service.PdfRecordPrinter.java
License:Open Source License
public void printSpecsHistory(List<EyeformSpecsHistory> specsHistory) throws DocumentException { ProviderDao providerDao = (ProviderDao) SpringUtils.getBean("providerDao"); /*/* w ww . ja v a2 s . com*/ if( getNewPage() ) getDocument().newPage(); else setNewPage(true); */ Font obsfont = new Font(getBaseFont(), FONTSIZE, Font.UNDERLINE); Paragraph p = new Paragraph(); p.setAlignment(Paragraph.ALIGN_LEFT); Phrase phrase = new Phrase(LEADING, "\n", getFont()); p.add(phrase); phrase = new Phrase(LEADING, "Specs History", obsfont); p.add(phrase); getDocument().add(p); PdfPTable table = new PdfPTable(2); table.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table.setSpacingBefore(10f); table.setSpacingAfter(10f); table.setTotalWidth(new float[] { 10f, 60f }); table.setTotalWidth(5f); table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); for (EyeformSpecsHistory specs : specsHistory) { PdfPCell cell1 = new PdfPCell(new Phrase(getFormatter().format(specs.getDate()), getFont())); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); table.addCell(cell1); PdfPCell cell2 = new PdfPCell(new Phrase(specs.toString2(), getFont())); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); table.addCell(cell2); } getDocument().add(table); }
From source file:org.posterita.core.TabularReport.java
License:Open Source License
public byte[] getPDFData() throws DocumentException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4); PdfWriter pdfWriter = PdfWriter.getInstance(document, bos); document.open();//www. j a va 2 s .com // Font Syle Font style1 = new Font(Font.TIMES_ROMAN, 12.0f, Font.BOLD); Font style2 = new Font(Font.TIMES_ROMAN, 8.0f, Font.BOLD); Font style3 = new Font(Font.TIMES_ROMAN, 8.0f); Font style4 = new Font(Font.TIMES_ROMAN, 9.0f, Font.BOLD); float[] widths = { 2f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f }; // Table header PdfPTable mytable = new PdfPTable(7); mytable.setTotalWidth(widths); mytable.setWidthPercentage(100f); PdfPCell header = new PdfPCell(new Paragraph(getTitle() + "\n" + getSubtitle(), style1)); header.setColspan(7); header.setHorizontalAlignment(Element.ALIGN_CENTER); header.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); mytable.addCell(header); // Table sub header PdfPCell subheader = new PdfPCell(); subheader = new PdfPCell(new Paragraph("")); mytable.addCell(subheader); subheader = new PdfPCell(new Paragraph("QUANTITY", style2)); subheader.setColspan(2); subheader.setHorizontalAlignment(Element.ALIGN_CENTER); mytable.addCell(subheader); subheader = new PdfPCell(new Paragraph("VALUE (Excl. VAT)", style2)); subheader.setColspan(2); subheader.setHorizontalAlignment(Element.ALIGN_CENTER); mytable.addCell(subheader); subheader = new PdfPCell(new Paragraph("DISCREPANCY", style2)); subheader.setColspan(2); subheader.setHorizontalAlignment(Element.ALIGN_CENTER); mytable.addCell(subheader); // Rows Header PdfPCell rowHeader = new PdfPCell(new Paragraph("PRODUCT NAME", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("BOOK", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("COUNT", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("BOOK", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("COUNT", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("QTY", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("VALUE", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); document.add(mytable); Object[] headers = reportData.get(0); PdfPTable table = new PdfPTable(headers.length); table.setTotalWidth(widths); table.setWidthPercentage(100f); for (Object[] row : reportData) { for (Object data : row) { PdfPCell dataCell = new PdfPCell(new Phrase(data.toString(), style3)); table.addCell(dataCell); } } document.add(table); document.close(); return bos.toByteArray(); }