Example usage for com.lowagie.text Annotation Annotation

List of usage examples for com.lowagie.text Annotation Annotation

Introduction

In this page you can find the example usage for com.lowagie.text Annotation Annotation.

Prototype

public Annotation(float llx, float lly, float urx, float ury, int named) 

Source Link

Document

Constructs an Annotation.

Usage

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 w ww.j  a v a 2 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);//from w  ww .  ja  v  a2s  . 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 www.j av a  2s .c o 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$
    }
}