您可以在已经转换的 PDF 中插入空行吗?
我遇到一种情况,需要增加已从 XSL 模板转换而来的 PDF 上的表格和标题之间的空间。 我需要在新创建的空间中插入一个地址。这部分很简单,我可以使用压模和新桌子来完成。
然而,我正在努力寻找一种解决方案来将网格向下移动以腾出空间。
基本上,我使用 FOP 从 XSL 模板创建 PDF,使用类似于以下的代码:
OutputStream out = new java.io.FileOutputStream(pdf);
Driver driver = new Driver();
driver.setRenderer(Driver.RENDER_PDF);
driver.setOutputStream(out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xsl));
StringReader xmlStream = new StringReader(xmlData);
Source xmlSource = new StreamSource(xmlStream);
Result res = new SAXResult(driver.getContentHandler());
transformer.transform(xmlSource, res);
是否可以通过添加新空间的方式访问 PDF?如果是这样,我有什么选择?我应该提到的是,我不知道转变发生时我是否需要额外的空间。我只有在获得 PDF 的页数后才知道我需要它。
非常感谢任何帮助!
I have a situation where I need to increase the space between a table and the header on a PDF that has already been transformed from an XSL template.
I need to insert an address in the newly created space. This part is easy enough and I can do that using a stamper and a new table.
However, I am struggling to find a solution to move the grid down to make the space.
Basically I am using FOP to create the PDF from an XSL template using code similar to the following:
OutputStream out = new java.io.FileOutputStream(pdf);
Driver driver = new Driver();
driver.setRenderer(Driver.RENDER_PDF);
driver.setOutputStream(out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xsl));
StringReader xmlStream = new StringReader(xmlData);
Source xmlSource = new StreamSource(xmlStream);
Result res = new SAXResult(driver.getContentHandler());
transformer.transform(xmlSource, res);
Is it even possible to access the PDF in a way to add the new space? If so, what are my options? I should mention that I don’t know at the time the transformation is happening that I will need the extra space. I only know I need it once I get a page count of the PDF.
Any help is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
本身不可能添加“新空间”,但可以获取页面上对象的坐标,然后在其他地方重新绘制该对象。不幸的是,没有快速简单的解决方案,您将需要第三方 SDK 来执行此操作。
PDF 不是文字处理器格式,因此不可能像在 MS Word 中那样简单地添加几个回车符。
尝试 iText,它是用 Java 编写的,具有相当多的操作 PDF 的功能。
It's not possible to add "new space" per se, but it is possible to get the co-ordinates of an object on the page and then re-draw that object somewhere else. Unfortunately there's no quick and easy solution and you will need a third-party SDK to do this.
PDF isn't a word processor format, so it's not possible to simply add a couple of carriage returns, as you might in MS Word.
Try iText, it's written in Java and has a decent amount of functionality for manipulating PDFs.
一旦生成 PDF,似乎就不可能(至少从我尝试和阅读的所有内容来看)移动转换后的对象。
由于我已经在使用 iText 和 PdfStamper 类,因此我能够插入一个新页面并插入一个包含当前地址信息的新表。我使用以下代码做到了这一点:
这不是我的问题的答案,我认为我会分享一个可行的解决方案,以防其他人陷入同一问题。
It seems it is not possible (at least from everything I have tried and read) to move transformed objects around once the PDF has already been generated.
Since I was already using iText and the PdfStamper class I was able to insert a new page and insert a new table with the current address info. I did this with the following code:
This is not the answer to my question by a viable solution I thought I would share in case others get hung up on the same issue.