Java 添加、下载、读取PDF附件信息(基于Spire.Cloud.SDK for Java)
2020-12-22 17:30
标签:rip image mamicode public pen system ota img 方式 完成配置后,点击“Import Changes” 即可导入所有需要的jar文件。如果使用的是Eclipse,可参考这里的导入方法。 二、登录冰蓝云账号,创建文件夹,上传文档。 附件添加结果: 【示例2】下载附件文档(以上文中生成的PDF文档为例,读取添加的Word附件) 读取结果如下,可在路径中查看下载的附件文档: 附件信息读取结果: (完) Java 添加、下载、读取PDF附件信息(基于Spire.Cloud.SDK for Java) 标签:rip image mamicode public pen system ota img 方式 原文地址:https://blog.51cto.com/eiceblue/2507642
一、导入jar文件。(有2种方式)
(推荐)方式1. 创建Maven项目程序,通过maven仓库下载导入。以IDEA为例,新建Maven项目,在pom.xml文件中配置maven仓库路径,并指定spire.cloud.sdk的依赖,如下:
导入结果:
方式2:手动下载jar包,然后解压文件,手动导入jar,同时还需另行手动导入其他几个jar文件。
三、创建应用程序,获取App ID及App Key。
四、Java代码示例
【示例1】添加附件import spire.cloud.pdf.sdk.ApiException;
import spire.cloud.pdf.sdk.Configuration;
import spire.cloud.pdf.sdk.api.PdfAttachmentsApi;
import java.io.File;
public class AddAttachment {
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl= "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static PdfAttachmentsApi pdfAttachmentsApi = new PdfAttachmentsApi(configuration);
public static void main(String[] args) throws ApiException {
String name = "sample.pdf";//用于测试的PDF源文档
String outPath = "output/AddAttachment.pdf";//结果文档路径(结果文档保存在云端output文件夹下)
File file = new File("test.docx");//加载附件文档
String attachmentFileName = "AddAttachment.docx";//设置附件文档名称
String attachmentDescription = "A Nice File";//附件描述
String folder = "input";//源文档所在文件夹
String storage = null;//冰蓝云提供的2G免费云存储空间
String password = null;//源文档密码
//调用方法添加附件
pdfAttachmentsApi.addAttachment(name, outPath, file, attachmentFileName, attachmentDescription, folder, storage, password);
}
}
import spire.cloud.pdf.sdk.ApiException;
import spire.cloud.pdf.sdk.Configuration;
import spire.cloud.pdf.sdk.api.PdfAttachmentsApi;
import java.io.File;
public class DownloadAttachment {
//配置账号信息
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl= "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static PdfAttachmentsApi pdfAttachmentsApi = new PdfAttachmentsApi(configuration);
public static void main(String[] args) throws ApiException {
String name = "AddAttachment.pdf";//包含附件的PDF源文档
Integer orderNumber = 1;
String folder = "output";//源文档所在云端文件夹
String storage = null;//冰蓝云提供的2G免费云存储空间
String password = null;//源文档密码
//调用方法下载PDF文档中的附件文档
File response = pdfAttachmentsApi.downloadAttachment(name, orderNumber, folder, storage, password);
System.out.println(response);
}
}
【示例3】获取附件信息import spire.cloud.pdf.sdk.ApiException;
import spire.cloud.pdf.sdk.Configuration;
import spire.cloud.pdf.sdk.api.PdfAttachmentsApi;
import spire.cloud.pdf.sdk.model.Attachments;
public class GetAttachmentInfo {
//配置账号信息
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl= "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static PdfAttachmentsApi pdfAttachmentsApi = new PdfAttachmentsApi(configuration);
public static void main(String[] args) throws ApiException {
String name = "AddAttachment.pdf";//包含附件的PDF源文档
String folder = "output";//源文档所在文件夹
String storage = null;//冰蓝云提供的2G云存储空间
String password = null;//源文档密码
//调用方法获取附件信息
Attachments response = pdfAttachmentsApi.getAttachmentsInfo(name, folder, storage, password);
System.out.println(response);
}
}
文章标题:Java 添加、下载、读取PDF附件信息(基于Spire.Cloud.SDK for Java)
文章链接:http://soscw.com/index.php/essay/37623.html