List of usage examples for com.itextpdf.text.pdf PdfPCell setVerticalAlignment
public void setVerticalAlignment(int verticalAlignment)
From source file:edu.ksu.cs.a4vm.bse.reporter.Reporter.java
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: // build a controller SwingController controller = new SwingController(); // Build a SwingViewFactory configured with the controller SwingViewBuilder factory = new SwingViewBuilder(controller); // Use the factory to build a JPanel that is pre-configured //with a complete, active Viewer UI. JPanel viewerComponentPanel = factory.buildViewerPanel(); // add copy keyboard command ComponentKeyBinding.install(controller, viewerComponentPanel); // add interactive mouse link annotation support via callback controller.getDocumentViewController().setAnnotationCallback( new org.icepdf.ri.common.MyAnnotationCallback(controller.getDocumentViewController())); // Create a JFrame to display the panel in JFrame window = new JFrame("Using the Viewer Component"); window.getContentPane().add(viewerComponentPanel); window.pack();/*ww w. j ava 2s . c o m*/ window.setVisible(true); String Path; JFileChooser fr = new JFileChooser(); FileSystemView fw = fr.getFileSystemView(); // System.out.println(fw.getDefaultDirectory()); Path = fw.getDefaultDirectory() + "/reporter.pdf"; try { br1 = new BufferedReader(new FileReader(f)); BufferedReader b1 = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException ex) { } String line = ""; bull1 = new String[number_of_rows - 1][]; int k = 0; BufferedReader br3 = null; try { br3 = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException ex) { } try { while ((line = br3.readLine()) != null) { // use comma as separator String Bull[] = line.split(","); if (k != 0) { System.out.println(Bull.length); bull1[k - 1] = new String[Bull.length]; for (int j = 0; j < Bull.length; j++) { bull1[k - 1][j] = Bull[j]; } } k++; } } catch (IOException ex) { } Document doc = new Document(); PdfWriter docWriter = null; DecimalFormat df = new DecimalFormat("0.00"); try { //special font sizes Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 6); Font bfBold20 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); //file path docWriter = PdfWriter.getInstance(doc, new FileOutputStream(Path)); //document header attributes doc.addAuthor("Shubh Chopra"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Shubh Chopra"); doc.addTitle("BES"); doc.setPageSize(PageSize.LETTER.rotate()); //open document doc.open(); //create a paragraph Paragraph paragraph = new Paragraph("BULL EVALUATION\n\n"); paragraph.setFont(bfBold20); paragraph.setAlignment(Element.ALIGN_CENTER); Image img = Image.getInstance("VETMED.png"); img.scaleToFit(300f, 150f); doc.add(paragraph); PdfPTable table1 = new PdfPTable(2); table1.setWidthPercentage(100); PdfPCell cell = new PdfPCell(img); cell.setBorder(PdfPCell.NO_BORDER); table1.addCell(cell); String temp1 = "\tOwner: " + bull1[1][62] + " " + bull1[1][63] + "\n\n\tRanch: " + bull1[1][64] + "\n\n\tAddress: " + bull1[1][55] + "\n\n\tCity: " + bull1[1][57] + "\n\n\tState: " + bull1[1][60] + "\tZip: " + bull1[1][61] + "\n\n\tPhone: " + bull1[1][59] + "\n\n"; table1.addCell(getCell(temp1, PdfPCell.ALIGN_LEFT)); doc.add(table1); if (dlm3.size() == 1) { String str; str = dlm3.get(0).toString(); String[] parts = str.split(":"); String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; String[][] temp = new String[25][6]; temp[0][0] = "Tag"; temp[0][1] = bull1[row][7]; temp[0][2] = "Comments"; temp[0][3] = ""; temp[0][4] = "Total Count"; temp[0][5] = ""; temp[1][0] = "Tatoo"; temp[1][1] = bull1[row][8]; temp[1][2] = "All Normal"; temp[1][3] = "Yes"; temp[2][0] = "RFID"; temp[2][1] = bull1[row][6]; temp[2][2] = "Eyes"; temp[2][3] = bull1[row][10]; temp[3][0] = "Lot#"; temp[3][1] = bull1[row][5]; temp[3][2] = "Feet"; temp[3][3] = bull1[row][12]; temp[4][0] = "Brand"; temp[4][1] = bull1[row][2]; temp[4][2] = "Legs"; temp[4][3] = bull1[row][14]; temp[5][0] = "Date of Birth"; temp[5][1] = bull1[row][4]; temp[5][2] = "Testicals"; temp[5][3] = bull1[row][16]; temp[6][0] = "Age"; temp[6][1] = bull1[row][0]; temp[6][2] = "Accessory Sex Glands"; temp[6][3] = bull1[row][18]; temp[7][0] = "Breed"; temp[7][1] = bull1[row][3]; temp[7][2] = "Inguinal"; temp[7][3] = bull1[row][20]; temp[8][0] = "Other"; temp[8][1] = bull1[row][9]; temp[8][2] = "Scrotal"; temp[8][3] = bull1[row][22]; temp[9][0] = "Clinic Info"; temp[9][1] = "xx"; temp[9][2] = "Epidydimides"; temp[9][3] = bull1[row][24]; temp[10][4] = "Measurements"; temp[10][5] = "xx"; temp[10][0] = "Clinic Name"; temp[10][1] = bull1[row][73]; temp[10][2] = "Penis"; temp[10][3] = bull1[row][26]; temp[11][4] = "Scrotal Cirumference"; temp[11][5] = bull1[row][54]; temp[11][0] = "Veterinarian Name"; temp[11][1] = bull1[row][74] + " " + bull1[row][75]; temp[11][2] = "Prepuce"; temp[11][3] = bull1[row][28]; temp[12][4] = "Body Condition"; temp[12][5] = bull1[row][47]; temp[12][0] = "Address"; temp[12][1] = bull1[row][66] + " " + bull1[row][67]; temp[12][2] = "Scrotum"; temp[12][3] = bull1[row][30]; temp[13][4] = "Pelvic X Measure"; temp[13][5] = bull1[row][52]; temp[13][0] = "City"; temp[13][1] = bull1[row][68]; temp[13][2] = "Sex Drive"; temp[13][3] = "xx"; temp[14][4] = "Pelvic Y Measure"; temp[14][5] = bull1[row][53]; temp[14][0] = "State"; temp[14][1] = bull1[row][71]; temp[14][2] = "Breeding seasons used"; temp[14][3] = bull1[row][40]; temp[15][4] = "Hip Hight"; temp[15][5] = bull1[row][50]; temp[15][0] = "Zip Code"; temp[15][1] = bull1[row][72]; temp[15][2] = "Performance last season"; temp[15][3] = bull1[row][38]; temp[16][4] = "Frame Score"; temp[16][5] = bull1[row][49]; temp[16][0] = "Email"; temp[16][1] = bull1[row][69]; temp[16][2] = "Single or Multi sire"; temp[16][3] = bull1[row][41]; temp[17][4] = "Other"; temp[17][5] = bull1[row][48]; temp[17][0] = "Phone"; temp[17][1] = bull1[row][70]; temp[17][2] = "Other"; temp[17][3] = bull1[row][39]; temp[18][4] = "Motility"; temp[18][5] = "xx"; temp[18][0] = "Classification"; temp[18][1] = bull1[row][35]; temp[18][2] = "Comments"; temp[18][3] = bull1[row][37]; temp[19][4] = "Individual Motility"; temp[19][5] = bull1[row][45]; temp[19][0] = "Comments"; temp[19][1] = bull1[row][36]; temp[19][2] = ""; temp[19][3] = ""; temp[20][4] = "Motility %"; temp[20][5] = bull1[row][46]; temp[20][0] = ""; temp[20][1] = ""; temp[20][2] = ""; temp[20][3] = ""; temp[21][4] = "Gross Motility"; temp[21][5] = bull1[row][44]; temp[21][0] = ""; temp[21][1] = ""; temp[21][2] = ""; temp[21][3] = ""; for (int i = 9; i <= 29; i += 2) { if (bull1[row][i].equals("FALSE")) { temp[1][4] = "No"; break; } } int i; int total = 0; for (i = 77; i < header.length && i < bull1[row].length; i++) { temp[i - 76][4] = header[i].split("_")[1]; temp[i - 76][5] = bull1[row][i]; total += Integer.parseInt(bull1[row][i]); } temp[0][5] = Integer.toString(total); for (int j = i; j <= 85; j++) { temp[j - 76][4] = ""; temp[j - 76][5] = ""; } PdfPTable table = new PdfPTable(6); PdfPCell cell11, cell12, cell13; cell11 = new PdfPCell(new Phrase("Bull Info", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell11.setColspan(2); cell11.setHorizontalAlignment(Element.ALIGN_CENTER); cell11.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell11); cell12 = new PdfPCell( new Phrase("Physical Exam", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell12.setColspan(2); cell12.setHorizontalAlignment(Element.ALIGN_CENTER); cell12.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell12); cell13 = new PdfPCell(new Phrase("Morphology", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell13.setColspan(2); cell13.setHorizontalAlignment(Element.ALIGN_CENTER); cell13.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell13); for (int l = 0; l <= 21; l++) { for (int j = 0; j < 6; j++) { // System.out.println(l+" "+j); if (!temp[l][j].equals("xx") && temp[l][j] != null) { cell = new PdfPCell( new Phrase(temp[l][j], FontFactory.getFont(FontFactory.TIMES_ROMAN, 10))); cell.setBorder(PdfPCell.NO_BORDER); if ((l == 9 && j == 0) || (l == 13 && j == 2) || (l == 10 && j == 4) || (l == 18 && j == 4)) { cell = new PdfPCell( new Phrase(temp[l][j], FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); } table.addCell(cell); } } } table.setWidthPercentage(90f); Reporter re; re = new Reporter(); doc.add(table); if (jCheckBox2.isSelected() || jCheckBox1.isSelected()) doc.newPage(); } else { //specify column widths int temp = dlm2.size(); float[] columnWidths = new float[temp]; for (int x = 0; x < columnWidths.length; x++) { columnWidths[x] = 2f; } //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); // set table width a percentage of the page width table.setWidthPercentage(90f); Reporter re; re = new Reporter(); re.insertCell(table, "Bull Info", Element.ALIGN_CENTER, 1, bfBold12); for (int i = 0; i < dlm2.size(); i++) { String[] parts = dlm2.get(i).toString().split(": "); String part2 = parts[1]; re.insertCell(table, newhead[Integer.parseInt(part2)], Element.ALIGN_CENTER, 1, bfBold12); } table.setHeaderRows(1); //insert an empty row //create section heading by cell merging //just some random data to fill for (int x = 0; x < dlm3.size(); x++) { String str = dlm3.get(x).toString(); //System.out.println(str); String[] parts = str.split(":"); String part2 = parts[1]; // System.out.println(part2); int row = Integer.parseInt(part2) - 1; re.insertCell(table, Bulls[row], Element.ALIGN_CENTER, 1, bf12); for (int i = 0; i < dlm2.getSize(); i++) { for (int j = 0; j < header.length && j < bull1[row].length; j++) { String str1 = dlm2.get(i).toString(); String[] p1 = str1.split(": "); String p2 = p1[0]; if (p2.equals(header[j])) { re.insertCell(table, bull1[row][j], Element.ALIGN_CENTER, 1, bf12); } } } // re.insertCell(table, bull1[x][7] , Element.ALIGN_CENTER, 1, bf12); } doc.add(table); } if (jCheckBox2.isSelected()) { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); for (int i = 0; i < dlm3.size(); i++) { String str = dlm3.get(i).toString(); System.out.println(str); String[] parts = str.split(":"); String part1 = parts[0]; String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; float total = (float) 0.0; for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (bull1[row][j].equals("")) { continue; } else { total += Integer.parseInt(bull1[row][j]); } } System.out.println(total); for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (!bull1[row][j].equals("")) { String[] Parts = header[j].split("_"); String Part2 = Parts[1]; dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, Part2, part1); } else { dataSet.setValue(0, "Percent", header[j]); } } } JFreeChart chart = ChartFactory.createBarChart("Multi Bull Morphology Chart ", "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, true, true, false); if (dlm3.size() > 12) { doc.newPage(); } PdfContentByte contentByte = docWriter.getDirectContent(); PdfTemplate template = contentByte.createTemplate(325, 250); PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250); Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250); chart.draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 0, 0); } if (jCheckBox1.isSelected()) { for (int i = 0; i < dlm3.size(); i++) { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); String str = dlm3.get(i).toString(); System.out.println(str); String[] parts = str.split(":"); String part1 = parts[0]; String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; float total = (float) 0.0; for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (bull1[row][j].equals("")) { continue; } else { total += Integer.parseInt(bull1[row][j]); } } System.out.println(total); for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (!bull1[row][j].equals("")) { String[] Parts = header[j].split("_"); String Part2 = Parts[1]; dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, "Percent", Part2); } else { dataSet.setValue(0, "Percent", header[j]); } } JFreeChart chart = ChartFactory.createBarChart("Single Bull Morphology Chart " + part1, "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false); if ((dlm3.size() > 12 && i == 0) || jCheckBox2.isSelected()) { doc.newPage(); } PdfContentByte contentByte = docWriter.getDirectContent(); PdfTemplate template = contentByte.createTemplate(325, 250); PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250); Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250); chart.draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 0, 0); doc.newPage(); } } } catch (DocumentException dex) { dex.printStackTrace(); } catch (FileNotFoundException ex) { Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex); } finally { if (doc != null) { //close the document doc.close(); } if (docWriter != null) { //close the writer docWriter.close(); } } controller.openDocument(Path); }
From source file:es.baudlord.pcpartpicker.controller.BuildViewController.java
License:Open Source License
@FXML public void onBillAction(ActionEvent event) { if (build.isComplete()) { try {/*from ww w .ja va 2s .c o m*/ FileChooser chooser = new FileChooser(); chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("PDF", "*.pdf")); File file = chooser.showSaveDialog(((Node) event.getSource()).getScene().getWindow()); if (file == null) return; Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); // Begin header generation PdfPTable table = new PdfPTable(2); table.setWidths(new int[] { 3, 7 }); com.itextpdf.text.Image image = com.itextpdf.text.Image .getInstance(App.class.getResource("img/logo.png")); image.scaleToFit(100f, 100f); PdfPCell cell = new PdfPCell(image); cell.setBorder(0); PdfPCell cell2 = new PdfPCell( new Paragraph("Hipster PC Store", new Font(Font.FontFamily.HELVETICA, 30))); cell2.setBorder(0); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); table.addCell(cell2); document.add(table); // End header generation document.add(build.createPdfPTable(new Font(Font.FontFamily.COURIER, 7))); // Begin generate date warning Calendar cal = Calendar.getInstance(); Instant now = cal.toInstant(); cal.add(Calendar.DAY_OF_MONTH, 7); Instant end = cal.toInstant(); DateTimeFormatter localFormat = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT) .withZone(ZoneId.systemDefault()); Paragraph p1 = new Paragraph(GENERAL_BUNDLE.getString("bill.date.warning"), new Font(Font.FontFamily.COURIER, 10, Font.BOLD)); Paragraph p2 = new Paragraph( GENERAL_BUNDLE.getString("bill.date.emitted") + " " + localFormat.format(now) + "\n" + GENERAL_BUNDLE.getString("bill.date.valid") + " " + localFormat.format(end), new Font(Font.FontFamily.COURIER, 10)); p1.setAlignment(Element.ALIGN_CENTER); p2.setAlignment(Element.ALIGN_CENTER); document.add(p1); document.add(p2); // End generate date warning document.close(); Alert dialog = new Alert(Alert.AlertType.CONFIRMATION); dialog.setTitle(GENERAL_BUNDLE.getString("bill.generated")); // TODO: translate dialog.setHeaderText(GENERAL_BUNDLE.getString("bill.validity")); dialog.getButtonTypes().setAll(ButtonType.CLOSE, new ButtonType(GENERAL_BUNDLE.getString("button.Print"), ButtonBar.ButtonData.FINISH), new ButtonType(GENERAL_BUNDLE.getString("button.ShowPDF"), ButtonBar.ButtonData.OK_DONE)); dialog.showAndWait(); if (dialog.getResult() != null) { ButtonBar.ButtonData result = dialog.getResult().getButtonData(); if (result.equals(ButtonBar.ButtonData.FINISH)) { Desktop.getDesktop().print(file); } else if (result.equals(ButtonBar.ButtonData.OK_DONE)) { Desktop.getDesktop().open(file); } } } catch (DocumentException | IOException e) { e.printStackTrace(); } } else { Alert dialog = new Alert(Alert.AlertType.WARNING); dialog.getButtonTypes().setAll( new ButtonType(GENERAL_BUNDLE.getString("button.tryAgain"), ButtonBar.ButtonData.OK_DONE), ButtonType.CANCEL); dialog.setTitle(GENERAL_BUNDLE.getString("dialog.build.incomplete")); List<Product.Category> missing = build.getMissingMandatoryParts(); dialog.setHeaderText(GENERAL_BUNDLE.getString("dialog.build.needed")); final HBox content = new HBox(10); missing.forEach(category -> { Button button = new Button(App.PART_NAMES_BUNDLE.getString(category.toString())); button.setGraphic(Category.getGraphic(category, 30)); button.setContentDisplay(ContentDisplay.TOP); button.setId(category.toString()); button.setOnAction(actionEvent -> { try { Part part = pickNewPart(category); if (part != null) { saved.set(false); build.add(part); displayBuild(); if (Category.isStorage(category)) { content.getChildren() .removeIf(node -> node.getId().equals(Product.Category.HDD_SSD.toString()) || node.getId().equals(Product.Category.HDD.toString())); content.autosize(); } else { content.getChildren().remove(button); } dialog.getDialogPane().getScene().getWindow().sizeToScene(); if (content.getChildren().isEmpty()) { buttonBill.fire(); dialog.close(); } } } catch (IOException e) { e.printStackTrace(); } }); content.getChildren().add(button); }); dialog.getDialogPane().setContent(content); dialog.showAndWait(); ButtonType result = dialog.getResult(); if (result != null && result.getButtonData().equals(ButtonBar.ButtonData.OK_DONE)) { dialog.hide(); onBillAction(event); } } }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java
License:Open Source License
protected PdfPCell getContentCell() { PdfPCell cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPaddingBottom(5);//from ww w. j a va 2 s . c o m cell.setBorder(Rectangle.BOTTOM | Rectangle.TOP); return cell; }
From source file:eu.geopaparazzi.plugins.pdfexport.PdfExportDialogFragment.java
License:Open Source License
public void processNote(Document document, Note note, int count) throws Exception { String name = Utilities.makeXmlSafe(note.getName()); String form = note.getForm(); DaoImages daoImages = new DaoImages(); if (form != null && form.length() > 0) { JSONObject sectionObject = new JSONObject(form); if (!sectionObject.has(FormUtilities.ATTR_SECTIONNAME)) { return; }//from ww w.ja v a 2 s . c o m String sectionName = sectionObject.getString(FormUtilities.ATTR_SECTIONNAME); Anchor anchor = new Anchor(sectionName); anchor.setName(sectionName); Chapter currentChapter = new Chapter(new Paragraph(anchor), count); addEmptyLine(currentChapter, 3); PdfPTable infoTable = new PdfPTable(2); infoTable.setHeaderRows(0); infoTable.setWidthPercentage(90); currentChapter.add(infoTable); addKeyValueToTableRow(infoTable, "Timestamp", new Date(note.getTimeStamp()).toString()); addKeyValueToTableRow(infoTable, "Latitude", note.getLat() + ""); addKeyValueToTableRow(infoTable, "Longitude", note.getLon() + ""); addEmptyLine(currentChapter, 3); List<String> formsNames = TagsManager.getFormNames4Section(sectionObject); for (String formName : formsNames) { Paragraph section = new Paragraph(formName); currentChapter.addSection(section); addEmptyLine(currentChapter, 3); PdfPTable currentTable = new PdfPTable(2); currentTable.setHeaderRows(1); currentTable.setWidthPercentage(90); currentChapter.add(currentTable); JSONObject form4Name = TagsManager.getForm4Name(formName, sectionObject); JSONArray formItems = TagsManager.getFormItems(form4Name); for (int i = 0; i < formItems.length(); i++) { JSONObject formItem = formItems.getJSONObject(i); if (!formItem.has(FormUtilities.TAG_KEY)) { continue; } String type = formItem.getString(FormUtilities.TAG_TYPE); String key = formItem.getString(FormUtilities.TAG_KEY); String value = formItem.getString(FormUtilities.TAG_VALUE); String label = key; if (formItem.has(FormUtilities.TAG_LABEL)) { label = formItem.getString(FormUtilities.TAG_LABEL); } if (type.equals(FormUtilities.TYPE_PICTURES)) { if (value.trim().length() == 0) { continue; } String[] imageIdsSplit = value.split(Note.IMAGES_SEPARATOR); for (String imageId : imageIdsSplit) { Image image = daoImages.getImage(Long.parseLong(imageId)); String imgName = image.getName(); byte[] imageData = daoImages.getImageData(Long.parseLong(imageId)); com.itextpdf.text.Image itextImage = com.itextpdf.text.Image.getInstance(imageData); Paragraph caption = new Paragraph(imgName); caption.setAlignment(Element.ALIGN_CENTER); PdfPCell keyCell = new PdfPCell(new Phrase(label)); keyCell.setHorizontalAlignment(Element.ALIGN_CENTER); keyCell.setVerticalAlignment(Element.ALIGN_MIDDLE); keyCell.setPadding(10); currentTable.addCell(keyCell); PdfPCell valueCell = new PdfPCell(); valueCell.setHorizontalAlignment(Element.ALIGN_CENTER); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setPadding(10); valueCell.addElement(itextImage); valueCell.addElement(caption); currentTable.addCell(valueCell); } } else if (type.equals(FormUtilities.TYPE_MAP)) { if (value.trim().length() == 0) { continue; } String imageId = value.trim(); Image image = daoImages.getImage(Long.parseLong(imageId)); String imgName = image.getName(); byte[] imageData = daoImages.getImageData(Long.parseLong(imageId)); com.itextpdf.text.Image itextImage = com.itextpdf.text.Image.getInstance(imageData); Paragraph caption = new Paragraph(imgName); caption.setAlignment(Element.ALIGN_CENTER); PdfPCell keyCell = new PdfPCell(new Phrase(label)); keyCell.setHorizontalAlignment(Element.ALIGN_CENTER); keyCell.setVerticalAlignment(Element.ALIGN_MIDDLE); keyCell.setPadding(10); currentTable.addCell(keyCell); PdfPCell valueCell = new PdfPCell(); valueCell.setHorizontalAlignment(Element.ALIGN_CENTER); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setPadding(10); valueCell.addElement(itextImage); valueCell.addElement(caption); currentTable.addCell(valueCell); } else if (type.equals(FormUtilities.TYPE_SKETCH)) { if (value.trim().length() == 0) { continue; } String[] imageIdsSplit = value.split(Note.IMAGES_SEPARATOR); for (String imageId : imageIdsSplit) { Image image = daoImages.getImage(Long.parseLong(imageId)); String imgName = image.getName(); byte[] imageData = daoImages.getImageData(Long.parseLong(imageId)); com.itextpdf.text.Image itextImage = com.itextpdf.text.Image.getInstance(imageData); Paragraph caption = new Paragraph(imgName); caption.setAlignment(Element.ALIGN_CENTER); PdfPCell keyCell = new PdfPCell(new Phrase(label)); keyCell.setHorizontalAlignment(Element.ALIGN_CENTER); keyCell.setVerticalAlignment(Element.ALIGN_MIDDLE); keyCell.setPadding(10); currentTable.addCell(keyCell); PdfPCell valueCell = new PdfPCell(); valueCell.setHorizontalAlignment(Element.ALIGN_CENTER); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setPadding(10); valueCell.addElement(itextImage); valueCell.addElement(caption); currentTable.addCell(valueCell); } } else { addKeyValueToTableRow(currentTable, label, value); } } } document.add(currentChapter); document.newPage(); } }
From source file:eu.geopaparazzi.plugins.pdfexport.PdfExportDialogFragment.java
License:Open Source License
private void addKeyValueToTableRow(PdfPTable table, String key, String value) { PdfPCell keyCell = new PdfPCell(new Phrase(key)); keyCell.setHorizontalAlignment(Element.ALIGN_CENTER); keyCell.setVerticalAlignment(Element.ALIGN_MIDDLE); keyCell.setPadding(10);/*www . ja v a 2 s . c om*/ table.addCell(keyCell); PdfPCell valueCell = new PdfPCell(new Phrase(value)); valueCell.setHorizontalAlignment(Element.ALIGN_CENTER); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setPadding(10); table.addCell(valueCell); }
From source file:Export.DocNotaDebito.java
@SuppressWarnings({ "CallToPrintStackTrace", "null", "UnusedAssignment" }) public String docSeguros(String nomeSeguro, String numApolice, String interCodVendedor, String idCliente, String fundoContrato, ArrayList<String[]> listaValores, Contrato contrato, String user, String moeda, String arquivo, String numeroRegistro) { String reString;/*from w ww.ja va 2 s. c o m*/ try { Font fontCabecalhoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.2f); Font fontLinha = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 0.000000358f); Font fontCabecalhoS = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.2f); Font fontCorpo = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f); Font fontCorpoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f); Font fontNull = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 4f); Font fontMenor = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 3f); PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 80, 20 }); pTableEmpresaPricipal.setWidthPercentage(95); PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres2 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres3 = new PdfPTable(2); PdfPTable pTableEmpresaInforImpres4 = new PdfPTable(2); PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1); PdfPTable pTableFatura = new PdfPTable(new float[] { 80, 20 }); pTableFatura.setWidthPercentage(95); PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(Empresa.NOME, fontCabecalhoN)); pCellNomeEmpresa.setBorder(0); PdfPCell pCellNomeEndereco = new PdfPCell(new Phrase(Empresa.ENDERECO, fontCabecalhoN)); pCellNomeEndereco.setBorder(0); PdfPCell pCellCaixaPostal = new PdfPCell(new Phrase(Empresa.CAIXAPOSTAL, fontCabecalhoN)); pCellCaixaPostal.setBorder(0); PdfPCell pCellTeleFax = new PdfPCell( new Phrase(Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, fontCabecalhoN)); pCellTeleFax.setBorder(0); PdfPCell pCellSociedade = new PdfPCell(new Phrase(Empresa.SOCIEDADE, fontCabecalhoN)); pCellSociedade.setBorder(0); PdfPCell pCellCapital = new PdfPCell(new Phrase(Empresa.CAPITALSOCIAL, fontCabecalhoN)); pCellCapital.setBorder(0); PdfPCell pCellPolice = new PdfPCell(new Phrase(Empresa.APOLICE + numApolice, fontCabecalhoN)); pCellPolice.setBorder(0); PdfPCell pCellDebNF = new PdfPCell(new Phrase("Deb. N", fontCabecalhoS)); pCellDebNF.setHorizontalAlignment(Element.ALIGN_RIGHT); pCellDebNF.setBorder(0); PdfPCell pCellDebN = new PdfPCell(new Phrase(numeroRegistro, fontCabecalhoS)); pCellDebN.setHorizontalAlignment(Element.ALIGN_CENTER); pCellDebN.setBorder(0); PdfPCell pCellInterCoF = new PdfPCell(new Phrase("Inter COD:", fontCabecalhoS)); pCellInterCoF.setHorizontalAlignment(Element.ALIGN_RIGHT); pCellInterCoF.setBorder(0); PdfPCell pCellInterCo = new PdfPCell(new Phrase(interCodVendedor, fontCabecalhoS)); pCellInterCo.setHorizontalAlignment(Element.ALIGN_CENTER); pCellInterCo.setBorder(0); Image imageEmpresa = Image.getInstance("logo.png"); imageEmpresa.scaleToFit(120f, 100f); pTableEmpresaInforImpres1.addCell(pCellNomeEmpresa); pTableEmpresaInforImpres1.addCell(pCellNomeEndereco); pTableEmpresaInforImpres1.addCell(pCellCaixaPostal); pTableEmpresaInforImpres1.addCell(pCellTeleFax); pTableEmpresaInforImpres1.addCell(pCellSociedade); pTableEmpresaInforImpres2.addCell(pCellCapital); pTableEmpresaInforImpres2.addCell(pCellPolice); pTableEmpresaInforImpres3.addCell(pCellDebNF); pTableEmpresaInforImpres3.addCell(pCellDebN); pTableEmpresaInforImpres3.addCell(pCellInterCoF); pTableEmpresaInforImpres3.addCell(pCellInterCo); PdfPCell cellTabela1 = new PdfPCell(pTableEmpresaInforImpres2); cellTabela1.setBorder(0); pTableEmpresaInforImpres4.addCell(cellTabela1); PdfPCell cellTabela2 = new PdfPCell(pTableEmpresaInforImpres3); cellTabela2.setBorder(0); pTableEmpresaInforImpres4.addCell(cellTabela2); PdfPCell cellTabela3 = new PdfPCell(pTableEmpresaInforImpres1); cellTabela3.setBorder(0); pTableEmpresaInforImpres5.addCell(cellTabela3); PdfPCell cellTabela4 = new PdfPCell(pTableEmpresaInforImpres4); cellTabela4.setBorder(0); pTableEmpresaInforImpres5.addCell(cellTabela4); PdfPCell cellTabela5 = new PdfPCell(pTableEmpresaInforImpres5); cellTabela5.setBorder(0); pTableEmpresaPricipal.addCell(cellTabela5); PdfPCell cellTabela6 = new PdfPCell(imageEmpresa); cellTabela6.setBorder(0); cellTabela6.setHorizontalAlignment(Element.ALIGN_RIGHT); pTableEmpresaPricipal.addCell(cellTabela6); PdfPCell cellFaturaTitulo = new PdfPCell(new Phrase("FACTURA", fontCabecalhoN)); cellFaturaTitulo.setBorder(0); cellFaturaTitulo.setHorizontalAlignment(Element.ALIGN_RIGHT); PdfPCell cellFaturaTipo = new PdfPCell(new Phrase(nomeSeguro, fontCabecalhoN)); cellFaturaTipo.setHorizontalAlignment(Element.ALIGN_CENTER); cellFaturaTipo.setBorder(0); PdfPTable pTableLinha = new PdfPTable(1); pTableLinha.setWidthPercentage(95); PdfPCell linha = new PdfPCell(new Phrase(" ", fontLinha)); linha.setBorderWidthTop(0.5f); linha.setBorderWidthBottom(0); linha.setBorderWidthLeft(0); linha.setBorderWidthRight(0); pTableLinha.addCell(linha); pTableFatura.addCell(cellFaturaTitulo); pTableFatura.addCell(cellFaturaTipo); PdfPTable pTableClientePrincipal = new PdfPTable(new float[] { 60, 10, 30 }); pTableClientePrincipal.setWidthPercentage(95); PdfPTable pTableClienteDescisao = new PdfPTable(1); PdfPTable pTableDataEVenda = new PdfPTable(1); PdfPTable pTableTitulo = new PdfPTable(1); pTableTitulo.setWidthPercentage(95); ClienteI ci = null; ArrayList<DataReseguro.DataEmpresa> listaDataEmpresas = new ArrayList<>(); if (!isReseguro) { ci = new ClienteI(idCliente); } else { listaDataEmpresas = DataReseguro.getDadosEmpresa(Integer.valueOf(idCliente)); } Paragraph pCl = new Paragraph(); pCl.add(new Phrase((isReseguro) ? "NOME: " : ci.getNOMEL_(), fontCorpo)); pCl.add(new Phrase( (isReseguro) ? listaDataEmpresas.get(0).getEMPRESA().toUpperCase() + " (" + segurado + ")" : ci.getNOME_(), fontCorpoN)); PdfPCell cellNomeCliente = new PdfPCell(pCl); cellNomeCliente.setBorder(0); pCl = new Paragraph(); pCl.add(new Phrase((isReseguro) ? "ENDEREO: " : ci.getENDERECOL_(), fontCorpo)); pCl.add(new Phrase((isReseguro) ? listaDataEmpresas.get(0).getENDERECO() : ci.getENDERECO_(), fontCorpoN)); if (!isReseguro) { pCl.add(new Phrase(" ", fontCorpoN)); pCl.add(new Phrase((isReseguro) ? "" : ci.getCODPOSTALL_(), fontCorpo)); pCl.add(new Phrase((isReseguro) ? "" : ci.getCODPOSTAL_(), fontCorpoN)); } PdfPCell cellClienteMorada = new PdfPCell(pCl); cellClienteMorada.setBorder(0); PdfPCell cellNomeLocalidade = null; PdfPCell cellNomeTelefone = null; if (!isReseguro) { pCl = new Paragraph(); pCl.add(new Phrase(ci.getLOCALTRABALHOL_(), fontCorpo)); pCl.add(new Phrase(ci.getLOCALTRABALHO_(), fontCorpoN)); cellNomeLocalidade = new PdfPCell(pCl); cellNomeLocalidade.setBorder(0); pCl = new Paragraph(); pCl.add(new Phrase(ci.getTELEFONEL_(), fontCorpo)); pCl.add(new Phrase(ci.getTELEFONE_(), fontCorpoN)); cellNomeTelefone = new PdfPCell(pCl); cellNomeTelefone.setBorder(0); } SimpleDateFormat sdf = new SimpleDateFormat("dd 'de' MMMM 'de' yyyy", new Locale("pt", "BR")); SimpleDateFormat sdfContr = new SimpleDateFormat("dd-MM-yyyy"); SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss"); PdfPCell cellDataContrato = new PdfPCell(new Phrase( "Data: " + (contrato.getDataInicio() != null ? sdfContr.format(contrato.getDataInicio()) : "") + " - " + (contrato.getDataFim() != null ? sdfContr.format(contrato.getDataFim()) : ""), fontCorpo)); cellDataContrato.setHorizontalAlignment(Element.ALIGN_CENTER); cellDataContrato.setVerticalAlignment(Element.ALIGN_BOTTOM); cellDataContrato.setBorderWidthTop(1f); cellDataContrato.setBorderWidthBottom(0f); cellDataContrato.setBorderWidthLeft(1f); cellDataContrato.setBorderWidthRight(1f); PdfPCell cellVendetor = new PdfPCell(new Phrase("Vendedor: " + ((!isReseguro) ? "NICON SEGUROS" : listaDataEmpresas.get(0).getEMPRESA().toUpperCase()), fontCorpo)); cellVendetor.setHorizontalAlignment(Element.ALIGN_CENTER); cellVendetor.setVerticalAlignment(Element.ALIGN_TOP); cellVendetor.setBorderWidthTop(0f); cellVendetor.setBorderWidthBottom(1f); cellVendetor.setBorderWidthLeft(1f); cellVendetor.setBorderWidthRight(1f); pTableClienteDescisao.addCell(cellNomeCliente); pTableClienteDescisao.addCell(cellClienteMorada); if (!isReseguro) { pTableClienteDescisao.addCell(cellNomeLocalidade); pTableClienteDescisao.addCell(cellNomeTelefone); } PdfPCell cellZerro = new PdfPCell(new Phrase(" ", fontNull)); cellZerro.setBorder(0); PdfPCell cellZerro2 = new PdfPCell(new Phrase(" ")); cellZerro2.setBorderWidthTop(0f); cellZerro2.setBorderWidthBottom(0f); cellZerro2.setBorderWidthLeft(1f); cellZerro2.setBorderWidthRight(1f); PdfPTable pTableNull = new PdfPTable(1); pTableNull.setWidthPercentage(95); pTableNull.addCell(cellZerro); pTableDataEVenda.addCell(cellDataContrato); pTableDataEVenda.addCell(cellZerro2); pTableDataEVenda.addCell(cellVendetor); PdfPCell cellTitulo = new PdfPCell(new Phrase("Cliente", fontCabecalhoN)); cellTitulo.setBorder(0); pTableTitulo.addCell(cellZerro); pTableTitulo.addCell(cellTitulo); PdfPCell cellCliente = new PdfPCell(pTableClienteDescisao); cellCliente.setBorder(0); PdfPCell cellCliente1 = new PdfPCell(pTableDataEVenda); cellCliente1.setBorder(0); pTableClientePrincipal.addCell(cellCliente); pTableClientePrincipal.addCell(cellZerro); pTableClientePrincipal.addCell(cellCliente1); PdfPCell cellQuan = new PdfPCell(new Phrase("QTD", fontCorpo)); PdfPCell cellDescricao = new PdfPCell(new Phrase("Descrio", fontCorpo)); PdfPCell cellValorUnitatio = new PdfPCell(new Phrase("Valor Unitrio", fontCorpo)); PdfPCell cellTotal = new PdfPCell(new Phrase("Total", fontCorpo)); PdfPTable TableRegistro = new PdfPTable(new float[] { 10, 45, 28, 17 }); TableRegistro.setWidthPercentage(95); cellQuan.setBorderWidthBottom(1f); cellQuan.setBorderWidthTop(1f); cellQuan.setBorderWidthLeft(1f); cellQuan.setBorderWidthRight(1f); cellQuan.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuan.setVerticalAlignment(Element.ALIGN_CENTER); cellDescricao.setBorderWidthBottom(1f); cellDescricao.setBorderWidthTop(1f); cellDescricao.setBorderWidthLeft(0.5f); cellDescricao.setBorderWidthRight(1f); cellDescricao.setHorizontalAlignment(Element.ALIGN_CENTER); cellDescricao.setVerticalAlignment(Element.ALIGN_CENTER); cellValorUnitatio.setBorderWidthBottom(1f); cellValorUnitatio.setBorderWidthTop(1f); cellValorUnitatio.setBorderWidthLeft(0.5f); cellValorUnitatio.setBorderWidthRight(1f); cellValorUnitatio.setHorizontalAlignment(Element.ALIGN_CENTER); cellValorUnitatio.setVerticalAlignment(Element.ALIGN_CENTER); cellTotal.setBorderWidthBottom(1f); cellTotal.setBorderWidthTop(1f); cellTotal.setBorderWidthLeft(0.5f); cellTotal.setBorderWidthRight(1f); cellTotal.setHorizontalAlignment(Element.ALIGN_CENTER); cellTotal.setVerticalAlignment(Element.ALIGN_CENTER); TableRegistro.addCell(cellQuan); TableRegistro.addCell(cellDescricao); TableRegistro.addCell(cellValorUnitatio); TableRegistro.addCell(cellTotal); int total = (listaValores.size() > 21) ? listaValores.size() : 18; boolean rulpas = false; for (int i = 0; i < total + 1; i++) { /** * Serve para add linha a Table <TableRegistro> e testa caso o ArrayList tenha * Menos linha que o <total> a Table <TableRegistro> continua recebendo dados Com String Vazios */ if (listaValores.size() - 1 >= i || (listaValores.size() - 1 == i)) { // System.err.println(i); cellQuan = new PdfPCell(new Phrase(listaValores.get(i)[0], fontCorpo)); cellDescricao = new PdfPCell(new Phrase(listaValores.get(i)[1], fontCorpo)); cellValorUnitatio = new PdfPCell(new Phrase(listaValores.get(i)[2] + " " + ((!nomeSeguro.equals("Viagem")) ? contrato.getSigla() : ""), fontCorpo)); cellTotal = new PdfPCell(new Phrase(listaValores.get(i)[3] + " " + ((!nomeSeguro.equals("Viagem") || listaValores.size() - 1 == i) ? contrato.getSigla() : ""), fontCorpo)); cellQuan.setPaddingTop(2.5f); cellDescricao.setPaddingTop(2.5f); cellValorUnitatio.setPaddingTop(2.5f); cellTotal.setPaddingTop(2.5f); cellQuan.setPaddingBottom(2.5f); cellDescricao.setPaddingBottom(2.5f); cellValorUnitatio.setPaddingBottom(2.5f); cellTotal.setPaddingBottom(2.5f); cellQuan.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellDescricao.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellValorUnitatio.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellTotal.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); } else { cellQuan = new PdfPCell(new Phrase(" ", fontCorpo)); cellDescricao = new PdfPCell(new Phrase(" ", fontCorpo)); cellValorUnitatio = new PdfPCell(new Phrase(" ", fontCorpo)); cellTotal = new PdfPCell(new Phrase(" ", fontCorpo)); } if (listaValores.size() - 1 == i && !rulpas) { cellDescricao.setRowspan(total - i); rulpas = true; } cellQuan.setBorderWidthBottom(0f); cellQuan.setBorderWidthTop((listaValores.size() - 1 == i) ? 1f : 0f); cellQuan.setHorizontalAlignment(Element.ALIGN_CENTER); cellDescricao.setBorderWidthBottom((listaValores.size() - 1 == i) ? 1f : 0f); cellDescricao.setBorderWidthTop((listaValores.size() - 1 == i) ? 1f : 0f); cellDescricao.setHorizontalAlignment(Element.ALIGN_CENTER); cellValorUnitatio.setBorderWidthBottom(0f); cellValorUnitatio.setBorderWidthTop((listaValores.size() - 1 == i) ? 1f : 0f); cellValorUnitatio.setHorizontalAlignment(Element.ALIGN_CENTER); cellTotal.setBorderWidthBottom(0f); cellTotal.setBorderWidthTop((listaValores.size() - 1 == i) ? 1f : 0f); cellTotal.setHorizontalAlignment(Element.ALIGN_CENTER); if (i + 1 == total) { cellQuan.setBorderWidthBottom(1f); cellDescricao.setBorderWidthBottom(1f); cellValorUnitatio.setBorderWidthBottom(1f); cellTotal.setBorderWidthBottom(1f); } TableRegistro.addCell(cellQuan); if (listaValores.size() - 1 >= i || listaValores.size() - 1 == i) { TableRegistro.addCell(cellDescricao); } TableRegistro.addCell(cellValorUnitatio); TableRegistro.addCell(cellTotal); } PdfPTable pTablePrincipalPagamento = new PdfPTable(new float[] { 55, 45 }); pTablePrincipalPagamento.setWidthPercentage(95); PdfPTable pTableFomaPagamentoPricipal = new PdfPTable(1); PdfPTable pTableFomaPagamento = new PdfPTable(new float[] { 15, 50, 10 }); PdfPTable pTableFomaValoresPricipal = new PdfPTable(1); PdfPTable pTableFomaValores = new PdfPTable(new float[] { 15, 47, 38 }); PdfPCell cellvazio = new PdfPCell(new Phrase(" ", fontCorpo)); PdfPCell cellTituloFormaPagamento = new PdfPCell(new Phrase("Forma de Pagamento", fontCorpoN)); cellTituloFormaPagamento.setBorderWidthBottom(0f); cellTituloFormaPagamento.setBorderWidthTop(1f); cellTituloFormaPagamento.setBorderWidthRight(0f); cellTituloFormaPagamento.setBorderWidthLeft(0f); PdfPCell cellTituloForma1 = new PdfPCell(new Phrase(" Cheque", fontCorpo)); cellTituloForma1.setBorderWidthBottom(0f); cellTituloForma1.setBorderWidthTop(0f); cellTituloForma1.setBorderWidthRight(0f); cellTituloForma1.setBorderWidthLeft(0f); PdfPCell cellTituloForma2 = new PdfPCell(new Phrase(" Dinheiro", fontCorpo)); cellTituloForma2.setBorderWidthBottom(0f); cellTituloForma2.setBorderWidthTop(0f); cellTituloForma2.setBorderWidthRight(0f); cellTituloForma2.setBorderWidthLeft(0f); PdfPCell cellTituloForma3 = new PdfPCell(new Phrase(" Outros", fontCorpo)); cellTituloForma3.setBorderWidthBottom(1f); cellTituloForma3.setBorderWidthTop(0f); cellTituloForma3.setBorderWidthRight(0f); cellTituloForma3.setBorderWidthLeft(0f); cellvazio.setBorderWidthBottom(0f); cellvazio.setBorderWidthTop(1f); cellvazio.setBorderWidthRight(0f); cellvazio.setBorderWidthLeft(1f); pTableFomaPagamento.addCell(cellvazio); pTableFomaPagamento.addCell(cellTituloFormaPagamento); cellvazio.setBorderWidthBottom(0f); cellvazio.setBorderWidthTop(1f); cellvazio.setBorderWidthRight(1f); cellvazio.setBorderWidthLeft(0f); pTableFomaPagamento.addCell(cellvazio); cellvazio.setBorderWidthBottom(0f); cellvazio.setBorderWidthTop(0f); cellvazio.setBorderWidthRight(0f); cellvazio.setBorderWidthLeft(1f); pTableFomaPagamento.addCell(cellvazio); pTableFomaPagamento.addCell(cellTituloForma1); cellvazio.setBorderWidthBottom(0f); cellvazio.setBorderWidthTop(0f); cellvazio.setBorderWidthRight(1f); cellvazio.setBorderWidthLeft(0f); pTableFomaPagamento.addCell(cellvazio); cellvazio.setBorderWidthBottom(0f); cellvazio.setBorderWidthTop(0f); cellvazio.setBorderWidthRight(0f); cellvazio.setBorderWidthLeft(1f); pTableFomaPagamento.addCell(cellvazio); pTableFomaPagamento.addCell(cellTituloForma2); cellvazio.setBorderWidthBottom(0f); cellvazio.setBorderWidthTop(0f); cellvazio.setBorderWidthRight(1f); cellvazio.setBorderWidthLeft(0f); pTableFomaPagamento.addCell(cellvazio); cellvazio.setBorderWidthBottom(1f); cellvazio.setBorderWidthTop(0f); cellvazio.setBorderWidthRight(0f); cellvazio.setBorderWidthLeft(1f); pTableFomaPagamento.addCell(cellvazio); pTableFomaPagamento.addCell(cellTituloForma3); cellvazio.setBorderWidthBottom(1f); cellvazio.setBorderWidthTop(0f); cellvazio.setBorderWidthRight(1f); cellvazio.setBorderWidthLeft(0f); pTableFomaPagamento.addCell(cellvazio); PdfPCell cellNull = new PdfPCell(new Phrase(" ", fontMenor)); cellNull.setBorderWidthBottom(0f); cellNull.setBorderWidthTop(0f); cellNull.setBorderWidthRight(0f); cellNull.setBorderWidthLeft(0f); pTableFomaPagamentoPricipal.addCell(cellNull); PdfPCell cellPagamento = new PdfPCell(pTableFomaPagamento); cellPagamento.setBorder(0); pTableFomaPagamentoPricipal.addCell(cellPagamento); PdfPCell cellPecentage1 = new PdfPCell(new Phrase(((nomeSeguro.equals("Viagem") || isReseguro) ? " " : ((nomeSeguro.equals("Acidente Para Grupo")) ? " " : "2.50%")), fontCorpo)); cellPecentage1.setHorizontalAlignment(Element.ALIGN_CENTER); cellPecentage1.setBorderWidthBottom(0f); cellPecentage1.setBorderWidthTop(1f); cellPecentage1.setBorderWidthRight(0f); cellPecentage1.setBorderWidthLeft(1f); PdfPCell cellPecentage2 = new PdfPCell(new Phrase((isReseguro) ? " " : "5%", fontCorpo)); cellPecentage2.setHorizontalAlignment(Element.ALIGN_CENTER); cellPecentage2.setBorderWidthBottom(0f); cellPecentage2.setBorderWidthTop(0f); cellPecentage2.setBorderWidthRight(0f); cellPecentage2.setBorderWidthLeft(1f); PdfPCell cellPecentage3 = new PdfPCell(new Phrase(" ", fontCorpo)); cellPecentage3.setHorizontalAlignment(Element.ALIGN_CENTER); cellPecentage3.setBorderWidthBottom(0f); cellPecentage3.setBorderWidthTop(0f); cellPecentage3.setBorderWidthRight(0f); cellPecentage3.setBorderWidthLeft(1f); PdfPCell cellFundo = new PdfPCell(new Phrase(fundoContrato, fontCorpo)); cellFundo.setHorizontalAlignment(Element.ALIGN_RIGHT); cellFundo.setBorderWidthBottom(0f); cellFundo.setBorderWidthTop(1f); cellFundo.setBorderWidthRight(0f); cellFundo.setBorderWidthLeft(0f); PdfPCell cellImposto = new PdfPCell(new Phrase((isReseguro) ? " " : "IMPOSTO", fontCorpo)); cellImposto.setHorizontalAlignment(Element.ALIGN_RIGHT); cellImposto.setBorderWidthBottom(0f); cellImposto.setBorderWidthTop(0f); cellImposto.setBorderWidthRight(0f); cellImposto.setBorderWidthLeft(0f); PdfPCell cellSelo = new PdfPCell(new Phrase((isReseguro) ? " " : "ACESSORIOS", fontCorpo)); cellSelo.setHorizontalAlignment(Element.ALIGN_RIGHT); cellSelo.setBorderWidthBottom(0f); cellSelo.setBorderWidthTop(0f); cellSelo.setBorderWidthRight(0f); cellSelo.setBorderWidthLeft(0f); PdfPCell cellvazio1; if (!isReseguro) { cellvazio1 = new PdfPCell( new Phrase( ((nomeSeguro.equals("Viagem")) ? ((contrato.getValorNC() == null || contrato.getValorNC().isEmpty()) ? " " : Moeda.format( Double.valueOf(contrato.getValorNC().replace(',', '.'))) + " EUR") : ((nomeSeguro.equals("Acidente Para Grupo")) ? " " : ((nomeSeguro.equals("Automovel")) ? Moeda.format( (Double.valueOf(contrato.getPremioLiquido()) * 0.025)) + " " + contrato.getSigla() : "2.50%"))), fontCorpo)); } else { cellvazio1 = new PdfPCell(new Phrase(" ", fontCorpo)); } pTableFomaValores.addCell(cellPecentage1); pTableFomaValores.addCell(cellFundo); cellvazio1.setBorderWidthTop(1); cellvazio1.setBorderWidthRight(1); cellvazio1.setHorizontalAlignment(Element.ALIGN_RIGHT); pTableFomaValores.addCell(cellvazio1); double i05 = 0;//imposto 0.05% double i25 = 0;//imposto 2.5% try { if (nomeSeguro.equals("Viagem")) { i05 = 0.05 * Moeda.arrendodamento(contrato.getValorNC().replace(',', '.')); i25 = 0.006 * Moeda.arrendodamento(contrato.getValorNC().replace(',', '.')); } else if (!isReseguro) { i05 = 0.05 * Moeda.arrendodamento(contrato.getPremioLiquido()); i25 = 0.006 * Moeda.arrendodamento(contrato.getPremioLiquido()); } } catch (Exception e) { } PdfPCell cellvazio2 = new PdfPCell( new Phrase((isReseguro) ? " " : (Moeda.format(i05) + " " + contrato.getSigla()), fontCorpo)); pTableFomaValores.addCell(cellPecentage2); pTableFomaValores.addCell(cellImposto); cellvazio2.setBorderWidthRight(1); cellvazio2.setBottom(10000); cellvazio2.setHorizontalAlignment(Element.ALIGN_RIGHT); pTableFomaValores.addCell(cellvazio2); PdfPCell cellvazio3 = new PdfPCell( new Phrase((isReseguro) ? " " : (Moeda.format(i25) + " " + contrato.getSigla()), fontCorpo)); pTableFomaValores.addCell(cellPecentage3); pTableFomaValores.addCell(cellSelo); cellvazio3.setBorderWidthRight(1); cellvazio3.setHorizontalAlignment(Element.ALIGN_RIGHT); pTableFomaValores.addCell(cellvazio3); PdfPTable pTableTotalPagar = new PdfPTable(2); PdfPCell cellTituloTotalPagar = new PdfPCell( new Phrase("TOTAL A PAGAR " + contrato.getSigla(), fontCorpoN)); cellTituloTotalPagar.setBorderWidthBottom(1f); cellTituloTotalPagar.setBorderWidthTop(0f); cellTituloTotalPagar.setBorderWidthRight(0f); cellTituloTotalPagar.setBorderWidthLeft(1f); PdfPCell cellValorPagar = new PdfPCell( new Phrase(contrato.getPremioLiquidoMoeda() + " " + contrato.getSigla(), fontCorpo)); cellValorPagar.setBorderWidthBottom(1f); cellValorPagar.setBorderWidthTop(0f); cellValorPagar.setBorderWidthRight(1f); cellValorPagar.setBorderWidthLeft(0f); cellValorPagar.setHorizontalAlignment(Element.ALIGN_RIGHT); pTableTotalPagar.addCell(cellTituloTotalPagar); pTableTotalPagar.addCell(cellValorPagar); PdfPTable pTableSubTotal = new PdfPTable(new float[] { 62, 38 }); PdfPCell cellTituloSubTotal = new PdfPCell(new Phrase("SubTotal", fontCorpoN)); cellTituloSubTotal.setBorder(0); cellTituloSubTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); PdfPCell cellValorSubTotal = new PdfPCell( new Phrase(contrato.getPremioBrutoMoeda() + " " + contrato.getSigla(), fontCorpo)); cellValorSubTotal.setBorderWidthBottom(0.5f); cellValorSubTotal.setBorderWidthTop(1f); cellValorSubTotal.setBorderWidthRight(0.5f); cellValorSubTotal.setBorderWidthLeft(0.5f); cellValorSubTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); pTableSubTotal.addCell(cellTituloSubTotal); pTableSubTotal.addCell(cellValorSubTotal); PdfPCell cellPagament1 = new PdfPCell(pTableSubTotal); cellPagament1.setBorder(0); PdfPCell cellPagament2 = new PdfPCell(pTableFomaValores); cellPagament2.setBorder(0); PdfPCell cellPagament3 = new PdfPCell(pTableTotalPagar); cellPagament3.setBorder(0); pTableFomaValoresPricipal.addCell(cellPagament1); pTableFomaValoresPricipal.addCell(cellPagament2); pTableFomaValoresPricipal.addCell(cellPagament3); PdfPCell cellPagamentPricipal1 = new PdfPCell(pTableFomaPagamentoPricipal); cellPagamentPricipal1.setBorder(0); PdfPCell cellPagamentPricipal2 = new PdfPCell(pTableFomaValoresPricipal); cellPagamentPricipal2.setBorder(0); pTablePrincipalPagamento.addCell(cellPagamentPricipal1); pTablePrincipalPagamento.addCell(cellPagamentPricipal2); PdfPTable pTableCambio = new PdfPTable(2); pTableCambio.setWidthPercentage(95); PdfPCell cellTituloCambio1 = new PdfPCell(new Phrase("Cambio", fontCorpoN)); cellTituloCambio1.setBorder(0); cellTituloCambio1.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cellTituloCambio2 = new PdfPCell(new Phrase("Total Em Dobras", fontCorpoN)); cellTituloCambio2.setBorder(0); cellTituloCambio2.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cellValorCambio = new PdfPCell(new Phrase( "1 " + contrato.getSigla() + "= " + Moeda.format(valorCompra(contrato.getDataRegistro(), contrato)) + " " + "STD", fontCorpo)); cellValorCambio.setBorder(0); cellValorCambio.setHorizontalAlignment(Element.ALIGN_CENTER); DecimalFormat formato = new DecimalFormat("#.##"); String numero = formato.format(Double.valueOf(contrato.getPremioLiquido())); double premioLiquido = Double.valueOf((numero).replace(',', '.')); // System.err.println(taxa + "Taxa * Premio Liquido" + Double.valueOf(contrato.getPremioLiquido())); // System.err.println(taxa + "Taxa * Premio Liquido" + Double.toString(premioLiquido)); PdfPCell cellValorDobras = new PdfPCell( new Phrase(Moeda.format((taxa * premioLiquido)) + " STD", fontCorpo)); cellValorDobras.setBorder(0); cellValorDobras.setHorizontalAlignment(Element.ALIGN_CENTER); pTableCambio.addCell(cellTituloCambio1); pTableCambio.addCell(cellTituloCambio2); pTableCambio.addCell(cellValorCambio); pTableCambio.addCell(cellValorDobras); PdfPTable pTableData = new PdfPTable(1); pTableData.setWidthPercentage(95); Paragraph pData = new Paragraph(); pData.add(new Phrase("Elaborado por ", fontCorpo)); pData.add(new Phrase(interCodVendedor, fontCorpoN)); pData.add(new Phrase(" Data ".toUpperCase() + sdf.format(new Date()), fontCorpo)); PdfPCell cellData = new PdfPCell(pData); cellData.setBorder(0); cellData.setBorderWidthBottom(0.1f); cellData.setHorizontalAlignment(Element.ALIGN_CENTER); pTableData.addCell(cellData); Document documento = new Document(); documento.setPageSize(PageSize.A4); documento.setMargins(20f, 20f, 70f, 5f); String f1 = (arquivo + "/" + user + "/Seguro " + nomeSeguro + "/"); File f = new File(f1); String Ddata = sdf1.format(new Date()); f.mkdirs(); f = new File(f.getAbsoluteFile() + "/" + "Nota de Debito " + Ddata + ".pdf"); reString = "../Documentos/" + user + "/Seguro " + nomeSeguro + "/" + "Nota de Debito " + Ddata + ".pdf"; OutputStream outputStraem = new FileOutputStream(f); PdfWriter writer = PdfWriter.getInstance(documento, outputStraem); if (MarcaDAgua.isSimulation) { MarcaDAgua.SimulacaoVertical v = new MarcaDAgua.SimulacaoVertical(); writer.setPageEvent(v); } if (MarcaDAgua.isCanceled) { MarcaDAgua.AnulacaoVertical v = new MarcaDAgua.AnulacaoVertical(); writer.setPageEvent(v); } documento.open(); documento.add(pTableEmpresaPricipal); documento.add(pTableFatura); documento.add(pTableLinha); documento.add(pTableLinha); documento.add(pTableTitulo); documento.add(pTableClientePrincipal); documento.add(pTableNull); documento.add(TableRegistro); documento.add(pTablePrincipalPagamento); documento.add(pTableNull); documento.add(pTableNull); documento.add(pTableCambio); documento.add(pTableNull); documento.add(pTableNull); documento.add(pTableNull); documento.add(pTableData); documento.add(pTableNull); documento.add(pTableNull); documento.add(pTableNull); documento.add(pTableLinha); documento.add(pTableLinha); documento.close(); isReseguro = false; // PrintPdf printPdf = new PrintPdf(f.getAbsolutePath(), f.getAbsolutePath(), 0, 595f,842f,"\\\\JIGASOFTPC\\Hewlett-Packard HP LaserJet P2035",1); // PrintPdf printPdf = new PrintPdf(f.getAbsolutePath(), f.getAbsolutePath(), 1, 595f,842f,"Enviar Para o OneNote 2013",1); // printPdf.print(); return reString; } catch (FileNotFoundException | DocumentException e) { e.printStackTrace(); } catch (IOException ex) { Logger.getLogger(DocNotaDebito.class.getName()).log(Level.SEVERE, null, ex); } return ""; }
From source file:Export.DocOfReCoSeguro.java
public static void docSeguros(String nomeSeguro, String user, String arquivo, String numDebito, String tileDoc, int idReseguro, boolean isReseguroOfNICON) { String reString;/*from ww w.j a v a2s .c o m*/ try { Font fontCabecalhoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.2f); Font fontLinha = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 0.000000358f); Font fontCabecalhoS = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.2f); Font fontCorpo = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f); Font fontCorpoS = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f, Font.UNDERLINE); Font fontCorpoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f); Font fontNull = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 4f); Font fontMenor = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 3f); DataResseguro reS = DataReseguro.getDadosReseguro(idReseguro); PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 80, 20 }); pTableEmpresaPricipal.setWidthPercentage(90); PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres2 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres4 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1); PdfPTable pTableFatura = new PdfPTable(new float[] { 80, 20 }); PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(ConfigDoc.Empresa.NOME, fontCabecalhoN)); pCellNomeEmpresa.setBorder(0); PdfPCell pCellNomeEndereco = new PdfPCell(new Phrase(ConfigDoc.Empresa.ENDERECO, fontCabecalhoN)); pCellNomeEndereco.setBorder(0); PdfPCell pCellCaixaPostal = new PdfPCell(new Phrase(ConfigDoc.Empresa.CAIXAPOSTAL, fontCabecalhoN)); pCellCaixaPostal.setBorder(0); PdfPCell pCellTeleFax = new PdfPCell( new Phrase(ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, fontCabecalhoN)); pCellTeleFax.setBorder(0); PdfPCell pCellSociedade = new PdfPCell(new Phrase(ConfigDoc.Empresa.SOCIEDADE, fontCabecalhoN)); pCellSociedade.setBorder(0); PdfPCell pCellCapital = new PdfPCell(new Phrase(ConfigDoc.Empresa.CAPITALSOCIAL, fontCabecalhoN)); pCellCapital.setBorder(0); PdfPCell pCellPolice = new PdfPCell( new Phrase(ConfigDoc.Empresa.APOLICE + reS.getAPOLICE(), fontCabecalhoN)); pCellPolice.setBorder(0); Image imageEmpresa = Image.getInstance("logo.png"); imageEmpresa.scaleToFit(120f, 100f); pTableEmpresaInforImpres1.addCell(pCellNomeEmpresa); pTableEmpresaInforImpres1.addCell(pCellNomeEndereco); pTableEmpresaInforImpres1.addCell(pCellCaixaPostal); pTableEmpresaInforImpres1.addCell(pCellTeleFax); pTableEmpresaInforImpres1.addCell(pCellSociedade); pTableEmpresaInforImpres2.addCell(pCellCapital); pTableEmpresaInforImpres2.addCell(pCellPolice); PdfPCell cellTabela1 = new PdfPCell(pTableEmpresaInforImpres2); cellTabela1.setBorder(0); pTableEmpresaInforImpres4.addCell(cellTabela1); PdfPCell cellTabela3 = new PdfPCell(pTableEmpresaInforImpres1); cellTabela3.setBorder(0); pTableEmpresaInforImpres5.addCell(cellTabela3); PdfPCell cellTabela4 = new PdfPCell(pTableEmpresaInforImpres4); cellTabela4.setBorder(0); pTableEmpresaInforImpres5.addCell(cellTabela4); PdfPCell cellTabela5 = new PdfPCell(pTableEmpresaInforImpres5); cellTabela5.setBorder(0); pTableEmpresaPricipal.addCell(cellTabela5); PdfPCell cellTabela6 = new PdfPCell(imageEmpresa); cellTabela6.setBorder(0); cellTabela6.setHorizontalAlignment(Element.ALIGN_RIGHT); pTableEmpresaPricipal.addCell(cellTabela6); PdfPTable pTableLinha = new PdfPTable(1); pTableLinha.setWidthPercentage(90); PdfPCell linha = new PdfPCell(new Phrase(" ", fontLinha)); linha.setBorderWidthTop(0.5f); linha.setBorderWidthBottom(0); linha.setBorderWidthLeft(0); linha.setBorderWidthRight(0); pTableLinha.addCell(linha); /** * Tile Doc start */ /* PdfPTable pTableTileDoc = new PdfPTable(new float[]{50, 50}); PdfPCell cellTileDoc = new PdfPCell(new Phrase(tileDoc, fontCabecalhoS)); cellTileDoc.setColspan(2); cellTileDoc.setPaddingTop(10f); cellTileDoc.setPaddingBottom(20f); cellTileDoc.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellTileDoc.setBorder(PdfPCell.NO_BORDER); pTableTileDoc.addCell(cellTileDoc); Paragraph pTile = new Paragraph(); pTile.add(new Phrase("DEBIT: ", fontCorpoN)); pTile.add(new Phrase("NiCON Seguros STP", fontCorpoN)); PdfPCell cellDebit = new PdfPCell(pTile); cellDebit.setBorder(PdfPCell.NO_BORDER); pTableTileDoc.addCell(cellDebit); Paragraph pNotaNum = new Paragraph(); pNotaNum.add(new Phrase("DEBIT NOTE NO: ", fontCorpoN)); pNotaNum.add(new Phrase("05525", fontCorpo)); cellDebit = new PdfPCell(pNotaNum); cellDebit.setPaddingLeft(20f); cellDebit.setBorder(PdfPCell.NO_BORDER); pTableTileDoc.addCell(cellDebit); cellDebit = new PdfPCell(new Phrase(" Avenida Marginal 12 de Junlho, 977", fontCorpo)); cellDebit.setBorder(PdfPCell.NO_BORDER); pTableTileDoc.addCell(cellDebit); Paragraph pDate = new Paragraph(); pDate.add(new Phrase("Date: ", fontCorpoN)); SimpleDateFormat format = new SimpleDateFormat("dd MMMM',' yyyy",new Locale("pt", "BR")); pDate.add(new Phrase(format.format(new Date()), fontCorpo)); cellDebit = new PdfPCell(pDate); cellDebit.setBorder(PdfPCell.NO_BORDER); cellDebit.setPaddingLeft(20f); pTableTileDoc.addCell(cellDebit); cellDebit = new PdfPCell(new Phrase(" Cx Postal 556-So Tom", fontCorpo)); cellDebit.setBorder(PdfPCell.NO_BORDER); pTableTileDoc.addCell(cellDebit); cellDebit = new PdfPCell(new Phrase(" ")); cellDebit.setBorder(PdfPCell.NO_BORDER); pTableTileDoc.addCell(cellDebit); */ /** * Tile Doc end */ ArrayList<DataEmpresa> listaDataEmpresas = DataReseguro.getDadosEmpresa(idReseguro); /** * Data Parte 1 Start */ PdfPTable pTableDataPart1 = new PdfPTable(new float[] { 18f, 82f }); pTableDataPart1.setWidthPercentage(90); PdfPCell cellDataPart1 = new PdfPCell(new Phrase("EMPRESA LIDER:", fontCorpoN)); cellDataPart1.setBorder(PdfPCell.NO_BORDER); cellDataPart1.setPaddingTop(10f); cellDataPart1.setPaddingBottom(5f); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell( new Phrase(((!isReseguroOfNICON) ? listaDataEmpresas.get(0).getEMPRESA().toUpperCase() : ConfigDoc.Empresa.NOME), fontCorpo)); cellDataPart1.setPaddingTop(10f); cellDataPart1.setPaddingBottom(5f); cellDataPart1.setBorder(PdfPCell.NO_BORDER); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase("CONTRATO N:", fontCorpoN)); cellDataPart1.setBorder(PdfPCell.NO_BORDER); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase(reS.getAPOLICE(), fontCorpo)); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); cellDataPart1.setBorder(PdfPCell.NO_BORDER); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase("DESCRIO:", fontCorpoN)); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); cellDataPart1.setBorder(PdfPCell.NO_BORDER); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase(reS.getDESCRICAO(), fontCorpo)); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); cellDataPart1.setBorder(PdfPCell.NO_BORDER); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase("PERIODO:", fontCorpoN)); cellDataPart1.setBorder(PdfPCell.NO_BORDER); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase(reS.getINICIO() + " - " + reS.getFIM(), fontCorpo)); cellDataPart1.setBorder(PdfPCell.NO_BORDER); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase("LIMITE:", fontCorpoN)); cellDataPart1.setBorder(PdfPCell.NO_BORDER); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase((covertDouble(reS.getLIMITE()) == null) ? reS.getLIMITE() : Moeda.format(covertDouble(reS.getLIMITE())), fontCorpo)); cellDataPart1.setBorder(PdfPCell.NO_BORDER); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(5f); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase("MOEDA:", fontCorpoN)); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(10f); cellDataPart1.setBorder(PdfPCell.NO_BORDER); pTableDataPart1.addCell(cellDataPart1); cellDataPart1 = new PdfPCell(new Phrase(reS.getMOEDA(), fontCorpo)); cellDataPart1.setPaddingTop(5f); cellDataPart1.setPaddingBottom(10f); cellDataPart1.setBorder(PdfPCell.NO_BORDER); pTableDataPart1.addCell(cellDataPart1); /** * Data Part 1 end */ /** * Data Part 2 start */ PdfPTable pTableDataPart2 = new PdfPTable(new float[] { 33.333333333f, 33.333333333f, 33.333333333f }); pTableDataPart2.setWidthPercentage(90); PdfPCell cellDataPart2 = new PdfPCell(new Phrase("PREMIO GROSSO:", fontCorpoN)); cellDataPart2.setColspan(2); cellDataPart2.setBorder(PdfPCell.NO_BORDER); cellDataPart2.setPaddingTop(10f); cellDataPart2.setPaddingBottom(5f); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase( Moeda.format(Double.valueOf(reS.getPREMIOGROSSO().replace(',', '.'))) + " " + reS.getMOEDA(), fontCorpo)); cellDataPart2.setPaddingTop(10f); cellDataPart2.setPaddingBottom(5f); cellDataPart2.setBorder(PdfPCell.NO_BORDER); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase("DEDUO:", fontCorpoN)); cellDataPart2.setBorder(PdfPCell.NO_BORDER); cellDataPart2.setColspan(2); cellDataPart2.setPaddingTop(5f); cellDataPart2.setPaddingBottom(5f); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase(reS.getDEDUCAO() + "%", fontCorpo)); cellDataPart2.setPaddingTop(5f); cellDataPart2.setPaddingBottom(5f); cellDataPart2.setBorder(PdfPCell.NO_BORDER); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase("LIQUIDO:", fontCorpoN)); cellDataPart2.setBorder(PdfPCell.NO_BORDER); cellDataPart2.setColspan(2); cellDataPart2.setPaddingTop(5f); cellDataPart2.setPaddingBottom(5f); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase( Moeda.format(Double.valueOf(reS.getPREMIOGROSSO().replace(',', '.'))) + " " + reS.getMOEDA(), fontCorpo)); cellDataPart2.setPaddingTop(5f); cellDataPart2.setPaddingBottom(5f); cellDataPart2.setBorder(PdfPCell.NO_BORDER); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase("TOTAL:", fontCorpoN)); cellDataPart2.setBorder(PdfPCell.NO_BORDER); cellDataPart2.setPaddingTop(5f); cellDataPart2.setPaddingBottom(10f); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase("100%", fontCorpo)); cellDataPart2.setPaddingTop(5f); cellDataPart2.setPaddingBottom(10f); cellDataPart2.setBorder(PdfPCell.NO_BORDER); pTableDataPart2.addCell(cellDataPart2); cellDataPart2 = new PdfPCell(new Phrase( Moeda.format(Double.valueOf(reS.getTOTAL().replace(',', '.'))) + " " + reS.getMOEDA(), fontCorpo)); cellDataPart2.setPaddingTop(5f); cellDataPart2.setPaddingBottom(10f); cellDataPart2.setBorder(PdfPCell.NO_BORDER); pTableDataPart2.addCell(cellDataPart2); // cellDataPart2 = new PdfPCell(new Phrase("Your faithfully", fontCorpo)); // cellDataPart2.setColspan(3); // cellDataPart2.setPaddingTop(5f); // cellDataPart2.setPaddingBottom(0.7f); // cellDataPart2.setBorder(PdfPCell.NO_BORDER); // pTableDataPart2.addCell(cellDataPart2); // cellDataPart2 = new PdfPCell(new Phrase("THE UNITED AFRICAN INSURANCE BROKERS LTD", fontCorpo)); // cellDataPart2.setColspan(3); // cellDataPart2.setPaddingTop(0.7f); // cellDataPart2.setPaddingBottom(10F); // cellDataPart2.setBorder(PdfPCell.NO_BORDER); // pTableDataPart2.addCell(cellDataPart2); /** * Data Part 2 end */ PdfPTable pTableSecureter = new PdfPTable(new float[] { 30f, 30f, 40f }); PdfPCell cellSecureterNull = new PdfPCell(new Phrase(" ", fontCorpoN)); cellSecureterNull.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellSecureterNull.setPaddingTop(2f); cellSecureterNull.setPaddingBottom(2f); cellSecureterNull.setColspan(3); cellSecureterNull.setBorder(PdfPCell.NO_BORDER); pTableSecureter.addCell(cellSecureterNull); cellSecureterNull.setColspan(0); if (isReseguroOfNICON) { PdfPCell cellSecureter = new PdfPCell(new Phrase("RESSEGURADORA USADA", fontCorpoN)); cellSecureter.setColspan(2); cellSecureter.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellSecureter.setPaddingTop(8f); cellSecureter.setPaddingBottom(8f); cellSecureter.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); pTableSecureter.addCell(cellSecureter); pTableSecureter.addCell(cellSecureterNull); cellSecureter = new PdfPCell(new Phrase("RESSEGURA", fontCorpoN)); cellSecureter.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellSecureter.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellSecureter.setPaddingTop(5f); cellSecureter.setPaddingBottom(5); pTableSecureter.addCell(cellSecureter); cellSecureter = new PdfPCell(new Phrase("%PERCENTAGEM", fontCorpoN)); cellSecureter.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellSecureter.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellSecureter.setPaddingTop(5f); cellSecureter.setPaddingBottom(5); pTableSecureter.addCell(cellSecureter); pTableSecureter.addCell(cellSecureterNull); int total = listaDataEmpresas.size(); for (int i = 0; (i < total); i++) { cellSecureter = new PdfPCell(new Phrase(listaDataEmpresas.get(i).getEMPRESA(), fontCorpo)); cellSecureter.setPaddingTop(5f); cellSecureter.setPaddingBottom(5); cellSecureter.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); pTableSecureter.addCell(cellSecureter); cellSecureter = new PdfPCell(new Phrase( listaDataEmpresas.get(i).getPERCENTAGEM() + "% -- " + Moeda.format(((covertDouble(listaDataEmpresas.get(i).getPERCENTAGEM()) / 100) * covertDouble(reS.getPREMIOGROSSO()))) + " " + reS.getMOEDA(), fontCorpo)); cellSecureter.setPaddingTop(5f); cellSecureter.setPaddingBottom(5); cellSecureter.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellSecureter.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); pTableSecureter.addCell(cellSecureter); pTableSecureter.addCell(cellSecureterNull); } } PdfPTable pTablePocessed = new PdfPTable(new float[] { 100 }); PdfPCell cellPocessed = new PdfPCell(new Phrase("_____________________________", fontCorpoN)); cellPocessed.setBorder(PdfPCell.NO_BORDER); cellPocessed.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM); cellPocessed.setPaddingTop(50f); cellPocessed.setPaddingBottom(1f); pTablePocessed.addCell(cellPocessed); cellPocessed = new PdfPCell(new Phrase("PROCESSED BY", fontCorpoN)); cellPocessed.setPaddingTop(1f); cellPocessed.setVerticalAlignment(PdfPCell.ALIGN_TOP); cellPocessed.setBorder(PdfPCell.NO_BORDER); pTablePocessed.addCell(cellPocessed); SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss"); Document documento = new Document(); documento.setPageSize(PageSize.A4); documento.setMargins(20f, 20f, 70f, 5f); String f1 = (arquivo + "/" + user + "/Seguro " + nomeSeguro + "/"); File f = new File(f1); String Ddata = sdf1.format(new Date()); f.mkdirs(); f = new File(f.getAbsoluteFile() + "/" + "Doc Nota CO-ReSSEGURO " + Ddata + ".pdf"); reString = "../Documentos/" + user + "/Seguro " + nomeSeguro + "/" + "Doc Nota CO-ReSSEGURO " + Ddata + ".pdf"; OutputStream outputStraem = new FileOutputStream(f); PdfWriter writer = PdfWriter.getInstance(documento, outputStraem); documento.open(); documento.add(pTableEmpresaPricipal); documento.add(pTableLinha); documento.add(pTableLinha); /* documento.add(pTableTileDoc); documento.add(pTableLinha); */ documento.add(pTableDataPart1); documento.add(pTableLinha); documento.add(pTableDataPart2); documento.add(pTableLinha); documento.add(pTableLinha); documento.add(pTableSecureter); // documento.add(pTablePocessed); pTablePocessed.setTotalWidth(200); pTablePocessed.writeSelectedRows(-1, 100, 100f, 175f, writer.getDirectContent()); documento.close(); RequestContext.getCurrentInstance().execute("openAllDocument('" + reString + "')"); } catch (FileNotFoundException | DocumentException e) { } catch (IOException ex) { Logger.getLogger(DocNotaCredito.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Export.ExportViagemSemanaPdf.java
public static void criarDoc(Date dataInicio, Date dateFim, String user, String nomeFuncinario) { Font fontTableCorpo = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f); Font fontTableTitile = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f); Font fontRoadape = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f); Font fontRoadapeP = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f); Font fontRoadapeB = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f); Font fontRoadapeBU = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f, Font.UNDEFINED);// w w w .j a va2s. c o m Font fontCabecalhoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.5f); Font fontCorpoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.5f); Font fontCabecalhoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 16f, Font.UNDERLINE); OutputStream outputStraem; try { SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh.mm.ss"); SimpleDateFormat sdfTitile = new SimpleDateFormat("dd-MM-yyyy"); Document documento = new Document(); documento.setPageSize(PageSize.A4.rotate()); documento.setMargins(10f, 10f, 35f, 20f); File ff = new File(ConfigDoc.Fontes.getDiretorio() + "/" + user + "/Seguro Viagem/"); ff.mkdirs(); String Ddata = sdf.format(new Date()); ff = new File(ff.getAbsoluteFile() + "/" + "Export Mapa Viagem Semanal " + Ddata + ".pdf"); String reString = "../Documentos/" + user + "/Seguro Viagem/" + "Export Mapa Viagem Semanal " + Ddata + ".pdf"; outputStraem = new FileOutputStream(ff); PdfWriter writer = PdfWriter.getInstance(documento, outputStraem); PdfPTable tableDados = new PdfPTable( new float[] { 5f, 10.6f, 5f, 5f, 4.6f, 19f, 5.6f, 6f, 10.6f, 9.6f, 7f, 5.5f, 5.5f }); tableDados.setWidthPercentage(100f); BaseColor colorCinza = new BaseColor(129, 138, 145); for (int j = 0; j < 13; j++) { PdfPCell cellTitileTable = new PdfPCell(new Phrase(titileTable(j), fontTableTitile)); cellTitileTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cellTitileTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellTitileTable.setBackgroundColor(colorCinza); tableDados.addCell(cellTitileTable); } dataViagem(dataInicio, dateFim); float premiototal = 0; for (HashMap<String, Object> data : hasList) { tableDados.addCell(new Phrase(toString(data.get(DATA)), fontTableCorpo)); tableDados.addCell(ExportViagemSemanaPdf .cellEspecial(new PdfPCell(new Phrase(toString(data.get(NUMEROAPOLICE)), fontTableCorpo)))); tableDados.addCell( new Phrase(ConfigDoc.toFormat(toString(data.get(INICIO)), "dd-MM-yyyy", "yyyy-MM-dd"), fontTableCorpo)); tableDados.addCell(new Phrase( ConfigDoc.toFormat(toString(data.get(FIM)), "dd-MM-yyyy", "yyyy-MM-dd"), fontTableCorpo)); premiototal += toFloat(data.get(PREMIO)); PdfPCell cellRigh = new PdfPCell( new Phrase(ConfigDoc.toMoeda(toFloat(data.get(PREMIO)), ""), fontTableCorpo)); cellRigh.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); tableDados.addCell(cellRigh); tableDados.addCell(new Phrase(toString(data.get(CLIENTE)), fontTableCorpo)); tableDados.addCell(new Phrase(toString(data.get(DATANASCIMENTO)), fontTableCorpo)); tableDados.addCell(new Phrase(toString(data.get(TELEFONE)), fontTableCorpo)); tableDados.addCell(new Phrase(toString(data.get(ENDERECO)), fontTableCorpo)); tableDados.addCell(new Phrase(toString(data.get(LOCALNASCIMENTO)), fontTableCorpo)); tableDados.addCell(new Phrase(toString(data.get(PAISDESTINO)), fontTableCorpo)); tableDados.addCell(new Phrase(toString(data.get(CIDADEDESTINO)), fontTableCorpo)); tableDados.addCell(new Phrase(toString(data.get(ZONADESTINO)), fontTableCorpo)); } PdfPCell cellTotal = new PdfPCell(ExportViagemSemanaPdf.cellEspecial(new PdfPCell( new Phrase("AL AMOUNT..........................................", fontTableTitile)))); cellTotal.setColspan(4); cellTotal.setPadding(1.5f); cellTotal.setBackgroundColor(colorCinza); tableDados.addCell(cellTotal); cellTotal = new PdfPCell(ExportViagemSemanaPdf .cellEspecial(new PdfPCell(new Phrase(ConfigDoc.toMoeda(premiototal, ""), fontTableTitile)))); cellTotal.setPadding(1.5f); cellTotal.setBackgroundColor(colorCinza); tableDados.addCell(cellTotal); cellTotal = new PdfPCell( ExportViagemSemanaPdf.cellEspecial(new PdfPCell(new Phrase(" ", fontTableTitile)))); cellTotal.setColspan(8); cellTotal.setPadding(1.5f); cellTotal.setBackgroundColor(colorCinza); tableDados.addCell(cellTotal); PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 15f, 85f }); PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1); PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(ConfigDoc.Empresa.NOME, fontCabecalhoNG)); pCellNomeEmpresa.setBorder(0); PdfPCell pCellNomeEndereco = new PdfPCell(new Phrase(ConfigDoc.Empresa.ENDERECO, fontCabecalhoN)); pCellNomeEndereco.setBorder(0); PdfPCell pCellCaixaPostal = new PdfPCell(new Phrase(ConfigDoc.Empresa.CAIXAPOSTAL, fontCabecalhoN)); pCellCaixaPostal.setBorder(0); PdfPCell pCellTeleFax = new PdfPCell( new Phrase(ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, fontCabecalhoN)); pCellTeleFax.setBorder(0); PdfPCell pCellSociedade = new PdfPCell(new Phrase(ConfigDoc.Empresa.SOCIEDADE, fontCabecalhoN)); pCellSociedade.setBorder(0); Image imageEmpresa = Image.getInstance("logo.png"); imageEmpresa.scaleToFit(120f, 85f); pTableEmpresaInforImpres1.addCell(pCellNomeEmpresa); pTableEmpresaInforImpres1.addCell(pCellNomeEndereco); pTableEmpresaInforImpres1.addCell(pCellCaixaPostal); pTableEmpresaInforImpres1.addCell(pCellTeleFax); pTableEmpresaInforImpres1.addCell(pCellSociedade); PdfPCell cellTabela3 = new PdfPCell(pTableEmpresaInforImpres1); cellTabela3.setBorder(0); pTableEmpresaInforImpres5.addCell(cellTabela3); PdfPCell cellTabela5 = new PdfPCell(pTableEmpresaInforImpres5); cellTabela5.setBorder(0); PdfPCell cellTabela6 = new PdfPCell(imageEmpresa); cellTabela6.setBorder(0); pTableEmpresaPricipal.setWidthPercentage(95); pTableEmpresaPricipal.addCell(cellTabela6); pTableEmpresaPricipal.addCell(cellTabela5); PdfPTable pTableTitulo = new PdfPTable(1); pTableTitulo.setHorizontalAlignment(Element.ALIGN_CENTER); pTableTitulo.setWidthPercentage(100); PdfPCell cellTitulo = new PdfPCell(new Phrase("RLELATORIO SEMANAL NO. " + "" + "\n" + ((dataInicio != null) ? sdfTitile.format(dataInicio) + " - " : "") + ((dateFim != null) ? sdfTitile.format(dateFim) : ""), fontCorpoNG)); cellTitulo.setBorder(0); cellTitulo.setPaddingBottom(20f); cellTitulo.setPaddingTop(10f); cellTitulo.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); pTableTitulo.addCell(cellTitulo); pTableEmpresaPricipal.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPTable pTableRodape = new PdfPTable(new float[] { 50f, 50f }); pTableRodape.setWidthPercentage(90f); PdfPCell cellRodape = new PdfPCell(new Phrase("DEPARTAMENTO FINANCEIRO", fontRoadapeBU)); cellRodape.setBorder(0); cellRodape.setColspan(2); cellRodape.setPaddingTop(20f); pTableRodape.addCell(cellRodape); cellRodape = new PdfPCell(new Phrase("QUEIRA POR FAVOR CONFERIR OS PAGAMENTOS", fontRoadape)); cellRodape.setColspan(2); cellRodape.setBorder(0); pTableRodape.addCell(cellRodape); cellRodape = new PdfPCell(new Phrase("ELABORADO POR", fontRoadapeB)); cellRodape.setBorder(0); pTableRodape.addCell(cellRodape); cellRodape = new PdfPCell(new Phrase("VENFICADO POR", fontRoadapeB)); cellRodape.setBorder(0); cellRodape.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); pTableRodape.addCell(cellRodape); cellRodape = new PdfPCell(new Phrase("................................................", fontRoadape)); cellRodape.setBorder(0); cellRodape.setPaddingTop(30f); pTableRodape.addCell(cellRodape); cellRodape = new PdfPCell(new Phrase("................................................", fontRoadape)); cellRodape.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); cellRodape.setBorder(0); cellRodape.setPaddingTop(30f); pTableRodape.addCell(cellRodape); cellRodape = new PdfPCell(new Phrase(nomeFuncinario, fontRoadapeP)); cellRodape.setColspan(2); cellRodape.setBorder(0); pTableRodape.addCell(cellRodape); documento.open(); documento.add(pTableEmpresaPricipal); documento.add(pTableTitulo); documento.add(tableDados); documento.add(pTableRodape); documento.close(); RequestContext.getCurrentInstance().execute("openAllDocument('" + reString + "')"); } catch (FileNotFoundException | DocumentException ex) { Logger.getLogger(ExportViagemSemanaPdf.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ExportViagemSemanaPdf.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Export.FuncPagamento.java
private String pequenoPagamento(String numPagamento, String user, String nomeUser, int i) { OutputStream outputStraem;/* w w w . j av a 2s . c o m*/ try { SimpleDateFormat sdf = new SimpleDateFormat("MMMM yyyy - dd", new Locale("pt", "BR")); SimpleDateFormat sdf3 = new SimpleDateFormat("dd-MM-yyyy"); SimpleDateFormat sdf2 = new SimpleDateFormat("dd 'de' MMMM 'de' yyyy", new Locale("pt", "BR")); SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss"); Font fontCabecalhoN = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 14f); Font fontCorpo = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 8.5f); Font fontCorpoU = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f, Font.UNDERLINE); // Font fontCorpoP= FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED ,8f ); Font fontCorpoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f); Font fontCorpoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8.5f); // Font fontCorpoNGT= FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED , 13f ,Font.UNDERLINE); Font fontCabecalhoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 16f, Font.UNDERLINE); Document documento = new Document(); documento.setPageSize(PageSize.A4); documento.setMargins(20f, 20f, 10f, 5f); String Ddata = sdf1.format(new Date()); ArrayList<HashMap<String, Object>> mapList = getObj(numPagamento); int total = mapList.size(); File ff = new File(ConfigDoc.Fontes.getDiretorio() + "/" + user + "/Pagamentos/"); ff.mkdirs(); ff = new File(ff.getAbsoluteFile() + "/" + "Pagamentos Func " + Ddata + ".pdf"); outputStraem = new FileOutputStream(ff); PdfWriter writer = PdfWriter.getInstance(documento, outputStraem); MyFooterA5 event = new MyFooterA5(); writer.setPageEvent(event); documento.open(); PdfPTable pTableTitile = new PdfPTable(new float[] { 100 }); pTableTitile.setWidthPercentage(95f); PdfPCell cellTitile = new PdfPCell(); cellTitile.setBorder(0); Paragraph pTitile = new Paragraph(); pTitile.add(new Phrase(ConfigDoc.Empresa.NOME.toUpperCase(), fontCabecalhoNG)); pTitile.setAlignment(Element.ALIGN_CENTER); PdfPTable pTableSubTitile = new PdfPTable(new float[] { 80, 20 }); pTableSubTitile.setWidthPercentage(101f); PdfPCell cellSubTitile = new PdfPCell( new Phrase("Petty cash voucher no.".toUpperCase(), fontCabecalhoN)); cellSubTitile.setBorder(0); cellSubTitile.setHorizontalAlignment(Element.ALIGN_RIGHT); cellSubTitile.setPaddingBottom(20); cellSubTitile.setPaddingRight(67); cellSubTitile.setPaddingTop(10); pTableSubTitile.addCell(cellSubTitile); cellSubTitile = new PdfPCell( new Phrase(toData((mapList.size() > 0) ? mapList.get(0).get(REGISTRO) : " ", i).toUpperCase(), fontCabecalhoN)); cellSubTitile.setHorizontalAlignment(Element.ALIGN_LEFT); cellSubTitile.setBorder(0); cellSubTitile.setPaddingBottom(20); cellSubTitile.setPaddingTop(10); pTableSubTitile.addCell(cellSubTitile); // pTitile.add(cellSubTitile); pTitile.add(pTableSubTitile); cellTitile.addElement(pTitile); pTableTitile.addCell(cellTitile); documento.add(pTableTitile); PdfPTable pTableDados = new PdfPTable(new float[] { 5.6f, 6.05f, 53.5f, 17.95f, 19f }); pTableDados.setWidthPercentage(95f); PdfPCell cellDados = new PdfPCell(new Phrase("S/N", fontCorpoNG)); cellDados.setHorizontalAlignment(Element.ALIGN_CENTER); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("Qty", fontCorpoNG)); cellDados.setHorizontalAlignment(Element.ALIGN_CENTER); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("Detail Description", fontCorpoNG)); cellDados.setHorizontalAlignment(Element.ALIGN_CENTER); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("Unit price", fontCorpoNG)); cellDados.setHorizontalAlignment(Element.ALIGN_CENTER); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase("AMT (STD)", fontCorpoNG)); cellDados.setHorizontalAlignment(Element.ALIGN_CENTER); pTableDados.addCell(cellDados); Double toPa = 0.0; for (int j = 0; j < total; j++) { int tLinha = toString(mapList.get(j).get(DESCRICAOPAGAMENTO)).split("\n").length; float pad = setPadding(total, tLinha); cellDados = new PdfPCell(new Phrase((j + 1) + "", fontCorpo)); cellDados.setPaddingBottom(pad); cellDados.setVerticalAlignment(Element.ALIGN_MIDDLE); cellDados.setPaddingTop(pad); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase(toInt(mapList.get(j).get(QUANTIDADE)) + "", fontCorpo)); cellDados.setPaddingBottom(pad); cellDados.setVerticalAlignment(Element.ALIGN_MIDDLE); cellDados.setPaddingTop(pad); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase(toString(mapList.get(j).get(DESCRICAOPAGAMENTO)), fontCorpo)); cellDados.setPaddingBottom(pad); cellDados.setVerticalAlignment(Element.ALIGN_MIDDLE); cellDados.setPaddingTop(pad); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase(toMoeda( (toDouble(mapList.get(j).get(VALORPAGAMENTO)) / (float) toInt(mapList.get(j).get(QUANTIDADE))), toString(mapList.get(j).get(SIGLA))), fontCorpo)); cellDados.setPaddingBottom(pad); cellDados.setVerticalAlignment(Element.ALIGN_MIDDLE); cellDados.setPaddingTop(pad); pTableDados.addCell(cellDados); cellDados = new PdfPCell(new Phrase( toMoeda(toDouble(mapList.get(j).get(VALORPAGAMENTO)), toString(mapList.get(j).get(SIGLA))), fontCorpo)); cellDados.setPaddingBottom(pad); cellDados.setVerticalAlignment(Element.ALIGN_MIDDLE); cellDados.setPaddingTop(pad); pTableDados.addCell(cellDados); toPa += toDouble(mapList.get(j).get(VALORPAGAMENTO)); } // 5.6f,5.6f,53.5f,17.95f,19.45f PdfPTable pTableRodape = new PdfPTable(new float[] { 5.6f, 6.05f, 19.795f, 33.705f, 17.95f, 19f }); pTableRodape.setWidthPercentage(95f); cellDados = new PdfPCell(new Phrase(" ", fontCorpoNG)); pTableRodape.addCell(cellDados); cellDados = new PdfPCell(new Phrase("CODE", fontCorpoNG)); pTableRodape.addCell(cellDados); cellDados = new PdfPCell(new Phrase(toString(mapList.get(0).get(DOCFORMAPAGAMENTO)), fontCorpoNG)); pTableRodape.addCell(cellDados); cellDados = new PdfPCell(new Phrase(toString(mapList.get(0).get(DESCRICAOCONTABANCO)), fontCorpoNG)); pTableRodape.addCell(cellDados); cellDados = new PdfPCell(new Phrase("TOTAL", fontCorpoNG)); pTableRodape.addCell(cellDados); cellDados = new PdfPCell(new Phrase(toMoeda(toPa, toString(mapList.get(0).get(SIGLA))), fontCorpoNG)); pTableRodape.addCell(cellDados); documento.add(pTableDados); documento.add(pTableRodape); PdfPTable pTableAssiEstenso = new PdfPTable(new float[] { 100f }); pTableAssiEstenso.setWidthPercentage(95f); PdfPCell cellAssiEstenso = new PdfPCell(); Paragraph pAssiEstenso = new Paragraph(); PdfPTable pTableResposavel = new PdfPTable(new float[] { 70, 30 }); pTableResposavel.setWidthPercentage(100f); PdfPCell cellResposavel = new PdfPCell(); cellResposavel .addElement(new Phrase("Requested by:_________________________________________", fontCorpoN)); cellResposavel.setPaddingTop(10f); cellResposavel.setPaddingBottom(20f); cellResposavel.setBorder(0); pTableResposavel.addCell(cellResposavel); cellResposavel = new PdfPCell(); cellResposavel.addElement(new Phrase(" HOD:___________________", fontCorpoN)); cellResposavel.setPaddingTop(10f); cellResposavel.setPaddingBottom(20f); cellResposavel.setBorder(0); pTableResposavel.addCell(cellResposavel); cellResposavel = new PdfPCell(); cellResposavel .addElement(new Phrase("Approveds by:_________________________________________", fontCorpoN)); cellResposavel.setPaddingTop(-5f); cellResposavel.setPaddingBottom(20f); cellResposavel.setBorder(0); pTableResposavel.addCell(cellResposavel); cellResposavel = new PdfPCell(); cellResposavel.addElement(new Phrase(" Date:___________________", fontCorpoN)); cellResposavel.setPaddingTop(-5f); cellResposavel.setPaddingBottom(20f); cellResposavel.setBorder(0); pTableResposavel.addCell(cellResposavel); pAssiEstenso.add(pTableResposavel); cellAssiEstenso.addElement(pAssiEstenso); PdfPTable pTableExteso = new PdfPTable(new float[] { 25f, 75f }); pTableExteso.setWidthPercentage(100f); JTextPane jtp = new JTextPane(); Moeda.EscreverEstenso(toPa, jtp, ((mapList.size() > 0) ? toString(mapList.get(0).get(MOEDA)) : "")); PdfPCell cellExteso = new PdfPCell(new Phrase("Recived the sum of", fontCorpoN)); cellExteso.setBorder(0); pTableExteso.addCell(cellExteso); cellExteso = new PdfPCell(new Phrase(jtp.getText().toUpperCase().trim(), fontCorpoU)); cellExteso.setBorder(0); pTableExteso.addCell(cellExteso); pAssiEstenso.add(pTableExteso); PdfPTable pTableAss = new PdfPTable(new float[] { 45f, 55f }); pTableAss.setWidthPercentage(100f); PdfPCell cellAss = new PdfPCell(new Phrase(" ______________", fontCorpoN)); cellAss.setPaddingTop(15f); cellAss.setHorizontalAlignment(Element.ALIGN_CENTER); cellAss.setBorder(0); cellAss.setPaddingBottom(0f); pTableAss.addCell(cellAss); cellAss = new PdfPCell(new Phrase(" ____________________________________________", fontCorpoN)); cellAss.setPaddingTop(15f); cellAss.setPaddingBottom(0f); cellAss.setHorizontalAlignment(Element.ALIGN_CENTER); cellAss.setBorder(0); pTableAss.addCell(cellAss); cellAss = new PdfPCell(new Phrase("Date", fontCorpoN)); cellAss.setHorizontalAlignment(Element.ALIGN_CENTER); cellAss.setBorder(0); pTableAss.addCell(cellAss); cellAss = new PdfPCell(new Phrase("Receiver name & signature", fontCorpoN)); cellAss.setHorizontalAlignment(Element.ALIGN_CENTER); cellAss.setBorder(0); pTableAss.addCell(cellAss); pTableAss.setHorizontalAlignment(Element.ALIGN_CENTER); pAssiEstenso.add(pTableAss); pAssiEstenso.setAlignment(Element.ALIGN_CENTER); pAssiEstenso.add(new Phrase( "NOTA: Um recibo oficial pode ser obtido por um pagamento e informado na parte inversa deste comprovativo.\n\n", fontCorpoN)); cellAssiEstenso = new PdfPCell(); cellAssiEstenso.addElement(pAssiEstenso); pTableAssiEstenso.addCell(cellAssiEstenso); documento.add(pTableAssiEstenso); documento.close(); reString = "../Documentos/" + user + "/Pagamentos/" + "Pagamentos Func " + Ddata + ".pdf"; return reString; } catch (FileNotFoundException | DocumentException ex) { Logger.getLogger(FuncPagamento.class.getName()).log(Level.SEVERE, null, ex); } return reString; }
From source file:Export.GenericPDFs.java
/** * * @param user// w w w . j av a2 s . c om * @param nomeDoc * @param titleDoc * @param rs * @param op * @param paramFilter * @return */ public static String createDoc(String user, String nomeDoc, String titleDoc, DataTableControl rs, OrientacaoPagina op, int paramFilter) { nomeDocR = nomeDoc; try { Font fontCabecalhoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 10f); Font fontCorpo = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f); Font fontCorpoTable = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 7.5f); Font fontCorpoTableN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 7.8f); Font fontCorpoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f); Font fontCorpoTitile = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 11.5f); Font fontCabecalhoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 16f, Font.UNDERLINE); getMap(rs, paramFilter); ar = createPerncetage(list, paramFilter); PdfPTable tableDados = new PdfPTable(ar); Document documento = new Document(); i = 0; SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss"); File ff = new File(ConfigDoc.Fontes.getDiretorio() + "/" + user + "/Relatorio"); ff.mkdirs(); String Ddata = sdf1.format(new Date()); ff = new File(ff.getAbsoluteFile() + "/" + nomeDoc + " " + Ddata + ".pdf"); OutputStream outputStraem = new FileOutputStream(ff); reString = "../Documentos/" + user + "/Relatorio/" + nomeDoc + " " + Ddata + ".pdf"; PdfWriter writer = PdfWriter.getInstance(documento, outputStraem); MyFooter event = new MyFooter(); writer.setPageEvent(event); if (op == OrientacaoPagina.HORIZONTAL) { documento.setPageSize(PageSize.A4.rotate()); } else { documento.setPageSize(PageSize.A4); } documento.setMargins(10f, 10f, 35f, 35f); PdfPTable pTableEmpresaPricipal = new PdfPTable( (OrientacaoPagina.HORIZONTAL == op) ? new float[] { 14f, 86f } : new float[] { 18.5f, 82.5f }); PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1); PdfPTable pTableNull = new PdfPTable(1); PdfPCell cellNull = new PdfPCell(new Phrase(" ", fontCorpo)); cellNull.setBorder(0); pTableNull.addCell(cellNull); PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(ConfigDoc.Empresa.NOME, fontCabecalhoNG)); pCellNomeEmpresa.setBorder(0); PdfPCell pCellNomeEndereco = new PdfPCell(new Phrase(ConfigDoc.Empresa.ENDERECO, fontCabecalhoN)); pCellNomeEndereco.setBorder(0); PdfPCell pCellCaixaPostal = new PdfPCell(new Phrase(ConfigDoc.Empresa.CAIXAPOSTAL, fontCabecalhoN)); pCellCaixaPostal.setBorder(0); PdfPCell pCellTeleFax = new PdfPCell( new Phrase(ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, fontCabecalhoN)); pCellTeleFax.setBorder(0); PdfPCell pCellSociedade = new PdfPCell(new Phrase(ConfigDoc.Empresa.SOCIEDADE, fontCabecalhoN)); pCellSociedade.setBorder(0); Image imageEmpresa = Image.getInstance("logo.png"); imageEmpresa.scaleToFit(120f, 85f); pTableEmpresaInforImpres1.addCell(pCellNomeEmpresa); pTableEmpresaInforImpres1.addCell(pCellNomeEndereco); pTableEmpresaInforImpres1.addCell(pCellCaixaPostal); pTableEmpresaInforImpres1.addCell(pCellTeleFax); pTableEmpresaInforImpres1.addCell(pCellSociedade); PdfPCell cellTabela3 = new PdfPCell(pTableEmpresaInforImpres1); cellTabela3.setBorder(0); pTableEmpresaInforImpres5.addCell(cellTabela3); PdfPCell cellTabela5 = new PdfPCell(pTableEmpresaInforImpres5); cellTabela5.setBorder(0); PdfPCell cellTabela6 = new PdfPCell(imageEmpresa); cellTabela6.setBorder(0); pTableEmpresaPricipal.setWidthPercentage(97); pTableEmpresaPricipal.addCell(cellTabela6); pTableEmpresaPricipal.addCell(cellTabela5); documento.open(); documento.add(pTableEmpresaPricipal); documento.add(pTableNull); PdfPTable pTableTitile = new PdfPTable(1); SimpleDateFormat format = new SimpleDateFormat("dd 'de' MMMM 'de' yyyy", new Locale("pt", "BR")); PdfPCell cellTitile = new PdfPCell(new Phrase(titleDoc.toUpperCase() + ((dF != null && dI != null) ? (" de " + format.format(dI) + " " + format.format(dF)).toUpperCase() : ""), fontCorpoTitile)); cellTitile.setPaddingBottom(20f); cellTitile.setBorder(0); cellTitile.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); pTableTitile.addCell(cellTitile); documento.add(pTableTitile); tableDados.setWidthPercentage(97f); PdfPTable tableTitile = new PdfPTable(ar); tableTitile.setWidthPercentage(97f); if (paramFilter < 0) { for (Object[] emap : list) { tableDados = new PdfPTable(ar); tableDados.setWidthPercentage(97f); if (emap[0] == null || !emap[0].equals("TOTAL")) { for (int j = 0; j < emap.length; j++) { if (cabe && i == 0) { lista_titulo_table = emap; PdfPCell cellTitileTable = new PdfPCell( new Phrase(toString(emap[j]).toUpperCase(), fontCorpoNG)); cellTitileTable.setBorderWidth(1f); cellTitileTable.setPaddingTop(8f); cellTitileTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellTitileTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); BaseColor colorAzul = new BaseColor(255, 255, 255); cellTitileTable.setBackgroundColor(colorAzul); cellTitileTable.setPaddingBottom(8f); tableTitile.addCell(cellTitileTable); } else { PdfPCell dados = new PdfPCell(new Phrase(toString(emap[j]), fontCorpoTable)); dados.setHorizontalAlignment( (alignment.containsKey(j)) ? alignment.get(j).i : PdfPCell.ALIGN_LEFT); dados.setPaddingTop(5f); dados.setPaddingBottom(5f); BaseColor colorCinza = new BaseColor(255, 255, 255); dados.setBackgroundColor(((i % 2 != 0) ? colorCinza : null)); tableDados.addCell(dados); } } i++; cabe = false; } if (i == 1) { documento.add(tableTitile); } documento.add(tableDados); } PdfPTable tableTotal = new PdfPTable(ar); tableTotal.setWidthPercentage(97f); mapTotal.entrySet().stream().forEach((entrySet) -> { mapTotal.get(entrySet.getKey()).stream().forEach((get) -> { for (int g = 0; g < get.length; g++) { if (g != paramFilter) { PdfPCell dados = new PdfPCell( new Phrase(((g == 0) ? "TOTAL" : toString(get[g])), fontCorpoTableN)); dados.setHorizontalAlignment( (alignment.containsKey(g)) ? alignment.get(g).i : PdfPCell.ALIGN_LEFT); dados.setPaddingTop(5f); dados.setPaddingBottom(5f); BaseColor colorCinza = new BaseColor(255, 255, 255); dados.setBackgroundColor(colorCinza); tableTotal.addCell(dados); } } }); }); documento.add(tableTotal); } else { int t = 0; for (Map.Entry<String, ArrayList<Object[]>> lista : map.entrySet()) { i = 0; cabe = true; PdfPTable pTableSubTitile = new PdfPTable(new float[] { 100 }); pTableSubTitile.setWidthPercentage(97f); PdfPCell cellSubTitile = new PdfPCell( new Paragraph(lista.getKey().toUpperCase(), fontCorpoTitile)); cellSubTitile.setBorder(PdfPCell.NO_BORDER); cellSubTitile.setPaddingTop(0f); cellSubTitile.setPaddingBottom(0f); pTableSubTitile.addCell(cellSubTitile); documento.add(pTableSubTitile); documento.add(new Paragraph(" ")); for (Object[] emap : lista.getValue()) { tableDados = new PdfPTable(ar); tableTitile = new PdfPTable(ar); tableDados.setWidthPercentage(97f); tableTitile.setWidthPercentage(97f); int k = 0; for (int j = 0; j < emap.length; j++) { if (k != paramFilterOculta) { if (cabe && i == 0) { lista_titulo_table = emap; PdfPCell cellTitileTable = new PdfPCell( new Phrase(toString(emap[j]).toUpperCase(), fontCorpoNG)); cellTitileTable.setBorderWidth(1f); cellTitileTable.setPaddingTop(8f); cellTitileTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellTitileTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); BaseColor colorAzul = new BaseColor(255, 255, 255); cellTitileTable.setBackgroundColor(colorAzul); cellTitileTable.setPaddingBottom(8f); tableTitile.addCell(cellTitileTable); } else { PdfPCell dados = new PdfPCell(new Phrase(toString(emap[j]), fontCorpoTable)); dados.setHorizontalAlignment( (alignment.containsKey(j)) ? alignment.get(j).i : PdfPCell.ALIGN_LEFT); dados.setPaddingTop(5f); dados.setPaddingBottom(5f); BaseColor colorCinza = new BaseColor(255, 255, 255); dados.setBackgroundColor(((i % 2 != 0) ? colorCinza : null)); tableDados.addCell(dados); } } k++; } i++; cabe = false; if (i == 1) { documento.add(tableTitile); } documento.add(tableDados); } PdfPTable tableTotal = new PdfPTable(ar); tableTotal.setWidthPercentage(97f); if (mapTotal.containsKey(lista.getKey())) { mapTotal.get(lista.getKey()).stream().forEach((get) -> { for (int g = 0; g < get.length; g++) { if (g != paramFilterOculta) { PdfPCell dados = new PdfPCell( new Phrase(((g == 0) ? "TOTAL" : toString(get[g])), fontCorpoTableN)); dados.setHorizontalAlignment( (alignment.containsKey(g)) ? alignment.get(g).i : PdfPCell.ALIGN_LEFT); dados.setPaddingTop(5f); dados.setPaddingBottom(5f); BaseColor colorCinza = new BaseColor(255, 255, 255); dados.setBackgroundColor(colorCinza); tableTotal.addCell(dados); } } }); } documento.add(tableTotal); t++; documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); if (t == map.size() && paramFilter > -1) { PdfPTable tableTotal_t = new PdfPTable(ar); tableTotal_t.setWidthPercentage(97f); for (int j = 0; j < lista_titulo_table.length; j++) { if (j != paramFilterOculta) { PdfPCell cellTitileTable = new PdfPCell( new Phrase(toString(lista_titulo_table[j]).toUpperCase(), fontCorpoNG)); cellTitileTable.setBorderWidth(1f); cellTitileTable.setPaddingTop(8f); cellTitileTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cellTitileTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); BaseColor colorAzul = new BaseColor(255, 255, 255); cellTitileTable.setBackgroundColor(colorAzul); cellTitileTable.setPaddingBottom(8f); tableTotal_t.addCell(cellTitileTable); } } Double[] total_total = new Double[lista_titulo_table.length]; mapTotal.entrySet().stream().forEach((entrySet) -> { mapTotal.get(entrySet.getKey()).stream().forEach((value) -> { for (int g = 0; g < value.length; g++) { if (!entrySet.getKey().equals("TOTAL")) { if (g != paramFilterOculta) { if (Moeda.unFormat(toString(value[g]).replaceAll(" ", "") .replaceAll(",", ".").replaceAll("STD", "")) != -1) { double v = ((total_total[g] == null) ? 0.0 : total_total[g]); total_total[g] = (Moeda .unFormat(toString(value[g]).replaceAll(" ", "") .replaceAll(",", ".").replaceAll("STD", "")) + v); } PdfPCell dados = new PdfPCell(new Phrase( ((g == 0) ? "TOTAL " + entrySet.getKey().toUpperCase() : toString(value[g])), fontCorpoTableN)); dados.setHorizontalAlignment( (alignment.containsKey(g)) ? alignment.get(g).i : PdfPCell.ALIGN_LEFT); dados.setPaddingTop(5f); dados.setPaddingBottom(5f); BaseColor colorCinza = new BaseColor(255, 255, 255); dados.setBackgroundColor(colorCinza); tableTotal_t.addCell(dados); } } } }); }); for (int j = 0; j < total_total.length; j++) { if (j != paramFilterOculta) { PdfPCell cellTitileTable = new PdfPCell( new Phrase((total_total[j] != null) ? Moeda.format(total_total[j]) : " ", fontCorpoNG)); cellTitileTable.setPaddingTop(5f); cellTitileTable.setHorizontalAlignment( (alignment.containsKey(j)) ? alignment.get(j).i : PdfPCell.ALIGN_LEFT); BaseColor colorAzul = new BaseColor(255, 255, 255); cellTitileTable.setBackgroundColor(colorAzul); cellTitileTable.setPaddingBottom(5f); tableTotal_t.addCell(cellTitileTable); } } documento.add(tableTotal_t); } } } documento.close(); no = false; nomeNo = ""; dI = null; dF = null; paramFilterOculta = -1; removeItem = new int[] {}; renameItem = new HashMap<>(); alignment = new HashMap<>(); arrValoresTotal = new int[] {}; valoresTotal = new String[] {}; RequestContext.getCurrentInstance().execute("openAllDocument('" + reString + "')"); return reString; } catch (BadElementException | IOException ex) { Logger.getLogger(GenericPDFs.class.getName()).log(Level.SEVERE, null, ex); return ""; } catch (DocumentException ex) { Logger.getLogger(GenericPDFs.class.getName()).log(Level.SEVERE, null, ex); return ""; } }