本文整理汇总了Java中org.apache.pdfbox.pdmodel.common.PDRectangle.getUpperRightY方法的典型用法代码示例。如果您正苦于以下问题:Java PDRectangle.getUpperRightY方法的具体用法?Java PDRectangle.getUpperRightY怎么用?Java PDRectangle.getUpperRightY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.pdmodel.common.PDRectangle
的用法示例。
在下文中一共展示了PDRectangle.getUpperRightY方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRotateMoveBox
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/40611736/rotate-pdf-around-its-center-using-pdfbox-in-java">
* Rotate PDF around its center using PDFBox in java
* </a>
* <p>
* This test shows how to rotate the page content and then move its crop box and
* media box accordingly to make it appear as if the content was rotated around
* the center of the crop box.
* </p>
*/
@Test
public void testRotateMoveBox() throws IOException
{
try ( InputStream resource = getClass().getResourceAsStream("IRJET_Copy_Right_form.pdf") )
{
PDDocument document = PDDocument.load(resource);
PDPage page = document.getDocumentCatalog().getPages().get(0);
PDPageContentStream cs = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false, false);
Matrix matrix = Matrix.getRotateInstance(Math.toRadians(45), 0, 0);
cs.transform(matrix);
cs.close();
PDRectangle cropBox = page.getCropBox();
float cx = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2;
float cy = (cropBox.getLowerLeftY() + cropBox.getUpperRightY()) / 2;
Point2D.Float newC = matrix.transformPoint(cx, cy);
float tx = (float)newC.getX() - cx;
float ty = (float)newC.getY() - cy;
page.setCropBox(new PDRectangle(cropBox.getLowerLeftX() + tx, cropBox.getLowerLeftY() + ty, cropBox.getWidth(), cropBox.getHeight()));
PDRectangle mediaBox = page.getMediaBox();
page.setMediaBox(new PDRectangle(mediaBox.getLowerLeftX() + tx, mediaBox.getLowerLeftY() + ty, mediaBox.getWidth(), mediaBox.getHeight()));
document.save(new File(RESULT_FOLDER, "IRJET_Copy_Right_form-rotated-move-box.pdf"));
}
}
示例2: testRotateCenter
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/40611736/rotate-pdf-around-its-center-using-pdfbox-in-java">
* Rotate PDF around its center using PDFBox in java
* </a>
* <p>
* This test shows how to rotate the page content around the center of its crop box.
* </p>
*/
@Test
public void testRotateCenter() throws IOException
{
try ( InputStream resource = getClass().getResourceAsStream("IRJET_Copy_Right_form.pdf") )
{
PDDocument document = PDDocument.load(resource);
PDPage page = document.getDocumentCatalog().getPages().get(0);
PDPageContentStream cs = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false, false);
PDRectangle cropBox = page.getCropBox();
float tx = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2;
float ty = (cropBox.getLowerLeftY() + cropBox.getUpperRightY()) / 2;
cs.transform(Matrix.getTranslateInstance(tx, ty));
cs.transform(Matrix.getRotateInstance(Math.toRadians(45), 0, 0));
cs.transform(Matrix.getTranslateInstance(-tx, -ty));
cs.close();
document.save(new File(RESULT_FOLDER, "IRJET_Copy_Right_form-rotated-center.pdf"));
}
}
示例3: testRotateCenterScale
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/40611736/rotate-pdf-around-its-center-using-pdfbox-in-java">
* Rotate PDF around its center using PDFBox in java
* </a>
* <p>
* This test shows how to rotate the page content around the center of its crop box
* and then crop it to make all previously visible content fit.
* </p>
*/
@Test
public void testRotateCenterScale() throws IOException
{
try ( InputStream resource = getClass().getResourceAsStream("IRJET_Copy_Right_form.pdf") )
{
PDDocument document = PDDocument.load(resource);
PDPage page = document.getDocumentCatalog().getPages().get(0);
PDPageContentStream cs = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false, false);
Matrix matrix = Matrix.getRotateInstance(Math.toRadians(45), 0, 0);
PDRectangle cropBox = page.getCropBox();
float tx = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2;
float ty = (cropBox.getLowerLeftY() + cropBox.getUpperRightY()) / 2;
Rectangle rectangle = cropBox.transform(matrix).getBounds();
float scale = Math.min(cropBox.getWidth() / (float)rectangle.getWidth(), cropBox.getHeight() / (float)rectangle.getHeight());
cs.transform(Matrix.getTranslateInstance(tx, ty));
cs.transform(matrix);
cs.transform(Matrix.getScaleInstance(scale, scale));
cs.transform(Matrix.getTranslateInstance(-tx, -ty));
cs.close();
document.save(new File(RESULT_FOLDER, "IRJET_Copy_Right_form-rotated-center-scale.pdf"));
}
}
示例4: drawText
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
public void drawText(PDPage page, PDPageContentStream contentStream, String _text) throws IOException {
String text = _text;
// contentStream.beginText();
// contentStream.setFont(getDefaultFont(), 12);
// contentStream.newLine();
// contentStream.newLineAtOffset(100, 700);
// contentStream.showText(this.text);
// contentStream.endText();
float fontSize = 25;
float leading = 1.5f * fontSize;
PDRectangle mediabox = page.getMediaBox();
float margin = 72;
float width = mediabox.getWidth() - 2 * margin;
float startX = mediabox.getLowerLeftX() + margin;
float startY = mediabox.getUpperRightY() - margin;
int lastSpace = -1;
while (text.length() > 0) {
int spaceIndex = text.indexOf(' ', lastSpace + 1);//text.indexOf("\n", lastSpace + 1);
if (spaceIndex < 0) {
spaceIndex = text.length();
}
String subString = text.substring(0, spaceIndex);
float size = fontSize * getDefaultFont().getStringWidth(subString) / 1000;
LOGGER.debug("'{}' - {} of {}\n", subString, size, width);
if (size > width) {
if (lastSpace < 0)
lastSpace = spaceIndex;
subString = text.substring(0, lastSpace);
lines.add(subString);
text = text.substring(lastSpace).trim();
LOGGER.debug("'{}' is line\n", subString);
lastSpace = -1;
} else if (spaceIndex == text.length()) {
lines.add(text);
LOGGER.debug("'{}' is line\n", text);
text = "";
} else {
lastSpace = spaceIndex;
}
}
contentStream.beginText();
contentStream.setFont(getDefaultFont(), fontSize);
contentStream.newLineAtOffset(startX, startY);
for (String line : lines) {
contentStream.showText(line);
contentStream.newLineAtOffset(0, -leading);
}
contentStream.endText();
}
示例5: transformToPageRotation
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
* Transform the rectangle in order to match the page rotation
* @param rect the rectangle.
* @param page the page.
* @return the transformed rectangle.
*/
public static PDRectangle transformToPageRotation(
final PDRectangle rect, final PDPage page) {
AffineTransform transform = transformToPageRotation(page);
if (transform == null) {
return rect;
}
float[] points = new float[] {rect.getLowerLeftX(), rect.getLowerLeftY(), rect.getUpperRightX(), rect.getUpperRightY()};
float[] rotatedPoints = new float[4];
transform.transform(points, 0, rotatedPoints, 0, 2);
PDRectangle rotated = new PDRectangle();
rotated.setLowerLeftX(rotatedPoints[0]);
rotated.setLowerLeftY(rotatedPoints[1]);
rotated.setUpperRightX(rotatedPoints[2]);
rotated.setUpperRightY(rotatedPoints[3]);
return rotated;
}
示例6: fillBeadRectangles
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
private void fillBeadRectangles(PDPage page)
{
beadRectangles = new ArrayList<PDRectangle>();
for (PDThreadBead bead : page.getThreadBeads())
{
if (bead == null)
{
// can't skip, because of null entry handling in processTextPosition()
beadRectangles.add(null);
continue;
}
PDRectangle rect = bead.getRectangle();
// bead rectangle is in PDF coordinates (y=0 is bottom),
// glyphs are in image coordinates (y=0 is top),
// so we must flip
PDRectangle mediaBox = page.findMediaBox();
float upperRightY = mediaBox.getUpperRightY() - rect.getLowerLeftY();
float lowerLeftY = mediaBox.getUpperRightY() - rect.getUpperRightY();
rect.setLowerLeftY(lowerLeftY);
rect.setUpperRightY(upperRightY);
// adjust for cropbox
PDRectangle cropBox = page.findCropBox();
if (cropBox.getLowerLeftX() != 0 || cropBox.getLowerLeftY() != 0)
{
rect.setLowerLeftX(rect.getLowerLeftX() - cropBox.getLowerLeftX());
rect.setLowerLeftY(rect.getLowerLeftY() - cropBox.getLowerLeftY());
rect.setUpperRightX(rect.getUpperRightX() - cropBox.getLowerLeftX());
rect.setUpperRightY(rect.getUpperRightY() - cropBox.getLowerLeftY());
}
beadRectangles.add(rect);
}
}
示例7: assertPositionAndSize
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
* Quick method to validate position and size.
*/
private void assertPositionAndSize(float x, float y, PDImageXObject image, PDPage page) throws PdfProcessingException {
PDRectangle pageArea = page.getCropBox();
// Assert position is in page
if (x < pageArea.getLowerLeftX() || x > pageArea.getUpperRightX())
throw new PdfProcessingException("X position not valid. (" + x + "," + y + ") out of page");
if (y < pageArea.getLowerLeftY() || y > pageArea.getUpperRightY())
throw new PdfProcessingException("Y position not valid. (" + x + "," + y + ") out of page");
// Assert image fits
if (x + image.getWidth() > pageArea.getUpperRightX() ||
y + image.getHeight() > pageArea.getUpperRightY())
throw new PdfProcessingException("Image dos not fit in page");
}
示例8: toQuadPoints
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
* Return the quad points representation of the given rect.
*
* @param rect
* the rectangle.
* @param xOffset
* the offset in x-direction to add.
* @param yOffset
* the offset in y-direction to add.
* @return the quad points.
*/
public static float[] toQuadPoints(final PDRectangle rect, float xOffset,
float yOffset) {
float[] quads = new float[8];
quads[0] = rect.getLowerLeftX() + xOffset; // x1
quads[1] = rect.getUpperRightY() + yOffset; // y1
quads[2] = rect.getUpperRightX() + xOffset; // x2
quads[3] = quads[1]; // y2
quads[4] = quads[0]; // x3
quads[5] = rect.getLowerLeftY() + yOffset; // y3
quads[6] = quads[2]; // x4
quads[7] = quads[5]; // y5
return quads;
}
示例9: PdfBoxPage
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
* The default constructor.
*/
public PdfBoxPage(PDPage page, int pageNumber) {
super(null); // We cannot pass this here.
this.pdPage = page;
this.pageNumber = pageNumber;
// The CropBox is usually the visible page area within a larger MediaBox.
// It is often used to hide things like printers crop marks and is generally
// the visible part you see in a PDF viewer.
// But it is possible, that the cropBox is larger than the mediaBox. In that
// cases, take the mediaBox as cropBox.
// See https://blog.idrsolutions.com/2012/02/...
// what-happens-if-the-cropbox-is-smaller-than-the-mediabox/
PDRectangle mediaBox = pdPage.getMediaBox();
PDRectangle cropBox = pdPage.getCropBox();
this.mediaBox = new SimpleRectangle(
mediaBox.getLowerLeftX(), mediaBox.getLowerLeftY(),
mediaBox.getUpperRightX(), mediaBox.getUpperRightY());
this.cropBox = new SimpleRectangle(
cropBox.getLowerLeftX(), cropBox.getLowerLeftY(),
cropBox.getUpperRightX(), cropBox.getUpperRightY());
this.cropXOffset = this.cropBox.getMinX() - this.mediaBox.getMinX();
this.cropYOffset = this.cropBox.getMinY() - this.mediaBox.getMinX();
// Check, if the cropBox is larger than the mediaBox.
if (this.cropBox.getArea() > this.mediaBox.getArea()) {
// Swap cropBox and mediaBox.
Rectangle tmp = this.cropBox;
this.cropBox = this.mediaBox;
this.mediaBox = tmp;
}
this.artBox = this.cropBox;
this.trimBox = this.cropBox;
this.verticalCharacterPitchesCounter = new FloatCounter();
}
示例10: getRightX
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
@SuppressWarnings("unused")
public float getRightX() {
try {
int angle = getRotation();
PDRectangle box = getMediaBox();
return box.getUpperRightY()-borders;
} catch (Exception ex) {
return getMediaBox().getUpperRightX()-borders;
}
}
示例11: rectToQuadArray
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
private float[] rectToQuadArray(PDRectangle r) {
float[] convertedQuadPoints = new float[]{r.getLowerLeftX(),r.getLowerLeftY(),
r.getUpperRightX(), r.getLowerLeftY(), r.getLowerLeftX(), r.getUpperRightY(),
r.getUpperRightX(), r.getUpperRightY()};
return convertedQuadPoints;
}
示例12: setBoundingBox
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
public void setBoundingBox(PDRectangle bBox)
{
x1 = bBox.getLowerLeftX(); x2 = bBox.getUpperRightX();
y1 = bBox.getLowerLeftY(); y2 = bBox.getUpperRightY();
}