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


Java ImageIOUtil类代码示例

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


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

示例1: generateImage

import org.apache.pdfbox.tools.imageio.ImageIOUtil; //导入依赖的package包/类
@Override
public File generateImage(PDDocument pdDocument) throws FileNotFoundException {
    File imageFile = null;
    try{
        PDFRenderer pdfRenderer = new PDFRenderer(pdDocument);
        for(int x = 0;x < pdDocument.getNumberOfPages();x++){
            BufferedImage bImage = pdfRenderer.renderImageWithDPI(x,300, ImageType.RGB);
            ImageIOUtil.writeImage(bImage,String.format(folderPath + "/template_image.%s" ,"jpg"),300);
        }
        pdDocument.close();
        imageFile = new File(folderPath + "/template_image.jpg");
    }catch (IOException e){
        e.printStackTrace();
    }
    return  imageFile;
}
 
开发者ID:grassrootza,项目名称:grassroot-platform,代码行数:17,代码来源:PdfGeneratingServiceImpl.java

示例2: testSetCropBoxImgENG_US_NMATSCJ_1_103_0330

import org.apache.pdfbox.tools.imageio.ImageIOUtil; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/39689004/pdfbox-2-0-3-set-cropbox-using-textposition-coordinates">
 * PDFBox 2.0.3 Set cropBox using TextPosition coordinates
 * </a>
 * <br/>
 * <a href="http://downloadcenter.samsung.com/content/UM/201504/20150407095631744/ENG-US_NMATSCJ-1.103-0330.pdf">
 * ENG-US_NMATSCJ-1.103-0330.pdf
 * </a>
 * <p>
 * This test shows how to set the crop box on page twelve and render the cropped page as image.
 * </p>
 */
@Test
public void testSetCropBoxImgENG_US_NMATSCJ_1_103_0330() throws IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("ENG-US_NMATSCJ-1.103-0330.pdf"))
    {
        PDDocument pdDocument = PDDocument.load(resource);
        PDPage page = pdDocument.getPage(12-1);
        page.setCropBox(new PDRectangle(40f, 680f, 510f, 100f));

        PDFRenderer renderer = new PDFRenderer(pdDocument);
        BufferedImage img = renderer.renderImage(12 - 1, 4f);
        ImageIOUtil.writeImage(img, new File(RESULT_FOLDER, "ENG-US_NMATSCJ-1.103-0330-page12cropped.jpg").getAbsolutePath(), 300);
        pdDocument.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:28,代码来源:SetCropBox.java

示例3: savePdfPageAsPNG

import org.apache.pdfbox.tools.imageio.ImageIOUtil; //导入依赖的package包/类
/**
 * Renders PDF page with DPI specified in settings and saves it in specified directory.
 *
 * @param renderer  PDF renderer instance
 * @param page      page number
 * @param outputDir output directory
 * @throws IOException
 */
private void savePdfPageAsPNG(PDFRenderer renderer, int page, Path outputDir) throws IOException {
    BufferedImage bim;
    synchronized (this) {
        bim = renderer.renderImageWithDPI(page, settings.getPdfRenderingDpi(), ImageType.RGB);
    }
    Path outPath = outputDir.resolve(Paths.get("page_" + (page + 1) + ".png"));
    ImageIOUtil.writeImage(bim, outPath.toString(), settings.getPdfRenderingDpi());

}
 
开发者ID:rostrovsky,项目名称:pdf-table,代码行数:18,代码来源:PdfTableReader.java

示例4: toImageFiles

import org.apache.pdfbox.tools.imageio.ImageIOUtil; //导入依赖的package包/类
public static List<File> toImageFiles(File pdfFile, int resolution) throws Exception {
	PDDocument document = PDDocument.load(pdfFile);		
	PDFRenderer pdfRenderer = new PDFRenderer(document);
	/*
	List<PDPage> pages = new LinkedList<PDPage>();
	for (int i=0; i < document.getDocumentCatalog().getPages().getCount(); i++) {
		pages.add( document.getDocumentCatalog().getPages().get(i) );
	}
	*/
	File tmpDir = new File(Constants.getWorkTmpDir() + "/" + PdfConvertUtils.class.getSimpleName() 
			+ "/" + System.currentTimeMillis() + "/");
	FileUtils.forceMkdir( tmpDir );
	List<File> files = new LinkedList<File>();
	//int len = String.valueOf(pages.size()+1).length();
	int len = String.valueOf(document.getDocumentCatalog().getPages().getCount()+1).length();
	//for (int i=0; i<pages.size(); i++) {
	for (int i=0; i<document.getDocumentCatalog().getPages().getCount(); i++) {
		String name = StringUtils.leftPad(String.valueOf(i+1), len, "0");
		BufferedImage bufImage = pdfRenderer.renderImageWithDPI(i, resolution, ImageType.RGB);
		File imageFile = new File( tmpDir.getPath() + "/" + name + ".png" );
		FileOutputStream fos = new FileOutputStream(imageFile);
		ImageIOUtil.writeImage(bufImage, "png", fos, resolution);
		fos.flush();
		fos.close();
		files.add(imageFile);
	}
	document.close();
	tmpDir = null;
	return files;
}
 
开发者ID:billchen198318,项目名称:bamboobsc,代码行数:31,代码来源:PdfConvertUtils.java

示例5: initialize

import org.apache.pdfbox.tools.imageio.ImageIOUtil; //导入依赖的package包/类
@FXML
public void initialize() {
	this.txtImageLocation.setOnAction(ev -> {
		String location = this.txtImageLocation.getText();
		File file = new File(location);
		if (file.exists()) {
			FileUtil.openFile(file);
		}
	});

	// 붙여넣기시 클립보드 이미지 처리하는 함수.
	this.addEventHandler(KeyEvent.KEY_PRESSED, ev -> {

		if (ev.getCode() == KeyCode.V && ev.isControlDown()) {
			if (ev.isConsumed())
				return;
			Image pastImage = null;
			if ((pastImage = FxClipboardUtil.pastImage()) != null) {
				this.IvImage.setImage(pastImage);

				try {
					BufferedImage bufferedImage = SwingFXUtils.fromFXImage(pastImage, null);
					ByteArrayOutputStream output = new ByteArrayOutputStream();
					ImageIOUtil.writeImage(bufferedImage, "png", output);
					this.txtBase64.setText(Base64.getEncoder().encodeToString(output.toByteArray()));
				} catch (Exception e) {
					LOGGER.error(ValueUtil.toString(e));
				}
			}

			ev.consume();
		}

	});
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:36,代码来源:Base64ImageConvertComposte.java

示例6: toInputStream

import org.apache.pdfbox.tools.imageio.ImageIOUtil; //导入依赖的package包/类
/**
 * inputStream으로 변환
 *
 * @param bufferedImage
 * @return
 * @throws IOException
 */
public static InputStream toInputStream(BufferedImage bufferedImage) throws IOException {
	final ByteArrayOutputStream output = new ByteArrayOutputStream() ;
	
	ImageIOUtil.writeImage(bufferedImage, "png", output);
	return new ByteArrayInputStream(output.toByteArray()/*, 0, output.size()*/);
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:14,代码来源:PDFUtil.java


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