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


Java PDRectangle.getHeight方法代码示例

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


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

示例1: addHeaderPJ

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
 * @param textHeader
 * @param font
 * @param PAGE_SIZE_A4
 * @param contentStream
 * @return ajoute un header a la piece
 * @throws IOException
 */
private Float addHeaderPJ(final String textHeader, final PDFont font, final PDRectangle PAGE_SIZE_A4,
		final PDPageContentStream contentStream) throws IOException {
	Float marginTop = 0f;
	// si font Ok, on ajoute le text
	if (font != null && ConstanteUtils.DOSSIER_ADD_HEADER_IMG) {

		// calcul de la largeur et hauteur du txt
		Float titleWidth = font.getStringWidth(textHeader) / 1000 * ConstanteUtils.DOSSIER_FONT_SIZE;
		Float titleHeight = font.getFontDescriptor().getFontBoundingBox().getHeight() / 1000
				* ConstanteUtils.DOSSIER_FONT_SIZE;

		// calcul de la marge du haut : hauteur du text + marge
		marginTop = titleHeight + ConstanteUtils.DOSSIER_MARGIN;

		// calcul de la position du text
		Float xText = (PAGE_SIZE_A4.getWidth() - 2 * ConstanteUtils.DOSSIER_MARGIN - titleWidth) / 2;
		Float yText = PAGE_SIZE_A4.getHeight() - marginTop;

		// ecriture du text
		contentStream.beginText();
		contentStream.setFont(PDType1Font.HELVETICA_BOLD, ConstanteUtils.DOSSIER_FONT_SIZE);
		contentStream.newLineAtOffset(xText, yText);
		contentStream.showText(textHeader);
		contentStream.endText();
	}
	return marginTop;
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:36,代码来源:CandidatureController.java

示例2: render

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
 * Renders this table to a document
 * 
 * @param document
 *            The document this table will be rendered to
 * @param width
 *            The width of the table
 * @param left
 *            The left edge of the table
 * @param top
 *            The top edge of the table
 * @param paddingTop
 *            The amount of free space at the top of a new page (if a page break is necessary)
 * @param paddingBottom
 *            The minimal amount of free space at the bottom of the page before inserting a page break
 * @return The bottom edge of the last rendered table part
 * @throws IOException
 *             If writing to the document fails
 */
@SuppressWarnings("resource")
public float render(final PDDocument document, final float width, final float left, float top, final float paddingTop, final float paddingBottom)
		throws IOException {
	float yPos = top;
	final PDPage page = document.getPage(document.getNumberOfPages() - 1);
	final PDRectangle pageSize = page.getMediaBox();
	PDPageContentStream stream = new PDPageContentStream(document, page, AppendMode.APPEND, true);
	float height = getHeight(width);
	if (height > pageSize.getHeight() - paddingTop - paddingBottom) {
		final float[] colWidths = getColumnWidths(width);
		for (int i = 0; i < rows.size(); ++i) {
			if (rows.get(i).getHeight(colWidths) > yPos - paddingBottom) {
				drawBorder(stream, left, top, width, top - yPos);
				stream = newPage(document, stream);
				top = pageSize.getHeight() - paddingTop;
				yPos = top;
				yPos = renderRows(document, stream, 0, getNumHeaderRows(), width, left, yPos);
				i = Math.max(i, getNumHeaderRows());
			}
			yPos = renderRows(document, stream, i, i + 1, width, left, yPos);
		}
		drawBorder(stream, left, top, width, top - yPos);

		handleEvent(EventType.AFTER_TABLE, document, stream, left, top, width, top - yPos);
	} else {
		if (height > top - paddingBottom) {
			stream = newPage(document, stream);
			top = pageSize.getHeight() - paddingTop;
			yPos = top;
		}
		yPos = renderRows(document, stream, 0, -1, width, left, yPos);
		drawBorder(stream, left, top, width, top - yPos);
		handleEvent(EventType.AFTER_TABLE, document, stream, left, top, width, top - yPos);
	}
	stream.close();

	return yPos;
}
 
开发者ID:errt,项目名称:BoxTable,代码行数:58,代码来源:Table.java

示例3: createBookPage

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
 * Creates a pdf page from two pages from another 'original' pdf document
 * @param doc original pdf from which the pages will be taken
 * @param leftPage page number of the page to go on the left side 
 * @param rightPage page number of the page to go on the right side
 * @return generated page containing the left and right pages from the original document side-by-side.
 */
private static PDPage createBookPage(PDDocument doc, int leftPage, int rightPage) {
	// double the width of a normal page to create the booklet
	PDRectangle baseSize = doc.getPage(0).getMediaBox();		
	PDRectangle box = new PDRectangle(baseSize.getWidth()*2, baseSize.getHeight());
	

	if(sizeOverride != null) {
		box = sizeOverride.asPDRectangle();
	}
	
	PDPage page = new PDPage(box);
	
	try {
		PDImageXObject leftImg = PrintDF.pageToImage(doc, leftPage, scale);
		PDImageXObject rightImg = PrintDF.pageToImage(doc, rightPage, scale);
		
		
		
		PDPageContentStream contentStream = new PDPageContentStream(doc, page);
		if(leftImg != null)
			contentStream.drawImage(leftImg, 0, 0, box.getWidth()/2, box.getHeight());
		if(rightImg != null)
			contentStream.drawImage(rightImg, box.getWidth()/2, 0, box.getWidth()/2, box.getHeight());
		contentStream.close();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	return page;
}
 
开发者ID:Raudius,项目名称:PrintDF,代码行数:39,代码来源:BookletMaker.java

示例4: findMaxFontSize

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
 * Calculates the maximum font size that can be used to fit in to a given bounding box.
 * Assumes that landscape (wider than taller) boxes are using horizontal text and
 * portrait (taller than wider) boxes are using text rotated 90 degrees
 * @param font Font text will be drawn in
 * @param text Lines of text to be drawn. Must contain at least one line
 * @param boundingBox Bounds to fit text in
 * @return font size
 * @throws IOException Error working with font bubbled up from PDFBox
 */
static int findMaxFontSize(PDFont font, List<String> text, PDRectangle boundingBox) throws IOException {
    if (text.size() == 0) {
        throw new RuntimeException("findMaxFontSize called with empty text argument");
    }
    float maxTextWidth;
    float maxTextHeight;
    if (boundingBox.getWidth() > boundingBox.getHeight()) {
        maxTextWidth = boundingBox.getWidth();
        maxTextHeight = boundingBox.getHeight();
    } else {
        maxTextWidth = boundingBox.getHeight();
        maxTextHeight = boundingBox.getWidth();
    }

    Float maxLineSize = Float.MAX_VALUE;
    for (String line : text) {
        float lineSize = findMaxLineSize(font, line, maxTextWidth, maxTextHeight);
        if (lineSize < maxLineSize) {
            maxLineSize = lineSize;
        }
    }
    if (maxLineSize * text.size() > maxTextHeight ) {
        maxLineSize = maxLineSize / text.size();
    }
    return  maxLineSize.intValue();
}
 
开发者ID:kumoregdev,项目名称:kumoreg,代码行数:37,代码来源:BadgeLib.java

示例5: processYAngle90

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
private static float processYAngle90(PDRectangle mediaBox, ImageAndResolution ires, SignatureImageParameters signatureImageParameters, BufferedImage visualImageSignature) {
    float y;

    SignatureImageParameters.VisualSignatureAlignmentHorizontal alignmentHorizontal = getVisualSignatureAlignmentHorizontal(signatureImageParameters);

    switch (alignmentHorizontal) {
        case LEFT:
        case NONE:
            y = signatureImageParameters.getxAxis();
            break;
        case CENTER:
            y = (mediaBox.getHeight() - ires.toXPoint(visualImageSignature.getHeight())) / 2;
            break;
        case RIGHT:
            y = mediaBox.getHeight() - ires.toYPoint(visualImageSignature.getHeight()) - signatureImageParameters.getxAxis();
            break;
        default:
            throw new IllegalStateException(SUPPORTED_HORIZONTAL_ALIGNMENT_ERROR_MESSAGE + alignmentHorizontal.name());
    }

    return y;
}
 
开发者ID:esig,项目名称:dss,代码行数:23,代码来源:SignatureImageAndPositionProcessor.java

示例6: processYAngle180

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
private static float processYAngle180(PDRectangle mediaBox, ImageAndResolution ires, SignatureImageParameters signatureImageParameters, BufferedImage visualImageSignature) {
    float y;

    SignatureImageParameters.VisualSignatureAlignmentVertical alignmentVertical = getVisualSignatureAlignmentVertical(signatureImageParameters);

    switch (alignmentVertical) {
        case TOP:
        case NONE:
            y = mediaBox.getHeight() - ires.toYPoint(visualImageSignature.getHeight()) - signatureImageParameters.getyAxis();
            break;
        case MIDDLE:
            y = (mediaBox.getHeight() - ires.toYPoint(visualImageSignature.getHeight())) / 2;
            break;
        case BOTTON:
            y = signatureImageParameters.getyAxis();
            break;
        default:
            throw new IllegalStateException(SUPPORTED_VERTICAL_ALIGNMENT_ERROR_MESSAGE + alignmentVertical.name());
    }

    return y;
}
 
开发者ID:esig,项目名称:dss,代码行数:23,代码来源:SignatureImageAndPositionProcessor.java

示例7: processYAngle270

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
private static float processYAngle270(PDRectangle mediaBox, ImageAndResolution ires, SignatureImageParameters signatureImageParameters, BufferedImage visualImageSignature) {
    float y;

    SignatureImageParameters.VisualSignatureAlignmentHorizontal alignmentHorizontal = getVisualSignatureAlignmentHorizontal(signatureImageParameters);

    switch (alignmentHorizontal) {
        case LEFT:
        case NONE:
            y = mediaBox.getHeight() - ires.toYPoint(visualImageSignature.getHeight()) - signatureImageParameters.getxAxis();
            break;
        case CENTER:
            y = (mediaBox.getHeight() - ires.toXPoint(visualImageSignature.getHeight())) / 2;
            break;
        case RIGHT:
            y = signatureImageParameters.getxAxis();
            break;
        default:
            throw new IllegalStateException(SUPPORTED_HORIZONTAL_ALIGNMENT_ERROR_MESSAGE + alignmentHorizontal.name());
    }

    return y;
}
 
开发者ID:esig,项目名称:dss,代码行数:23,代码来源:SignatureImageAndPositionProcessor.java

示例8: processYAngle360

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
private static float processYAngle360(PDRectangle mediaBox, ImageAndResolution ires, SignatureImageParameters signatureImageParameters, BufferedImage visualImageSignature) {
    float y;

    SignatureImageParameters.VisualSignatureAlignmentVertical alignmentVertical = getVisualSignatureAlignmentVertical(signatureImageParameters);

    switch (alignmentVertical) {
        case TOP:
        case NONE:
            y = signatureImageParameters.getyAxis();
            break;
        case MIDDLE:
            y = (mediaBox.getHeight() - ires.toYPoint(visualImageSignature.getHeight())) / 2;
            break;
        case BOTTON:
            y = mediaBox.getHeight() - ires.toYPoint(visualImageSignature.getHeight()) - signatureImageParameters.getyAxis();
            break;
        default:
            throw new IllegalStateException(SUPPORTED_VERTICAL_ALIGNMENT_ERROR_MESSAGE + alignmentVertical.name());
    }

    return y;
}
 
开发者ID:esig,项目名称:dss,代码行数:23,代码来源:SignatureImageAndPositionProcessor.java

示例9: toImages

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
@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;
}
 
开发者ID:sgoeschl,项目名称:java-image-processing-survival-guide,代码行数:22,代码来源:PdfBoxPreviewTest.java

示例10: drawStringRotatedWithResizing

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
     * Draws the given string, optionally supports scaling to fit.
     * @param x Left side of text, or center point of text if centered (1/72 inch)
     * @param y Bottom of text, in points (1/72 inch)
     * @param text Text to draw
     * @param optOrig Resize Options
     * @throws IOException Error generating PDF
     */
    void drawStringRotatedWithResizing(PDPageContentStream stream, float x, float y, int width, int height, String text, ResizeOptions optOrig) throws IOException {
        stream.setNonStrokingColor(Color.gray);
        PDRectangle boundingBox = new PDRectangle(x, y, width, height);
        stream.fillRect(x, y, width, height);

        ResizeOptions opt = new ResizeOptions(optOrig);
        float textSize = opt.font.getStringWidth(text); // in thousandths of font pt size.
        float size = opt.size;

        float centeredXPosition = x + (boundingBox.getWidth()/2f);
        float stringWidth = opt.font.getStringWidth( text );
        float centeredYPosition = y + (boundingBox.getHeight() /2f);

        stream.setNonStrokingColor(Color.GREEN);
        stream.fillRect(centeredXPosition, centeredYPosition, 3, 3);

        Matrix offset = Matrix.getRotateInstance(90 * Math.PI * 0.25,
                centeredXPosition, centeredYPosition-(stringWidth/1000/2));
        stream.beginText();
        stream.setTextMatrix(offset);

        stream.setStrokingColor(Color.black);
        stream.setNonStrokingColor(Color.black);
        stream.setFont(opt.font, size);
        stream.showText(text);
        stream.endText();

//
//        // If text size is greater than maximum width, recalculate the correct font size, based on our restrictions
//        if (textSize * (size/1000.0f) > opt.maxTextWidth) {
//            size = opt.maxTextWidth * 1000.0f / textSize;
//            if (size < opt.minFontSize) {
//                // We have utterly failed to fit the text with the minimum font size,
//                // So we're forced to use that.
//                size = opt.minFontSize;
//            }
//        }
//
//        if (opt.centered) {
//            y -= textSize * (size/(2*1000.0f));
//        }
////
////        Matrix offset = Matrix.getRotateInstance(i * Math.PI * 0.25,
////                centered XPosition, pageSize.getHeight() - centeredYPosition)
//        Matrix offset = new Matrix();
//        offset.rotate(Math.toRadians(5));
//        offset.translate(100, 100);
//        // Actually draw the text
    }
 
开发者ID:kumoregdev,项目名称:kumoreg,代码行数:58,代码来源:FormatterBase.java

示例11: createPageElement

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
 * Creates an element that represents a single page.
 * @return the resulting DOM element
 */
protected Element createPageElement()
{
    String pstyle = "";
    PDRectangle layout = getCurrentMediaBox();
    if (layout != null)
    {
        /*System.out.println("x1 " + layout.getLowerLeftX());
        System.out.println("y1 " + layout.getLowerLeftY());
        System.out.println("x2 " + layout.getUpperRightX());
        System.out.println("y2 " + layout.getUpperRightY());
        System.out.println("rot " + pdpage.findRotation());*/
        
        float w = layout.getWidth();
        float h = layout.getHeight();
        final int rot = pdpage.getRotation();
        if (rot == 90 || rot == 270)
        {
            float x = w; w = h; h = x;
        }
        
        pstyle = "width:" + w + UNIT + ";" + "height:" + h + UNIT + ";";
        pstyle += "overflow:hidden;";
    }
    else
        log.warn("No media box found");
    
    Element el = doc.createElement("div");
    el.setAttribute("id", "page_" + (pagecnt++));
    el.setAttribute("class", "page");
    el.setAttribute("style", pstyle);
    return el;
}
 
开发者ID:radkovo,项目名称:Pdf2Dom,代码行数:37,代码来源:PDFDomTree.java

示例12: createPageStyle

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
/**
   * Creates a style definition used for pages.
   * @return The page style definition.
   */
  protected NodeData createPageStyle()
  {
      NodeData ret = createBlockStyle();
      TermFactory tf = CSSFactory.getTermFactory();
      ret.push(createDeclaration("position", tf.createIdent("relative")));
ret.push(createDeclaration("border-width", tf.createLength(1f, Unit.px)));
ret.push(createDeclaration("border-style", tf.createIdent("solid")));
ret.push(createDeclaration("border-color", tf.createColor(0, 0, 255)));
ret.push(createDeclaration("margin", tf.createLength(0.5f, Unit.em)));

      PDRectangle layout = getCurrentMediaBox();
      if (layout != null)
      {
          float w = layout.getWidth();
          float h = layout.getHeight();
          final int rot = pdpage.getRotation();
          if (rot == 90 || rot == 270)
          {
              float x = w; w = h; h = x;
          }
          
          ret.push(createDeclaration("width", tf.createLength(w, unit)));
          ret.push(createDeclaration("height", tf.createLength(h, unit)));
      }
      else
          log.warn("No media box found");
      
      return ret;
  }
 
开发者ID:radkovo,项目名称:Pdf2Dom,代码行数:34,代码来源:CSSBoxTree.java

示例13: calculateSegmentBoundingBox

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
private Rectangle2D calculateSegmentBoundingBox(COSArray quadsArray, int segmentPointer) {
    // Extract coordinate values
    float upperLeftX = toFloat(quadsArray.get(segmentPointer));
    float upperLeftY = toFloat(quadsArray.get(segmentPointer + 1));
    float upperRightX = toFloat(quadsArray.get(segmentPointer + 2));
    float upperRightY = toFloat(quadsArray.get(segmentPointer + 3));
    float lowerLeftX = toFloat(quadsArray.get(segmentPointer + 4));
    float lowerLeftY = toFloat(quadsArray.get(segmentPointer + 5));

    // Post-processing of the raw coordinates.
    PDRectangle pageSize = page.getMediaBox();
    float ulx = upperLeftX - 1; // It is magic.
    float uly = pageSize.getHeight() - upperLeftY;
    float width = upperRightX - lowerLeftX;
    float height = upperRightY - lowerLeftY;

    return new Rectangle2D.Float(ulx, uly, width, height);
}
 
开发者ID:JabRef,项目名称:jabref,代码行数:19,代码来源:TextExtractor.java

示例14: startPage

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
@Override
protected void startPage(PDPage page) throws IOException {
	super.startPage(page);
	final PDRectangle rect = page.getCropBox();
	xFactor = imageDimension.width / rect.getWidth();
	yFactor = imageDimension.height / rect.getHeight();
}
 
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:8,代码来源:PDFBoxHighlighter.java

示例15: writeString

import org.apache.pdfbox.pdmodel.common.PDRectangle; //导入方法依赖的package包/类
@Override
protected void writeString(String text, List<TextPosition> textPositions) throws IOException {
    text = text.toLowerCase();
    int index = text.indexOf(mTextToHighlight);
    if (index != -1) {
        PDPage currentPage = getCurrentPage();
        PDRectangle pageBoundingBox = currentPage.getBBox();
        AffineTransform flip = new AffineTransform();
        flip.translate(0, pageBoundingBox.getHeight());
        flip.scale(1, -1);
        PDRectangle mediaBox = currentPage.getMediaBox();
        float mediaHeight = mediaBox.getHeight();
        float mediaWidth = mediaBox.getWidth();
        int size = textPositions.size();
        while (index != -1) {
            int last = index + mTextToHighlight.length() - 1;
            for (int i = index; i <= last; i++) {
                TextPosition pos = textPositions.get(i);
                PDFont font = pos.getFont();
                BoundingBox bbox = font.getBoundingBox();
                Rectangle2D.Float rect = new Rectangle2D.Float(0, bbox.getLowerLeftY(), font.getWidth(pos.getCharacterCodes()[0]), bbox.getHeight());
                AffineTransform at = pos.getTextMatrix().createAffineTransform();
                if (font instanceof PDType3Font) {
                    at.concatenate(font.getFontMatrix().createAffineTransform());
                } else {
                    at.scale(1 / 1000f, 1 / 1000f);
                }
                Shape shape = flip.createTransformedShape(at.createTransformedShape(rect));
                AffineTransform transform = mGC.getTransform();
                int rotation = currentPage.getRotation();
                if (rotation != 0) {
                    switch (rotation) {
                        case 90:
                            mGC.translate(mediaHeight, 0);
                            break;
                        case 270:
                            mGC.translate(0, mediaWidth);
                            break;
                        case 180:
                            mGC.translate(mediaWidth, mediaHeight);
                            break;
                        default:
                            break;
                    }
                    mGC.rotate(Math.toRadians(rotation));
                }
                mGC.fill(shape);
                if (rotation != 0) {
                    mGC.setTransform(transform);
                }
            }
            index = last < size - 1 ? text.indexOf(mTextToHighlight, last + 1) : -1;
        }
    }
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:56,代码来源:PdfRenderer.java


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