您的位置:首頁>正文

print2flash文檔線上預覽應用

一、背景

二、print2flash安裝

這裡LZ為了簡單實驗主要介紹破解版的安裝(費了好大的力才找到的), 如果商用, 還是給錢找別人買吧。

2)運行print2flashsetup.exe一直下一步就OK。

4)註冊print2flash4服務。 運行print2flash, options->print2flash service configuration,輸入Windows密碼, 沒有的話就不用輸, 勾選Grant access and launch pemmissions to Everyone給EveryOne用戶授予許可權。 點擊OK, 如果提示successful, Current status顯示Installed表示安裝成功。

5)開啟print2flash4服務。 安裝成功後, 在windows服務中可以找到print2flash服務。 啟動該服務。

三、java操作API

開始前我們需要將print2flash提供的SDK中的P2FConst.java引入:

1 public class P2FConst 2 { 3 // 枚舉常量 4 public static final int MSEXCEL = 0x00000001; 5 public static final int MSWORD = 0x00000002; 6 public static final int MSPOWERPOINT = 0x00000004; 7 public static final int ACROBAT = 0x00000008; 8 9 10 public static final int JPEG = 1; 11 public static final int PNG = 2; 12 13 14 public static final int STRETCH = 1; 15 public static final int TILE = 2; 16 17 18 public static final int INTLOGO = 0x00000001; 19 public static final int INTDRAG = 0x00000002; 20 public static final int INTSELTEXT = 0x00000004; 21 public static final int INTZOOMSLIDER = 0x00000008; 22 public static final int INTZOOMBOX = 0x00000010; 23 public static final int INTFITWIDTH = 0x00000020; 24 public static final int INTFITPAGE = 0x00000040; 25 public static final int INTPREVPAGE = 0x00000080; 26 public static final int INTGOTOPAGE = 0x00000100; 27 public static final int INTNEXTPAGE = 0x00000200; 28 public static final int INTSEARCHBOX = 0x00000400; 29 public static final int INTSEARCHBUT = 0x00000800; 30 public static final int INTROTATE = 0x00001000; 31 public static final int INTPRINT = 0x00002000; 32 public static final int INTNEWWIND = 0x00004000; 33 public static final int INTHELP = 0x00008000; 34 public static final int INTBACKBUTTON = 0x00030000; 35 public static final int INTBACKBUTTONAUTO = 0x00010000; 36 public static final int INTFORWARDBUTTON = 0x000C0000; 37 public static final int INTFORWARDBUTTONAUTO = 0x00040000; 38 public static final int INTFULLSCREEN = 0x00300000; 39 public static final int INTFULLSCREENAUTO = 0x00100000; 40 41 42 // METADATAPORMAT enumeration constants 43 public static final int XML = 1; 44 public static final int TEXT = 2; 45 46 // OUTPUTFORMAT enumeration constants 47 public static final int SINGLEFILE = 1; 48 public static final int SINGLEFILEPERPAGE = 2; 49 public static final int EXTVIEWER = 4; 50 51 // PAPER_ORIENTATION enumeration constants 52 public static final int ORIENT_PORTRAIT = 1; 53 public static final int ORIENT_LANDSCAPE = 2; 54 55 // PROTECTION_OPTION enumeration constants 56 public static final int PROTDISPRINT = 0x00000001; 57 public static final int PROTDISTEXTCOPY = 0x00000002; 58 public static final int PROTENAPI = 0x00000004; 59 60 // ThreeStateFlag enumeration constants 61 public static final int TSF_NO = 0; 62 public static final int TSF_YES = 1; 63 public static final int TSF_AUTO = 2; 64 65 // TOOLBARIMAGE enumeration constants 66 public static final int IMGLOGO = 1; 67 public static final int IMGDRAG = 2; 68 public static final int IMGSELTEXT = 3; 69 public static final int IMGZOOMRULER = 4; 70 public static final int IMGZOOMFOCUSNADLE = 5; 71 public static final int IMGZOOMNADLE = 6; 72 public static final int IMGFITWIDTH = 7; 73 public static final int IMGFITPAGE = 8; 74 public static final int IMGPREVPAGE = 9; 75 public static final int IMGNEXTPAGE = 10; 76 public static final int IMGSEARCHBUT = 11; 77 public static final int IMGROTATE = 12; 78 public static final int IMGPRINT = 13; 79 public static final int IMGNEWWIND = 14; 80 public static final int IMGHELP = 15; 81 public static final int IMGMORE = 16; 82 public static final int IMGTOOLBARBGR = 17; 83 public static final int IMGBACK = 18; 84 public static final int IMGFORWARD = 19; 85 public static final int IMGFULLSCREEN = 20; 86 public static final int IMGEXITFULLSCREEN = 21; 87 88 // TEMPLATETYPE enumeration constants 89 public static final int TEMPLATE_CUSTOM = 1; 90 public static final int TEMPLATE_ACTIONSCRIPT2 = 2; 91 public static final int TEMPLATE_ACTIONSCRIPT3 = 3; 92 93 // WATERMARKANCHOR enumeration constants 94 public static final int CENTER = 0; 95 public static final int LEFTCENTER = 1; 96 public static final int RIGHTCENTER = 2; 97 public static final int TOPCENTER = 16; 98 public static final int BOTTOMCENTER = 32; 99 public static final int LEFTTOP = 17; 100 public static final int RIGHTTOP = 18; 101 public static final int LEFTBOTTOM = 33; 102 public static final int RIGHTBOTTOM = 34; 103 104 // COMPRESSION_METHOD enumeration constants 105 public static final int COMPRESSION_METHOD_ZLIB = 0; 106 public static final int COMPRESSION_METHOD_LZMA = 1; 107 108 // DOCUMENT_TYPE Enumeration constants 109 public static final int FLASH = 1; 110 public static final int HTML5 = 2; 111 112 // BROWSER_TYPE Enumeration public static final intants 113 public static final int INTERNET_EXPLORER = 1; 114 public static final int FIREFOX = 2; 115 public static final int CHROME = 4; 116 public static final int OPERA = 8; 117 public static final int SAFARI = 16; 118 119 // POWERPOINT_PRINTOUTPUT Enumeration constants 120 public static final int POWERPOINT_PRINTOUTPUT_AUTO = 0; 121 public static final int POWERPOINT_PRINTOUTPUT_Slides = 1; 122 public static final int POWERPOINT_PRINTOUTPUT_TwoSlideHandouts = 2; 123 public static final int POWERPOINT_PRINTOUTPUT_ThreeSlideHandouts = 3; 124 public static final int POWERPOINT_PRINTOUTPUT_SixSlideHandouts = 4; 125 public static final int POWERPOINT_PRINTOUTPUT_NotesPages = 5; 126 public static final int POWERPOINT_PRINTOUTPUT_Outline = 6; 127 public static final int POWERPOINT_PRINTOUTPUT_BuildSlides = 7; 128 public static final int POWERPOINT_PRINTOUTPUT_FourSlideHandouts = 8; 129 public static final int POWERPOINT_PRINTOUTPUT_NineSlideHandouts = 9; 130 public static final int POWERPOINT_PRINTOUTPUT_OneSlideHandouts = 10; 131 }

開始轉換Test.java類:

1 package print2flash; 2 3 import java.io.IOException; 4 5 import com.jacob.activeX.*; 6 import com.jacob.com.*; 7 8 public class Test { 9 10 public static void main(String[] args) throws IOException { 11 try { 12 ComThread.InitSTA;//com組件管理,
用來初始化com執行緒, 釋放執行緒 13 ActiveXComponent p2f = new ActiveXComponent("Print2Flash4.Server");//創建print2flash的一個應用, 調用print2flash服務 14 //設置屬性值, 可根據自己需求修改 15 ActiveXComponent defProfile = new ActiveXComponent(p2f.getProperty("DefaultProfile").toDispatch); 16 defProfile.setProperty("InterfaceOptions", P2FConst.INTLOGO | P2FConst.INTZOOMSLIDER | P2FConst.INTPREVPAGE 17 | P2FConst.INTGOTOPAGE | P2FConst.INTNEXTPAGE); 18 defProfile.setProperty("ProtectionOptions", P2FConst.PROTDISPRINT | P2FConst.PROTENAPI); 19 defProfile.setProperty("DocumentType", P2FConst.FLASH | P2FConst.HTML5); 20 p2f.invoke("ConvertFile", "E:/print2flashTest/test.doc");//方法調用 21 System.out.println("轉換成功!"); 22 } catch (Exception e) { 23 System.out.println("轉換異常: " + e.toString); 24 } finally { 25 ComThread.Release; 26 } 27 } 28 }

1)將jacob.jar build path。

2)將jacob-1.16-M1-x64.dll(根據自己系統情況選擇)複製到jre/bin目錄(如果沒有該dll, 會拋出找不到ComThread類異常)

接下來LZ準備一個test.doc, 來進行測試:

test.docx.swf即為生成的flash檔, 可嵌入到你需要的網頁中。

四、.NET操作API

.NET的操作相對來說就簡單得多了, LZ這裡也是只做一個簡單的win32控制台演示:

1)首先新建win32控制台應用程式, 增加程式集Interop.Print2Flash4.dll。

2)在Proogram.cs中寫具體業務邏輯:

1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Linq; 5 using System.Text; 6 7 namespace Test 8 { 9 class Program 10 { 11 static void Main(string[] args) 12 { 13 string fs_filename = System.AppDomain.CurrentDomain.BaseDirectory+"/print2flashTest/test.docx"; 14 string fs_convertedfilename = System.AppDomain.CurrentDomain.BaseDirectory+"/print2flashTest/swf/test.swf"; 15 Print2Flash4.Server2 p2fServer = new Print2Flash4.Server2;//創建print2flash物件 16 //設置參數值, 可以參考官網SDK文檔 17 p2fServer.ConvertFile(fs_filename, fs_convertedfilename, null, null, null); 18 } 19 } 20 }

運行結果與java一樣。 官網SDK還提供了ASP、PHP等指令碼語言的操作API, 有情趣的同學可以自己嘗試一下。

五、總結

同類文章
Next Article
喜欢就按个赞吧!!!
点击关闭提示