简体   繁体   English

用Java将PDF一起添加

[英]Add PDFs together in Java

I am using an api which allows me to generate reports in PDF format. 我正在使用一个API该API可让我生成PDF格式的报告。 From the api I get the PDF in a byte[] . 从api中,我得到了一个byte[]的PDF。 I send the reports to users via e-mail. 我通过电子邮件将报告发送给用户。 Sometimes users will get one report, but in many cases they'll get many reports. 有时用户会收到一份报告,但是在许多情况下,他们会收到许多报告。

I'm wondering whether it's possible to take the bytes for more than one pdf and combine them in some way with another (or many) report(s) so I only send the user one pdf rather than 3 or 4. Thanks for the help! 我想知道是否可以将一个以上的pdf字节并以某种方式将它们与另一个(或多个)报告合并,因此我只向用户发送一个pdf,而不是3或4。感谢您的帮助!

No, concatenating the bytestream will not work (read the standard ;-). 不,串联字节流将不起作用(请阅读标准;-)。 You need to use something like Apache PDFBox to create a new PDF. 您需要使用Apache PDFBox之类的东西来创建新的PDF。

I highly recommend IText for generating and manipulating pdfs in Java. 我强烈建议使用IText在Java中生成和处理pdf。 But even if you want to use your orginal package to generate the pdf, you can still use IText to merge all your pdfs together into 1 big pdf, as explained here: iText Merge PDF with cropbox 但是,即使您想使用原始包来生成pdf,也可以使用IText将所有pdf合并为1个大pdf,如此处所述: iText与cropbox合并PDF

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

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