List of usage examples for com.lowagie.text Rectangle BOTTOM
int BOTTOM
To view the source code for com.lowagie.text Rectangle BOTTOM.
Click Source Link
Rectangle
. From source file:org.areasy.common.doclet.document.tags.TagPRE.java
License:Open Source License
/** * Creates a PRE tag object./* w w w . ja v a 2 s . c o m*/ * * @param parent The parent HTML object. * @param type The type for this tag. */ public TagPRE(HtmlTag parent, int type) { super(parent, type); setPre(true); cellPara = new Paragraph("", getFont()); colorTitleCell = new PdfPCell(cellPara); colorTitleCell.setBorder(Rectangle.TOP + Rectangle.LEFT + Rectangle.RIGHT + Rectangle.BOTTOM); colorTitleCell.setPadding(6); colorTitleCell.setPaddingBottom(12); colorTitleCell.setPaddingLeft(10); colorTitleCell.setPaddingRight(10); colorTitleCell.setBorderWidth(1); colorTitleCell.setBorderColor(Color.gray); colorTitleCell.setBackgroundColor(COLOR_LIGHTER_GRAY); colorTitleCell.addElement(cellPara); mainTable.addCell(colorTitleCell); }
From source file:org.egov.works.web.actions.estimate.EstimatePDFGenerator.java
License:Open Source License
public void generatePDF() { try {// www. j av a 2 s . c o m final Paragraph headerTextPara = new Paragraph( new Chunk(headerText, new Font(Font.UNDEFINED, LARGE_FONT, Font.BOLD))); String projectCode; final String oldEstNo = ""; HeaderFooter hf; headerTextPara.setAlignment(Element.ALIGN_CENTER); document.add(headerTextPara); document.add(makePara("Executing Department:" + estimate.getExecutingDepartment().getName(), Element.ALIGN_LEFT)); if (estimate.getUserDepartment() != null) document.add( makePara("User Department:" + estimate.getUserDepartment().getName(), Element.ALIGN_LEFT)); final CFinancialYear estimateFinancialYear = estimate.getMultiYearEstimates().get(0).getFinancialYear(); addZoneYearHeader(estimate, estimateFinancialYear); document.add(makePara("Name of Work: " + estimate.getName(), Element.ALIGN_LEFT)); document.add(makePara("Description: " + estimate.getDescription(), Element.ALIGN_LEFT)); if (estimate.getProjectCode() != null) { projectCode = "Project Code : " + estimate.getProjectCode().getCode(); document.add(makePara(projectCode, Element.ALIGN_LEFT)); hf = new HeaderFooter(new Phrase("\t \t \t \t \t \t \t \t \t \t \t \t \t \t \t" + "\t \t \t \t \t\t \t \t \t \t\t \t \t \t \t\t \t \t " + "\t \t \t \t \t\t \t \t \t \t" + headerText.concat("\n") .concat("\t \t \t \t \t \t \t \t \t \t" + "\t \t \t \t \t\t \t \t \t \t\t \t \t \t \t\t \t \t " + "\t \t \t \t \t\t \t \t \t \t ABSTRACT ESTIMATE") .concat("\n\n").concat("Name of Work: " + estimate.getName()).concat("\n") .concat("Description: " + estimate.getDescription()).concat("\n") .concat("Estimate Number: " + estimate.getEstimateNumber()).concat(oldEstNo) .concat("\n").concat(projectCode)), false); } else hf = new HeaderFooter(new Phrase("\t \t \t \t \t \t \t \t \t \t \t \t \t \t \t" + "\t \t \t \t \t\t \t \t \t \t\t \t \t \t \t\t \t \t " + "\t \t \t \t \t\t \t \t \t \t" + headerText.concat("\n") .concat("\t \t \t \t \t \t \t \t \t \t" + "\t \t \t \t \t\t \t \t \t \t\t \t \t \t \t\t \t \t " + "\t \t \t \t \t\t \t \t \t \t ABSTRACT ESTIMATE") .concat("\n\n").concat("Name of Work: " + estimate.getName()).concat("\n") .concat("Description: " + estimate.getDescription()).concat("\n") .concat("Estimate Number: " + estimate.getEstimateNumber()).concat(oldEstNo)), false); hf.disableBorderSide(Rectangle.TOP); hf.disableBorderSide(Rectangle.BOTTOM); hf.setLeft(Element.ALIGN_LEFT); document.setHeader(hf); final PdfPTable overheadsTable = createOverheadsTable(estimate); document.add(spacer()); document.add(overheadsTable); document.add(spacer()); final PdfPTable multiyearTable = createMultiYearTable(estimate); document.add(makePara("Year-wise Estimate")); document.add(spacer()); document.add(multiyearTable); document.add(spacer()); document.add(makePara("Estimate Created By: " + estimate.getCreatedBy().getName())); document.add(spacer()); document.add(spacer()); document.add(makePara("Checked By: ")); document.newPage(); addZoneYearHeaderWithOutEstimateNo(estimate, estimateFinancialYear); document.add(createActivitiesTable(estimate)); document.add(spacer()); final PdfPTable approvaldetailsTable = createApprovalDetailsTable(estimate); // TODO:Fixme - commented final out workflow history final details since ordering final of approval is final not // getting final listed properly /* * if (approvaldetailsTable.getRows().size() != 1) { document.add(makePara("Approval Details")); * document.add(spacer()); document.add(approvaldetailsTable); } */ final String appropriationNumber = abstractEstimateService .getLatestEstimateAppropriationNumber(estimate); if (isSkipBudgetCheck()) { final PdfPTable depositWorksAppropriationTable = createDepositAppropriationTable(estimate, appropriationNumber); if (depositWorksAppropriationTable.getRows().size() != 1) if (appropriationNumber != null) { document.newPage(); document.add(spacer()); document.add(makePara("Deposit Code Appropriation Details")); document.add(spacer()); document.add(depositWorksAppropriationTable); } } else { final PdfPTable BudgetaryAppropriationTable = createBudgetaryAppropriationTable(estimate, appropriationNumber); final String estimateNumber = estimate.getEstimateNumber(); if (BudgetaryAppropriationTable.getRows().size() != 1) if (!getBudgetDetailUsage(estimateNumber).isEmpty() && appropriationNumber != null) { document.newPage(); document.add(spacer()); document.add(makePara("Budgetary Appropriation")); document.add(spacer()); document.add(BudgetaryAppropriationTable); } } document.newPage(); document.add(spacer()); document.add(makePara( "EXECUTIVE ENGINEER'S OFFICE, ZONE.......................................................................", Element.ALIGN_LEFT)); document.add(spacer()); document.add(makePara( "Est No. Unit: Dept.", Element.ALIGN_LEFT)); document.add(spacer()); final Paragraph budgetheadTextPara = new Paragraph( new Chunk("BUDGET HEAD", new Font(Font.UNDEFINED, LARGE_FONT, Font.BOLD))); budgetheadTextPara.setAlignment(Element.ALIGN_CENTER); document.add(budgetheadTextPara); document.add(spacer()); document.add(makePara("____________________________________________________________________________", Element.ALIGN_LEFT)); document.add(makePara("Rs. ", Element.ALIGN_LEFT)); document.add(makePara("____________________________________________________________________________", Element.ALIGN_LEFT)); document.add(makePara("Works: ", Element.ALIGN_LEFT)); document.add(spacer()); document.add(spacer()); final Paragraph memoTextPara = new Paragraph( new Chunk("MEMO", new Font(Font.UNDEFINED, LARGE_FONT, Font.BOLD))); memoTextPara.setAlignment(Element.ALIGN_CENTER); document.add(memoTextPara); document.add(makePara("Budget Grant ", Element.ALIGN_LEFT)); document.add(makePara("Amount Appropriated:__________________________________________________________", Element.ALIGN_LEFT)); document.add(makePara("Balance on Hand: ", Element.ALIGN_LEFT)); document.add( makePara("Amount of this estimate_________________________________________________________", Element.ALIGN_LEFT)); document.add(makePara("Balance forward_______________________________________________________________", Element.ALIGN_LEFT)); document.add( makePara("Submitted for favour of sanction ", Element.ALIGN_LEFT)); document.add(spacer()); document.add(spacer()); document.add( makePara("A.E.E.Unit " + space1 + "\t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t" + "Exe.Eng.Zone.....................", Element.ALIGN_LEFT)); document.add(spacer()); document.add(makePara("Sanctioned", Element.ALIGN_CENTER)); document.add(spacer()); document.add(spacer()); document.add(makePara("DATE:" + space1 + "\t \t \t \t \t \t \t \t \t \t \t \t\t \t \t \t \t \t \t \t \t \t \t \t" + "Asst.Commissioner Zone...............", Element.ALIGN_LEFT)); document.add(spacer()); document.add(makePara( space1 + "\t \t \t \t \t \t \t \t \t \t \t \t\t \t \t \t \t \t \t \t \t \t \t \t" + "APPROPRIATION No.", Element.ALIGN_LEFT)); document.add(makePara(space1 + "\t \t \t \t \t \t \t \t \t \t \t \t" + "\t \t \t \t \t \t \t \t \t \t \t \t \t \t \t" + "Date:", Element.ALIGN_LEFT)); // WF for signature ----- if (approvaldetailsTable.getRows().size() != 1) if (shouldShowApprovalNumber) { document.resetHeader(); document.newPage(); document.add( makePara("\t \t \t \t \t \t \t \t \t \t \t \t \t \t \t" + "\t \t \t \t \t\t \t \t \t \t\t \t \t \t \t\t \t \t " + "\t \t \t \t \t\t \t \t \t \t" + headerText.concat("\n").concat("\t \t \t \t \t \t \t \t \t \t" + "\t \t \t \t \t\t \t \t \t \t\t \t \t \t \t\t \t \t " + "\t \t \t \t \t\t \t \t \t \t ABSTRACT ESTIMATE") .concat("\n\n"))); document.add( makePara( "File Current Number :" + space1 + "\t \t \t \t \t \t \t \t \t \t \t \t \t " + "Date: \t \t", Element.ALIGN_LEFT)); document.add(makePara(space1 + "\t \t \t \t \t \t \t \t \t \t \t \t\t \t \t \t \t \t \t \t \t \t \t " + "Department : ", Element.ALIGN_LEFT)); document.add(spacer()); final Paragraph headingPara1 = new Paragraph( new Chunk("NOTE FOR ADMINISTRATIVE SANCTION AS PER RULE 78 OF ", new Font(Font.UNDEFINED, LARGE_FONT, Font.BOLD))); headingPara1.setAlignment(Element.ALIGN_CENTER); document.add(headingPara1); final Paragraph headingPara2 = new Paragraph( new Chunk("MCMC ACT 1919 ", new Font(Font.UNDEFINED, LARGE_FONT, Font.BOLD))); headingPara2.setAlignment(Element.ALIGN_CENTER); document.add(headingPara2); document.add(spacer()); final PdfPTable estimateDetailsTable1 = createEstimateDetailsTable1(estimate); document.add(estimateDetailsTable1); final PdfPTable budgetDetailsTableFourCols = createBudgetDetailsForEstimateTable(estimate); document.add(budgetDetailsTableFourCols); final PdfPTable estimateDetailsTable2 = createBalanceAmtCalculationTable(estimate); document.add(estimateDetailsTable2); document.add(spacer()); final Paragraph endTextPara = new Paragraph( new Chunk("** END **", new Font(Font.UNDEFINED, LARGE_FONT, Font.BOLD))); endTextPara.setAlignment(Element.ALIGN_CENTER); document.add(endTextPara); } document.close(); } catch (final DocumentException e) { throw new ApplicationRuntimeException("estimate.pdf.error", e); } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.itext.PatchRtfBorderGroup.java
License:Open Source License
/** * Adds borders to the PatchRtfBorderGroup * * @param bordersToAdd//from www .j a v a 2s . co m * The borders to add (Rectangle.LEFT, Rectangle.RIGHT, Rectangle.TOP, Rectangle.BOTTOM, Rectangle.BOX) * @param borderStyle * The style of border to add (from PatchRtfBorder) * @param borderWidth * The border width to use * @param borderColor * The border color to use */ public void addBorder(int bordersToAdd, int borderStyle, float borderWidth, Color borderColor) { if ((bordersToAdd & Rectangle.LEFT) == Rectangle.LEFT) { setBorder(PatchRtfBorder.LEFT_BORDER, borderStyle, borderWidth, borderColor); } if ((bordersToAdd & Rectangle.TOP) == Rectangle.TOP) { setBorder(PatchRtfBorder.TOP_BORDER, borderStyle, borderWidth, borderColor); } if ((bordersToAdd & Rectangle.RIGHT) == Rectangle.RIGHT) { setBorder(PatchRtfBorder.RIGHT_BORDER, borderStyle, borderWidth, borderColor); } if ((bordersToAdd & Rectangle.BOTTOM) == Rectangle.BOTTOM) { setBorder(PatchRtfBorder.BOTTOM_BORDER, borderStyle, borderWidth, borderColor); } if ((bordersToAdd & Rectangle.BOX) == Rectangle.BOX && this.borderType == PatchRtfBorder.ROW_BORDER) { setBorder(PatchRtfBorder.VERTICAL_BORDER, borderStyle, borderWidth, borderColor); setBorder(PatchRtfBorder.HORIZONTAL_BORDER, borderStyle, borderWidth, borderColor); } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.itext.PatchRtfBorderGroup.java
License:Open Source License
/** * Removes borders from the list of borders * * @param bordersToRemove//from w w w . j ava 2 s .c o m * The borders to remove (from Rectangle) */ public void removeBorder(int bordersToRemove) { if ((bordersToRemove & Rectangle.LEFT) == Rectangle.LEFT) { this.borders.remove(new Integer(PatchRtfBorder.LEFT_BORDER)); } if ((bordersToRemove & Rectangle.TOP) == Rectangle.TOP) { this.borders.remove(new Integer(PatchRtfBorder.TOP_BORDER)); } if ((bordersToRemove & Rectangle.RIGHT) == Rectangle.RIGHT) { this.borders.remove(new Integer(PatchRtfBorder.RIGHT_BORDER)); } if ((bordersToRemove & Rectangle.BOTTOM) == Rectangle.BOTTOM) { this.borders.remove(new Integer(PatchRtfBorder.BOTTOM_BORDER)); } if ((bordersToRemove & Rectangle.BOX) == Rectangle.BOX && this.borderType == PatchRtfBorder.ROW_BORDER) { this.borders.remove(new Integer(PatchRtfBorder.VERTICAL_BORDER)); this.borders.remove(new Integer(PatchRtfBorder.HORIZONTAL_BORDER)); } }
From source file:org.revager.export.PDFExporter.java
License:Open Source License
/** * Creates an empty PdfPTable cell with a defined height and colspan. * /*from w w w.j a va 2s. c o m*/ * @param height * the height of the created cell * @param colspan * the colspan * * @return Empty cell with defined minimum height */ protected PdfPCell createVerticalStrut(float height, int colspan) { PdfPCell fill = new PdfPCell(); fill.setColspan(colspan); fill.setMinimumHeight(height); fill.disableBorderSide(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP | Rectangle.BOTTOM); return fill; }
From source file:org.sonarqube.report.extendedpdf.OverviewPDFReporter.java
License:Open Source License
protected void printFrontPage(Document frontPageDocument, PdfWriter frontPageWriter) throws org.dom4j.DocumentException, ReportException { String frontPageTemplate = "/templates/frontpage.pdf"; try {//www . ja va2s . c o m PdfContentByte cb = frontPageWriter.getDirectContent(); PdfReader reader = new PdfReader(this.getClass().getResourceAsStream(frontPageTemplate)); PdfImportedPage page = frontPageWriter.getImportedPage(reader, 1); frontPageDocument.newPage(); cb.addTemplate(page, 0, 0); Project project = getProject(); Rectangle pageSize = frontPageDocument.getPageSize(); PdfPTable projectInfo = new PdfPTable(1); projectInfo.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE); projectInfo.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); projectInfo.getDefaultCell().setBorder(Rectangle.BOTTOM); projectInfo.getDefaultCell().setPaddingBottom(10); projectInfo.getDefaultCell().setBorderColor(Color.GRAY); Font font = FontFactory.getFont(FontFactory.COURIER, 18, Font.NORMAL, Color.LIGHT_GRAY); Phrase projectName = new Phrase("Project: " + project.getName(), font); projectInfo.addCell(projectName); Phrase projectVersion = new Phrase("Version: " + project.getMeasures().getVersion(), font); projectInfo.addCell(projectVersion); SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm"); Phrase projectAnalysisDate = new Phrase("Analysis Date: " + df.format(project.getMeasures().getDate()), font); projectInfo.addCell(projectAnalysisDate); projectInfo.setTotalWidth( pageSize.getWidth() - frontPageDocument.leftMargin() * 2 - frontPageDocument.rightMargin() * 2); projectInfo.writeSelectedRows(0, -1, frontPageDocument.leftMargin(), pageSize.getHeight() - 575, frontPageWriter.getDirectContent()); projectInfo.setSpacingAfter(10); } catch (IOException e) { Logger.error("Cannot find the required template: " + frontPageTemplate); e.printStackTrace(); } }
From source file:org.unitime.timetable.export.PDFPrinter.java
License:Open Source License
@Override public void printHeader(String... fields) { iTable = new PdfPTable(fields.length - iHiddenColumns.size()); iMaxWidth = new float[fields.length]; iTable.setHeaderRows(1);/* w w w. ja va 2 s . co m*/ iTable.setWidthPercentage(100); for (int idx = 0; idx < fields.length; idx++) { if (iHiddenColumns.contains(idx)) continue; String f = fields[idx]; PdfPCell cell = new PdfPCell(); cell.setBorder(Rectangle.BOTTOM); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_LEFT); Font font = PdfFont.getFont(true); cell.addElement(new Chunk(f, font)); iTable.addCell(cell); float width = 0; if (f.indexOf('\n') >= 0) { for (StringTokenizer s = new StringTokenizer(f, "\n"); s.hasMoreTokens();) width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize())); } else width = Math.max(width, font.getBaseFont().getWidthPoint(f, font.getSize())); iMaxWidth[idx] = width; } }
From source file:permit.InvoicePdf.java
License:Open Source License
void writePages(HttpServletResponse res, Invoice invoice) { ///* ww w. jav a 2s.c o m*/ // paper size legal (A4) 8.5 x 11 // page 1-inch = 72 points // String fileName = "row_invoice_" + invoice.getInvoice_num() + ".pdf"; Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11" Document document = new Document(pageSize, 36, 36, 18, 18); ServletOutputStream out = null; Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL); Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD); Font fnts = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL); Font fntbs = new Font(Font.TIMES_ROMAN, 8, Font.BOLD); String spacer = " "; PdfPTable header = getHeader(); Company company = invoice.getCompany(); Contact contact = null; if (invoice.hasContact()) { contact = invoice.getContact(); } List<Page> pages = invoice.getPages(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); String str = ""; document.open(); document.add(header); // // title float[] width = { 100f }; // one cell PdfPTable table = new PdfPTable(width); table.setWidthPercentage(100.0f); PdfPCell cell = new PdfPCell(new Phrase("INVOICE", fntb)); // cell.setBorder(Rectangle.BOTTOM); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); document.add(table); // // we need these later Paragraph pp = new Paragraph(); Chunk ch = new Chunk(" ", fntb); Phrase phrase = new Phrase(); // float[] widths = { 35f, 30f, 35f }; // percentages table = new PdfPTable(widths); table.setWidthPercentage(100.0f); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); // // first row float[] widthOne = { 100f }; PdfPTable leftTable = new PdfPTable(widthOne); leftTable.setWidthPercentage(35.0f); leftTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); // if (company != null) { ch = new Chunk("Company\n", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); phrase = new Phrase(); ch = new Chunk(company.getName() + "\n", fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); } if (contact != null) { phrase = new Phrase(); ch = new Chunk(contact.getFullName(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); phrase = new Phrase(); ch = new Chunk(contact.getAddress(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); ch = new Chunk(contact.getCityStateZip(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); } table.addCell(leftTable); // // middle cell // cell = new PdfPCell(new Phrase(spacer, fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); // float[] widths2 = { 50f, 50f }; // percentages PdfPTable rightTable = new PdfPTable(widths2); rightTable.setWidthPercentage(35.0f); rightTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); // ch = new Chunk("Invoice No.", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk(invoice.getInvoice_num(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("Status", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk(invoice.getStatus(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("Invoice Date", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk(invoice.getDate(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("From ", fntb); phrase = new Phrase(); phrase.add(ch); ch = new Chunk(invoice.getStart_date(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("To ", fntb); phrase = new Phrase(); phrase.add(ch); ch = new Chunk(invoice.getEnd_date(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); table.addCell(rightTable); // // document.add(table); // phrase = new Phrase(new Chunk(spacer, fnt)); document.add(phrase); // int jj = 0; if (pages != null) { for (Page page : pages) { jj++; // float[] widthOne = {100f}; PdfPTable borderTable = new PdfPTable(widthOne); borderTable.setWidthPercentage(100.0f); borderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); float[] widthTwo = { 50f, 50f }; PdfPTable titleTable = new PdfPTable(widthTwo); titleTable.setWidthPercentage(75.0f); titleTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); phrase = new Phrase("Invoice No. ", fntb); ch = new Chunk(invoice.getInvoice_num(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Rectangle.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); titleTable.addCell(cell); // phrase = new Phrase(page.getPage_num(), fnt); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT); cell.setBorder(Rectangle.NO_BORDER); titleTable.addCell(cell); // borderTable.addCell(titleTable); float[] width4 = { 25f, 40f, 25f, 10f }; PdfPTable contTable = new PdfPTable(width4); cell = new PdfPCell(new Phrase("Excavation Permit Number", fntb)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("Project", fntb)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("Date Issued", fntb)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("Permit Fee", fntb)); contTable.addCell(cell); List<Permit> permits = page.getPermits(); if (permits != null) { for (Permit permit : permits) { cell = new PdfPCell(new Phrase(permit.getPermit_num(), fnt)); contTable.addCell(cell); phrase = new Phrase(permit.getProject() + "\n", fnt); List<Excavation> cuts = permit.getExcavations(); if (cuts != null) { for (Excavation one : cuts) { ch = new Chunk(one.getAddress() + " (" + one.getCut_type() + ")", fnt); phrase.add(ch); } } cell = new PdfPCell(phrase); contTable.addCell(cell); cell = new PdfPCell(new Phrase(permit.getDate(), fnt)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("$" + permit.getFee(), fnt)); cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT); contTable.addCell(cell); cell = new PdfPCell(new Phrase(spacer, fnt)); // // space line cell.setColspan(4); contTable.addCell(cell); } } if (page.getNeededLines() > 0) { // first page for (int j = 0; j < page.getNeededLines(); j++) { cell = new PdfPCell(new Phrase(spacer, fnt)); contTable.addCell(cell); contTable.addCell(cell); contTable.addCell(cell); contTable.addCell(cell); } } if (jj == pages.size()) { cell = new PdfPCell(new Phrase("Total Invoice Amount\n" + invoice.getTotal(), fntb)); cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT); cell.setColspan(4); contTable.addCell(cell); } borderTable.addCell(contTable); cell = new PdfPCell(new Phrase( "Payment due upon receipt. Please Make check payable to 'City of Bloomington'. Thank You.", fnt)); cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); cell.setBorder(Rectangle.NO_BORDER); borderTable.addCell(cell); borderTable.addCell(titleTable); // invoice and date document.add(borderTable); if (jj < pages.size()) { document.newPage(); } } } // document.close(); writer.close(); res.setHeader("Expires", "0"); res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); // // if you want for users to download, uncomment the following line // // res.setHeader("Content-Disposition","attachment; filename="+fileName); res.setHeader("Pragma", "public"); // // setting the content type res.setContentType("application/pdf"); // // the contentlength is needed for MSIE!!! res.setContentLength(baos.size()); // out = res.getOutputStream(); if (out != null) { baos.writeTo(out); } } catch (Exception ex) { logger.error(ex); } }
From source file:permit.PermitPdf.java
License:Open Source License
void writePage(HttpServletResponse res, Permit permit) { ////from ww w . j a v a2s. c om // paper size legal (A4) 8.5 x 11 // page 1-inch = 72 points // String fileName = "row_permit_" + permit.getId() + ".pdf"; Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11" Document document = new Document(pageSize, 36, 36, 18, 18); ServletOutputStream out = null; Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL); Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD); Font fnts = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL); Font fntbs = new Font(Font.TIMES_ROMAN, 8, Font.BOLD); String spacer = " "; PdfPTable header = getHeader(); Bond bond = permit.getBond(); Invoice invoice = permit.getInvoice(); if (bond == null) bond = new Bond(); if (invoice == null) invoice = new Invoice(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); String str = ""; document.open(); document.add(header); // // title float[] width = { 100f }; // one cell PdfPTable table = new PdfPTable(width); table.setWidthPercentage(100.0f); PdfPCell cell = new PdfPCell(new Phrase("Right Of Way Excavation Permit", fntb)); // cell.setBorder(Rectangle.BOTTOM); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); document.add(table); // // we need these later Paragraph pp = new Paragraph(); Chunk ch = new Chunk(" ", fntb); Phrase phrase = new Phrase(); // float[] widths = { 14f, 20f, 17f, 18f, 13f, 20f }; // percentages table = new PdfPTable(widths); table.setWidthPercentage(100.0f); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); // // first row cell = new PdfPCell(new Phrase("Company", fntb)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(permit.getCompany().getName(), fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Status", fntb)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(permit.getStatus(), fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Permit", fntb)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(permit.getPermit_num(), fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); // // 2nd row // cell = new PdfPCell(new Phrase("Responsible", fntb)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(permit.getContact().getFullName(), fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Inspector", fntb)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(permit.getReviewer().getFullName(), fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Date Issued", fntb)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(permit.getDate(), fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); // // 3rd row cell = new PdfPCell(new Phrase("Project", fntb)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(permit.getProject(), fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Permit Fee", fntb)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("$" + permit.getFee(), fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Start Date", fntb)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(permit.getStart_date(), fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); // // 4th row cell = new PdfPCell(new Phrase("Bond Amount", fntb)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("$" + bond.getAmount(), fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Expiration Date", fntb)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(bond.getExpire_date(), fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Invoice", fntb)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(invoice.getStatus(), fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); document.add(table); // phrase = new Phrase(new Chunk(spacer, fnt)); document.add(phrase); // float[] widths2 = { 25f, 15f, 15f, 25f, 10f, 10f }; table = new PdfPTable(widths2); table.setWidthPercentage(100.0f); cell = new PdfPCell(new Phrase("Address", fntb)); table.addCell(cell); cell = new PdfPCell(new Phrase("Cut Type", fntb)); table.addCell(cell); cell = new PdfPCell(new Phrase("Utility", fntb)); table.addCell(cell); cell = new PdfPCell(new Phrase("Description", fntb)); table.addCell(cell); cell = new PdfPCell(new Phrase("Width", fntb)); table.addCell(cell); cell = new PdfPCell(new Phrase("Length", fntb)); table.addCell(cell); List<Excavation> list = permit.getExcavations(); if (list != null && list.size() > 0) { for (Excavation one : list) { cell = new PdfPCell(new Phrase(one.getAddress().getAddress(), fnt)); table.addCell(cell); cell = new PdfPCell(new Phrase(one.getCut_type(), fnt)); table.addCell(cell); cell = new PdfPCell(new Phrase(one.getUtility_type().getName(), fnt)); table.addCell(cell); cell = new PdfPCell(new Phrase(one.getCut_description(), fnt)); table.addCell(cell); cell = new PdfPCell(new Phrase(one.getWidth(), fnt)); table.addCell(cell); cell = new PdfPCell(new Phrase(one.getLength(), fnt)); table.addCell(cell); } } document.add(table); // pp = new Paragraph(); pp.setIndentationLeft(12); pp.setAlignment(Element.ALIGN_LEFT); pp.setLeading(0f, 1f); ch = new Chunk("\nSpecial Provisions\n", fntb); phrase = new Phrase(); phrase.add(ch); ch = new Chunk(permit.getNotes() + "\n", fnt); phrase.add(ch); pp.add(phrase); document.add(pp); // pp = new Paragraph(); pp.setIndentationLeft(12); pp.setAlignment(Element.ALIGN_LEFT); ch = new Chunk("Standards Conditions of Approval\n", fntb); phrase = new Phrase(); phrase.add(ch); pp.add(phrase); document.add(pp); // pp = new Paragraph(); pp.setIndentationLeft(12); pp.setAlignment(Element.ALIGN_LEFT); pp.setLeading(0f, 1f); ch = new Chunk("1 - " + conditions[0] + "\n", fntbs); phrase = new Phrase(); phrase.add(ch); pp.add(phrase); document.add(pp); // int jj = 1; for (int j = 1; j < conditions.length; j++) { jj = j + 1; pp = new Paragraph(); pp.setLeading(0f, 1f); pp.setIndentationLeft(12); pp.setAlignment(Element.ALIGN_LEFT); ch = new Chunk(jj + " - " + conditions[j] + "\n", fnts); phrase = new Phrase(); phrase.add(ch); pp.add(phrase); document.add(pp); } pp = new Paragraph(); pp.setIndentationLeft(20); pp.setAlignment(Element.ALIGN_RIGHT); ch = new Chunk("\n\n___________________\n", fnt); phrase = new Phrase(); phrase.add(ch); pp.add(phrase); ch = new Chunk(permit.getReviewer().getFullName(), fnt); phrase = new Phrase(); phrase.add(ch); pp.add(phrase); document.add(pp); document.close(); writer.close(); res.setHeader("Expires", "0"); res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); res.setHeader("Content-Disposition", "attachment; filename=" + fileName); res.setHeader("Pragma", "public"); // // setting the content type res.setContentType("application/pdf"); // // the contentlength is needed for MSIE!!! res.setContentLength(baos.size()); // out = res.getOutputStream(); if (out != null) { baos.writeTo(out); } } catch (Exception ex) { logger.error(ex); } }
From source file:permit.ReceiptPdf.java
License:Open Source License
void writePages(HttpServletResponse res, Receipt receipt) { ////from w ww. j a va 2 s. co m // paper size legal (A4) 8.5 x 11 // page 1-inch = 72 points // Invoice invoice = receipt.getInvoice(); String fileName = "row_receipt_" + receipt.getId() + ".pdf"; Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11" Document document = new Document(pageSize, 36, 36, 18, 18); ServletOutputStream out = null; Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL); Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD); Font fnts = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL); Font fntbs = new Font(Font.TIMES_ROMAN, 8, Font.BOLD); String spacer = " "; PdfPTable header = getHeader(); Company company = invoice.getCompany(); Contact contact = null; if (invoice.hasContact()) { contact = invoice.getContact(); } List<Page> pages = invoice.getPages(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); String str = ""; document.open(); document.add(header); // // title float[] width = { 100f }; // one cell PdfPTable table = new PdfPTable(width); table.setWidthPercentage(100.0f); PdfPCell cell = new PdfPCell(new Phrase("RECEIPT", fntb)); // cell.setBorder(Rectangle.BOTTOM); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); document.add(table); // // we need these later Paragraph pp = new Paragraph(); Chunk ch = new Chunk(" ", fntb); Phrase phrase = new Phrase(); // float[] widths = { 35f, 30f, 35f }; // percentages table = new PdfPTable(widths); table.setWidthPercentage(100.0f); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); // // first row float[] widthOne = { 100f }; PdfPTable leftTable = new PdfPTable(widthOne); leftTable.setWidthPercentage(35.0f); leftTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); // if (company != null) { ch = new Chunk("Company\n", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); phrase = new Phrase(); ch = new Chunk(company.getName() + "\n", fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); } if (contact != null) { phrase = new Phrase(); ch = new Chunk(contact.getFullName(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); phrase = new Phrase(); ch = new Chunk(contact.getAddress(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); ch = new Chunk(contact.getCityStateZip(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); } table.addCell(leftTable); // // middle cell // cell = new PdfPCell(new Phrase(spacer, fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); // float[] widths2 = { 50f, 50f }; // percentages PdfPTable rightTable = new PdfPTable(widths2); rightTable.setWidthPercentage(35.0f); rightTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); // ch = new Chunk("Receipt No.", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk(receipt.getId(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("Invoice No.", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk(invoice.getInvoice_num(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("Receipt Date", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk(receipt.getDate(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("Amount Paid $", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("$" + receipt.getAmount_paid(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("Payment Method ", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk(receipt.getPayment_type(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // table.addCell(rightTable); // document.add(table); // phrase = new Phrase(new Chunk(spacer, fnt)); document.add(phrase); // int jj = 0; if (pages != null) { for (Page page : pages) { jj++; PdfPTable borderTable = new PdfPTable(widthOne); borderTable.setWidthPercentage(100.0f); borderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); float[] widthTwo = { 50f, 50f }; PdfPTable titleTable = new PdfPTable(widthTwo); titleTable.setWidthPercentage(75.0f); titleTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); phrase = new Phrase("Receipt Number ", fntb); ch = new Chunk(receipt.getId(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Rectangle.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); titleTable.addCell(cell); // phrase = new Phrase(page.getPage_num(), fnt); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT); cell.setBorder(Rectangle.NO_BORDER); titleTable.addCell(cell); // borderTable.addCell(titleTable); float[] width4 = { 25f, 40f, 25f, 10f }; PdfPTable contTable = new PdfPTable(width4); cell = new PdfPCell(new Phrase("Excavation Permit Number", fntb)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("Project", fntb)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("Date Issued", fntb)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("Permit Fee", fntb)); contTable.addCell(cell); List<Permit> permits = page.getPermits(); if (permits != null) { for (Permit permit : permits) { cell = new PdfPCell(new Phrase(permit.getPermit_num(), fnt)); contTable.addCell(cell); phrase = new Phrase(permit.getProject() + "\n", fnt); List<Excavation> cuts = permit.getExcavations(); if (cuts != null) { for (Excavation one : cuts) { ch = new Chunk(one.getAddress() + " (" + one.getCut_type() + ")", fnt); phrase.add(ch); } } cell = new PdfPCell(phrase); contTable.addCell(cell); cell = new PdfPCell(new Phrase(permit.getDate(), fnt)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("$" + permit.getFee(), fnt)); cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT); contTable.addCell(cell); cell = new PdfPCell(new Phrase(spacer, fnt)); // // space line // cell.setColspan(4); contTable.addCell(cell); } } if (page.getNeededLines() > 0) { // first page for (int j = 0; j < page.getNeededLines(); j++) { cell = new PdfPCell(new Phrase(spacer, fnt)); contTable.addCell(cell); contTable.addCell(cell); contTable.addCell(cell); contTable.addCell(cell); } } if (jj == pages.size()) { cell = new PdfPCell(new Phrase("Total Invoice Amount\n" + invoice.getTotal(), fntb)); cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT); cell.setColspan(4); contTable.addCell(cell); } borderTable.addCell(contTable); cell = new PdfPCell(new Phrase("Thank You.", fnt)); cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); cell.setBorder(Rectangle.NO_BORDER); borderTable.addCell(cell); borderTable.addCell(titleTable); // receipt and date document.add(borderTable); if (jj < pages.size()) { document.newPage(); } } } // document.close(); writer.close(); res.setHeader("Expires", "0"); res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); // res.setHeader("Content-Disposition","attachment; filename="+fileName); res.setHeader("Pragma", "public"); // // setting the content type res.setContentType("application/pdf"); // // the contentlength is needed for MSIE!!! res.setContentLength(baos.size()); // out = res.getOutputStream(); if (out != null) { baos.writeTo(out); } } catch (Exception ex) { logger.error(ex); } }