當前位置: 首頁>>代碼示例>>Java>>正文


Java PDDocument.getPages方法代碼示例

本文整理匯總了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 {

  };

}
 
開發者ID:hrbrmstr,項目名稱:pdfbox,代碼行數:51,代碼來源:App.java

示例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();	
	}
 
開發者ID:djdivix,項目名稱:IDBuilderFX,代碼行數:41,代碼來源:ExtractPhoto.java

示例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);

}
 
開發者ID:hrbrmstr,項目名稱:pdfbox,代碼行數:26,代碼來源:App.java


注:本文中的org.apache.pdfbox.pdmodel.PDDocument.getPages方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。