IDEA中怎么设置项目更改后的分析延迟时间,IDEA是java编程语言的集成开发环境,使用该软件编写代码时,可以设置项目更改后的分析延迟时间,这样就可确保项目范围分析的正确性,具体的操作步骤如下。......
2023-07-04 626 JAVA
Spire.Cloud.SDK for Java提供了PdfAttachmentsApi接口添加附件addAttachment()、下载附件downloadAttachment()、获取附件信息getAttachmentsInfo(),本文将通过Java代码示例介绍具体实现方法。详细内容参考以下步骤。
(推荐)方式1. 创建Maven项目程序,通过maven仓库下载导入。以IDEA为例,新建Maven项目,在pom.xml文件中配置maven仓库路径,并指定spire.cloud.sdk的依赖,如下:
repositories>
repository>
id>com.e-iceblue/id>
name>cloud/name>
url>http://repo.e-iceblue.cn/repository/maven-public//url>
/repository>
/repositories>
dependencies>
dependency>
groupId> cloud /groupId>
artifactId>spire.cloud.sdk/artifactId>
version>3.5.0/version>
/dependency>
dependency>
groupId> com.google.code.gson/groupId>
artifactId>gson/artifactId>
version>2.8.1/version>
/dependency>
dependency>
groupId> com.squareup.okhttp/groupId>
artifactId>logging-interceptor/artifactId>
version>2.7.5/version>
/dependency>
dependency>
groupId> com.squareup.okhttp /groupId>
artifactId>okhttp/artifactId>
version>2.7.5/version>
/dependency>
dependency>
groupId> com.squareup.okio /groupId>
artifactId>okio/artifactId>
version>1.6.0/version>
/dependency>
dependency>
groupId> io.gsonfire/groupId>
artifactId>gson-fire/artifactId>
version>1.8.0/version>
/dependency>
dependency>
groupId>io.swagger/groupId>
artifactId>swagger-annotations/artifactId>
version>1.5.18/version>
/dependency>
dependency>
groupId> org.threeten /groupId>
artifactId>threetenbp/artifactId>
version>1.3.5/version>
/dependency>
/dependencies>
完成配置后,点击“Import Changes” 即可导入所有需要的jar文件。
如果使用的是Eclipse,可参考"E-iceblue官网-在线编辑-帮助文档-WebAPI-Java-通过 Maven 仓库安装 Spire.Cloud Web API "的导入方法。
方式2:手动下载jar包,然后解压文件,手动导入jar,同时还需另行手动导入其他几个jar文件(相对比较麻烦一点)。
最终导入结果如下:
如下图:
如下图:
【示例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);
}
}
附件添加结果:
【示例2】下载附件文档(以上文中生成的PDF文档为例,读取添加的Word附件)
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);
}
}
信息读取结果:
以上方法由办公区教程网编辑摘抄自百度经验可供大家参考!
相关文章
IDEA中怎么设置项目更改后的分析延迟时间,IDEA是java编程语言的集成开发环境,使用该软件编写代码时,可以设置项目更改后的分析延迟时间,这样就可确保项目范围分析的正确性,具体的操作步骤如下。......
2023-07-04 626 JAVA
IDEA中怎么设置调试器最近表达式的最大数量,IDEA是java编程语言的集成开发环境,使用该软件编写代码时,可以设置调试器最近表达式的最大数量,从而有效避免调试器中表达式存储过多。......
2023-07-04 442 JAVA