本文整理匯總了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;
}
示例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));
}
示例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);
}