List of usage examples for com.lowagie.text Font UNDERLINE
int UNDERLINE
To view the source code for com.lowagie.text Font UNDERLINE.
Click Source Link
From source file:classroom.filmfestival_a.Movies04.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1/* ww w.j a va2 s. c o m*/ Document document = new Document(); try { // step 2 PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 Session session = (Session) MySessionFactory.currentSession(); Query q = session.createQuery("from FilmTitle order by title"); java.util.List<FilmTitle> results = q.list(); Paragraph p; Chunk c; Anchor a; Font bold = new Font(Font.HELVETICA, 12, Font.BOLD); Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC); Font underlined = new Font(Font.HELVETICA, 12, Font.UNDERLINE, Color.BLUE); for (FilmTitle movie : results) { p = new Paragraph(20); c = new Chunk(movie.getTitle(), bold); c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId()); p.add(c); c = new Chunk(" (" + movie.getYear() + ") ", italic); p.add(c); a = new Anchor("IMDB", underlined); a.setReference("http://www.imdb.com/title/tt" + movie.getImdb()); p.add(a); document.add(p); Set<DirectorName> directors = movie.getDirectorNames(); List list = new List(); for (DirectorName director : directors) { list.add(director.getName()); } document.add(list); } // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }
From source file:com.aripd.clms.service.ContractServiceBean.java
@Override public void generatePdf(ContractEntity contract) { String baseFontUrl = "/fonts/Quivira.otf"; FontFactory.register(baseFontUrl);/*from w ww .j av a 2 s .c o m*/ ByteArrayOutputStream output = new ByteArrayOutputStream(); try { BaseFont bf = BaseFont.createFont(baseFontUrl, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font font18n = new Font(bf, 18, Font.NORMAL); Font font12n = new Font(bf, 12, Font.NORMAL); Font font8n = new Font(bf, 8, Font.NORMAL); Font font8nbu = new Font(bf, 8, Font.BOLD | Font.UNDERLINE); Font font8ng = new Font(bf, 8, Font.NORMAL, Color.DARK_GRAY); Font font6n = new Font(bf, 6, Font.NORMAL); Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, output); document.open(); addMetaData(document); addTitlePage(document, contract); Image imgBlue = Image.getInstance(1, 1, 3, 8, new byte[] { (byte) 0, (byte) 0, (byte) 255, }); imgBlue.scaleAbsolute(document.getPageSize().getWidth(), 10); imgBlue.setAbsolutePosition(0, document.getPageSize().getHeight() - imgBlue.getScaledHeight()); PdfImage stream = new PdfImage(imgBlue, "", null); stream.put(new PdfName("ITXT_SpecialId"), new PdfName("123456789")); PdfIndirectObject ref = writer.addToBody(stream); imgBlue.setDirectReference(ref.getIndirectReference()); document.add(imgBlue); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); PdfPCell cell = new PdfPCell(new Paragraph(contract.getName(), font18n)); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); cell.setPadding(5); table.addCell(cell); cell = new PdfPCell(new Paragraph("Version: " + contract.getVersion(), font8n)); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); cell.setPadding(5); table.addCell(cell); cell = new PdfPCell(new Paragraph("Review: " + contract.getReview(), font8n)); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); cell.setPadding(5); table.addCell(cell); cell = new PdfPCell(new Paragraph(contract.getRemark(), font12n)); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); cell.setPadding(5); table.addCell(cell); document.add(table); // Start a new page document.newPage(); HTMLWorker htmlWorker = new HTMLWorker(document); htmlWorker.parse(new StringReader(contract.getRemark())); // Start a new page document.newPage(); document.add(new Paragraph("Review Board", font18n)); document.add(new LineSeparator(0.5f, 100, null, 0, -5)); table = new PdfPTable(3); table.setWidthPercentage(100); cell = new PdfPCell(new Paragraph("Review Board", font18n)); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Paragraph("Version", font12n)); table.addCell(cell); cell = new PdfPCell(new Paragraph("Date", font12n)); table.addCell(cell); cell = new PdfPCell(new Paragraph("Review", font12n)); table.addCell(cell); for (HistoryContractEntity history : historyContractService.listing(contract)) { cell = new PdfPCell(new Paragraph(history.getVersion().toString(), font8n)); table.addCell(cell); cell = new PdfPCell(new Paragraph(history.getStartdate().toString(), font8n)); table.addCell(cell); cell = new PdfPCell(new Paragraph(history.getReview(), font8n)); table.addCell(cell); } document.add(table); document.close(); FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.reset(); response.addHeader("Content-Type", "application/force-download"); String filename = URLEncoder.encode(contract.getName() + ".pdf", "UTF-8"); // response.addHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + filename); response.getOutputStream().write(output.toByteArray()); response.getOutputStream().flush(); context.responseComplete(); context.renderResponse(); } catch (BadPdfFormatException | IOException ex) { Logger.getLogger(ContractServiceBean.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(ContractServiceBean.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.aryjr.nheengatu.util.TagsManager.java
License:Open Source License
public void doH4() { ((GraphicsState) states.get(states.size() - 1)).getFont().setSize(12); ((GraphicsState) states.get(states.size() - 1)).getFont().setStyle(Font.UNDERLINE); ((GraphicsState) states.get(states.size() - 1)).setSpacingBefore(6f); ((GraphicsState) states.get(states.size() - 1)).setSpacingAfter(6f); }
From source file:com.aryjr.nheengatu.util.TagsManager.java
License:Open Source License
public void doU() { ((GraphicsState) states.get(states.size() - 1)).getFont().setStyle(Font.UNDERLINE); }
From source file:com.bibisco.export.ITextExporter.java
License:GNU General Public License
@Override public void addText(String pStrText, TextFormatting pTextFormatting) { mLog.debug("Start addText(): " + pStrText); Font lFont = new Font(); lFont.setFamily(mFont.getFamilyname()); lFont.setSize(mFont.getSize());//from w ww . j ava 2 s . c om int lIntStyle = 0; if (pTextFormatting.bold) { lIntStyle = lIntStyle | Font.BOLD; } if (pTextFormatting.italic) { lIntStyle = lIntStyle | Font.ITALIC; } if (pTextFormatting.underline) { lIntStyle = lIntStyle | Font.UNDERLINE; } if (pTextFormatting.strike) { lIntStyle = lIntStyle | Font.STRIKETHRU; } lFont.setStyle(lIntStyle); Chunk lChunk = new Chunk(pStrText, lFont); if (mListItem != null) { mListItem.add(lChunk); } else if (mParagraph != null) { mParagraph.add(lChunk); } mLog.debug("End addText()"); }
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;/* www .j a va 2 s.c o m*/ 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.develog.utils.report.engine.export.JRPdfExporter.java
License:Open Source License
/** * *///from w ww. j a v a2 s . c o m protected Chunk getChunk(Map attributes, String text) throws JRException, DocumentException, IOException { JRFont jrFont = new JRBaseFont(attributes); BaseFont baseFont = null; Exception initialException = null; try { baseFont = BaseFont.createFont(jrFont.getPdfFontName(), jrFont.getPdfEncoding(), jrFont.isPdfEmbedded(), true, null, null); } catch (Exception e) { initialException = e; } if (baseFont == null) { byte[] bytes = null; try { bytes = JRLoader.loadBytesFromLocation(jrFont.getPdfFontName()); } catch (JRException e) { throw new JRException("Could not load the following font : " + "\npdfFontName : " + jrFont.getPdfFontName() + "\npdfEncoding : " + jrFont.getPdfEncoding() + "\nisPdfEmbedded : " + jrFont.isPdfEmbedded(), initialException); } baseFont = BaseFont.createFont(jrFont.getPdfFontName(), jrFont.getPdfEncoding(), jrFont.isPdfEmbedded(), true, bytes, null); } Color forecolor = (Color) attributes.get(TextAttribute.FOREGROUND); Color backcolor = (Color) attributes.get(TextAttribute.BACKGROUND); /* if (forecolor == null) { forecolor = Color.black; } */ Font font = new Font(baseFont, (float) jrFont.getSize(), //((jrFont.isBold())?Font.BOLD:0) + //((jrFont.isItalic())?Font.ITALIC:0) + (jrFont.isUnderline() ? Font.UNDERLINE : 0) | (jrFont.isStrikeThrough() ? Font.STRIKETHRU : 0), forecolor); Chunk chunk = new Chunk(text, font); if (backcolor != null) { chunk.setBackground(backcolor); } return chunk; }
From source file:com.dlya.facturews.DlyaPdfExporter2.java
License:Open Source License
/** * Creates a PDF font./* ww w . j av a 2 s . c om*/ * * @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.bookmarks.Anchor.java
License:Open Source License
public Anchor() throws Exception { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("anchor.pdf")); document.open();/* www.j a v a 2 s . c o m*/ // Code 1 Font font = new Font(); font.setColor(Color.BLUE); font.setStyle(Font.UNDERLINE); document.add(new Chunk("Chapter 1")); document.add(new Paragraph(new Chunk("Press here to go chapter 2", font).setLocalGoto("2")));// Code 2 document.newPage(); document.add(new Chunk("Chapter 2").setLocalDestination("2")); document.add(new Paragraph( new Chunk("http://www.geek-tutorials.com", font).setAnchor("http://www.geek-tutorials.com")));//Code 3 document.add( new Paragraph(new Chunk("Open outline.pdf chapter 3", font).setRemoteGoto("outline.pdf", "3")));//Code 4 document.close(); }
From source file:com.krawler.esp.handlers.PdfGenHandler.java
License:Open Source License
public static ByteArrayOutputStream getReceiptAcc1(String ackrecp) { ByteArrayOutputStream os = null; try {/*from ww w . j a va 2s .c o m*/ os = new ByteArrayOutputStream(); JSONObject jbj = new JSONObject(ackrecp); com.krawler.utils.json.base.JSONArray gridinfo = jbj.getJSONArray("items"); String ginfo[] = new String[gridinfo.length() * 2]; String ids[] = { "name", "receiptno", "paymentdate", "address" }; String currency = "USD"; // String address = jbj.getString("address"); String uinfo[] = new String[ids.length]; for (int i = 0; i < uinfo.length; i++) { uinfo[i] = jbj.getString(ids[i]); } Font font = FontFactory.getFont("Helvetica", 10, Font.BOLD, Color.BLACK); Font font1 = FontFactory.getFont("Helvetica", 14, Font.BOLD, Color.BLACK); Font font3 = FontFactory.getFont("Helvetica", 12, Font.BOLD, Color.BLACK); //Font font4 = FontFactory.getFont("Helvetica", 12, Font.NORMAL, Color.BLACK); Font font7 = FontFactory.getFont("Helvetica", 8, Font.BOLD, Color.BLACK); Font font10 = FontFactory.getFont("Helvetica", 12, Font.BOLD, Color.BLACK); Font font11 = FontFactory.getFont("Helvetica", 12, Font.NORMAL, Color.BLACK); Font font12 = FontFactory.getFont("Helvetica", 10, Font.NORMAL, Color.BLACK); Document document1 = new Document(PageSize.A4, 15, 15, 15, 15); PdfWriter writer = PdfWriter.getInstance(document1, os); HeaderFooter temp = new HeaderFooter(new Phrase( String.format("Note: This is a computer generated document and does not require signature"), font7), false); temp.setAlignment(Element.ALIGN_CENTER); document1.setFooter(temp); document1.open(); PdfPTable tableHinfo = new PdfPTable(1); PdfPTable table = new PdfPTable(1); font3.setStyle(Font.UNDERLINE); String cnxt = "";//StorageHandler.getProfileStorePath() + "/inceif-200.png"; PdfPCell cell1 = null; try { Image img = Image.getInstance(cnxt); // img.scalePercent(90); cell1 = new PdfPCell(img); } catch (Exception e) { cnxt = StorageHandler.GetProfileImgStorePath() + "/140-logo.png"; Image img = Image.getInstance(cnxt); cell1 = new PdfPCell(img); } cell1.setBorder(0); cell1.setPaddingTop(18); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); tableHinfo.addCell(cell1); tableHinfo = addspace(1, tableHinfo); tableHinfo = addspace(4, tableHinfo); cell1 = new PdfPCell(new Paragraph("RECEIPT", font1)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); tableHinfo.addCell(cell1); tableHinfo = addspace(0, tableHinfo); // cell1 = new PdfPCell(new Paragraph(uinfo[4], font11)); // cell1.setBorder(0); // cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); // tableHinfo.addCell(cell1); document1.add(tableHinfo); PdfPTable tableUinfo = new PdfPTable(1); cell1 = new PdfPCell(new Paragraph(receiptheading[0], font12)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); tableUinfo.addCell(cell1); cell1 = new PdfPCell(new Paragraph(uinfo[0], font10)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); tableUinfo.addCell(cell1); cell1 = new PdfPCell(new Paragraph(uinfo[3], font11)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); tableUinfo.addCell(cell1); document1.add(new Paragraph("\u00a0")); tableUinfo = addspace(1, tableUinfo); String hed[] = { "", "Receipt No : ", "Date : ", "" }; PdfPTable tableDinfo = new PdfPTable(1); //tableDinfo.setTotalWidth(100); for (int j = 1; j < 3; j++) { PdfPTable nested1 = new PdfPTable(3); cell1 = new PdfPCell(); cell1.setBorder(0); nested1.addCell(cell1); cell1 = new PdfPCell(new Paragraph(hed[j], font)); cell1.setBorder(0); nested1.addCell(cell1); cell1 = new PdfPCell(new Paragraph(uinfo[j], font12)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); nested1.addCell(cell1); cell1 = new PdfPCell(nested1); cell1.setBorder(0); tableDinfo.addCell(cell1); } PdfPTable container = new PdfPTable(2); cell1 = new PdfPCell(tableUinfo); cell1.setBorder(0); cell1.setPaddingBottom(15); container.addCell(cell1); cell1 = new PdfPCell(tableDinfo); cell1.setBorder(0); container.addCell(cell1); document1.add(container); PdfPTable table1 = new PdfPTable(2); String[] colwidth2 = { "Invoice No.", "Amount Paid($)" }; for (int i = 0; i < colwidth2.length; i++) { PdfPCell cell = new PdfPCell(new Paragraph(colwidth2[i], font)); if (i == 1) { cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorderWidthLeft(0); } else { cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthLeft(1); } cell.setBackgroundColor(Color.getHSBColor(0f, 0f, 0.9f)); cell.setPaddingBottom(5); cell.setBorderWidthRight(1); cell.setBorderWidthTop(1); table1.addCell(cell); } table1.setHeaderRows(1); double d = 0; colwidth2 = new String[] { "invoicenum", "amount" }; java.text.DecimalFormat df = new java.text.DecimalFormat("0.00"); for (int i = 0; i < gridinfo.length(); i++) { for (int j = 0; j < colwidth2.length; j++) { PdfPCell cell = null; if (j == 1) { cell = new PdfPCell(new Paragraph( df.format(Double.parseDouble(gridinfo.getJSONObject(i).getString(colwidth2[j]))), font12)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorderWidthLeft(0); } else { cell = new PdfPCell( new Paragraph(gridinfo.getJSONObject(i).getString(colwidth2[j]), font12)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthLeft(1); } //cell.setMinimumHeight(25); cell.setBorderWidthRight(1); cell.setPaddingTop(5); cell.setFixedHeight(100); table1.addCell(cell); if (j == colwidth2.length - 1) { d += Double.parseDouble(gridinfo.getJSONObject(i).getString(colwidth2[j])); } } } // EnglishDecimalFormat f1 = new EnglishDecimalFormat(); PdfPCell cell = new PdfPCell(new Paragraph("", font)); cell.setBorderWidthBottom(1); cell.setBorderWidthRight(0); cell.setBorderWidthLeft(1); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table1.addCell(cell); cell = new PdfPCell(new Paragraph("Total " + df.format(d), font)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); //cell.setPaddingBottom(15); cell.setPaddingLeft(15); cell.setPaddingBottom(5); cell.setBorderWidthBottom(1); cell.setBorderWidthLeft(0); cell.setBorderWidthRight(1); table1.addCell(cell); PdfPTable table3 = new PdfPTable(1); cell = new PdfPCell(new Paragraph("Amount in words : " + CurrencyConvert(currency, d), font)); //cell.setPaddingBottom(15); cell.setBorder(0); cell.setColspan(4); cell.setBorderWidthBottom(1); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); cell.setPaddingBottom(5); table3.addCell(cell); document1.add(table1); document1.add(table3); document1.add(new Paragraph("\u00a0")); cell = new PdfPCell(new Paragraph(String.format( "All payments are non-refundable and non-transferable. \nThis Receipt is valid subject to clearance of the payments."), font11)); //cell.setPaddingLeft(5); cell.setBorder(0); table.addCell(cell); // String delFlag = jbj.getString("delflag"); // if(delFlag.compareTo("2")==0){ // BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); // PdfContentByte cb = writer.getDirectContentUnder(); // cb.saveState(); // cb.setColorFill(Color.BLACK); // cb.beginText(); // cb.setFontAndSize(bf, 48); // cb.showTextAligned(Element.ALIGN_CENTER, "Canceled Payment", document1.getPageSize().getWidth() / 2, document1.getPageSize().getHeight() / 2, 45); // cb.endText(); // cb.restoreState(); // } document1.add(table); document1.close(); writer.close(); os.close(); } catch (Exception e) { System.out.println(e); } return os; }