当前位置: 首页>>代码示例>>Java>>正文


Java PDRectangle.getUpperRightY方法代码示例

本文整理汇总了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"));
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:36,代码来源:RotatePageContent.java

示例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"));
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:27,代码来源:RotatePageContent.java

示例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"));
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:35,代码来源:RotatePageContent.java

示例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();

	}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:60,代码来源:SimpleTextPDFHelpeBuilder.java

示例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;
   }
 
开发者ID:ralfstuckert,项目名称:pdfbox-layout,代码行数:23,代码来源:CompatibilityHelper.java

示例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);
    }
}
 
开发者ID:hemangandhi,项目名称:my-cv-site,代码行数:37,代码来源:FormattedReader.java

示例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");
}
 
开发者ID:abelsromero,项目名称:pdf-box-examples,代码行数:17,代码来源:PdfImagesHelper.java

示例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;
   }
 
开发者ID:ralfstuckert,项目名称:pdfbox-layout,代码行数:25,代码来源:CompatibilityHelper.java

示例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();
}
 
开发者ID:ckorzen,项目名称:icecite,代码行数:42,代码来源:PdfBoxPage.java

示例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;
	}
}
 
开发者ID:purbon,项目名称:pdfwriter,代码行数:11,代码来源:PDFPage.java

示例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;
}
 
开发者ID:DeveloperLiberationFront,项目名称:Pdf-Reviewer,代码行数:7,代码来源:Pdf.java

示例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();
}
 
开发者ID:tamirhassan,项目名称:pdfxtk,代码行数:6,代码来源:GenericSegment.java


注:本文中的org.apache.pdfbox.pdmodel.common.PDRectangle.getUpperRightY方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。