List of usage examples for com.lowagie.text Image setAnnotation
public void setAnnotation(Annotation annotation)
From source file:ambit.data.qmrf.MyHandler.java
License:Open Source License
@Override public void handleStartingTags(String name, Properties attributes) { System.out.println(name);//from ww w . ja v a2 s . c o m if (Image.isTag(name)) { try { // Image img = Image.getInstance(attributes); System.out.println("ambit/data/qmrf/logo.png"); Image img = Image .getInstance(Qmrf_Xml_Pdf.class.getClassLoader().getResource("ambit/data/qmrf/logo.png")); Object current; try { // if there is an element on the stack... current = stack.pop(); // ...and it's a Chapter or a Section, the Image can be // added directly if (current instanceof Chapter || current instanceof Section || current instanceof Cell) { ((TextElementArray) current).add(img); stack.push(current); return; } // ...if not, the Image is wrapped in a Chunk before it's // added else { Stack newStack = new Stack(); try { while (!(current instanceof Chapter || current instanceof Section || current instanceof Cell)) { newStack.push(current); if (current instanceof Anchor) { img.setAnnotation(new Annotation(0, 0, 0, 0, ((Anchor) current).reference())); } current = stack.pop(); } ((TextElementArray) current).add(img); stack.push(current); } catch (EmptyStackException ese) { document.add(img); } while (!newStack.empty()) { stack.push(newStack.pop()); } return; } } catch (EmptyStackException ese) { // if there is no element on the stack, the Image is added // to the document try { document.add(img); } catch (DocumentException de) { throw new ExceptionConverter(de); } return; } } catch (Exception e) { throw new ExceptionConverter(e); } } else super.handleStartingTags(name, attributes); }
From source file:classroom.newspaper_a.Newspaper07.java
public static void putImage(PdfContentByte canvas, Image img, String url, float llx, float lly, float w, float h) throws DocumentException { img.scaleToFit(w, h);// www . j a v a 2 s. c o m float offsetX = (w - img.getScaledWidth()) / 2f; float offsetY = (h - img.getScaledHeight()) / 2f; img.setAbsolutePosition(llx + offsetX, lly + offsetY); img.setAnnotation(new Annotation(0, 0, 0, 0, url)); canvas.addImage(img); }
From source file:es.gob.afirma.signers.pades.PdfPreProcessor.java
License:Open Source License
/** Sobreimpone una imagen JPEG en un documento PDF. * @param jpegImage Imagen JPEG/*from w ww . jav a2 s . co m*/ * @param width Ancho de la imagen * @param height Alto de la imagen * @param left Distancia de la imagen al borde izquiero de la página del PDF * @param bottom Distancia de la imagen al borde inferior de la página del PDF * @param pageNum Número de página del PDF donde insertar la imagen * (la numeración comienza en 1) * @param url URL a la que enlazará la imagen si queremos que esta sea un hipervínculo * (puede ser <code>null</code>) * @param stp Estampador PDF de iText * @throws IOException En caso de errores de entrada / salida */ public static void addImage(final byte[] jpegImage, final int width, final int height, final int left, final int bottom, final int pageNum, final String url, final PdfStamper stp) throws IOException { final PdfContentByte content = stp.getOverContent(pageNum); try { final Image image = new Jpeg(jpegImage); if (url != null) { image.setAnnotation(new Annotation(0, 0, 0, 0, url)); } content.addImage(image, // Image width, // Image width 0, 0, height, // Image height left, // Lower left X position of the image bottom, // Lower left Y position of the image false // Inline ); } catch (final DocumentException e) { throw new IOException("Error durante la insercion de la imagen en el PDF: " + e, e); //$NON-NLS-1$ } }
From source file:jp.ac.utokyo.rcast.karkinos.graph.output.PdfReport.java
License:Apache License
private static void addObj(Document document, Object obj, int width, int hight, int size, PdfWriter writer, int figcount) throws Exception, IOException { if (obj instanceof JFreeChart) { JFreeChart chart = (JFreeChart) obj; BufferedImage bufferedImage = chart.createBufferedImage(width * size, hight * size); Image image = Image.getInstance(writer, bufferedImage, 1.0f); image.scalePercent(20);// www. j a v a 2 s. c o m image.setAnnotation(new Annotation("fig" + figcount, "karkinos fig" + figcount)); document.add(image); } else if (obj instanceof Element) { document.add((Element) obj); } else if (obj instanceof java.awt.Image) { java.awt.Image aim = (java.awt.Image) obj; Image image = Image.getInstance(writer, aim, 1.0f); image.scalePercent(50); document.add(image); } else { document.add(new Paragraph(String.valueOf(obj))); } }