org.apache.pdfbox.pdmodel.common.PDRectangle Java Examples

The following examples show how to use org.apache.pdfbox.pdmodel.common.PDRectangle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PDFCreator.java    From Knowage-Server with GNU Affero General Public License v3.0 7 votes vote down vote up
private static void writeFrontpageDetails(PDDocument doc, PDFont font, float fontSize, FrontpageDetails details) throws IOException {
	String name = "Name: " + details.getName();
	String description = "Description: " + details.getDescription();
	String date = "Date: " + DEFAULT_DATE_FORMATTER.format(details.getDate());
	PDPage page = doc.getPage(0);
	PDRectangle pageSize = page.getMediaBox();
	float stringWidth = font.getStringWidth(StringUtilities.findLongest(name, description, date)) * fontSize / 1000f;
	float stringHeight = font.getFontDescriptor().getFontBoundingBox().getHeight() * fontSize / 1000f;

	int rotation = page.getRotation();
	boolean rotate = rotation == 90 || rotation == 270;
	float pageWidth = rotate ? pageSize.getHeight() : pageSize.getWidth();
	float pageHeight = rotate ? pageSize.getWidth() : pageSize.getHeight();
	float startX = rotate ? pageHeight / 3f : (pageWidth - stringWidth - stringHeight) / 3f;
	float startY = rotate ? (pageWidth - stringWidth) / 1f : pageWidth / 0.9f;

	// append the content to the existing stream
	try (PDPageContentStream contentStream = new PDPageContentStream(doc, page, AppendMode.APPEND, true, true)) {
		// draw rectangle
		writeText(contentStream, new Color(4, 44, 86), font, fontSize, rotate, startX, startY, name, description, date);
	}
}
 
Example #2
Source File: PDTextAppearanceHandler.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private void drawCheck(PDAnnotationText annotation, final PDAppearanceContentStream contentStream)
        throws IOException
{
    PDRectangle bbox = adjustRectAndBBox(annotation, 20, 19);

    float min = Math.min(bbox.getWidth(), bbox.getHeight());

    contentStream.setMiterLimit(4);
    contentStream.setLineJoinStyle(1);
    contentStream.setLineCapStyle(0);
    contentStream.setLineWidth(0.59f); // value from Adobe

    contentStream.transform(Matrix.getScaleInstance(0.001f * min / 0.8f, 0.001f * min / 0.8f));
    contentStream.transform(Matrix.getTranslateInstance(0, 50));

    // we get the shape of a Zapf Dingbats check (0x2714) and use that one.
    // Adobe uses a different font (which one?), or created the shape from scratch.
    GeneralPath path = PDType1Font.ZAPF_DINGBATS.getPath("a20");
    addPath(contentStream, path);
    contentStream.fillAndStroke();
}
 
Example #3
Source File: FDFAnnotationFreeText.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private void initFringe(Element element) throws IOException
{
    String fringe = element.getAttribute("fringe");
    if (fringe != null && !fringe.isEmpty())
    {
        String[] fringeValues = fringe.split(",");
        if (fringeValues.length != 4)
        {
            throw new IOException("Error: wrong amount of numbers in attribute 'fringe'");
        }
        PDRectangle rect = new PDRectangle();
        rect.setLowerLeftX(Float.parseFloat(fringeValues[0]));
        rect.setLowerLeftY(Float.parseFloat(fringeValues[1]));
        rect.setUpperRightX(Float.parseFloat(fringeValues[2]));
        rect.setUpperRightY(Float.parseFloat(fringeValues[3]));
        setFringe(rect);
    }
}
 
Example #4
Source File: ObjectExtractorStreamEngine.java    From tabula-java with MIT License 6 votes vote down vote up
protected ObjectExtractorStreamEngine(PDPage page) {
    super(page);

    this.log = LoggerFactory.getLogger(ObjectExtractorStreamEngine.class);

    this.rulings = new ArrayList<>();
    this.pageTransform = null;

    // calculate page transform
    PDRectangle cb = this.getPage().getCropBox();
    int rotation = this.getPage().getRotation();

    this.pageTransform = new AffineTransform();

    if (Math.abs(rotation) == 90 || Math.abs(rotation) == 270) {
        this.pageTransform = AffineTransform.getRotateInstance(rotation * (Math.PI / 180.0), 0, 0);
        this.pageTransform.concatenate(AffineTransform.getScaleInstance(1, -1));
    } else {
        this.pageTransform.concatenate(AffineTransform.getTranslateInstance(0, cb.getHeight()));
        this.pageTransform.concatenate(AffineTransform.getScaleInstance(1, -1));
    }

    this.pageTransform.translate(-cb.getLowerLeftX(), -cb.getLowerLeftY());
}
 
Example #5
Source File: PDFPage.java    From Open-Lowcode with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void print(PDDocument document) throws IOException {
	// create the page
	this.document = document;
	page = new PDPage(new PDRectangle(width * MM_TO_POINT, height * MM_TO_POINT));
	document.addPage(page);
	contentStream = new PDPageContentStream(document, page);
	// print the widgets
	for (int i = 0; i < widgetstoprint.size(); i++) {
		PageExecutable thiswidget = widgetstoprint.get(i);
		thiswidget.printComponent();
	}
	// close the page
	contentStream.close();

}
 
Example #6
Source File: RotatePageContent.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
/**
 * <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 = Loader.loadPDF(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"));
    }
}
 
Example #7
Source File: PDFExtractor.java    From science-parse with Apache License 2.0 6 votes vote down vote up
@Override
protected void endPage(PDPage pdfboxPage) {
  if (!curLineTokens.isEmpty()) {
    curLines.add(toLine(curLineTokens));
  }
  PDRectangle pageRect = pdfboxPage.getMediaBox() == null ?
    pdfboxPage.getArtBox() :
    pdfboxPage.getMediaBox();
  val page = PDFPage.builder()
    .lines(new ArrayList<>(curLines))
    .pageNumber(pages.size())
    .pageWidth((int) pageRect.getWidth())
    .pageHeight((int) pageRect.getHeight())
    .build();
  pages.add(page);
}
 
Example #8
Source File: PDCIDFontType0.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private BoundingBox generateBoundingBox()
{
    if (getFontDescriptor() != null) {
        PDRectangle bbox = getFontDescriptor().getFontBoundingBox();
        if (bbox.getLowerLeftX() != 0 || bbox.getLowerLeftY() != 0 ||
            bbox.getUpperRightX() != 0 || bbox.getUpperRightY() != 0) {
            return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(),
                                   bbox.getUpperRightX(), bbox.getUpperRightY());
        }
    }
    if (cidFont != null)
    {
        return cidFont.getFontBBox();
    }
    else
    {
        try
        {
            return t1Font.getFontBBox();
        }
        catch (IOException e)
        {
            return new BoundingBox();
        }
    }
}
 
Example #9
Source File: PDFCreator.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
private static void createPDF(List<InputStream> inputImages, Path output) throws IOException {
	PDDocument document = new PDDocument();
	try {
		for (InputStream is : inputImages) {
			BufferedImage bimg = ImageIO.read(is);
			float width = bimg.getWidth();
			float height = bimg.getHeight();
			PDPage page = new PDPage(new PDRectangle(width, height));
			document.addPage(page);

			PDImageXObject img = LosslessFactory.createFromImage(document, bimg);
			try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) {
				contentStream.drawImage(img, 0, 0);
			}
		}
		document.save(output.toFile());
	} finally {
		document.close();
	}
}
 
Example #10
Source File: PDCIDFontType2.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private BoundingBox generateBoundingBox() throws IOException
{
    if (getFontDescriptor() != null)
    {
        PDRectangle bbox = getFontDescriptor().getFontBoundingBox();
        if (bbox != null &&
                (Float.compare(bbox.getLowerLeftX(), 0) != 0 || 
                 Float.compare(bbox.getLowerLeftY(), 0) != 0 ||
                 Float.compare(bbox.getUpperRightX(), 0) != 0 ||
                 Float.compare(bbox.getUpperRightY(), 0) != 0))
        {
            return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(),
                                   bbox.getUpperRightX(), bbox.getUpperRightY());
        }
    }
    return ttf.getFontBBox();
}
 
Example #11
Source File: PDFImprinter.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
private PDPageContentStream openContentStream(PDPage page, boolean setPageSize, boolean applyPageOrientation) throws IOException {
	contentStream = new PDPageContentStream(doc, page, true, false);
	if (painter != null) {
		PDRectangle pageSize = page.findMediaBox();
		if (PageOrientation.LANDSCAPE.equals(painter.getPageOrientation())) {
			if (setPageSize) {
				painter.setPageHeight(pageSize.getWidth());
				painter.setPageWidth(pageSize.getHeight());
			}
			if (applyPageOrientation) {
				contentStream.concatenate2CTM(0, 1, -1, 0, pageSize.getWidth(), 0); // cos(theta) sin(theta) -sin(theta) cos(theta) 0 0 cm
			}
		} else {
			if (setPageSize) {
				painter.setPageHeight(pageSize.getHeight());
				painter.setPageWidth(pageSize.getWidth());
			}
		}
	}
	return contentStream;
}
 
Example #12
Source File: FDFAnnotationCircle.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private void initFringe(Element element) throws IOException
{
    String fringe = element.getAttribute("fringe");
    if (fringe != null && !fringe.isEmpty())
    {
        String[] fringeValues = fringe.split(",");
        if (fringeValues.length != 4)
        {
            throw new IOException("Error: wrong amount of numbers in attribute 'fringe'");
        }
        PDRectangle rect = new PDRectangle();
        rect.setLowerLeftX(Float.parseFloat(fringeValues[0]));
        rect.setLowerLeftY(Float.parseFloat(fringeValues[1]));
        rect.setUpperRightX(Float.parseFloat(fringeValues[2]));
        rect.setUpperRightY(Float.parseFloat(fringeValues[3]));
        setFringe(rect);
    }
}
 
Example #13
Source File: AppearanceGeneratorHelper.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private AffineTransform calculateMatrix(PDRectangle bbox, int rotation)
{
    if (rotation == 0)
    {
        return new AffineTransform();
    }
    float tx = 0, ty = 0;
    switch (rotation)
    {
        case 90:
            tx = bbox.getUpperRightY();
            break;
        case 180:
            tx = bbox.getUpperRightY();
            ty = bbox.getUpperRightX();
            break;
        case 270:
            ty = bbox.getUpperRightX();
            break;
        default:
            break;
    }
    Matrix matrix = Matrix.getRotateInstance(Math.toRadians(rotation), tx, ty);
    return matrix.createAffineTransform();

}
 
Example #14
Source File: SignatureImageAndPositionProcessor.java    From dss with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static float processY(int rotation, ImageAndResolution ires, BufferedImage visualImageSignature, PDPage pdPage, SignatureImageParameters signatureImageParameters) {
    float y;
    
    PDRectangle pageBox = pdPage.getMediaBox();
    float height = getHeight(signatureImageParameters, visualImageSignature, ires, ImageRotationUtils.isSwapOfDimensionsRequired(rotation));
    
    switch (rotation) {
        case ImageRotationUtils.ANGLE_90:
            y = processYAngle90(pageBox, signatureImageParameters, height);
            break;
        case ImageRotationUtils.ANGLE_180:
            y = processYAngle180(pageBox, signatureImageParameters, height);
            break;
        case ImageRotationUtils.ANGLE_270:
            y = processYAngle270(pageBox, signatureImageParameters, height);
            break;
        case ImageRotationUtils.ANGLE_360:
            y = processYAngle360(pageBox, signatureImageParameters, height);
            break;
        default:
            throw new IllegalStateException(ImageRotationUtils.SUPPORTED_ANGLES_ERROR_MESSAGE);
    }

    return y;
}
 
Example #15
Source File: RotatePageContent.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
/**
 * <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 set the crop
 * box and media box to the bounding rectangle of the rotated page area.
 * </p>
 */
@Test
public void testRotateExpandBox() throws IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("IRJET_Copy_Right_form.pdf")  )
    {
        PDDocument document = Loader.loadPDF(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();
        Rectangle rectangle = cropBox.transform(matrix).getBounds();
        PDRectangle newBox = new PDRectangle((float)rectangle.getX(), (float)rectangle.getY(), (float)rectangle.getWidth(), (float)rectangle.getHeight());
        page.setCropBox(newBox);
        page.setMediaBox(newBox);

        document.save(new File(RESULT_FOLDER, "IRJET_Copy_Right_form-rotated-expand-box.pdf"));
    }
}
 
Example #16
Source File: PdfBoxPreviewTest.java    From java-image-processing-survival-guide with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public List<BufferedImage> toImages(PDDocument pdDocument, int startPage, int endPage, int resolution, int imageType) throws Exception {
    final List<BufferedImage> result = new ArrayList<BufferedImage>();
    final List<PDPage> pages = pdDocument.getDocumentCatalog().getAllPages();
    final int pagesSize = pages.size();

    for (int i = startPage - 1; i < endPage && i < pagesSize; i++) {
        PDPage page = pages.get(i);
        PDRectangle cropBox = page.findCropBox();
        float width = cropBox.getWidth();
        float height = cropBox.getHeight();
        int currResolution = calculateResolution(resolution, width, height);
        BufferedImage image = page.convertToImage(imageType, currResolution);

        if (image != null) {
            result.add(image);
        }
    }

    return result;
}
 
Example #17
Source File: PDTextAppearanceHandler.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private void drawCrossHairs(PDAnnotationText annotation, final PDAppearanceContentStream contentStream)
        throws IOException
{
    PDRectangle bbox = adjustRectAndBBox(annotation, 20, 20);

    float min = Math.min(bbox.getWidth(), bbox.getHeight());

    contentStream.setMiterLimit(4);
    contentStream.setLineJoinStyle(0);
    contentStream.setLineCapStyle(0);
    contentStream.setLineWidth(0.61f); // value from Adobe

    contentStream.transform(Matrix.getScaleInstance(0.001f * min / 1.5f, 0.001f * min / 1.5f));
    contentStream.transform(Matrix.getTranslateInstance(0, 50));

    // we get the shape of a Symbol crosshair (0x2295) and use that one.
    // Adobe uses a different font (which one?), or created the shape from scratch.
    GeneralPath path = PDType1Font.SYMBOL.getPath("circleplus");
    addPath(contentStream, path);
    contentStream.fillAndStroke();
}
 
Example #18
Source File: PdfVeryDenseMergeTool.java    From testarea-pdfbox2 with Apache License 2.0 5 votes vote down vote up
public PdfVeryDenseMergeTool(PDRectangle size, float top, float bottom, float gap)
{
    this.pageSize = size;
    this.topMargin = top;
    this.bottomMargin = bottom;
    this.gap = gap;
}
 
Example #19
Source File: PDTrueTypeFont.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private BoundingBox generateBoundingBox() throws IOException
{
    if (getFontDescriptor() != null) {
        PDRectangle bbox = getFontDescriptor().getFontBoundingBox();
        if (bbox != null)
        {
            return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(),
                    bbox.getUpperRightX(), bbox.getUpperRightY());
        }
    }
    return ttf.getFontBBox();
}
 
Example #20
Source File: PDPage.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * This will set the CropBox for this page.
 * 
 * @param cropBox The new CropBox for this page.
 */
public void setCropBox(PDRectangle cropBox)
{
    if (cropBox == null)
    {
        page.removeItem(COSName.CROP_BOX);
    }
    else
    {
        page.setItem(COSName.CROP_BOX, cropBox.getCOSArray());
    }
}
 
Example #21
Source File: PageRenderer.java    From PDF4Teachers with Apache License 2.0 5 votes vote down vote up
public void updatePosition(int totalHeight){
    if(totalHeight == -1) totalHeight = (int) getTranslateY();

    PDRectangle pageSize = MainWindow.mainScreen.document.pdfPagesRender.getPageSize(page);
    final double ratio = pageSize.getHeight() / pageSize.getWidth();

    setWidth(MainWindow.mainScreen.getPageWidth());
    setHeight(MainWindow.mainScreen.getPageWidth() * ratio);

    setMaxWidth(MainWindow.mainScreen.getPageWidth());
    setMinWidth(MainWindow.mainScreen.getPageWidth());

    setMaxHeight(MainWindow.mainScreen.getPageWidth() * ratio);
    setMinHeight(MainWindow.mainScreen.getPageWidth() * ratio);

    setTranslateX(30);
    setTranslateY(totalHeight);

    totalHeight = (int) (totalHeight + getHeight() + 30);

    if(MainWindow.mainScreen.document.totalPages > page+1){
        MainWindow.mainScreen.document.pages.get(page + 1).updatePosition(totalHeight);
    }else{
        MainWindow.mainScreen.updateSize(totalHeight);
    }

    if(pageEditPane != null) pageEditPane.updatePosition();

}
 
Example #22
Source File: PDPage.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of PDPage for embedding.
 * 
 * @param mediaBox The MediaBox of the page.
 */
public PDPage(PDRectangle mediaBox)
{
    page = new COSDictionary();
    page.setItem(COSName.TYPE, COSName.PAGE);
    page.setItem(COSName.MEDIA_BOX, mediaBox);
}
 
Example #23
Source File: CreateMultipleVisualizations.java    From testarea-pdfbox2 with Apache License 2.0 5 votes vote down vote up
/**
 * <a href="https://stackoverflow.com/questions/52829507/multiple-esign-using-pdfbox-2-0-12-java">
 * Multiple esign using pdfbox 2.0.12 java?
 * </a>
 * <br/>
 * <a href="https://drive.google.com/open?id=1DKSApmjrT424wT92yBdynKUkvR00x9i2">
 * C10000000713071804294534.pdf
 * </a>
 * <p>
 * This test demonstrates how to create a single signature in multiple signature
 * fields with one widget annotation each only referenced from a single page each
 * only. (Actually there is an extra invisible signature; it is possible to get
 * rid of it with some more code.) It uses the test file provided by the OP.
 * </p>
 */
@Test
public void testCreateSignatureWithMultipleVisualizationsC10000000713071804294534() throws IOException {
    try (   InputStream resource = getClass().getResourceAsStream("C10000000713071804294534.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "C10000000713071804294534-SignedMultipleVisualizations.pdf"));
            PDDocument pdDocument = Loader.loadPDF(resource)   )
    {
        PDAcroForm acroForm = pdDocument.getDocumentCatalog().getAcroForm();
        if (acroForm == null) {
            pdDocument.getDocumentCatalog().setAcroForm(acroForm = new PDAcroForm(pdDocument));
        }
        acroForm.setSignaturesExist(true);
        acroForm.setAppendOnly(true);
        acroForm.getCOSObject().setDirect(true);

        PDRectangle rectangle = new PDRectangle(100, 600, 300, 100);
        PDSignature signature = new PDSignature();
        signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
        signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
        signature.setName("Example User");
        signature.setLocation("Los Angeles, CA");
        signature.setReason("Testing");
        signature.setSignDate(Calendar.getInstance());
        pdDocument.addSignature(signature, this);

        for (PDPage pdPage : pdDocument.getPages()) {
            addSignatureField(pdDocument, pdPage, rectangle, signature);
        }

        pdDocument.saveIncremental(result);
    }
}
 
Example #24
Source File: TilingPaint.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Returns the anchor rectangle, which includes the XStep/YStep and scaling.
 */
private Rectangle2D getAnchorRect(PDTilingPattern pattern)
{
    float xStep = pattern.getXStep();
    if (xStep == 0)
    {
        xStep = pattern.getBBox().getWidth();
    }

    float yStep = pattern.getYStep();
    if (yStep == 0)
    {
        yStep = pattern.getBBox().getHeight();
    }

    float xScale = patternMatrix.getScalingFactorX();
    float yScale = patternMatrix.getScalingFactorY();
    float width = xStep * xScale;
    float height = yStep * yScale;

    if (Math.abs(width * height) > MAXEDGE * MAXEDGE)
    {
        // PDFBOX-3653: prevent huge sizes
        LOG.info("Pattern surface is too large, will be clipped");
        LOG.info("width: " + width + ", height: " + height);
        LOG.info("XStep: " + xStep + ", YStep: " + yStep);
        LOG.info("bbox: " + pattern.getBBox());
        LOG.info("pattern matrix: " + pattern.getMatrix());
        LOG.info("concatenated matrix: " + patternMatrix);
        width = Math.min(MAXEDGE, Math.abs(width)) * Math.signum(width);
        height = Math.min(MAXEDGE, Math.abs(height)) * Math.signum(height);
        //TODO better solution needed
    }

    // returns the anchor rect with scaling applied
    PDRectangle anchor = pattern.getBBox();
    return new Rectangle2D.Float(anchor.getLowerLeftX() * xScale,
                                 anchor.getLowerLeftY() * yScale,
                                 width, height);
}
 
Example #25
Source File: PdfToTextInfoConverter.java    From testarea-pdfbox2 with Apache License 2.0 5 votes vote down vote up
@Override
public void processPage(PDPage page) throws IOException {
    PDRectangle pageSize = page.getCropBox();

    lowerLeftX = pageSize.getLowerLeftX();
    lowerLeftY = pageSize.getLowerLeftY();

    super.processPage(page);
}
 
Example #26
Source File: PDTilingPattern.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * This will set the BBox (bounding box) for this Pattern.
 * @param bbox The new BBox for this Pattern.
 */
public void setBBox(PDRectangle bbox)
{
    if( bbox == null )
    {
        getCOSObject().removeItem( COSName.BBOX );
    }
    else
    {
        getCOSObject().setItem( COSName.BBOX, bbox.getCOSArray() );
    }
}
 
Example #27
Source File: PDAbstractAppearanceHandler.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
PDRectangle handleBorderBox(PDAnnotationSquareCircle annotation, float lineWidth)
{
    // There are two options. The handling is not part of the PDF specification but
    // implementation specific to Adobe Reader
    // - if /RD is set the border box is the /Rect entry inset by the respective
    //   border difference.
    // - if /RD is not set the border box is defined by the /Rect entry. The /RD entry will
    //   be set to be the line width and the /Rect is enlarged by the /RD amount
    PDRectangle borderBox;
    float[] rectDifferences = annotation.getRectDifferences();
    if (rectDifferences.length == 0)
    {
        borderBox = getPaddedRectangle(getRectangle(), lineWidth / 2);
        // the differences rectangle
        annotation.setRectDifferences(lineWidth / 2);
        annotation.setRectangle(addRectDifferences(getRectangle(), annotation.getRectDifferences()));
        // when the normal appearance stream was generated BBox and Matrix have been set to the
        // values of the original /Rect. As the /Rect was changed that needs to be adjusted too.
        annotation.getNormalAppearanceStream().setBBox(getRectangle());
        AffineTransform transform = AffineTransform.getTranslateInstance(-getRectangle().getLowerLeftX(), -getRectangle().getLowerLeftY());
        annotation.getNormalAppearanceStream().setMatrix(transform);
    }
    else
    {
        borderBox = applyRectDifferences(getRectangle(), rectDifferences);
        borderBox = getPaddedRectangle(borderBox, lineWidth / 2);
    }
    return borderBox;
}
 
Example #28
Source File: Overlay.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private LayoutPage(PDRectangle mediaBox, COSStream contentStream, COSDictionary resources, int rotation)
{
    overlayMediaBox = mediaBox;
    overlayContentStream = contentStream;
    overlayResources = resources;
    overlayRotation = rotation;
}
 
Example #29
Source File: PDFLayoutTextStripper.java    From PDFLayoutTextStripper with Apache License 2.0 5 votes vote down vote up
/**
* 
* @param page page to parse
*/
@Override
public void processPage(PDPage page) throws IOException {
    PDRectangle pageRectangle = page.getMediaBox();
    if (pageRectangle!= null) {
        this.setCurrentPageWidth(pageRectangle.getWidth());
        super.processPage(page);
        this.previousTextPosition = null;
        this.textLineList = new ArrayList<TextLine>();
    }
}
 
Example #30
Source File: PDVisibleSigBuilder.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void createHolderForm(PDResources holderFormResources, PDStream holderFormStream,
                             PDRectangle bbox)
{
    PDFormXObject holderForm = new PDFormXObject(holderFormStream);
    holderForm.setResources(holderFormResources);
    holderForm.setBBox(bbox);
    holderForm.setFormType(1);
    pdfStructure.setHolderForm(holderForm);
    LOG.info("Holder form has been created");

}