如何把pdf格式的文件转换成照片怎么转换pdf格式格式

发表评论:
馆藏&15820
TA的推荐TA的最新馆藏[转]&[转]&[转]&使用PDFBox处理PDF文档(新建PDF文件、修改PDF文件、PDF中插入图片、将PDF文件转换为图片)-爱编程
使用PDFBox处理PDF文档(新建PDF文件、修改PDF文件、PDF中插入图片、将PDF文件转换为图片)
项目需要在原有的PDF文件中插入图片、文字,并将最终的PDF文件转换为图片,在网上找了很多Demo,现在开源可以解析处理PDF文件的第三方插件比较多,eg:IText、PDFBox等,现在就PDFBox解析处理PDF文件总结如下:
【PDFBox简介】
自从Adobe公司1993年第一次发布公共PDF参考以来,支持各种语言和平台的PDF工具和类库就如雨后春笋般涌现。然而,Java应用开发中Adobe技术的支持相对滞后了。这是个奇怪的现象,因为PDF文档是企业信息系统存储和交换信息的大势所趋,而Java技术特别适合这种应用。然而,Java开发人员似乎直到最近才获得成熟可用的PDF支持。
PDFBox(一个BSD许可下的源码开放项目)是一个为开发人员读取和创建PDF文档而准备的纯Java类库。它提供如下特性:
提取文本,包括Unicode字符。和Jakarta Lucene等文本搜索引擎的整合过程十分简单。加密/解密PDF文档。从PDF和XFDF格式中导入或导出表单数据。向已有PDF文档中追加内容。将一个PDF文档切分为多个文档。覆盖PDF文档。
PS:/link?url=TsYWHJtTPMhlf0UvKzPOk-j3f9KzF7morIa4CqoZ0s4yIDCLB3z8nLVgLHVz-AO4dE6S7ls_3_yuvXP03nLSiq
【PDFBox下载】
最常见的一种PDF文本抽取工具就是PDFBox了,访问网址http://pdfbox.apache.org/download.cgi,进入如下图所示的下载界面。读者可以在该网页下载其最新的版本。本书采用的是pdfbox-1.8.8版本。PDFBox是一个开源的Java PDF库,这个库允许你访问PDF文件的各项信息。在接下来的例子中,将演示如何使用PDFBox提供的API操作PDF文件。
【将刚下载的7个jar包引入到工程当中】
pdfbox-1.8.8-src.zip为pdfbox源代码,里面有很对的例子,在pdfbox-1.8.8\examples目录下存在
【以下为Demo正式开始】
1、创建PDF文件
public void createHelloPDF() {
PDDocument doc = null;
PDPage page = null;
doc = new PDDocument();
page = new PDPage();
doc.addPage(page);
PDFont font = PDType1Font.HELVETICA_BOLD;
PDPageContentStream content = new PDPageContentStream(doc, page);
content.beginText();
content.setFont(font, 12);
content.moveTextPositionByAmount(100, 700);
content.drawString("hello");
content.endText();
content.close();
doc.save("F:\\java56班\\eclipse-SDK-4.2-win32\\pdfwithText.pdf");
doc.close();
} catch (Exception e) {
System.out.println(e);
2、读取PDF文件:
public void readPDF() {
PDDocument helloDocument =
helloDocument = PDDocument.load(new File(
"F:\\java56班\\eclipse-SDK-4.2-win32\\pdfwithText.pdf"));
PDFTextStripper textStripper = new PDFTextStripper("GBK");
System.out.println(textStripper.getText(helloDocument));
helloDocument.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
3、修改PDF文件(处理中文乱码,我可以搞定的):
* Locate a string in a PDF and replace it with a new string.
* @param inputFile The PDF to open.
* @param outputFile The PDF to write to.
* @param strToFind The string to find in the PDF document.
* @param message The message to write in the file.
* @throws IOException If there is an error writing the data.
* @throws COSVisitorException If there is an error writing the PDF.
public void doIt( String inputFile, String outputFile, String strToFind, String message)
throws IOException, COSVisitorException
// the document
PDDocument doc = null;
doc = PDDocument.load( inputFile );
PDFTextStripper stripper=new PDFTextStripper("ISO-8859-1");
List pages = doc.getDocumentCatalog().getAllPages();
for( int i=0; i&pages.size(); i++ )
PDPage page = (PDPage)pages.get( i );
PDStream contents = page.getContents();
PDFStreamParser parser = new PDFStreamParser(contents.getStream() );
parser.parse();
List tokens = parser.getTokens();
for( int j=0; j&tokens.size(); j++ )
Object next = tokens.get( j );
if( next instanceof PDFOperator )
PDFOperator op = (PDFOperator)
//Tj and TJ are the two operators that display
//strings in a PDF
if( op.getOperation().equals( "Tj" ) )
//Tj takes one operator and that is the string
//to display so lets update that operator
COSString previous = (COSString)tokens.get( j-1 );
String string = previous.getString();
string = string.replaceFirst( strToFind, message );
System.out.println(string);
System.out.println(string.getBytes("GBK"));
previous.reset();
previous.append( string.getBytes("GBK") );
else if( op.getOperation().equals( "TJ" ) )
COSArray previous = (COSArray)tokens.get( j-1 );
for( int k=0; k&previous.size(); k++ )
Object arrElement = previous.getObject( k );
if( arrElement instanceof COSString )
COSString cosString = (COSString)arrE
String string = cosString.getString();
string = string.replaceFirst( strToFind, message );
cosString.reset();
cosString.append( string.getBytes("GBK") );
//now that the tokens are updated we will replace the
//page content stream.
PDStream updatedStream = new PDStream(doc);
OutputStream out = updatedStream.createOutputStream();
ContentStreamWriter tokenWriter = new ContentStreamWriter(out);
tokenWriter.writeTokens( tokens );
page.setContents( updatedStream );
doc.save( outputFile );
if( doc != null )
doc.close();
4、在PDF中加入图片:
* Add an image to an existing PDF document.
* @param inputFile The input PDF to add the image to.
* @param image The filename of the image to put in the PDF.
* @param outputFile The file to write to the pdf to.
* @throws IOException If there is an error writing the data.
* @throws COSVisitorException If there is an error writing the PDF.
public void createPDFFromImage( String inputFile, String image, String outputFile )
throws IOException, COSVisitorException
// the document
PDDocument doc = null;
doc = PDDocument.load( inputFile );
//we will add the image to the first page.
PDPage page = (PDPage)doc.getDocumentCatalog().getAllPages().get( 0 );
PDXObjectImage ximage = null;
if( image.toLowerCase().endsWith( ".jpg" ) )
ximage = new PDJpeg(doc, new FileInputStream( image ) );
else if (image.toLowerCase().endsWith(".tif") || image.toLowerCase().endsWith(".tiff"))
ximage = new PDCcitt(doc, new RandomAccessFile(new File(image),"r"));
BufferedImage awtImage = ImageIO.read( new File( image ) );
ximage = new PDPixelMap(doc, awtImage);
PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, true);
//contentStream.drawImage(ximage, 20, 20 );
// better method inspired by /a/646
float scale = 0.5f; // reduce this value if the image is too large
System.out.println(ximage.getHeight());
System.out.println(ximage.getWidth());
ximage.setHeight(ximage.getHeight()/5);
ximage.setWidth(ximage.getWidth()/5);
contentStream.drawXObject(ximage, 20, 200, ximage.getWidth()*scale, ximage.getHeight()*scale);
contentStream.close();
doc.save( outputFile );
if( doc != null )
doc.close();
5、PDF文件转换为图片:
1 public void toImage() {
PDDocument doc = PDDocument
.load("F:\\java56班\\eclipse-SDK-4.2-win32\\pdfwithText.pdf");
int pageCount = doc.getPageCount();
System.out.println(pageCount);
List pages = doc.getDocumentCatalog().getAllPages();
for (int i = 0; i & pages.size(); i++) {
PDPage page = (PDPage) pages.get(i);
BufferedImage image = page.convertToImage();
Iterator iter = ImageIO.getImageWritersBySuffix("jpg");
ImageWriter writer = (ImageWriter) iter.next();
File outFile = new File("F:\\java56班\\eclipse-SDK-4.2-win32\\"
+ i + ".jpg");
FileOutputStream out = new FileOutputStream(outFile);
ImageOutputStream outImage = ImageIO
.createImageOutputStream(out);
writer.setOutput(outImage);
writer.write(new IIOImage(image, null, null));
doc.close();
System.out.println("over");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
6、图片转换为PDF文件(支持多张图片转换为PDF文件):
* create the second sample document from the PDF file format specification.
* @param file
The file to write the PDF to.
* @param image
The filename of the image to put in the PDF.
* @throws IOException
If there is an error writing the data.
* @throws COSVisitorException
If there is an error writing the PDF.
public void createPDFFromImage(String file, String image)throws IOException, COSVisitorException {
// 多张图片转换为PDF文件
PDDocument doc = null;
doc = new PDDocument();
PDPage page = null;
PDXObjectImage ximage = null;
PDPageContentStream contentStream = null;
File files = new File(image);
String[] a = files.list();
for (String string : a) {
if (string.toLowerCase().endsWith(".jpg")) {
String temp = image + "\\" +
ximage = new PDJpeg(doc, new FileInputStream(temp));
page = new PDPage();
doc.addPage(page);
contentStream = new PDPageContentStream(doc, page);
float scale = 0.5f;
contentStream.drawXObject(ximage, 20, 400, ximage.getWidth()
* scale, ximage.getHeight() * scale);
PDFont font = PDType1Font.HELVETICA_BOLD;
contentStream.beginText();
contentStream.setFont(font, 12);
contentStream.moveTextPositionByAmount(100, 700);
contentStream.drawString("Hello");
contentStream.endText();
contentStream.close();
doc.save(file);
doc.close();
7、替换PDF文件中的某个字符串:
* Locate a string in a PDF and replace it with a new string.
* @param inputFile The PDF to open.
* @param outputFile The PDF to write to.
* @param strToFind The string to find in the PDF document.
* @param message The message to write in the file.
* @throws IOException If there is an error writing the data.
* @throws COSVisitorException If there is an error writing the PDF.
public void doIt( String inputFile, String outputFile, String strToFind, String message)
throws IOException, COSVisitorException
// the document
PDDocument doc = null;
doc = PDDocument.load( inputFile );
PDFTextStripper stripper=new PDFTextStripper("ISO-8859-1");
List pages = doc.getDocumentCatalog().getAllPages();
for( int i=0; i&pages.size(); i++ )
PDPage page = (PDPage)pages.get( i );
PDStream contents = page.getContents();
PDFStreamParser parser = new PDFStreamParser(contents.getStream() );
parser.parse();
List tokens = parser.getTokens();
for( int j=0; j&tokens.size(); j++ )
Object next = tokens.get( j );
if( next instanceof PDFOperator )
PDFOperator op = (PDFOperator)
//Tj and TJ are the two operators that display
//strings in a PDF
if( op.getOperation().equals( "Tj" ) )
//Tj takes one operator and that is the string
//to display so lets update that operator
COSString previous = (COSString)tokens.get( j-1 );
String string = previous.getString();
string = string.replaceFirst( strToFind, message );
System.out.println(string);
System.out.println(string.getBytes("GBK"));
previous.reset();
previous.append( string.getBytes("GBK") );
else if( op.getOperation().equals( "TJ" ) )
COSArray previous = (COSArray)tokens.get( j-1 );
for( int k=0; k&previous.size(); k++ )
Object arrElement = previous.getObject( k );
if( arrElement instanceof COSString )
COSString cosString = (COSString)arrE
String string = cosString.getString();
string = string.replaceFirst( strToFind, message );
cosString.reset();
cosString.append( string.getBytes("GBK") );
//now that the tokens are updated we will replace the
//page content stream.
PDStream updatedStream = new PDStream(doc);
OutputStream out = updatedStream.createOutputStream();
ContentStreamWriter tokenWriter = new ContentStreamWriter(out);
tokenWriter.writeTokens( tokens );
page.setContents( updatedStream );
doc.save( outputFile );
if( doc != null )
doc.close();
上述描述的只是PDFBox的部分功能,在原始资源包中有很对例子,大家可以学习,PDFBox API路径:http://pdfbox.apache.org/docs/1.8.8/javadocs/
版权所有 爱编程 (C) Copyright 2012. . All Rights Reserved.
闽ICP备号-3
微信扫一扫关注爱编程,每天为您推送一篇经典技术文章。【求助】怎样把pdf文件转换成高清的图片,要非常高清哦。_word吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:43,334贴子:
【求助】怎样把pdf文件转换成高清的图片,要非常高清哦。收藏
福利不只是穿多穿少,还要有迷人的微笑!
直接另存可以存为清晰的图片。最好不要用JPG格式。还可以通知虚拟打印机打印成图片。300线可以满足基本的打印要示,600线可以满足印刷要求。你要高清有多清楚?
我另存的图片不怎么高清啊。就是比原来的pdf图片不清晰很多。
Adobe Acrobat Pro用这个。你用的是什么软件?
Adobe Acrobat 7
你还可以用OFFICE带的虚拟打印机打印.用TIF格式,超精细.我电脑上只有300DPI.PDF文件本身中的图片清晰度比较低.原文件不够,怎么做也不会变成清晰的.多问一句:你这样做的目的是什么?
我要图片啊。 虚拟打印我不会唉,悲。
呵呵,你的提问是就要图片,你要图片做什么?我是想再推荐一个其它更好的方法。 只要装了OFFICE,就有虚拟打印机
图片有用,上传的,贴吧不是只能上传图片吗
你这个打印面是哪里的,调出word吗?
不需要,那只是个打印机。 图片只是为了上传,96DPI就行了。 还有,上传文件直接抓屏就可以了.
我菜鸟,不太会唉,不明白你说的。 图片稍微有点大,直接截屏搞不了。
你都用Adobe Acrobat 7了,还是菜鸟?我真服了你了! 图片要上传,屏幕显示不了,要再大有什么用?! 电脑是一个系统,不是一双筷子!
跟QuickTime有什么关系?
不晓得,不好打印。
记住伟大领袖毛主席的教导:天天学习,好好向上!
万一你上传的地方限制图片大小或者解析度你就要悲剧了。
楼主说了半天,也没说pdf文档的情况。pdf哪来的?里边的图片是不是清晰的?如果你pdf文档里的图片本身就不是很清楚,那你还怎么能存成“高清”的你需要的是一个资深PS高手,不是word用户!顺便说一下:“高清”一般用来描述视频,而不是图片。摄影这么多年,我还不知道什么样的图片算“高清”图片呢,OUT了
虚拟打印机超级好用,很棒
我试过 用photoshop,打开PDF,转换为图片,基本是很清晰的,希望对你有帮助
用PHOTOSHOP 打开PDF文件(填写300左右像素)然后直接另存为图片
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或您的位置:
扫描的PDF文件怎么转换成JPG格式图片
日 11:32:44 | 作者:冯伟 | 来源:it168网站
摘要:PDF格式文档相信大家都不会陌生,这也是常用的办公文档格式,扫描件也经常以PDF格式文档的形式进行保存。但是现今我们已经不仅仅满足于阅读PDF文件,更多的是需要对PDF文件进行编辑处理。
PDF格式文档相信大家都不会陌生,这也是常用的办公文档格式,扫描件也经常以PDF格式文档的形式进行保存。但是现今我们已经不仅仅满足于阅读,更多的是需要对PDF文件进行。
如果扫描的PDF文件内容为图片,需要编辑该扫描件的内容,我们应该怎么办呢?这个时候我们可以将PDF扫描文件进行格式转换处理,比如转换成图片再进行编辑。今天小编就和大家分享:扫描的PDF文件转换成的方法。
第一种方法,使用Adobe Reader软件。具体的操作步骤如下所示:
步骤1:首先安装Adobe Reader软件,运行该软件后点击界面上的“打开”,选择需要编辑的PDF文件。
步骤2:然后在工具栏处,依次点击“编辑――拍快照”选项。
步骤3:然后光标就会变成瞄准状态,只要移动到需要转换格式的页面处单击鼠标即可完成快照。这时会弹出一个对话框显示“选中区域已被复制”。
步骤4:最后打开一个画图工具,在界面菜单上点击“粘贴”按钮,再保存图片。之后就可以使用PS等图片编辑工具进行修改处理啦。
第二种方法,使用专业的迅捷PDF转换器。具体的操作步骤如下所示:
步骤1:首先用户需要安装迅捷PDF转换器,运行该软件后选择界面左侧的“文件转IMG”(其中“文件”已包含PDF格式)。
步骤2:然后点击“选择文件”选项,并且打开需要转换格式的PDF文件,再按“确定”按钮。
步骤3:最后在“自定义文件夹”处(+本站微信networkworldweixin),选择文件所用存放的路径,然后一键点击“开始转换”按钮即可。
迅捷PDF转换器的操作步骤非常的简单,不存在什么高难的的使用技巧。经过不断地优化与升级,目前迅捷PDF转换器已经成功地实现了基于超线程技术的PDF文件批量转换技术。只需把要转换的文件放置同一个文件夹,然后选择“添加文件夹” ,再一键点击“开始转换”即可完成批量转换。而且使用期间有任何问题,都可以找人工客服咨询,有专业的工程师为你保驾护航。
以上就是小编为大家介绍的内容――扫描的PDF文件怎么转换成JPG格式图片的方法。有需要的朋友,赶快使用上述方法进行文件格式转换吧!
[责任编辑:软件频道 ]
正在加载...
我也说几句
汇编一周来国内外网络和IT行业发生的焦点新闻,精挑细选,第一时间推送独家采写的深度报道和热点专题,深入挖掘新闻事件背后的故事,剖析新闻事件的来龙去脉,让读者准确把握业界的发展态势。
汇集存储频道每周精华内容,让您在最短的时间内,以最便捷的方式获取权威的购买指南,专家博客,皆汇聚在此。
定期为您带来深入权威的网络,交换机,路由器,无线,通信领域信息服务,涵盖产品,技术,新闻,应用案例,评测,购买指南,专栏,技巧等多个方面的信息。与企业网络相关的一切,尽在网络通信邮件,您怎可错过?
新一代数据中心建设管理最新信息快递――聚焦新一代绿色数据中心的设计、建设、运营和管理,汇集业界专家与用户的最精粹观点,展示国内外数据中心经典案例!
定期为您带来安全领域权威专业的产品,技术,新闻,应用案例,评测,购买指南等信息,保护您在网络畅游之时不受病毒的威胁,企业运行之际减少安全的风险。一份邮件在手,一份安全在心!
深入、专业关注云计算相关的技术与实践,范围覆盖私有云建设、公有云服务运营、开源云平台发展、重要云服务商动态等领域,面向企业CIO和IT经理提供深度原创报道,以及云计算、云服务领域最新的市场资讯。
汇集软件频道每周精华内容,让您在最短的时间内,以最便捷的方式获取权威的企业软件新闻,SOA,SaaS,BI,ERP,开源技术,产品,技巧等全方面的实用资讯。还犹豫什么,这就开始体验一下吧!
深入、专业关注大数据相关的技术与实践,提供Hadoop、NoSQL等领域的最新技术资讯,定期发布由业界专家撰写的大数据专栏文章,面向企业CIO、IT经理、DBA提供深度原创报道,以及大数据领域的最新市场资讯。
汇集服务器频道每周精华内容,让您在最短的时间内,以最便捷的方式获取权威的服务器虚拟化,刀片服务器,操作系统,大型机,服务器芯片信息,最新最全的服务器技巧,购买指南,专家博客,皆汇聚在此。
网界网网络学院频道,内容涵盖移动互联,技术开发,Web前端,安全,网络通信,云计算,数据中心,存储,服务器,软件等内容。
订阅过的用户,全部取消选择,可取消订阅
网络世界移动客户端网界网微信订阅号}

我要回帖

更多关于 照片转换为pdf格式 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信