List of usage examples for com.lowagie.text Font BOLD
int BOLD
To view the source code for com.lowagie.text Font BOLD.
Click Source Link
From source file:com.bytecode.customexporter.PDFCustomExporter.java
@Override public void export(ActionEvent event, String tableId, FacesContext context, String filename, String tableTitle, boolean pageOnly, boolean selectionOnly, String encodingType, MethodExpression preProcessor, MethodExpression postProcessor, boolean subTable) throws IOException { try {//w ww . jav a 2s . com Document document = new Document(); if (orientation.equalsIgnoreCase("Landscape")) document.setPageSize(PageSize.A4.rotate()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); StringTokenizer st = new StringTokenizer(tableId, ","); while (st.hasMoreElements()) { String tableName = (String) st.nextElement(); UIComponent component = SearchExpressionFacade.resolveComponent(context, event.getComponent(), tableName); if (component == null) { throw new FacesException("Cannot find component \"" + tableName + "\" in view."); } if (!(component instanceof DataTable || component instanceof DataList)) { throw new FacesException("Unsupported datasource target:\"" + component.getClass().getName() + "\", exporter must target a PrimeFaces DataTable/DataList."); } if (preProcessor != null) { preProcessor.invoke(context.getELContext(), new Object[] { document }); } if (!document.isOpen()) { document.open(); } if (tableTitle != null && !tableTitle.isEmpty() && !tableId.contains("" + ",")) { Font tableTitleFont = FontFactory.getFont(FontFactory.TIMES, encodingType, Font.DEFAULTSIZE, Font.BOLD); Paragraph title = new Paragraph(tableTitle, tableTitleFont); document.add(title); Paragraph preface = new Paragraph(); addEmptyLine(preface, 3); document.add(preface); } PdfPTable pdf; DataList list = null; DataTable table = null; if (component instanceof DataList) { list = (DataList) component; pdf = exportPDFTable(context, list, pageOnly, encodingType); } else { table = (DataTable) component; pdf = exportPDFTable(context, table, pageOnly, selectionOnly, encodingType, subTable); } if (pdf != null) { document.add(pdf); } // add a couple of blank lines Paragraph preface = new Paragraph(); addEmptyLine(preface, datasetPadding); document.add(preface); if (postProcessor != null) { postProcessor.invoke(context.getELContext(), new Object[] { document }); } } document.close(); writePDFToResponse(context.getExternalContext(), baos, filename); } catch (DocumentException e) { throw new IOException(e.getMessage()); } }
From source file:com.bytecode.customexporter.PDFCustomExporter.java
protected void createCustomFonts(String encoding) { if (fontName != null && FontFactory.getFont(fontName).getBaseFont() != null) { this.cellFont = FontFactory.getFont(fontName, encoding); this.facetFont = FontFactory.getFont(fontName, encoding, Font.DEFAULTSIZE, Font.BOLD); } else {/*from w ww .j a va2 s . co m*/ this.cellFont = FontFactory.getFont(FontFactory.TIMES, encoding); this.facetFont = FontFactory.getFont(FontFactory.TIMES, encoding, Font.DEFAULTSIZE, Font.BOLD); } if (facetFontColor != null) { this.facetFont.setColor(facetFontColor); } if (facetFontSize != null) { this.facetFont.setSize(facetFontSize); } if (facetFontStyle != null) { this.facetFont.setStyle(facetFontStyle); } if (cellFontColor != null) { this.cellFont.setColor(cellFontColor); } if (cellFontSize != null) { this.cellFont.setSize(cellFontSize); } if (cellFontStyle != null) { this.cellFont.setStyle(cellFontStyle); } }
From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
License:Apache License
private void initialize(boolean isUseCase) { chapterFont = FontFactory.getFont(FontFactory.TIMES, isUseCase ? 16 : 20, Font.BOLD, new Color(0, 0, 0)); sectionFont = FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLD, new Color(0, 0, 0)); subSectionFont = FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)); normalFont = FontFactory.getFont(FontFactory.TIMES, 12, Font.NORMAL, new Color(0, 0, 0)); boldFont = FontFactory.getFont(FontFactory.TIMES, 12, Font.BOLD, new Color(0, 0, 0)); fixedWidthFont = FontFactory.getFont(FontFactory.COURIER, 11, Font.NORMAL, new Color(0, 0, 0)); excludedAttributes = new HashSet<String>(); excludedAttributes.add(WorkAttributeConstant.LOGICAL_ID); excludedAttributes.add(WorkAttributeConstant.REFERENCE_ID); excludedAttributes.add(WorkAttributeConstant.WORK_DISPLAY_INFO); excludedAttributes.add(WorkAttributeConstant.REFERENCES); excludedAttributes.add(WorkAttributeConstant.DOCUMENTATION); excludedAttributes.add(WorkAttributeConstant.SIMULATION_STUB_MODE); excludedAttributes.add(WorkAttributeConstant.SIMULATION_RESPONSE); excludedAttributes.add(WorkAttributeConstant.DESCRIPTION); excludedAttributes.add(WorkAttributeConstant.BAM_START_MSGDEF); excludedAttributes.add(WorkAttributeConstant.BAM_FINISH_MSGDEF); excludedAttributesForSpecificValues = new HashMap<String, String>(); excludedAttributesForSpecificValues.put("DoNotNotifyCaller", "false"); excludedAttributesForSpecificValues.put("DO_LOGGING", "True"); tabularAttributes = new HashMap<String, List<String>>(); tabularAttributes.put("Notices", Arrays.asList(new String[] { "Outcome", "Template", "Notifier Class(es)" })); tabularAttributes.put("Variables", Arrays.asList(new String[] { "Variable", "ReferredAs", "Display", "Seq.", "Index" })); tabularAttributes.put("WAIT_EVENT_NAMES", Arrays.asList(new String[] { "Event Name", "Completion Code", "Recurring" })); tabularAttributes.put("variables", Arrays.asList(new String[] { "=", "SubProcess Variable", "Binding Expression" })); tabularAttributes.put("processmap", Arrays.asList(new String[] { "=", "Logical Name", "Process Name", "Process Version" })); tabularAttributes.put("Bindings", Arrays.asList(new String[] { "=", "Variable", "LDAP Attribute" })); tabularAttributes.put("Parameters", Arrays.asList(new String[] { "=", "Input Variable", "Binding Expression" })); textboxAttributes = new HashMap<String, String>(); textboxAttributes.put("Rule", "Code"); textboxAttributes.put("Java", "Java"); textboxAttributes.put("PreScript", "Pre-Script"); textboxAttributes.put("PostScript", "Post-Script"); }
From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
License:Apache License
private Object generateElementHtml(Element element, int depth, Font font) { String tag = element.getName(); Object myself;/* w w w. j a va 2 s .c o m*/ Object av; if (element instanceof HTMLDocument.RunElement) { HTMLDocument.RunElement re = (HTMLDocument.RunElement) element; int start = re.getStartOffset(); int end = re.getEndOffset(); try { String content = re.getDocument().getText(start, end - start); HtmlAttr htmlattr = printAttributesHtml(re); av = re.getAttribute(CSS.Attribute.FONT_SIZE); String fontsize = av == null ? null : av.toString(); av = re.getAttribute(CSS.Attribute.FONT_FAMILY); String fontfamily = av == null ? null : av.toString(); av = re.getAttribute(CSS.Attribute.COLOR); String fontcolor = av == null ? null : av.toString(); if (fontcolor != null || fontsize != null || fontfamily != null) { if (fontfamily == null) fontfamily = font.getFamilyname(); if (fontsize != null && fontsize.endsWith("pt")) fontsize = fontsize.substring(0, fontsize.indexOf("pt")); float size = fontsize == null ? font.getSize() : (Float.parseFloat(fontsize) + 8); int style = font.getStyle(); Color color; if (fontcolor != null) { color = Color.decode(fontcolor); } else color = font.getColor(); font = FontFactory.getFont(fontfamily, size, style, color); } else if (htmlattr.bold || htmlattr.italic) { String family = font.getFamilyname(); float size = font.getSize(); Color color = font.getColor(); if (htmlattr.bold && htmlattr.italic) font = FontFactory.getFont(family, size, Font.BOLDITALIC, color); else if (htmlattr.italic) font = FontFactory.getFont(family, size, Font.ITALIC, color); else if (htmlattr.bold) font = FontFactory.getFont(family, size, Font.BOLD); } myself = new Chunk(content, font); } catch (BadLocationException e) { e.printStackTrace(); myself = null; } } else if (element instanceof HTMLDocument.BlockElement) { HTMLDocument.BlockElement be = (HTMLDocument.BlockElement) element; HtmlAttr htmlattr = printAttributesHtml(be); if (htmlattr.bold) { System.out.println("+++BOLD!!!"); } av = be.getAttribute(javax.swing.text.html.HTML.Attribute.ALIGN); String align = av == null ? null : av.toString(); if (htmlattr.bold || htmlattr.italic) { String family = font.getFamilyname(); float size = font.getSize(); Color color = font.getColor(); if (htmlattr.bold && htmlattr.italic) font = FontFactory.getFont(family, size, Font.BOLDITALIC, color); else if (htmlattr.italic) font = FontFactory.getFont(family, size, Font.ITALIC, color); else if (htmlattr.bold) font = FontFactory.getFont(family, size, Font.BOLD, Color.blue); } if (tag.equalsIgnoreCase("html")) { myself = generateElementChildrenHtml(element, depth + 1, font); } else if (tag.equalsIgnoreCase("head")) { myself = null; } else if (tag.equalsIgnoreCase("body")) { myself = generateElementChildrenHtml(element, depth + 1, font); } else if (tag.equalsIgnoreCase("p") || tag.equalsIgnoreCase("p-implied")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); Paragraph paragraph = new Paragraph(); paragraph.setFirstLineIndent(0F); for (Object child : children) { if (child instanceof Chunk) { Chunk chunk = (Chunk) child; /*if (!chunk.getContent().equals("\n"))*/ paragraph.add(chunk); } else paragraph.add(child); } if (align != null) paragraph.setAlignment(align); myself = paragraph; } else if (tag.equalsIgnoreCase("h1") || tag.equalsIgnoreCase("h2") || tag.equalsIgnoreCase("h3")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, subSectionFont); Paragraph title = new Paragraph(); for (Object child : children) { title.add(child); } myself = new TempSectionPdf(title); } else if (tag.equalsIgnoreCase("ul")) { com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f); list.setIndentationLeft(25.0f); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { list.add(child); } myself = list; } else if (tag.equalsIgnoreCase("ol")) { com.lowagie.text.List list = new com.lowagie.text.List(true, false, 20.0f); list.setIndentationLeft(25.0f); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { list.add(child); } myself = list; } else if (tag.equalsIgnoreCase("li")) { ListItem li = new ListItem(); li.setSpacingAfter(0.0f); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { li.add(child); } myself = li; } else if (tag.equalsIgnoreCase("table")) { List<Object> rows = generateElementChildrenHtml(element, depth + 1, normalFont); try { int ncols = 0; for (Object row : rows) { if (row instanceof List<?>) { int n = ((List<?>) row).size(); if (n > ncols) ncols = n; } } Table table = new Table(2); table.setBorderWidth(1); table.setBorderColor(new Color(0, 128, 128)); table.setPadding(1.0f); table.setSpacing(0.5f); Cell c = new Cell("header"); c.setHeader(true); c.setColspan(ncols); table.addCell(c); table.endHeaders(); for (Object row : rows) { if (row instanceof List<?>) { for (Object cell : (List<?>) row) { if (cell instanceof Cell) table.addCell((Cell) cell); } } } myself = table; } catch (BadElementException e) { e.printStackTrace(); myself = null; } } else if (tag.equalsIgnoreCase("tr")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); myself = children; } else if (tag.equalsIgnoreCase("td")) { Cell cell = new Cell(); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { cell.add(child); } myself = cell; } else if (tag.equalsIgnoreCase("div")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); Paragraph paragraph = new Paragraph(); paragraph.setFirstLineIndent(0F); for (Object child : children) { paragraph.add(child); } if (align != null) paragraph.setAlignment(align); myself = paragraph; } else { System.err.println("Unknown element " + element.getName()); myself = null; } } else { myself = null; // could be BidiElement - not sure what it is } return myself; }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
License:Open Source License
private static boolean parseLine(WikiPDFContext context, String line, Paragraph main, Connection db, ArrayList<Integer> wikiListTodo, float cellWidth, PdfPCell cell) throws Exception { LOG.debug("PARSING LINE: " + line); // Context Objects Project project = context.getProject(); WikiExportBean exportBean = context.getExportBean(); HashMap<String, ImageInfo> imageList = context.getImageList(); String fileLibrary = context.getFileLibrary(); boolean needsCRLF = true; boolean bold = false; boolean italic = false; boolean bolditalic = false; StringBuffer subject = new StringBuffer(); StringBuffer data = new StringBuffer(); int linkL = 0; int linkR = 0; int attr = 0; int underlineAttr = 0; // parse characters for (int i = 0; i < line.length(); i++) { char c1 = line.charAt(i); String c = String.valueOf(c1); // False attr/links if (!"'".equals(c) && attr == 1) { data.append("'").append(c); attr = 0;// w w w . j a va 2 s . c om continue; } if (!"_".equals(c) && underlineAttr == 1) { data.append("_").append(c); underlineAttr = 0; continue; } if (!"[".equals(c) && linkL == 1) { data.append("[").append(c); linkL = 0; continue; } if (!"]".equals(c) && linkR == 1) { data.append("]").append(c); linkR = 0; continue; } // Links if ("[".equals(c)) { ++linkL; continue; } if ("]".equals(c)) { ++linkR; if (linkL == 2 && linkR == 2) { LOG.debug("main.add(new Chunk(data.toString()))"); main.add(new Chunk(data.toString())); data.setLength(0); // Different type of links... String link = subject.toString().trim(); if (link.startsWith("Image:") || link.startsWith("image:")) { // @note From WikiImageLink.java String image = link.substring(6); String title = null; int frame = -1; int thumbnail = -1; int left = -1; int right = -1; int center = -1; int none = -1; int imageLink = -1; int alt = -1; if (image.indexOf("|") > 0) { // the image is first image = image.substring(0, image.indexOf("|")); // any directives are next frame = link.indexOf("|frame"); thumbnail = link.indexOf("|thumb"); left = link.indexOf("|left"); right = link.indexOf("|right"); center = link.indexOf("|center"); none = link.indexOf("|none"); imageLink = link.indexOf("|link="); alt = link.indexOf("|alt="); // the optional caption is last int last = link.lastIndexOf("|"); if (last > frame && last > thumbnail && last > left && last > right && last > center && last > none && last > imageLink && last > alt) { title = link.substring(last + 1); } } //A picture, including alternate text: //[[Image:Wiki.png|The logo for this Wiki]] //You can put the image in a frame with a caption: //[[Image:Wiki.png|frame|The logo for this Wiki]] // Access some image details int width = 0; int height = 0; ImageInfo imageInfo = imageList.get(image + (thumbnail > -1 ? "-TH" : "")); if (imageInfo != null) { width = imageInfo.getWidth(); height = imageInfo.getHeight(); } // Alt String altText = null; if (alt > -1) { int startIndex = alt + 4; int endIndex = link.indexOf("|", startIndex); if (endIndex == -1) { endIndex = link.length(); } altText = link.substring(startIndex, endIndex); } // Looks like the image needs a link (which is always last) String url = null; if (imageLink > -1) { // Get the entered link int startIndex = imageLink + 6; int endIndex = link.length(); String href = link.substring(startIndex, endIndex); // Treat as a wikiLink to validate and to create a proper url WikiLink wikiLink = new WikiLink(project.getId(), (altText != null ? href + " " + altText : href)); url = wikiLink.getUrl(""); if (!url.startsWith("http://") && !url.startsWith("https://")) { // @todo Use a local link // @todo Use an external link } } // Determine if local or external image if ((image.startsWith("http://") || image.startsWith("https://"))) { // retrieve external image String imageUrl = null; try { URL imageURL = new URL(image); imageUrl = image; } catch (Exception e) { } } else { // local image try { // @todo image alignment and links Image thisImage = Image.getInstance( getImageFilename(db, fileLibrary, project, image, (thumbnail > -1))); LOG.debug("Drawing image for area: " + cellWidth); if (cellWidth > 0f) { LOG.debug(" Image is embedded in cell"); // Guess the size of the cell float cellPixels = (500f * (cellWidth / 100f)); if (cellPixels > 0f && (float) width > cellPixels) { // Shrink image to fit the cell LOG.debug(" Scaling to fit"); thisImage.scaleToFit(cellPixels, 500f); } else { // Align image to left instead of scaling it to fit thisImage.setAlignment(Image.LEFT); } LOG.debug("cell.addElement(thisImage)"); cell.addElement(thisImage); } else { LOG.debug(" Image is inline"); if (width > 500) { LOG.debug(" Scaling to fit"); thisImage.scaleToFit(500f, 500f); } LOG.debug("main.add(thisImage)"); main.add(thisImage); } // thisImage.setAlignment(); // thisImage.Alignment = Image.TEXTWRAP | Image.ALIGN_RIGHT; // main.add(thisImage); } catch (FileNotFoundException fnfe) { LOG.warn("WikiPDFUtils-> Image was not found in the FileLibrary (" + getImageFilename(db, fileLibrary, project, image, (thumbnail > -1)) + ")... will continue."); } } /* if (frame > -1 || thumbnail > -1) { sb.append("</div>"); sb.append("<div id=\"caption\" style=\"margin-bottom: 5px; margin-left: 5px; margin-right: 5px; text-align: left;\">"); } if (thumbnail > -1) { sb.append("<div style=\"float:right\"><a target=\"_blank\" href=\"ProjectManagementWiki.do?command=Img&pid=" + wiki.getProjectId() + "&subject=" + StringUtils.replace(StringUtils.jsEscape(image), "%20", "+") + "\"><img src=\"images/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"Enlarge\" border=\"0\" /></a></div>"); } if (frame > -1 || thumbnail > -1) { if (title != null) { sb.append(StringUtils.toHtml(title)); } sb.append( " </div>\n" + "</div>"); } */ /* if (none > -1) { sb.append("<br clear=\"all\">"); } */ if (i + 1 == line.length() && (right > -1 || left > -1) || none > -1) { needsCRLF = false; } } else { // This is most likely a Wiki link String title = subject.toString().trim(); if (link.indexOf("|") > 0) { link = link.substring(0, link.indexOf("|")).trim(); title = title.substring(title.indexOf("|") + 1); } if (link.indexOf("http://") > -1 || link.indexOf("https://") > -1) { String label = link; if (link.indexOf(" ") > 0) { label = link.substring(link.indexOf(" ") + 1); link = link.substring(0, link.indexOf(" ")); } Anchor anchor1 = new Anchor(label, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, new Color(0, 0, 255))); anchor1.setReference(link); anchor1.setName("top"); main.add(anchor1); } else { // Place a wiki link if (exportBean.getFollowLinks()) { // See if target link exists before creating a link to it int linkedWikiId = -1; if (StringUtils.hasText(title) && !title.startsWith("|")) { Wiki subwiki = WikiList.queryBySubject(db, title, project.getId()); if (subwiki.getId() > -1) { linkedWikiId = subwiki.getId(); } } // Display the linked item if (linkedWikiId > -1) { // Display as an anchor Anchor linkToWiki = new Anchor(title, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255))); linkToWiki.setReference("#" + title.toLowerCase()); LOG.debug("Link to: #" + title.toLowerCase()); main.add(linkToWiki); LOG.debug(" main.add(linkToWiki)"); // main.add(new Chunk(title, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255))).setLocalGoto(link)); // Add this wiki to the to do list... if (!wikiListTodo.contains(linkedWikiId)) { wikiListTodo.add(linkedWikiId); } } else { // Display without the link main.add(new Chunk(title, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255)))); } } else { // Not following links, so display... perhaps as an external link someday main.add(new Chunk(title, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255)))); } } } subject.setLength(0); linkL = 0; linkR = 0; } continue; } if (!"[".equals(c) && linkL == 2 && !"]".equals(c)) { subject.append(c); continue; } // Attribute properties if ("'".equals(c)) { ++attr; continue; } if (!"'".equals(c) && attr > 1) { if (attr == 2) { if (!italic) { main.add(new Chunk(data.toString())); data.setLength(0); data.append(c); italic = true; } else { data.append(c); main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC, new Color(0, 0, 0)))); data.setLength(0); italic = false; } attr = 0; continue; } if (attr == 3) { if (!bold) { main.add(new Chunk(data.toString())); data.setLength(0); data.append(c); bold = true; } else { data.append(c); main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0, 0, 0)))); data.setLength(0); bold = false; } attr = 0; continue; } if (attr == 5) { if (!bolditalic) { main.add(new Chunk(data.toString())); data.setLength(0); data.append(c); bolditalic = true; } else { data.append(c); main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLDITALIC, new Color(0, 0, 0)))); data.setLength(0); bolditalic = false; } attr = 0; continue; } } data.append(c); } for (int x = 0; x < linkR; x++) { data.append("]"); } for (int x = 0; x < linkL; x++) { data.append("["); } if (attr == 1) { data.append("'"); } if (italic) { main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC, new Color(0, 0, 0)))); } else if (bold) { main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0, 0, 0)))); } else if (bolditalic) { main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLDITALIC, new Color(0, 0, 0)))); } else { main.add(new Chunk(data.toString())); } data.setLength(0); return needsCRLF; }
From source file:com.crm.webapp.util.PDFCustomExporter.java
License:Apache License
@Override public void export(ActionEvent event, String tableId, FacesContext context, String filename, String tableTitle, boolean pageOnly, boolean selectionOnly, String encodingType, MethodExpression preProcessor, MethodExpression postProcessor, boolean subTable) throws IOException { try {/*w w w. j a v a 2 s. com*/ Document document = new Document(); if (orientation.equalsIgnoreCase("Landscape")) { document.setPageSize(PageSize.A4.rotate()); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); StringTokenizer st = new StringTokenizer(tableId, ","); while (st.hasMoreElements()) { String tableName = (String) st.nextElement(); UIComponent component = SearchExpressionFacade.resolveComponent(context, event.getComponent(), tableName); if (component == null) { throw new FacesException("Cannot find component \"" + tableName + "\" in view."); } if (!(component instanceof DataTable || component instanceof DataList)) { throw new FacesException("Unsupported datasource target:\"" + component.getClass().getName() + "\", exporter must target a PrimeFaces DataTable/DataList."); } if (preProcessor != null) { preProcessor.invoke(context.getELContext(), new Object[] { document }); } if (!document.isOpen()) { document.open(); } if (tableTitle != null && !tableTitle.isEmpty() && !tableId.contains("" + ",")) { Font tableTitleFont = FontFactory.getFont(FontFactory.TIMES, encodingType, Font.DEFAULTSIZE, Font.BOLD); Paragraph title = new Paragraph(tableTitle, tableTitleFont); document.add(title); Paragraph preface = new Paragraph(); addEmptyLine(preface, 3); document.add(preface); } PdfPTable pdf; DataList list = null; DataTable table = null; if (component instanceof DataList) { list = (DataList) component; pdf = exportPDFTable(context, list, pageOnly, encodingType); } else { table = (DataTable) component; pdf = exportPDFTable(context, table, pageOnly, selectionOnly, encodingType, subTable); } if (pdf != null) { document.add(pdf); } // add a couple of blank lines Paragraph preface = new Paragraph(); addEmptyLine(preface, datasetPadding); document.add(preface); if (postProcessor != null) { postProcessor.invoke(context.getELContext(), new Object[] { document }); } } document.close(); writePDFToResponse(context.getExternalContext(), baos, filename); } catch (DocumentException e) { throw new IOException(e.getMessage()); } }
From source file:com.crm.webapp.util.PDFCustomExporter.java
License:Apache License
protected void createCustomFonts(String encoding) { this.cellFont = FontFactory.getFont(FontFactory.TIMES, encoding); this.facetFont = FontFactory.getFont(FontFactory.TIMES, encoding, Font.DEFAULTSIZE, Font.BOLD); if (facetFontColor != null) { this.facetFont.setColor(facetFontColor); }/* w w w. j av a 2s .com*/ if (facetFontSize != null) { this.facetFont.setSize(facetFontSize); } if (facetFontStyle != null) { this.facetFont.setStyle(facetFontStyle); } if (cellFontColor != null) { this.cellFont.setColor(cellFontColor); } if (cellFontSize != null) { this.cellFont.setSize(cellFontSize); } if (cellFontStyle != null) { this.cellFont.setStyle(cellFontStyle); } if (fontName != null) { cellFont.setFamily(fontName); facetFont.setFamily(fontName); } }
From source file:com.dlya.facturews.DlyaPdfExporter2.java
License:Open Source License
/** * Creates a PDF font.//from www. ja v a2 s .c o m * * @param attributes the text attributes of the font * @param locale the locale for which to create the font * @param setFontLines whether to set underline and strikethrough as font style * @return the PDF font for the specified attributes */ @SuppressWarnings("deprecation") protected Font getFont(Map<Attribute, Object> attributes, Locale locale, boolean setFontLines) { JRFont jrFont = new JRBaseFont(attributes); Exception initialException = null; Color forecolor = (Color) attributes.get(TextAttribute.FOREGROUND); // use the same font scale ratio as in JRStyledText.getAwtAttributedString float fontSizeScale = 1f; Integer scriptStyle = (Integer) attributes.get(TextAttribute.SUPERSCRIPT); if (scriptStyle != null && (TextAttribute.SUPERSCRIPT_SUB.equals(scriptStyle) || TextAttribute.SUPERSCRIPT_SUPER.equals(scriptStyle))) { fontSizeScale = 2f / 3; } Font font = null; PdfFont pdfFont = null; FontKey key = new FontKey(jrFont.getFontName(), jrFont.isBold(), jrFont.isItalic()); if (fontMap != null && fontMap.containsKey(key)) { pdfFont = pdfFontMap.get(key); } else { FontInfo fontInfo = FontUtil.getInstance(jasperReportsContext).getFontInfo(jrFont.getFontName(), locale); if (fontInfo == null) { //fontName NOT found in font extensions pdfFont = new PdfFont(jrFont.getPdfFontName(), jrFont.getPdfEncoding(), jrFont.isPdfEmbedded()); } else { //fontName found in font extensions FontFamily family = fontInfo.getFontFamily(); FontFace face = fontInfo.getFontFace(); int faceStyle = java.awt.Font.PLAIN; if (face == null) { //fontName matches family name in font extension if (jrFont.isBold() && jrFont.isItalic()) { face = family.getBoldItalicFace(); faceStyle = java.awt.Font.BOLD | java.awt.Font.ITALIC; } if (face == null && jrFont.isBold()) { face = family.getBoldFace(); faceStyle = java.awt.Font.BOLD; } if (face == null && jrFont.isItalic()) { face = family.getItalicFace(); faceStyle = java.awt.Font.ITALIC; } if (face == null) { face = family.getNormalFace(); faceStyle = java.awt.Font.PLAIN; } // if (face == null) // { // throw new JRRuntimeException("Font family '" + family.getName() + "' does not have the normal font face."); // } } else { //fontName matches face name in font extension; not family name faceStyle = fontInfo.getStyle(); } String pdfFontName = null; int pdfFontStyle = java.awt.Font.PLAIN; if (jrFont.isBold() && jrFont.isItalic()) { pdfFontName = family.getBoldItalicPdfFont(); pdfFontStyle = java.awt.Font.BOLD | java.awt.Font.ITALIC; } if (pdfFontName == null && jrFont.isBold()) { pdfFontName = family.getBoldPdfFont(); pdfFontStyle = java.awt.Font.BOLD; } if (pdfFontName == null && jrFont.isItalic()) { pdfFontName = family.getItalicPdfFont(); pdfFontStyle = java.awt.Font.ITALIC; } if (pdfFontName == null) { pdfFontName = family.getNormalPdfFont(); pdfFontStyle = java.awt.Font.PLAIN; } if (pdfFontName == null) { //in theory, face file cannot be null here pdfFontName = (face == null || face.getFile() == null ? jrFont.getPdfFontName() : face.getFile()); pdfFontStyle = faceStyle;//FIXMEFONT not sure this is correct, in case we inherit pdfFontName from default properties } // String ttf = face.getFile(); // if (ttf == null) // { // throw new JRRuntimeException("The '" + face.getName() + "' font face in family '" + family.getName() + "' returns a null file."); // } pdfFont = new PdfFont(pdfFontName, family.getPdfEncoding() == null ? jrFont.getPdfEncoding() : family.getPdfEncoding(), family.isPdfEmbedded() == null ? jrFont.isPdfEmbedded() : family.isPdfEmbedded().booleanValue(), jrFont.isBold() && ((pdfFontStyle & java.awt.Font.BOLD) == 0), jrFont.isItalic() && ((pdfFontStyle & java.awt.Font.ITALIC) == 0)); } } int pdfFontStyle = (pdfFont.isPdfSimulatedBold() ? Font.BOLD : 0) | (pdfFont.isPdfSimulatedItalic() ? Font.ITALIC : 0); if (setFontLines) { pdfFontStyle |= (jrFont.isUnderline() ? Font.UNDERLINE : 0) | (jrFont.isStrikeThrough() ? Font.STRIKETHRU : 0); } try { font = FontFactory.getFont(pdfFont.getPdfFontName(), pdfFont.getPdfEncoding(), pdfFont.isPdfEmbedded(), jrFont.getFontSize() * fontSizeScale, pdfFontStyle, forecolor); // check if FontFactory didn't find the font if (font.getBaseFont() == null && font.family() == Font.UNDEFINED) { font = null; } } catch (Exception e) { initialException = e; } if (font == null) { byte[] bytes = null; try { bytes = RepositoryUtil.getInstance(jasperReportsContext) .getBytesFromLocation(pdfFont.getPdfFontName()); } catch (JRException e) { throw //NOPMD new JRRuntimeException("Could not load the following font : " + "\npdfFontName : " + pdfFont.getPdfFontName() + "\npdfEncoding : " + pdfFont.getPdfEncoding() + "\nisPdfEmbedded : " + pdfFont.isPdfEmbedded(), initialException); } BaseFont baseFont = null; try { baseFont = BaseFont.createFont(pdfFont.getPdfFontName(), pdfFont.getPdfEncoding(), pdfFont.isPdfEmbedded(), true, bytes, null); } catch (DocumentException e) { throw new JRRuntimeException(e); } catch (IOException e) { throw new JRRuntimeException(e); } font = new Font(baseFont, jrFont.getFontSize() * fontSizeScale, pdfFontStyle, forecolor); } return font; }
From source file:com.geek.tutorial.itext.text.Chunk_Example.java
License:Open Source License
public Chunk_Example() throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("chunk_example.pdf")); document.open();/*from w w w . j a v a 2 s. com*/ Font font = new Font(Font.COURIER, 10, Font.BOLD); // 1 font.setColor(new Color(0x92, 0x90, 0x83)); Chunk chunk = new Chunk("testing text element", font); // 2 chunk.setBackground(new Color(0xff, 0xe4, 0x00)); // 3 document.add(chunk); // 4 document.close(); }
From source file:com.geek.tutorial.itext.text.Paragraph_Example.java
License:Open Source License
public Paragraph_Example() throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("paragraph_example.pdf")); document.open();/*from ww w . java 2 s.c o m*/ Font font = new Font(Font.COURIER, 10, Font.BOLD); font.setColor(new Color(0x92, 0x90, 0x83)); Chunk chunk = new Chunk("testing text element ", font); chunk.setBackground(new Color(0xff, 0xe4, 0x00)); Phrase phrase = new Phrase(20, "This is initial text. "); for (int i = 0; i < 10; i++) { phrase.add(chunk); } Paragraph paragraph = new Paragraph(); // 1 paragraph.add(phrase); // 2 document.add(paragraph); // 3 document.add(paragraph); // 4 document.close(); }