本文整理汇总了Java中org.apache.pdfbox.pdmodel.PDDocument.getNumberOfPages方法的典型用法代码示例。如果您正苦于以下问题:Java PDDocument.getNumberOfPages方法的具体用法?Java PDDocument.getNumberOfPages怎么用?Java PDDocument.getNumberOfPages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.pdmodel.PDDocument
的用法示例。
在下文中一共展示了PDDocument.getNumberOfPages方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.pdfbox.pdmodel.PDDocument; //导入方法依赖的package包/类
public void process(File pdf, File output){
PDDocument pdDoc;
try {//Kudos for closing: http://stackoverflow.com/questions/156508/closing-a-java-fileinputstream
File tmpfile = File.createTempFile(String.format("txttmp-%s", UUID.randomUUID().toString()), null);
RandomAccessFile raf = new RandomAccessFile(tmpfile, "rw");
pdDoc = PDDocument.loadNonSeq(pdf, raf);
FileWriter writer = new FileWriter(output);
try {
PDFTextStripper stripper = new PDFTextStripper();
int numberOfPages = pdDoc.getNumberOfPages();
for (int j = 1; j < numberOfPages+1; j++) {
stripper.setStartPage(j);
stripper.setEndPage(j);
writer.write(stripper.getText(pdDoc));
writer.flush();
}
} finally {
pdDoc.close();
raf.close();
tmpfile.delete();
writer.close();
}
} catch (IOException ioe) {
// log.warn(String.format("Failed to create txt for file: %s", pdf.getName()), ioe);
}
}
示例2: make
import org.apache.pdfbox.pdmodel.PDDocument; //导入方法依赖的package包/类
/**
* Given a pdf document, creates a printable booklet.
* @param doc original document to be converted
* @return booklet form of the original document.
*/
public static PDDocument make(PDDocument doc) {
PDDocument booklet = new PDDocument();
// "effective pages" defines the effective number of pages in the booklet (including blanks)
int effectivePages = doc.getNumberOfPages() + doc.getNumberOfPages() % 4;
// "pages" defines the actual number of sides of paper the booklet will use
int pages = effectivePages / 2;
boolean left = false; // smaller page number goes on the left?
for(int i=0; i<pages; i++) {
int page1 = i;
int page2 = effectivePages - i - 1;
PDPage page;
if(left) page = createBookPage(doc, page1, page2);
else page = createBookPage(doc, page2, page1);
booklet.addPage(page);
left = !left;
}
return booklet;
}
示例3: pagesSequence
import org.apache.pdfbox.pdmodel.PDDocument; //导入方法依赖的package包/类
/**
* Selects every 'period-th' page starting with 'start'
* @param doc document from which pages are selected
* @param start starting page which is selected
* @param period periodic interval at which pages a selected
* @return
*/
public static PageSelector pagesSequence(PDDocument doc, int start, int period) {
PageSelector br = new PageSelector();
for(int i=start; i<doc.getNumberOfPages(); i+=period)
br.addPage(doc, i);
return br;
}
示例4: pageToImage
import org.apache.pdfbox.pdmodel.PDDocument; //导入方法依赖的package包/类
public static PDImageXObject pageToImage(PDDocument doc, int page, int scale) throws IOException {
// return empty pages if page number excedes number of pages
if(page >= doc.getNumberOfPages())
return null;
PDFRenderer pdfRenderer = new PDFRenderer(doc);
BufferedImage bim = pdfRenderer.renderImage(page, scale);
PDImageXObject img = JPEGFactory.createFromImage(doc, bim);
return img;
}