本分步教程详细介绍了如何在云中使用 Java REST API**将 PDF 转换为 XLS。为了将 PDF 导出为 XLS 格式,我们使用 Aspose.PDF for Java Cloud SDK。如果您需要在 Java 低代码 API 中将 PDF 转换为 XLS,则可以借助以下步骤和代码片段来执行相同操作。
先决条件
- 创建帐户并获取 API 凭据
- 下载 Aspose.PDF Cloud SDK for Java
- 使用上述SDK设置Java项目
在 Java REST API 中将 PDF 转换为 XLS 的步骤
- 设置 API 的客户端 ID 和客户端密钥
- 使用客户端凭据创建 pdfApi 类的对象
- 指定输入和输出文件
- 读取输入 PDF 文件并上传到云存储
- 创建具有输入和输出文件格式的 pdfApi 对象
- 调用 putPdfInStorageToXls 方法使用 REST API 将 PDF 转换为 XLS
- 将输出 XLS 文件保存在本地磁盘上
Java 低代码 API 中的 PDF 到 XLS 转换代码
String ClientID = Client.getID(); //replace Client.getID() with your own client ID here | |
String ClientSecret = Client.getSecret(); //replace3 Client.getSecret() with your own client secret here | |
try { | |
ApiClient apiClient = new ApiClient(); | |
apiClient.setAppKey(ClientSecret); | |
apiClient.setAppSid(ClientID); | |
PdfApi pdfApi = new PdfApi(apiClient); | |
String inputFile = "PDFtoXLS.pdf"; | |
String outputFile = "PDFtoXLS.xls"; | |
String folder = "Temp"; | |
String format = "xls"; | |
// Upload file to cloud storage | |
File file = new File("C:/Temp/" + inputFile); | |
pdfApi.uploadFile(folder + "/" + inputFile, file, null); | |
AsposeResponse response = pdfApi.putPdfInStorageToXls(inputFile, folder + '/' + outputFile, null, false, null, | |
null , folder, null); | |
// Download output file from Cloud Storage | |
File downloadResponse = pdfApi.downloadFile(folder + "/" + outputFile, null, null); | |
File dest = new File("C:/Temp/" + outputFile); | |
Files.copy(downloadResponse.toPath(), dest.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} |
上面显示的代码可帮助您使用 Java REST API 将 PDF 转换为 XLS。您只需借助适用于 Java 的 Aspose.PDF REST API SDK 上传 PDF 文件,并使用 Aspose 在线转换 API 下载输出 XLS 文件以将其保存在本地。
上述 PDF 到 XLS 转换可用于任何平台上的任何无代码或低代码应用程序。
另一个相关功能可以在以下网址找到:如何使用 Java REST API 将 PDF 转换为 DOCX