List of usage examples for com.lowagie.text Font setStyle
public void setStyle(String style)
String
containing one of more of the following values: normal, bold, italic, underline, strike. From source file:com.krawler.esp.servlets.ExportMPXServlet.java
License:Open Source License
public void createPDFFile(Connection conn, HttpServletRequest request, HttpServletResponse response) throws ConfigurationException { String projid = request.getParameter("projectid"); try {// ww w . ja v a2 s . com String userid = AuthHandler.getUserid(request); String companyid = AuthHandler.getCompanyid(request); String tasks = projdb.getProjectTasks(conn, projid, userid, companyid, 0, -1, true); ByteArrayOutputStream os = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4); document.setPageSize(PageSize.A4.rotate()); PdfWriter writer = PdfWriter.getInstance(document, os); setHeaderFooter(document, request.getParameter("header")); JSONObject jobj = new JSONObject(request.getParameter("options")); JSONArray jarr = jobj.getJSONArray("data"); ArrayList tabCols = new ArrayList(); ArrayList tabArr = createTables(jarr, tabCols, document);//new ArrayList(); writer.setPageEvent(new EndPage()); HashMap taskIdIndex = new HashMap(); JSONArray taskArr = new com.krawler.utils.json.base.JSONObject(tasks).getJSONArray("data"); for (int c = 0; c < taskArr.length(); c++) { com.krawler.utils.json.base.JSONObject temp = taskArr.getJSONObject(c); taskIdIndex.put(temp.getString("taskid"), temp.getInt("taskindex")); } taskIdIndex.put("0", 0); for (int c = 0; c < taskArr.length(); c++) { com.krawler.utils.json.base.JSONObject temp = taskArr.getJSONObject(c); String pred = ""; if (!StringUtil.isNullOrEmpty(temp.getString("predecessor"))) { String[] p = temp.getString("predecessor").split(","); for (int i = 0; i < p.length; i++) { pred += taskIdIndex.get(p[i]).toString() + ","; } pred = pred.substring(0, (pred.length() - 1)); } String taskResourceNames = projdb.getTaskResourcesNames(conn, temp.getString("taskid"), projid); for (int i = 0; i < tabArr.size(); i++) { int lvl = 0; if (i == 0) { lvl = temp.getInt("level"); } String[] colArr = (String[]) tabCols.get(i); String[] values = getPDFCellOfRec(colArr, temp, pred, taskResourceNames); Font fnt = new Font(); if (temp.getBoolean("isparent")) { fnt.setStyle(Font.BOLD); } else { fnt.setStyle(Font.NORMAL); } addPdfRowToTable(values, (PdfPTable) tabArr.get(i), fnt, lvl); } } document.open(); getCompanyDetails(request); addComponyLogo(document); for (int i = 0; i < tabArr.size(); i++) { PdfPTable temp = (PdfPTable) tabArr.get(i); temp.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); document.add(temp); document.newPage(); } document.close(); os.close(); String fname = request.getParameter("filename"); os.close(); response.setHeader("Content-Disposition", "attachment; filename=\"" + fname + ".pdf\""); response.setContentType("application/octet-stream"); response.setContentLength(os.size()); response.getOutputStream().write(os.toByteArray()); response.getOutputStream().flush(); String type = "[PDF]"; AddToAuditTrail(conn, request, projid, type); conn.commit(); } catch (ServiceException ex) { Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (JSONException e) { Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, e); } catch (SessionExpiredException e) { Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, e); } }
From source file:com.krawler.esp.servlets.ExportMPXServlet.java
License:Open Source License
public static PdfPTable createPdfTable(ArrayList header, ArrayList widths, ArrayList tabCol, Document doc) throws DocumentException { PdfPTable temp = new PdfPTable(header.size()); float[] wid = new float[widths.size()]; String[] cols = new String[header.size()]; for (int i = 0; i < widths.size(); i++) { wid[i] = (float) (Integer.parseInt(widths.get(i).toString())); cols[i] = header.get(i).toString(); }/*from w w w . j a v a 2 s . com*/ temp.setWidthPercentage(wid, doc.getPageSize()); temp.setTotalWidth(100); Font fnt1 = new Font(); fnt1.setStyle(Font.NORMAL); addPdfRowToTable(cols, temp, fnt1, 0); temp.setHeaderRows(1); tabCol.add(cols); return temp; }
From source file:cz.incad.kramerius.pdf.utils.pdf.FontMap.java
License:Open Source License
public FontMap(File fontDirectory) throws DocumentException, IOException { super();//w w w.j av a 2 s .co m this.fontDirectory = fontDirectory; Font logoFont = createGentiumFont(this.fontDirectory); logoFont.setSize(48f); Font normalFont = createGentiumFont(this.fontDirectory); normalFont.setSize(14f); Font strongFont = createGentiumFont(this.fontDirectory); strongFont.setSize(14f); strongFont.setStyle(Font.BOLD); Font header4Font = createGentiumFont(this.fontDirectory); header4Font.setSize(16f); header4Font.setStyle(Font.BOLD); Font smallerFont = createGentiumFont(this.fontDirectory); smallerFont.setSize(12f); Font smallFont = createGentiumFont(this.fontDirectory); smallFont.setSize(10f); this.registerFont(NORMAL_FONT, normalFont); this.registerFont(STRONG_FONT, strongFont); this.registerFont(LOGO_FONT, logoFont); this.registerFont(HEADER4_FONT, header4Font); this.registerFont(SMALLER_FONT, smallerFont); this.registerFont(SMALL_FONT, smallFont); }
From source file:EplanPrinter.RTFWrite.java
License:Open Source License
public String addItem(String comment, String category, String group) throws DocumentException, IOException { if (cg.compareTo(group) != 0) { count = 1;//www.j a v a 2 s . c o m cg = group; cc = category; Font groupContent = new Font(); groupContent.setStyle("bold"); groupContent.setStyle("underline"); groupContent.setSize(12); Paragraph g = new Paragraph(group, groupContent); Font catContent = new Font(); catContent.setSize(12); Paragraph c = new Paragraph(category, catContent); c.setIndentationLeft(30); document.add(g); document.add(c); } else if (cc.compareTo(category) != 0) { count = 1; cc = category; Paragraph c = new Paragraph(category); c.setIndentationLeft(30); document.add(c); } Paragraph p = new Paragraph(); //document.add(p); String test = count + ". " + comment; test = test.replaceAll("<p>", " "); test = test.replaceAll("</p>", " "); if (test.indexOf("<ol>") != -1) { test = test.replaceAll("<ol>", ""); test = test.replaceAll("</ol>", ""); test = test.replaceAll("</li>", "<br />"); int subCount = 1; while (test.indexOf("<li>") != -1) { test = test.replaceFirst("<li>", subCount + ". "); subCount++; } int marker = test.lastIndexOf("<br />"); String sub1 = test.substring(0, marker); String sub2 = test.substring(marker); sub2 = sub2.replaceAll("<br />", ""); test = sub1 + sub2; } if (test.indexOf("<ul>") != -1) { test = test.replaceAll("<ul>", ""); test = test.replaceAll("</ul>", ""); test = test.replaceAll("</li>", "<br />"); int c = 149; char ch = (char) 149; test = test.replaceAll("<li>", "•"); int marker = test.lastIndexOf("<br />"); String sub1 = test.substring(0, marker); String sub2 = test.substring(marker); sub2 = sub2.replaceAll("<br />", ""); test = sub1 + sub2; } StringReader str = new StringReader(test); List<Element> e = HTMLWorker.parseToList(str, null); for (int k = 0; k < e.size(); ++k) { p.add((com.lowagie.text.Element) e.get(k)); } p.setIndentationLeft(40); p.setFirstLineIndent(30); document.add(p); count = count + 1; return ""; }
From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableAnchor.java
License:Open Source License
public void applyStyles(Style style) { this.lastStyleApplied = style; StyleTextProperties textProperties = style.getTextProperties(); if (textProperties != null) { // Font/*from ww w .java 2 s. co m*/ Font font = textProperties.getFont(); if (font != null) { if (!font.isUnderlined()) { font = new Font(font); font.setStyle(font.getStyle() | Font.UNDERLINE); } super.setFont(font); } } }
From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableAnchor.java
License:Open Source License
@SuppressWarnings("unchecked") public Element getElement() { // underline font if not explicitly set ArrayList<Chunk> chunks = getChunks(); for (Chunk chunk : chunks) { Font f = chunk.getFont(); if (f != null && !f.isUnderlined()) { f = new Font(f); f.setStyle(f.getStyle() | Font.UNDERLINE); chunk.setFont(f);/*w w w. j a v a 2s . co m*/ } } return this; }
From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableParagraph.java
License:Open Source License
@SuppressWarnings("unchecked") private void postProcessLineHeightAndBaseline() { // adjust line height and baseline Font font = getMostOftenUsedFont(); if (font == null || font.getBaseFont() == null) { font = this.font; }//ww w . j a va 2 s.c om if (font != null && font.getBaseFont() != null) { // iText and open office computes proportional line height differently // [iText] line height = coefficient * font size // [open office] line height = coefficient * (font ascender + font descender + font extra margin) // we have to increase paragraph line height to generate pdf similar to open office document // this algorithm may be inaccurate if fonts with different multipliers are used in this paragraph float size = font.getSize(); float ascender = font.getBaseFont().getFontDescriptor(BaseFont.AWT_ASCENT, size); float descender = -font.getBaseFont().getFontDescriptor(BaseFont.AWT_DESCENT, size); // negative value float margin = font.getBaseFont().getFontDescriptor(BaseFont.AWT_LEADING, size); float multiplier = (ascender + descender + margin) / size; if (multipliedLeading > 0.0f) { setMultipliedLeading(getMultipliedLeading() * multiplier); } // iText seems to output text with baseline lower than open office // we raise all paragraph text by some amount // again this may be inaccurate if fonts with different size are used in this paragraph float itextdescender = -font.getBaseFont().getFontDescriptor(BaseFont.DESCENT, size); // negative float textRise = itextdescender + getTotalLeading() - font.getSize() * multiplier; ArrayList<Chunk> chunks = getChunks(); for (Chunk chunk : chunks) { Font f = chunk.getFont(); if (f != null) { // have to raise underline and strikethru as well float s = f.getSize(); if (f.isUnderlined()) { f.setStyle(f.getStyle() & ~Font.UNDERLINE); chunk.setUnderline(s * 1 / 17, s * -1 / 7 + textRise); } if (f.isStrikethru()) { f.setStyle(f.getStyle() & ~Font.STRIKETHRU); chunk.setUnderline(s * 1 / 17, s * 1 / 4 + textRise); } } chunk.setTextRise(chunk.getTextRise() + textRise); } } }
From source file:ilarkesto.integration.itext.Paragraph.java
License:Open Source License
private Font createFont(String name, FontStyle fontStyle) { Font font; try {/* w w w.j av a 2 s.co m*/ font = new Font(BaseFont.createFont(name, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); } catch (Exception ex) { throw new RuntimeException("Loading font failed: " + name, ex); } if (fontStyle != null) { font.setStyle(createStyle(fontStyle)); font.setSize(PdfBuilder.mmToPoints(fontStyle.getSize())); font.setColor(fontStyle.getColor()); } return font; }
From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java
License:Open Source License
private Font decodeFont(String fontstring, Font returnFont) { if (fontstring != null) { int family = -1; StringTokenizer tokener = new StringTokenizer(fontstring, "-"); // family part if (tokener.hasMoreTokens()) { family = Font.getFamilyIndex(tokener.nextToken()); }//from w w w .ja v a2s.c o m if (family > -1) { Font font = new Font(family); // size part if (tokener.hasMoreTokens()) { float size = Float.parseFloat(tokener.nextToken()); font.setSize(size); } // style part if (tokener.hasMoreTokens()) { font.setStyle(tokener.nextToken()); } // color part if (tokener.hasMoreTokens()) { font.setColor(IWColor.getAWTColorFromHex(tokener.nextToken())); } return font; } } return returnFont; }
From source file:managedbean.afos.FlightDutyBacking.java
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.open();/* www . ja va2 s . c o m*/ pdf.setPageSize(PageSize.A4); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "logo.png"; Image logoImg = Image.getInstance(logo); logoImg.scalePercent(20f); SimpleDateFormat sdf = new SimpleDateFormat("E, dd/MM/yyyy 'at' hh:mm:ss a"); Font titleFont = new Font(); Font subtitleFont = new Font(); titleFont.setSize(16); titleFont.setStyle(Font.BOLD); subtitleFont.setSize(12); subtitleFont.setStyle(Font.BOLD); Paragraph title = new Paragraph(flightReport.getType() + " Duty Report", titleFont); title.setAlignment(Element.ALIGN_CENTER); title.setSpacingAfter(12f); Paragraph subTitle1 = new Paragraph("Flight Information:", subtitleFont); subTitle1.setSpacingAfter(8f); Paragraph subTitle2 = new Paragraph(flightReport.getType() + " Checklist:", subtitleFont); subTitle2.setSpacingBefore(12f); subTitle2.setSpacingAfter(12f); com.lowagie.text.List list = new com.lowagie.text.List(true, 15); list.setLettered(true); list.add("Flight: " + selectedFlightSchedule.getFlight().getFlightNo()); list.add("Return Flight: " + selectedFlightSchedule.getFlight().getReturnedFlight().getFlightNo()); Airport departure, arrival; departure = selectedFlightSchedule.getLeg().getDepartAirport(); arrival = selectedFlightSchedule.getLeg().getArrivalAirport(); sdf.setTimeZone(TimeZone.getTimeZone(getTimeZone(departure))); list.add("Departure Time: " + sdf.format(selectedFlightSchedule.getDepartDate()) + " (" + departure.getCity().getCityName() + " Time)"); sdf.setTimeZone(TimeZone.getTimeZone(getTimeZone(arrival))); list.add("Arrival Time: " + sdf.format(selectedFlightSchedule.getArrivalDate()) + " (" + arrival.getCity().getCityName() + " Time)"); list.add("Origin: " + departure.getCity().getCityName() + " (" + departure.getAirportName() + ")"); list.add("Destination: " + arrival.getCity().getCityName() + " (" + arrival.getAirportName() + ")"); pdf.add(logoImg); pdf.add(new Paragraph(" ")); pdf.add(title); pdf.add(subTitle1); pdf.add(list); pdf.add(subTitle2); pdf.setMargins(72, 72, 72, 72); pdf.addAuthor("Merlion Airline"); pdf.addCreationDate(); sdf.applyPattern("dd/MM/yyyy_hh:mm:ss"); pdf.addTitle("Post-Flight Duty Report_" + selectedFlightSchedule.getFlight().getFlightNo() + "_" + sdf.format(selectedFlightSchedule.getDepartDate())); }