本文整理匯總了Java中org.apache.pdfbox.pdmodel.PDDocument.getPages方法的典型用法代碼示例。如果您正苦於以下問題:Java PDDocument.getPages方法的具體用法?Java PDDocument.getPages怎麽用?Java PDDocument.getPages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.pdfbox.pdmodel.PDDocument
的用法示例。
在下文中一共展示了PDDocument.getPages方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: extractAttachments
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
public static void extractAttachments(String pdfPath, String extractPath) throws IOException {
PDDocument document = null;
try {
File input = new File(pdfPath);
String filePath = input.getParent() + System.getProperty("file.separator");
document = PDDocument.load(input);
PDDocumentNameDictionary namesDictionary =
new PDDocumentNameDictionary( document.getDocumentCatalog() );
PDEmbeddedFilesNameTreeNode efTree = namesDictionary.getEmbeddedFiles();
if (efTree != null) {
Map<String, PDComplexFileSpecification> names = efTree.getNames();
if (names != null) {
extractFiles(names, filePath);
} else {
List<PDNameTreeNode<PDComplexFileSpecification>> kids = efTree.getKids();
for (PDNameTreeNode<PDComplexFileSpecification> node : kids) {
names = node.getNames();
extractFiles(names, filePath);
};
};
};
for (PDPage page : document.getPages()) {
for (PDAnnotation annotation : page.getAnnotations()) {
if (annotation instanceof PDAnnotationFileAttachment) {
PDAnnotationFileAttachment annotationFileAttachment = (PDAnnotationFileAttachment) annotation;
PDComplexFileSpecification fileSpec = (PDComplexFileSpecification) annotationFileAttachment.getFile();
PDEmbeddedFile embeddedFile = getEmbeddedFile(fileSpec);
extractFile(filePath, fileSpec.getFilename(), embeddedFile);
};
};
};
} finally {
};
}
示例2: findPhoto
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
public static void findPhoto(String path,int empId) throws IOException, SQLException, Error{
// Loading an existing document
int imageFound=0;
File file = new File(path);
PDDocument document=PDDocument.load(file);
PDPageTree list=document.getPages();
for(PDPage page:list){ //check in all pages of pdf
PDResources pdResources=page.getResources(); //get all resources
for(COSName cosName:pdResources.getXObjectNames()) //loop for all resources
{
PDXObject pdxObject=pdResources.getXObject(cosName);
if (pdxObject instanceof PDImageXObject) { //check that the resource is image
BufferedImage br=((PDImageXObject) pdxObject).getImage();
RgbImage im = RgbImageJ2se.toRgbImage(br);
// step #3 - convert image to greyscale 8-bits
RgbAvgGray toGray = new RgbAvgGray();
toGray.push(im);
// step #4 - initialize face detector with correct Haar profile
InputStream is = ExtractPhoto.class.getResourceAsStream("/haar/HCSB.txt");
Gray8DetectHaarMultiScale detectHaar = new Gray8DetectHaarMultiScale(is, 1,40);
// step #5 - apply face detector to grayscale image
List<Rect> result= detectHaar.pushAndReturn(toGray.getFront());
if(result.size()!=0)
{
database.StorePhoto.storePhoto(empId,br);
imageFound=1;
break;
}
}
}
if(imageFound==1)
break;
}
System.out.println(imageFound);
if(imageFound!=1){
BufferedImage in = ImageIO.read(ExtractPhoto.class.getResource("/images/nopic.jpg"));
database.StorePhoto.storePhoto(empId,in);
}
document.close();
}
示例3: image_count
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
public static long image_count(String pdfPath) throws IOException {
PDDocument document = null;
long count = 0;
try {
File input = new File(pdfPath);
String filePath = input.getParent() + System.getProperty("file.separator");
document = PDDocument.load(input);
PdfImageCounter counter = new PdfImageCounter();
for (PDPage pdPage : document.getPages()) {
counter.processPage(pdPage);
}
count = counter.getDocumentImageCount();
} finally {};
return(count);
}