flex开发的仿pdf阅读器(swftools将PDF转成swf)
- 格式:doc
- 大小:52.50 KB
- 文档页数:7
SWFTools 是一组用来处理 Flash 的 swf 文件的工具包,包括:1. 合并工具 swfcombine2. 抽取工具 swfextract3. PDF/JPEG/PNG/AVI/TTF/WAV 到 SWF 的转换工具:pdf2swf, jpeg2swf, png2swf, avi2swf, font2swf, and wav2swf|4. 文本解析工具 swfstrings5. SWF 解析器 swfdump6. SWF 读写库 rfxswflib一个简单的将PDF文档转成SWF的用法:C:\SWFTools\pdf2swf Paper3.pdf -o Paper3.swf -f -T 9pdf2swf man pagepdf2swf -s parametersCurrent GitUsage: /usr/local/swft_git/bin/pdf2swf [-options] file.pdf -o file.swf-h , --help Print short help message and exit-V , --version Print version info and exit-o , --output file.swf Direct output to file.swf. If file.swf contains '%' (file%.swf), then each page goes to a seperate file.-p , --pages range Convert only pages in range with range e.g. 1-20 or 1,4,6,9-11 or-P , --password password Use password for deciphering the pdf.-v , --verbose Be verbose. Use more than one -v for greater effect. -z , --zlib Use Flash 6 (MX) zlib compression.-i , --ignore Allows pdf2swf to change the draw order of the pdf. This may make the generated-j , --jpegquality quality Set quality of embedded jpeg pictures to quality.0 is worst (small), 100 is best (big). (default:85)-s , --set param=value Set a SWF encoder specific parameter. See pdf2swf -s help for more information.-w , --samewindow When converting pdf hyperlinks, don't make the links open a new window.-t , --stop Insert a stop() command in each page.-T , --flashversion num Set Flash Version in the SWF header to num.-F , --fontdir directory Add directory to the font search path.-b , --defaultviewer Link a standard viewer to the swf file.-l , --defaultloader Link a standard preloader to the swf file which will be displayed while the main swf is loading.-B , --viewer filename Link viewer filename to the swf file.-L , --preloader filename Link preloader filename to the swf file.-q , --quiet Suppress normal messages. Use -qq to suppress warnings, also.-S , --shapes Don't use SWF Fonts, but store everything as shape. -f , --fonts Store full fonts in SWF. (Don't reduce to used characters).-G , --flatten Remove as many clip layers from file as possible. -I , --info Don't do actual conversion, just display a list of all pages in the PDF.-Q , --maxtime n Abort conversion after n seconds. Only available on Unix.-s Set a SWF encoder specificPDF Parameters:PDF device global parameters:fontdir=<dir> a directory with additional fontsfont=<filename> an additional font filenamepages=<range> the range of pages to convert (example: pages=1-100,210-) zoom=<dpi> the resultion (default: 72)languagedir=<dir> Add an xpdf language directorymultiply=<times> Render everything at <times> the resolutionpoly2bitmap Convert graphics to bitmapsbitmap Convert everything to bitmapsSWF Parameters:SWF layer options:jpegsubpixels=<pixels> resolution adjustment for jpeg images (same as jpegdpi, but in pixels)ppmsubpixels=<pixels resolution adjustment for lossless images (same as ppmdpi, but in pixels)subpixels=<pixels> shortcut for setting both jpegsubpixels and ppmsubpixelsdrawonlyshapes convert everything to shapes (currently broken) ignoredraworder allow to perform a few optimizations for creating smaller SWFslinksopennewwindow make links open a new browser windowlinktarget target window name of new linkslinkcolor=<color) color of links (format: RRGGBBAA)linknameurl Link buttons will be named like the URL they refer to (handy foriterating through links with actionscript)storeallcharacters don't reduce the fonts to used characters in the output fileenablezlib switch on zlib compression (also done if flashversion>=6)bboxvars store the bounding box of the SWF file in actionscript variablesdots Take care to handle dots correctlyreordertags=0/1 (default: 1) perform some tag optimizations internallinkfunction=<name> when the user clicks a internal link (to a different page) in the converted file, this actionscript function is calledexternallinkfunction=<name> when the user clicks an external link (e.g. http://www.foo.bar/) on the converted file, this actionscript function is called disable_polygon_conversion never convert strokes to polygons (will remove capstyles and joint styles)caplinewidth=<width> the minimum thichness a line needs to have so that capstyles become visible (and are converted)insertstop put an ActionScript "STOP" tag in every frame protect add a "protect" tag to the file, to prevent loading in the Flash editorflashversion=<version> the SWF fileversion (6)framerate=<fps> SWF framerateminlinewidth=<width> convert horizontal/vertical boxes smaller than this width to lines (0.05)simpleviewer Add next/previous buttons to the SWFanimate insert a showframe tag after each placeobject (animate draw order of PDF files)jpegquality=<quality> set compression quality of jpeg imagessplinequality=<value> Set the quality of spline convertion to value (0-100, default: 100).disablelinks Disable links.通过代码将PDF转换成SWF来说,现在比较常用的一种方式就是利用SWFTools工具中的pdf2swf(/)。
一、准备转换工具1.SWFTools (有windows系统的和 linux 系统的)2.xpdf (有windows系统的和 linux 系统的 )作用:主要解决中文乱码问题3.准备 FlexPaper_1.2.4_flash(网上直接下载里面含有 js插件 jsp页面下面会展示)FlexPaper( FlexPaper_1.2.4_flash 重命名来的)这个包必须放到 webapps 下面 jsp页面里面才能取得到文件二、1、上传的pdf文件到本地(windows 和 linux 都行)2、pdf 转成 swf (两种我都试过了,都成功了!)/*** @author张志广* QQ:691554407* pdf格式文件转化为swf格式插件* 插件要求:必须安装SWFTools工具* windows:D:\\SWFTools\\pdf2swf.exe 可以根据自己的路径进行修改* filePath = pdf文件上传路径(不含文件名);* fileName = "test.pdf";*/publicclass Convert {publicstaticvoid convertPDF2SWF(String filePath, StringfileName ,HttpServletRequest request) throws IOException { //使用pdf2swf转换命令//filePath = "C:" + filePath;String RealPath =request.getSession().getServletContext().getRealPath("/");RealPath = RealPath.substring(0,RealPath.length()-1);//System.out.println("-----------------RealPath="+ RealPath);File uploadFile = new File(RealPath + filePath); //指定上传文件的位置if(!uploadFile.exists() || uploadFile == null) { //判断指定路径dir是否存在,不存在则创建路径uploadFile.mkdirs();}String exepath_windows = "D:/SWFTools/pdf2swf.exe";String exePath_linux ="SWFTools/pdf2swf.exe";Process pro = null;String swffile_name =fileName.substring(0,fileName.indexOf("."))+".swf";if(isWindowsSystem()){//如果是windows系统String command= exepath_windows + " -t \""+filePath+"\\"+ fileName +"\" -o \""+RealPath + filePath+"\\"+ swffile_name +"\" -slanguagedir=D:\\xpdf\\xpdf-chinese-simplified -s flashversion=9 ";// System.out.println("command="+command);//执行cmd命令pro = Runtime.getRuntime().exec("cmd /c "+command);}else{//如果是linux系统,路径不能有空格,而且一定不能用双引号,否则无法创建进程/* String[] cmd = new String[2];cmd[0] = "/usr/local/bin/pdf2swf";cmd[1] = "-o "+RealPath + filePath+"/"+ swffile_name +" -T -z -t "+ languagedir=/usr/share/xpdf/xpdf-chinese-simplified -sflashversion=9";*/String command = "/usr/local/bin/pdf2swf -o "+ RealPath + filePath+"/"+ swffile_name +" -T -z -t "+ filePath+"/"+ fileName + " -s languagedir=/usr/share/xpdf/xpdf-chinese-simplified -s flashversion=9";//RealPath + filePath+"/"+ swffile_name必须转到webapps项目程下面去才能够在页面取得到// String cmd[]={"/bin/csh",null,command};////Runtime执行后返回创建的进程对象pro = Runtime.getRuntime().exec(command);}//非要读取一遍cmd的输出,要不不会flush生成文件(多线程)new DoOutput(pro.getInputStream()).start();new DoOutput(pro.getErrorStream()).start();try {//调用waitFor方法,是为了阻塞当前进程,直到cmd执行完pro.waitFor();} catch (InterruptedException e) {e.printStackTrace();}}/*** 判断是否是windows操作系统* @author iori* @return*/privatestaticboolean isWindowsSystem() {String p = System.getProperty("");return p.toLowerCase().indexOf("windows") >= 0 ? true :false;}/*** 多线程内部类* 读取转换时cmd进程的标准输出流和错误输出流,这样做是因为如果不读取流,进程将死锁* @author iori*/privatestaticclass DoOutput extends Thread {public InputStream is;// 构造方法public DoOutput(InputStream is) {this.is = is;publicvoid run() {BufferedReaderbr = new BufferedReader(new InputStreamReader(this.is));String str = null;try {// 这里并没有对流的内容进行处理,只是读了一遍while ((str = br.readLine()) != null);} catch (IOException e) {e.printStackTrace();} finally {if (br != null) {try {br.close();} catch (IOException e) {e.printStackTrace();}}}}}Action 中1、你可以在上传pdf文件后调用Convert进行转换//filePath:\file\db_file\2011413//fileName: iBATIS-SqlMaps.pdfString swf_name =fileName.substring(0,fileName.indexOf("."))+".swf";String real_swf_name = filePath + "/" + swf_name;request.setAttribute("real_swf_name", real_swf_name);----jsp页面<%@page language="java"contentType="text/html;charset=UTF-8"%><%@include file="../com/sessionCheck.jsp"%><%String context = request.getContextPath(); %><!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0Transitional//EN""/TR/xhtml1/DTD/xhtml1-transitional.d td"><!-- saved from url=(0014)about:internet --><html xmlns="/1999/xhtml"lang="en"xml:lang="en"><head><title></title><meta http-equiv="Content-Type"content="text/html; charset=utf-8"/><style type="text/css"media="screen">html,body{ height:100%; }body { margin:0; padding:0; overflow:auto; }#flashContent{ display:none; }</style><script type="text/javascript"src="js/swfobject/swfobject.js"></scrip t><script type="text/javascript">if(window.addEventListener)window.addEventListener('DOMMouseScroll', handleWheel, false);window.onmousewheel = document.onmousewheel = handleWheel;if (window.attachEvent)window.attachEvent("onmousewheel", handleWheel);function handleWheel(event){try{if(!window.document.FlexPaperViewer.hasFocus()){returntrue;}window.document.FlexPaperViewer.setViewerFocus(true);window.document.FlexPaperViewer.focus();if(navigator.appName == "Netscape"){if (event.detail)delta = 0;if (event.preventDefault){event.preventDefault();event.returnValue = false;}}returnfalse;}catch(err){returntrue;}}</script><script type="text/javascript"><!-- For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. -->var swfVersionStr = "9.0.124";<!-- To use express install, set to playerProductInstall.swf, otherwise the empty string. -->var xiSwfUrlStr = "${expressInstallSwf}";var flashvars = {SwfFile : escape("<%=context%>${real_swf_name}"), //工程名/你的swf真实路径(必须得在webapps下面)Scale : 0.6,ZoomTransition :"easeOut",ZoomTime : 0.5,ZoomInterval : 0.1,FitPageOnLoad :false,FitWidthOnLoad :true,PrintEnabled :true,FullScreenAsMaxWindow :false,localeChain: "en_US"};var params = {}params.quality = "high";params.bgcolor = "#ffffff";params.allowscriptaccess = "sameDomain";params.allowfullscreen = "true";var attributes = {};attributes.id = "FlexPaperViewer"; = "FlexPaperViewer";swfobject.embedSWF("/FlexPaper/FlexPaperViewer.swf", "flashContent", // 同样在webapps目录下,可以自己调"900", "600",swfVersionStr, xiSwfUrlStr,flashvars, params, attributes);swfobject.createCSS("#flashContent","display:block;text-align:center;");</script></head><body><div style="position:absolute;left:10px;top:10px;"><div id="flashContent"><p>需要安装flash 10 及以上版本才可以浏览。
flexpaper_flash使用说明1.FlexPaper简介FlexPaper是一个开源轻量级的文档浏览组件,被设计和比如PDF2SWF库(包含于SWFTools)一起工作,使得在网页上,Adobe Flex以及别的基于Flash的应用程序中显示和交互PDF文件成为可能。
即,使得在没有安装PDF阅读器软件的情况下浏览PDF文件成为可能。
FlexPaper 项目同时提供了Flex库和独立的Flash版本。
2.使用FlexPaper2.1下载FlexPaperFlexPaper在google code上的项目地址为/p/flexpaper/。
目前,FlexPaper 最新的flash版本为FlexPaper_1.5.1_flash.zip。
下载、解压后,可以看到如图6-1显示的目录:主要文件,文件夹说明:examples文件夹:存放FlexPaper使用的例子js文件夹:存放FlexPaper调用的js文件php文件夹:存放php使用FlexPaper的例子index.html:例子主页FlexPaperViewer.swf:FlexPaper的核心文件playerProductInstall.swf:如果客户端浏览器的flashplayer版本过低,将嵌入此swf文件2.2FlexPaper参数说明SwfFile(String):需要使用FlexPaper打开的文档Scale(Number):初始化缩放比例,参数值应该是大于零的整数(1=100%)ZoomTransition(String):FlexPaper中缩放样式,它使用和Tweener一样的样式,默认参数值为easeOut,其他可选值包括:easenone,easeout,linear,easeoutquadZoomTime(Number):从一个缩放比例变为另外一个缩放比例需要花费的时间,该参数值应该为0或更大ZoomInterval(Number):缩放比例之间间隔,默认值为0.1,该值应该为正数FitPageOnLoad(Boolean):初始化时自适应页面,与使用工具栏上的适应页面按钮同样的效果FitWidthOnLoad(Boolean):初始化时自适应页面宽度,与工具栏上的适应宽度按钮同样的效果localeChain(String):设置地区(语言),目前支持一下语言:en_US (English);fr_FR (French);zh_CN (Chinese,Simple);es_ES (Spanish);pt_BR (Brazilian Portugese);ru_RU (Russian);fi_FN (FInnish);de_DE (German);nl_NL (Netherlands);tr_TR (Turkish);se_SE (Swedish);pt_PT (Portugese);el_EL (Greek);da_DN (Danish);cz_CS (Czech);it_IT (Italian);pl_PL (Polish);pv_FN (Finish);hu_HU (Hungarian)。
Java FlexPaper swfTools_仿百度文库文档在线预览系统设计与实现最近在给客户开发文档管理系统时,客户要求上传到管理系统的文档(包括ppt,word,excel,txt)只能预览不允许下载。
想到了百度文库和豆丁网,百度文库和豆丁网的在线预览都是利用flash来播放文档的,在网上查阅了大量资料,终于实现了该项功能,现将自己的设计和实现整理如下,自己可以试试。
一、如何将文档转成flash支持的swf文件实现在线播放?1.先用openOffice把ppt、word、excel、txt类型的文档转换成pdf2.用swftools将pdf转换成swf,然后利用FlexPaper插件实现在线播放预览。
二、具体实现1.安装必备工具组件(1)安装openoffice,openoffice是开源免费的文字处理软件,它可以将office文档转成pdf文件(笔者安装到D:\Program Files),openOffice下载地址/download/index.html(2)安装完openoffice后必须启动其server,以命令行方式启动openoffice server。
进入cmd命令行提示符D:\Program Files\ 3\program\键入如下命令:soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;"–nofirststartwizard进入windows任务管理器查看有个进程soffice.bin,说明openoffice启动成功!(3)安装swfTools(安装到D:\Program Files)swftools作用是将pdf转换为swf文件以便flexpaper播放。
下载地址:/download.html(4)下载flexpaper,下载地址:/download/笔者下载的是FlexPaper_1.5.1,下载后将其解压备用。
一个可以把pdf转换swf的转换器,因为有时候需要pdf转换成swf来拿到别的地方用。
或者要把pdf转换成word、excel、HTML等文件格式时就需要到pdf转swf格式转换器啦。
一个万能的pdf格式转换器下载。
特别是一些工作人员,有时上头发下来的文件是pdf的要编辑的话需要转换word会比较方便哦。
无论你是转换那个pdf转swf格式转换器都可以的。
打开,pdf转换器后选择最下面的pdf转swf格式转换器。
这个就是用来把pdf转换成swf转换器了。
还有其他几个转换器大家需要的也可以直接打开用。
用法也是和,pdf转swf格式转换器差不多的。
然后把文件添加到pdf转swf格式转换器里面去,你可以点击左上角的绿色加号添加文件,也可以选择加号旁边的文件夹图标添加文件夹里面的全部pdf文件。
pdf 转swf格式转换器是可以批量转换的。
如果你文件不多也可以直接拖文件到pdf转swf格式转换器里面的空白区。
在pdf转swf格式转换器的左边你可以设置一下转换时的参数,比如说转换的开始页和结束页,或者全部转换。
还有是不是要添加播放按钮,FPS值是多少。
这些参数你都可以在设置里面一一选择。
选择好了后就点开始转换。
文件多的话就要久一点,个把文件pdf转swf格式转换器基本上是一两分钟就可以搞定。
Flexpaper 开发教程1. Flexpaper介绍1.1 Flexpaper是什么?Flexpaper 是由一家新西兰的 Devaldi 公司开发的在线浏览各 种文件的组件,它采用的是 GPL开源的协议,即源代码开放 并可以最其进行修改使用,这一切都是免费得,但不能对 Flexpaper 源码修改后封装成商业软件进行发布和销售。
Flexpaper 官方主页:1.2 Flexpaper可以做什么?如果你有一些DOC、PPT、PDF等格式的文档,想在网站里提供给大家在线阅读,那怎样做好呢?现在 Flexpaper 可以为你做到,当然 Flexpaper 还有一个搭档,那就是 SWFTools,通过 SWFTools 生产SWF,再通过Flexpaper组件显示,这对黄金搭档可以为你实现的在线文档功能。
使用Flexpaper浏览PDF,那需要PDF软件环境的支持吗?答案是不需要的,Flexpaper还可以被 当做 Flex 的库来使用,这些都使开发、使用变得更简单。
1.3 Flexpaper版本Flexpaper的初始版本1.0发布于2009年, 到现在已经有42个版本。
swc版本为组件包, 使用swc 组件包需要导入到工程中再调用,flash 版本为可以单独执行的,里面有例子、JS 文件、SWF 文 件,我们采用flash版本很容易就可以使用Flexpaper显示在线文档。
SWFTools介绍1.5 SWFTools介绍SWFTools是一个SWF处理、转换的开源工具,它的功能主要体现在:1. SWF的抽取、合并、解析、读写;2. PDF/JPEG/PNG/AVI/TTF/WAV等格式转换成SWF。
SWFTools是采用GPL开源协议,永久免费,现在SWFTools已经支持 Solaris, Linux (32 bit 和 64 bit), FreeBSD, OpenBSD, HPUX, Solaris, MacOS X and Windows 98/ME/2000/XP/Vista等多个系 统。
pdf转swf最简单方式
要将PDF文件转换为SWF文件(即Adobe Flash格式),可以使用一些工具和库来实现。
以下是其中一种简单的方式:
1. 使用SWFTools:SWFTools是一个开源的软件套件,提供了一些命令行工具来处理SWF文件。
2. 安装完SWFTools后,打开命令行终端或命令提示符。
3. 使用以下命令将PDF转换为SWF:
```
pdf2swf input.pdf -o output.swf -T 9
```
其中,input.pdf是要转换的PDF文件的路径,output.swf是生成的SWF文件的路径,-T 9用于指定转换质量,9表示最高质量。
4. 运行命令后,SWFTools将开始转换过程,并生成一个SWF文件。
请注意,SWF是一种已经逐渐被淘汰的技术,由于安全和性能方面的考虑,许多现代浏览器已停止对SWF的支持。
因此,在将PDF转换为SWF之前,建议您考虑是否有其他更适合的格式来呈现内容,例如HTML5或其他支持的文档格式。
Java基于springmvc实现⽂档预览(openoffice+swftools+fle。
Java基于springmvc实现⽂档预览(openoffice+swftools+flexpaper)(排坑记录)本⽂代码来源已在末尾标注,写本⽂的⽬的在于记录⾃⼰在实践过程中遇到的问题及解决⽅案需求实现⽂档在线预览原理1.通过第三⽅⼯具openoffice,将word、excel、ppt、txt等⽂件转换为pdf⽂件2.通过swfTools将pdf⽂件转换成swf格式的⽂件3.通过FlexPaper⽂档组件在页⾯上进⾏展⽰安装包下载1.openoffice是Apache下的⼀个开放免费的⽂字处理软件下载地址:Apache Open Office 4.x2.SWFTools是⼀组⽤来处理Flash的swf⽂件的⼯具包,我们使⽤它将pdf⽂件转成swf⽂件!下载地址:SWFTools官⽹下载 swftools-2013-04-09-1007.exe3.FlexPaper是⼀个开源轻量级的在浏览器上显⽰各种⽂档的组件下载地址:FlexPaper官⽹下载⼯具安装安装过程中,出现了点问题,我习惯将软件装在D:\Program Files (x86)或者D:\Program Files下,结果就是在这⾥出了问题安装openoffice,安装路径⾃定义,没有问题,安装完成后需要将服务打开,从cmd进⼊到openoffice 的安装盘符,⽤下⾯的命令启动服务soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard安装swftools,第⼀安装路径:D:\Program Files (x86)\SWFTools,安装完成,项⽬中有个swftools的路径,更改成安装路径,如下结果运⾏项⽬时,报错如下,说找不到这个⽂件断点调试后发现,程序中⽤到了swftools的安装路径,⽽路径中带有空格,按照空格符拆分字符串后,得到的路径时“D:\Program”,⽽不是”D:\Program Files (x86)\SWFTools”,于是问题转化为了怎么去去掉空格,避免这⾥拆分字符串后分离这个路径两种解决⽅案1、⽤另外的⽅法表⽰这个路径,使路径中不带有空格,这种想法⼜有两种实现,⼀种是缩写,另⼀种是镜像,亲⾃试验了⼀下两种都失败了,但是这⾥还是列出来,毕竟涨了⼀下姿势⽤缩写。
使用FlexPaper实现office文件的预览(C#版)需求很简单,用户上传office文件(word、excel、ppt)后,可以预览上传的这些文件。
搜索的相关的资料后。
整理如下:Step1.用户上传office文件。
Step2.把Office文件转化为pdf文件Step3.把pdf文件转化为swf文件Step4.使用flexpaper插件预览swf文件根据这四步,我们逐步分析:Step1.上传文件,在此不做赘述。
Step2.把Office文件转化为pdf文件。
必须保证你的office版本在2007之上。
我第一次使用office2003,不报错,但是也没用生成相关的pdf文件。
果断使用了最新的office2013即可完美运行。
在次贴出将word转化为pdf文件的代码,完整实例,请看附件。
///<summary>///把Word文件转换成为PDF格式文件///</summary>///<param name="sourcePath">源文件路径</param>///<param name="targetPath">目标文件路径</param>///<returns>true=转换成功</returns>public static bool WordToPDF(string sourcePath, string targetPath){bool result = false;Microsoft.Office.Interop.Word.WdExportFormat exportFormat = Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF;Microsoft.Office.Interop.Word.ApplicationClassapplication = null;Microsoft.Office.Interop.Word.Document document = null;try{application = newMicrosoft.Office.Interop.Word.ApplicationClass();application.Visible = false;document = application.Documents.Open(sourcePath); document.SaveAs();document.ExportAsFixedFormat(targetPath, exportFormat);result = true;}catch (Exception e){Console.WriteLine(e.Message);result = false;}finally{if (document != null){document.Close();document = null;}if (application != null){application.Quit();application = null;}GC.Collect();GC.WaitForPendingFinalizers();GC.Collect();GC.WaitForPendingFinalizers();}return result;}(考虑到有些和我一样的新手,在此赘述几句吧:如果你使用vs2010开发,在添加office 引用的时候,直接选择.net栏目下的office、Microsoft.Office.Interop.Word,Microsoft.Office.Interop.PowerPoint和Microsoft.Office.Interop.Excel,并且保证office的版本高于后三者就行啦。
3. SWFTools的简单使用有了第一章的介绍,大家对SWFTools应该有了基本的认识,下面我们开始演示怎样使用SWFTools 的gpdf2swf.exe、pdf2swf.exe的使用,由于本教程的内容范围较小,所以其他工具使用不在这里介绍。
3.1 使用swftools生成第一个SWF方式一、使用gpdf2swf可视化窗口我们打开gpdf2swf可视化窗口后,选择Open PDF,选择要生成SWF的PDF文件,之后保存为SWF,你可以选择把所有页面或者部分页面加入到SWF文件,操作如下图:(打开PDF文件)(选择PDF文件)(设置参数)(保存为SWF文件)在这里大家要注意,使用目前最新版本的SWFTools中gpdf2swf.exe生成PDF,在设置参数中,只能选择Flash 7或者8版本,但目前Flash 9或者10版本都大行其道,因此mark建议生成SWF时采用第二种方式,我们下面继续介绍。
方式二、使用pdf2swf.exe命令我们打开CMD,进入SWFTools的安装目录,这里我的安装目录是D:\Program Files\SWFTools,pdf2swf.exe的命令形式为:pdf2swf.exe [-options] file.pdf -o file.swf我们执行下面的命令:pdf2swf.exe -t F:\ajava\FusionCharts.pdf -s flashversion=9 -oF:\ajava\FusionCharts.swf由上图我们可以看到每页转换的提示,最后写入到SWF文件中,打开F:\ajava目录,可以看到FusionCharts.swf已经生成,这个swf的版本是flash 9。
这里用到了pdf2swf.exe的-t、-s、-o参数,下一节我们对pdf2swf.exe的参数作详细介绍。
注意:pdf2swf.exe命令中的文件名、目录名,不能带空格,否则不能生成SWF。
1.主要思路:文档(Word,PPT等)---->转换为pdf---->转换为SWF----->使用FlexPaper在线浏览第一步:文档--->转换为pdf用openoffice+jodconverter,openoffice是sun公司自己用Java写的一套开源office 软件,openoffice的缺点在于这个文件很大。
用Flashpaper实现,有绿色版,可通过命令行CMD调用。
第二步:pdf-->转swf用pdf2swf,pdf2swf提供了命令行参数,我们可以通过Java的Runtime和Process 调用pdf2swf提供的命令将pdf转为swf.第三步就是显示了,通过flexpaper实现2.CMD命令行中运行SWFTools文件夹名字带有空格对于-t,-o这两个参数,就是对于源文件路径来输出文件路径的问题,如果你的文件夹的名字中有空格的话,是不能找到文件的。
比如说:要转换的pdf源文件在E:\Program Files\SWFTools\这个文件夹下,当我这样写-t E:\Program Files\SWFTools\ajax.pdf或者是输出文件路径写成这样-o E:\Program Files\SWFTools\ajax.swf这样都是不能成功的,因为这里面有文件夹名含有空格,在路径的前后加上又引号就能成功啦,如-o"E:\Program Files\SWFTools\ajax.swf"这样就OK啦.3.Flexpaper不能加载swf文件FlexPaper加载swf时,一直处于等待状态,无法显示,检查swf的路径也没错,但就是一直无法加载。
这种情况,很有可能就是.swf文件的版本问题啦。
我们运行SWFTools的图形工具(gpdf2swf.exe)把pdf转换为swf,但是转换后的swf也不能被Flexpaper 正常加载,确保路径没错的话,那就是版本的问题啦。
以前我刚工作的时候,做一个视频的项目,用的是flash media server和flash。
其中有个需求是在线的文档协同浏览,也就是,用户上传一个word文档,ppt, pdf之类的,然后在浏览器里显示出来,还可以在上面涂涂画画的,并且是所有用户都能看见的。
当时为文档的转换很头疼,一直也没有好的方法,不过这个项目最后也没成功。
以前的那种转换的思路不是很好,是将doc转换为图片,然后再操作,用了一个c库,还非要在windows上搞。
现在竟然又要做一个在线文档转换和协同浏览的功能,不过换了一种思路,而且方法也成熟可靠很多。
现在的思路是doc,ppt,excel ,txt --->pdf---> 分割pdf ----> pdf --->swf 。
这样就可以分别操作每一页的文档了。
首先我们要做的就是把doc转换为pdf,这个用OpenOffice很方便的。
服务器用的是linux ,我装的是ooo3。
装ooo的时候记得装pyuno bridge 组件。
然后我们需要用到un oc onv,这其实是一个python文件,调用ooo来转换各种文档,比如,将a.doc转换为pdf,那么只需要unoconv -f pdf a.doc 就会生成一个a.pdf。
在使用unoconv的时候有两个需要注意的问题。
第一个就是需要x-server ,如果没有x,在转换的时候会报这样的错误:/usr/lib/ope no /program/soffice.bi n X11 error: Can't ope ndisplay:Set DISPLAY en vir onment variable, use -display opti onor check permissi ons of your X-Server(See "ma n X&qu ot; resp. "ma n xhost&qu ot; for details)但是我是有x桌面的,在转换的时候仍然会有这样的错误,解决的方法是导入环境变量exprot DISPLAY=localhost:1 ,这样就能成功转换,但是,作为服务器是不开x的。
JAVA+FlexPaper+swfTools仿文库文档在线阅读一、文档在线阅读思路1.用OpenOffice把PPT、Word、Excel、Text转换为pdf2.用SWFTool将生成的pdf转换成swf,然后利用FlexPlayer实现在线预览播放二、准备工作1.安装OpenOffice,官网下载地址:/download/index.html,最新版为3.4.1,我使用的版本为3.3.0:/share/link?shareid=1181746637&uk=1913152192#dir/path=%2F%E8%BD%AF%E4%BB%B6%E5%B7%A5%E5%85%B72.启动OpenOffice服务,CMD命令进入OpenOffice安装目录下的program 目录,键入如下命令soffice"-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManag er" -nologo -headless –nofirststartwizard参考资料:/hbcui1984/article/details/51091693.下载JODConverter:/projects/jodconverter/files/,项目中主要使用lib目录下的jar包。
4.下载并安装SWFTools:/download.html,下载exe文件安装完成即可5.下载FlexPlayer/share/link?shareid=1181746637&uk=1913152192 #dir/path=%2F%E8%BD%AF%E4%BB%B6%E5%B7%A5%E5%85%B7官网下载地址:/download/,版本为2.1.5,与1.5.1有较大差别,未使用最新版。
三、软件开发1.新建web项目并引入jar包阅读JODConverter/lib目录下的DEPENDENCIES.txt可知需要添加哪些jar包新建OfficeOnline项目,引入相应jar包(使用的是cos进行文档上传,cos.jar 需要另外下载),将FlexPaper_1.5.1_flash.zip解压后的js目录引入到项目中,FlexPaperViewer.swf也引入进来2.新建DocConverter.java注意:根据SWFTools安装路径不同需要修改pdf2swf()方法中pdf2swf.exe的路径,我安装的路径是在D盘main()测试中根据自己文档路径进行修改测试。
java将office文档pdf文档转换成swf文件在线预览第一步,安装是一套sun的开源office办公套件,能在widows,linux,solaris等操作系统上执行。
主要模块有writer(文本文档),impress(演示文稿),Calc(电子表格),Draw(绘图),Math (公式),base(数据库)笔者下载的是 3.3.0。
下载完直接安装即可。
但是,我们还需要启动openoffice server。
有两种做法:1.以命令行方式启动openoffice server,缺点是每次系统重启,都需要手动去把openoffice server启动。
2.将openoffice server作为操作系统的服务启动,既然成为了系统服务,就可以设定开机自动启动了。
我们先来看第一种方式,1.以命令行方式启动openoffice server在cmd命令下,cd opeonofiice的安装路径/program 如:cd c:\program files\ 3\program\soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard2.以系统服务的方式启动这里我们还需要Windows Resource Kit tools ,将openoffice server设为系统服务。
Windows Resource Kit tools 是微软专为管理人员、开发人员和高级用户开发的,包括管理活动目录、组策略、TCP/IP网络、注册表、系统安全、监测等涉及Windows Server 2003 操作系统的其它很多方面的非常规安装的工具组件。
Resource Kit Tools for XP的发布使得XP用户也能使用Resource Kit Tools对这些问题进行处理。
下载windows resource kit tools,我们进行默认安装。
Private Sub pdf2swf(ByVal fn As String)Dim fnl() As String = tools1.getfileinfo(fn)'Dim fnl1() As String = Split(fnl(0), "\")'Dim nfn As String = Label1.Text.Trim & "\" & fnl1(fnl1.Length - 2)'If Directory.Exists(nfn) = False Then' Directory.CreateDirectory(nfn)'End IfDim nfn As String = Label1.Text.Trimnfn = nfn & "\" & fnl(3)If Directory.Exists(nfn) = False ThenDirectory.CreateDirectory(nfn)End If'nfn = nfn & "\" & Int(Mid(fnl(1), fnl(1).Length - 2, 3)) & ".swf"nfn = nfn & "\" & fnl(1) & ".swf"If File.Exists(fn) = True And File.Exists(nfn) = False ThenTryDim proc As New System.Diagnostics.Processproc.StartInfo.FileName = "d:\pdf2swf\pdf2swf.exe"proc.StartInfo.Arguments = fn & " -o " & nfn & " -T 9 -G -f -s lang uagedir=d:\pdf2swf\"eShellExecute = Falseproc.StartInfo.RedirectStandardOutput = Trueproc.StartInfo.RedirectStandardError = Trueproc.StartInfo.CreateNoWindow = Trueproc.Start()'proc.PriorityClass = ProcessPriorityClass.NormalDim logpath As String = "w:\pdf2swf.txt"Dim log As String = proc.StandardOutput.ReadToEndtools1.AppendText(logpath, log)Dim loge As String = proc.StandardError.ReadToEndIf loge.Trim <> Nothing Thendgvrow(loge & " " & fn)tools1.AppendText(logpath, loge & " " & fn)End Ifproc.WaitForExit()'File.Delete(fn)Catch ex As Exceptiondgvrow(ex.Message)End TryEnd Ifprobarp()End Sub。
把PDF转换成像豆丁网那样的SWF
王彦博
【期刊名称】《网友世界》
【年(卷),期】2011(000)007
【摘要】平时我们搜索资料时,在豆丁网上会看到以SWF形式显示的文章,阅读起来享年方便,更方便的是制作这种形式的网页也报省事。
那如何才能将自己的PDF文档制作成这种形式的SWF文件呢?那就来使用SWFTools这款工具集提供的PDF2SWF小工具吧!
【总页数】1页(P21-21)
【作者】王彦博
【作者单位】不详
【正文语种】中文
【中图分类】TP317.4
【相关文献】
1.没有豆丁元照样下载豆丁文档 [J], 王昌红
2.网络文库的发展及运营模式的比较研究--以豆丁网与百度文库为例 [J], 姚平
3.豆丁网 [J],
4.无阻碍下载豆丁网的收费文档 [J], 王志军
5.PDF轻松转WORD:pdf转换成word转换器 [J],
因版权原因,仅展示原文概要,查看原文内容请购买。
flex开发的仿pdf阅读器(swftools将PDF转成swf)SWFTools 是一组用来处理 Flash 的 swf 文件的工具包,包括:1. 合并工具 swfcombine2. 抽取工具 swfextract3. PDF/JPEG/PNG/AVI/TTF/WAV 到 SWF 的转换工具:pdf2swf, jpeg2swf, png2swf,avi2swf, font2swf, and wav2swf|4. 文本解析工具 swfstrings5. SWF 解析器 swfdump6. SWF 读写库 rfxswflibSWFTools提供了一系列将各种文件转成swf的工具:∙font2swf.exe∙gif2swf.exe∙jpeg2swf.exe∙pdf2swf.exe∙png2swf.exe∙wav2swf.exe具体的功能就顾名思义了。
其中把pdf转成swf的工具就是pdf2swf了。
在命令行中运行pdf2swf src.pdf des.swf一般能满足需求。
而命令行参数可以通过pdf2swf -f得到:∙-h , –help Print short help message and exit 打印帮助信息∙-V , –version Print version info andexit 打印版本号∙-o , –output file.swf Direct output to file.swf. If file.swf contains ‘13568621′ (file13568630.swf), then each page指定输出的swf文件名∙-p , –pages range Convert only pages in range with range e.g.1-20or 1,4,6,9-11 or指定转换的页面范围,使用的页码描述方法与打印机打印文件时候的选页一样∙-P , –password password Use password for deciphering the pdf.指定打开pdf的密码∙-v , –verbose Be verbose. Use more than one -v for greater effect.转换时输出详细的内容∙-z , –zlib Use Flash 6 (MX) zlib compression.使用Flash 6的zlib压缩机制∙-i , –ignore Allows pdf2swf to change the draw order of the pdf. This may make the generated允许程序修改pdf的绘制顺序,可能会导致结果与原来有差异∙-j , –jpegquality quality Set quality of embedded jpeg pictures to quality. 0 is worst (small), 100 is best (big). (default:85)设置转换其中的jpeg图片的质量,从0到100,默认值是85。
∙-s , –set param=value Set a SWF encoder specific parameter. See pdf2swf -s help for more information. 设置SWF转码时候的参数,具体参数可以用pdf2swf -s help获取∙-w , –samewindow When converting pdf hyperlinks, don’t make the links open a new window. 设置转换后的swf打开原pdf中的连接时使用相同的窗口∙-t , –stop Insert a stop() command in each page. 在每页结尾添加一个stop()命令∙-T , –flashversion num Set Flash Version in the SWF header to num. 设置SWF所使用的flash版本号∙-F , –fontdir directory Add directory to the font search path. 指定字体文件所在路径∙-b , –defaultviewer Link a standard viewer to the swf file. 指定默认的swf导航文件,用来翻页、放大缩小等等∙-l , –defaultloader Link a standard preloader to the swf file which will be displayed while the main swf is loading. 指定默认的swf 加载文件,用来显示加载进程效果∙-B , –viewer filename Link viewer filename to the swf file. 指定swf导航文件,作用同-b∙-L , –preloader filename Link preloader filename to the swf file. 指定swf加载文件,作用同-l∙-q , –quiet Suppress normal messages. Use -qq to suppress warnings, also. 不打印普通信息,用-qq就不打印警告信息。
∙-S , –shapes Don’t use SWF Fonts, but store everything as shape. 不使用字体,所有都转为形状。
∙-f , –fonts St ore full fonts in SWF. (Don’t reduce to used characters). 在swf中保存全部字体。
∙-G , –flatten Remove as many clip layers from file as possible. 在文件中尽量去除影片层,合并它们∙-I , –info Don’t do actual conversion, just display a list of all pages in the PDF. 不做实际转换,仅显示PDF的信息。
∙-Q , –maxtime n Abort conversion after n seconds. Only available on Unix. 如果运行时间超时则退出。
然后看看-s都可以设置些什么:PDF Parameters:PDF device global parameters:fontdir= a directory with additional fonts 指定字体目录, 与1级参数的-F相若font= an additional font filename 增加额外的字体文件pages= the range of pages to convert (example: pages=1-100,210-) 指定页面范围,与1级参数的-p相若zoom= the resolution (default: 72) 指定分辨率,默认为72dpilanguagedir= Add an xpdf language directory 增加一个xpdf的语言目录,对非西欧字符有用multiply= Render everything at the resolution 在几倍分辨率下渲染poly2bitmap Convert graphics to bitmaps 把其中的图形转成点阵bitmap Convert everything to bitmaps 把所有内容转成点阵(包括字体)SWF Parameters:SWF layer options:jpegsubpixels=<pixels> resolution adjustment for jpeg images (same as jpegdpi, but in pixels) jpeg图片的分辨率ppmsubpixels=<pixels> resolution adjustment for lossless images (same asppmdpi, but in pixels) 无损图片的分辨率subpixels=<pixels> shortcut for setting both jpegsubpixels and ppmsubpixels 快速设置上两个参数drawonlyshapes convert everything to shapes (currently broken) 所有都转成图形ignoredraworder allow to perform a few optimizations for creating smaller SWFs 允许执行一些小优化linksopennewwindow make links open a new browser window 链接打开新窗口linktarget target window name of new links 新链接窗口的名称linkcolor=<color) color of links (format: RRGGBBAA) 链接的颜色linknameurl Link buttons will be named like the URL they refer to (handy for iterating through links with actionscript) 链接名称与链接URL一致storeallcharacters don’t reduce the fonts to used characters in the output file 保存所有的字符字体enablezlib switch on zlib compression (also done if flashversion>=7) 使用zlib压缩bboxvars store the bounding box of the SWF file in actionscript variables 在as中保存swf的区域大小dots Take care to handle dots correctly 保存单点显示reordertags=0/1 (default: 1) perform some tag optimizations 执行某些tag优化internallinkfunction=<name> when the user clicks a internal link (to a different page) in the converted file, this actionscript function is called 内部链接函数,如果点击一个内部链接,将调用该actionscript函数externallinkfunction=<name> when the user clicks an external link (e.g.有些pdf中的图形转换效果不好,会产生过多shape,这种情况下可以使用 -s poly2bitmap 的参数,将图形转成点阵。