List of usage examples for com.itextpdf.text FontFactory getFont
public static Font getFont(final String fontname)
Font
-object. From source file:com.vectorprint.report.itext.debug.DebugHelper.java
License:Open Source License
public static BaseFont debugFont(PdfContentByte canvas, EnhancedMap settings) { BaseFont bf = FontFactory.getFont(FontFactory.HELVETICA).getBaseFont(); canvas.setFontAndSize(bf, 8);//from w w w.j a v a 2 s . co m canvas.setColorFill( itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR))); canvas.setColorStroke( itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR))); return bf; }
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// ww w . 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:com.vectorprint.report.itext.style.parameters.BaseFontWrapper.java
License:Open Source License
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject();/*from w w w .j av a 2 s.co m*/ Font f = FontFactory.getFont(fontName); if (f.getBaseFont() == null) { throw new VectorPrintRuntimeException("No basefont for: " + fontName); } baseFont = f.getBaseFont(); }
From source file:com.vectorprint.report.itext.style.parameters.binding.ReportBindingHelper.java
License:Open Source License
@Override public <T> T convert(String value, Class<T> clazz) { if (BaseFontWrapper.class.equals(clazz)) { Font f = FontFactory.getFont(value); if (f.getBaseFont() == null) { throw new VectorPrintRuntimeException("No basefont for: " + value); }// w ww .ja v a 2s . c o m return (T) new BaseFontWrapper(f.getBaseFont()); } else { return super.convert(value, clazz); } }
From source file:com.vectorprint.report.itext.style.stylers.Text.java
License:Open Source License
@Override protected void draw(PdfContentByte canvas, float x, float y, float width, float height, String genericTag) throws VectorPrintException { BaseFont bf = FontFactory.getFont(getAlias()).getBaseFont(); if (bf == null) { throw new VectorPrintRuntimeException( "font " + getAlias() + " does not have a basefont, check your fontloading"); }//w w w. j a va 2s . com canvas.setFontAndSize(bf, getSize()); canvas.setColorFill(itextHelper.fromColor((isDrawShadow()) ? getShadowColor() : getColor())); canvas.setColorStroke(itextHelper.fromColor((isDrawShadow()) ? getShadowColor() : getColor())); canvas.beginText(); canvas.showTextAligned(Element.ALIGN_LEFT, getData(), x, y, getRotate()); canvas.endText(); if (getSettings().getBooleanProperty(Boolean.FALSE, ReportConstants.DEBUG)) { DebugHelper.styleLink(canvas, getStyleClass(), " (styling)", x, y, getSettings(), getLayerManager()); } }
From source file:containers.Receipt.java
public void printReceiptTogether() { try {//from ww w . j a v a2s . c om String path = System.getProperty("user.home") + File.separator + "Documents"; OutputStream file = new FileOutputStream(new File(path + "\\receiptTogether.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER)); Image img = Image.getInstance(new URL(link)); img.scalePercent(56f); p.add(img); p.add(header); p.add(new Date().toString()); footerTogether(); p.add(body); p.add(footer); document.add(p); document.close(); file.close(); header = ""; body = ""; footer = ""; } catch (Exception e) { e.printStackTrace(); } }
From source file:containers.Receipt.java
public void printReceiptSeparate() { try {//from w w w.ja v a2 s . co m String path = System.getProperty("user.home") + File.separator + "Documents"; OutputStream file = new FileOutputStream(new File(path + "\\receipt" + orderNumber + ".pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER)); Image img = Image.getInstance(new URL(link)); img.scalePercent(56f); p.add(img); p.add(header); p.add(new Date().toString()); footerSeparate(); p.add(body); p.add(footer); document.add(p); document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:containers.Receipt.java
public void printSentOrder(Order order) { ArrayList<Item> items = order.getItems(); orderNumber = Integer.toString(order.getOrderNo()); drink = "Bar Order\n"; drink += "\nOrder #: " + orderNumber + "\n"; drink += "Server : " + empName + "\n\n"; drink += String.format("%-15s\n", "Item"); drink += String.format("%-15s\n", "----"); food = "Kitchen Order\n"; food += "\nOrder #: " + orderNumber + "\n"; food += "Server : " + empName + "\n\n"; food += String.format("%-15s\n", "Item"); food += String.format("%-15s\n", "----"); for (Item item : items) { if (item.getItemType().equalsIgnoreCase("drink")) { drink += String.format("%-15s", item.getItemName()); drink += "\n"; drinkCount++;/*from ww w . ja v a2 s . c o m*/ } else { food += String.format("%-15s", item.getItemName()); food += "\n"; foodCount++; } } if (drinkCount > 0) { try { String path = System.getProperty("user.home") + File.separator + "Documents"; OutputStream file = new FileOutputStream(new File(path + "\\barOrder" + orderNumber + ".pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER)); p.add(new Date().toString() + "\n"); p.add(drink); document.add(p); document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } } if (foodCount > 0) { try { String path = System.getProperty("user.home") + File.separator + "Documents"; OutputStream file = new FileOutputStream(new File(path + "\\kitchenOrder" + orderNumber + ".pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER)); p.add(new Date().toString() + "\n"); p.add(food); document.add(p); document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } } drink = ""; food = ""; }
From source file:containers.Report.java
public void generateHours(String hours, String from, String to) { try {/*from w w w . j ava 2 s . com*/ String path = System.getProperty("user.home") + File.separator + "Documents"; OutputStream file = new FileOutputStream(new File(path + "\\EmployeeReport.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER)); Image img = Image.getInstance(new URL(link)); img.scalePercent(56f); p.add(img); ehours = hours; body = String.format("%-15s - %2s\n", "Employee Number", empno); body += String.format("%-15s - %5s\n", "First Name", fname); body += String.format("%-15s - %1s\n", "Last Name", lname); body += String.format("%-15s - %9s\n", "Address", address); body += String.format("%-15s - %9s\n", "Phone Number", phone); body += String.format("%-15s - %3s\n", "Position", position); body += String.format("%-15s - %8s\n", "Total Hours", ehours); body += "\n"; from = from.substring(0, 10); to = to.substring(0, 10); p.add(new Date().toString()); p.add("\n\nEmployee Report\n\n"); p.add("Reporting Date: \n" + from + " - " + to + "\n\n"); p.add(body); document.add(p); document.close(); file.close(); body = ""; } catch (Exception e) { e.printStackTrace(); } }
From source file:containers.Report.java
public void generateOrderByDate(ArrayList<String> entry, String from, String to) { try {/*w w w. ja v a 2 s . c om*/ String path = System.getProperty("user.home") + File.separator + "Documents"; OutputStream file = new FileOutputStream(new File(path + "\\DateOrderReport.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER)); Image img = Image.getInstance(new URL(link)); img.scalePercent(56f); p.add(img); body2 = String.format("%5s - %5s - %5s - %5s\n", "Order No.", "Order Total", "Payment Type", "Order Date"); double counter = 0; for (int i = 0; i < entry.size(); i += 4) { body2 += String.format("%-10s %8s %15s %24s\n", entry.get(i), entry.get(i + 1), entry.get(i + 2), entry.get(i + 3).substring(0, 19)); counter += Double.parseDouble(entry.get(i + 1)); } body2 += "\n\nTotal for all orders: $" + counter; from = from.substring(0, 10); to = to.substring(0, 10); p.add(new Date().toString()); p.add("\n\nOrder by Date Report\n"); p.add("Reporting Date: \n" + from + " - " + to + "\n\n"); p.add(body2); document.add(p); document.close(); file.close(); body2 = ""; } catch (Exception e) { e.printStackTrace(); } }