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


Java PDDocument.getPage方法代码示例

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


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

示例1: render

import org.apache.pdfbox.pdmodel.PDDocument; //导入方法依赖的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

示例2: renderPage

import org.apache.pdfbox.pdmodel.PDDocument; //导入方法依赖的package包/类
public static void renderPage(String pdfPath, String outPath, int pageNumber, Rectangle area,
                              boolean drawTextChunks, boolean drawSpreadsheets, boolean drawRulings, boolean drawIntersections,
                              boolean drawColumns, boolean drawCharacters, boolean drawArea, boolean drawCells,
                              boolean drawUnprocessedRulings, boolean drawProjectionProfile, boolean drawClippingPaths,
                              boolean drawDetectedTables) throws IOException {
    PDDocument document = PDDocument.load(new File(pdfPath));

    ObjectExtractor oe = new ObjectExtractor(document);

    Page page = oe.extract(pageNumber + 1);

    if (area != null) {
        page = page.getArea(area);
    }

    PDPage p = document.getPage(pageNumber);

    BufferedImage image = Utils.pageConvertToImage(p, 72, ImageType.RGB);

    Graphics2D g = (Graphics2D) image.getGraphics();

    if (drawTextChunks) {
        debugTextChunks(g, page);
    }
    if (drawSpreadsheets) {
        debugSpreadsheets(g, page);
    }
    if (drawRulings) {
        debugRulings(g, page);
    }
    if (drawIntersections) {
        debugIntersections(g, page);
    }
    if (drawColumns) {
        debugColumns(g, page);
    }
    if (drawCharacters) {
        debugCharacters(g, page);
    }
    if (drawArea) {
        g.setColor(Color.ORANGE);
        drawShape(g, area);
    }
    if (drawCells) {
        debugCells(g, area, page);
    }
    if (drawUnprocessedRulings) {
        debugNonCleanRulings(g, page);
    }
    if (drawProjectionProfile) {
        debugProjectionProfile(g, page);
    }
    if (drawClippingPaths) {
        // TODO: Enable when oe.clippingPaths is done
        //drawShapes(g, oe.clippingPaths,
        //		new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, new float[] { 3f }, 0f));
    }
    if (drawDetectedTables) {
        debugDetectedTables(g, page);
    }

    document.close();

    ImageIO.write(image, "jpg", new File(outPath));
}
 
开发者ID:redmyers,项目名称:484_P7_1-Java,代码行数:66,代码来源:Debug.java

示例3: testJPEG2000DoesNotRaise

import org.apache.pdfbox.pdmodel.PDDocument; //导入方法依赖的package包/类
@Test
public void testJPEG2000DoesNotRaise() throws IOException {
    PDDocument pdf_document = PDDocument.load(new File("src/test/resources/technology/tabula/jpeg2000.pdf"));
    PDPage page = pdf_document.getPage(0);
    Utils.pageConvertToImage(page, 360, ImageType.RGB);
}
 
开发者ID:redmyers,项目名称:484_P7_1-Java,代码行数:7,代码来源:TestUtils.java


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