操作PDF、tiff tifpdfjpg
程序员文章站
2024-03-24 19:16:34
...
public static void tif_2_jpg(String path)throws Exception{ FileSeekableStream ss = new FileSeekableStream(path); TIFFDecodeParam param0 = null; TIFFEncodeParam param = new TIFFEncodeParam(); JPEGEncodeParam param1 = new JPEGEncodeParam(); ImageDecoder dec = ImageCodec.createImageDecoder("tiff",ss,param0); int count = dec.getNumPages(); param.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4); param.setLittleEndian(false); System.out.println("这个文件有"+ count+"个图片"); File file = null; for (int i = 0; i < count; i++) { RenderedImage page = dec.decodeAsRenderedImage(i); file = new File(path.replace(path.substring(path.lastIndexOf("."),path.length()),i+"_tiff_.jpg")); System.out.println("SAVEING "+file.getAbsoluteFile()); ParameterBlock pb = new ParameterBlock(); pb.addSource(page); pb.add(file.toString()); pb.add("JPEG"); pb.add(param1); JAI.create("filestore",pb); } } 操作老版本的tiff
public static void tiffToJPEGByImageIO(String tiff) { ImageInputStream input; try { input = ImageIO.createImageInputStream(new File(tiff));//以图片输入流形式读取到tif // Get the reader while (ImageIO.getImageReaders(input).hasNext()){ ImageReader reader = ImageIO.getImageReaders(input).next();//获得image阅读器,阅读对象为tif文件转换的流 String path,tiffName; path = tiff.substring(0, tiff.lastIndexOf(".")); tiffName = tiff.substring(tiff.lastIndexOf("\\"),tiff.lastIndexOf(".")); try { reader.setInput(input); // Read page 2 of the TIFF file int count = reader.getNumImages(true);//tif文件页数 //System.out.println(count); for(int i = 0; i < count; i++){ BufferedImage image = reader.read(i, null);//取得第i页 File f = new File(path+"_"+i+".jpg"); ImageIO.write(image, "JPEG", f);//保存图片 } }catch (IOException e){ e.printStackTrace(); } finally { System.out.println(tiff+"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); reader.dispose(); input.close(); } } }catch (IOException e) { e.printStackTrace(); } } 操作pdf
public static void PDF2ImagPDFbox(String filePath)throws Exception { PDDocument pdf = null; pdf = PDDocument.load(new File(filePath)); PDFRenderer pdfRenderer = new PDFRenderer(pdf); PDPageTree pageTree = pdf.getPages(); int pageCounter = 0; for (int i = 0; i < pageTree.getCount(); i++) { float width = pageTree.get(i).getCropBox().getWidth(); float scale = 1.0f; if (width > 720) { scale = 720 / width; } BufferedImage bim = pdfRenderer.renderImage(i, scale, ImageType.RGB); ImageIOUtil.writeImage(bim, filePath.replace(filePath.substring(filePath.lastIndexOf("."), filePath.length()), i + ".jpg"), 300); System.out.println("!!!!!!!!!!!!!!!!"); } }
上一篇: Web中间件学习篇Tomcat
推荐阅读
-
操作PDF、tiff tifpdfjpg
-
利用itext操作pdf从数据库导出大量数据--创建PDF表格(三) 博客分类: 开源组件
-
利用itext操作pdf从数据库导出大量数据--创建PDF表格(三) 博客分类: 开源组件
-
利用itext操作pdf从数据库导出大量数据--功能汇总(一) 博客分类: 开源组件 javaitextpdf水印
-
java操作pdf
-
Itext5库的对PDF文件的基本操作(一)---新建文档,设置文档属性,设置文档密码
-
读取操作PDF的Java类库 JavaluceneXSLBeanJNI
-
java word操作 通过字符串生成word文件,读取word内容,word转pdf、html,pdf流输出展示到页面,file转 MultipartFile
-
如何基于DevExpress实现对PDF等文档预览及操作处理 DevExpressPDF文档处理
-
java使用pdfbox操作pdf文件示例