List of usage examples for com.lowagie.text Image setAlt
public void setAlt(String alt)
From source file:be.fedict.eid.applet.service.impl.PdfGenerator.java
License:Open Source License
/** * Create a PDF image from eID photo/*from w ww . j a v a 2 s .c om*/ * * @param photoData raw bytes * @return PDF image * @throws IOException * @throws BadElementException */ private Image createImageFromPhoto(byte[] photoData) throws IOException, BadElementException { Image image = Image.getInstance(photoData); image.setAlt("Photo"); image.setAlignment(Element.ALIGN_CENTER); image.setSpacingAfter(20); return image; }
From source file:com.amphisoft.epub2pdf.content.XhtmlHandler.java
License:Open Source License
private void handleImage(String url, String alt, String borderWidth, String alignment) throws DocumentException { float marginTopPt = document.topMargin(); float marginBottomPt = document.bottomMargin(); float marginLeftPt = document.leftMargin(); float marginRightPt = document.rightMargin(); if (url == null) return;//from ww w.j a v a 2 s.co m Image img = null; String imgSimpleName = ""; try { File imgFile = new File(xhtmlDir, url); String imgPath = imgFile.getCanonicalPath(); imgSimpleName = imgFile.getName(); img = Image.getInstance(imgPath); if (alt == null) { alt = imgSimpleName; } img.setAlt(alt); } catch (Exception e) { printlnerr("epub2pdf: problem adding image " + imgSimpleName + ": " + e.getMessage()); return; } if (borderWidth != null) { int border = Integer.parseInt(borderWidth); if (border == 0) { img.setBorder(Image.NO_BORDER); } else { img.setBorder(Image.BOX); img.setBorderWidth(border); } } if (alignment != null) { int align = Image.DEFAULT; if (ElementTags.ALIGN_LEFT.equalsIgnoreCase(alignment)) align = Image.LEFT; else if (ElementTags.ALIGN_RIGHT.equalsIgnoreCase(alignment)) align = Image.RIGHT; else if (ElementTags.ALIGN_MIDDLE.equalsIgnoreCase(alignment)) align = Image.MIDDLE; img.setAlignment(align | Image.TEXTWRAP); } else { img.setAlignment(Image.MIDDLE); } Rectangle pageRect = document.getPageSize(); float verticalMarginTotal = marginTopPt + marginBottomPt; float horizontalMarginTotal = marginLeftPt + marginRightPt; float imgMaxWidth = pageRect.getWidth() - horizontalMarginTotal - 2; float imgMaxHeight = pageRect.getHeight() - verticalMarginTotal - 2; float imgOrigWidth = img.getWidth(); float imgOrigHeight = img.getHeight(); if (imgOrigHeight > imgMaxHeight || imgOrigWidth > imgMaxWidth) { img.scaleToFit(imgMaxWidth, imgMaxHeight); } boolean addOK = addToDocument(img); if (!addOK) { System.err.println("** addToDocument(" + img.getUrl() + ") returned false"); } }