License 偶尔错误

我公司买了License 后 word 转 pdf 时 偶尔报license 错误(大概10次中就有一次如下错误),使用代码为aspose-words-20.5-jdk17.jar,报错代码见附件图片。
报错如下:
java.lang.IllegalStateException: Invalid license signature. Please make sure the license file was not modified.
license报错.png (201.6 KB)

@kongc,

请“通过私人消息”发布您的许可证文件。 为了发送带有附件的私人消息,请单击我的名字并找到“消息”按钮。

Setting or Applying Aspose.Words licence

然后,我们将最终对您的许可证文件进行调查,并为您提供更多信息。

附言 请不要在论坛主题中公开共享您的许可证文件。

许可证已通过Message给你,麻烦查收!

@kongc,

感谢您通过私人消息共享您的许可证文件。 但是,您共享的许可证文件可以很好地工作,例如,我们最终使用最新版本(20.5)的Aspose.Words for Java测试它。 请确保您为SetLicense方法引用了正确的许可证文件。

肯定是正确的许可证啊,没有许可证会有水印提示的,许可证可以正常的使用,我现在转换的文档都是正常的没有水印提示,只是如果调用太频繁的时候,偶尔会有一次这样的错误。

@kongc,

我们已使用您屏幕截图中的以下Java代码对此进行了测试:

InputStream in = new FileInputStream("E:\\Temp\\input.docx");
OutputStream out = new FileOutputStream("E:\\Temp\\awjava-20.5.pdf");

wordToPdf(in, out, false);

public static boolean wordToPdf(InputStream inputStream, OutputStream outputStream, boolean readonly) {
    boolean flag = true;
    try {
        License license = new License();
        license.setLicense(Program.class.getResourceAsStream("Aspose.Words.lic"));

        LoadOptions loadOptions = new LoadOptions();
        loadOptions.getLanguagePreferences().setDefaultEditingLanguage(EditingLanguage.CHINESE_PRC);
        Document doc = null;
        doc = new Document(inputStream, loadOptions);
        if (readonly) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            doc.save(baos, SaveFormat.PDF);

            flag = true;
        } else {
            doc.save(outputStream, SaveFormat.PDF);
        }
    } catch (Exception e) {
        flag = false;
    }

    return flag;
} 

您在一个特定的文档中看到此问题吗? 您能否分享您的Word文档样本?

您使用“ protectPDF”方法使用哪种API保护Aspose.Words最终生成的PDF?

如果您请创建一个独立的简单Java应用程序(无编译错误的源代码),这将非常有用,它可以帮助我们重现当前的问题并将其附加在此处进行测试。 请不要在其中包含Aspose.Words JAR文件,以减小文件大小。 然后,我们将开始进一步调查您的情况并为您提供更多信息。 谢谢您的合作。

放到calss的static块中加载 license 应该可以了
static {
License license = new License();
InputStream licenseInput = null;
licenseInput = License.class.getResourceAsStream(“Aspose.Words.lic”);
try {
license.setLicense(licenseInput);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

@kongc,

恐怕,当我们最终执行以下代码时,我们仍然看不到您的许可证文件有任何问题。 (另请参见输出PDF :awjava-20.5.pdf (969.8 KB)):

import com.aspose.words.*;
import java.io.*;

public class Program {

    public static void main(String[] args) throws Exception {

        InputStream in = new FileInputStream("E:\\Temp\\213535 - 7\\input.docx");
        OutputStream out = new FileOutputStream("E:\\Temp\\213535 - 7\\awjava-20.5.pdf");

        wordToPdf(in, out, false);
    }

    static {
        License license = new License();
        InputStream licenseInput = null;
        licenseInput = Program.class.getResourceAsStream("Aspose.Words.lic");
        try {
            license.setLicense(licenseInput);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static boolean wordToPdf(InputStream inputStream, OutputStream outputStream, boolean readOnly) {
        boolean flag = true;
        InputStream licenseInput = null;
        try {
            // License license = new License();
            // licenseInput = License.class.getResourceAsStream("Aspose.Words.lic");
            // license.setLicense(licenseInput);
            // 获取文档
            LoadOptions opts = new LoadOptions();
            opts.getLanguagePreferences().setDefaultEditingLanguage(EditingLanguage.CHINESE_PRC);//设置默认为中文
            Document doc = null;
            doc = new Document(inputStream,opts);
            doc.getRange().replace("", " ", new FindReplaceOptions());//将(U + E5E5 PUA字符)乱码(方框) 替换为空格
            if (readOnly) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                doc.save(baos, SaveFormat.PDF);
                // 设置PDF只读
                // resultCode = protectPdf(baos.toByteArray(), outputStream);
            } else {
                doc.save(outputStream, SaveFormat.PDF);
            }
        } catch (Exception e) {
            e.printStackTrace();
            flag = false;
        }

        return flag;
    }
}