Example usage for com.lowagie.text.pdf PdfAnnotation setAppearance

List of usage examples for com.lowagie.text.pdf PdfAnnotation setAppearance

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfAnnotation setAppearance.

Prototype

public void setAppearance(PdfName ap, PdfTemplate template) 

Source Link

Usage

From source file:classroom.newspaper_b.Newspaper08.java

public static void main(String[] args) {
    try {/*from   w w w. ja  va2s  .  co  m*/
        PdfReader reader = new PdfReader(NEWSPAPER);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));

        PdfAnnotation annotation1 = PdfAnnotation.createText(stamper.getWriter(),
                new Rectangle(LLX1, LLY1, URX1, URY1), "Advertisement 1", MESSAGE, false, "Insert");
        PdfAppearance ap = stamper.getOverContent(1).createAppearance(W1, H1);
        ap.setRGBColorStroke(0xFF, 0x00, 0x00);
        ap.setLineWidth(3);
        ap.moveTo(0, 0);
        ap.lineTo(W1, H1);
        ap.moveTo(W1, 0);
        ap.lineTo(0, H1);
        ap.stroke();
        annotation1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, ap);
        stamper.addAnnotation(annotation1, 1);

        PdfAnnotation annotation2 = PdfAnnotation.createText(stamper.getWriter(),
                new Rectangle(LLX2, LLY2, URX2, URY2), "Advertisement 2", MESSAGE, true, "Insert");
        annotation2.put(PdfName.C, new PdfArray(new float[] { 0, 0, 1 }));
        stamper.addAnnotation(annotation2, 1);

        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfLogicalPageDrawable.java

License:Open Source License

protected void drawHyperlink(final RenderNode box, final String target, final String window,
        final String title) {
    if (box.isNodeVisible(getDrawArea()) == false) {
        return;/*  w w w .j  ava2  s. com*/
    }

    final PdfAction action = createActionForLink(target);

    final AffineTransform affineTransform = getGraphics().getTransform();
    final float translateX = (float) affineTransform.getTranslateX();

    final float leftX = translateX + (float) (StrictGeomUtility.toExternalValue(box.getX()));
    final float rightX = translateX + (float) (StrictGeomUtility.toExternalValue(box.getX() + box.getWidth()));
    final float lowerY = (float) (globalHeight
            - StrictGeomUtility.toExternalValue(box.getY() + box.getHeight()));
    final float upperY = (float) (globalHeight - StrictGeomUtility.toExternalValue(box.getY()));

    if (action != null) {
        final PdfAnnotation annotation = new PdfAnnotation(writer, leftX, lowerY, rightX, upperY, action);
        writer.addAnnotation(annotation);
    } else if (StringUtils.isEmpty(title) == false) {
        final Rectangle rect = new Rectangle(leftX, lowerY, rightX, upperY);
        final PdfAnnotation commentAnnotation = PdfAnnotation.createText(writer, rect, "Tooltip", title, false,
                null);
        commentAnnotation.setAppearance(PdfAnnotation.APPEARANCE_NORMAL,
                writer.getDirectContent().createAppearance(rect.getWidth(), rect.getHeight()));
        writer.addAnnotation(commentAnnotation);
    }
}