本文整理汇总了Java中org.apache.pdfbox.pdmodel.common.PDRectangle.getLowerLeftY方法的典型用法代码示例。如果您正苦于以下问题:Java PDRectangle.getLowerLeftY方法的具体用法?Java PDRectangle.getLowerLeftY怎么用?Java PDRectangle.getLowerLeftY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.pdmodel.common.PDRectangle
的用法示例。
在下文中一共展示了PDRectangle.getLowerLeftY方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testCoverTextByRectanglesMwbI201711
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
* <a href="https://stackoverflow.com/questions/46080131/text-coordinates-when-stripping-from-pdfbox">
* Text coordinates when stripping from PDFBox
* </a>
* <br/>
* <a href="https://download-a.akamaihd.net/files/media_mwb/b7/mwb_I_201711.pdf">
* mwb_I_201711.pdf
* </a>
* <p>
* This test applies the OP's code to his example PDF file and indeed, there is an offset!
* This is due to the <code>LegacyPDFStreamEngine</code> method <code>showGlyph</code>
* which manipulates the text rendering matrix to make the lower left corner of the
* crop box the origin. In the current version of this test, that offset is corrected,
* see below.
* </p>
*/
@Test
public void testCoverTextByRectanglesMwbI201711() throws IOException {
try ( InputStream resource = getClass().getResourceAsStream("mwb_I_201711.pdf") ) {
PDDocument doc = PDDocument.load(resource);
myStripper stripper = new myStripper();
stripper.setStartPage(1); // fix it to first page just to test it
stripper.setEndPage(1);
stripper.getText(doc);
TextLine line = stripper.lines.get(1); // the line i want to paint on
float minx = -1;
float maxx = -1;
for (TextPosition pos: line.textPositions)
{
if (pos == null)
continue;
if (minx == -1 || pos.getTextMatrix().getTranslateX() < minx) {
minx = pos.getTextMatrix().getTranslateX();
}
if (maxx == -1 || pos.getTextMatrix().getTranslateX() > maxx) {
maxx = pos.getTextMatrix().getTranslateX();
}
}
TextPosition firstPosition = line.textPositions.get(0);
TextPosition lastPosition = line.textPositions.get(line.textPositions.size() - 1);
// corrected x and y
PDRectangle cropBox = doc.getPage(0).getCropBox();
float x = minx + cropBox.getLowerLeftX();
float y = firstPosition.getTextMatrix().getTranslateY() + cropBox.getLowerLeftY();
float w = (maxx - minx) + lastPosition.getWidth();
float h = lastPosition.getHeightDir();
PDPageContentStream contentStream = new PDPageContentStream(doc, doc.getPage(0), PDPageContentStream.AppendMode.APPEND, false, true);
contentStream.setNonStrokingColor(Color.RED);
contentStream.addRect(x, y, w, h);
contentStream.fill();
contentStream.close();
File fileout = new File(RESULT_FOLDER, "mwb_I_201711-withRectangles.pdf");
doc.save(fileout);
doc.close();
}
}
示例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: processPage
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
@Override
public void processPage(PDPage page) throws IOException {
PDRectangle pageSize = page.getCropBox();
lowerLeftX = pageSize.getLowerLeftX();
lowerLeftY = pageSize.getLowerLeftY();
super.processPage(page);
}
示例8: 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");
}
示例9: 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;
}
示例10: 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();
}
示例11: getLeftX
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
@SuppressWarnings("unused")
public float getLeftX() {
try {
int angle = getRotation();
PDRectangle box = getMediaBox();
return box.getLowerLeftY()+borders;
} catch (Exception ex) {
return getMediaBox().getLowerLeftX()+borders;
}
}
示例12: writeDescription
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
private PDPage writeDescription(int x, int y, Invoice invoice, PDPage page, PDPageContentStream contentStream) throws IOException {
float fontSize = 12;
float leading = 1.5f * fontSize;
int marginX = x;
int marginY = y;
PDRectangle mediabox = page.findMediaBox();
float width = mediabox.getWidth() - 2*marginX;
float startX = mediabox.getLowerLeftX() + marginX;
float startY = mediabox.getLowerLeftY() + marginY;
List<String> lines = new ArrayList<String>();
int lastSpace = -1;
String text = invoice.getDescription();
while (text.length() > 0)
{
int spaceIndex = text.indexOf(' ', lastSpace + 1);
if (spaceIndex < 0)
{
lines.add(text);
text = "";
}
else
{
String subString = text.substring(0, spaceIndex);
float size = fontSize * normalFont.getStringWidth(subString) / 1000;
if (size > width)
{
if (lastSpace < 0)
lastSpace = spaceIndex;
subString = text.substring(0, lastSpace);
lines.add(subString);
text = text.substring(lastSpace).trim();
lastSpace = -1;
}
else
{
lastSpace = spaceIndex;
}
}
}
contentStream.beginText();
contentStream.setFont(normalFont, fontSize);
contentStream.moveTextPositionByAmount(startX, startY);
for (String line: lines)
{
contentStream.drawString(line);
contentStream.moveTextPositionByAmount(0, -leading);
}
contentStream.endText();
return page;
}
示例13: 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;
}
示例14: 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();
}
示例15: toJavaRect
import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
* Converts a Rectangle from PDF coordinates to AWT coordinates. The y-axis
* of one is inverted with respect to the other.
*
* @param rect
* - the PDF formatted rectangle
* @param mediaDim
* - the Dimension of the page. Only the height is used in this
* method.
* @return a Rectangle2D in the AWT coordinate system.
*/
private Rectangle2D toJavaRect(PDRectangle rect, Dimension mediaDim) {
int width = (int) (difference(rect.getLowerLeftX(),
rect.getUpperRightX()));
int height = (int) (difference(rect.getLowerLeftY(),
rect.getUpperRightY()));
int xval = (int) rect.getLowerLeftX();
int yval = (int) (mediaDim.getHeight() - height - rect.getLowerLeftY());
return new java.awt.geom.Rectangle2D.Double(xval, yval, width, height);
}