浅谈print2flash的在线预览转换应用(原创)

print2flash是一种在线预览转换工具,可以将doc、docx、xls、pdf、ppt等格式的文档转换成flash文件进行预览,因为之前使用的flash2paper只支持32为操作系统,不支持64为win7,所以才考虑用print2flash。

在使用过程中遇到了很多问题,下面我将遇到的问题总结一下。

1、安装以后,进行pdf转换出现系统错误,code 1155 没有应用程序与当前的操作的文件相关联,百度以后才发现是注册表的问题,

运行regedit进入注册表,删除注册表中的
HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerFileExts.PDF 项,然后将以下内容保存为 REG 文件双击导入:

  1 Windows Registry Editor Version 5.00
  2 
  3 [HKEY_CLASSES_ROOT.pdf]
  4 "Content Type"="application/pdf"
  5 @="AcroExch.Document"
  6 
  7 [HKEY_CLASSES_ROOT.pdfOpenWithList]
  8 @=""
  9 
 10 [HKEY_CLASSES_ROOT.pdfOpenWithListAcroRd32.exe]
 11 @=""
 12 
 13 [HKEY_CLASSES_ROOT.pdfPersistentHandler]
 14 @="{F6594A6D-D57F-4EFD-B2C3-DCD9779E382E}"
 15 
 16 [HKEY_CLASSES_ROOT.pdfShellEx]
 17 
 18 [HKEY_CLASSES_ROOT.pdfShellEx{8895b1c6-b41f-4c1c-a562-0d564250836f}]
 19 @="{DC6EFB56-9CFA-464D-8880-44885D7DC193}"
 20 
 21 [HKEY_CLASSES_ROOTAcroExch.Document.7]
 22 "FriendlyTypeName"="PDF 文档"
 23 @="Adobe Acrobat Document"
 24 "EditFlags"=hex:00,00,01,00
 25 "BrowseInPlace"="1"
 26 
 27 [HKEY_CLASSES_ROOTAcroExch.Document.7CLSID]
 28 @="{B801CA65-A1FC-11D0-85AD-444553540000}"
 29 
 30 [HKEY_CLASSES_ROOTAcroExch.Document.7DefaultIcon]
 31 @="C:\Windows\Installer\{AC76BA86-7AD7-2052-7B44-A92000000001}\PDFFile_8.ico,0"
 32 
 33 [HKEY_CLASSES_ROOTAcroExch.Document.7Insertable]
 34 @=""
 35 
 36 [HKEY_CLASSES_ROOTAcroExch.Document.7protocol]
 37 
 38 [HKEY_CLASSES_ROOTAcroExch.Document.7protocolStdFileEditing]
 39 
 40 [HKEY_CLASSES_ROOTAcroExch.Document.7protocolStdFileEditingRequestDataFormats]
 41 @="NoteshNote"
 42 
 43 [HKEY_CLASSES_ROOTAcroExch.Document.7protocolStdFileEditingserver]
 44 @=""C:\Program Files\Adobe\Reader 9.0\Acrobat\Acrobat.exe""
 45 
 46 [HKEY_CLASSES_ROOTAcroExch.Document.7protocolStdFileEditingSetDataFormats]
 47 @="NotesDocInfo"
 48 
 49 [HKEY_CLASSES_ROOTAcroExch.Document.7protocolStdFileEditingverb]
 50 
 51 [HKEY_CLASSES_ROOTAcroExch.Document.7protocolStdFileEditingverb0]
 52 @="&Open"
 53 
 54 [HKEY_CLASSES_ROOTAcroExch.Document.7shell]
 55 @="Read"
 56 
 57 [HKEY_CLASSES_ROOTAcroExch.Document.7shellOpen]
 58 
 59 [HKEY_CLASSES_ROOTAcroExch.Document.7shellOpencommand]
 60 @=""C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe" "%1""
 61 
 62 [HKEY_CLASSES_ROOTAcroExch.Document.7shellPrint]
 63 
 64 [HKEY_CLASSES_ROOTAcroExch.Document.7shellPrintcommand]
 65 @=""C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe" /p /h "%1""
 66 
 67 [HKEY_CLASSES_ROOTAcroExch.Document.7shellPrintto]
 68 
 69 [HKEY_CLASSES_ROOTAcroExch.Document.7shellPrinttocommand]
 70 @=""C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe" /t "%1" "%2" "%3" "%4""
 71 
 72 [HKEY_CLASSES_ROOTAcroExch.Document.7shellRead]
 73 @="使用 Adobe Reader 9 打开"
 74 
 75 [HKEY_CLASSES_ROOTAcroExch.Document.7shellReadcommand]
 76 @=""C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe" "%1""
 77 
 78 [HKEY_CLASSES_ROOTAcroExch.Document.7Shellex]
 79 
 80 [HKEY_CLASSES_ROOTAcroExch.Document.7ShellexPropertySheetHandlers]
 81 @="InfoPage"
 82 
 83 [HKEY_CLASSES_ROOTAcroExch.Document.7ShellexPropertySheetHandlersInfoPage]
 84 @="{F9DB5320-233E-11D1-9F84-707F02C10627}"
 85 
 86 [HKEY_CLASSES_ROOTAcroExch.Document.7Shellex{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}]
 87 @="{F9DB5320-233E-11D1-9F84-707F02C10627}"
 88 
 89 [HKEY_CLASSES_ROOTAcroExch.Document]
 90 "FriendlyTypeName"="PDF 文档"
 91 "EditFlags"=hex:00,00,01,00
 92 "BrowseInPlace"="1"
 93 @="Adobe Acrobat Document"
 94 
 95 [HKEY_CLASSES_ROOTAcroExch.DocumentCLSID]
 96 @="{B801CA65-A1FC-11D0-85AD-444553540000}"
 97 
 98 [HKEY_CLASSES_ROOTAcroExch.DocumentCurVer]
 99 @="AcroExch.Document.7"
100 
101 [HKEY_CLASSES_ROOTAcroExch.DocumentDefaultIcon]
102 @="C:\Windows\Installer\{AC76BA86-7AD7-2052-7B44-A92000000001}\PDFFile_8.ico,0"
103 
104 [HKEY_CLASSES_ROOTAcroExch.DocumentShell]
105 
106 [HKEY_CLASSES_ROOTAcroExch.DocumentShellopen]
107 
108 [HKEY_CLASSES_ROOTAcroExch.DocumentShellopenCommand]
109 @=""C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe" "%1""

问题搞定。

2、关于引用dll的问题

这里要将jawin.dll添加到java.library.path中,至于如何添加请百度我就不详细说了。

3、在工程项目中添加jawin.jar包。

4、写测试类TestPrint2Flash

 1 import java.io.*;
 2 import org.jawin.DispatchPtr;
 3 import org.jawin.win32.Ole32;
 4 public class TestPrint2Flash{
 5 
 6     public static void main(String[] args) throws java.io.IOException{
 7      getswf("F:\自己动手写网络爬虫.pdf");
 8     }
 9     public static void getswf(String args) throws IOException{
10       if (args.length() > 0){
11            try{
12                 Ole32.CoInitialize();
13                 // Create Server object
14                 DispatchPtr p2f = new DispatchPtr("Print2Flash3.Server");
15             
16                 // Setup interface and protection options
17                 //DispatchPtr defProfile = (DispatchPtr)p2f.get("DefaultProfile");
18                 DispatchPtr DefBPOpt = (DispatchPtr)p2f.get("DefaultBatchProcessingOptions");
19                 //p2f.invoke("SetP2FPrinterAsDefault");
20                 //defProfile.put("ApplicationType", P2FConst.MSEXCEL|P2FConst.MSPOWERPOINT|P2FConst.MSWORD|P2FConst.ACROBAT);
21                 //defProfile.put("InterfaceOptions",P2FConst.INTLOGO | P2FConst.INTZOOMSLIDER | P2FConst.INTPREVPAGE | P2FConst.INTGOTOPAGE | P2FConst.INTNEXTPAGE);
22                 //DefBPOpt.put("ProtectionOptions", P2FConst.PROTDISPRINT | P2FConst.PROTENAPI);
23                 DefBPOpt.put("BeforePrintingTimeout", 6000);
24                 DefBPOpt.put("PrintingTimeout", 60000);
25                 DefBPOpt.put("KeepAutomationAppRef",P2FConst.MSEXCEL|P2FConst.MSPOWERPOINT|P2FConst.MSWORD|P2FConst.ACROBAT);
26                 DefBPOpt.put("KillAllAutomationProcesses",2 );
27                 DefBPOpt.invoke("ApplyChanges");
28                 // Convert document
29                 p2f.invoke("ConvertFile", new String(args));
30                 System.out.println("Conversion completed successfully");
31            }catch (Exception e){
32                    System.out.println("An error occurred at conversion: "+e.toString());
33            }finally{
34                 try {
35                  Ole32.CoUninitialize();
36                 }catch (Exception e){
37                     
38                 }
39            }
40        }else{
41               System.out.println("Please provide a document file name as a parameter");
42               System.out.println("Press Enter to exit...");
43               System.in.read();
44       
45        }
46 }
47 
48  

定义常量

(可能定义的常量与测试代码中的有出入不过不影响使用,这些常量可以查询API帮助文档)

  1 public class P2FConst {
  2  // APPLICATIONTYPE enumeration constants
  3  public static final int MSEXCEL = 0x00000001;
  4  public static final int MSWORD = 0x00000002;
  5  public static final int MSPOWERPOINT = 0x00000004;
  6  public static final int ACROBAT = 0x00000008;
  7 
  8  // IMAGEFORMAT enumeration constants
  9  public static final int JPEG = 1;
 10  public static final int PNG = 2;
 11 
 12  // IMGBEHAVIOR enumeration constants
 13  public static final int STRETCH = 1;
 14  public static final int TILE = 2;
 15 
 16  // INTERFACE_OPTION enumeration constants
 17  public static final int INTLOGO = 0x00000001;
 18  public static final int INTDRAG = 0x00000002;
 19  public static final int INTSELTEXT = 0x00000004;
 20  public static final int INTZOOMSLIDER = 0x00000008;
 21  public static final int INTZOOMBOX = 0x00000010;
 22  public static final int INTFITWIDTH = 0x00000020;
 23  public static final int INTFITPAGE = 0x00000040;
 24  public static final int INTPREVPAGE = 0x00000080;
 25  public static final int INTGOTOPAGE = 0x00000100;
 26  public static final int INTNEXTPAGE = 0x00000200;
 27  public static final int INTSEARCHBOX = 0x00000400;
 28  public static final int INTSEARCHBUT = 0x00000800;
 29  public static final int INTROTATE = 0x00001000;
 30  public static final int INTPRINT = 0x00002000;
 31  public static final int INTNEWWIND = 0x00004000;
 32  public static final int INTHELP = 0x00008000;
 33  public static final int INTBACKBUTTON = 0x00030000;
 34  public static final int INTBACKBUTTONAUTO = 0x00010000;
 35  public static final int INTFORWARDBUTTON = 0x000C0000;
 36  public static final int INTFORWARDBUTTONAUTO = 0x00040000;
 37  public static final int INTFULLSCREEN = 0x00300000;
 38  public static final int INTFULLSCREENAUTO = 0x00100000;
 39 
 40 
 41  // METADATAPORMAT enumeration constants
 42  public static final int XML = 1;
 43  public static final int TEXT = 2;
 44 
 45  // OUTPUTFORMAT enumeration constants
 46  public static final int SINGLEFILE = 1;
 47  public static final int SINGLEFILEPERPAGE = 2;
 48  public static final int EXTVIEWER = 4;
 49 
 50  // PAPER_ORIENTATION enumeration constants
 51  public static final int ORIENT_PORTRAIT = 1;
 52  public static final int ORIENT_LANDSCAPE = 2;
 53 
 54  // PROTECTION_OPTION enumeration constants
 55  public static final int PROTDISPRINT = 0x00000001;
 56  public static final int PROTDISTEXTCOPY = 0x00000002;
 57  public static final int PROTENAPI = 0x00000004;
 58 
 59  // ThreeStateFlag enumeration constants
 60  public static final int TSF_NO = 0;
 61  public static final int TSF_YES = 1;
 62  public static final int TSF_AUTO = 2;
 63 
 64  // TOOLBARIMAGE enumeration constants
 65  public static final int IMGLOGO = 1;
 66  public static final int IMGDRAG = 2;
 67  public static final int IMGSELTEXT = 3;
 68  public static final int IMGZOOMRULER = 4;
 69  public static final int IMGZOOMFOCUSNADLE = 5;
 70  public static final int IMGZOOMNADLE = 6;
 71  public static final int IMGFITWIDTH = 7;
 72  public static final int IMGFITPAGE = 8;
 73  public static final int IMGPREVPAGE = 9;
 74  public static final int IMGNEXTPAGE = 10;
 75  public static final int IMGSEARCHBUT = 11;
 76  public static final int IMGROTATE = 12;
 77  public static final int IMGPRINT = 13;
 78  public static final int IMGNEWWIND = 14;
 79  public static final int IMGHELP = 15;
 80  public static final int IMGMORE = 16;
 81  public static final int IMGTOOLBARBGR = 17;
 82  public static final int IMGBACK = 18;
 83  public static final int IMGFORWARD = 19;
 84  public static final int IMGFULLSCREEN = 20;
 85  public static final int IMGEXITFULLSCREEN = 21;
 86 
 87  // TEMPLATETYPE enumeration constants
 88  public static final int TEMPLATE_CUSTOM = 1;
 89  public static final int TEMPLATE_ACTIONSCRIPT2 = 2;
 90  public static final int TEMPLATE_ACTIONSCRIPT3 = 3;
 91 
 92  // WATERMARKANCHOR enumeration constants
 93  public static final int CENTER = 0;
 94  public static final int LEFTCENTER = 1;
 95  public static final int RIGHTCENTER = 2;
 96  public static final int TOPCENTER = 16;
 97  public static final int BOTTOMCENTER = 32;
 98  public static final int LEFTTOP = 17;
 99  public static final int RIGHTTOP = 18;
100  public static final int LEFTBOTTOM = 33;
101  public static final int RIGHTBOTTOM = 34;
102 }

5、定制自己想要的转换功能

这一点可以查看安装后的帮助文档,虽然是英文的,但是仔细看一看就能弄明白,API写的非常清楚

原文地址:https://www.cnblogs.com/sparkbj/p/5802698.html