Java tutorial
/* * 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.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; /** * * @author Rob */ public class Cross extends Annotation { /** * Empty constructor */ public Cross() { } public Cross(int x, int y) { this.x = x; this.y = y; this.rectangle = new PDRectangle(); } /** * Constructor for Cross * * @param x * @param y * @param page */ public Cross(int x, int y, PDPage page) { this.x = x; this.y = y; this.page = page; this.rectangle = new PDRectangle(); } /** * Draw method * * @param contentStream */ @Override public void draw(PDPageContentStream contentStream) { try { //float pw = this.page.getMediaBox().getUpperRightX(); //float ph = this.page.getMediaBox().getUpperRightY(); //rectangle.setLowerLeftX((int) ((double) this.x / getImageBufWidth() * pw)); //rectangle.setLowerLeftY((int) (ph - (double) this.y / getImageBufHeight() * ph)); //rectangle.setUpperRightX((int) ((double) e.getX() / getImageBufWidth() * pw)); //rectangle.setUpperRightY((int) (ph - (double) e.getY() / getImageBufHeight() * ph)); contentStream.setStrokingColor(Color.red); contentStream.drawLine(this.x, this.y, this.x + 20, this.y - 20); contentStream.drawLine(this.x + 20, this.y, this.x, this.y - 20); contentStream.close(); } catch (IOException ex) { Logger.getLogger(Cross.class.getName()).log(Level.SEVERE, null, ex); } } }