• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PDPageTree类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.pdfbox.pdmodel.PDPageTree的典型用法代码示例。如果您正苦于以下问题:Java PDPageTree类的具体用法?Java PDPageTree怎么用?Java PDPageTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PDPageTree类属于org.apache.pdfbox.pdmodel包,在下文中一共展示了PDPageTree类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testRemoveLikeStephanImproved

import org.apache.pdfbox.pdmodel.PDPageTree; //导入依赖的package包/类
/**
 * <a href="https://stackoverflow.com/questions/45812696/pdfbox-delete-comment-maintain-strikethrough">
 * PDFBox delete comment maintain strikethrough
 * </a>
 * <br/>
 * <a href="https://expirebox.com/files/3d955e6df4ca5874c38dbf92fc43b5af.pdf">
 * only_fields.pdf
 * </a>
 * <a href="https://file.io/DTvqhC">
 * (alternative download)
 * </a>
 * <p>
 * The OP only wanted the comment removed, not the strike-through. Thus, we must
 * not remove the annotation but merely the comment building attributes.
 * </p>
 */
@Test
public void testRemoveLikeStephanImproved() throws IOException {
    final COSName POPUP = COSName.getPDFName("Popup");
    try (InputStream resource = getClass().getResourceAsStream("only_fields.pdf")) {
        PDDocument document = PDDocument.load(resource);
        List<PDAnnotation> annotations = new ArrayList<>();
        PDPageTree allPages = document.getDocumentCatalog().getPages();

        List<COSObjectable> objectsToRemove = new ArrayList<>();

        for (int i = 0; i < allPages.getCount(); i++) {
            PDPage page = allPages.get(i);
            annotations = page.getAnnotations();

            for (PDAnnotation annotation : annotations) {
                if ("StrikeOut".equals(annotation.getSubtype()))
                {
                    COSDictionary annotationDict = annotation.getCOSObject();
                    COSBase popup = annotationDict.getItem(POPUP);
                    annotationDict.removeItem(POPUP);
                    annotationDict.removeItem(COSName.CONTENTS); // plain text comment
                    annotationDict.removeItem(COSName.RC);       // rich text comment
                    annotationDict.removeItem(COSName.T);        // author

                    if (popup != null)
                        objectsToRemove.add(popup);
                }
            }

            annotations.removeAll(objectsToRemove);
        }

        document.save(new File(RESULT_FOLDER, "only_fields-removeImproved.pdf"));
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:52,代码来源:RemoveStrikeoutComment.java


示例2: findPhoto

import org.apache.pdfbox.pdmodel.PDPageTree; //导入依赖的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: testRemoveLikeStephan

import org.apache.pdfbox.pdmodel.PDPageTree; //导入依赖的package包/类
/**
 * <a href="https://stackoverflow.com/questions/45812696/pdfbox-delete-comment-maintain-strikethrough">
 * PDFBox delete comment maintain strikethrough
 * </a>
 * <br/>
 * <a href="https://expirebox.com/files/3d955e6df4ca5874c38dbf92fc43b5af.pdf">
 * only_fields.pdf
 * </a>
 * <a href="https://file.io/DTvqhC">
 * (alternative download)
 * </a>
 * <p>
 * Due to a bug in the <code>COSArrayList</code> usage for page annotations,
 * the indirect reference to the annotation in question is not removed from
 * the actual page annotations array.
 * </p>
 */
@Test
public void testRemoveLikeStephan() throws IOException {
    try (InputStream resource = getClass().getResourceAsStream("only_fields.pdf")) {
        PDDocument document = PDDocument.load(resource);
        List<PDAnnotation> annotations = new ArrayList<>();
        PDPageTree allPages = document.getDocumentCatalog().getPages();

        for (int i = 0; i < allPages.getCount(); i++) {
            PDPage page = allPages.get(i);
            annotations = page.getAnnotations();

            List<PDAnnotation> annotationToRemove = new ArrayList<PDAnnotation>();

            if (annotations.size() < 1)
                continue;
            else {
                for (PDAnnotation annotation : annotations) {

                    if (annotation.getContents() != null
                            && annotation.getContents().equals("Sample Strikethrough")) {
                        annotationToRemove.add(annotation);
                    }
                }
                annotations.removeAll(annotationToRemove);
            }
        }

        document.save(new File(RESULT_FOLDER, "only_fields-removeLikeStephan.pdf"));
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:48,代码来源:RemoveStrikeoutComment.java


示例4: checkImageSimilarityPdf

import org.apache.pdfbox.pdmodel.PDPageTree; //导入依赖的package包/类
private void checkImageSimilarityPdf(String samplePdf, String checkPdf, float similarity) throws IOException {
	DSSDocument document = sign(signablePdfs.get(samplePdf));
	PDDocument sampleDocument = PDDocument.load(document.openStream());
	PDDocument checkDocument = PDDocument.load(getClass().getResourceAsStream("/visualSignature/check/" + checkPdf));

	PDPageTree samplePageTree = sampleDocument.getPages();
	PDPageTree checkPageTree = checkDocument.getPages();

	Assert.assertEquals(checkPageTree.getCount(), samplePageTree.getCount());

	PDFRenderer sampleRenderer = new PDFRenderer(sampleDocument);
	PDFRenderer checkRenderer = new PDFRenderer(checkDocument);

	for (int pageNumber = 0; pageNumber < checkPageTree.getCount(); pageNumber++) {
		BufferedImage sampleImage = sampleRenderer.renderImageWithDPI(pageNumber, DPI);
		BufferedImage checkImage = checkRenderer.renderImageWithDPI(pageNumber, DPI);

		float checkSimilarity = checkImageSimilarity(sampleImage, checkImage, CHECK_RESOLUTION);
		float calculatedSimilarity = ((int) (similarity * 100f)) / 100f; // calulate rotated position has about 1
																			// pixel position difference
		Assert.assertTrue(checkSimilarity >= calculatedSimilarity);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:24,代码来源:PAdESVisibleSignaturePositionTest.java


示例5: determineSafe

import org.apache.pdfbox.pdmodel.PDPageTree; //导入依赖的package包/类
int determineSafe(PDDocument document, PDAnnotationWidget widget) throws IOException
{
    COSDictionary widgetObject = widget.getCOSObject();
    PDPageTree pages = document.getPages();
    for (int i = 0; i < pages.getCount(); i++)
    {
        for (PDAnnotation annotation : pages.get(i).getAnnotations())
        {
            COSDictionary annotationObject = annotation.getCOSObject();
            if (annotationObject.equals(widgetObject))
                return i;
        }
    }
    return -1;
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:16,代码来源:DetermineWidgetPage.java


示例6: PdfBoxDrawer

import org.apache.pdfbox.pdmodel.PDPageTree; //导入依赖的package包/类
/**
 * Creates a new visualizer from the given PDDocument.
 */
public PdfBoxDrawer(PDDocument pdDocument) throws IOException {
  this.pdDocument = pdDocument;

  if (pdDocument == null) {
    throw new IllegalArgumentException("No pd document given");
  }
  
  PDDocumentCatalog catalog = pdDocument.getDocumentCatalog();
  
  if (catalog == null) {
    throw new IllegalArgumentException("No document catalog given.");
  }
  
  PDPageTree pages = catalog.getPages();
  
  if (pages == null) {
    throw new IllegalArgumentException("No pages given.");
  }
  
  this.pageStreams.add(null); // Add dummy, because pageNumbers are 1-based.
  this.pageBoundingBoxes.add(null);
  // Preallocate the list of streams.
  for (PDPage page : pages) {
    pageStreams.add(new PDPageContentStream(pdDocument, page,
        PDPageContentStream.AppendMode.APPEND, true));
    Rectangle boundingBox = new SimpleRectangle();

    PDRectangle box = page.getCropBox();
    if (box == null) {
      box = page.getMediaBox();
    }
    if (box != null) {
      boundingBox.setMinX(box.getLowerLeftX());
      boundingBox.setMinY(box.getLowerLeftY());
      boundingBox.setMaxX(box.getUpperRightX());
      boundingBox.setMaxY(box.getUpperRightY());
    }

    pageBoundingBoxes.add(boundingBox);
  }
}
 
开发者ID:ckorzen,项目名称:icecite,代码行数:45,代码来源:PdfBoxDrawer.java


示例7: extractImagesForOCR

import org.apache.pdfbox.pdmodel.PDPageTree; //导入依赖的package包/类
private void extractImagesForOCR(ParserResultItem result, PdfOcrContext context)
		throws SearchLibException, IOException, InterruptedException, java.util.concurrent.ExecutionException {

	context.ocr = ClientCatalog.getOcrManager();
	if (context.ocr == null || context.ocr.isDisabled())
		return;
	if (!getFieldMap().isMapped(ParserFieldEnum.ocr_content) && !getFieldMap().isMapped(
			ParserFieldEnum.image_ocr_boxes))
		return;
	if (context.ghostScript == null)
		context.pdfRenderer = new PDFRenderer(context.pdf);

	context.hocrPdf = new HocrPdf();
	final PDPageTree pageTree = context.pdf.getDocumentCatalog().getPages();
	int currentPage = 0;
	AtomicInteger emptyPageImages = new AtomicInteger(0);

	final ExecutorService executorService = config.getThreadPool();
	final List<Future<Boolean>> futures = new ArrayList<>();
	for (PDPage page : pageTree) {
		final ImageOcrCallable callable = new ImageOcrCallable(context, currentPage++, emptyPageImages);
		futures.add(executorService.submit(callable));
	}
	ThreadUtils.<Boolean>done(futures);

	if (currentPage > 0 && emptyPageImages.get() == currentPage)
		throw new SearchLibException("All pages are blank " + currentPage);

	if (getFieldMap().isMapped(ParserFieldEnum.image_ocr_boxes))
		context.hocrPdf.putHocrToParserField(result, ParserFieldEnum.image_ocr_boxes);
	if (getFieldMap().isMapped(ParserFieldEnum.ocr_content))
		context.hocrPdf.putTextToParserField(result, ParserFieldEnum.ocr_content);

}
 
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:35,代码来源:PdfParser.java


示例8: getThumbnail

import org.apache.pdfbox.pdmodel.PDPageTree; //导入依赖的package包/类
/**
 * Take a Snapshot from PDFObject.
 * 
 * @param media
 *              the MediaObject
 * @param seek
 *              position to take a snapshot
 * @param maxWidth
 *              maximum output width
 * @param maxHeight
 *              maximum output height
 * @param keepAspect
 *              set to keep aspect ratio
 */
@SuppressWarnings("unchecked")
public synchronized byte[] getThumbnail(MCRMediaObject media, long seek, int maxWidth, int maxHeight,
    boolean keepAspect)
    throws Exception {
    byte[] imageInByte = null;

    try (PDDocument pdf = PDDocument.load(new File(media.folderName + media.fileName))) {
        PDPageTree pages = pdf.getDocumentCatalog().getPages();
        PDFRenderer pdfRenderer = new PDFRenderer(pdf);

        BufferedImage image = pdfRenderer.renderImageWithDPI((int) seek, 96, ImageType.RGB);

        int[] scaledSize = ((MCRPDFObject) media).getScaledSize(maxWidth, maxHeight, keepAspect);

        BufferedImage resized = new BufferedImage(scaledSize[0], scaledSize[1], image.getType());
        Graphics2D g = resized.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
        g.drawImage(image, 0, 0, scaledSize[0], scaledSize[1], 0, 0, image.getWidth(), image.getHeight(), null);
        g.dispose();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(image, "png", baos);
        baos.flush();
        imageInByte = baos.toByteArray();
        baos.close();
    } catch (Exception e) {
        throw new Exception(e.getMessage());
    }

    return imageInByte;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:47,代码来源:MCRPDFObject.java


示例9: toImage

import org.apache.pdfbox.pdmodel.PDPageTree; //导入依赖的package包/类
/**
 * @작성자 : KYJ
 * @작성일 : 2017. 2. 20.
 * @param pdfFile
 * @param handler
 * @throws IOException
 */
public static void toImage(PdfToImageHandler handler) throws IOException {
	File pdfFile = handler.getPdfFile();
	try (PDDocument doc = PDDocument.load(pdfFile)) {
		PDFRenderer pdfRenderer = new PDFRenderer(doc);
		PDDocumentCatalog catal = doc.getDocumentCatalog();
		PDPageTree pages = catal.getPages();
		int totalPageCount = pages.getCount();
		int start = handler.getStartPage();
		int end = handler.getEndPage();

		//페이지 유효성 검증
		if (start > end) {
			throw new RuntimeException(String.format("Invalide page index start : %d end : %d", start, end));
		}

		if (start == -1)
			start = 0;
		if (end == -1)
			end = totalPageCount;

		if (end > totalPageCount) {
			end = totalPageCount;
		}

		// 파일 디렉토리 검증
		File outputDir = handler.getOutputDir();
		if (!outputDir.isDirectory()) {
			throw new RuntimeException("OutputDir is not Directory.");
		}

		//디렉토리가 없으면 생성
		if (!outputDir.exists())
			outputDir.mkdirs();

		for (int currentPage = start; currentPage < totalPageCount; currentPage++) {
			if (currentPage > end)
				break;
			BufferedImage renderImage = pdfRenderer.renderImage(currentPage);
			handler.write(outputDir, currentPage, renderImage);
		}
	}

}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:51,代码来源:PDFUtil.java


示例10: getPages

import org.apache.pdfbox.pdmodel.PDPageTree; //导入依赖的package包/类
PDPageTree getPages() {
return document.getPages();
   }
 
开发者ID:segreeeen,项目名称:fountainizer,代码行数:4,代码来源:AbstractPager.java


示例11: getPages

import org.apache.pdfbox.pdmodel.PDPageTree; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public PDPageTree getPages() {
	return document.getPages();
}
 
开发者ID:juliusHuelsmann,项目名称:paint,代码行数:7,代码来源:XDocument.java


示例12: processPages

import org.apache.pdfbox.pdmodel.PDPageTree; //导入依赖的package包/类
/**
 * This will process the given pages.
 * 
 * @param pages
 *          The pages object in the document.
 * 
 * @throws IOException
 *           If there is an error parsing the text.
 */
protected void processPages(PDPageTree pages) throws IOException {
  for (PDPage page : pages) {
    processPage(page);
  }
}
 
开发者ID:ckorzen,项目名称:icecite,代码行数:15,代码来源:PdfStreamEngine.java



注:本文中的org.apache.pdfbox.pdmodel.PDPageTree类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TaskListener类代码示例发布时间:2022-05-22
下一篇:
Java CallerPrincipalCallback类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap