List of usage examples for com.itextpdf.text Paragraph Paragraph
public Paragraph(Phrase phrase)
Paragraph
with a certain Phrase
. From source file:bsf.conn.DBMS.java
private static void addContent(Document document) throws DocumentException { Anchor anchor = new Anchor("Personal Info", catFont); anchor.setName("Personal Info"); // Second parameter is the number of the chapter Chapter catPart = new Chapter(new Paragraph(anchor), 1); Paragraph subPara = new Paragraph(null, smallBold); Section subCatPart = catPart.addSection(subPara); // add a table subPara.setAlignment(Element.ALIGN_LEFT); createTable(subCatPart, info.personalInfo); // now add all this to the document document.add(catPart);/*from w w w. j a v a 2s . com*/ // Next section anchor = new Anchor("Personal Information", catFont); anchor.setName("Personal Information"); // Second parameter is the number of the chapter catPart = new Chapter(new Paragraph(anchor), 1); subPara = new Paragraph("Running Details", smallBold); subPara.setAlignment(Element.ALIGN_LEFT); subCatPart = catPart.addSection(subPara); // add a table addEmptyLine(subPara, 3); createTable(subCatPart, info.runningDetails); // now add all this to the document document.add(catPart); // Next section anchor = new Anchor("Personal Information", catFont); anchor.setName("Personal Information"); // Thrd parameter is the number of the chapter catPart = new Chapter(new Paragraph(anchor), 1); subPara = new Paragraph("Leave Details", smallBold); subCatPart = catPart.addSection(subPara); // add a table addEmptyLine(subPara, 3); subPara.setAlignment(Element.ALIGN_LEFT); createTable(subCatPart, info.leaveDetails); // now add all this to the document document.add(catPart); // Next section anchor = new Anchor("Family Information", catFont); anchor.setName("Family Information"); // Fourth parameter is the number of the chapter catPart = new Chapter(new Paragraph(anchor), 1); subPara = new Paragraph(null, smallBold); subCatPart = catPart.addSection(subPara); // add a table subPara.setAlignment(Element.ALIGN_LEFT); addEmptyLine(subPara, 3); createTable(subCatPart, info.familyInfo); // now add all this to the document document.add(catPart); // Next section anchor = new Anchor("Course Information", catFont); anchor.setName("Course Information"); // Fifth parameter is the number of the chapter catPart = new Chapter(new Paragraph(anchor), 1); subPara = new Paragraph(null, smallBold); subCatPart = catPart.addSection(subPara); // add a table subPara.setAlignment(Element.ALIGN_LEFT); addEmptyLine(subPara, 3); createTable(subCatPart, info.courseDetails); // now add all this to the document document.add(catPart); }
From source file:Business.PDFMaker.java
public PDFMaker(String filename, TicketMap tm, int pr1, int pr2, int pr3) { Document doc = new Document(); try {//from ww w . ja v a 2s . c o m PdfWriter.getInstance(doc, new FileOutputStream(filename)); doc.open(); doc.add(new Phrase("Cabaz de Natal, Cl Schindler")); doc.add(new Paragraph("As seguintes Rifas foram vendidas:")); doc.add(new Paragraph("\n")); PdfPTable table = new PdfPTable(5); for (Ticket t : tm.getFullTickets()) { PdfPCell cell = new PdfPCell(new Paragraph(t.getId() + "-" + t.getName())); table.addCell(cell); } doc.add(table); doc.add(new Chapter("Vencedores deste ano:", 1)); doc.add(new Paragraph("1 Prmio. " + tm.getTicket(pr1))); doc.add(new Paragraph("2 Prmio. " + tm.getTicket(pr2))); doc.add(new Paragraph("3 Prmio. " + tm.getTicket(pr3))); doc.close(); } catch (Exception e) { } }
From source file:bussiness.ReportHandler.java
private void BuildBodyPrescription(List<Medicine> medicines, Document veterinaryPrescription, Double totalCost, PdfPTable table) throws DocumentException { Font font2 = new Font(); font2.setSize(20);//from ww w . j av a2 s . c o m for (Medicine medicine : medicines) { table.addCell(new Phrase(medicine.getName(), font2)); table.addCell(new Phrase(medicine.getDose(), font2)); table.addCell(new Phrase(medicine.getAdministration(), font2)); } PdfPCell celdaFinal = new PdfPCell(new Paragraph("Total: " + totalCost)); celdaFinal.setBorderWidthRight(0); celdaFinal.setBorderWidthLeft(0); celdaFinal.setBorderColorTop(BaseColor.DARK_GRAY); celdaFinal.setBorderColorBottom(BaseColor.DARK_GRAY); celdaFinal.setPaddingLeft(50); // Indicamos cuantas columnas ocupa la celda celdaFinal.setColspan(3); celdaFinal.setPaddingLeft(235); table.addCell(celdaFinal); veterinaryPrescription.add(table); }
From source file:bussiness.ReportHandler.java
private void BuildHeaderSaleReport(Document documento) throws DocumentException { Date date = new Date(); Chunk glue = new Chunk(new VerticalPositionMark()); Paragraph p = new Paragraph(hourdateFormat.format(date)); p.add(new Chunk(glue)); p.add("Le atendio: " + Receptionist.name); documento.add(p);/*from w w w.ja v a2s. c o m*/ }
From source file:bussiness.ReportHandler.java
private void BuildBodySaleReport(PdfPTable table, double totalCost, Document documento) throws DocumentException { List<Medicine> purchases = SalesViewHelper.getInstance().getPurchasesInformation(); for (Medicine product : purchases) { table.addCell(product.getName()); table.addCell(Double.toString(product.getCost())); }/*w w w . java 2 s . c om*/ PdfPCell celdaFinal = new PdfPCell(new Paragraph("Total: " + String.valueOf(totalCost))); celdaFinal.setBorderWidthRight(0); celdaFinal.setBorderWidthLeft(0); celdaFinal.setBorderColorTop(BaseColor.DARK_GRAY); celdaFinal.setBorderColorBottom(BaseColor.DARK_GRAY); celdaFinal.setPaddingLeft(50); // Indicamos cuantas columnas ocupa la celda celdaFinal.setColspan(2); celdaFinal.setPaddingLeft(235); table.addCell(celdaFinal); documento.add(table); }
From source file:bussiness.ReportHandler.java
private void BuildFooterSaleReport(Document documento) throws DocumentException { documento.add(new Chunk("\n")); documento.add(new Chunk("\n")); documento.add(new Chunk("\n")); Paragraph p2 = new Paragraph("GRACIAS POR SU PREFERENCIA"); p2.setAlignment(Element.ALIGN_CENTER); Paragraph p3 = new Paragraph("VUELVA PRONTO"); p3.setAlignment(Element.ALIGN_CENTER); documento.add(p2);// www . j a va 2 s . c om documento.add(p3); }
From source file:CadastroDeMusicas.Principal.java
public static void main(String[] args) throws Exception { ConecBanco c = new ConecBanco(con); Genero g;/* w ww . j a va 2 s . com*/ Artista a1; Album a2; Musica m; String nome, tipo; int nota, duracao, ano; int opc; try { new Principal(); } catch (ClassNotFoundException | SQLException e) { System.out.println("No conectado."); } do { opc = Integer.parseInt(JOptionPane.showInputDialog( "Informe a OPO:\n1.Inserir\n2.Deletar\n3.Pesquisar\n4.Relatorio em Pdf\n5.Sair")); switch (opc) { case 1: nome = JOptionPane.showInputDialog("Genero: "); g = new Genero(nome); nome = JOptionPane.showInputDialog("Artista: "); a1 = new Artista(nome); nome = JOptionPane.showInputDialog("Album: "); ano = Integer.parseInt(JOptionPane.showInputDialog("Ano: ")); a2 = new Album(nome, ano); nome = JOptionPane.showInputDialog("Musica: "); nota = Integer.parseInt(JOptionPane.showInputDialog("Nota (1/10): ")); duracao = Integer.parseInt(JOptionPane.showInputDialog("Durao: ")); m = new Musica(nome, nota, duracao); c.cadastrar(g, a1, a2, m); break; case 2: System.out.println("DELETAR MUSICA: "); nome = JOptionPane.showInputDialog("Musica: "); c.deletar(nome); break; case 3: System.out.println("PESQUISAR MUSICA: "); ResultSet rs = ConecBanco.pesquisar(); if (rs != null) { try { while (rs.next()) { System.out.println("MUSICA: " + rs.getString("nome")); System.out.println("NOTA: " + rs.getString("nota")); System.out.println("DURAO: " + rs.getString("duracao")); System.out.println("ALBUM: " + rs.getString("nomeAL")); System.out.println("ANO: " + rs.getString("ano")); System.out.println("ARTISTA: " + rs.getString("nomeAR")); System.out.println("GENERO: " + rs.getString("nomeGE")); } } catch (SQLException e) { System.out.println("Problema para exibir registros!"); } } else { System.out.println("A pesquisa no retornou nenhum registro!"); } break; case 4: Document doc = null; OutputStream os = null; String add; System.out.println("LISTA DE MUSICAS: "); try { doc = new Document(PageSize.A4, -1, -1, 25, 1) { }; os = new FileOutputStream("Relatorio.pdf"); PdfWriter.getInstance((com.itextpdf.text.Document) doc, os); doc.open(); Image img = Image.getInstance("images.jpg"); img.setAlignment(Element.ALIGN_CENTER); doc.add(img); PdfPTable TB1, TB2, TB3, TB4; TB1 = new PdfPTable(2); TB2 = new PdfPTable(3); TB3 = new PdfPTable(4); TB4 = new PdfPTable(5); PdfPCell T1, T2, T3, T4, T5; T1 = new PdfPCell(new Paragraph("\nCADASTRO DE MUSICAS\n")); T1.setColspan(2); TB1.addCell(T1); T2 = new PdfPCell(new Paragraph("\nGENEROS\n")); T2.setColspan(2); TB1.addCell(T2); ResultSet res, res1, res2, res3; res = ConecBanco.relatorioGenero(); if (res != null) { try { while (res.next()) { TB1.addCell("ID: " + res.getString("id")); TB1.addCell("NOME: " + res.getString("nomeGE")); } doc.add(TB1); } catch (SQLException e) { System.out.println("Problema para exibir registros!"); } } else { System.out.println("A pesquisa no retornou nenhum registro!"); } T3 = new PdfPCell(new Paragraph("\nARTISTAS\n")); T3.setColspan(3); TB2.addCell(T3); res1 = ConecBanco.relatorioArtista(); if (res1 != null) { try { while (res1.next()) { TB2.addCell("ID: " + res1.getString("id")); TB2.addCell("NOME: " + res1.getString("nomeAR")); TB2.addCell("GENERO ID: " + res1.getString("genero_id")); } doc.add(TB2); } catch (SQLException e) { System.out.println("Problema para exibir registros!"); } } else { System.out.println("A pesquisa no retornou nenhum registro!"); } T4 = new PdfPCell(new Paragraph("\nALBUM\n")); T4.setColspan(4); TB3.addCell(T4); res2 = ConecBanco.relatorioAlbum(); if (res2 != null) { try { while (res2.next()) { TB3.addCell("ID: " + res2.getString("id")); TB3.addCell("NOME: " + res2.getString("nomeAL")); TB3.addCell("ANO: " + res2.getString("ano")); TB3.addCell("ARTISTA ID: " + res2.getString("artista_id")); } doc.add(TB3); } catch (SQLException e) { System.out.println("Problema para exibir registros!"); } } else { System.out.println("A pesquisa no retornou nenhum registro!"); } T5 = new PdfPCell(new Paragraph("\nMUSICA\n")); T5.setColspan(5); TB4.addCell(T5); res3 = ConecBanco.relatorioMusica(); if (res3 != null) { try { while (res3.next()) { TB4.addCell("ID: " + res3.getString("id")); TB4.addCell("NOME: " + res3.getString("nome")); TB4.addCell("NOTA: " + res3.getString("nota")); TB4.addCell("DURAO: " + res3.getString("duracao")); TB4.addCell("ALBUM ID: " + res3.getString("album_id")); } doc.add(TB4); } catch (SQLException e) { System.out.println("Problema para exibir registros!"); } } else { System.out.println("A pesquisa no retornou nenhum registro!"); } } finally { if (doc != null) { doc.close(); } if (os != null) { os.close(); } } break; case 5: System.out.println("SAINDO..."); break; default: System.out.println("OPO INVALIDA!"); } } while (opc != 5); }
From source file:cis_690_report.DynamicReporter.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed JFileChooser chooser = new JFileChooser(); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile() != null) { File3 = chooser.getSelectedFile().getAbsolutePath(); }//from w w w . j a va2 s. c o m 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); Font bfBold25 = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.BOLD); //file path docWriter = PdfWriter.getInstance(doc, new FileOutputStream(File3)); //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(bfBold25); 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); //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); DynamicReporter re; re = new DynamicReporter(); 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; 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(Reporter.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex); } finally { if (doc != null) { //close the document doc.close(); } if (docWriter != null) { //close the writer docWriter.close(); } } } // TODO add your handling code here: }
From source file:cis_690_report.DynamicReporter.java
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed // 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();//w w w . j a va 2 s . c o m window.setVisible(true); String Path; Path = "C:/Users/Shubh Chopra/Documents/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); //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); DynamicReporter re; re = new DynamicReporter(); 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; 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(Reporter.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Reporter.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:cis_690_report.DynamicReporter.java
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed // 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();//www . java 2s . c om window.setVisible(true); String Path; Path = "C:/Users/Shubh Chopra/Documents/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); //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); DynamicReporter re; re = new DynamicReporter(); 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; 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(Reporter.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Reporter.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); }