List of usage examples for com.itextpdf.text Image scaleToFit
public void scaleToFit(final float fitWidth, final float fitHeight)
From source file:adams.gui.print.PDFWriter.java
License:Open Source License
/** * generates the actual output./* ww w . ja v a 2s. com*/ * * @throws Exception if something goes wrong */ @Override public void generateOutput() throws Exception { BufferedImage bi; Document doc; Image image; float scale; FileOutputStream fos; // render image bi = createBufferedImage(); // generate PDF scale = (float) m_ImageScale; doc = new Document(); fos = new FileOutputStream(getFile().getAbsoluteFile()); PdfWriter.getInstance(doc, fos); doc.open(); image = Image.getInstance(Toolkit.getDefaultToolkit().createImage(bi.getSource()), null); if (m_ImageRotation != 0) { image.setRotationDegrees(m_ImageRotation); image.rotate(); } image.scaleToFit(doc.getPageSize().getWidth() * scale, doc.getPageSize().getHeight() * scale); doc.add(image); doc.close(); FileUtils.closeQuietly(fos); }
From source file:app.logica.gestores.GestorPDF.java
License:Open Source License
/** * Mtodo para crear un PDF a partir de una pantalla. */*from ww w. ja v a 2s. c om*/ * @param pantallaAPDF * pantalla que se imprimir en PDF * @return PDF de una captura de la pantalla pasada */ private PDF generarPDF(Node pantallaAPDF) throws Exception { //Se imprime la pantalla en una imagen new Scene((Parent) pantallaAPDF); WritableImage image = pantallaAPDF.snapshot(new SnapshotParameters(), null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", baos); byte[] imageInByte = baos.toByteArray(); baos.flush(); baos.close(); //Se carga la imagen en un PDF Image imagen = Image.getInstance(imageInByte); Document document = new Document(); ByteArrayOutputStream pdfbaos = new ByteArrayOutputStream(); PdfWriter escritor = PdfWriter.getInstance(document, pdfbaos); document.open(); imagen.setAbsolutePosition(0, 0); imagen.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight()); document.add(imagen); document.close(); //Se obtiene el archivo PDF byte[] pdfBytes = pdfbaos.toByteArray(); pdfbaos.flush(); escritor.close(); pdfbaos.close(); //Se genera un objeto PDF return (PDF) new PDF().setArchivo(pdfBytes); }
From source file:app.logica.gestores.GestorPDF.java
License:Open Source License
/** * Mtodo para crear un PDF a partir de varias pantalla. *// ww w . j ava 2 s . c o m * @param pantallaAPDF * pantalla que se imprimir en PDF * @return PDF de una captura de la pantalla pasada */ private PDF generarPDF(ArrayList<Node> pantallasAPDF) throws Exception { Document document = new Document(); ByteArrayOutputStream pdfbaos = new ByteArrayOutputStream(); PdfWriter escritor = PdfWriter.getInstance(document, pdfbaos); document.open(); for (Node pantalla : pantallasAPDF) { new Scene((Parent) pantalla); WritableImage image = pantalla.snapshot(new SnapshotParameters(), null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", baos); byte[] imageInByte = baos.toByteArray(); baos.flush(); baos.close(); Image imagen = Image.getInstance(imageInByte); imagen.setAbsolutePosition(0, 0); imagen.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight()); document.add(imagen); document.newPage(); } document.close(); byte[] pdfBytes = pdfbaos.toByteArray(); pdfbaos.flush(); escritor.close(); pdfbaos.close(); return (PDF) new PDF().setArchivo(pdfBytes); }
From source file:be.kcbj.placemat.Placemat.java
License:Open Source License
private PdfPCell generateCell(Sponsor sponsor, float cellHeight) throws IOException, BadElementException { int numLines = 0; Paragraph p = new Paragraph(); if (sponsor.image != null) { Image image = Image.getInstance(SponsorManager.getImageUrl(sponsor.image)); if (sponsor.imageWidth != 0) { image.scaleToFit(sponsor.imageWidth, 1000); } else if (sponsor.imageHeight != 0) { image.scaleToFit(1000, sponsor.imageHeight); }/*from ww w .j a va 2s . c om*/ Chunk imageChunk = new Chunk(image, 0, 0, true); p.add(imageChunk); } if (sponsor.twoColumns) { StringBuilder sb = new StringBuilder(); if (sponsor.name != null) { sb.append(sponsor.name); } if (sponsor.name2 != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.name2); } if (sponsor.address != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.address); } if (sponsor.address2 != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.address2); } p.add(Chunk.NEWLINE); p.add(new Chunk(sb.toString(), new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))); numLines++; } else { if (sponsor.twoRows && sponsor.image != null) { p.add(Chunk.NEWLINE); } if (sponsor.name != null) { p.add(generateFittedChunk(sponsor.name, Font.BOLD)); numLines++; } if (sponsor.name2 != null) { p.add(Chunk.NEWLINE); p.add(generateFittedChunk(sponsor.name2, Font.BOLD)); numLines++; } if (sponsor.address != null) { p.add(new Chunk("\n\n", new Font(Font.FontFamily.HELVETICA, 2, Font.NORMAL))); p.add(new Chunk(sponsor.address, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); numLines++; } if (sponsor.address2 != null) { p.add(Chunk.NEWLINE); p.add(new Chunk(sponsor.address2, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); numLines++; } } p.setPaddingTop(0); p.setSpacingBefore(0); p.setAlignment(Element.ALIGN_CENTER); p.setMultipliedLeading(numLines <= 3 ? 1.3f : 1.1f); PdfPCell cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setFixedHeight(cellHeight); if (sponsor.twoColumns) { cell.setColspan(2); } if (sponsor.twoRows) { cell.setRowspan(2); if (sponsor.image == null) { p.setMultipliedLeading(p.getMultipliedLeading() * 1.5f); } } cell.setBorder(PdfPCell.NO_BORDER); cell.setCellEvent(CELL_EVENT); cell.setPaddingBottom(4); cell.addElement(p); if (sponsor.isTodo()) { cell.setBackgroundColor(BaseColor.ORANGE); } return cell; }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
/** * createPdf es una funcin estatica que funciona como plantilla para generar * reportes dinamicos, segn la necesidad del usuario. * @param path La direccin del archivo donde se guardar el pdf * @param titulo El Ttulo que llevar el pdf * @param encabezado Un texto que se mostrar bajo el ttulo * @param tabla La tabla de resultados que mostrar el pdf */// w w w. ja v a 2s.c o m static public void createPdf(String path, String titulo, String encabezado, PdfPTable tabla) { Document document = new Document(); // step 2 try { PdfWriter.getInstance(document, new FileOutputStream(path)); Font myFontTitle = new Font(); myFontTitle.setFamily("Arial"); myFontTitle.setStyle(Font.BOLD); myFontTitle.setSize(14); Font Univallef = new Font(); Univallef.setColor(BaseColor.RED); Univallef.setFamily("Arial"); Univallef.setSize(18); Image header = Image .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png")); header.setAlignment(Image.ALIGN_CENTER); header.scaleToFit(50, 75); Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef); Univalle.setAlignment(Paragraph.ALIGN_CENTER); Paragraph pTitulo = new Paragraph(titulo, myFontTitle); pTitulo.setAlignment(Paragraph.ALIGN_CENTER); Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle); biblioteca.setAlignment(Paragraph.ALIGN_CENTER); Paragraph developers = new Paragraph( "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle); developers.setAlignment(Paragraph.ALIGN_CENTER); Paragraph Fecha = new Paragraph("Fecha y Hora del Reporte: " + fecha, myFontTitle); document.open(); // step 4 document.add(header); document.add(new Paragraph("\r\n")); document.add(Univalle); document.add(new Paragraph("\r\n")); document.add(pTitulo); document.add(new Paragraph("\r\n")); document.add(biblioteca); document.add(new Paragraph("\r\n")); document.add(developers); document.add(new Paragraph("\r\n")); document.add(Fecha); document.add(new Paragraph("\r\n")); document.add(new Paragraph(encabezado + (tabla.getRows().size() - 1))); document.add(new Paragraph("\r\n")); document.add(tabla); // step 5 document.close(); } catch (DocumentException de) { System.err.println(de); } catch (IOException ioex) { System.err.println(ioex); } }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
static public void createArrayListPdf(String path, String titulo, String encabezado, ArrayList<PdfPTable> tablas) { Document document = new Document(); ArrayList<String> NombreTablas = new DaoReportesEstadisticas().getNombreTablas(); //step 2/*from w w w . j a va 2s . c o m*/ try { PdfWriter.getInstance(document, new FileOutputStream(path)); Font myFontTitle = new Font(); myFontTitle.setFamily("Arial"); myFontTitle.setStyle(Font.BOLD); myFontTitle.setSize(12); Font Univallef = new Font(); Univallef.setColor(BaseColor.RED); Univallef.setFamily("Arial"); Univallef.setSize(18); Image header = Image .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png")); header.setAlignment(Image.ALIGN_CENTER); header.scaleToFit(50, 75); Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef); Univalle.setAlignment(Paragraph.ALIGN_CENTER); Paragraph pTitulo = new Paragraph(titulo, myFontTitle); pTitulo.setAlignment(Paragraph.ALIGN_CENTER); Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle); biblioteca.setAlignment(Paragraph.ALIGN_CENTER); Paragraph developers = new Paragraph( "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle); developers.setAlignment(Paragraph.ALIGN_CENTER); Paragraph Fecha = new Paragraph("Fecha y Hora de Reporte: " + fecha, myFontTitle); document.open(); // step 4 document.add(header); document.add(new Paragraph("\r\n")); document.add(Univalle); document.add(new Paragraph("\r\n")); document.add(pTitulo); document.add(new Paragraph("\r\n")); document.add(biblioteca); document.add(new Paragraph("\r\n")); document.add(developers); document.add(new Paragraph("\r\n")); document.add(Fecha); document.add(new Paragraph("\r\n")); for (int i = 0; i < tablas.size(); i++) { document.add(new Paragraph(NombreTablas.get(i))); document.add(new Paragraph(encabezado + (tablas.get(i).getRows().size() - 1))); document.add(new Paragraph("\r\n")); document.add(tablas.get(i)); } // step 5 document.close(); } catch (DocumentException de) { System.err.println(de); } catch (IOException ioex) { System.err.println(ioex); } }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
static public void createDinamicPdf(String path, String titulo, String encabezado, ArrayList<Element> contenido) { Document document = new Document(); //step 2/*from www . j a v a 2 s . com*/ try { PdfWriter.getInstance(document, new FileOutputStream(path)); Font myFontTitle = new Font(); myFontTitle.setFamily("Arial"); myFontTitle.setStyle(Font.BOLD); myFontTitle.setSize(12); Font Univallef = new Font(); Univallef.setColor(BaseColor.RED); Univallef.setFamily("Arial"); Univallef.setSize(18); Image header = Image .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png")); header.setAlignment(Image.ALIGN_CENTER); header.scaleToFit(50, 75); Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef); Univalle.setAlignment(Paragraph.ALIGN_CENTER); Paragraph pTitulo = new Paragraph(titulo, myFontTitle); pTitulo.setAlignment(Paragraph.ALIGN_CENTER); Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle); biblioteca.setAlignment(Paragraph.ALIGN_CENTER); Paragraph developers = new Paragraph( "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle); developers.setAlignment(Paragraph.ALIGN_CENTER); Paragraph Fecha = new Paragraph("Fecha y Hora de Reporte: " + fecha, myFontTitle); //Paragraph Introduccion = new Paragraph("Reporte de usuarios registrados"); document.open(); // step 4 document.add(header); document.add(new Paragraph("\r\n")); document.add(Univalle); document.add(new Paragraph("\r\n")); document.add(pTitulo); document.add(new Paragraph("\r\n")); document.add(biblioteca); document.add(new Paragraph("\r\n")); document.add(developers); document.add(new Paragraph("\r\n")); document.add(Fecha); document.add(new Paragraph("\r\n")); // document.add(Introduccion); document.add(new Paragraph("\r\n")); for (int i = 0; i < contenido.size(); i++) { document.add(contenido.get(i).getClass().equals(new PdfPTable(2).getClass()) ? (PdfPTable) contenido.get(i) : contenido.get(i)); } // step 5 document.close(); } catch (DocumentException de) { System.err.println(de); } catch (IOException ioex) { System.err.println(ioex); } }
From source file:BUS.ExportPDF.java
public boolean ExportTKDT(ArrayList<String[]> al, String year) throws BadElementException, IOException, DocumentException { // To i tng ti liu Document document = new Document(PageSize.A4, 50, 50, 50, 50); File fontFile = new File("src\\Helper\\arialuni.ttf"); BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font f = new Font(unicode, 12); try {/*from w w w .jav a2 s .co m*/ // To i tng PdfWriter Date d = new Date(); SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss"); String s = "ThongKeDoanhThu_" + ft.format(d) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(s)); // M file thc hin ghi document.open(); Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); document.add(title1); //Logo Group Image image1 = Image.getInstance("src\\Library\\cao.png"); document.add(new Paragraph()); document.add(image1); //Nam can bao cao Paragraph title2 = new Paragraph(year, FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); document.add(title2); //Chart Image image = Image.getInstance("src\\Library\\barChart3D.jpeg"); image.scaleToFit(500, 400); document.add(new Paragraph()); document.add(image); //Data PdfPTable t = new PdfPTable(4); t.setSpacingBefore(25); t.setSpacingAfter(25); PdfPCell c1 = new PdfPCell(new Phrase("Thng", f)); t.addCell(c1); PdfPCell c2 = new PdfPCell(new Phrase("Doanh thu", f)); t.addCell(c2); PdfPCell c3 = new PdfPCell(new Phrase("Ti?n n", f)); t.addCell(c3); PdfPCell c4 = new PdfPCell(new Phrase("Li", f)); t.addCell(c4); for (int i = 0; i < al.size(); i++) { Object ob = i + 1; t.addCell(ob.toString()); t.addCell(al.get(i)[0]); t.addCell(al.get(i)[1]); t.addCell(al.get(i)[2]); } document.add(t); // ?ng File document.close(); System.out.println("Write file succes!"); } catch (FileNotFoundException | DocumentException e) { return false; } return true; }
From source file:BUS.ExportPDF.java
public boolean ExportTKSP(ArrayList<String[]> al, String year) throws BadElementException, IOException, DocumentException { // To i tng ti liu Document document = new Document(PageSize.A4, 50, 50, 50, 50); File fontFile = new File("src\\Helper\\arialuni.ttf"); BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font f = new Font(unicode, 12); try {// www .java 2 s . co m // To i tng PdfWriter Date d = new Date(); SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss"); String s = "ThongKeSanPham_" + ft.format(d) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(s)); // M file thc hin ghi document.open(); Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); document.add(title1); //Logo Group Image image1 = Image.getInstance("src\\Library\\cao.png"); document.add(new Paragraph()); document.add(image1); //Nm c bo co Paragraph title2 = new Paragraph(year, FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); document.add(title2); //Chart Image image = Image.getInstance("src\\Library\\pie_Chart3D.jpeg"); image.scaleToFit(500, 400); document.add(new Paragraph()); document.add(image); //Data PdfPTable t = new PdfPTable(5); t.setSpacingBefore(25); t.setSpacingAfter(25); PdfPCell c1 = new PdfPCell(new Phrase("STT")); t.addCell(c1); PdfPCell c2 = new PdfPCell(new Phrase("M sn phm", f)); t.addCell(c2); PdfPCell c3 = new PdfPCell(new Phrase("Tn sn phm", f)); t.addCell(c3); PdfPCell c4 = new PdfPCell(new Phrase("Tng s lng", f)); t.addCell(c4); PdfPCell c5 = new PdfPCell(new Phrase("Tng ti?n", f)); t.addCell(c5); for (int i = 0; i < al.size(); i++) { Object ob = i + 1; t.addCell(ob.toString()); t.addCell(al.get(i)[0]); t.addCell(new Phrase(al.get(i)[1], f)); t.addCell(al.get(i)[2]); t.addCell(al.get(i)[3]); } document.add(t); // ?ng File document.close(); System.out.println("Write file succes!"); } catch (FileNotFoundException | DocumentException e) { return false; } return true; }
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 .ja va 2 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: }