@SuppressWarnings("BooleanMethodIsAlwaysInverted") private boolean placeAnnotation(AffineTransform transform, Shape linkShape, Rectangle2D targetArea, PDAnnotationLink annot) { annot.setRectangle(new PDRectangle((float) targetArea.getMinX(), (float) targetArea.getMinY(), (float) targetArea.getWidth(), (float) targetArea.getHeight())); if (linkShape != null) { float[] quadPoints = mapShapeToQuadPoints(transform, linkShape, targetArea); /* * Is this not an area shape? Then we can not setup quads - ignore this shape. */ if (quadPoints.length == 0) return false; annot.setQuadPoints(quadPoints); } return true; }
@SuppressWarnings("BooleanMethodIsAlwaysInverted") private boolean placeAnnotation(AffineTransform transform, Shape linkShape, Rectangle2D targetArea, PDAnnotationLink annot) { annot.setRectangle(new PDRectangle((float) targetArea.getMinX(), (float) targetArea.getMinY(), (float) targetArea.getWidth(), (float) targetArea.getHeight())); if (linkShape != null) { float[] quadPoints = mapShapeToQuadPoints(transform, linkShape, targetArea); /* * Is this not an area shape? Then we can not setup quads - ignore this shape. */ if (quadPoints.length == 0) return false; annot.setQuadPoints(quadPoints); } return true; }
@SuppressWarnings("BooleanMethodIsAlwaysInverted") private boolean placeAnnotation(AffineTransform transform, Shape linkShape, Rectangle2D targetArea, PDAnnotationLink annot) { annot.setRectangle(new PDRectangle((float) targetArea.getMinX(), (float) targetArea.getMinY(), (float) targetArea.getWidth(), (float) targetArea.getHeight())); if (linkShape != null) { float[] quadPoints = mapShapeToQuadPoints(transform, linkShape, targetArea); /* * Is this not an area shape? Then we can not setup quads - ignore this shape. */ if (quadPoints.length == 0) return false; annot.setQuadPoints(quadPoints); } return true; }
position.setUpperRightX(INCH + textWidth); position.setUpperRightY(ph - 1.5f * INCH); txtLink.setRectangle(position); position.setUpperRightX(INCH + textWidth); position.setUpperRightY(ph - 2 * INCH); pageLink.setRectangle(position);
rect.setUpperRightX(quads[2]); rect.setUpperRightY(quads[1]); txtLink.setRectangle(rect);
private PDRectangle addAnnotationLinkRectangle(final float x, final float y, final float width, final float height, final String linkURL) throws IOException { final float startingY = checkYAndSwitchPage(y, height); final PDAnnotationLink txtLink = new PDAnnotationLink(); final PDRectangle position = new PDRectangle(); position.setLowerLeftX(x); position.setLowerLeftY(startingY); position.setUpperRightX(x + width); position.setUpperRightY(startingY + height); txtLink.setRectangle(position); final PDActionURI action = new PDActionURI(); action.setURI(linkURL); txtLink.setAction(action); currentPage.getAnnotations().add(txtLink); return new PDRectangle(x, startingY, width, height); }
PDBorderStyleDictionary borderULine = new PDBorderStyleDictionary(); borderULine.setStyle(PDBorderStyleDictionary.STYLE_UNDERLINE); borderULine.setWidth(1); PDAnnotationLink txtLink = new PDAnnotationLink(); txtLink.setBorderStyle(borderULine); // Set the rectangle containing the link textWidth = font.getStringWidth("Click here") / 1000 * xscale; position = new PDRectangle(); position.setLowerLeftX(...); position.setLowerLeftY(...); position.setUpperRightX(...); position.setUpperRightY(...); txtLink.setRectangle(position); // add an action PDActionURI action = new PDActionURI(); action.setURI("http://pdfbox.apache.org"); txtLink.setAction(action); annotations.add(txtLink);
position.setUpperRightX(x + textWidth); position.setUpperRightY(y + 12); link.setRectangle(position);
position.setUpperRightX(INCH + textWidth); position.setUpperRightY(ph - 1.5f * INCH); txtLink.setRectangle(position); position.setUpperRightX(INCH + textWidth); position.setUpperRightY(ph - 2 * INCH); pageLink.setRectangle(position);