List of usage examples for com.lowagie.text.pdf PdfPCell setBorderWidth
public void setBorderWidth(float borderWidth)
From source file:biblivre3.administration.reports.ReservationReport.java
License:Open Source License
@Override protected void generateReportBody(Document document, BaseReportDto reportData) throws Exception { ReservationReportDto dto = (ReservationReportDto) reportData; Paragraph p1 = new Paragraph(this.getText("REPORTS_RESERVATION_TITLE")); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1);// ww w . j ava2 s. co m document.add(new Phrase("\n\n")); boolean hasBiblioData = dto.getBiblioReservations() != null && !dto.getBiblioReservations().isEmpty(); boolean hasHoldingData = dto.getHoldingReservations() != null && !dto.getHoldingReservations().isEmpty(); if (hasBiblioData) { PdfPTable biblioTable = new PdfPTable(7); biblioTable.setWidthPercentage(100f); PdfPCell cell = new PdfPCell( new Paragraph(this.getHeaderChunk(this.getText("REPORTS_RESERVATION_BIBLIO")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setColspan(7); biblioTable.addCell(cell); createHeader(biblioTable); createBody(biblioTable, dto.getBiblioReservations()); document.add(biblioTable); document.add(new Phrase("\n")); } if (hasHoldingData) { PdfPTable holdingTable = new PdfPTable(7); holdingTable.setWidthPercentage(100f); PdfPCell cell = new PdfPCell( new Paragraph(this.getHeaderChunk(this.getText("REPORTS_RESERVATION_HOLDING")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setColspan(7); holdingTable.addCell(cell); createHeader(holdingTable); createBody(holdingTable, dto.getHoldingReservations()); document.add(holdingTable); } if (!hasBiblioData && !hasHoldingData) { PdfPTable noDataTable = new PdfPTable(1); noDataTable.setWidthPercentage(100f); String message = this.getText("REPORTS_NO_DATA") + " - " + dateFormat.format(new Date()); PdfPCell cell = new PdfPCell(new Paragraph(this.getHeaderChunk(message))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); noDataTable.addCell(cell); document.add(noDataTable); } }
From source file:biblivre3.administration.reports.ReservationReport.java
License:Open Source License
private void createHeader(PdfPTable table) { PdfPCell cell; cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_ENROL")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell);/*from w ww . java 2 s.c o m*/ cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_NAME")))); cell.setBackgroundColor(headerBgColor); cell.setColspan(2); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_TITLE")))); cell.setBackgroundColor(headerBgColor); cell.setColspan(2); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_AUTHOR")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_RESERVATION_DATE")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); }
From source file:biblivre3.administration.reports.SearchesByDateReport.java
License:Open Source License
private PdfPTable createTable(SearchesByDateReportDto dto) { PdfPTable table = new PdfPTable(2); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); //Table header PdfPCell cell; cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_DATE")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell);//from w w w .j a v a 2 s . c o m cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_TOTAL")))); cell.setBackgroundColor(headerBgColor); cell.setColspan(2); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); //Table body if (dto.getData() == null || dto.getData().isEmpty()) return table; for (String[] data : dto.getData()) { cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[1]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[0]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); } return table; }
From source file:biblivre3.administration.reports.SummaryReport.java
License:Open Source License
private void createHeader(PdfPTable table) { PdfPCell cell; cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_DEWEY")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell);/* ww w . j a va 2s .c o m*/ cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_TITLE")))); cell.setBackgroundColor(headerBgColor); cell.setColspan(2); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_AUTHOR")))); cell.setBackgroundColor(headerBgColor); cell.setColspan(2); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_ISBN")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_EDITOR")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_YEAR")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_EDITION")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getBoldChunk(this.getText("REPORTS_HOLDINGS_TOTAL")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); }
From source file:biblivre3.administration.reports.UserReport.java
License:Open Source License
private PdfPTable createLendingsTable(List<String[]> lendings) { PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100f);/* w w w. j av a 2 s. c o m*/ PdfPCell cell; cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_DATE")))); cell.setBackgroundColor(headerBgColor); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_TITLE")))); cell.setBackgroundColor(headerBgColor); cell.setColspan(2); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_AUTHOR")))); cell.setBackgroundColor(headerBgColor); cell.setColspan(2); cell.setBorderWidth(headerBorderWidth); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); for (String[] lending : lendings) { cell = new PdfPCell(new Paragraph(this.getNormalChunk(lending[0]))); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(lending[1]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(this.getNormalChunk(lending[2]))); cell.setColspan(2); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); } return table; }
From source file:br.gov.jfrj.itextpdf.Documento.java
License:Open Source License
public static byte[] stamp(byte[] abPdf, String sigla, boolean rascunho, boolean cancelado, boolean semEfeito, boolean internoProduzido, String qrCode, String mensagem, Integer paginaInicial, Integer paginaFinal, Integer cOmitirNumeracao, String instancia, String orgaoUsu) throws DocumentException, IOException { PdfReader pdfIn = new PdfReader(abPdf); Document doc = new Document(PageSize.A4, 0, 0, 0, 0); // final SimpleDateFormat sdf = new SimpleDateFormat( // "EEE MMM dd HH:mm:ss zzz yyyy"); // doc.add(new Meta("creationdate", sdf.format(new Date(0L)))); final ByteArrayOutputStream boA4 = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(doc, boA4); doc.open();//from w w w. j a v a 2s . c o m PdfContentByte cb = writer.getDirectContent(); // Resize every page to A4 size // // double thetaRotation = 0.0; for (int i = 1; i <= pdfIn.getNumberOfPages(); i++) { int rot = pdfIn.getPageRotation(i); float left = pdfIn.getPageSize(i).getLeft(); float bottom = pdfIn.getPageSize(i).getBottom(); float top = pdfIn.getPageSize(i).getTop(); float right = pdfIn.getPageSize(i).getRight(); PdfImportedPage page = writer.getImportedPage(pdfIn, i); float w = page.getWidth(); float h = page.getHeight(); // Logger.getRootLogger().error("----- dimensoes: " + rot + ", " + w // + ", " + h); doc.setPageSize((rot != 0 && rot != 180) ^ (w > h) ? PageSize.A4.rotate() : PageSize.A4); doc.newPage(); cb.saveState(); if (rot != 0 && rot != 180) { float swap = w; w = h; h = swap; } float pw = doc.getPageSize().getWidth(); float ph = doc.getPageSize().getHeight(); double scale = Math.min(pw / w, ph / h); // do my transformations : cb.transform(AffineTransform.getScaleInstance(scale, scale)); if (!internoProduzido) { cb.transform(AffineTransform.getTranslateInstance(pw * SAFETY_MARGIN, ph * SAFETY_MARGIN)); cb.transform(AffineTransform.getScaleInstance(1.0f - 2 * SAFETY_MARGIN, 1.0f - 2 * SAFETY_MARGIN)); } if (rot != 0) { double theta = -rot * (Math.PI / 180); if (rot == 180) { cb.transform(AffineTransform.getRotateInstance(theta, w / 2, h / 2)); } else { cb.transform(AffineTransform.getRotateInstance(theta, h / 2, w / 2)); } if (rot == 90) { cb.transform(AffineTransform.getTranslateInstance((w - h) / 2, (w - h) / 2)); } else if (rot == 270) { cb.transform(AffineTransform.getTranslateInstance((h - w) / 2, (h - w) / 2)); } } // Logger.getRootLogger().error( // "----- dimensoes: " + rot + ", " + w + ", " + h); // Logger.getRootLogger().error("----- page: " + pw + ", " + ph); // cb.transform(AffineTransform.getTranslateInstance( // ((pw / scale) - w) / 2, ((ph / scale) - h) / 2)); // put the page cb.addTemplate(page, 0, 0); // draw a red rectangle at the page borders // // cb.saveState(); // cb.setColorStroke(Color.red); // cb.rectangle(pdfIn.getPageSize(i).getLeft(), pdfIn.getPageSize(i) // .getBottom(), pdfIn.getPageSize(i).getRight(), pdfIn // .getPageSize(i).getTop()); // cb.stroke(); // cb.restoreState(); cb.restoreState(); } doc.close(); abPdf = boA4.toByteArray(); final ByteArrayOutputStream bo2 = new ByteArrayOutputStream(); final PdfReader reader = new PdfReader(abPdf); final int n = reader.getNumberOfPages(); final PdfStamper stamp = new PdfStamper(reader, bo2); // adding content to each page int i = 0; PdfContentByte under; PdfContentByte over; final BaseFont helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false); // Image img = Image.getInstance("watermark.jpg"); final BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); byte maskr[] = { (byte) 0xff }; Image mask = Image.getInstance(1, 1, 1, 1, maskr); mask.makeMask(); mask.setInverted(true); while (i < n) { i++; // watermark under the existing page under = stamp.getUnderContent(i); over = stamp.getOverContent(i); final Barcode39 code39 = new Barcode39(); // code39.setCode(doc.getCodigo()); code39.setCode(sigla.replace("-", "").replace("/", "").replace(".", "")); code39.setStartStopText(false); final Image image39 = code39.createImageWithBarcode(over, null, null); Rectangle r = stamp.getReader().getPageSizeWithRotation(i); image39.setInitialRotation((float) Math.PI / 2.0f); image39.setAbsolutePosition( r.getWidth() - image39.getHeight() + (STAMP_BORDER_IN_CM - PAGE_BORDER_IN_CM) * CM_UNIT, BARCODE_HEIGHT_IN_CM * CM_UNIT); image39.setBackgroundColor(Color.green); image39.setBorderColor(Color.RED); image39.setBorderWidth(0.5f * CM_UNIT); image39.setImageMask(mask); over.setRGBColorFill(255, 255, 255); mask.setAbsolutePosition(r.getWidth() - image39.getHeight() - (PAGE_BORDER_IN_CM) * CM_UNIT, (BARCODE_HEIGHT_IN_CM - STAMP_BORDER_IN_CM) * CM_UNIT); mask.scaleAbsolute(image39.getHeight() + 2 * STAMP_BORDER_IN_CM * CM_UNIT, image39.getWidth() + 2 * STAMP_BORDER_IN_CM * CM_UNIT); over.addImage(mask); over.setRGBColorFill(0, 0, 0); over.addImage(image39); // over.addImage(mask, mask.getScaledWidth() * 8, 0, 0, // mask.getScaledHeight() * 8, 100, 450); if (qrCode != null) { java.awt.Image imgQRCode = createQRCodeImage(qrCode); Image imageQRCode = Image.getInstance(imgQRCode, Color.BLACK, true); imageQRCode.scaleAbsolute(QRCODE_SIZE_IN_CM * CM_UNIT, QRCODE_SIZE_IN_CM * CM_UNIT); imageQRCode.setAbsolutePosition(QRCODE_LEFT_MARGIN_IN_CM * CM_UNIT, PAGE_BORDER_IN_CM * CM_UNIT); over.setRGBColorFill(255, 255, 255); mask.setAbsolutePosition((QRCODE_LEFT_MARGIN_IN_CM - STAMP_BORDER_IN_CM) * CM_UNIT, (PAGE_BORDER_IN_CM - STAMP_BORDER_IN_CM) * CM_UNIT); mask.scaleAbsolute((QRCODE_SIZE_IN_CM + 2 * STAMP_BORDER_IN_CM) * CM_UNIT, (QRCODE_SIZE_IN_CM + 2 * STAMP_BORDER_IN_CM) * CM_UNIT); over.addImage(mask); over.setRGBColorFill(0, 0, 0); over.addImage(imageQRCode); } if (mensagem != null) { PdfPTable table = new PdfPTable(1); table.setTotalWidth(r.getWidth() - image39.getHeight() - (QRCODE_LEFT_MARGIN_IN_CM + QRCODE_SIZE_IN_CM + 4 * STAMP_BORDER_IN_CM + PAGE_BORDER_IN_CM) * CM_UNIT); PdfPCell cell = new PdfPCell(new Paragraph(mensagem, FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, Color.BLACK))); cell.setBorderWidth(0); table.addCell(cell); over.setRGBColorFill(255, 255, 255); mask.setAbsolutePosition( (QRCODE_LEFT_MARGIN_IN_CM + QRCODE_SIZE_IN_CM + STAMP_BORDER_IN_CM) * CM_UNIT, (PAGE_BORDER_IN_CM - STAMP_BORDER_IN_CM) * CM_UNIT); mask.scaleAbsolute(2 * STAMP_BORDER_IN_CM * CM_UNIT + table.getTotalWidth(), 2 * STAMP_BORDER_IN_CM * CM_UNIT + table.getTotalHeight()); over.addImage(mask); over.setRGBColorFill(0, 0, 0); table.writeSelectedRows(0, -1, (QRCODE_LEFT_MARGIN_IN_CM + QRCODE_SIZE_IN_CM + 2 * STAMP_BORDER_IN_CM) * CM_UNIT, table.getTotalHeight() + PAGE_BORDER_IN_CM * CM_UNIT, over); } if (cancelado) { over.saveState(); final PdfGState gs = new PdfGState(); gs.setFillOpacity(0.5f); over.setGState(gs); over.setColorFill(Color.GRAY); over.beginText(); over.setFontAndSize(helv, 72); over.showTextAligned(Element.ALIGN_CENTER, "CANCELADO", r.getWidth() / 2, r.getHeight() / 2, 45); over.endText(); over.restoreState(); } else if (rascunho) { over.saveState(); final PdfGState gs = new PdfGState(); gs.setFillOpacity(0.5f); over.setGState(gs); over.setColorFill(Color.GRAY); over.beginText(); over.setFontAndSize(helv, 72); over.showTextAligned(Element.ALIGN_CENTER, "MINUTA", r.getWidth() / 2, r.getHeight() / 2, 45); over.endText(); over.restoreState(); } else if (semEfeito) { over.saveState(); final PdfGState gs = new PdfGState(); gs.setFillOpacity(0.5f); over.setGState(gs); over.setColorFill(Color.GRAY); over.beginText(); over.setFontAndSize(helv, 72); over.showTextAligned(Element.ALIGN_CENTER, "SEM EFEITO", r.getWidth() / 2, r.getHeight() / 2, 45); over.endText(); over.restoreState(); } // if (!rascunho // && request.getRequestURL().indexOf("http://laguna/") == -1) { if (!rascunho && !cancelado && !semEfeito && ((!Contexto.resource("isVersionTest").equals("false")) || (!Contexto.resource("isBaseTest").equals("false")))) { over.saveState(); final PdfGState gs = new PdfGState(); gs.setFillOpacity(0.5f); over.setGState(gs); over.setColorFill(Color.GRAY); over.beginText(); over.setFontAndSize(helv, 72); over.showTextAligned(Element.ALIGN_CENTER, "INVLIDO", r.getWidth() / 2, r.getHeight() / 2, 45); over.endText(); over.restoreState(); } // Imprime um circulo com o numero da pagina dentro. if (paginaInicial != null) { String sFl = String.valueOf(paginaInicial + i - 1); // Se for a ultima pagina e o numero nao casar, acrescenta "-" e // pagina final if (n == i) { if (paginaFinal != paginaInicial + n - 1) { sFl = sFl + "-" + String.valueOf(paginaFinal); } } if (i > cOmitirNumeracao) { // Raio do circulo interno final float radius = 18f; // Distancia entre o circulo interno e o externo final float circleInterspace = Math.max(helv.getAscentPoint(instancia, TEXT_HEIGHT), helv.getAscentPoint(orgaoUsu, TEXT_HEIGHT)) - Math.min(helv.getDescentPoint(instancia, TEXT_HEIGHT), helv.getDescentPoint(orgaoUsu, TEXT_HEIGHT)) + 2 * TEXT_TO_CIRCLE_INTERSPACE; // Centro do circulo float xCenter = r.getWidth() - 1.8f * (radius + circleInterspace); float yCenter = r.getHeight() - 1.8f * (radius + circleInterspace); over.saveState(); final PdfGState gs = new PdfGState(); gs.setFillOpacity(1f); over.setGState(gs); over.setColorFill(Color.BLACK); over.saveState(); over.setColorStroke(Color.black); over.setLineWidth(1f); over.setColorFill(Color.WHITE); // Circulo externo over.circle(xCenter, yCenter, radius + circleInterspace); over.fill(); over.circle(xCenter, yCenter, radius + circleInterspace); over.stroke(); // Circulo interno over.circle(xCenter, yCenter, radius); over.stroke(); over.restoreState(); { over.saveState(); over.beginText(); over.setFontAndSize(helv, TEXT_HEIGHT); // Escreve o texto superior do carimbo float fDescent = helv.getDescentPoint(instancia, TEXT_HEIGHT); showTextOnArc(over, instancia, helv, TEXT_HEIGHT, xCenter, yCenter, radius - fDescent + TEXT_TO_CIRCLE_INTERSPACE, true); // Escreve o texto inferior float fAscent = helv.getAscentPoint(orgaoUsu, TEXT_HEIGHT); showTextOnArc(over, orgaoUsu, helv, TEXT_HEIGHT, xCenter, yCenter, radius + fAscent + TEXT_TO_CIRCLE_INTERSPACE, false); over.endText(); over.restoreState(); } over.beginText(); int textHeight = 23; // Diminui o tamanho do font ate que o texto caiba dentro do // circulo interno while (helv.getWidthPoint(sFl, textHeight) > (2 * (radius - TEXT_TO_CIRCLE_INTERSPACE))) textHeight--; float fAscent = helv.getAscentPoint(sFl, textHeight) + helv.getDescentPoint(sFl, textHeight); over.setFontAndSize(helv, textHeight); over.showTextAligned(Element.ALIGN_CENTER, sFl, xCenter, yCenter - 0.5f * fAscent, 0); over.endText(); over.restoreState(); } } } stamp.close(); return bo2.toByteArray(); }
From source file:br.org.acessobrasil.silvinha.util.GeraRelatorioPDF.java
License:Open Source License
private static void geraCabecalho(PdfPTable table) { PdfPCell cell; cell = new PdfPCell(new Paragraph(TradGeraRelatorioPDF.P_V)); cell.setBorderWidth(1.5f); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell);/*w w w . j a v a2 s . c om*/ cell = new PdfPCell(new Paragraph(TradGeraRelatorioPDF.DESCRICAO)); cell.setColspan(3); cell.setBorderWidth(1.5f); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(TradGeraRelatorioPDF.OCORRENCIAS)); cell.setBorderWidth(1.5f); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph(TradGeraRelatorioPDF.LINHAS)); cell.setBorderWidth(1.5f); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); table.addCell(cell); }
From source file:bucks.AuditSheet.java
License:Open Source License
void generateSheet(HttpServletResponse res, List<Batch> batches) { ///* www. ja va 2s . c o m*/ // paper size legal (A4) 8.5 x 11 // page 1-inch = 72 points // String spacer = " \n"; ServletOutputStream out = null; String filename = "marketbucks_audit_sheet.pdf"; try { // space // Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11" Document document = new Document(pageSize, 36, 36, 18, 18);// 18,18,54,35 ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); document.open(); URL imgUrl = new URL(imageUrl); Image image = Image.getInstance(imgUrl); image.scalePercent(20f); // image.scaleAbsolute(100f, 100f);// width, height // image.setRotation(3.1f); // in radians // image.setRotationDegrees(90f); // degrees // image.setSpacingBefore(10f); // image.setSpacingAfter(10f); // image.setWidthPercentage(25.0f); Font fnt = new Font(Font.TIMES_ROMAN, 12, Font.NORMAL); Font fntb = new Font(Font.TIMES_ROMAN, 12, Font.BOLD); Font fntb2 = new Font(Font.TIMES_ROMAN, 14, Font.BOLD); Phrase spacePhrase = new Phrase(); Chunk ch = new Chunk(spacer, fnt); spacePhrase.add(ch); float[] widths = { 25f, 75f }; // percentages PdfPTable headTable = new PdfPTable(widths); headTable.setWidthPercentage(100); headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cell = new PdfPCell(image); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); headTable.addCell(cell); Phrase phrase = new Phrase(); ch = new Chunk("Printed Market Bucks Audit Sheet\n ", fntb2); phrase.add(ch); Paragraph pp = new Paragraph(); pp.setIndentationLeft(20); pp.setAlignment(Element.ALIGN_LEFT); pp.add(phrase); cell = new PdfPCell(pp); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); headTable.addCell(cell); document.add(headTable); // document.add(spacePhrase); document.add(spacePhrase); // float[] widths3 = { 50f, 50f }; // percentages PdfPTable table = new PdfPTable(widths3); table.setWidthPercentage(100); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); phrase = new Phrase(); ch = new Chunk(" Date: ", fntb); phrase.add(ch); ch = new Chunk(Helper.getToday() + "\n\n\n", fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk(" ", fntb); // empty cell phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); // document.add(table); // phrase = new Phrase(new Chunk("\n", fnt)); document.add(phrase); // float[] widths2 = { 15f, 10f, 15f, 15f, 15f, 15f, 15f }; // percentages table = new PdfPTable(widths2); table.setWidthPercentage(90); // table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); // table.getDefaultCell().setPadding(5); phrase = new Phrase(); ch = new Chunk("Count of MB/GC", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Value", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Total Dollars", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Printed By", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Start Number", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("End Number", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("Printed Date", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // // next rows // for (Batch one : batches) { phrase = new Phrase(); ch = new Chunk(one.getBatch_size(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("$" + one.getValue() + ".00", fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk(moneyFormat.format(one.getTotal()), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk(one.getUser().toString(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(1f); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk(one.getStart_seq(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk(one.getEnd_seq(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk(one.getDate(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(1f); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); } document.add(table); // document.add(spacePhrase); document.add(spacePhrase); // ch = new Chunk("Audit By:____________________________________________________________________\n\n", fnt); phrase = new Phrase(); phrase.add(ch); document.add(phrase); ch = new Chunk(" :_______________________________________)_____________________________\n\n", fnt); phrase = new Phrase(); phrase.add(ch); document.add(phrase); ch = new Chunk(" :_____________________________________________________________________\n\n", fnt); phrase = new Phrase(); phrase.add(ch); document.add(phrase); // document.add(spacePhrase); document.add(spacePhrase); // document.close(); writer.close(); res.setHeader("Expires", "0"); res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); res.setHeader("Pragma", "public"); // // setting the content type res.setHeader("Content-Disposition", " attachment; filename=" + filename); 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) { System.err.println(ex); } }
From source file:bucks.RedeemInvoice.java
License:Open Source License
void generateInvoice(HttpServletResponse res, Redeem redeem) { ////from ww w . j a v a2 s . c om // paper size legal (A4) 8.5 x 11 // page 1-inch = 72 points // String spacer = " \n"; User user = redeem.getUser(); Vendor vendor = redeem.getVendor(); List<Buck> bk_bucks = redeem.getBk_bucks(); List<Buck> gc5_bucks = redeem.getGc5_bucks(); List<Buck> gc20_bucks = redeem.getGc20_bucks(); List<Buck> gc_bucks = redeem.getGc_bucks(); List<Dispute> disputes = redeem.getDisputes(); int bk_total = 0, gc5_total = 0, gc20_total = 0, total = 0; if (bk_bucks.size() > 0) { bk_total = bk_bucks.size() * 3; } if (gc5_bucks.size() > 0) { gc5_total = gc5_bucks.size() * 5; } if (gc20_bucks.size() > 0) { gc20_total = gc20_bucks.size() * 20; } total = bk_total + gc5_total + gc20_total; String vendor_name = ""; if (vendor != null) { vendor_name = vendor.getCleanName(); } ServletOutputStream out = null; String filename = "invoice_" + vendor_name + "_" + redeem.getId() + ".pdf"; try { // space // Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11" Document document = new Document(pageSize, 36, 36, 18, 18);// 18,18,54,35 ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); document.open(); Image image = Image.getInstance(imageUrl); // image = Image.getInstance(byte bytes[]);// generated image image.scalePercent(20f); Font fnt = new Font(Font.TIMES_ROMAN, 12, Font.NORMAL); Font fntb = new Font(Font.TIMES_ROMAN, 12, Font.BOLD); Font fntb2 = new Font(Font.TIMES_ROMAN, 14, Font.BOLD); // Phrase spacePhrase = new Phrase(); Chunk ch = new Chunk(spacer, fnt); spacePhrase.add(ch); float[] widths = { 15f, 85f }; // percentages PdfPTable headTable = new PdfPTable(widths); headTable.setWidthPercentage(100); headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // image.setWidthPercentage(15.0f); PdfPCell cell = new PdfPCell(image); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setFixedHeight(46f); headTable.addCell(cell); Phrase phrase = new Phrase(); ch = new Chunk( "City of Bloomington Community Farmers Market\n Gift Certificates/Market Bucks Invoice\n ", fntb2); phrase.add(ch); Paragraph pp = new Paragraph(); pp.setIndentationLeft(20); pp.setAlignment(Element.ALIGN_LEFT); pp.add(phrase); cell = new PdfPCell(pp); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); headTable.addCell(cell); document.add(headTable); // float[] widths3 = { 50f, 50f }; // percentages PdfPTable table = new PdfPTable(widths3); table.setWidthPercentage(100); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); phrase = new Phrase(); ch = new Chunk(" Vendor Name: ", fntb); phrase.add(ch); ch = new Chunk(vendor.getFullName(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Date: ", fntb); phrase.add(ch); ch = new Chunk(redeem.getDate(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); phrase = new Phrase(); ch = new Chunk(" Vendor Number: ", fntb); phrase.add(ch); ch = new Chunk(vendor.getId(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); phrase = new Phrase(); // empty cell ch = new Chunk(" ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); table.addCell(cell); // extra space table.addCell(cell); document.add(table); // phrase = new Phrase(new Chunk("\n", fnt)); document.add(phrase); // float[] widths2 = { 30f, 25f, 15f, 15f, 15f }; // percentages table = new PdfPTable(widths2); table.setWidthPercentage(90); // table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); // table.getDefaultCell().setPadding(5); phrase = new Phrase(); ch = new Chunk("Type of Voucher", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("City Account Number", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Quantity", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("Multiply", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("Value", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorderWidth(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // // second row phrase = new Phrase(); ch = new Chunk("Market Bucks", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("201-18-1865003-47240", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); // phrase = new Phrase(); String str = " "; if (bk_bucks.size() > 0) { str = "" + bk_bucks.size(); } ch = new Chunk(str, fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setPadding(4); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("x $3.00 = ", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); phrase = new Phrase(); str = " "; if (bk_total > 0) { str = "$" + bk_total + ".00"; } ch = new Chunk(str, fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setPadding(4); table.addCell(cell); // // 3rd row phrase = new Phrase(); ch = new Chunk("$5 Gift Cerificates", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("201-18-1865003-47230", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); // phrase = new Phrase(); str = " "; if (gc5_bucks.size() > 0) { str = "" + gc5_bucks.size(); } ch = new Chunk(str, fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setPadding(4); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("x $5.00 = ", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); phrase = new Phrase(); str = " "; if (gc5_total > 0) { str = "$" + gc5_total + ".00"; } ch = new Chunk(str, fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setPadding(4); table.addCell(cell); // // 4th row phrase = new Phrase(); ch = new Chunk("$20 Gift Certificates", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("201-18-1865003-47230", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); // phrase = new Phrase(); str = " "; if (gc20_bucks.size() > 0) { str = "" + gc20_bucks.size(); } ch = new Chunk(str, fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setPadding(4); table.addCell(cell); phrase = new Phrase(); ch = new Chunk("x $20.00 = ", fnt); phrase.add(ch); cell = new PdfPCell(phrase); table.addCell(cell); str = " "; if (gc20_total > 0) { str = "$" + gc20_total + ".00"; } phrase = new Phrase(); ch = new Chunk(str, fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setPadding(4); table.addCell(cell); // // 5th row total phrase = new Phrase(); ch = new Chunk(" Total Value: ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setColspan(4); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(2f); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk("$" + total + ".00", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(2f); cell.setPadding(4); cell.setLeading(2f, 1.2f); table.addCell(cell); document.add(table); // // float[] withs5 = { 100f }; table = new PdfPTable(withs5); table.setWidthPercentage(100); cell = new PdfPCell(new Phrase(" ")); cell.setBorder(Rectangle.BOTTOM); // cell.setBorderColorBottom(Color.BLACK); cell.setBorderWidthBottom(2f); table.addCell(cell); document.add(table); // ch = new Chunk("\n", fnt); phrase = new Phrase(); phrase.add(ch); document.add(phrase); // // float[] widths3 = {50f, 50f}; // percentages table = new PdfPTable(widths3); table.setWidthPercentage(100); // table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); phrase = new Phrase(); ch = new Chunk(" Data Entry Completed by: ", fntb); phrase.add(ch); ch = new Chunk(user.getFullName(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); // phrase = new Phrase(); ch = new Chunk(" Invoice Number: ", fntb); phrase.add(ch); ch = new Chunk(redeem.getId(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); document.add(table); document.add(spacePhrase); document.add(spacePhrase); // // adding bucks and GC // float[] widths4 = { 100f }; // percentages table = new PdfPTable(widths4); table.setWidthPercentage(100); // table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); int row = 1, col = 1; if (bk_bucks.size() > 0) { phrase = new Phrase(); ch = new Chunk(" Market Bucks ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(2f); table.addCell(cell); phrase = new Phrase(); for (Buck one : bk_bucks) { ch = new Chunk("" + one.getId() + " ", fntb); phrase.add(ch); col++; if (col > 15) { row++; col = 1; cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); phrase = new Phrase(); } } if (col > 1) { cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); } if (row < 10) { for (int j = 0; j < 2; j++) { phrase = new Phrase(); ch = new Chunk(" ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); row++; } } } col = 1; if (gc_bucks.size() > 0) { phrase = new Phrase(); ch = new Chunk(" Gift Certificates ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(2f); table.addCell(cell); phrase = new Phrase(); for (Buck one : gc_bucks) { ch = new Chunk("" + one.getId() + " ", fntb); phrase.add(ch); col++; if (col > 15) { row++; col = 1; cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); phrase = new Phrase(); } } if (col > 1) { cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); } if (row < 15) { for (int j = 0; j < 2; j++) { phrase = new Phrase(); ch = new Chunk(" ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); row++; } } } if (disputes != null && disputes.size() > 0) { phrase = new Phrase(); ch = new Chunk(" Disputed Market Bucks and/or Gift Certificates (number: reason)", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(2f); table.addCell(cell); row++; for (Dispute one : disputes) { phrase = new Phrase(); ch = new Chunk(one.getBuck_id() + ": " + one.getReason(), fnt); phrase.add(ch); if (one.hasNotes()) { ch = new Chunk("\nNotice: " + one.getNotes(), fnt); phrase.add(ch); row++; } cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); row++; } } if (redeem.hasNotes()) { phrase = new Phrase(); ch = new Chunk("\nNotice: " + redeem.getNotes(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); row++; } if (row < 18) { for (int j = row; j < 18; j++) { phrase = new Phrase(); ch = new Chunk(" ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); } } document.add(table); document.close(); writer.close(); res.setHeader("Expires", "0"); res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); res.setHeader("Pragma", "public"); // // setting the content type res.setHeader("Content-Disposition", " attachment; filename=" + filename); 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) { System.err.println(ex); } }
From source file:ca.sqlpower.architect.profile.output.ProfilePDFFormat.java
License:Open Source License
/** * @param widths The maximum width of each column's contents in * points. THIS ARRAY WILL BE MODIFIED to the width of the widest * single word in the heading if it is wider than the existing * width value for that column. Words are split using the default * settings for java.util.StringTokenizer. * @param headerTopNColumns reference to the null count/% inner table in the header * @param headerValueColumns reference to the unique count/% inner table in the header * @param headerLengthColumns reference to the length min/max/avg inner table in the header * @param headerUniqueColumns reference to the value min/max/avg inner table in the header * @param headerNullColumns reference to the top N Value/count inner table in the header * we will resert widths of these inner table after we have all rows *///from www. j a v a2s. c o m private void addHeaderRow(TableProfileResult result, ProfileTableStructure profile, BaseFont bf, float titleFSize, float colHeadingFSize, float[] widths) throws DocumentException, IOException, SQLObjectException { int ncols = headings.length; Font titleFont = new Font(bf, titleFSize, Font.BOLD); Font colHeadingFont = new Font(bf, colHeadingFSize); PdfPTable table = profile.getMainTable(); SQLTable sqlTable = result.getProfiledObject(); // TableProfileResult tProfile = (TableProfileResult) pm.getResult(sqlTable); PdfPTable infoTable = new PdfPTable(2); StringBuffer heading = new StringBuffer(); heading.append("Connection: ").append(sqlTable.getParentDatabase().getName()).append("\n"); heading.append("Table: ").append(SQLObjectUtils.toQualifiedName(sqlTable, SQLDatabase.class)); if (result.getException() != null) { heading.append("\nProfiling Error"); if (result.getException() != null) { heading.append(":\n").append(result.getException()); StackTraceElement[] stackTrace = result.getException().getStackTrace(); for (int i = 0; i < STACK_TRACE_LENGTH && i < stackTrace.length; i++) { StackTraceElement element = stackTrace[i]; heading.append("\n ").append(element.getFileName()).append(".").append(element.getClassName()) .append(".").append(element.getMethodName()).append("(").append(element.getLineNumber()) .append(")"); } if (stackTrace.length > STACK_TRACE_LENGTH) { heading.append("\n ... ").append(stackTrace.length).append(" more"); } } } else { PdfPCell infoCell; infoCell = new PdfPCell(new Phrase("Row Count:", colHeadingFont)); infoCell.setBorder(Rectangle.NO_BORDER); infoCell.setHorizontalAlignment(Element.ALIGN_RIGHT); infoTable.addCell(infoCell); infoCell = new PdfPCell(new Phrase(String.valueOf(result.getRowCount()), colHeadingFont)); infoCell.setBorder(Rectangle.NO_BORDER); infoTable.addCell(infoCell); infoCell = new PdfPCell(new Phrase("Create Date:", colHeadingFont)); infoCell.setBorder(Rectangle.NO_BORDER); infoCell.setHorizontalAlignment(Element.ALIGN_RIGHT); infoTable.addCell(infoCell); DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); infoCell = new PdfPCell(new Phrase(df.format(new Date(result.getCreateStartTime())), colHeadingFont)); infoCell.setBorder(Rectangle.NO_BORDER); infoTable.addCell(infoCell); infoCell = new PdfPCell(new Phrase("Elapsed:", colHeadingFont)); infoCell.setBorder(Rectangle.NO_BORDER); infoCell.setHorizontalAlignment(Element.ALIGN_RIGHT); infoTable.addCell(infoCell); infoCell = new PdfPCell(new Phrase(result.getTimeToCreate() + "ms", colHeadingFont)); infoCell.setBorder(Rectangle.NO_BORDER); infoTable.addCell(infoCell); } PdfPCell hcell = new PdfPCell(new Phrase(heading.toString(), titleFont)); hcell.setColspan(ncols - 3); hcell.setBorder(Rectangle.NO_BORDER); hcell.setVerticalAlignment(Element.ALIGN_BOTTOM); table.addCell(hcell); hcell = new PdfPCell(infoTable); hcell.setColspan(3); hcell.setBorder(Rectangle.NO_BORDER); table.addCell(hcell); if (sqlTable.getColumns().size() > 0) { int colNo = 0; // column name Phrase colTitle = new Phrase("Column Name", colHeadingFont); PdfPCell cell = new PdfPCell(colTitle); cell.setBorder(Rectangle.BOTTOM | Rectangle.TOP); cell.setBorderWidth(2); cell.setBackgroundColor(new Color(200, 200, 200)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); // ensure column width is at least enough for widest word in heading widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; // date type colTitle = new Phrase("Data Type", colHeadingFont); cell = new PdfPCell(colTitle); cell.setBorder(Rectangle.BOTTOM | Rectangle.TOP); cell.setBorderWidth(2); cell.setBackgroundColor(new Color(200, 200, 200)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; // null count and % colTitle = new Phrase("NULL", colHeadingFont); cell = new PdfPCell(colTitle); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableNullColumn().addCell(cell); colTitle = new Phrase("#", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableNullColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; colTitle = new Phrase("%", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableNullColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; cell = new PdfPCell(profile.getInnerTableNullColumn()); cell.setColspan(2); cell.setBackgroundColor(new Color(200, 200, 200)); cell.setBorderWidth(2); cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cell); // unique count and % colTitle = new Phrase("Unique", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); profile.getInnerTableUniqueColumn().addCell(cell); colTitle = new Phrase("#", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableUniqueColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; colTitle = new Phrase("%", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableUniqueColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; cell = new PdfPCell(profile.getInnerTableUniqueColumn()); cell.setColspan(2); cell.setBackgroundColor(new Color(200, 200, 200)); cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM); cell.setBorderWidth(2); table.addCell(cell); // length max/min/avg colTitle = new Phrase("Length", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); profile.getInnerTableLengthColumn().addCell(cell); colTitle = new Phrase("Min", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableLengthColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; colTitle = new Phrase("Max", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableLengthColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; colTitle = new Phrase("Avg", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableLengthColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; cell = new PdfPCell(profile.getInnerTableLengthColumn()); cell.setColspan(3); cell.setBackgroundColor(new Color(200, 200, 200)); cell.setBorderWidth(2); cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cell); // value max/min/avg colTitle = new Phrase("Value", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); profile.getInnerTableValueColumn().addCell(cell); colTitle = new Phrase("Min", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableValueColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; colTitle = new Phrase("Max", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableValueColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; colTitle = new Phrase("Avg", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableValueColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; cell = new PdfPCell(profile.getInnerTableValueColumn()); cell.setColspan(3); cell.setBackgroundColor(new Color(200, 200, 200)); cell.setBorderWidth(2); cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cell); // top n colTitle = new Phrase("Top N", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); profile.getInnerTableTopNColumn().addCell(cell); colTitle = new Phrase("Values", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableTopNColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; colTitle = new Phrase("#", colHeadingFont); cell = new PdfPCell(colTitle); cell.setHorizontalAlignment(Element.ALIGN_CENTER); profile.getInnerTableTopNColumn().addCell(cell); widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize)); colNo++; cell = new PdfPCell(profile.getInnerTableTopNColumn()); cell.setColspan(2); cell.setBackgroundColor(new Color(200, 200, 200)); cell.setBorderWidth(2); cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cell); } else { hcell = new PdfPCell(new Phrase("No Column Found in the table", titleFont)); hcell.setColspan(ncols); hcell.setBorder(Rectangle.BOTTOM); hcell.setVerticalAlignment(Element.ALIGN_LEFT); table.addCell(hcell); } table.setHeaderRows(2); }