/** * Get the length or width of the text, based on a given rotation. * * @param rotation Rotation that was used to determine coordinates (0,90,180,270) * @return Width of text in display units */ private float getWidthRot(float rotation) { if (Float.compare(rotation, 90) == 0 || Float.compare(rotation, 270) == 0) { return Math.abs(endY - textMatrix.getTranslateY()); } else { return Math.abs(endX - textMatrix.getTranslateX()); } }
/** * Return the X starting coordinate of the text, adjusted by the given rotation amount. * The rotation adjusts where the 0,0 location is relative to the text. * * @param rotation Rotation to apply (0, 90, 180, or 270). 0 will perform no adjustments. * @return X coordinate */ private float getXRot(float rotation) { if (Float.compare(rotation, 0) == 0) { return textMatrix.getTranslateX(); } else if (Float.compare(rotation, 90) == 0) { return textMatrix.getTranslateY(); } else if (Float.compare(rotation, 180) == 0) { return pageWidth - textMatrix.getTranslateX(); } else if (Float.compare(rotation, 270) == 0) { return pageHeight - textMatrix.getTranslateY(); } return 0; }
/** * This will get the y position of the character with 0,0 in lower left. * This will be adjusted by the given rotation. * * @param rotation Rotation to apply to text to adjust the 0,0 location (0,90,180,270) * @return The y coordinate of the text */ private float getYLowerLeftRot(float rotation) { if (Float.compare(rotation, 0) == 0) { return textMatrix.getTranslateY(); } else if (Float.compare(rotation, 90) == 0) { return pageWidth - textMatrix.getTranslateX(); } else if (Float.compare(rotation, 180) == 0) { return pageHeight - textMatrix.getTranslateY(); } else if (Float.compare(rotation, 270) == 0) { return textMatrix.getTranslateX(); } return 0; }
System.out.println("position in PDF = " + ctmNew.getTranslateX() + ", " + ctmNew.getTranslateY() + " in user space units");
float nextX = nextTextRenderingMatrix.getTranslateX(); float nextY = nextTextRenderingMatrix.getTranslateY(); float dxDisplay = nextX - textRenderingMatrix.getTranslateX(); float dyDisplay = height * textRenderingMatrix.getScalingFactorY();
/** * Get the length or width of the text, based on a given rotation. * * @param rotation Rotation that was used to determine coordinates (0,90,180,270) * @return Width of text in display units */ private float getWidthRot(float rotation) { if (rotation == 90 || rotation == 270) { return Math.abs(endY - textMatrix.getTranslateY()); } else { return Math.abs(endX - textMatrix.getTranslateX()); } }
/** * Get the length or width of the text, based on a given rotation. * * @param rotation Rotation that was used to determine coordinates (0,90,180,270) * @return Width of text in display units */ private float getWidthRot(float rotation) { if (rotation == 90 || rotation == 270) { return Math.abs(endY - textMatrix.getTranslateY()); } else { return Math.abs(endX - textMatrix.getTranslateX()); } }
/** * This will get the y position of the character with 0,0 in lower left. * This will be adjusted by the given rotation. * * @param rotation Rotation to apply to text to adjust the 0,0 location (0,90,180,270) * @return The y coordinate of the text */ private float getYLowerLeftRot(float rotation) { if (rotation == 0) { return textMatrix.getTranslateY(); } else if (rotation == 90) { return pageWidth - textMatrix.getTranslateX(); } else if (rotation == 180) { return pageHeight - textMatrix.getTranslateY(); } else if (rotation == 270) { return textMatrix.getTranslateX(); } return 0; }
/** * Return the X starting coordinate of the text, adjusted by the given rotation amount. * The rotation adjusts where the 0,0 location is relative to the text. * * @param rotation Rotation to apply (0, 90, 180, or 270). 0 will perform no adjustments. * @return X coordinate */ private float getXRot(float rotation) { if (rotation == 0) { return textMatrix.getTranslateX(); } else if (rotation == 90) { return textMatrix.getTranslateY(); } else if (rotation == 180) { return pageWidth - textMatrix.getTranslateX(); } else if (rotation == 270) { return pageHeight - textMatrix.getTranslateY(); } return 0; }
/** * This will get the y position of the character with 0,0 in lower left. * This will be adjusted by the given rotation. * * @param rotation Rotation to apply to text to adjust the 0,0 location (0,90,180,270) * @return The y coordinate of the text */ private float getYLowerLeftRot(float rotation) { if (rotation == 0) { return textMatrix.getTranslateY(); } else if (rotation == 90) { return pageWidth - textMatrix.getTranslateX(); } else if (rotation == 180) { return pageHeight - textMatrix.getTranslateY(); } else if (rotation == 270) { return textMatrix.getTranslateX(); } return 0; }
/** * Return the X starting coordinate of the text, adjusted by the given rotation amount. * The rotation adjusts where the 0,0 location is relative to the text. * * @param rotation Rotation to apply (0, 90, 180, or 270). 0 will perform no adjustments. * @return X coordinate */ private float getXRot(float rotation) { if (rotation == 0) { return textMatrix.getTranslateX(); } else if (rotation == 90) { return textMatrix.getTranslateY(); } else if (rotation == 180) { return pageWidth - textMatrix.getTranslateX(); } else if (rotation == 270) { return pageHeight - textMatrix.getTranslateY(); } return 0; }
Matrix ctmNew = getGraphicsState().getCurrentTransformationMatrix(); float imageXScale = ctmNew.getScalingFactorX(); float imageYScale = ctmNew.getScalingFactorY(); // position in user space units. 1 unit = 1/72 inch at 72 dpi System.out.println("position in PDF = " + ctmNew.getTranslateX() + ", " + ctmNew.getTranslateY() + " in user space units");
/** * Transforms a length according to the current transformation matrix. */ protected float transformLength(float w) { Matrix ctm = getGraphicsState().getCurrentTransformationMatrix(); Matrix m = new Matrix(); m.setValue(2, 0, w); return m.multiply(ctm).getTranslateX(); }
System.out.println("position in PDF = " + ctmNew.getTranslateX() + ", " + ctmNew.getTranslateY() + " in user space units");
@Override protected void processOperator(Operator operator, List<COSBase> operands) throws IOException { String operation = operator.getName(); if ("Do".equals(operation)) { COSName objectName = (COSName)operands.get(0); PDXObject xobject = getResources().getXObject(objectName); if (xobject instanceof PDImageXObject) { PDImageXObject image = (PDImageXObject)xobject; Matrix ctmNew = getGraphicsState().getCurrentTransformationMatrix(); PDRectangle pageRect = this.getCurrentPage().getCropBox(); float w = ctmNew.getScalingFactorX(); float h = ctmNew.getScalingFactorY(); float x = ctmNew.getTranslateX(); float y = pageRect.getHeight() - ctmNew.getTranslateY() - h; buffer.add(new ImageOperator(x, y, w, h)); } else if (xobject instanceof PDFormXObject) { PDFormXObject form = (PDFormXObject)xobject; showForm(form); } } else { super.processOperator(operator, operands); } } }
Matrix td = Matrix.getTranslateInstance(tx, ty); Matrix nextTextRenderingMatrix = td.multiply(textMatrix).multiply(ctm); float nextX = nextTextRenderingMatrix.getTranslateX(); float nextY = nextTextRenderingMatrix.getTranslateY(); float dxDisplay = nextX - textRenderingMatrix.getTranslateX(); float dyDisplay = height * textRenderingMatrix.getScalingFactorY(); float glyphSpaceToTextSpaceFactor = 0.001F;
float nextX = nextTextRenderingMatrix.getTranslateX(); float nextY = nextTextRenderingMatrix.getTranslateY(); float dxDisplay = nextX - textRenderingMatrix.getTranslateX(); float dyDisplay = height * textRenderingMatrix.getScalingFactorY();
float nextX = nextTextRenderingMatrix.getTranslateX(); float nextY = nextTextRenderingMatrix.getTranslateY(); float dxDisplay = nextX - textRenderingMatrix.getTranslateX(); float dyDisplay = height * textRenderingMatrix.getScalingFactorY();
float nextX = nextTextRenderingMatrix.getTranslateX(); float nextY = nextTextRenderingMatrix.getTranslateY(); float dxDisplay = nextX - textRenderingMatrix.getTranslateX(); float dyDisplay = height * textRenderingMatrix.getScalingFactorY();