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


Java PDRectangle.getLowerLeftX方法代码示例

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


在下文中一共展示了PDRectangle.getLowerLeftX方法的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"));
    }
}
 
开发者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: 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();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:69,代码来源:RectanglesOverText.java

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

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

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

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

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

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

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

示例13: getLowY

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

示例14: 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;
}
 
开发者ID:nyholmniklas,项目名称:vaadinInvoiceGenerator,代码行数:55,代码来源:Invoice2PdfBoxImpl.java

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


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