Example usage for com.itextpdf.text Image setAnnotation

List of usage examples for com.itextpdf.text Image setAnnotation

Introduction

In this page you can find the example usage for com.itextpdf.text Image setAnnotation.

Prototype

public void setAnnotation(final Annotation annotation) 

Source Link

Document

Sets the annotation of this Image.

Usage

From source file:com.vectorprint.report.itext.debug.DebugHelper.java

License:Open Source License

/**
 * When in debugging mode, adds a border to the image and calls {@link VectorPrintDocument#addHook(com.vectorprint.report.itext.VectorPrintDocument.AddElementHook)
 * } to be able to print debugging info and link for the image
 *
 * @param canvas/*from  w w w .ja va  2 s  .com*/
 * @param img
 * @param bordercolor
 * @param styleClass
 * @param extraInfo
 * @param settings
 * @param layerAware
 * @param document
 */
public static void debugImage(PdfContentByte canvas, Image img, Color bordercolor, String styleClass,
        String extraInfo, EnhancedMap settings, LayerManager layerAware, VectorPrintDocument document) {
    if (null != img) {
        img.setBorder(Rectangle.BOX);
        img.setBorderWidth(0.3f);
        img.setBorderColor(itextHelper.fromColor(bordercolor));
        if (styleClass == null) {
            log.warning("not showing link to styleClass because there is no styleClass");
            return;
        }
        img.setAnnotation(new Annotation(DEBUG,
                "click for link to styleClass information (" + styleClass + extraInfo + ")"));
        document.addHook(new VectorPrintDocument.AddElementHook(
                VectorPrintDocument.AddElementHook.INTENTION.DEBUGIMAGE, img, null, styleClass));
    }
}

From source file:EplanPrinter.PDFPrint.java

License:Open Source License

public String insertComment(String sx, String sy, String id, String deptValue, String userInit, String comment,
        int pageNum, int masterHeight, int masterWidth, int pinned, int customFontSize)
        throws DocumentException, IOException {
    float ratio = getRatio(masterHeight, masterWidth, pageNum);
    float x = Float.parseFloat(sx);
    float y = Float.parseFloat(sy);
    float[] f = commentTrans(x, y, masterHeight, masterWidth, pageNum);
    PdfGState gs1 = new PdfGState();
    gs1.setFillOpacity(1);/*from   w ww.  j  a  v a 2  s.  c om*/
    if (customFontSize > 0)
        fontSize = customFontSize;

    PdfContentByte fg = pds.getOverContent(pageNum);
    fg.setGState(gs1);
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    float[] trans = translate(x, y, r[pageNum - 1].getHeight(), r[pageNum - 1].getWidth(), masterHeight,
            masterWidth, pageNum);
    // comment tag image (width=35pts, height=8pts)
    float[] scalar = scale(trans[0], trans[1], 35, 8, masterHeight, masterWidth, pageNum);

    /* Addition. ftorres - 7/21/2015 - Added to account for rotated pages 
     *   with the origin (0,0) not set to the bottom-left of the page. [1400] */
    float coords[] = translateRotation(trans[0], trans[1], pageNum);
    coords = checkBounds(coords[0], coords[1], pageNum);

    /* Addition. ftorres - 10/20/2015 - If the comment was pinned in EPC, then
     *   render the comment inside a comment box. */
    if (pinned == 1) {
        insertPinnedComment(coords[0], coords[1], id + " - " + deptValue + " (" + userInit + ")", comment,
                pageNum, masterHeight, masterWidth);

        // Add the pinned comment text to page annotation -Jon Changkachith 11/24/2015
        Rectangle rect = new Rectangle(0, 0, 0, 0);
        PdfAnnotation annotation = PdfAnnotation.createText(pds.getWriter(), rect,
                id + " - " + deptValue + " (" + userInit + ")", cleanupComment(comment), true, id);
        pds.addAnnotation(annotation, pds.getWriter().getCurrentPageNumber());
    } else {
        Image image = Image.getInstance(commentIMGPath);
        image.setAbsolutePosition(coords[0] + (scalar[0] * (id.length() / 5f)), coords[1]);

        /*
         * Commented out by Jon Changkachith 12/09/2015 because it was throwing
         * DocumentException with the message "The image must have absolute positioning."
        image.scaleAbsoluteHeight(1);
        image.scaleAbsoluteWidth(1);
        */
        image.scalePercent(ratio); //Added to fix DocumentException "The image must have absolute positioning." Jon Changkachith 12/09/2015
        image.setAnnotation(new Annotation(id + " - " + deptValue + " (" + userInit + ")",
                cleanupComment(comment), 0, 0, 0, 0));
        fg.addImage(image);
    }

    fg.setLineWidth(.5f * ratio);
    fg.setColorStroke(new BaseColor(Color.decode("0x6E2405").getRGB()));
    fg.setColorFill(new BaseColor(Color.decode("0x6E2405").getRGB()));

    float tHeight = scalar[1];
    float tWidth = 0;
    if (id.length() > 3) {
        tWidth = (scalar[0] * (id.length() / 5f));
    } else {
        tWidth = (scalar[0]);
    }

    fg.moveTo(coords[0], coords[1]);
    fg.lineTo(coords[0] + (10f * ratio), coords[1] - (tHeight / 2));
    fg.lineTo(coords[0] + tWidth, coords[1] - (tHeight / 2));
    fg.lineTo(coords[0] + tWidth, coords[1] + (tHeight / 2));
    fg.lineTo(coords[0] + (10f * ratio), coords[1] + (tHeight / 2));

    fg.lineTo(coords[0], coords[1]);
    fg.closePathFillStroke();
    fg.fill();

    // Comment number that goes on the comment tag image
    Phrase p = new Phrase(id);
    p.getFont().setColor(BaseColor.WHITE);
    p.getFont().setSize(8f * ratio); //comment number font size = 8f
    //p.getChunks().get(0).setAnnotation(PdfAnnotation.createText(pds.getWriter(), new Rectangle(trans[0],trans[1], trans[0]+5f, trans[1]+5f), id, comment, true, id));

    float fs[] = translateRotation(f[0], f[1], pageNum);
    fs = checkBounds(fs[0], fs[1], pageNum);
    ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, p, (float) (fs[0] + (9 * ratio)),
            (float) (fs[1] - (3 * ratio)), 0);

    return "";
}

From source file:org.opentox.io.publishable.PDFObject.java

License:Open Source License

public void publish(YaqpIOStream stream) throws YaqpException {
    if (stream == null) {
        throw new NullPointerException("Cannot public pdf to a null output stream");
    }/* w ww .j a  v a  2 s . c  o  m*/
    try {
        Document doc = new Document();
        try {
            PdfWriter.getInstance(doc, (OutputStream) stream.getStream());
        } catch (ClassCastException ex) {
            throw new ClassCastException("The stream you provided is not a valid output stream");
        }
        doc.open();
        doc.addAuthor(pdfAuthor);
        doc.addCreationDate();
        doc.addProducer();
        doc.addSubject(subject);
        doc.addCreator(pdfCreator);
        doc.addTitle(pdfTitle);
        doc.addKeywords(pdfKeywords);
        doc.addHeader("License", "GNU GPL v3");
        Image image = null;
        try {
            image = Image.getInstance(new URL(OpenToxLogoUrl));
        } catch (Exception ex) {// OpenTox Logo was not found on the web...
            try {// use the cached image instead
                YaqpLogger.LOG.log(new Trace(getClass(), "OpenTox Logo not found at " + OpenToxLogoUrl));
                image = Image.getInstance(alternativeLogoPath);
            } catch (Exception ex1) {// if no image at local folder
                YaqpLogger.LOG.log(new Debug(getClass(),
                        "OpenTox Logo not found at " + alternativeLogoPath + " :: " + ex1));
            }
        }
        if (image != null) {
            image.scalePercent(40);
            image.setAnnotation(new Annotation(0, 0, 0, 0, "http://opentox.org"));
            Chunk ck_ot = new Chunk(image, -5, -30);
            doc.add(ck_ot);
        }
        try {
            Image yaqp = Image.getInstance(yaqpLogo);
            yaqp.scalePercent(30);
            yaqp.setAnnotation(new Annotation(0, 0, 0, 0, "https://opentox.ntua.gr"));
            yaqp.setAlt("YAQP(R), yet another QSAR Project");
            Chunk ck_yaqp = new Chunk(yaqp, 15, -30);
            doc.add(ck_yaqp);
        } catch (Exception ex) {
            YaqpLogger.LOG
                    .log(new Warning(getClass(), "YAQP Logo not found at " + kinkyDesignLogo + " :: " + ex));
        }
        doc.add(new Paragraph("\n\n\n"));
        for (Element e : elements) {
            doc.add(e);
        }
        doc.close();
    } catch (DocumentException ex) {
        String message = "Error while generating PDF representation.";
        YaqpLogger.LOG.log(new Warning(getClass(), message));
        throw new YaqpException(XPDF18, message, ex);
    }

}