- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 PdfClown 打印 pdf 时,打印超出页面,而 PdfClown 没有创建新页面,如何解决此问题?
代码如下,它将文本打印到 pdf 页面上,当打印开始超出页面底部时,应自动添加另一个 pdf 页面,是否有 PdfClown 设置可以解决此问题?
任何帮助将不胜感激。
import org.pdfclown.documents.Document;
import org.pdfclown.documents.Page;
import org.pdfclown.documents.contents.composition.BlockComposer;
import org.pdfclown.documents.contents.composition.PrimitiveComposer;
import org.pdfclown.documents.contents.composition.XAlignmentEnum;
import org.pdfclown.documents.contents.composition.YAlignmentEnum;
import org.pdfclown.documents.contents.fonts.StandardType1Font;
import org.pdfclown.files.File;
import org.pdfclown.files.SerializationModeEnum;
import org.pdfclown.util.math.geom.Dimension;
import java.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
public class PrintWithPdfClown{
private static final int Margin_X = 50;
private static final int Margin_Y = 50;
public void printAuthorInfo() {
// Create a document and add a page to it
try {
for (int j = 0; j < author.size(); j++) {
String name = author.get(j).getFirstName();
String lastName = author.get(j).getLastName();
String addressLine1 = author.get(j).getAddressLine1();
String addressLine2 = author.get(j).getAddressLine2();
String city = author.get(j).getCity();
String state = author.get(j).getState();
String postalCode = author.get(j).getPostalCode();
String country = author.get(j).getCountry();
Document document = new File().getDocument();
Page page = new Page(document);
document.getPages().add(page);
Dimension2D pageSize = page.getSize();
PrimitiveComposer composer = new PrimitiveComposer(page);
BlockComposer blockComposer = new BlockComposer(composer);
composer.beginLocalState();
Rectangle2D frame = new Rectangle2D.Double(Margin_X, Margin_Y, pageSize.getWidth() - Margin_X * 2, pageSize.getHeight() - Margin_Y * 2);
blockComposer.begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top);
Dimension breakSize = new Dimension(24, 8); // Indentation (24pt)
// and top margin (8pt).
composer.setFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Courier, true, false), 8);
blockComposer.begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top);
blockComposer.showText("########## Author Address ##########");
blockComposer.showBreak(breakSize);
blockComposer.showBreak(breakSize);
blockComposer.showText(name + " " + lastName + " " );
blockComposer.showBreak(breakSize);
blockComposer.showText(addressLine1);
blockComposer.showBreak(breakSize);
blockComposer.showText(addressLine2);
blockComposer.showBreak(breakSize);
blockComposer.showText(city + " " + state + " " + postalCode + " " + country);
blockComposer.showBreak(breakSize);
blockComposer.showBreak(breakSize);
for (int i = 0; i < author.get(j).booksOfAuthor.size(); i++) {
String productName = author.get(j).booksOfAuthor.get(i).getBookName();
String pages = author.get(j).booksOfAuthor.get(i).getPages();
blockComposer.showBreak(breakSize);
blockComposer.showText("########## <" + (i + 1) + ". Book > ##########");
blockComposer.showBreak(breakSize);
blockComposer.showText(" <Book Name:> " + bookName + " <Pages:> " + pages);
blockComposer.showBreak(breakSize);
blockComposer.showBreak(breakSize);
}
blockComposer.end();
composer.flush();
document.getFile().save(job.getAuthorFileLocalDir() + "/" + "Author_Info " + j + ".pdf", SerializationModeEnum.Standard);
}
} catch (Exception e) {
e.printStackTrace();
}
}
最佳答案
目前(版本 0.2.0 之前)PDF Clown 要求您的代码在页面已满时显式创建新页面。
以下代码演示了如何做到这一点。由于我没有您的图书数据,因此代码使用了 String[] 段落
中的一些静态文本。 (实际上,该示例是 PDF Clown cli 示例 ComplexTypesettingSample 的精简版本,并且还使用该示例中使用的文本):
@Test
public void testShowMultiPageText() throws IOException
{
String[] paragraphs = new String[]
{
"We maintain this free software definition to show clearly what must be true about a particular software program for it to be considered free software.",
"\"Free software\" is a matter of liberty, not price. To understand the concept, you should think of \"free\" as in \"free speech\", not as in \"free beer\".",
"Free software is a matter of the users' freedom to run, copy, distribute, study, change and improve the software. More precisely, it refers to four kinds of freedom, for the users of the software:",
"* The freedom to run the program, for any purpose (freedom 0).",
"* The freedom to study how the program works, and adapt it to your needs (freedom 1). Access to the source code is a precondition for this.",
"* The freedom to redistribute copies so you can help your neighbor (freedom 2).",
"* The freedom to improve the program, and release your improvements to the public, so that the whole community benefits (freedom 3). Access to the source code is a precondition for this.",
"A program is free software if users have all of these freedoms. Thus, you should be free to redistribute copies, either with or without modifications, either gratis or charging a fee for distribution, to anyone anywhere. Being free to do these things means (among other things) that you do not have to ask or pay for permission.",
"You should also have the freedom to make modifications and use them privately in your own work or play, without even mentioning that they exist. If you do publish your changes, you should not be required to notify anyone in particular, or in any particular way.",
"The freedom to use a program means the freedom for any kind of person or organization to use it on any kind of computer system, for any kind of overall job, and without being required to communicate subsequently with the developer or any other specific entity.",
"The freedom to redistribute copies must include binary or executable forms of the program, as well as source code, for both modified and unmodified versions. (Distributing programs in runnable form is necessary for conveniently installable free operating systems.) It is ok if there is no way to produce a binary or executable form for a certain program (since some languages don't support that feature), but you must have the freedom to redistribute such forms should you find or develop a way to make them.",
"In order for the freedoms to make changes, and to publish improved versions, to be meaningful, you must have access to the source code of the program. Therefore, accessibility of source code is a necessary condition for free software.",
"In order for these freedoms to be real, they must be irrevocable as long as you do nothing wrong; if the developer of the software has the power to revoke the license, without your doing anything to give cause, the software is not free.",
"However, certain kinds of rules about the manner of distributing free software are acceptable, when they don't conflict with the central freedoms. For example, copyleft (very simply stated) is the rule that when redistributing the program, you cannot add restrictions to deny other people the central freedoms. This rule does not conflict with the central freedoms; rather it protects them.",
"You may have paid money to get copies of free software, or you may have obtained copies at no charge. But regardless of how you got your copies, you always have the freedom to copy and change the software, even to sell copies.",
"\"Free software\" does not mean \"non-commercial\". A free program must be available for commercial use, commercial development, and commercial distribution. Commercial development of free software is no longer unusual; such free commercial software is very important.",
"Rules about how to package a modified version are acceptable, if they don't substantively block your freedom to release modified versions. Rules that \"if you make the program available in this way, you must make it available in that way also\" can be acceptable too, on the same condition. (Note that such a rule still leaves you the choice of whether to publish the program or not.) It is also acceptable for the license to require that, if you have distributed a modified version and a previous developer asks for a copy of it, you must send one, or that you identify yourself on your modifications.",
"In the GNU project, we use \"copyleft\" to protect these freedoms legally for everyone. But non-copylefted free software also exists. We believe there are important reasons why it is better to use copyleft, but if your program is non-copylefted free software, we can still use it.",
"See Categories of Free Software for a description of how \"free software,\" \"copylefted software\" and other categories of software relate to each other.",
"Sometimes government export control regulations and trade sanctions can constrain your freedom to distribute copies of programs internationally. Software developers do not have the power to eliminate or override these restrictions, but what they can and must do is refuse to impose them as conditions of use of the program. In this way, the restrictions will not affect activities and people outside the jurisdictions of these governments.",
"Most free software licenses are based on copyright, and there are limits on what kinds of requirements can be imposed through copyright. If a copyright-based license respects freedom in the ways described above, it is unlikely to have some other sort of problem that we never anticipated (though this does happen occasionally). However, some free software licenses are based on contracts, and contracts can impose a much larger range of possible restrictions. That means there are many possible ways such a license could be unacceptably restrictive and non-free.",
"We can't possibly list all the possible contract restrictions that would be unacceptable. If a contract-based license restricts the user in an unusual way that copyright-based licenses cannot, and which isn't mentioned here as legitimate, we will have to think about it, and we will probably decide it is non-free.",
"When talking about free software, it is best to avoid using terms like \"give away\" or \"for free\", because those terms imply that the issue is about price, not freedom. Some common terms such as \"piracy\" embody opinions we hope you won't endorse. See Confusing Words and Phrases that are Worth Avoiding for a discussion of these terms. We also have a list of translations of \"free software\" into various languages.",
"Finally, note that criteria such as those stated in this free software definition require careful thought for their interpretation. To decide whether a specific software license qualifies as a free software license, we judge it based on these criteria to determine whether it fits their spirit as well as the precise words. If a license includes unconscionable restrictions, we reject it, even if we did not anticipate the issue in these criteria. Sometimes a license requirement raises an issue that calls for extensive thought, including discussions with a lawyer, before we can decide if the requirement is acceptable. When we reach a conclusion about a new issue, we often update these criteria to make it easier to see why certain licenses do or don't qualify.",
"If you are interested in whether a specific license qualifies as a free software license, see our list of licenses. If the license you are concerned with is not listed there, you can ask us about it by sending us email at <licensing@fsf.org>.",
"If you are contemplating writing a new license, please contact the FSF by writing to that address. The proliferation of different free software licenses means increased work for users in understanding the licenses; we may be able to help you find an existing Free Software license that meets your needs.",
"If that isn't possible, if you really need a new license, with our help you can ensure that the license really is a Free Software license and avoid various practical problems.",
"Another group has started using the term \"open source\" to mean something close (but not identical) to \"free software\". We prefer the term \"free software\" because, once you have heard it refers to freedom rather than price, it calls to mind freedom. The word \"open\" never does that."
};
org.pdfclown.files.File file = new org.pdfclown.files.File();
Document document = file.getDocument();
Font font = new StandardType1Font(document,StandardType1Font.FamilyEnum.Courier, false, false);
Page page = new Page(document);
document.getPages().add(page);
Dimension2D pageSize = page.getSize();
PrimitiveComposer composer = new PrimitiveComposer(page);
BlockComposer blockComposer = new BlockComposer(composer);
Rectangle2D frame = new Rectangle2D.Double(30, 30, (pageSize.getWidth() - 60), pageSize.getHeight() - 60);
blockComposer.begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top);
composer.setFont(font, 15);
for (String paragraph : paragraphs)
{
int paragraphTextIndex = 0;
while ((paragraphTextIndex += blockComposer.showText(paragraph.substring(paragraphTextIndex))) < paragraph.length())
{
blockComposer.end();
composer.flush();
document.getPages().add(page = new Page(document));
composer = new PrimitiveComposer(page);
blockComposer = new BlockComposer(composer);
blockComposer.begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top);
composer.setFont(font, 15);
}
blockComposer.showBreak(new Dimension(10, 10));
}
blockComposer.end();
composer.flush();
file.save("multiPage.pdf", SerializationModeEnum.Standard);
file.close();
}
如您所见,您只需检查 blockComposer.showText
的返回代码即可查看文本是否确实适合输出框架。如果没有,则关闭当前的 Composer ,开始新页面,打开新的 Composer ,然后继续从剪切位置绘制剪切段落。
您还可以创建更复杂的布局,每页有多个框架。为此,请查看示例 ComplexTypesettingSample .
<小时/>0.2.0 版本一出现,新的 Content composition engine会主动承担起你的苦差事。
关于java - 使用 PdfClown 打印 pdf 时,打印超出页面,而没有 PdfClown 创建新页面,如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35531396/
@Cacheable在同一类中方法调用无效 上述图片中,同一个类中genLiveBullets()方法调用同类中的queryLiveByRoom()方法,这样即便标识了Cacheable标签,
目录 @Transaction注解导致动态切换更改数据库失效 使用场景 遇到问题 解决 @Transaction
@RequestBody不能class类型匹配 在首次第一次尝试使用@RequestBody注解 开始加载字符串使用post提交(貌似只能post),加Json数据格式传输的时候,
目录 @Autowired注入static接口问题 @Autowired自动注入普通service很方便 但是如果注入static修饰的serv
目录 @RequestBody部分属性丢失 问题描述 JavaBean实现 Controller实现
目录 解决@PathVariable参数接收不完整的问题 今天遇到的问题是: 解决办法: @PathVariable接受的参
这几天在项目里面发现我使用@Transactional注解事务之后,抛了异常居然不回滚。后来终于找到了原因。 如果你也出现了这种情况,可以从下面开始排查。 1、特性 先来了解一下@Trans
概述: ? 1
场景: 在处理定时任务时,由于这几个方法都是静态方法,在aop的切面中使用@Around注解,进行监控方法调用是否有异常。 发现aop没有生效。 代码如下:
最近做项目的时候 用户提出要上传大图片 一张图片有可能十几兆 本来用的第三方的上传控件 有限制图片上传大小的设置 以前设置的是2M&nb
我已经实现了这个SCIM reference code在我们的应用程序中。 我实现的代码确实通过了此postman link中存在的所有用户测试集合。 。我的 SCIM Api 也被 Azure 接受
我一直对“然后”不被等待的行为感到困扰,我明白其原因。然而,我仍然需要绕过它。这是我的用例。 doWork(family) { return doWork1(family)
我正在尝试查找 channel 中的消息是否仍然存在,但是,我不确定如何解决 promise ,查看其他答案和文档,我可以看到它可能是通过函数实现的,但我是不完全确定如何去做。我希望能在这方面获得一些
我有以下情况: 同一工作区中的 2 个 Eclipse 项目:Apa 和 Bepa(为简洁起见,使用化名)。 Apa 项目引用(包括)Bepa 项目。 我在 Bepa 有一个类 X,具有公共(publ
这个问题已经有答案了: Why am I getting a NoClassDefFoundError in Java? (31 个回答) 已关闭 6 年前。 我正在努力学习 spring。所以我输入
我正在写一个小游戏,屏幕上有许多圆圈在移动。 我在两个线程中管理圈子,如下所示: public void run() { int stepCount = 0; int dx;
我在使用 Sympy 求解方程时遇到问题。当我运行代码时,例如: 打印(校正(10)) 我希望它打印一个数字 f。相反,它给我错误:执行中止。 def correction(r): from
好吧,我制作的每个页面都有这个问题。我不确定我做错了什么,但我所有的页面都不适用于所有分辨率。可能是因为我使用的是宽屏?大声笑我不确定,但在小于宽屏分辨率的情况下,它永远不会看起来正确。它的某些部分你
我正在尝试像这样进行一个非常简单的文化 srting 检查 if(culture.ToUpper() == "ES-ES" || "IT-IT") { //do something } else
Closed. This question is off-topic. It is not currently accepting answers. Learn more。 想改进这个问题吗?Upda
我是一名优秀的程序员,十分优秀!