import com.itextpdf.text.Document; import com.itextpdf.text.Image; import com.itextpdf.text.Rectangle; import com.itextpdf.text.pdf.PdfWriter; import java.io.FileOutputStream; import java.io.IOException; public class Tifftopdf { /** * tiff文件转pdf文件 * @param source tiff文件输入路径 * @param target pdf文件输出路径 */ public static void convert(String source, String target) { Document document = new Document(); //设置文档页边距 document.setMargins(0,0,0,0); FileOutputStream fos = null; try { fos = new FileOutputStream(target); PdfWriter.getInstance(document, fos); //打开文档 document.open(); //获取图片的宽高 Image image = Image.getInstance(source); float imageHeight=image.getScaledHeight(); float imageWidth=image.getScaledWidth(); //设置页面宽高与图片一致 Rectangle rectangle = new Rectangle(imageWidth, imageHeight); document.setPageSize(rectangle); //图片居中 image.setAlignment(Image.ALIGN_CENTER); //新建一页添加图片 document.newPage(); document.add(image); } catch (Exception ioe) { System.out.println(ioe.getMessage()); } finally { //关闭文档 document.close(); try { fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); } } } public static void main(String[] args) { String source = "C:/ls_ftp/433003/1/2021/20210807/222.tiff";//输入文件路径 String target = "C:/ls_ftp/433003/1/2021/20210807/222.pdf";//输出文件路径 convert(source, target); } }
tiff文件转pdf文件
转载上一篇:pdf文件转tiff文件

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
SpringBoot word文件转pdf
当使用 maven 来打包jar 包发布时,需要注意配置将外部的jar包进行打包 includeSystemScope 标签配置为 true。
spring boot java spring jar 加载 -
tiff或tif文件的读取
以下是VC下读取TIFF文件的代码 下面的代码是用GDAL打开的
tiff tif ico 数据 perl -
如何实现PDF转Word文件,怎么把Word转PDF?
如何把Office文件转化为PDF文件呢?首先我们可以采用一些微软的软件进行转换,例如我们的Offic软件。其次给他家腿甲一个免费的快速便捷的转化工具: http://61office.cn/,可以实现office于PDF之间的互相转换。
office转word word转office office转换 PPT转HTML -
Js 之pdf文件转图片上传
Js 之pdf文件转图片上传
Js 之pdf文件转图片上传 -
jquery在线预览PDF文件,打开PDF文件
最主要的是使用
html jquery javascript -
Office 文件转 PDF 之服务实战
其他
flask python html