Protection 接口描述

 

对Word文档进行加密。

接口方法1: protectDocumentInRequest()以指定保护类型保护文档

HTTP请求方法:PUT

请求URL:https://api.e-iceblue.cn/v1/word/document/protectionInRequest

请求参数:

参数 是否必选 类型 可选值范围 说明
file file 原文档
docPassword string 原文档打开密码,没有则为null
protectionType string AllowOnlyReading, AllowOnlyComments, AllowOnlyFormFields, AllowOnlyRevisions, NoProtection 保护类型
protectionPwd string 用于加密的密码

代码示例:

  • .NET
  • Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
using System.IO;

namespace ProtectDocumentInRequest
{
    class Program
    {
        static string appId = "your id";
        static string appKey = "your key";
        static string baseUrl = "https://api.e-iceblue.cn";
        static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
        static ProtectionApi protectionApi = new ProtectionApi(wordConfiguration);
        static void Main(string[] args)
        {
            string inputFilePath = "D:/inputFile/Template.docx";
            Stream inputFile = new FileStream(inputFilePath, FileMode.Open);
            string protectionType = "AllowOnlyReading"; //AllowOnlyComments,AllowOnlyFormFields,AllowOnlyRevisions,NoProtection
            string docPassword = null;
            string protectiongPwd = "123456";
            var response = protectionApi.ProtectDocumentInRequest(inputFile, protectionType, docPassword, protectiongPwd);
        }
    }
}

	
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.ProtectionApi;
import java.io.File;

public class ProtectDocumentInRequest {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
    static ProtectionApi protectionApi = new ProtectionApi(wordConfiguration);

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

        String inputFilePath = "D:/inputFile/Template.docx";
        File inputFile= new File(inputFilePath);
        String protectionType = "AllowOnlyReading";
        String docPassword = null;
        String protectiongPwd = "123456";
        File response = protectionApi.protectDocumentInRequest(inputFile, protectionType, docPassword, protectiongPwd);
    }
}

接口方法2:protectDocument()以指定保护类型保护文档

HTTP请求方法:PUT

请求URL:https://api.e-iceblue.cn/v1/word/document/{name}/protection

请求参数:

参数 是否必选 类型 可选值范围 说明
name string 原文档名称
folder string 存放原文档的文件夹,没有则为null
storage string 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null
docPassword string 原文档打开密码,没有则为null
protectionType string AllowOnlyReading, AllowOnlyComments, AllowOnlyFormFields, AllowOnlyRevisions, NoProtection 保护类型
protectionPwd string 用于加密的密码

代码示例:

  • .NET
  • Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;

namespace ProtectDocument
{
    class Program
    {
        static string appId = "your id";
        static string appKey = "your key";
        static string baseUrl = "https://api.e-iceblue.cn";
        static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
        static ProtectionApi protectionApi = new ProtectionApi(wordConfiguration);
        static void Main(string[] args)
        {
            var fileName = "Template.docx";
            string name = fileName;
            string protectionType = "AllowOnlyReading"; //AllowOnlyComments,AllowOnlyFormFields,AllowOnlyRevisions,NoProtection
            string folder = "input";
            string storage = null;
            string docPassword = null;
            string protectiongPwd = "123456";
            string destFilePath = "output/Template_output.docx";
            protectionApi.ProtectDocument(name, protectionType, destFilePath, folder, storage, docPassword, protectiongPwd);
        }
    }
}
	
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.ProtectionApi;

public class ProtectDocument {

    static String appId = "your id";
    static String appKey = "your key";
    static String baseUrl = "https://api.e-iceblue.cn";
    static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
    static ProtectionApi protectionApi = new ProtectionApi(wordConfiguration);

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

        String fileName = "Template.docx";
        String name = fileName;
        String protectionType = "AllowOnlyReading"; 
        String folder = "input";
        String storage = null;
        String docPassword = null;
        String protectiongPwd = "123456";
        String destFilePath = "output/Template_output.docx" ;
        protectionApi.protectDocument(name, protectionType, destFilePath, folder, storage, docPassword, protectiongPwd);
    }
}