使用pdfbox复制一页n次
我制作了一个单页pdf模板文件。然后,我使用 pdfbox 创建一个包含“n”页数的 pdf(取决于报告大小)。我希望所有“n”页都是模板 pdf 文件中的页面。让所有“n”页成为该页的副本的最佳方法是什么?这是我当前的代码:
PDDocument document = null;
try {
document = PDDocument.load(WestfieldClientReportApp.class.getResource("/com/dramble/resources/template.pdf"));
} catch (IOException ex) {
Logger.getLogger(WestfieldClientReportView.class.getName()).log(Level.SEVERE, null, ex);
}
PDPage templatepage = (PDPage) document.getDocumentCatalog().getAllPages().get(0);
int n = 0;
while (n < numPages) {
n++;
document.importPage(templatepage);
}
问题是当我有很大的结果集时。我将打开 pdf,它将显示为 11 页,前 2 页看起来很棒,但是当我滚动到第 3 页时,Acrobat 错误,虽然模板页面似乎在那里,但上面没有我的报告数据。我认为问题可能出在上面的代码上。有什么想法吗?谢谢。
I have made a single page pdf template file. I then use pdfbox to create a pdf with "n" number of pages (depending on report size). I want all "n" of these pages to be the page from the template pdf file. What is the best way to get all "n" pages to be a copy of that page? Here is my current code:
PDDocument document = null;
try {
document = PDDocument.load(WestfieldClientReportApp.class.getResource("/com/dramble/resources/template.pdf"));
} catch (IOException ex) {
Logger.getLogger(WestfieldClientReportView.class.getName()).log(Level.SEVERE, null, ex);
}
PDPage templatepage = (PDPage) document.getDocumentCatalog().getAllPages().get(0);
int n = 0;
while (n < numPages) {
n++;
document.importPage(templatepage);
}
The problem is when I have large result sets. I'll open the pdf, it will show as 11 pages, the first 2 pages look great, but when I scroll to the 3rd page, Acrobat errors, though the template page seems to be there, but without my report data on it. I figure the problem is probably with the code above. Any ideas? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是因为当您从列表显式转换为 PDPage 时,它会删除其 acrofields。
it might be because when you are casting explicitely from list to PDPage, it removes its acrofields.
您的代码似乎没有保存结果。你是?
这是我对类似的场景可能会对您有所帮助。
Your code doesn't appear to be saving the result. Are you?
Here is my answer to a similar scenario which may help you.