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


Java PDRectangle.getUpperRightX方法代码示例

本文整理汇总了Java中org.apache.pdfbox.pdmodel.common.PDRectangle.getUpperRightX方法的典型用法代码示例。如果您正苦于以下问题:Java PDRectangle.getUpperRightX方法的具体用法?Java PDRectangle.getUpperRightX怎么用?Java PDRectangle.getUpperRightX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.pdfbox.pdmodel.common.PDRectangle的用法示例。


在下文中一共展示了PDRectangle.getUpperRightX方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例5: 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

示例6: 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

示例7: 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

示例8: testDrunkenFistSample

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
 * Applying the code to the OP's sample file from a former question.
 * 
 * @throws IOException
 * @throws CryptographyException
 * @throws COSVisitorException
 */
@Test
public void testDrunkenFistSample() throws IOException, CryptographyException, COSVisitorException
{
    try (   InputStream resource = getClass().getResourceAsStream("sample.pdf");
            InputStream left = getClass().getResourceAsStream("left.png");
            InputStream right = getClass().getResourceAsStream("right.png");
            PDDocument document = PDDocument.load(resource) )
    {
        if (document.isEncrypted())
        {
            document.decrypt("");
        }
        
        PDJpeg leftImage = new PDJpeg(document, ImageIO.read(left));
        PDJpeg rightImage = new PDJpeg(document, ImageIO.read(right));

        ImageLocator locator = new ImageLocator();
        List<?> allPages = document.getDocumentCatalog().getAllPages();
        for (int i = 0; i < allPages.size(); i++)
        {
            PDPage page = (PDPage) allPages.get(i);
            locator.processStream(page, page.findResources(), page.getContents().getStream());
        }

        for (ImageLocation location : locator.getLocations())
        {
            PDRectangle cropBox = location.getPage().findCropBox();
            float center = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2.0f;
            PDJpeg image = location.getMatrix().getXPosition() < center ? leftImage : rightImage;
            AffineTransform transform = location.getMatrix().createAffineTransform();

            PDPageContentStream content = new PDPageContentStream(document, location.getPage(), true, false, true);
            content.drawXObject(image, transform);
            content.close();
        }

        document.save(new File(RESULT_FOLDER, "sample-changed.pdf"));
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:47,代码来源:OverwriteImage.java

示例9: getTopY

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
@SuppressWarnings("unused")
public float getTopY() {
	try {
		int angle = getRotation();
		PDRectangle box = getMediaBox();
			return box.getUpperRightX()-borders;
	} catch (Exception ex) {
		return getMediaBox().getUpperRightY()-borders;
	}
}
 
开发者ID:purbon,项目名称:pdfwriter,代码行数:11,代码来源:PDFPage.java

示例10: 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

示例11: 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.getUpperRightX方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。