同一个word文档,一个部门下载后不可编辑,一个可以修改和上传

要求有点另类,
但文档涉及部门权限和机密,也就可以理解了
非常简单

import com.spire.doc.*;


public class Test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		//加载测试文档
        String input = "E://a.docx";
        String output= "E://b.docx";
        Document doc = new Document(input);
        
//        doc.encrypt("123");//设置文档打开密码
        doc.protect(ProtectionType.Allow_Only_Reading,"123");//设置文档只读
        //doc.protect(ProtectionType.Allow_Only_Comments,"123");
        //doc.protect(ProtectionType.Allow_Only_Revisions,"123");

        //保存加密后的文档
        doc.saveToFile(output);
        doc.dispose();
	}

}

后来变卦了,机密要求有点高 要pdf的

package com.sinosoft.common.wordEncrypt;

import com.spire.doc.*;


public class Test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		//加载测试文档
        String input = "E://a.doc";

        String targetPath = "E://bb.pdf";
		Document document = new com.spire.doc.Document();
		System.out.println("================== 读取文件开始" + targetPath);
		//加载word文档
		document.loadFromFile(input);
		//保存结果文件
		document.saveToFile(targetPath, com.spire.doc.FileFormat.PDF);
	}

}

add:

小常识: pdf还是可以编辑的, 想要pdf不可编辑, 需要加数字签名

https://www.e-iceblue.cn/pdf_java_security/add-digital-signature-to-pdf-in-java.html

spire处理pdf后会在第一页加信息 ,如何去掉:

https://blog.csdn.net/qq_21416547/article/details/108250016

简而言之:

a.getPages().add(); 
...
a.getPages().remove(a.getPages().get(a.getPages().getCount()-1));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值