繁体   English   中英

使用 PDFBox 保存方法将文件上传到 SFTP 服务器而不将文件存储到本地系统?

[英]Upload a file to an SFTP server using PDFBox save method without storing the file to the local system?

我正在尝试将已编辑的 PDF 保存到其位置,而无需将其下载/存储在本地计算机上。 我正在使用 JSch SFTP 方法从 SFTP 服务器获取输入 PDF 文件,使用

x = new BufferedInputStream(channelSftp.get("example.pdf"));
PDDocument document = PDDocument.load(x);

在使用 PDFbox 进行一些编辑后,我尝试使用以下方法保存它:

documents.save(new File("ftp/path/location"));

我不能,因为我知道它只适用于您的本地目录。 我也可以看到document.save接受 OutputStream` 参数,但我不知道如何在这里使用它。

使用 stream 阅读器进行输入没有任何问题。 我所需要的只是将已编辑的 PDF 保存回其位置(可能替换),而无需在我的本地系统上下载它。

使用返回OutputStreamChannelSftp.put重载

try (OutputStream out = channelSftp.put("example.pdf")) {
    documents.save(out);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM