如何使用 pdfBox 合并两个 pdf
您好,我正在尝试通过组合本地计算机中的两个和 s3 中的另一个来生成 pdf,我不知道如何执行此操作 这是我尝试做的 -
S3Object object = amazonS3.getObject(new GetObjectRequest(bucket, "name.pdf"));
InputStream ins = object.getObjectContent();
try {
PDDocument doc = PDDocument.load(ins);
File file1 = new File(
"C:\\Users\\admin\\example.pdf");
PDFMergerUtility obj = new PDFMergerUtility();
obj.setDestinationFileName(
"C:\\Users\\admin\\newMerged.pdf");
obj.addSource(file1);
obj.addSource(String.valueOf(doc));
obj.mergeDocuments();
System.out.println("PDF Documents merged to a single file");
}
catch (Exception e){
e.printStackTrace();
}
错误 - org.apache.pdfbox.pdmodel.PDDocument@4d33940d (系统找不到指定的文件)
我知道这不可能是这样,我想知道如何做这件事。
Hi there I am trying to generate pdf by combining two one from my local machine and another one from s3 I am not sure how to do this
here is what I tried doing -
S3Object object = amazonS3.getObject(new GetObjectRequest(bucket, "name.pdf"));
InputStream ins = object.getObjectContent();
try {
PDDocument doc = PDDocument.load(ins);
File file1 = new File(
"C:\\Users\\admin\\example.pdf");
PDFMergerUtility obj = new PDFMergerUtility();
obj.setDestinationFileName(
"C:\\Users\\admin\\newMerged.pdf");
obj.addSource(file1);
obj.addSource(String.valueOf(doc));
obj.mergeDocuments();
System.out.println("PDF Documents merged to a single file");
}
catch (Exception e){
e.printStackTrace();
}
Error - org.apache.pdfbox.pdmodel.PDDocument@4d33940d (The system cannot find the file specified)
I know this could not be the way, I wanna know how to do this thing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑使用文件所在位置的绝对路径名。
Consider to use absolute pathname to where the file exists.