List of usage examples for com.itextpdf.text.pdf PdfPCell setBorderColor
public void setBorderColor(final BaseColor borderColor)
From source file:com.mycom.products.mywebsite.backend.util.DownloadHandler.java
License:Open Source License
private void setTableHeader(String value, PdfPTable table) { PdfPCell cell = new PdfPCell(new Paragraph(value)); cell.setBorderColor(BaseColor.GRAY); cell.setFixedHeight(25);/*from w w w. j a va2 s. c o m*/ BaseColor myColor = WebColors.getRGBColor("#F7F7F7"); cell.setBackgroundColor(myColor); cell.setPaddingLeft(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); }
From source file:com.mycom.products.mywebsite.backend.util.DownloadHandler.java
License:Open Source License
private void setTableContent(String value, PdfPTable table) { PdfPCell cell = new PdfPCell(new Paragraph(value)); cell.setBorderColor(BaseColor.GRAY); cell.setPaddingLeft(10);/*from w w w. j a va 2 s.co m*/ cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); }
From source file:com.pearson.controller.PdfGentrate.java
public static void main(String[] args) { try {//from w w w. j a v a 2 s . c om /*Document document = new Document(PageSize. A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance (document, new FileOutputStream("C:\\my.pdf")); document.open(); // create a chunk object using chunk class of itext library. Chunk underlined = new Chunk("Welcome to Pearson Q-Service Portal : "); // set the distance between text and line. underlined.setTextRise(8.0f); // set the width of the line, 'y' position, color and design of the line underlined.setUnderline(new Color(0x00, 0x00, 0xFF),0.0f, 0.2f, 3.0f, 0.0f, PdfContentByte.LINE_CAP_PROJECTING_SQUARE); // finally add object to the document. document.add(underlined); document.add(new Paragraph("Hi username", FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, new Color(255, 150, 200))));; document.add(new Paragraph("Tiltle",catFont)); document.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ smallBold)); document.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).", redFont)); PdfPTable table = new PdfPTable(3); // 3 columns. table.setWidthPercentage(100); //Width 100% table.setSpacingBefore(10f); //Space before table table.setSpacingAfter(10f); //Space after table //Set Column widths float[] columnWidths = {1f, 1f, 1f}; table.setWidths(columnWidths); PdfPCell cell1 = new PdfPCell(new Paragraph("Cell 1")); cell1.setBorderColor(BaseColor.BLUE); cell1.setPaddingLeft(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell2 = new PdfPCell(new Paragraph("Cell 2")); cell2.setBorderColor(BaseColor.GREEN); cell2.setPaddingLeft(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 3")); cell3.setBorderColor(BaseColor.RED); cell3.setPaddingLeft(10); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); //To avoid having the cell border and the content overlap, if you are having thick cell borders //cell1.setUserBorderPadding(true); //cell2.setUserBorderPadding(true); //cell3.setUserBorderPadding(true); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); document.add(table); document.close(); writer.close(); document.close(); } catch (Exception e2) { System.out.println(e2.getMessage()); } }*/ Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("AddTableExample.pdf")); document.open(); PdfPTable table = new PdfPTable(3); // 3 columns. table.setWidthPercentage(100); //Width 100% table.setSpacingBefore(10f); //Space before table table.setSpacingAfter(10f); //Space after table //Set Column widths float[] columnWidths = { 1f, 1f, 1f }; table.setWidths(columnWidths); PdfPCell cell1 = new PdfPCell(new Paragraph("Cell 1")); cell1.setBorderColor(BaseColor.BLUE); cell1.setPaddingLeft(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell2 = new PdfPCell(new Paragraph("Cell 2")); cell2.setBorderColor(BaseColor.GREEN); cell2.setPaddingLeft(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 3")); cell3.setBorderColor(BaseColor.RED); cell3.setPaddingLeft(10); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); //To avoid having the cell border and the content overlap, if you are having thick cell borders //cell1.setUserBorderPadding(true); //cell2.setUserBorderPadding(true); //cell3.setUserBorderPadding(true); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); document.add(table); document.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:controller.CreateTranscript.java
private void CreateTranscript(MyPerson p) {//,PrintWriter out){ Document document = new Document(); String name = p.getFName() + p.getLName(); try {//from w w w . j av a 2 s .c o m if (p.getUserType() == 6) { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("D:\\" + name + ".pdf")); document.open(); PdfPTable table = new PdfPTable(8); // 8 columns. table.setWidthPercentage(100); //Width 100% table.setSpacingBefore(10f); //Space before table table.setSpacingAfter(10f); //Space after table //Set Column widths float[] columnWidths = { 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f }; table.setWidths(columnWidths); PdfPCell cell1 = new PdfPCell(new Paragraph("Subject Name")); cell1.setBorderColor(BaseColor.BLUE); cell1.setPaddingLeft(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell2 = new PdfPCell(new Paragraph("Subject Code")); cell2.setBorderColor(BaseColor.BLUE); cell2.setPaddingLeft(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell3 = new PdfPCell(new Paragraph("Written Grade")); cell3.setBorderColor(BaseColor.BLUE); cell3.setPaddingLeft(10); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell4 = new PdfPCell(new Paragraph("Midterm Grade")); cell4.setBorderColor(BaseColor.BLUE); cell4.setPaddingLeft(10); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); cell4.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell5 = new PdfPCell(new Paragraph("Final Exam Grade")); cell5.setBorderColor(BaseColor.BLUE); cell5.setPaddingLeft(10); cell5.setHorizontalAlignment(Element.ALIGN_CENTER); cell5.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell6 = new PdfPCell(new Paragraph("Final Grade")); cell6.setBorderColor(BaseColor.BLUE); cell6.setPaddingLeft(10); cell6.setHorizontalAlignment(Element.ALIGN_CENTER); cell6.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell7 = new PdfPCell(new Paragraph("Term")); cell7.setBorderColor(BaseColor.BLUE); cell7.setPaddingLeft(10); cell7.setHorizontalAlignment(Element.ALIGN_CENTER); cell7.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell8 = new PdfPCell(new Paragraph("Registration Date")); cell8.setBorderColor(BaseColor.BLUE); cell8.setPaddingLeft(10); cell8.setHorizontalAlignment(Element.ALIGN_CENTER); cell8.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); table.addCell(cell5); table.addCell(cell6); table.addCell(cell7); table.addCell(cell8); ModelOfStudent modelOfStudent = new ModelOfStudent(); ResultSet rs = modelOfStudent.ViewMyCourses(p.getCode()); // if(!rs.next()){out.println("<font color='blue'>There is no Courses Untill Now ^_^ </font>");} while (rs.next()) { table.addCell(rs.getString("SubjectName")); table.addCell(rs.getString("ID")); table.addCell(rs.getString("WritenGrade")); table.addCell(rs.getString("MidtermGrade")); table.addCell(rs.getString("FinalExamGrade")); table.addCell(rs.getString("FinalGrade")); table.addCell(rs.getString("Term")); table.addCell(rs.getString("StudentRegisterSubjectDate")); /* String SubjectRegisterDate=String.valueOf(rs.getDate("SubjectRegisterDate")); table.addCell(SubjectRegisterDate); */ } //To avoid having the cell border and the content overlap, if you are having thick cell borders //cell1.setUserBorderPadding(true); //cell2.setUserBorderPadding(true); //cell3.setUserBorderPadding(true); document.add(new Paragraph("University: " + MyPerson.ReturnUniversityName(p.getCode()))); document.add(new Paragraph("Faculity: " + MyPerson.ReturnFaculityName(p.getCode()))); document.add( new Paragraph("Student Name: " + p.getFName() + " " + p.getMName() + " " + p.getLName())); document.add(new Paragraph("Level: " + MyPerson.ReturnLevelName(p.getCode()))); document.add(new Paragraph("Department: " + MyPerson.ReturnDepartmentName(p.getCode()))); document.add(table); System.out.println( "<script type='text/javascript' > alert('Successfull Creating Transcript ^_^ ');history.back();</script>"); //out.println("Successfull Creating Transcript ^_^"); document.close(); writer.close(); } //end of if student } catch (Exception e) { System.out.println("<script type='text/javascript' > alert('Failed Creating Transcript ^_^ Error:" + e.getMessage() + " ');history.back();</script>"); // out.println(""+e.getMessage()); e.printStackTrace(); } }
From source file:controller.PlanController.java
public Document PrintPressed(String Path) throws DocumentException, IOException { // step 1/*from w ww .ja v a 2 s.c o m*/ Document document = new Document(); // step 2 PdfWriter.getInstance(document, new FileOutputStream(Path)); // step 3 document.open(); // step 4 PdfPTable tablaDatosPlan = new PdfPTable(2); tablaDatosPlan.setWidthPercentage(100); if (!Team.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Team") + ":" + Team.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } if (!Season.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Season") + ":" + Season.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } if (!Date.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Date") + ":" + Date.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } if (!Players.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Players") + ":" + Players.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } if (!Start.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Start") + ":" + Start.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } if (!End.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("End") + ":" + End.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } if (!Place.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Place") + ":" + Place.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } if (!Equipment.getText().isEmpty()) { PdfPCell cell1 = new PdfPCell(new Phrase(messages.getString("Equipment") + ":" + Equipment.getText())); cell1.setBorderColor(BaseColor.WHITE); tablaDatosPlan.addCell(cell1); } document.add(tablaDatosPlan); document.add(new Phrase("\n")); document.add(new Phrase("\n")); PdfPTable tablaEjercicios = new PdfPTable(4); tablaEjercicios.setHeaderRows(contadorlineas); tablaEjercicios.addCell(messages.getString("Start")); tablaEjercicios.addCell(messages.getString("End")); tablaEjercicios.addCell(messages.getString("Drill")); tablaEjercicios.addCell(messages.getString("Notes")); int cont = 0; for (int aw = 4; aw < contadorlineas + 4; aw++) { tablaEjercicios.addCell(starColumn.getCellData(cont)); tablaEjercicios.addCell(endColumn.getCellData(cont)); tablaEjercicios.addCell(drillColumn.getCellData(cont)); tablaEjercicios.addCell(notesColumn.getCellData(cont)); cont++; } document.add(tablaEjercicios); int contadorListado = 0, contadorRecorrer = 0; if (checkboxDrills.isSelected()) { while (contadorListado < planData.size()) { contadorRecorrer = 0; while (contadorRecorrer < playData.size()) { System.out.println("Busco el ejercicio " + drillColumn.getCellData(contadorListado)); if (drillColumn.getCellData(contadorListado) .contains(playData.get(contadorRecorrer).getNombreJugada())) { int contador = 1; System.out.println("Ejercicio encontrado"); document.add(new Paragraph( messages.getString("Drill") + " " + drillColumn.getCellData(contadorListado))); while (contador < playData.get(contadorRecorrer).getContadorJugada() + 1) { document.add(new Paragraph(messages.getString("Diagram") + " " + contador)); document.add(new Paragraph(" ")); Image image2 = Image.getInstance(playData.get(contadorRecorrer).getNombreJugada() + "-" + playData.get(contadorRecorrer).getTipoJugada() + "-" + playData.get(contadorRecorrer).getSubtipoJugada() + "_" + contador); image2.scalePercent(50); PdfPTable table1 = new PdfPTable(2); table1.addCell(image2); table1.addCell( textPdf.textPdf(contador, playData.get(contadorRecorrer).getDescripcionJugada(), playData.get(contadorRecorrer).getContadorJugada())); document.add(table1); contador++; } } contadorRecorrer++; } contadorListado++; } } // step 5 document.close(); return document; }
From source file:edu.harvard.mcz.precapture.encoder.LabelEncoder.java
License:Open Source License
@SuppressWarnings("hiding") public static boolean printList(ArrayList<ContainerLabel> containers) throws PrintFailedException { log.debug("Invoked printList "); boolean result = false; ContainerLabel label = new ContainerLabel(); if (containers.isEmpty()) { log.debug("No labels to print."); } else {/*w w w .j a v a 2 s . co m*/ LabelDefinitionType printDefinition = null; LabelDefinitionListType printDefs = PreCaptureSingleton.getInstance().getPrintFormatDefinitionList(); List<LabelDefinitionType> printDefList = printDefs.getLabelDefinition(); Iterator<LabelDefinitionType> il = printDefList.iterator(); while (il.hasNext()) { LabelDefinitionType def = il.next(); if (def.getTitle().equals(PreCaptureSingleton.getInstance().getProperties().getProperties() .getProperty(PreCaptureProperties.KEY_SELECTED_PRINT_DEFINITION))) { printDefinition = def; } } if (printDefinition == null) { log.error("No selected print format defintion found."); //TODO change from message to error handling dialog that allows picking a print format. JOptionPane.showMessageDialog(null, "Unable to print. No print format is selected."); } else { log.debug(printDefinition.getTitle()); log.debug(printDefinition.getTextOrentation().toString()); LabelEncoder encoder = new LabelEncoder(containers.get(0)); try { Image image = encoder.getImage(); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(PreCaptureSingleton.getInstance() .getProperties().getProperties().getProperty(PreCaptureProperties.KEY_LABELPRINTFILE))); // Convert units in print definition to points (72 points/inch, 28.346456 points/cm) int paperWidthPoints = 612; // 8.5" int paperHeightPoints = 792; // 11" int marginsPoints = 36; // 0.5" int labelWidthPoints = 540; // 7.5" int labelHeightPoints = 720; // 10" int numColumns = 1; // goes with above numColumns = printDefinition.getColumns(); float relWidthTextCell = printDefinition.getRelWidthTextCell(); float relWidthBarcodeCell = printDefinition.getRelWidthBarcodeCell(); log.debug("relWidthTextCell = " + relWidthTextCell); log.debug("relWidthBarcodeCell = " + relWidthBarcodeCell); if (printDefinition.getUnits().toString().toLowerCase().equals("inches")) { paperWidthPoints = (int) Math.floor(printDefinition.getPaperWidth() * 72f); paperHeightPoints = (int) Math.floor(printDefinition.getPaperHeight() * 72f); marginsPoints = (int) Math.floor(printDefinition.getMargins() * 72f); labelWidthPoints = (int) Math.floor(printDefinition.getLabelWidth() * 72f); labelHeightPoints = (int) Math.floor(printDefinition.getLabelHeight() * 72f); } if (printDefinition.getUnits().toString().toLowerCase().equals("cm")) { paperWidthPoints = (int) Math.floor(printDefinition.getPaperWidth() * 28.346456f); paperHeightPoints = (int) Math.floor(printDefinition.getPaperHeight() * 28.346456f); marginsPoints = (int) Math.floor(printDefinition.getMargins() * 28.346456f); labelWidthPoints = (int) Math.floor(printDefinition.getLabelWidth() * 28.346456f); labelHeightPoints = (int) Math.floor(printDefinition.getLabelHeight() * 28.346456f); } if (printDefinition.getUnits().toString().toLowerCase().equals("points")) { paperWidthPoints = (int) Math.floor(printDefinition.getPaperWidth() * 1f); paperHeightPoints = (int) Math.floor(printDefinition.getPaperHeight() * 1f); marginsPoints = (int) Math.floor(printDefinition.getMargins() * 1f); labelWidthPoints = (int) Math.floor(printDefinition.getLabelWidth() * 1f); labelHeightPoints = (int) Math.floor(printDefinition.getLabelHeight() * 1f); } if (paperWidthPoints == 612 && paperHeightPoints == 792) { document.setPageSize(PageSize.LETTER); } else { document.setPageSize(new Rectangle(paperWidthPoints, paperHeightPoints)); } document.setMargins(marginsPoints, marginsPoints, marginsPoints, marginsPoints); document.open(); // Sanity check if (paperWidthPoints <= 0) { paperWidthPoints = 612; } if (paperHeightPoints <= 0) { paperHeightPoints = 792; } if (marginsPoints < 0) { marginsPoints = 0; } if (labelWidthPoints <= 0) { labelWidthPoints = 540; } if (labelHeightPoints <= 0) { labelHeightPoints = 720; } if (paperWidthPoints + (marginsPoints * 2) < labelWidthPoints) { labelWidthPoints = paperWidthPoints + (marginsPoints * 2); log.debug("Adjusting label width to fit printable page width"); } if (paperHeightPoints + (marginsPoints * 2) < labelHeightPoints) { labelHeightPoints = paperHeightPoints + (marginsPoints * 2); log.debug("Adjusting label height to fit printable page height"); } // calculate how many columns will fit on the paper. int columns = (int) Math.floor((paperWidthPoints - (marginsPoints * 2)) / labelWidthPoints); // if specified column count is smaller, use the specified. if (numColumns < columns) { columns = numColumns; log.debug( "Fewer columns specified in definition than will fit on page, using specified column count of " + numColumns); } // define two table cells per column, one for text one for barcode. int subCellColumnCount = columns * 2; // set the table, with an absolute width and relative widths of the cells in the table; PdfPTable table = setupTable(paperWidthPoints, marginsPoints, labelWidthPoints, columns, subCellColumnCount, relWidthTextCell, relWidthBarcodeCell); // figure out the width of the cells containing the barcodes. float ratio = ((float) relWidthBarcodeCell) / (((float) relWidthBarcodeCell) + ((float) relWidthTextCell)); float barcodeCellWidthPoints = (float) Math.floor(labelWidthPoints * ratio); log.debug("Width of barcode cell in points: " + barcodeCellWidthPoints); //Rectangle pageSizeRectangle = new Rectangle(paperWidthPoints, paperHeightPoints); //table.setWidthPercentage(cellWidthsPoints, pageSizeRectangle); //table.setTotalWidth(cellWidthsPoints); // Calculate how many cells fit on a page (two cells per label). int labelsPerColumn = (int) Math .floor((paperHeightPoints - (marginsPoints * 2)) / labelHeightPoints); int cellsPerPage = subCellColumnCount * labelsPerColumn; log.debug("Labels per column = " + labelsPerColumn); log.debug("Cells per page = " + cellsPerPage); Iterator<ContainerLabel> iterLabels = containers.iterator(); int cellCounter = 0; // counts number of cells filled on a page. int counter = 0; // counts number of pre capture label data rows to print (each of which may request more than one copy). // TODO: Doesn't fit on page. while (iterLabels.hasNext()) { // Loop through all of the container labels found to print label = iterLabels.next(); if (label != null) { log.debug(label); log.debug("Label: " + counter + " " + label.toString()); for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) { // For each container label, loop through the number of requested copies // Generate a text and a barcode cell for each, and add to array for page int toPrintPlus = toPrint + 1; // for pretty counter in log. log.debug("Copy " + toPrintPlus + " of " + label.getNumberToPrint()); PdfPCell cell = label.toPDFCell(printDefinition); cell.setFixedHeight(labelHeightPoints); // Colors to illustrate where the cells are on the layout if (PreCaptureSingleton.getInstance().getProperties().getProperties() .getProperty(PreCaptureProperties.KEY_DEBUGLABEL).equals("true")) { cell.setBackgroundColor(new BaseColor(255, 255, 30)); } PdfPCell cell_barcode = new PdfPCell(); cell_barcode.setBorderColor(BaseColor.LIGHT_GRAY); cell_barcode.disableBorderSide(PdfPCell.LEFT); cell_barcode.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell_barcode.setHorizontalAlignment(Element.ALIGN_RIGHT); cell_barcode.setFixedHeight(labelHeightPoints); if (PreCaptureSingleton.getInstance().getProperties().getProperties() .getProperty(PreCaptureProperties.KEY_DEBUGLABEL).equals("true")) { cell_barcode.setBackgroundColor(new BaseColor(255, 30, 255)); } encoder = new LabelEncoder(label); image = encoder.getImage(); image.setAlignment(Image.ALIGN_TOP); //image.setAlignment(Image.ALIGN_LEFT); image.setAlignment(Image.ALIGN_RIGHT); image.scaleToFit(barcodeCellWidthPoints, labelHeightPoints); cell_barcode.addElement(image); table.addCell(cell); table.addCell(cell_barcode); cellCounter = cellCounter + 2; // we've added two cells to the page (two cells per label). log.debug("Cells " + cellCounter + " of " + cellsPerPage + " cells per page."); // If we have hit a full set of labels for the page, add them to the document // in each column, filling left to right if (cellCounter >= cellsPerPage - 1) { log.debug("Page is full"); log.debug("Table has " + table.getNumberOfColumns() + " columns and " + table.getRows().size() + " rows "); // Reset to begin next page cellCounter = 0; table.setLockedWidth(true); document.add(table); log.debug("Adding new page"); document.newPage(); table = setupTable(paperWidthPoints, marginsPoints, labelWidthPoints, columns, subCellColumnCount, relWidthTextCell, relWidthBarcodeCell); log.debug("Setup new table"); } } // end loop through toPrint (for a taxon/precapture label data row) counter++; // Increment number of pre capture label data rows. } // end if not null label } // end while results has next (for all taxa requested) // get any remaining cells in pairs if (cellCounter > 0) { log.debug("Adding remaining cells in partial page"); if (cellCounter <= cellsPerPage) { for (int i = cellCounter; i <= cellsPerPage; i++) { PdfPCell emptyCell = new PdfPCell(); emptyCell.setBorder(PdfPCell.NO_BORDER); table.addCell(emptyCell); } } log.debug("Table has " + table.getNumberOfColumns() + " columns and " + table.getRows().size() + " rows "); table.setLockedWidth(true); document.add(table); } document.close(); // send to printer PrintingUtility.sendPDFToPrinter(printDefinition, paperWidthPoints, paperHeightPoints); // Check to see if there was content in the document. if (counter == 0) { result = false; } else { // Printed to pdf ok. result = true; } } catch (FileNotFoundException e) { log.debug(e.getMessage(), e); throw new PrintFailedException("File not found."); } catch (DocumentException e) { log.error(e.getMessage(), e); throw new PrintFailedException("Error building/printing PDF document. " + e.getMessage()); } catch (OutOfMemoryError e) { System.out.println("Out of memory error. " + e.getMessage()); System.out.println("Failed. Too many labels."); throw new PrintFailedException("Ran out of memory, too many labels at once."); } catch (BarcodeCreationException e) { System.out.println("BarcodeCreationException. " + e.getMessage()); System.out.println("Failed. Couldn't create barcode."); throw new PrintFailedException( "Unable to create barcode. Probably too many characters to encode. " + e.getMessage()); } } log.debug("printList Done. Success = " + result); } return result; }
From source file:edu.harvard.mcz.precapture.ui.ContainerLabel.java
License:Open Source License
/** * // w w w . jav a2 s .co m * @return a PDF paragraph cell containing a text encoding of the fields in this set. */ public PdfPCell toPDFCell(LabelDefinitionType printDefinition) { PdfPCell cell = new PdfPCell(); ; if (printDefinition.getTextOrentation().toString().toLowerCase() .equals(TextOrentationType.VERTICAL.toString().toLowerCase())) { log.debug("Print orientation of text is Vertical"); cell.setRotation(90); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); } cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell.disableBorderSide(PdfPCell.RIGHT); cell.setPaddingLeft(3); cell.setNoWrap(false); int leading = (int) (fields.get(0).getField().getFontSize() + printDefinition.getFontDelta()) - 1; Paragraph higher = new Paragraph(leading, "", new Font(Font.FontFamily.TIMES_ROMAN, fields.get(0).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL)); higher.setSpacingBefore(0); higher.setSpacingAfter(0); boolean added = false; boolean hasContent = false; for (int i = 0; i < fields.size(); i++) { log.debug(i); if (fields.get(i).getField().isNewLine() || (i == fields.size() - 1)) { if (!higher.isEmpty()) { log.debug(higher.getContent()); cell.addElement(higher); } leading = (int) (fields.get(i).getField().getFontSize() + printDefinition.getFontDelta()) - 1; higher = new Paragraph(leading, "", new Font(Font.FontFamily.TIMES_ROMAN, fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL)); higher.setSpacingBefore(0); higher.setSpacingAfter(0); added = false; hasContent = false; } log.debug(fields.get(i).getTextField().getText().trim()); Chunk chunk = new Chunk(fields.get(i).getTextField().getText().trim()); if (fields.get(i).getField().isUseItalic()) { chunk.setFont(new Font(Font.FontFamily.TIMES_ROMAN, fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.ITALIC)); } else { chunk.setFont(new Font(Font.FontFamily.TIMES_ROMAN, fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL)); } if (!chunk.isEmpty()) { hasContent = true; higher.add(chunk); log.debug(fields.get(i).getField().getSuffix()); if (fields.get(i).getField().getSuffix() != null && fields.get(i).getField().getSuffix().length() > 0) { higher.add(new Chunk(fields.get(i).getField().getSuffix())); } if (fields.get(i).getTextField().getText().trim().length() > 0) { // add a trailing space as a separator if there was something to separate. higher.add(new Chunk(" ")); } } } if (!added) { log.debug(higher.getContent()); cell.addElement(higher); } String extraText = PreCaptureSingleton.getInstance().getProperties().getProperties() .getProperty(PreCaptureProperties.KEY_EXTRAHUMANTEXT); if (extraText != null && extraText.length() > 0) { log.debug(extraText); cell.addElement(new Chunk(extraText)); } return cell; }
From source file:Export.ReciboPagamento.java
public PdfPTable detaDoc(HashMap<String, Object> map, Font fontTitile, Font fontRecibo, Font fontTitileShort, Font fontReciboTxt, Font fontConteudo, Font fontConteudoTxt, Font fontConteudoTxtUl) throws DocumentException { PdfPTable pTablePrincipal = new PdfPTable(new float[] { 100 }); try {/*from w w w . j a va2 s . c o m*/ pTablePrincipal.setWidthPercentage(100f); PdfPTable pTableTitulo = new PdfPTable(new float[] { 60, 40 }); pTableTitulo.setWidthPercentage(100); PdfPTable pTableTituloImage = new PdfPTable(new float[] { 20, 80 }); pTableTituloImage.setWidthPercentage(100); PdfPCell cellTitulo = new PdfPCell(new Phrase(ConfigDoc.Empresa.NOME, fontTitile)); cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER); cellTitulo.setBorder(0); cellTitulo.setPaddingTop(20f); cellTitulo.setPaddingLeft(70f); pTableTitulo.addCell(cellTitulo); cellTitulo = new PdfPCell(new Phrase("Recibo N ".toUpperCase() + map.get(IDAMORTIZACAO), fontRecibo)); cellTitulo.setVerticalAlignment(Element.ALIGN_BOTTOM); cellTitulo.setHorizontalAlignment(Element.ALIGN_RIGHT); cellTitulo.setBorder(0); pTableTitulo.addCell(cellTitulo); cellTitulo = new PdfPCell(new Phrase(ConfigDoc.Empresa.ENDERECO + ", " + ConfigDoc.Empresa.CAIXAPOSTAL + ", " + ConfigDoc.Empresa.TELEFAX, fontTitileShort)); cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER); cellTitulo.setPaddingLeft(70f); cellTitulo.setBorder(0); pTableTitulo.addCell(cellTitulo); cellTitulo = new PdfPCell(new Phrase(" ", fontTitileShort)); cellTitulo.setPaddingBottom(0f); cellTitulo.setPaddingTop(0f); cellTitulo.setBorder(0); pTableTitulo.addCell(cellTitulo); cellTitulo = new PdfPCell(new Phrase(ConfigDoc.Empresa.REPUBLICA, fontTitileShort)); cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER); cellTitulo.setBorder(0); cellTitulo.setPaddingLeft(70f); pTableTitulo.addCell(cellTitulo); cellTitulo = new PdfPCell(new Phrase(" ", fontTitileShort)); cellTitulo.setPaddingBottom(0f); cellTitulo.setPaddingTop(0f); cellTitulo.setBorder(0); pTableTitulo.addCell(cellTitulo); cellTitulo = new PdfPCell(new Phrase(ConfigDoc.Empresa.EMAIL, fontTitileShort)); cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER); cellTitulo.setBorder(0); cellTitulo.setPaddingLeft(70f); pTableTitulo.addCell(cellTitulo); cellTitulo = new PdfPCell(new Phrase(" ", fontTitileShort)); cellTitulo.setPaddingBottom(0f); cellTitulo.setPaddingTop(0f); cellTitulo.setBorder(0); pTableTitulo.addCell(cellTitulo); cellTitulo = new PdfPCell(new Phrase("Ordem de receita / recibo".toUpperCase(), fontRecibo)); cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER); cellTitulo.setBorder(0); cellTitulo.setPaddingLeft(70f); pTableTitulo.addCell(cellTitulo); cellTitulo = new PdfPCell(new Phrase(" ", fontTitileShort)); cellTitulo.setVerticalAlignment(Element.ALIGN_TOP); cellTitulo.setPaddingBottom(30f); cellTitulo.setPaddingTop(0f); cellTitulo.setBorder(0); pTableTitulo.addCell(cellTitulo); Image imageEmpresa = Image.getInstance("logo.png"); imageEmpresa.scaleToFit(120f, 85f); imageEmpresa.setAlignment(Image.ALIGN_CENTER); PdfPCell cellImagem = new PdfPCell(imageEmpresa); cellImagem.setBorder(PdfPCell.NO_BORDER); cellImagem.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellImagem.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); PdfPCell cellpTableTitulo = new PdfPCell(pTableTitulo); cellpTableTitulo.setBorder(PdfPCell.NO_BORDER); cellpTableTitulo.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); pTableTituloImage.addCell(cellImagem); pTableTituloImage.addCell(cellpTableTitulo); PdfPCell cellpTableTituloPrincipal = new PdfPCell(pTableTituloImage); cellpTableTituloPrincipal.setBorder(PdfPCell.NO_BORDER); pTablePrincipal.addCell(cellpTableTituloPrincipal); PdfPTable pTableDataCaixaMontante = new PdfPTable(new float[] { 35f, 5f, 60f }); pTableDataCaixaMontante.setWidthPercentage(100f); PdfPCell cellDataCaixaMontante = new PdfPCell(new Phrase(" ", fontRecibo)); cellDataCaixaMontante.setBorder(0); pTableDataCaixaMontante.addCell(cellDataCaixaMontante); pTableDataCaixaMontante.addCell(cellDataCaixaMontante); cellDataCaixaMontante = new PdfPCell(); cellDataCaixaMontante.setBorder(0); Paragraph p = new Paragraph(); p.add(new Phrase("Data: ".toUpperCase(), fontRecibo)); p.add(new Phrase(converterData(map.get(REGISTROAMORTIZACAO), 1), fontReciboTxt)); p.setAlignment(Element.ALIGN_RIGHT); cellDataCaixaMontante.addElement(p); cellDataCaixaMontante.setPaddingBottom(5f); pTableDataCaixaMontante.addCell(cellDataCaixaMontante); cellDataCaixaMontante = new PdfPCell(); p = new Paragraph(); p.add(new Phrase("Caixa de: ".toUpperCase(), fontRecibo)); p.add(new Phrase("So Tom", fontReciboTxt)); p.setAlignment(Element.ALIGN_LEFT); cellDataCaixaMontante.addElement(p); cellDataCaixaMontante.setPaddingTop(-2f); cellDataCaixaMontante.setPaddingBottom(5f); cellDataCaixaMontante.setBorderColor(BaseColor.BLUE.darker().darker().darker()); pTableDataCaixaMontante.addCell(cellDataCaixaMontante); cellDataCaixaMontante = new PdfPCell(new Phrase(" ", fontRecibo)); cellDataCaixaMontante.setBorder(0); pTableDataCaixaMontante.addCell(cellDataCaixaMontante); cellDataCaixaMontante = new PdfPCell(); p = new Paragraph(); p.add(new Phrase("Montante: ".toUpperCase(), fontRecibo)); Double montade = Moeda.arrendodamento(toString(map.get(VALORAMORTIZADO))); // SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:"); Object dRegistro = map.get(DATAREGAPOLICE); montade *= valorCompra(map.get(SIGLAMOEDA) + "", dRegistro); p.add(new Phrase(converterMoeda(montade, "STD") + "", fontReciboTxt)); p.setAlignment(Element.ALIGN_LEFT); cellDataCaixaMontante.addElement(p); cellDataCaixaMontante.setPaddingTop(-2f); cellDataCaixaMontante.setPaddingBottom(5f); cellDataCaixaMontante.setBorderColor(BaseColor.BLUE.darker().darker().darker()); pTableDataCaixaMontante.addCell(cellDataCaixaMontante); PdfPCell cellDataCaixaMontantePrincipal = new PdfPCell(pTableDataCaixaMontante); cellDataCaixaMontantePrincipal.setBorder(PdfPCell.NO_BORDER); pTablePrincipal.addCell(cellDataCaixaMontantePrincipal); PdfPTable pTableConteudo = new PdfPTable(new float[] { 40, 60 }); pTableConteudo.setWidthPercentage(100f); PdfPCell cellConteudo = new PdfPCell(); cellConteudo.setBorder(0); Paragraph pConteudo = new Paragraph(); pConteudo.add(new Phrase("N Assegurado: ".toUpperCase(), fontConteudo)); pConteudo.add(new Phrase(map.get(NUMREGISTRO) + "\n", fontConteudoTxt)); /** * For alter */ pConteudo.add(new Phrase("Prmio Liquido: ".toUpperCase(), fontConteudo)); pConteudo.add(new Phrase(converterMoeda(map.get(TOTALBRUTO), map.get(SIGLAMOEDA) + "") + "\n", fontConteudoTxt)); pConteudo.add(new Phrase("Impostos: ".toUpperCase(), fontConteudo)); pConteudo.add(new Phrase(converterMoeda(impostosCalculo(map.get(TOTAl), map.get(IMPOSTOCONSUMO)), map.get(SIGLAMOEDA) + "") + "\n", fontConteudoTxt)); pConteudo.add(new Phrase("Impostos Selo: ".toUpperCase(), fontConteudo)); pConteudo.add(new Phrase( converterMoeda(impostosCalculo(map.get(TOTAl), map.get(IMPOSTOSELO)), map.get(SIGLAMOEDA) + "") + "\n", fontConteudoTxt)); pConteudo.add(new Phrase("FGA: ", fontConteudo)); pConteudo.add(new Phrase( converterMoeda(impostosCalculo(map.get(TOTAl), map.get(MOTORFOUND)), map.get(SIGLAMOEDA) + "") + "\n", fontConteudoTxt)); pConteudo.add(new Phrase("Total: ".toUpperCase(), fontConteudo)); pConteudo.add( new Phrase(converterMoeda(map.get(TOTAl), map.get(SIGLAMOEDA) + "") + "\n", fontConteudoTxt)); pConteudo.add(new Phrase("Efeito: ".toUpperCase(), fontConteudo)); pConteudo.add(new Phrase(converterData(map.get(EFEITO), 1) + "\n", fontConteudoTxt)); pConteudo.add(new Phrase("Vencimento: ".toUpperCase(), fontConteudo)); pConteudo.add(new Phrase(converterData(map.get(VENCIMENTO), 1) + "\n", fontConteudoTxt)); cellConteudo.addElement(pConteudo); pTableConteudo.addCell(cellConteudo); cellConteudo = new PdfPCell(); cellConteudo.setBorder(0); pConteudo = new Paragraph(); pConteudo.add(new Phrase("Recebido do Sr: ".toUpperCase(), fontConteudo)); pConteudo.add(new Phrase(map.get(CLIENTE) + "\n", fontConteudoTxt)); PdfPTable pTableNomeCod = new PdfPTable(new float[] { 70, 30 }); pTableNomeCod.setWidthPercentage(100); Paragraph pNomeCod = new Paragraph(); pNomeCod.add(new Phrase("Nome do Assegurado/Pagador: ".toUpperCase(), fontConteudo)); pNomeCod.add(new Phrase(map.get(CLIENTE) + "", fontConteudoTxt)); PdfPCell cellNomeCod = new PdfPCell(); cellNomeCod.addElement(pNomeCod); cellNomeCod.setBorder(0); cellNomeCod.setPaddingTop(-2f); cellNomeCod.setPaddingBottom(2f); pTableNomeCod.addCell(cellNomeCod); cellNomeCod = new PdfPCell(); pNomeCod = new Paragraph(); pNomeCod.add(new Phrase("Codigo: ".toUpperCase(), fontConteudo)); pNomeCod.add(new Phrase(" ", fontConteudoTxt)); cellNomeCod.addElement(pNomeCod); cellNomeCod.setBorder(0); cellNomeCod.setPaddingTop(-2f); cellNomeCod.setPaddingBottom(2f); pTableNomeCod.addCell(cellNomeCod); pNomeCod = new Paragraph(); pNomeCod.add(new Phrase("Nome do Intermedirio: ".toUpperCase(), fontConteudo)); pNomeCod.add(new Phrase(" ", fontConteudoTxt)); cellNomeCod = new PdfPCell(); cellNomeCod.addElement(pNomeCod); cellNomeCod.setBorder(0); cellNomeCod.setPaddingTop(-2f); cellNomeCod.setPaddingBottom(2f); pTableNomeCod.addCell(cellNomeCod); cellNomeCod = new PdfPCell(); pNomeCod = new Paragraph(); pNomeCod.add(new Phrase("Codigo: ".toUpperCase(), fontConteudo)); pNomeCod.add(new Phrase(" ", fontConteudoTxt)); cellNomeCod.addElement(pNomeCod); cellNomeCod.setBorder(0); cellNomeCod.setPaddingTop(-2f); cellNomeCod.setPaddingBottom(2f); pTableNomeCod.addCell(cellNomeCod); pConteudo.add(pTableNomeCod); JTextPane jtp = new JTextPane(); Double valor = Moeda.arrendodamento((map.get(VALORPRESTACAO) + "")); valor *= valorCompra(map.get(SIGLAMOEDA) + "", dRegistro); Moeda.EscreverEstenso(valor, jtp, "Dobras"); pConteudo.add(new Phrase("A soma (por extenso) ".toUpperCase(), fontConteudo)); pConteudo.add(new Phrase(jtp.getText().trim() + "\n", fontConteudoTxt)); PdfPTable pTableApoliceDatasP = new PdfPTable(new float[] { 20, 80 }); pTableApoliceDatasP.setWidthPercentage(100); PdfPTable pTableApoliceDatas = new PdfPTable(new float[] { 60, 40 }); pTableApoliceDatas.setWidthPercentage(100); for (int i = 0; i < 1; i++) { PdfPCell cellApolice = new PdfPCell(); Paragraph pApolice = new Paragraph(); pApolice.add(new Phrase("N ", fontConteudo)); pApolice.add(new Phrase(map.get(APOLICA) + "", fontConteudoTxt)); cellApolice.addElement(pApolice); cellApolice.setPaddingTop(-2f); cellApolice.setPaddingBottom(2f); cellApolice.setBorder(0); pTableApoliceDatas.addCell(cellApolice); PdfPCell cellDatas = new PdfPCell(); Paragraph pDatas = new Paragraph(); pDatas.add(new Phrase("Data: ".toUpperCase(), fontConteudo)); pDatas.add(new Phrase(converterData(map.get(DATAREGAPOLICE), 2) + "", fontConteudoTxt)); cellDatas.addElement(pDatas); cellDatas.setBorder(0); cellDatas.setPaddingTop(-2f); cellDatas.setPaddingBottom(2f); pTableApoliceDatas.addCell(cellDatas); } PdfPCell cellApoliceP = new PdfPCell(new Phrase("Apolices".toUpperCase(), fontConteudo)); cellApoliceP.setVerticalAlignment(Element.ALIGN_MIDDLE); cellApoliceP.setBorder(0); pTableApoliceDatasP.addCell(cellApoliceP); cellApoliceP = new PdfPCell(pTableApoliceDatas); cellApoliceP.setBorder(0); pTableApoliceDatasP.addCell(cellApoliceP); pConteudo.add(pTableApoliceDatasP); // PdfPTable pTableTipoPagemento = new PdfPTable(new float[] { 70f, 30f }); pTableTipoPagemento.setWidthPercentage(100f); PdfPCell cellTipoPageme = new PdfPCell(); Paragraph pDatas = new Paragraph(); pDatas.add(new Phrase("Pagamento: ".toUpperCase(), fontConteudo)); pDatas.add(new Phrase(map.get(TIPOPAGAMENTO) + " ", fontConteudoTxt)); cellTipoPageme.addElement(pDatas); cellTipoPageme.setBorder(0); cellTipoPageme.setPaddingTop(-2f); cellTipoPageme.setPaddingBottom(2f); // cellTipoPageme.setBorderColor(BaseColor.BLUE.darker().darker().darker()); // cellTipoPageme.setBorderWidthTop((i==0)?0.5f:0f); // cellTipoPageme.setBorderWidthBottom(0.5f); pTableTipoPagemento.addCell(cellTipoPageme); cellTipoPageme = new PdfPCell(); pDatas = new Paragraph(); pDatas.add(new Phrase("N ".toUpperCase(), fontConteudo)); pDatas.add(new Phrase(toString(map.get(DOCUMENTOAMORTIZACAO)) + " ", fontConteudoTxt)); cellTipoPageme.addElement(pDatas); cellTipoPageme.setBorder(0); cellTipoPageme.setPaddingTop(-2f); cellTipoPageme.setPaddingBottom(2f); // cellTipoPageme.setBorderColor(BaseColor.BLUE.darker().darker().darker()); // cellTipoPageme.setBorderWidthTop((i==0)?0.5f:0f); // cellTipoPageme.setBorderWidthBottom(0.5f); pTableTipoPagemento.addCell(cellTipoPageme); pConteudo.add(pTableTipoPagemento); cellConteudo.addElement(pConteudo); pTableConteudo.addCell(cellConteudo); PdfPCell cellConteudoPrincipal = new PdfPCell(new PdfPTable(pTableConteudo)); cellConteudoPrincipal.setBorder(PdfPCell.NO_BORDER); pTablePrincipal.addCell(cellConteudoPrincipal); PdfPTable pTableAssinatura = new PdfPTable(new float[] { 50f, 50f }); pTableAssinatura.setWidthPercentage(100f); Font fontConteudoTxt_acess = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 5f, Font.ITALIC, BaseColor.BLACK.darker().darker().darker()); Font fontConteudo_acess = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 5f, Font.NORMAL, BaseColor.BLUE.darker().darker()); PdfPCell cellAcessorio = new PdfPCell(); Paragraph pAcessorio = new Paragraph(); pAcessorio.add(new Phrase("Acessrios: ".toUpperCase(), fontConteudo_acess)); pAcessorio.add(new Phrase( (map.get(ACCESSORIO) == null) ? " " : (map.get(ACCESSORIO) + "").replaceAll("\n", " "), fontConteudoTxt_acess)); cellAcessorio.addElement(pAcessorio); cellAcessorio.setColspan(2); cellAcessorio.setBorder(0); cellAcessorio.setPaddingBottom(4f); cellAcessorio.setPaddingTop(-2f); pTableAssinatura.addCell(cellAcessorio); PdfPCell cellLinhaAssina = new PdfPCell(); Paragraph pAssinatura = new Paragraph(); pAssinatura.add(new Paragraph("_________________________________", fontConteudo)); pAssinatura.add(new Paragraph(" Carimbo e Assinatura", fontConteudo)); pAssinatura.setAlignment(Element.ALIGN_CENTER); cellLinhaAssina.addElement(pAssinatura); cellLinhaAssina.setPaddingBottom(2f); cellLinhaAssina.setBorder(0); cellLinhaAssina.setPaddingTop(25f); pTableAssinatura.addCell(cellLinhaAssina); PdfPCell cellCambio = new PdfPCell(); Paragraph pCombio = new Paragraph(); pCombio.add(new Phrase("Cambio (USD): ".toUpperCase(), fontConteudo)); pCombio.add(new Phrase(converterMoeda(valorCompra("USD", dRegistro), "") + "\n", fontConteudoTxt)); pCombio.add(new Phrase("Cambio (EUR): ".toUpperCase(), fontConteudo)); pCombio.add(new Phrase(converterMoeda(valorCompra("EUR", dRegistro), "") + "\n", fontConteudoTxt)); cellCambio.addElement(pCombio); cellCambio.setBorder(0); cellCambio.setPaddingTop(-2f); cellCambio.setPaddingBottom(2f); pTableAssinatura.addCell(cellCambio); PdfPCell cellpTableAssinaturaPrincipal = new PdfPCell(pTableAssinatura); cellpTableAssinaturaPrincipal.setBorder(PdfPCell.NO_BORDER); pTablePrincipal.addCell(new PdfPCell(cellpTableAssinaturaPrincipal)); // pTableAssinatura.writeSelectedRows(-1, 2, 10, 70, writer.getDirectContent()); // pTableImagem.writeSelectedRows(-1, 2, 52.5f, 402.5f, writer.getDirectContent()); } catch (BadElementException | IOException ex) { Logger.getLogger(ReciboPagamento.class.getName()).log(Level.SEVERE, null, ex); } return pTablePrincipal; }
From source file:Funciones.TicketPDF.java
PdfPTable tablaHeader() throws IOException, BadElementException { PdfPTable tablaheader = new PdfPTable(4); tablaheader.setTotalWidth(600);/*from w ww. j a v a 2 s. co m*/ BasededatosManager bd = new BasededatosManager(); try { ResultSet consulta = bd.consultar("SELECT logoempresa FROM configuracion"); byte[] arreglo = null; while (consulta.next()) { arreglo = consulta.getBytes("logoempresa"); } Image logo = Image.getInstance(arreglo); logo.scalePercent(15); PdfPCell celdalogo = new PdfPCell(logo); celdalogo.setBorderColor(BaseColor.WHITE); celdalogo.setColspan(4); celdalogo.setHorizontalAlignment(Element.ALIGN_CENTER); tablaheader.addCell(celdalogo); } catch (SQLException ex) { Logger.getLogger(PedidoPDF.class.getName()).log(Level.SEVERE, null, ex); } Font a = new Font(FontFamily.HELVETICA, 18, Font.BOLD, BaseColor.BLACK); PdfPCell celdatitulo = new PdfPCell(new Paragraph("PEDIDO PIZZAS", a)); celdatitulo.setColspan(2); celdatitulo.setBorderColor(BaseColor.WHITE); tablaheader.addCell(celdatitulo); PdfPCell celdafecha = new PdfPCell(new Paragraph("Fecha: " + LocalDate.now(), f)); celdafecha.setBorderColor(BaseColor.WHITE); tablaheader.addCell(celdafecha); PdfPCell celdapedido = new PdfPCell(new Paragraph("N Pedido: " + idpedido, f)); celdapedido.setBorderColor(BaseColor.WHITE); tablaheader.addCell(celdapedido); vacio.setColspan(4); vacio.setBorder(Rectangle.BOTTOM); tablaheader.addCell(vacio); return tablaheader; }
From source file:GUI_StafKlinik.Panel_Penggajian.java
private PdfPTable createTableLaporan(Penggajian p) { PdfPTable tabel = new PdfPTable(2); PdfPCell cell; cell = new PdfPCell(new Phrase(("Nama Pegawai"), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setColspan(1);//from w w w . java 2 s. c o m cell.setBorder(Rectangle.BOX); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); cell = new PdfPCell(new Phrase(("" + p.getNamaPegawai()), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); cell = new PdfPCell(new Phrase(("ID Pegawai"), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setColspan(1); cell.setBorder(Rectangle.BOX); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); cell = new PdfPCell(new Phrase(("" + p.getIdPegawai()), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); cell = new PdfPCell(new Phrase(("Alamat"), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setColspan(1); cell.setBorder(Rectangle.BOX); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); cell = new PdfPCell(new Phrase((""), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); cell = new PdfPCell(new Phrase(("Telepon"), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setColspan(1); cell.setBorder(Rectangle.BOX); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); cell = new PdfPCell(new Phrase((""), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); cell = new PdfPCell(new Phrase(("Jabatan"), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setColspan(1); cell.setBorder(Rectangle.BOX); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); cell = new PdfPCell(new Phrase((""), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); cell = new PdfPCell(new Phrase(("Gaji Pokok"), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setColspan(1); cell.setBorder(Rectangle.BOX); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); cell = new PdfPCell(new Phrase(("" + p.getGajiPokok()), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); cell = new PdfPCell(new Phrase(("Gaji Tambahan"), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setColspan(1); cell.setBorder(Rectangle.BOX); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); cell = new PdfPCell(new Phrase(("" + p.getGajiTambahan()), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); cell = new PdfPCell(new Phrase(("Total Gaji"), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setColspan(1); cell.setBorder(Rectangle.BOX); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); cell = new PdfPCell(new Phrase(("" + p.getTotalGaji()), font2)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorderWidth(1); cell.setBorderColor(BaseColor.WHITE); tabel.addCell(cell); return tabel; }