pdfboxprototype.Comment.java Source code

Java tutorial

Introduction

Here is the source code for pdfboxprototype.Comment.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pdfboxprototype;

import java.awt.Color;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;

/**
 *
 * @author Rob
 */
public class Comment extends Annotation {
    /**
     * String content of Comment
     */
    private String content;

    /**
     * Empty constructor
     */
    public Comment() {
        this.content = "Comment";
    }

    /**
     * Constructor for Comment
     *
     * @param x
     * @param y
     * @param text
     */
    public Comment(int x, int y, String text) {
        this.x = x;
        this.y = y;
        this.content = text;
        this.rectangle = new PDRectangle();
    }

    /**
     * Draw method
     *
     * @param contentStream
     */
    @Override
    public void draw(PDPageContentStream contentStream) {
        try {
            //PDFont font = PDType1Font.HELVETICA_BOLD;
            contentStream.beginText();
            //contentStream.setFont(font, 24);
            contentStream.setNonStrokingColor(Color.blue);
            contentStream.moveTextPositionByAmount(this.x, this.y);
            contentStream.drawString(this.content);
            contentStream.endText();
        } catch (IOException ex) {
            Logger.getLogger(Cross.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}