List of usage examples for com.itextpdf.text FontFactory COURIER
String COURIER
To view the source code for com.itextpdf.text FontFactory COURIER.
Click Source Link
From source file:app.App.java
private void setLink(int pageId, PdfStamper stamper) throws ClassNotFoundException, IOException { // load the sqlite-JDBC driver using the current class loader Class.forName("org.sqlite.JDBC"); Connection connection = null; try {/*from ww w.j a v a 2 s . c o m*/ // create a database connection connection = DriverManager.getConnection("jdbc:sqlite:" + DATABASE); Statement statement = connection.createStatement(); statement.setQueryTimeout(30); // set timeout to 30 sec. ResultSet rs = statement.executeQuery( "select * from page_annotations " + "where annotation_type = 'goto' and page_id = " + pageId); float spendX = 0; float spendY = 0; float coordX = 0; float coordY = 0; int pageDest = 0; Rectangle rect; PdfAnnotation annotation; while (rs.next()) { spendX = rs.getFloat("pdf_width"); spendY = rs.getFloat("pdf_height"); coordX = rs.getFloat("pdf_x");// + rs.getFloat("pdf_width"); coordY = rs.getFloat("pdf_y"); pageDest = rs.getInt("annotation_target"); Font font = FontFactory.getFont(FontFactory.COURIER, 10, Font.UNDERLINE); // Blue font.setColor(0, 0, 255); Chunk chunk = new Chunk("GOTO", font); Anchor anchor = new Anchor(chunk); ColumnText.showTextAligned(stamper.getUnderContent(pageId), Element.ALIGN_LEFT, anchor, coordX + spendX, coordY, 0); rect = new Rectangle(coordX, coordY, spendX, spendY); annotation = PdfAnnotation.createLink(stamper.getWriter(), rect, PdfAnnotation.HIGHLIGHT_INVERT, new PdfAction("#" + pageDest)); stamper.addAnnotation(annotation, pageId); } } catch (SQLException e) { // if the error message is "out of memory", // it probably means no database file is found System.err.println(e.getMessage()); } finally { try { if (connection != null) connection.close(); } catch (SQLException e) { // connection close failed. System.err.println(e); } } }
From source file:com.base2.kagura.core.ExportHandler.java
License:Apache License
/** * Takes the output and transforms it into a PDF file. * @param out Output stream.// w w w .j a v a2 s. c o m * @param rows Rows of data from reporting-core * @param columns Columns to list on report */ public void generatePdf(OutputStream out, List<Map<String, Object>> rows, List<ColumnDef> columns) { try { Document document = new Document(); PdfWriter.getInstance(document, out); if (columns == null) { if (rows.size() > 0) return; columns = new ArrayList<ColumnDef>(CollectionUtils.collect(rows.get(0).keySet(), new Transformer() { @Override public Object transform(final Object input) { return new ColumnDef() { { setName((String) input); } }; } })); } if (columns.size() > 14) document.setPageSize(PageSize.A1); else if (columns.size() > 10) document.setPageSize(PageSize.A2); else if (columns.size() > 7) document.setPageSize(PageSize.A3); else document.setPageSize(PageSize.A4); document.open(); Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.NORMAL, BaseColor.BLACK); Font headerFont = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD, BaseColor.BLACK); int size = columns.size(); PdfPTable table = new PdfPTable(size); for (ColumnDef column : columns) { PdfPCell c1 = new PdfPCell(new Phrase(column.getName(), headerFont)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); if (rows != null) for (Map<String, Object> row : rows) { for (ColumnDef column : columns) { table.addCell(new Phrase(String.valueOf(row.get(column.getName())), font)); } } document.add(table); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.centurylink.mdw.pdf.PdfExportHelper.java
License:Apache License
public PdfExportHelper(Project project) { super(project); chapterFont = FontFactory.getFont(FontFactory.TIMES, 20, Font.BOLD); sectionFont = FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLD); subSectionFont = FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD); normalFont = FontFactory.getFont(FontFactory.TIMES, 12, Font.NORMAL); boldFont = FontFactory.getFont(FontFactory.TIMES, 12, Font.BOLD); fixedWidthFont = FontFactory.getFont(FontFactory.COURIER, 11, Font.NORMAL); }
From source file:com.vectorprint.report.itext.BaseReportGenerator.java
License:Open Source License
/** * This method will be called when exceptions are thrown in * {@link #createReportBody(com.itextpdf.text.Document, com.vectorprint.report.data.ReportDataHolder)} or * {@link DebugHelper#appendDebugInfo(com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document, com.vectorprint.configuration.EnhancedMap, com.vectorprint.report.itext.style.StylerFactory) }, * it will rethrow the exception by default. If you provide a property {@link ReportConstants#STOPONERROR} with a * value of false, the stacktrace will be appended to the pdf and the document and writer will be closed. * * @param ex//from w w w . ja va 2 s . c o m * @param output the pdf document output stream * @return 1 */ protected int handleException(Exception ex, OutputStream output) throws VectorPrintRuntimeException { if (getSettings().getBooleanProperty(Boolean.TRUE, ReportConstants.STOPONERROR)) { throw (ex instanceof VectorPrintRuntimeException) ? (VectorPrintRuntimeException) ex : new VectorPrintRuntimeException("failed to generate the report: " + ex.getMessage(), ex); } else { PrintStream out; ByteArrayOutputStream bo = new ByteArrayOutputStream(); out = new PrintStream(bo); ex.printStackTrace(out); out.close(); try { Font f = FontFactory.getFont(FontFactory.COURIER, 8); f.setColor(itextHelper.fromColor(getSettings().getColorProperty(Color.MAGENTA, "debugcolor"))); String s = getSettings().getProperty(bo.toString(), "renderfault"); eventHelper.setLastPage(writer.getCurrentPageNumber()); document.setPageSize(new Rectangle(ItextHelper.mmToPts(297), ItextHelper.mmToPts(210))); document.setMargins(5, 5, 5, 5); document.newPage(); eventHelper.setFailuresHereAfter(true); document.add( new Chunk("Below you find information that help solving the problems in this report.", f) .setLocalDestination(FAILUREPAGE)); newLine(); document.add(new Paragraph(new Chunk(s, f))); document.newPage(); DebugHelper.appendDebugInfo(writer, document, settings, stylerFactory); } catch (VectorPrintException | DocumentException e) { log.severe("Could not append to PDF:\n" + bo.toString()); log.log(java.util.logging.Level.SEVERE, null, e); } finally { document.close(); writer.close(); } } return ERRORINREPORT; }
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/*w w w. j a v a 2 s . c om*/ */ 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:containers.Receipt.java
public void printReceiptTogether() { try {/* w w w. ja v a2s. com*/ 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 va2 s . c o 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 w w w. ja va2 s .co 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 www.java2 s .c om*/ 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. jav a 2 s. co m 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(); } }