【aspose】aspose-cells-21.1 For Java 除水印

aspose-cells-21.1

俗话说得好,授人以鱼不如授人以渔,与其直接把包给到大家,不如直接教大家如何解除,当然,操作不好的,想直接要包的,可以到我的资源里面去下载
aspose-cells for java资源
下面介绍一下操作步骤

  • 1.首先得有个aspose的包可以到官网上下载
  • 2.通过包中License类下的setLicense()方法,可以看到内部的结构
  • 3.setLicense是个重载的方法有下面的实现

方法一

    public void setLicense(InputStream stream) {
        this.b = null;
        Document var2 = null;
        if (stream != null) {
            try {
                DocumentBuilder var3 = zae.b();
                var2 = var3.parse(stream);
            } catch (Exception var4) {
                throw new CellsException(9, zj.a(new byte[]{-62, 126, -80, 53, 67, 47, 88, -2, -12, -39, 65, 115, -15, 112, 117, 67, -20, 21, 121, 125, -29, -10, 45, 17, 109, -9, -87, -15, -29, -10, 72, -119, 0, 48, -122, 19, -11, -83, -11}) + var4.getMessage());
            }
        }

        this.a(var2);
        if (this.b != null) {
            throw new CellsException(9, this.b);
        }
    }

方法二

    public void setLicense(String licenseFileName) {
        this.b = null;
        File var2 = this.a(licenseFileName);
        if (var2 == null) {
            throw new CellsException(9, zj.a(new byte[]{51, -23, 63, -83, 59, -94, 6, -45, 84, 21, -56, -88, -125, -105, -29, -9, -84, -25, -81, -11, 69, -21, 50, -47, 53, -25, 21, -43, 69, -32, 30, 71, 9, 94, -11, -39, -11}) + licenseFileName);
        } else {
            if (zm.a()) {
                zm.a(zj.a(new byte[]{-21, 9, 80, -7, 3, -120, -16, 95, 53, 0, -58, -43, 69, -21, 50, -47, 53, -25, 21, -43, 69, -32, 30, 71, 9, 94, -11, -39, -11}) + var2.getAbsolutePath());
            }

            Document var3 = null;

            try {
                DocumentBuilder var4 = zae.b();
                var3 = var4.parse(var2);
            } catch (CellsException var5) {
                throw var5;
            } catch (Exception var6) {
                throw new CellsException(9, zj.a(new byte[]{49, 32, 12, 85, 49, 17, 58, 99, 126, 116, -104, 64, -81, -29, -9, -84, -100, -7, -4, -2, -12, -103, -58, 52, -20, -27, -39, -14, 68, 60, -59, -15, 77, -3, -39, -16, -113, 25, 74, -33, 53, -2, -11, -11}) + var6.getMessage());
            }

            this.a(var3);
            if (this.b != null) {
                throw new CellsException(9, this.b);
            }
        }
    }

方法三

    public void setLicense(Reader reader) {
        this.b = null;
        Document var2 = null;
        if (reader != null) {
            try {
                DocumentBuilder var3 = zae.b();
                var2 = var3.parse(new InputSource(reader));
            } catch (Exception var4) {
                throw new CellsException(9, zj.a(new byte[]{-92, -23, -22, -115, -124, -89, 36, -123, -40, 67, 94, -73, 53, -66, -40, -44, 116, -44, -107, -40, 115, -115, -42, -41, -16, 117, 3, -52, -45, -11, 98, -12, -16, 117, 26, -86, -32, 58, -96, -119, -11, -29, -11, -11}) + var4.getMessage());
            }
        }

        this.a(var2);
        if (this.b != null) {
            throw new CellsException(9, this.b);
        }
    }

我们可以看到,无论是那个方法,前面都经过了很多的校验,而我们就是要跳过这些校验,最终都会调用一个统一的方法

this.a(var);

点到这个方法里面,内容是非常的多,但是前面我们都不关心,就注意最后一段代码

	...
	a = this;
    zbjb.a();
    return;
    ...

帮我们调用了这个方法zbjb.a();
于是,我们就尝试,让我们的setLicense方法直接省去这些步骤,直接调用最后的方法。

步骤

引入反编译的maven依赖

        <dependency>
            <groupId>org.javassistgroupId>
            <artifactId>javassistartifactId>
            <version>3.27.0-GAversion>
        dependency>
	private static final String Desktop="E:\\upload\\";
    private static void crackAsposePdfJar(String jarName) {
        try {
            // 这个是得到反编译的池
            ClassPool pool = ClassPool.getDefault();

            // 取得需要反编译的jar文件,设定路径
            pool.insertClassPath(jarName);

            CtClass ctClass = pool.get("com.aspose.cells.License");

            CtMethod method_isLicenseSet = ctClass.getDeclaredMethod("isLicenseSet");
            method_isLicenseSet.setBody("return true;");
            CtMethod method_setLicense = ctClass.getDeclaredMethod("setLicense");
            method_setLicense.setBody("{    a = new com.aspose.cells.License();\n"
                    +"    com.aspose.cells.zbjb.a();}");
            CtMethod methodL = ctClass.getDeclaredMethod("l");
            methodL.setBody("return new java.util.Date(Long.MAX_VALUE);");
            CtMethod method_k = ctClass.getDeclaredMethod("k");
            method_k.setBody("return new java.util.Date(Long.MAX_VALUE);");

            ctClass.writeFile(Desktop);
        } catch (NotFoundException e) {
            e.printStackTrace();
        } catch (CannotCompileException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

执行上面代码之后,会在Desktop指定的目录上面生成一个class文件
【aspose】aspose-cells-21.1 For Java 除水印_第1张图片

我们将我们的jar给解压,进入到com/aspose/cells文件夹内将License.class替换进去
【aspose】aspose-cells-21.1 For Java 除水印_第2张图片
再将META-INF下的两个加密文件给删除掉
【aspose】aspose-cells-21.1 For Java 除水印_第3张图片

然后将解压后的文件重新压缩成zip,再更改后缀为.jar,然后引入我们的项目当中
注意要配合License.xml一起使用哦

<License>
    <Data>
        <Products>
            <Product>Aspose.Total for JavaProduct>
            <Product>Aspose.Words for JavaProduct>
        Products>
        <EditionType>EnterpriseEditionType>
        <SubscriptionExpiry>20991231SubscriptionExpiry>
        <LicenseExpiry>20991231LicenseExpiry>
        <SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7SerialNumber>
    Data>
    <Signature>
        sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=
    Signature>
License>

试试最终效果
在这里插入图片描述
可以看到,转出来的pdf就没有水印啦```

你可能感兴趣的:(工具,java,maven,开发语言)