List of usage examples for com.itextpdf.text Font Font
public Font(final FontFamily family, final float size, final int style)
From source file:opticalworkshopmonitoringsystem.GrindingDivisionView.java
License:Open Source License
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed try {/* ww w. j a v a 2 s. com*/ Document document = new Document(); JFileChooser fc = new JFileChooser(); fc.showOpenDialog(null); PdfWriter.getInstance(document, new FileOutputStream(fc.getSelectedFile().getAbsolutePath())); document.open(); Font courierFontItalic = new Font(Font.FontFamily.COURIER, 10, Font.ITALIC); Font courierFontUnderline = new Font(Font.FontFamily.COURIER, 10, Font.UNDERLINE); Font tr = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); Font timesRomanUnderline = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.UNDERLINE); Font helvetica = new Font(Font.FontFamily.HELVETICA, 14, Font.UNDERLINE); document.add(new Paragraph( " Grinding Division ", timesRomanUnderline)); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel2.getText(), tr)); document.add( new Chunk(" " + jTextField2.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel3.getText(), tr)); document.add( new Chunk(" " + jTextField3.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel1.getText(), tr)); document.add( new Chunk(" " + jTextField1.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel4.getText(), tr)); document.add( new Chunk(" " + jTextField4.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel5.getText(), tr)); document.add( new Chunk(" " + jTextField23.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel6.getText(), tr)); document.add( new Chunk(" " + jTextField24.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel7.getText(), tr)); document.add( new Chunk(" " + jTextField25.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel8.getText(), tr)); document.add( new Chunk(" " + jTextField26.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(" Slicing Operation ", helvetica)); document.add(new Paragraph(jLabel9.getText(), tr)); document.add( new Chunk(" " + jTextField27.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel11.getText(), tr)); document.add( new Chunk(" " + jTextField28.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel10.getText(), tr)); document.add( new Chunk(" " + jTextField29.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel23.getText(), tr)); document.add( new Chunk(" " + jTextField30.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel24.getText(), tr)); document.add( new Chunk(" " + jTextField31.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(" Trepening Operation ", helvetica)); document.add(new Paragraph(jLabel15.getText(), tr)); document.add( new Chunk(" " + jTextField19.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel17.getText(), tr)); document.add( new Chunk(" " + jTextField20.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel28.getText(), tr)); document.add( new Chunk(" " + jTextField21.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel29.getText(), tr)); document.add( new Chunk(" " + jTextField22.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel30.getText(), tr)); document.add( new Chunk(" " + jTextField32.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(" Curve Generation Operation ", helvetica)); document.add(new Paragraph(jLabel12.getText(), tr)); document.add( new Chunk(" " + jTextField5.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel13.getText(), tr)); document.add( new Chunk(" " + jTextField6.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel14.getText(), tr)); document.add( new Chunk(" " + jTextField7.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel25.getText(), tr)); document.add( new Chunk(" " + jTextField16.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel26.getText(), tr)); document.add( new Chunk(" " + jTextField17.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel27.getText(), tr)); document.add( new Chunk(" " + jTextField18.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add( new Paragraph(" Grinding and Smoothing Operation ", helvetica)); document.add(new Paragraph(jLabel38.getText(), tr)); document.add( new Chunk(" " + jTextField43.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel39.getText(), tr)); document.add( new Chunk(" " + jTextField44.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel40.getText(), tr)); document.add( new Chunk(" " + jTextField45.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel41.getText(), tr)); document.add( new Chunk(" " + jTextField46.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel42.getText(), tr)); document.add( new Chunk(" " + jTextField47.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel43.getText(), tr)); document.add( new Chunk(" " + jTextField48.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel44.getText(), tr)); document.add( new Chunk(" " + jTextField49.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(" Inspection Details ", helvetica)); document.add(new Chunk(" Specified")); document.add(new Chunk(" Measured")); document.add(new Paragraph(jLabel16.getText(), tr)); document.add( new Chunk(" " + jTextField8.getText())); document.add( new Chunk(" " + jTextField12.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel18.getText(), tr)); document.add( new Chunk(" " + jTextField9.getText())); document.add( new Chunk(" " + jTextField15.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel19.getText(), tr)); document.add( new Chunk(" " + jTextField10.getText())); document.add( new Chunk(" " + jTextField13.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(" Angles ", helvetica)); document.add(new Paragraph(jLabel32.getText(), tr)); document.add( new Chunk(" " + jTextField11.getText())); document.add( new Chunk(" " + jTextField14.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel33.getText(), tr)); document.add( new Chunk(" " + jTextField33.getText())); document.add( new Chunk(" " + jTextField38.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel34.getText(), tr)); document.add( new Chunk(" " + jTextField34.getText())); document.add( new Chunk(" " + jTextField39.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel35.getText(), tr)); document.add( new Chunk(" " + jTextField35.getText())); document.add( new Chunk(" " + jTextField40.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel36.getText(), tr)); document.add( new Chunk(" " + jTextField37.getText())); document.add( new Chunk(" " + jTextField41.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel37.getText(), tr)); document.add( new Chunk(" " + jTextField36.getText())); document.add( new Chunk(" " + jTextField42.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel45.getText(), tr)); document.add( new Chunk(" " + jTextField50.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel46.getText(), tr)); document.add( new Chunk(" " + jTextField51.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel47.getText(), tr)); document.add( new Chunk(" " + jTextField52.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel48.getText(), tr)); document.add( new Chunk(" " + jTextField53.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph( " ")); document.add(new Paragraph( " ")); document.add(new Paragraph( " ")); document.add(new Paragraph( " ")); document.add(new Paragraph( " Prepared by Checked by Approved by ")); document.close(); JOptionPane.showMessageDialog(null, "report generated successfully"); } catch (DocumentException ex) { Logger.getLogger(GrindingDivisionView.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(GrindingDivisionView.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:opticalworkshopmonitoringsystem.PolishingDivisionView.java
License:Open Source License
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed try {/*ww w . j ava 2s.com*/ // TODO add your handling code here: Document document = new Document(); JFileChooser fc = new JFileChooser(); fc.showOpenDialog(null); PdfWriter.getInstance(document, new FileOutputStream(fc.getSelectedFile().getAbsolutePath())); document.open(); Font courierFontItalic = new Font(Font.FontFamily.COURIER, 10, Font.ITALIC); Font courierFontUnderline = new Font(Font.FontFamily.COURIER, 10, Font.UNDERLINE); Font tr = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); Font timesRomanUnderline = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.UNDERLINE); Font helvetica = new Font(Font.FontFamily.HELVETICA, 14, Font.UNDERLINE); document.add(new Paragraph( " Polishing Division ", timesRomanUnderline)); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel1.getText(), tr)); document.add( new Chunk(" " + jTextField1.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel2.getText(), tr)); document.add( new Chunk(" " + jTextField2.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel3.getText(), tr)); document.add( new Chunk(" " + jTextField3.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(" Polisher Details ", helvetica)); document.add(new Paragraph(jLabel4.getText(), tr)); document.add( new Chunk(" " + jTextField4.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel5.getText(), tr)); document.add( new Chunk(" " + jTextField5.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel6.getText(), tr)); document.add( new Chunk(" " + jTextField6.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel7.getText(), tr)); document.add( new Chunk(" " + jTextField7.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel8.getText(), tr)); document.add( new Chunk(" " + jTextField8.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel9.getText(), tr)); document.add( new Chunk(" " + jTextField9.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add( new Paragraph(" Polishing Material(Processing) ", helvetica)); document.add(new Paragraph(jLabel10.getText(), tr)); document.add( new Chunk(" " + jTextField10.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel11.getText(), tr)); document.add( new Chunk(" " + jTextField11.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel12.getText(), tr)); document.add( new Chunk(" " + jTextField12.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel13.getText(), tr)); document.add( new Chunk(" " + jTextField13.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel14.getText(), tr)); document.add( new Chunk(" " + jTextField14.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(" Polishing Iteration ", helvetica)); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel17.getText(), tr)); document.add( new Chunk(" " + jTextField18.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel18.getText(), tr)); document.add( new Chunk(" " + jTextField19.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(" Final Inspection ", helvetica)); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel23.getText(), tr)); document.add( new Chunk(" " + jTextField23.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel24.getText(), tr)); document.add( new Chunk(" " + jTextField24.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel25.getText(), tr)); document.add( new Chunk(" " + jTextField25.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel26.getText(), tr)); document.add( new Chunk(" " + jTextField26.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph(jLabel27.getText(), tr)); document.add( new Chunk(" " + jTextField27.getText())); document.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); document.add(new Paragraph( " ")); document.add(new Paragraph( " ")); document.add(new Paragraph( " ")); document.add(new Paragraph( " ")); document.add(new Paragraph( " Prepared by Checked by Approved by ")); document.close(); JOptionPane.showMessageDialog(null, "report generated successfully"); } catch (DocumentException ex) { Logger.getLogger(PolishingDivisionView.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(PolishingDivisionView.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.alfresco.repo.content.transform.ITextPDFWorker.java
License:Apache License
/** * Set new font size./*from ww w.j av a 2 s .c o m*/ * * @param size * is the size - default is {@value #DEFAULT_FONT_SIZE} */ public void setFontSize(int size) { textFont = new Font(BASE_FONT, size, Font.NORMAL); }
From source file:org.fatec.lpbd.projetocurriculo.controller.CurriculoHelper.java
public static Paragraph simpleText(String text) { Font f = new Font(FontFamily.COURIER, 10, Font.NORMAL); Paragraph p = new Paragraph(text, f); p.setAlignment(Element.PARAGRAPH); return p;//from ww w. ja va 2s. c o m }
From source file:org.fatec.lpbd.projetocurriculo.controller.CurriculoHelper.java
public static Paragraph titleString(String text) { Font f = new Font(FontFamily.COURIER, 20, Font.BOLD); Paragraph p = new Paragraph(text, f); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(20);/*from www . j a va 2 s .com*/ return p; }
From source file:org.fatec.lpbd.projetocurriculo.controller.CurriculoHelper.java
public static Paragraph separatorText(String text) { Font f = new Font(FontFamily.COURIER, 12, Font.BOLD); Paragraph p = new Paragraph(text, f); // p.setSpacingBefore(5); p.setSpacingAfter(-15);//from w w w .jav a 2 s .com return p; }
From source file:org.fossa.rolp.util.PdfStreamSource.java
License:Open Source License
public PdfStreamSource(FossaApplication app, LebData lebData, LebCreator lebCreator) throws DocumentException, IOException, PdfFormatierungsException { this.lebData = lebData; this.lebCreator = lebCreator; BaseFont fontNormal = BaseFont.createFont( app.getContext().getBaseDirectory() + Config.getRelativeNormalFontPath(), BaseFont.CP1252, BaseFont.EMBEDDED);/* w w w.j av a 2 s. co m*/ BaseFont fontBold = BaseFont.createFont( app.getContext().getBaseDirectory() + Config.getRelativeBoldFontPath(), BaseFont.CP1252, BaseFont.EMBEDDED); BaseFont fontThin = BaseFont.createFont( app.getContext().getBaseDirectory() + Config.getRelativeThinFontPath(), BaseFont.CP1252, BaseFont.EMBEDDED); lernentwicklungsberichtUeberschriftFont = new Font(fontThin, 22, Font.NORMAL); standardTextFont = new Font(fontNormal, KlassenstufenUtils.getLebFontSize(lebData.getKlassenname()), Font.NORMAL); standardTextBoldFont = new Font(fontBold, KlassenstufenUtils.getLebFontSize(lebData.getKlassenname()), Font.NORMAL); headerFont = new Font(fontNormal, 12, Font.NORMAL); footerFont = new Font(fontNormal, 10, Font.NORMAL); fusszeilenFont = new Font(fontNormal, 8, Font.NORMAL); zeilenabstandsfaktor = KlassenstufenUtils.getLebZeilenabstandAsFactor(lebData.getKlassenname()); document = null; try { document = new Document(PageSize.A4, 100, 90, topMargin, bottomMargin); PdfWriter writer = PdfWriter.getInstance(document, outputStream); LebPageHelper event = new LebPageHelper(lebData, Image.getInstance(app.getContext().getBaseDirectory() + Config.getRelativeLogoPath()), fusszeilenFont); writer.setPageEvent(event); document.open(); addContent(writer); addFooter(lebData, writer); } finally { if (document != null) { document.close(); } } }
From source file:org.h819.commons.file.MyPDFUtils.java
/** * ? iTextAsian.jar//from w w w . ja v a 2 s. c o m * itext 5.5.9 ??? * * @return */ @Deprecated private static Font getChineseFont() { Font fontChinese = null; try { BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); fontChinese = new Font(bfChinese, 12, Font.NORMAL); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } return fontChinese; }
From source file:org.jaqpot.core.service.data.ReportService.java
public void report2PDF(Report report, OutputStream os) { Document document = new Document(); document.setPageSize(PageSize.A4);//from www .j a v a 2 s. c om document.setMargins(50, 45, 80, 40); document.setMarginMirroring(false); try { PdfWriter writer = PdfWriter.getInstance(document, os); TableHeader event = new TableHeader(); writer.setPageEvent(event); } catch (DocumentException ex) { throw new InternalServerErrorException(ex); } document.open(); /** setup fonts for pdf */ Font ffont = new Font(Font.FontFamily.UNDEFINED, 9, Font.ITALIC); Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC); Font paragraphFontBold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL); Font tableFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); /** print link to jaqpot*/ Chunk chunk = new Chunk( "This report has been automatically created by the JaqpotQuatro report service. Click here to navigate to our official webpage", ffont); chunk.setAnchor("http://www.jaqpot.org"); Paragraph paragraph = new Paragraph(chunk); paragraph.add(Chunk.NEWLINE); Chapter chapter = new Chapter(paragraph, 1); chapter.setNumberDepth(0); /** get title */ String title = null; if (report.getMeta() != null && report.getMeta().getTitles() != null && !report.getMeta().getTitles().isEmpty()) title = report.getMeta().getTitles().iterator().next(); /** print title aligned centered in page */ if (title == null) title = "Report"; chunk = new Chunk(title, chapterFont); paragraph = new Paragraph(chunk); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.add(Chunk.NEWLINE); paragraph.add(Chunk.NEWLINE); chapter.add(paragraph); /** report Description */ if (report.getMeta() != null && report.getMeta().getDescriptions() != null && !report.getMeta().getDescriptions().isEmpty() && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) { paragraph = new Paragraph(); paragraph.add(new Chunk("Description: ", paragraphFontBold)); paragraph.add(new Chunk(report.getMeta().getDescriptions().toString().replaceAll(":http", ": http"), paragraphFont)); chapter.add(paragraph); chapter.add(Chunk.NEWLINE); } /** report model, algorithm and/or dataset id */ if (report.getMeta() != null && report.getMeta().getHasSources() != null && !report.getMeta().getHasSources().isEmpty() && !report.getMeta().getDescriptions().isEmpty() && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) { Iterator<String> sources = report.getMeta().getHasSources().iterator(); sources.forEachRemaining(o -> { if (o != null) { String[] source = o.split("/"); if (source[source.length - 2].trim().equals("model") || source[source.length - 2].trim().equals("algorithm") || source[source.length - 2].trim().equals("dataset")) { Paragraph paragraph1 = new Paragraph(); paragraph1.add(new Chunk(source[source.length - 2].substring(0, 1).toUpperCase() + source[source.length - 2].substring(1) + ": ", paragraphFontBold)); paragraph1.add(new Chunk(source[source.length - 1], paragraphFont)); chapter.add(paragraph1); chapter.add(Chunk.NEWLINE); } } }); } /** report single calculations */ report.getSingleCalculations().forEach((key, value) -> { Paragraph paragraph1 = new Paragraph(); paragraph1 = new Paragraph(); paragraph1.add(new Chunk(key + ": ", paragraphFontBold)); paragraph1.add(new Chunk(value.toString().trim().replaceAll(" +", " "), paragraphFont)); chapter.add(paragraph1); chapter.add(Chunk.NEWLINE); }); /** report date of completion */ if (report.getMeta() != null && report.getMeta().getDate() != null) { Paragraph paragraph1 = new Paragraph(); paragraph1.add(new Chunk("Procedure completed on: ", paragraphFontBold)); paragraph1.add(new Chunk(report.getMeta().getDate().toString(), paragraphFont)); chapter.add(paragraph1); chapter.add(Chunk.NEWLINE); } try { document.add(chapter); } catch (DocumentException ex) { throw new InternalServerErrorException(ex); } Integer chapterNumber = 0; /** report all_data */ for (Entry<String, ArrayCalculation> entry : report.getArrayCalculations().entrySet()) { String label = entry.getKey(); ArrayCalculation ac = entry.getValue(); PdfPTable table = new PdfPTable(ac.getColNames().size() + 1); for (Entry<String, List<Object>> row : ac.getValues().entrySet()) { try { XMLWorkerHelper.getInstance().parseXHtml(w -> { if (w instanceof WritableElement) { List<Element> elements = ((WritableElement) w).elements(); for (Element element : elements) { PdfPCell pdfCell = new PdfPCell(); pdfCell.addElement(element); table.addCell(pdfCell); } } }, new StringReader(row.getKey())); } catch (IOException e) { e.printStackTrace(); } for (Object o : row.getValue()) { table.addCell(o.toString()); } table.completeRow(); } try { Chunk tableChunk = new Chunk(label, tableFont); Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber); tableChapter.add(Chunk.NEWLINE); tableChapter.add(table); document.newPage(); document.add(tableChapter); } catch (DocumentException ex) { throw new InternalServerErrorException(ex); } } /** report plots */ for (Entry<String, String> entry : report.getFigures().entrySet()) { try { byte[] valueDecoded = Base64.decodeBase64(entry.getValue()); Image l = Image.getInstance(valueDecoded); document.newPage(); //image starts at the half's half of pdf page l.setAbsolutePosition(0, (document.getPageSize().getHeight() / 2 / 2)); l.scaleToFit(document.getPageSize()); Chunk tableChunk = new Chunk(entry.getKey(), tableFont); Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber); tableChapter.add(l); document.add(tableChapter); } catch (IOException | DocumentException e) { e.printStackTrace(); } } document.close(); }
From source file:org.me.modelos.PDFHelper.java
public void tablaToPdf(JTable jTable, File pdfNewFile, String title) { try {// www . j a v a2 s . co m Font subCategoryFont = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD); Document document = new Document(PageSize.LETTER.rotate()); PdfWriter writer = null; try { writer = PdfWriter.getInstance(document, new FileOutputStream(pdfNewFile)); } catch (FileNotFoundException fileNotFoundException) { Message.showErrorMessage(fileNotFoundException.getMessage()); } writer.setBoxSize("art", new Rectangle(150, 10, 700, 580)); writer.setPageEvent(new HeaderFooterPageEvent()); document.open(); document.addTitle(title); document.addSubject("Reporte"); document.addKeywords("reportes, gestion, pdf"); document.addAuthor("Gestion de Proyectos de software"); document.addCreator("gestion de proyectos"); Paragraph parrafo = new Paragraph(title, subCategoryFont); PdfPTable table = new PdfPTable(jTable.getColumnCount()); table.setWidthPercentage(100); PdfPCell columnHeader; for (int column = 0; column < jTable.getColumnCount(); column++) { Font font = new Font(Font.FontFamily.HELVETICA); font.setColor(255, 255, 255); columnHeader = new PdfPCell(new Phrase(jTable.getColumnName(column), font)); columnHeader.setHorizontalAlignment(Element.ALIGN_LEFT); columnHeader.setBackgroundColor(new BaseColor(96, 125, 139)); table.addCell(columnHeader); } table.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255)); table.setHeaderRows(1); BaseColor verdad = new BaseColor(255, 255, 255); BaseColor falso = new BaseColor(214, 230, 244); boolean bandera = false; for (int row = 0; row < jTable.getRowCount(); row++) { for (int column = 0; column < jTable.getColumnCount(); column++) { if (bandera) { table.getDefaultCell().setBackgroundColor(verdad); } else { table.getDefaultCell().setBackgroundColor(falso); } table.addCell(jTable.getValueAt(row, column).toString()); bandera = !bandera; } } parrafo.add(table); document.add(parrafo); document.close(); //JOptionPane.showMessageDialog(null, "Se ha creado el pdf en " + pdfNewFile.getPath(), // "RESULTADO", JOptionPane.INFORMATION_MESSAGE); } catch (DocumentException documentException) { System.out.println("Se ha producido un error " + documentException); JOptionPane.showMessageDialog(null, "Se ha producido un error" + documentException, "ERROR", JOptionPane.ERROR_MESSAGE); } }