List of usage examples for com.itextpdf.text Font Font
public Font(final FontFamily family)
From source file:com.planning.project.controller.CreatePDF.java
public static PdfPTable createtableMaterial10(List<TbMaterial> tbMaterials10, String getSum) throws DocumentException, Exception { Font font = new Font(BaseFont.createFont("D:/THSarabunNew.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); font.setSize(16);/*from w w w.j a v a 2 s .co m*/ PdfPTable table = new PdfPTable(6); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell = new PdfPCell( new Phrase("3.10 ???", font)); cell.setColspan(6); table.addCell(cell); cell = new PdfPCell(new Phrase(" = " + getSum + " ", font)); cell.setColspan(6); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("??", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); int count = 0; for (TbMaterial items : tbMaterials10) { count++; table.addCell(new PdfPCell(new Phrase(String.valueOf(count), font))); table.addCell(new PdfPCell(new Phrase(items.getMName(), font))); table.addCell(new PdfPCell(new Phrase(items.getMQty(), font))); table.addCell(new PdfPCell(new Phrase(items.getMNub(), font))); table.addCell(new PdfPCell(new Phrase(items.getMPrice(), font))); table.addCell(new PdfPCell(new Phrase(items.getMTotal(), font))); } return table; }
From source file:com.planning.project.controller.CreatePDF.java
public static PdfPTable createtableMaterial11(List<TbMaterial> tbMaterials11, String getSum) throws DocumentException, Exception { Font font = new Font(BaseFont.createFont("D:/THSarabunNew.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); font.setSize(16);//from w w w . j a v a 2 s . c o m PdfPTable table = new PdfPTable(6); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell = new PdfPCell(new Phrase("3.11 ", font)); cell.setColspan(6); table.addCell(cell); cell = new PdfPCell(new Phrase(" = " + getSum + " ", font)); cell.setColspan(6); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("??", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); int count = 0; for (TbMaterial items : tbMaterials11) { count++; table.addCell(new PdfPCell(new Phrase(String.valueOf(count), font))); table.addCell(new PdfPCell(new Phrase(items.getMName(), font))); table.addCell(new PdfPCell(new Phrase(items.getMQty(), font))); table.addCell(new PdfPCell(new Phrase(items.getMNub(), font))); table.addCell(new PdfPCell(new Phrase(items.getMPrice(), font))); table.addCell(new PdfPCell(new Phrase(items.getMTotal(), font))); } return table; }
From source file:com.planning.project.controller.CreatePDF.java
public static PdfPTable createtablePublicutility(List<TbPublicutility> tbPublicutilitys, String getSum) throws DocumentException, Exception { Font font = new Font(BaseFont.createFont("D:/THSarabunNew.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); font.setSize(16);//from w w w .ja va 2 s. c o m PdfPTable table = new PdfPTable(6); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell = new PdfPCell( new Phrase("4.1 ?", font)); cell.setColspan(6); table.addCell(cell); cell = new PdfPCell(new Phrase(" = " + getSum + " ", font)); cell.setColspan(6); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); int count = 0; for (TbPublicutility items : tbPublicutilitys) { count++; table.addCell(new PdfPCell(new Phrase(String.valueOf(count), font))); table.addCell(new PdfPCell(new Phrase(items.getPubEle(), font))); table.addCell(new PdfPCell(new Phrase(items.getPubWater(), font))); table.addCell(new PdfPCell(new Phrase(items.getPubTel(), font))); table.addCell(new PdfPCell(new Phrase(items.getPubEms(), font))); table.addCell(new PdfPCell(new Phrase(items.getPubOther(), font))); table.addCell(new PdfPCell(new Phrase(items.getPubSum(), font))); } return table; }
From source file:com.thelinh.gui.Statistics.java
private void btnExportReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportReportActionPerformed Document document = new Document() { };/*from www . ja v a2s . c om*/ try { JFileChooser jfc = new JFileChooser("Save File"); if (jfc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { // String content = this.txtReport.getText(); jfc.setDialogTitle("Save File"); FileOutputStream fos = new FileOutputStream(jfc.getSelectedFile()); PdfWriter.getInstance(document, fos); // Font rfont = FontFactory.getFont("resources/fonts/vuArial.ttf", IDENTITY_H, true); Font rfont = new Font(BaseFont.createFont("resources/fonts/vuTimesBold.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); document.open(); document.add(new Paragraph( " TRNG ?I HC B?CH KHOA H NI", rfont)); if (k == 1) { document.add(new Paragraph( "\t\t TH?NG K MN HC\n", rfont)); String sqlSubject1 = "SELECT Count(SubjectId) AS subjectAll FROM Subjects"; String sqlSubject2 = "SELECT Subjects.SubjectName AS subjectChap, Count(*) AS subjectNumber FROM Chaps,Subjects WHERE Chaps.SubjectId = Subjects.SubjectId GROUP BY Subjects.SubjectName"; ResultSet rs1 = LoadTable.Display(sqlSubject1); ResultSet rs2 = LoadTable.Display(sqlSubject2); try { if (rs1.next()) { document.add(new Paragraph( "Tng s mn h?c l " + rs1.getInt("subjectAll") + "\n", rfont)); } document.add(new Paragraph("Thng k s chng ca mn h?c: \n\n", rfont)); PdfPTable table = new PdfPTable(2); PdfPCell header1 = new PdfPCell(new Paragraph("Mn h?c", rfont)); PdfPCell header2 = new PdfPCell(new Paragraph("S chng", rfont)); table.addCell(header1); table.addCell(header2); while (rs2.next()) { PdfPCell header3 = new PdfPCell(new Paragraph(rs2.getString("subjectChap"), rfont)); table.addCell(header3); PdfPCell header4 = new PdfPCell(new Paragraph("" + rs2.getInt("subjectNumber"))); table.addCell(header4); } document.add(table); } catch (SQLException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } } else if (k == 2) { try { document.add(new Paragraph( "\t\t TH?NG K CU HI\n", rfont)); String sqlQuestion1 = "SELECT Count(QuestionId) AS questionAll FROM Questions"; String sqlQuestion2 = "SELECT SubjectName AS subjectName, Count(QuestionId) AS questionSubject FROM Questions,Subjects WHERE Subjects.SubjectId = Questions.SubjectId GROUP BY Subjects.SubjectName"; ResultSet rs1 = LoadTable.Display(sqlQuestion1); ResultSet rs2 = LoadTable.Display(sqlQuestion2); if (rs1.next()) { document.add(new Paragraph( "Tng s cu h?i l " + rs1.getInt("questionAll") + "\n", rfont)); } document.add(new Paragraph("Thng k s cu h?i ca mn h?c: \n\n", rfont)); PdfPTable table = new PdfPTable(2); PdfPCell header1 = new PdfPCell(new Paragraph("Mn h?c", rfont)); PdfPCell header2 = new PdfPCell(new Paragraph("S cu h?i", rfont)); table.addCell(header1); table.addCell(header2); while (rs2.next()) { PdfPCell header3 = new PdfPCell(new Paragraph(rs2.getString("subjectName"), rfont)); table.addCell(header3); PdfPCell header4 = new PdfPCell(new Paragraph("" + rs2.getInt("questionSubject"))); table.addCell(header4); } document.add(table); } catch (SQLException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } } else if (k == 3) { try { document.add(new Paragraph( "\t\t TH?NG K NGI DNG\n", rfont)); String sqlUser1 = "SELECT Count(UserId) AS userAll FROM Users"; String sqlUser2 = "SELECT Class AS className, Count(UserId) AS userClass FROM Users GROUP BY Class"; ResultSet rs1 = LoadTable.Display(sqlUser1); ResultSet rs2 = LoadTable.Display(sqlUser2); if (rs1.next()) { document.add(new Paragraph( "Tng s ng?i dng l " + rs1.getInt("userAll") + "\n", rfont)); } document.add(new Paragraph("Thng k s h?c sinh ca lp: \n\n", rfont)); PdfPTable table = new PdfPTable(2); PdfPCell header1 = new PdfPCell(new Paragraph("Lp", rfont)); PdfPCell header2 = new PdfPCell(new Paragraph("S h?c sinh", rfont)); table.addCell(header1); table.addCell(header2); while (rs2.next()) { PdfPCell header3 = new PdfPCell(new Paragraph(rs2.getString("className"), rfont)); table.addCell(header3); PdfPCell header4 = new PdfPCell(new Paragraph("" + rs2.getInt("userClass"))); table.addCell(header4); } document.add(table); } catch (SQLException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } } else if (k == 4) { document.add(new Paragraph( "\t\t TH?NG K KT QU\n", rfont)); String sqlResult1 = "SELECT Count(*) AS resultAll FROM Results"; String sqlResult2 = "SELECT Count(*) AS exam1 FROM Results WHERE Result <= 4"; String sqlResult3 = "SELECT Count(*) AS exam2 FROM Results WHERE Result > 4 AND Result < 6"; String sqlResult4 = "SELECT Count(*) AS exam3 FROM Results WHERE Result >= 6 AND Result < 8"; String sqlResult5 = "SELECT Count(*) AS exam4 FROM Results WHERE Result >= 8"; ResultSet rs1 = LoadTable.Display(sqlResult1); ResultSet rs2 = LoadTable.Display(sqlResult2); ResultSet rs3 = LoadTable.Display(sqlResult3); ResultSet rs4 = LoadTable.Display(sqlResult4); ResultSet rs5 = LoadTable.Display(sqlResult5); if (rs1.next()) { document.add( new Paragraph("Tng s bi thi l " + rs1.getInt("resultAll") + "\n", rfont)); } document.add(new Paragraph("Thng k im thi: \n\n", rfont)); PdfPTable table = new PdfPTable(2); PdfPCell header1 = new PdfPCell(new Paragraph("?im", rfont)); PdfPCell header2 = new PdfPCell(new Paragraph("S bi thi", rfont)); table.addCell(header1); table.addCell(header2); PdfPCell header3 = new PdfPCell(new Paragraph("<= 4")); table.addCell(header3); if (rs2.next()) { PdfPCell header4 = new PdfPCell(new Paragraph(rs2.getInt("exam1"))); table.addCell(header4); } PdfPCell header5 = new PdfPCell(new Paragraph("> 4 v < 6")); table.addCell(header5); if (rs3.next()) { PdfPCell header6 = new PdfPCell(new Paragraph(rs3.getInt("exam2"))); table.addCell(header6); } PdfPCell header7 = new PdfPCell(new Paragraph(">= 6 v < 8")); table.addCell(header7); if (rs4.next()) { PdfPCell header8 = new PdfPCell(new Paragraph(rs4.getInt("exam3"))); table.addCell(header8); } PdfPCell header9 = new PdfPCell(new Paragraph(">= 8")); table.addCell(header9); if (rs5.next()) { PdfPCell header10 = new PdfPCell(new Paragraph(rs5.getInt("exam4"))); table.addCell(header10); } document.add(table); } document.add(new Paragraph( " H Ni, ngy 09 thng 12 nm 2016\n", rfont)); document.add(new Paragraph( " Gio Vin\n", rfont)); document.add(new Paragraph( " " + Controller.getCurrentAdmin().getAdminName() + "\n", rfont)); document.close(); JOptionPane.showMessageDialog(null, "Save success"); } } catch (FileNotFoundException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.vectorprint.report.itext.debug.DebugHelper.java
License:Open Source License
/** * This method will append to the pdf a legend explaining the visual feedback in the pdf, an overview of the styles * used and an overview of the properties used. * * @throws DocumentException//from www.j a va 2 s .c o m */ public static void appendDebugInfo(PdfWriter writer, Document document, EnhancedMap settings, StylerFactory stylerFactory) throws DocumentException, VectorPrintException { PdfContentByte canvas = writer.getDirectContent(); canvas.setFontAndSize(FontFactory.getFont(FontFactory.COURIER).getBaseFont(), 8); canvas.setColorFill( itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR))); canvas.setColorStroke( itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR))); Font f = FontFactory.getFont(FontFactory.COURIER, 8); f.setColor(itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR))); float top = document.getPageSize().getTop(); document.add(new Phrase(new Chunk("table: ", f).setLocalDestination(DEBUGPAGE))); document.add(Chunk.NEWLINE); document.add(new Phrase("cell: ", f)); document.add(Chunk.NEWLINE); document.add(new Phrase("image: ", f)); document.add(Chunk.NEWLINE); document.add(new Phrase("text: ", f)); document.add(Chunk.NEWLINE); document.add(new Phrase("background color is shown in a small rectangle", f)); document.add(Chunk.NEWLINE); canvas.setLineWidth(2); canvas.setLineDash(new float[] { 0.3f, 5 }, 0); float left = document.leftMargin(); canvas.rectangle(left + 80, top - 25, left + 80, 8); canvas.closePathStroke(); canvas.setLineWidth(0.3f); canvas.setLineDash(new float[] { 2, 2 }, 0); canvas.rectangle(left + 80, top - 37, left + 80, 8); canvas.closePathStroke(); canvas.setLineDash(new float[] { 1, 0 }, 0); canvas.rectangle(left + 80, top - 50, left + 80, 8); canvas.closePathStroke(); canvas.setLineDash(new float[] { 0.3f, 5 }, 0); canvas.rectangle(left + 80, top - 63, left + 80, 8); canvas.closePathStroke(); document.add(Chunk.NEWLINE); document.add(new Phrase("fonts available: " + FontFactory.getRegisteredFonts(), f)); document.add(Chunk.NEWLINE); if (settings.getBooleanProperty(false, DEBUG)) { document.add(new Phrase("OVERVIEW OF STYLES FOR THIS REPORT", f)); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); } Font b = new Font(f); b.setStyle("bold"); Set<Map.Entry<String, String>> entrySet = stylerFactory.getStylerSetup().entrySet(); for (Map.Entry<String, String> styleInfo : entrySet) { String key = styleInfo.getKey(); document.add(new Chunk(key, b).setLocalDestination(key)); document.add(new Chunk(": " + styleInfo.getValue(), f)); document.add(Chunk.NEWLINE); document.add(new Phrase(" styling configured by " + key + ": ", f)); for (BaseStyler st : (Collection<BaseStyler>) stylerFactory.getBaseStylersFromCache((key))) { document.add(Chunk.NEWLINE); document.add(new Chunk(" ", f)); document.add(new Chunk(st.getClass().getSimpleName(), DebugHelper.debugFontLink(canvas, settings)) .setLocalGoto(st.getClass().getSimpleName())); document.add(new Chunk(":", f)); document.add(Chunk.NEWLINE); document.add(new Phrase(" non default parameters for " + st.getClass().getSimpleName() + ": " + getParamInfo(st), f)); document.add(Chunk.NEWLINE); if (!st.getConditions().isEmpty()) { document.add(new Phrase(" conditions for this styler: ", f)); } for (StylingCondition sc : (Collection<StylingCondition>) st.getConditions()) { document.add(Chunk.NEWLINE); document.add(new Chunk(" ", f)); document.add( new Chunk(sc.getClass().getSimpleName(), DebugHelper.debugFontLink(canvas, settings)) .setLocalGoto(sc.getClass().getSimpleName())); document.add(Chunk.NEWLINE); document.add(new Phrase(" non default parameters for " + sc.getClass().getSimpleName() + ": " + getParamInfo(sc), f)); } } document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); } document.newPage(); document.add(new Phrase("Properties used for the report", f)); document.add(Chunk.NEWLINE); ByteArrayOutputStream bo = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(bo); settings.listProperties(ps); ps.close(); document.add(new Paragraph(bo.toString(), f)); document.newPage(); try { bo = new ByteArrayOutputStream(); ps = new PrintStream(bo); Help.printHelpHeader(ps); ps.close(); document.add(new Paragraph(bo.toString(), f)); Help.printStylerHelp(document, f); Help.printConditionrHelp(document, f); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) { log.log(Level.SEVERE, null, ex); } }
From source file:de.knurt.heinzelmann.util.itext.TextBlock.java
License:Creative Commons License
private List<Chunk> getChunks(String content) { Font italic = new Font(this.font); italic.setStyle(Font.ITALIC); Font normal = new Font(this.font); normal.setStyle(Font.NORMAL); Font bold = new Font(this.font); bold.setStyle(Font.BOLD);/*from w ww. j a va 2s.c o m*/ Font bolditalic = new Font(this.font); bolditalic.setStyle(Font.BOLDITALIC); Font markfont = null; boolean markModus = false; List<Chunk> result = new ArrayList<Chunk>(); List<Chunk> tmp = new ArrayList<Chunk>(); StringTokenizer tokenizer = new StringTokenizer(content, "\\*", true); while (tokenizer.hasMoreTokens()) { String tok = tokenizer.nextToken(); if (tok.equals("*")) { if (markModus) { if (markfont.getStyle() == Font.ITALIC) { markfont = bold; } else { markfont = bolditalic; } } else { if (markfont == null) { markfont = italic; markModus = true; } else if (markfont.getStyle() == Font.BOLDITALIC) { markfont = bold; } else if (markfont.getStyle() == Font.BOLD) { markfont = italic; } else if (markfont.getStyle() == Font.ITALIC) { markfont = null; } } continue; } if (markfont != null) { tmp.add(new Chunk(tok, markfont)); markModus = false; } else { tmp.add(new Chunk(tok, normal)); } } result.addAll(tmp); return result; }
From source file:fenix.planner.pdf.PDFGenerator.java
License:Open Source License
private void parseAndAddBodyTextLineToParagraph(Paragraph paragraph, String line, Font font) { // TODO add support for additional styles // TODO add better error checking and reporting Font currentFont = new Font(font); StringBuilder sb = new StringBuilder(); for (char c : line.toCharArray()) { if (c == '*') { if (sb.length() > 0) { paragraph.add(new Phrase(sb.toString(), currentFont)); sb = new StringBuilder(); }//from ww w. j a v a2s . co m if (currentFont.isBold()) { currentFont = deriveWithStyle(currentFont, currentFont.getStyle() & ~Font.BOLD); } else { currentFont = deriveWithStyle(currentFont, currentFont.getStyle() | Font.BOLD); } } else if (c == '_') { if (sb.length() > 0) { paragraph.add(new Phrase(sb.toString(), currentFont)); sb = new StringBuilder(); } if (currentFont.isItalic()) { currentFont = deriveWithStyle(currentFont, currentFont.getStyle() & ~Font.ITALIC); } else { currentFont = deriveWithStyle(currentFont, currentFont.getStyle() | Font.ITALIC); } } else { sb.append(c); } } paragraph.add(new Phrase(sb.toString(), currentFont)); }
From source file:fenix.planner.pdf.PDFGenerator.java
License:Open Source License
private static Font deriveWithStyle(Font original, int newStyle) { final Font copy = new Font(original); copy.setStyle(newStyle);//from w w w . j a v a2 s . c o m return copy; }
From source file:fenix.planner.pdf.PDFGenerator.java
License:Open Source License
private static Font changeColor(Font original, BaseColor newColor) { Font copy = new Font(original); copy.setColor(newColor);//from w w w . ja v a2 s . c om return copy; }
From source file:file.PDFWriter.java
License:Open Source License
/** * Set the font styles for the PDF/*ww w.j a va2 s.co m*/ */ private void setFontStyles() { lineFont = new Font(FontFamily.TIMES_ROMAN); lineFontUnderline = new Font(FontFamily.TIMES_ROMAN); errorFont = new Font(FontFamily.TIMES_ROMAN); lineFontBold = new Font(FontFamily.TIMES_ROMAN); errorFontBold = new Font(FontFamily.TIMES_ROMAN); lineFontUnderline.setStyle(Font.UNDERLINE); lineFontBold.setStyle(Font.BOLD); errorFont.setStyle(Font.ITALIC); errorFontBold.setStyle(Font.BOLDITALIC); }