Skip to content

授权并初始化 SDK

在调用任何 SDK 的接口之前,您的应用程序必须使用有效的许可证授权码初始化福昕 PDF SDK 库。试用许可证文件位于开发包的 lib 目录下,包含 **_sn.txt**_key.txt 两个文件。

初始化步骤:

  1. 获取授权码:

    • sn 参数的值取自 **_sn.txt 文件中 "SN=" 后面的字符串。
    • key 参数的值取自 **_key.txt 文件中 "Sign=" 后面的字符串。
  2. 调用初始化函数:

    • 使用获取到的 snkey 值,调用 Library.initialize(sn, key) 函数进行 SDK 初始化。

在初始化库之前,您需要首先根据系统加载正确的库。以下为示例代码,将自动加载正确的库,并初始化库:

java
// Load the library.
// You can also use System.load("filename") instead. The filename argument must be an absolute path name.
static {
        String os = System.getProperty("os.name").toLowerCase();
        String lib = "fsdk\_java\_";
        if (os.startsWith("win")) {
            lib += "win";
        } else if (os.startsWith("mac")) {
            lib += "mac";
        } else {
            lib += "linux";
        }
          if (System.getProperty("sun.arch.data.model").equals("64")) {
            if(System.getProperty("os.arch").equals("aarch64")){
              if(os.startsWith("mac")){
                 lib += "arm";
               }
               else{
                 lib += "armv8";
               }
             }
             else{
                lib += "64";
             }
          } else {
             if(System.getProperty("os.arch").equals("arm")){
                lib += "armv7";
             }
             else{
                lib += "32";
             }
        }
      System.loadLibrary(lib);
  }

// Initialize the library.
// The value of "sn" can be got from "gsdk\_sn.txt" (the string after "SN=").
// The value of "key" can be got from "gsdk\_key.txt" (the string after "Sign=").
String sn = " ";
String key = " ";
int error\_code = Library.initialize(sn, key);
if (error\_code != *e\_ErrSuccess*) 
	return;        
...