当前位置: 首页>>代码示例>>Java>>正文


Java PDXObjectImage类代码示例

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


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

示例1: buildImgKeyToImageObjMapping

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入依赖的package包/类
private static void buildImgKeyToImageObjMapping(PDPage page) throws IOException {
    PDResources resources = page.getResources();
    Map images = resources.getImages();

    if(images != null) {
        Iterator imageIter = images.keySet().iterator();

        while(imageIter.hasNext()) {
            String key = (String)imageIter.next();
            PDXObjectImage image = (PDXObjectImage)images.get(key);
            mapImgKeyToImageObj.put(key, image);
        }
    }
}
 
开发者ID:TekkLabs,项目名称:memoria-politica,代码行数:15,代码来源:FedDepPhotosUtility.java

示例2: exportImages

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入依赖的package包/类
private static void exportImages(File outputDir) throws IOException {
    for (String imgKey : mapImgKeyToPolName.keySet()) {
        String polName = StringUtil.stripAccents(mapImgKeyToPolName.get(imgKey));
        PDXObjectImage image = mapImgKeyToImageObj.get(imgKey);

        String dirPath = outputDir.getAbsolutePath();
        if (!dirPath.endsWith("/")) {
            dirPath += "/";
        }

        File outputFileName = new File(dirPath + polName + ".jpg");
        if (!outputFileName.getParentFile().exists() && !outputFileName.getParentFile().mkdirs()) {
            System.out.println("Não foi possível criar os diretórios intermediários para salvar o arquivo no caminho: " + outputFileName.getAbsolutePath());
        }

        if (!outputFileName.createNewFile()) {
            System.out.println("Não foi possível criar o arquivo: " + outputFileName.getAbsolutePath());
        }

        image.write2file(outputFileName);
        System.out.println("Arquivo salvo: " + outputFileName.getName());
    }
}
 
开发者ID:TekkLabs,项目名称:memoria-politica,代码行数:24,代码来源:FedDepPhotosUtility.java

示例3: extractPatternImages

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入依赖的package包/类
public void extractPatternImages(PDPatternResources pattern, String patternFormat) throws IOException
{
    COSDictionary resourcesDict = (COSDictionary) pattern.getCOSDictionary().getDictionaryObject(COSName.RESOURCES);
    if (resourcesDict == null)
        return;
    PDResources resources = new PDResources(resourcesDict);
    Map<String, PDXObject> xObjects = resources.getXObjects();
    if (xObjects == null)
        return;

    for (Map.Entry<String, PDXObject> entry : xObjects.entrySet())
    {
        PDXObject xObject = entry.getValue();
        String xObjectFormat = String.format(patternFormat, "-" + entry.getKey() + "%s", "%s");
        if (xObject instanceof PDXObjectForm)
            extractPatternImages((PDXObjectForm)xObject, xObjectFormat);
        else if (xObject instanceof PDXObjectImage)
            extractPatternImages((PDXObjectImage)xObject, xObjectFormat);
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:21,代码来源:ExtractPatternImages.java

示例4: extractAnnotationImages

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入依赖的package包/类
public void extractAnnotationImages(PDAppearanceStream appearance, String appearanceFormat) throws IOException
{
    PDResources resources = appearance.getResources();
    if (resources == null)
        return;
    Map<String, PDXObject> xObjects = resources.getXObjects();
    if (xObjects == null)
        return;

    for (Map.Entry<String, PDXObject> entry : xObjects.entrySet())
    {
        PDXObject xObject = entry.getValue();
        String xObjectFormat = String.format(appearanceFormat, "-" + entry.getKey() + "%s", "%s");
        if (xObject instanceof PDXObjectForm)
            extractAnnotationImages((PDXObjectForm)xObject, xObjectFormat);
        else if (xObject instanceof PDXObjectImage)
            extractAnnotationImages((PDXObjectImage)xObject, xObjectFormat);
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:20,代码来源:ExtractAnnotationImageTest.java

示例5: drawImageWithScale

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入依赖的package包/类
private static void drawImageWithScale(PDDocument doc, PDPageContentStream content, String imgPath,
                                       int bufferedImageType, float scale) throws IOException {
    BufferedImage bufferedImage = ImageIO.read(new File(imgPath));
    BufferedImage image = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), bufferedImageType);
    image.createGraphics().drawRenderedImage(bufferedImage, null);

    PDXObjectImage xImage = new PDPixelMap(doc, image);

    content.drawXObject(xImage, 100, 100, xImage.getWidth() * scale, xImage.getHeight() * scale);
}
 
开发者ID:asdf2014,项目名称:yuzhouwan,代码行数:11,代码来源:ReportConvertPdf.java

示例6: testPdfBox

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入依赖的package包/类
@Test
public void testPdfBox() throws IOException {

    File pdfFile = new File(PdfHelper.PDF_TEST_RESOURCES + "pdf/1.pdf");
    File outDir = new File("target");
    
    PDDocument document = PDDocument.load(pdfFile);
    @SuppressWarnings("unchecked")
    List<PDPage> pages = document.getDocumentCatalog().getAllPages();
    int imageId = 0;
    for (PDPage page : pages) {
        for (PDXObjectImage img : page.getResources().getImages().values()) {
            
            int height = img.getHeight();
            int width = img.getWidth();
            
            System.out.println(img.getCOSStream().toString());
            
            img.write2file(new File(outDir, imageId++ + "."
                    + img.getSuffix()));
        }
    }
}
 
开发者ID:BlueBrain,项目名称:bluima,代码行数:24,代码来源:ExtractImages.java

示例7: simpleDrawImage

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入依赖的package包/类
/**
     * TODO: extract byte[] from img and add it to ImageSegment
     *
     * @param x1
     * @param x2
     * @param y1
     * @param y2
     * @param img
     */
	public void simpleDrawImage(float x1, float x2, float y1, float y2, PDXObjectImage img ) {
		ImageSegment newImageSegment = new ImageSegment(x1, x2, y1, y2);
			//(ctm.getXPosition(), ctm.getXPosition() + (float)twh.getX(), 
				//ctm.getYPosition(), ctm.getYPosition() + (float)twh.getY());
/////		System.out.println("adding image segment: " + newImageSegment);
		newImageSegment.correctNegativeDimensions();
		newImageSegment.rotate(page);
/////		System.out.println("image before clipping: " + newImageSegment);
/////		System.out.println("clipBounds: " + clipBounds);
		newImageSegment.shrinkBoundingBox(clipBounds);
		if (!newImageSegment.isZeroSize())
		{
/////			System.out.println("adding image segment");
			imageList.add(newImageSegment);
		}
/////		else System.out.println("not adding image segment");
/////		System.out.println("after rotation: " + newImageSegment);
	}
 
开发者ID:tamirhassan,项目名称:pdfxtk,代码行数:28,代码来源:PDFObjectExtractor.java

示例8: drawImage

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入依赖的package包/类
public static void drawImage(final BufferedImage image,
    final PDDocument document, final PDPageContentStream contentStream,
    Position upperLeft, final float width, final float height)
    throws IOException {
PDXObjectImage cachedImage = getCachedImage(document, image);
float x = upperLeft.getX();
float y = upperLeft.getY() - height;
contentStream.drawXObject(cachedImage, x, y, width, height);
   }
 
开发者ID:ralfstuckert,项目名称:pdfbox-layout,代码行数:10,代码来源:CompatibilityHelper.java

示例9: getImageCache

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入依赖的package包/类
private static synchronized Map<BufferedImage, PDXObjectImage> getImageCache(
    final PDDocument document) {
Map<String, Map<?, ?>> documentCache = getDocumentCache(document);
@SuppressWarnings("unchecked")
Map<BufferedImage, PDXObjectImage> imageCache = (Map<BufferedImage, PDXObjectImage>) documentCache
	.get(IMAGE_CACHE);
if (imageCache == null) {
    imageCache = new HashMap<BufferedImage, PDXObjectImage>();
    documentCache.put(IMAGE_CACHE, imageCache);
}
return imageCache;
   }
 
开发者ID:ralfstuckert,项目名称:pdfbox-layout,代码行数:13,代码来源:CompatibilityHelper.java

示例10: testPDFBox

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入依赖的package包/类
@Test
public void testPDFBox() throws IOException {

	PDDocument document = null;

	File file = new File(JazzPDFReader.PDF_TESTE);

	document = PDDocument.load(file);

	List pages = document.getDocumentCatalog().getAllPages();

	for (Object object : pages) {

		PDPage page = (PDPage) object;
		PDResources resources = page.getResources();
		Map images = resources.getImages();
		if (images != null) {
			Set keySet = images.keySet();
			Iterator imageIter = keySet.iterator();
			while (imageIter.hasNext()) {
				String key = (String) imageIter.next();
				PDXObjectImage image = (PDXObjectImage) images.get(key);
				BufferedImage bufferedImage = image.getRGBImage();

				ImageIO.write(bufferedImage, "jpg", new File("/home/darcio/Desktop/ExamePDFTeste/pdfbox/imgFromPDFBOX" + System.currentTimeMillis() + ".jpg"));
			}
		}
	}
}
 
开发者ID:darciopacifico,项目名称:omr,代码行数:30,代码来源:JazzPDFReader.java

示例11: processResources

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入依赖的package包/类
/**
 *
 *
 * @param resources
 *
 * @throws IOException
 */
private void processResources(PDResources resources, TikaImageHelper helper)
throws IOException {
  if (resources == null)
    return;

  try {
    Map<String, PDXObject> xobjects = resources.getXObjects();
    if (xobjects != null) {
      Iterator<String> xobjectIter = xobjects.keySet().iterator();
      while (xobjectIter.hasNext()) {
        String key = xobjectIter.next();
        PDXObject xobject = xobjects.get(key);
        // write the images
        if (xobject instanceof PDXObjectImage) {
          PDXObjectImage image = (PDXObjectImage) xobject;
          if (ImageTools.imagePerPageRatioValid(imageCount++, pageCount)
              && ImageTools.imageSizeValid(image.getHeight(), image.getWidth())) {
            BufferedImage buffImage = image.getRGBImage();
            helper.addImage(buffImage);
          }
        }
        // maybe there are more images embedded in a form object
        else if (xobject instanceof PDXObjectForm) {
          if (ImageTools.imagePerPageRatioValid(imageCount, pageCount)) {
            PDXObjectForm xObjectForm = (PDXObjectForm) xobject;
            PDResources formResources = xObjectForm.getResources();
            processResources(formResources, helper);
          }
        }
      }
    }
  } catch (Exception e) {
    LOG.info("Shit happened", e);
  }

}
 
开发者ID:kolbasa,项目名称:OCRaptor,代码行数:44,代码来源:PDF2XHTML.java

示例12: addImageToPage

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入依赖的package包/类
public void addImageToPage(PDDocument document, int pdfpage, int x, int y, float scale, BufferedImage tmp_image)
        throws IOException {
    // Convert the image to TYPE_4BYTE_ABGR so PDFBox won't throw exceptions
    // (e.g. for transparent png's).
    BufferedImage image = new BufferedImage(tmp_image.getWidth(), tmp_image.getHeight(),
            BufferedImage.TYPE_4BYTE_ABGR);
    image.createGraphics().drawRenderedImage(tmp_image, null);

    PDXObjectImage ximage = new PDPixelMap(document, image);
    PDPage page = (PDPage) document.getDocumentCatalog().getAllPages().get(pdfpage);
    PDPageContentStream contentStream = new PDPageContentStream(document, page, true, true);

    contentStream.drawXObject(ximage, x, y, ximage.getWidth() * scale, ximage.getHeight() * scale);
    contentStream.close();
}
 
开发者ID:cmisdocs,项目名称:ServerDevelopmentGuideV2,代码行数:16,代码来源:CmisCustomPdfWatermarkServiceWrapper.java

示例13: scanResources

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入依赖的package包/类
private void scanResources(final PDResources rList, final PDDocument doc)
      throws FileNotFoundException, IOException {
    Map<String, PDXObject> xObs = rList.getXObjects();
    for(String k : xObs.keySet()) {
       final PDXObject xObj = xObs.get(k);
       if(xObj instanceof PDXObjectForm)
            scanResources(((PDXObjectForm) xObj).getResources(), doc);
       if(!(xObj instanceof PDXObjectImage))
            continue;
       PDXObjectImage img = (PDXObjectImage) xObj;
       System.out.println("Compressing image: " + k);
       final Iterator<ImageWriter> jpgWriters = 
               ImageIO.getImageWritersByFormatName("jpeg");
       final ImageWriter jpgWriter = jpgWriters.next();
       final ImageWriteParam iwp = jpgWriter.getDefaultWriteParam();
       iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
       iwp.setCompressionQuality(compQual);
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       jpgWriter.setOutput(ImageIO.createImageOutputStream(baos));
       jpgWriter.write(null,
               new IIOImage(img.getRGBImage(), null, null), iwp);
       ByteArrayInputStream bais = 
               new ByteArrayInputStream(baos.toByteArray());
       PDJpeg jpg = new PDJpeg(doc, bais);
       xObs.put(k, jpg);
    }
    rList.setXObjects(xObs);
}
 
开发者ID:bnanes,项目名称:shrink-pdf,代码行数:29,代码来源:ShrinkPDF.java

示例14: appendContent

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入依赖的package包/类
@Override
protected void appendContent(int start, int pages, int page, PDPageContentStream contentStream,
        PDRectangle rect) throws IOException {
    PDXObjectImage image = getResource().getImage();
    if (image != null) {
        float width = image.getWidth();
        float height = image.getHeight();
        AffineTransform transform = new AffineTransform(width, 0, 0, height, getCornerX(
                rect.getWidth(), width), getCornerY(rect.getHeight(), height));
        transform.rotate((float) ((getRotate() * Math.PI) / 180), 0.5, 0.5);
        contentStream.drawXObject(image, transform);
    }
}
 
开发者ID:brightgenerous,项目名称:brigen-base,代码行数:14,代码来源:ImagePageAppender.java

示例15: getImage

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入依赖的package包/类
@Override
public PDXObjectImage getImage() throws IOException {
    BufferedImage image;
    if (fileName != null) {
        image = ImageIO.read(new File(fileName));
    } else if (url != null) {
        image = ImageIO.read(url);
    } else if (bytes != null) {
        image = ImageIO.read(new ByteArrayInputStream(bytes));
    } else {
        throw new IllegalStateException();
    }
    return new PDJpeg(new PDDocument(), image, 1.0f);
}
 
开发者ID:brightgenerous,项目名称:brigen-base,代码行数:15,代码来源:ImageResource.java


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