List of usage examples for com.itextpdf.text Font Font
public Font(final FontFamily family, final float size)
From source file:com.thelinh.gui.PreviewExam.java
/** * Creates new form PreviewExam// w w w .j av a 2 s . c om */ public PreviewExam(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); this.superParent = null; try { timesBold_25 = new Font( BaseFont.createFont("resources/fonts/vuTimesBold.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 25); timesBold_15 = new Font( BaseFont.createFont("resources/fonts/vuTimesBold.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 15); times_15 = new Font( BaseFont.createFont("resources/fonts/vuTimes.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 15); times_13 = new Font( BaseFont.createFont("resources/fonts/vuTimes.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 13); } catch (DocumentException | IOException ex) { Logger.getLogger(PreviewExam.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.VanLesh.macsv10.macs.Models.Pdf.java
License:GNU General Public License
private static void addContent(Document doc, Calculation calc) { try {//from ww w . j a v a2 s . c o m //special font so we can render greek characters BaseFont bfComic = BaseFont.createFont("/system/fonts/DroidSansFallback.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font font1 = new Font(bfComic, 12); Font tgfont, tipfont; if (calc.getRollover() > calc.getDrag()) { tipfont = redFont; tgfont = smallBold; } else { tipfont = smallBold; tgfont = redFont; } Anchor anchor = new Anchor("Site", subFont); anchor.setName("Site Parameters"); Paragraph identifier = new Paragraph("Calculation ID: " + calc.getTitle(), font1); Paragraph engineer = new Paragraph("Engineer: " + calc.getEngineerName(), font1); Paragraph jobsite = new Paragraph("Jobsite: " + calc.getJobSite(), font1); Paragraph latitude = new Paragraph("Latitude: " + calc.getLatitude(), font1); Paragraph longitude = new Paragraph("Longitude: " + calc.getLongitude(), font1); Anchor vehicleAnchor = new Anchor("Vehicle", subFont); vehicleAnchor.setName("Vehicle"); Paragraph vehicleclass = new Paragraph("Vehicle Class: " + calc.getVehicle().getVehicleClass(), font1); Paragraph vehicletype = new Paragraph("Vehicle Type: " + calc.getVehicle().getVehicleType(), font1); Paragraph vehicleweight = new Paragraph("Wv: " + calc.getVehicle().getWv(), font1); Paragraph vehicletracklength = new Paragraph("Tl: " + calc.getVehicle().getTrackL(), font1); Paragraph vehicletrackwidth = new Paragraph("Tw: " + calc.getVehicle().getTrackW(), font1); Paragraph vehiclebladewidth = new Paragraph("Wb: " + calc.getVehicle().getBladeW(), font1); Anchor soilAnchor = new Anchor("Soil", subFont); soilAnchor.setName("Soil"); Paragraph soiltype = new Paragraph("Soil Type: " + calc.getSoil().getName(), font1); Paragraph soilunitweight = new Paragraph("\u03B3: " + calc.getSoil().getunitW(), font1); Paragraph soilfrictionangle = new Paragraph("\u03A6: " + calc.getSoil().getfrictA(), font1); Paragraph soilcohesion = new Paragraph("c: " + calc.getSoil().getC(), font1); Anchor measurementsAnchor = new Anchor("Measurements", subFont); anchor.setName("Measurements"); Paragraph beta = new Paragraph("\u03B2: " + calc.getBeta(), font1); Paragraph theta = new Paragraph("\u03B8: " + calc.getTheta(), font1); Paragraph Ha = new Paragraph("Ha: " + calc.getHa(), font1); Paragraph La = new Paragraph("La: " + calc.getLa(), font1); Paragraph Db = new Paragraph("Db: " + calc.getD_b(), font1); Anchor resultsAnchor = new Anchor("Results", subFont); int drag = (int) calc.getDrag(); int roll = (int) calc.getRollover(); Paragraph Tg = new Paragraph("Anchor cap Sliding : " + drag, tgfont); Paragraph tipover = new Paragraph("Anchor cap Overturning: " + roll, tipfont); doc.add(anchor); doc.add(identifier); doc.add(engineer); doc.add(jobsite); doc.add(latitude); doc.add(longitude); doc.add(vehicleAnchor); doc.add(vehicleclass); doc.add(vehicletype); doc.add(vehicleweight); doc.add(vehicletracklength); doc.add(vehicletrackwidth); doc.add(vehiclebladewidth); doc.add(soilAnchor); doc.add(soiltype); doc.add(soilunitweight); doc.add(soilfrictionangle); doc.add(soilcohesion); doc.add(measurementsAnchor); doc.add(beta); doc.add(theta); doc.add(Ha); doc.add(La); doc.add(Db); doc.add(resultsAnchor); doc.add(Tg); doc.add(tipover); Log.e("addingcontent", "complete"); } catch (Exception e) { Font font1 = new Font(Font.FontFamily.HELVETICA, 24, Font.NORMAL, BaseColor.BLACK); } }
From source file:com.vectorprint.report.itext.ItextHelper.java
License:Open Source License
public static float getTextWidth(String text, BaseFont bf, float size) { return getTextWidth(new Chunk(text, new Font(bf, size))); }
From source file:com.vectorprint.report.itext.ItextHelper.java
License:Open Source License
public static float getTextHeight(String text, BaseFont bf, float size) { return getTextHeight(new Chunk(text, new Font(bf, size))); }
From source file:controlador.generadorticket.GenerarpdfticketVE.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// ww w. j a v a 2s . c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8");// Forzar a usar codificacin UTF-8 iso-8859-1 String Encabezado = (request.getParameter("encabezado")); String Encabezado1 = (request.getParameter("encabezado1")); String Encabezado2 = (request.getParameter("encabezado2")); String total = (request.getParameter("total")); String Tipo[] = request.getParameterValues("tipo"); String Costo[] = request.getParameterValues("costo"); String Observacion[] = request.getParameterValues("observacion"); String Fecha = (request.getParameter("Fecha")); String Municipio = (request.getParameter("Municipio")); String Cliente = (request.getParameter("Cliente")); String Estado = (request.getParameter("Estado")); String Direccion = (request.getParameter("Direccion")); String Localidad = (request.getParameter("Localidad")); String Venta = (request.getParameter("Id_venta")); Font fuente = new Font(Font.FontFamily.COURIER, 10); Paragraph P = new Paragraph(); Chunk c = new Chunk(); P.setAlignment(Element.ALIGN_CENTER); try { FileOutputStream Archivo = new FileOutputStream("/home/rcortes/Ejemplo.pdf"); Document doc = new Document(); PdfWriter.getInstance(doc, Archivo); doc.open(); doc.add(new Paragraph(Encabezado)); doc.add(new Paragraph(Encabezado1)); doc.add(new Paragraph(Encabezado2)); PdfPTable tabla1 = new PdfPTable(3); doc.add(new Paragraph(" ")); doc.add(new Paragraph("Venta: " + Venta)); doc.add(new Paragraph("Cliente: " + Cliente)); doc.add(new Paragraph("Estado: " + Estado)); doc.add(new Paragraph("Municipio: " + Municipio)); doc.add(new Paragraph("Localidad: " + Localidad)); doc.add(new Paragraph("Direccin: " + Direccion)); doc.add(new Paragraph(" ")); tabla1.addCell("Tipo"); tabla1.addCell("Monto"); tabla1.addCell("Observacin"); for (int i = 0; i < Tipo.length; i++) { tabla1.addCell(Tipo[i]); tabla1.addCell(Costo[i]); tabla1.addCell(Observacion[i]); } doc.add(tabla1); doc.add(new Paragraph(" ")); doc.add(new Paragraph("Total: " + total)); doc.close(); System.out.println("Se creo pdf\n"); } catch (DocumentException e) { System.out.println(e); } }
From source file:de.aidger.utils.pdf.ActivityReportConverter.java
License:Open Source License
/** * Writes the logos and the address of the institute. *//*from w w w.j a v a2 s.com*/ private void writeLogo() { try { Font generatedByFont = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 8); Image aidger = Image.getInstance(getClass().getResource("/de/aidger/res/pdf/AidgerLogo.png")); aidger.scaleAbsolute(80.0f, 20.0f); PdfPTable table = new PdfPTable(2); table.setTotalWidth(reader.getPageSize(1).getRight()); PdfPCell cell = new PdfPCell(new Phrase(_("Generated by: "), generatedByFont)); cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); table.addCell(cell); cell = new PdfPCell(Image.getInstance(aidger)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); table.addCell(cell); table.writeSelectedRows(0, -1, 0, 25, contentByte); } catch (BadElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:de.aidger.utils.pdf.ActivityReportConverter.java
License:Open Source License
/** * Creates the table of employments.//w w w .j a v a2s.com */ private void createTable() { try { Font tableTitleFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10); String[] tableTitles = { "Zeitraum", "Veranstaltung", "Umfang" }; PdfPTable contentTable = new PdfPTable(1); PdfPTable titleTable = new PdfPTable(new float[] { 0.2f, 0.6f, 0.2f }); /* * Create the titles of the table entries. */ for (int i = 0; i < tableTitles.length; i++) { PdfPCell cell = new PdfPCell(new Phrase(tableTitles[i], tableTitleFont)); titleTable.addCell(cell); } PdfPCell cell = new PdfPCell(titleTable); cell.setPaddingTop(10.0f); cell.setPaddingBottom(2.0f); cell.setBorder(0); contentTable.addCell(cell); cell = new PdfPCell(addRows()); cell.setBorder(0); contentTable.addCell(cell); float xPos = 60, yPos = 500, width = reader.getPageSize(1).getWidth() - 120f; if (form.getFieldPositions("TableField") != null) { FieldPosition position = form.getFieldPositions("TableField").get(0); xPos = position.position.getLeft(); yPos = position.position.getTop(); width = position.position.getWidth(); } contentTable.setTotalWidth(width); contentTable.writeSelectedRows(0, -1, xPos, yPos, contentByte); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:de.aidger.utils.pdf.ActivityReportConverter.java
License:Open Source License
/** * Adds the rows of employments to the table. *//*from w w w . j a v a2 s. co m*/ private PdfPTable addRows() { PdfPTable contentTable = new PdfPTable(new float[] { 0.2f, 0.6f, 0.2f }); try { Font tableContentFont = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 9); for (String[] row : tableRows) { for (int i = 0; i < row.length; i++) { PdfPCell cell = new PdfPCell(new Phrase(row[i], tableContentFont)); cell.setPaddingBottom(5); contentTable.addCell(cell); } } } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return contentTable; }
From source file:de.aidger.utils.pdf.BalanceReportConverter.java
License:Open Source License
/** * Writes a semester table and adds the groups of that semester to it. * /*from ww w . j a va 2s .c o m*/ * @param semester * The name of the semester to be added. */ @SuppressWarnings("unchecked") private void createSemester(String semester) { balanceReportGroups = new ArrayList<ArrayList>(); try { Font semesterTitleFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 13); Font semesterNameFont = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 13); PdfPTable finalSemesterTable = new PdfPTable(1); PdfPTable semesterTitleTable = new PdfPTable(new float[] { 0.2f, 0.8f }); PdfPCell semesterCell = new PdfPCell(new Phrase(_("Semester"), semesterTitleFont)); semesterCell.setBorder(0); semesterTitleTable.addCell(semesterCell); semesterCell = new PdfPCell(new Phrase(semester, semesterNameFont)); semesterCell.setBorder(0); semesterTitleTable.addCell(semesterCell); semesterCell = new PdfPCell(semesterTitleTable); semesterCell.setBorder(0); semesterCell.setPaddingTop(7.0f); finalSemesterTable.addCell(semesterCell); PdfPTable contentTable = new PdfPTable(1); /* * As long as there are groups for this Balance report, create new * group tables. */ List<Course> courses = null; if (semester != null) { courses = (new Course()).getCoursesBySemester(semester); } else { courses = new ArrayList<Course>(); List<Course> unsortedCourses = new Course().getAll(); for (Course course : unsortedCourses) { if (course.getSemester() == null) { courses.add(new Course(course)); } } } List<Course> filteredCourses = balanceHelper.filterCourses(courses, filters); for (Course course : filteredCourses) { PdfPTable groupTable = null; if (balanceReportGroups.isEmpty()) { groupTable = createGroup(course); } else { boolean foundGroup = false; for (int i = 0; i <= balanceReportGroups.size() - 1; i++) { if (((ArrayList) balanceReportGroups.get(i)).get(1).equals(course.getGroup())) { foundGroup = true; break; } } if (!foundGroup) { groupTable = createGroup(course); } } } for (int i = 0; i <= balanceReportGroups.size() - 1; i++) { PdfPCell cell = new PdfPCell((PdfPTable) ((ArrayList) balanceReportGroups.get(i)).get(0)); cell.setBorder(0); cell.setPaddingBottom(8.0f); contentTable.addCell(cell); } PdfPCell contentCell = new PdfPCell(contentTable); contentCell.setPaddingLeft(10.0f); contentCell.setBorder(1); finalSemesterTable.addCell(contentCell); finalSemesterTable.setKeepTogether(true); document.add(finalSemesterTable); } catch (Exception e) { Logger.error(e.getMessage()); } }
From source file:de.aidger.utils.pdf.BalanceReportConverter.java
License:Open Source License
/** * Creates a row with the data of one course and returns it. * //w ww. j a va2 s . c o m * @param course * The course of which the data shall be written to a row. * @return The row as a PdfPCell */ private PdfPCell addRow(BalanceCourse balanceCourse, float[] columnwidths, ArrayList<Integer> costUnits) { PdfPTable groupContentTable = new PdfPTable(columnwidths); ArrayList<Object> rowObjectVector = new ArrayList<Object>(); Font tableContentFont; try { tableContentFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 9); for (int i = 0; i < 6; i++) { rowObjectVector.add((balanceCourse).getCourseObject()[i]); } sums.set(4, (Double) sums.get(4) + (Double) rowObjectVector.get(4)); sums.set(5, (Double) sums.get(5) + (Double) rowObjectVector.get(5)); int i = 0; for (Integer costUnit : costUnits) { boolean foundCostUnit = false; for (BudgetCost budgetCost : balanceCourse.getBudgetCosts()) { int budgetCostId = budgetCost.getId(); /* * Set the budget cost of the cost unit to the one * specified. */ if (budgetCostId == costUnit) { rowObjectVector.add(budgetCost.getValue()); foundCostUnit = true; } } if (!foundCostUnit) { rowObjectVector.add(0.0); } if (sums.size() < rowObjectVector.size()) { sums.add(rowObjectVector.get(rowObjectVector.size() - 1)); } else { sums.set(rowObjectVector.size() - 1, (Double) sums.get(rowObjectVector.size() - 1) + (Double) rowObjectVector.get(rowObjectVector.size() - 1)); } } for (Object courseObject : rowObjectVector.toArray()) { PdfPCell cell = null; if (courseObject.getClass().equals(Double.class)) { /* * Round to the configured precision. */ int decimalPlace = Integer.parseInt(Runtime.getInstance().getOption("rounding", "2")); double rounded = new BigDecimal((Double) courseObject) .setScale(decimalPlace, BigDecimal.ROUND_HALF_EVEN).doubleValue(); cell = new PdfPCell( new Phrase(new BigDecimal(rounded).setScale(2, BigDecimal.ROUND_HALF_EVEN).toString(), tableContentFont)); } else { cell = new PdfPCell(new Phrase(courseObject.toString(), tableContentFont)); } if (i != 0) { cell.setBorder(4 + Rectangle.BOTTOM); } else { cell.setBorder(0 + Rectangle.BOTTOM); i++; } cell.setPaddingBottom(5); groupContentTable.addCell(cell); } PdfPCell cell = new PdfPCell(groupContentTable); cell.setBorder(0); return cell; } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }