如何通过生成模板的iText PDF [英] How to generate PDF via IText Template

查看:376
本文介绍了如何通过生成模板的iText PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们要实现以下内容:


  1. 生成与模板,这意味着设定值AcroFields PDF

  2. 创建一个大的信息表(表结构也是模板)。在这一进展,细节将占据多个页面。

  3. 如果详细表是在多页,表中的标题也应是对新页面的顶部。

我们发现以下网站上的一些例子:

We found some examples on following website:

  • http://kuujinbo.info/cs/itext_template1.aspx
  • http://kuujinbo.info/cs/itext_template2.aspx

但细节的职能A anaylse省略那里。

But the details the founction is omitted there.

添加的内容;为_do_form_fields的code(),_get_transaction_details(),和_transaction_summary()被省略,因为它们只返回字符串添加到ColumnText。 ColumnText是聪明的;每次调用去()呈现,将适合在当前页上,并返回一个状态code,告诉你尽可能多的内容:(1)如何多的文字(写)的剩余量,和/或(2)有多少空间仍然可用在页面上。在每次迭代中添加文本到当前页面,调用ColumnText.HasMoreText()来检查状态,然后Document.NewPage()如果必要的。

Add content; the code for _do_form_fields(), _get_transaction_details(), and _transaction_summary() are omitted, since they only return strings to add to ColumnText. ColumnText is smart; each call to Go() renders as much text that will fit on the current page and returns a status code that tells you: (1) how much text (to write) is remaining, and/or (2) how much space is still available on the page. On each iteration you add text to the current page, call ColumnText.HasMoreText() to inspect the status, and then Document.NewPage() if necessary.

是否有任何人谁收到同样​​的情况?我们是AP preciated,你可以提供一些提示或建议。

Is there anyone who had same situation before? We are appreciated that you could offer some tips or suggestions.

感谢您。

最好的问候,

程功

推荐答案

您已经在您的要求的第一步犯了一个错误。

You are already making a mistake in the first step of your requirements.

您说的生成与模板,这意味着设定值AcroFields PDF。

You say "Generate PDF with Template,which means set value in AcroFields."

第一部分是确定:要生成一个模板的PDF文件。然而,这并不意味着在AcroFields设定值。这只是一个选项。这是如果你考虑PDF是纸数字相当于你拿的选项。形式是静态的:每一个坐标是固定的。你只需在适当的地方填写的数据。如果数据不符合指定的地方,你的运气了。我已经提到我的书的第6章中的注释。您还可以看到AcroForms在一个较长的教程是如何工作的: https://www.youtube.com/watch ?v = 6YwDME0Fl1c (本教程几乎完全致力于创造从数据集的报告。)

The first part is OK: you want to generate a PDF with a template. However, this doesn't mean setting values in AcroFields. That's only one option. It's the option you take if you consider PDF being the digital equivalent of paper. The form is static: every coordinate is fixed. You just fill out data at the appropriate places. If the data doesn't fit the designated areas, you're out of luck. I already referred to chapter 6 of my book in a comment. You can also see how AcroForms work in a longer tutorial: https://www.youtube.com/watch?v=6YwDME0Fl1c (This tutorial is almost completely dedicated to creating a report from a data set.)

从模板创建PDF的另一种方法是通过使用XML形式架构。在这种情况下(如果你有一个纯XFA表单),你的PDF是XML的容器。然后,您可以注入XML数据转换成这种形式,并根据数据的形式将调整自己。当填写了一份单页的形式可以很容易地成长为一个20页的文件。这是在这个视频说明: https://www.youtube.com/watch?v=h0wzj84tnmw (请注意,从2012年开始该产品的视频日期我present已完成,现在的结果要好得多。)

Another way to create PDF from a template is by using the XML Forms Architecture. In this case (if you have a pure XFA form), your PDF is a container for XML. You can then inject XML data into this form and the form will adapt itself depending on the data. A one-page form can easily grow into a 20-page document when filled out. This is explained in this video: https://www.youtube.com/watch?v=h0wzj84tnmw (Note that the video dates from 2012. The product I present has been finished and the results are much better now.)

替代这种方法可能是创建以HTML模板。我常常把这种溶液作为的穷人的XFA解决方案的。该解决方案需要XML工人。你可以看到在这个视频为例: https://www.youtube.com/watch?v= clWoDrEEl50

Alternatives to this approach could be to create a template in HTML. I often refer to this solution as a poor man's XFA solution. This solution requires XML Worker. You can see an example in this video: https://www.youtube.com/watch?v=clWoDrEEl50

这是一个普遍的答案。因为你的问题不明确,我不能更具体。你首先需要让你的头脑有关的方法。现在,请您谈一下 AcroFields 并在约 Col​​umnText 同一时间。在漫长的教程,这被描述为的硬盘的方式的。又见 相应的在线样本。为什么你问一个很棘手的问题问简单的问题之前,这是非常令人困惑。当然,除非你已经有答案了这些简单的问题。如果是的话,请分享这些答案。

This is a general answer. I couldn't be more specific because your question isn't clear. You first need to make your mind up regarding the approach. Right now, you talk about AcroFields and at the same time about ColumnText. In the long tutorial, this is described as the hard way. See also the corresponding online samples. It is very confusing why you're asking a very difficult question before asking the simple questions. Unless of course, you already have the answer to those simple questions. If so, please share these answers.

这篇关于如何通过生成模板的iText PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆