当前位置: 首页>>代码示例>>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;未经允许,请勿转载。