Example usage for com.itextpdf.text.pdf PdfAnnotation HIGHLIGHT_INVERT

List of usage examples for com.itextpdf.text.pdf PdfAnnotation HIGHLIGHT_INVERT

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfAnnotation HIGHLIGHT_INVERT.

Prototype

PdfName HIGHLIGHT_INVERT

To view the source code for com.itextpdf.text.pdf PdfAnnotation HIGHLIGHT_INVERT.

Click Source Link

Document

highlight attributename

Usage

From source file:app.App.java

private void setLink(int pageId, PdfStamper stamper) throws ClassNotFoundException, IOException {
    // load the sqlite-JDBC driver using the current class loader
    Class.forName("org.sqlite.JDBC");

    Connection connection = null;
    try {/* w w w . j av a 2 s  .  c o m*/
        // create a database connection
        connection = DriverManager.getConnection("jdbc:sqlite:" + DATABASE);
        Statement statement = connection.createStatement();
        statement.setQueryTimeout(30); // set timeout to 30 sec.

        ResultSet rs = statement.executeQuery(
                "select * from page_annotations " + "where annotation_type = 'goto' and page_id = " + pageId);
        float spendX = 0;
        float spendY = 0;
        float coordX = 0;
        float coordY = 0;
        int pageDest = 0;
        Rectangle rect;
        PdfAnnotation annotation;
        while (rs.next()) {
            spendX = rs.getFloat("pdf_width");
            spendY = rs.getFloat("pdf_height");
            coordX = rs.getFloat("pdf_x");// + rs.getFloat("pdf_width");
            coordY = rs.getFloat("pdf_y");
            pageDest = rs.getInt("annotation_target");

            Font font = FontFactory.getFont(FontFactory.COURIER, 10, Font.UNDERLINE);
            // Blue
            font.setColor(0, 0, 255);
            Chunk chunk = new Chunk("GOTO", font);
            Anchor anchor = new Anchor(chunk);
            ColumnText.showTextAligned(stamper.getUnderContent(pageId), Element.ALIGN_LEFT, anchor,
                    coordX + spendX, coordY, 0);

            rect = new Rectangle(coordX, coordY, spendX, spendY);
            annotation = PdfAnnotation.createLink(stamper.getWriter(), rect, PdfAnnotation.HIGHLIGHT_INVERT,
                    new PdfAction("#" + pageDest));
            stamper.addAnnotation(annotation, pageId);
        }
    } catch (SQLException e) {
        // if the error message is "out of memory", 
        // it probably means no database file is found
        System.err.println(e.getMessage());
    } finally {
        try {
            if (connection != null)
                connection.close();
        } catch (SQLException e) {
            // connection close failed.
            System.err.println(e);
        }
    }
}

From source file:fc.extensions.itext.Writer.java

License:MIT License

/**
 * write PDF annotation for debugging./*  w  w w.  j a  va  2 s.c om*/
 */
public void writeAnnotation(String title, String content, float leftX, float bottomY, float rightX, float topY)
        throws Exception {
    try {
        pdfWriterCB.saveState();
        pdfWriterCB.setRGBColorStroke(255, 255, 0);
        pdfWriterCB.setLineWidth(1F);
        pdfWriterCB.rectangle(leftX, bottomY, rightX - leftX, topY - bottomY);
        pdfWriterCB.stroke();
        PdfFormField field = PdfFormField.createTextField(pdfWriter, false, false, 0);
        field.setWidget(new Rectangle(leftX, bottomY, rightX, topY), PdfAnnotation.HIGHLIGHT_INVERT);
        field.setFlags(PdfAnnotation.FLAGS_PRINT);
        field.setFieldName(title);
        field.setPage();
        field.setValueAsString(content);
        field.setBorderStyle(new PdfBorderDictionary(0.5F, PdfBorderDictionary.STYLE_DASHED));
        pdfWriter.addAnnotation(field);
    } finally {
        pdfWriterCB.restoreState();
    }
}

From source file:gov.nih.nci.firebird.service.registration.AbstractPdfWriterGenerator.java

License:Open Source License

private void addSignatureField() throws DocumentException {
    PdfFormField field = PdfFormField.createSignature(writer);
    Rectangle signatureFieldRectangle = new Rectangle(SIGNATURE_FIELD_LOWER_LEFT_X,
            SIGNATURE_FIELD_LOWER_LEFT_Y, SIGNATURE_FIELD_UPPER_RIGHT_X, SIGNATURE_FIELD_UPPER_RIGHT_Y);
    field.setWidget(signatureFieldRectangle, PdfAnnotation.HIGHLIGHT_INVERT);
    field.setFieldName("signature");
    field.setFlags(PdfAnnotation.FLAGS_PRINT);
    field.setPage();/*from w ww .  jav  a 2s .c o m*/
    field.setMKBorderColor(BaseColor.BLACK);
    field.setMKBackgroundColor(BaseColor.WHITE);
    PdfAppearance appearance = PdfAppearance.createAppearance(writer, SIGNATURE_FIELD_WIDTH,
            SIGNATURE_FIELD_HEIGHT);
    appearance.rectangle(SIGNATURE_FIELD_APPEARANCE_X, SIGNATURE_FIELD_APPEARANCE_Y,
            SIGNATURE_FIELD_APPEARANCE_WIDTH, SIGNATURE_FIELD_APPEARANCE_HEIGHT);
    appearance.stroke();
    field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, appearance);
    writer.addAnnotation(field);
}