swftools將PDF轉成swf (含中文的pdf注意事項)


1. 下載swftools:http://www.swftools.org/download.html

    下載xpdf xpdf-chinese-simplified

2 . 安裝swftools 

     解壓縮xpdf 至任意路徑(簡直是狗屁!明明路徑要求不能出現空格。如C:/Program Files/SWFTools/xpdf根本無法正常使用。得改為--> c:/xpdf/chinese-simplified)

 

3.

修改xpdf下xpdfrc文件 將cidToUnicode 等路徑改為本機路徑如:

#----- begin Chinese Simplified support package (2004-jul-27)

cidToUnicode     Adobe-GB1  xpdf路徑/chinese-simplified/Adobe-GB1.cidToUnicode

unicodeMap ISO-2022-CN     xpdf路徑/chinese-simplified/ISO-2022-CN.unicodeMap

unicodeMap EUC-CN       xpdf路徑/chinese-simplified/EUC-CN.unicodeMap

unicodeMap GBK      xpdf路徑/chinese-simplified/GBK.unicodeMap

cMapDir      Adobe-GB1  xpdf路徑/chinese-simplified/CMap

toUnicodeDir                 xpdf路徑/chinese-simplified/CMap

#displayCIDFontTT   Adobe-GB1  /usr/..../gkai00mp.ttf

4.java部分程序

String command = “C://Program Files//SWFTools//pdf2swf.exe” + “ -t /"”+ sourcePath +”/"+ “ -s languagedir=xpdf路徑//xpdf-chinese-simplified “+”-s flashversion=9 “+ ” -o /"”+ destPath + fileName+"/";

Process pro = Runtime.getRuntime().exec(command);

 

 

備注:

 

swftools將PDF轉成swf
SWFTools提供了一系列將各種文件轉成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 and exit                        打印版本號 
-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-20
or 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                   Store 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) 指定分辨率,默認為72dpi
languagedir= 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. http://www.foo.bar/) on the converted file, this actionscript function is called 外部鏈接函數,如果點擊一個外部鏈接,將調用該actionscript函數
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 在swf的每個楨中添加stop()函數
protect                     add a “protect” tag to the file, to prevent loadingin the Flash editor 增加protect標簽,禁止在flash中加載該swf
flashversion=<version>  the SWF fileversion (6) 設置最低swf版本
framerate=<fps>         SWF framerate  設置楨率
minlinewidth=<width>  convert horizontal/vertical boxes smaller than thiswidth to lines (0.05)將寬度少於某值的矩形轉成線條
simpleviewer     Add next/previous buttons to the SWF 使用簡單的導航
animate           insert a showframe tag after each placeobject (animate draw order of PDF files) ???
jpegquality=<quality>  set compression quality of jpeg images 設置jpeg的壓縮質量
splinequality=<value>  Set the quality of spline convertion to value (0-100, default: 100). 設置樣條曲線的轉換質量
disablelinks                Disable links.  禁止鏈接

 

-------------------------------------------------------------------------------------

通過swftools實現轉換

1.下載:http://www.swftools.org/swftools-2010-10-12-2000.exe

2.安裝完成之后,在命令行跳到安裝目錄,執行pdf2swf.exe d:\sss\123.pdf  -o 123.swf

如果123.pdf為多頁的,則pdf2swf.exe -qG -s disablelinks -s languagedir="D:\xpdf-chinese-simplified" D:\sss\123.pdf  123%.swf,結果為每頁分別轉換為一個swf文件。結果為1231.swf,1232.swf

-q 不打印普通信息 -G 在文件中盡量去除影片層,合並它們 -s disablelinks 屏蔽鏈接 -s languagedir= "D:\xpdf-chinese-simplified"   增加一個xpdf的語言目錄,可以有效解決中文亂碼的問題,這個需要自己配置目錄。

      1).下載XPDF:ftp://ftp.foolabs.com/pub/xpdf/xpdf-chinese-simplified.tar.gz 解壓到 D:\xpdf-chinese-simplified

     2).下載字體:http://blog.pjoke.com/wp-content/uploads/2009/02/font.zip 解壓到D:\xpdf-chinese-simplified\CMap\

     3).用寫字板(用記事本打開的話格式不一樣)打開並修改xpdf-chinese-simplified目錄下的add-to-xpdfrc文件。將里面的路徑設為自己的路徑:

      原來為linux的目錄表示,改為如下

  1. #----- begin Chinese Simplified support package (2004-jul-27)  
  2. cidToUnicode Adobe-GB1 D:\xpdf-chinese-simplified\Adobe-GB1.cidToUnicode  
  3. unicodeMap ISO-2022-CN D:\xpdf-chinese-simplified\ISO-2022-CN.unicodeMap  
  4. unicodeMap EUC-CN  D:\xpdf-chinese-simplified\EUC-CN.unicodeMap  
  5. unicodeMap GBK  D:\xpdf-chinese-simplified\GBK.unicodeMap  
  6. cMapDir  Adobe-GB1 D:\xpdf-chinese-simplified\CMap  
  7. toUnicodeDir   D:\xpdf-chinese-simplified\CMap  
  8. displayCIDFontTT Adobe-GB1 D:\xpdf-chinese-simplified\CMap\gkai00mp.ttf  
  9. #----- end Chinese Simplified support package  
  10.  

     4).參照上面的代碼,在調用pdf2swf命令中加入-s languagedir= "D:\xpdf-chinese-simplified" 參數即可。

亂碼問題參考:http://www.iteye.com/topic/538361

3.會在當前目錄中生成123.swf文件。

4.批處理做的一個簡單的流程:pdf-->swf

 

  1. @echo on 
  2.  
  3. set "file_name=cdn"                            ;源文件名稱  
  4. cd D:\sss\bad_files\s_files                 ;源文件目錄  
  5. java -jar d:\jodconverter-2.2.2\lib\jodconverter-cli-2.2.2.jar -f pdf  D:\sss\bad_files\s_files\%file_name%.docx                                ;word文件轉換為pdf  
  6. cd D:\sss\bad_files\apdf_swf           ;swf文件存在的目錄  
  7. pdf2swf.exe D:\sss\bad_files\s_files\%file_name%.pdf %file_name%%%.swf   ;pdf文件轉換為swf文件  
  8.  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM