【发布时间】:2014-02-28 22:37:08
【问题描述】:
好吧,我一直在使用 PDFBox,但我仍然完全不明白,但我已经阅读了文档、使用字体和其他一些地方,但我已经找到了如何从PDF 和它的风格,但我正在创建它,而不是阅读它。
我正在尝试做点什么
点赞:这个(粗体和普通文本在同一行)。
我一直在使用流:
不确定这是否是帮助我所需的所有代码,因为我刚加入这个项目,但它在我加入时就开始了。
如果您能帮助我实现此代码,或者帮助我提供可以阅读解决方案的想法或来源,我将感谢大家。
我把我的代码留在这里:
public void rCovernoteFooter(PDPageContentStream stream , float x, float y) throws IOException {
y = y-20;
String currentDate = df1.format(new Date());
String[] issues = constants.issued().split("/");
String issued = issues[0] + currentDate + issues[1];
y = rText(stream, x, y, 90, 0, 10, issued, null);
stream.setFont(PDType1Font.TIMES_ROMAN, 8);
y = rText(stream, x, y - 50, 117, 0, 10, constants.terms(), null);
}
public float rText(PDPageContentStream cStream, float x, float y, int col1, int col2, int spc, String data1, String data2) throws IOException {
float y1 = 0f;
float y2 = 0f;
if (data2 == null) {
y = iterate(data1, col1, x, y, spc, cStream);
} else {
y1 = iterate(data1, col1, x, y, spc, cStream);
y2 = iterate(data2, col2, x + 125, y, spc, cStream);
if (y1 >= y2) {
return y2;
} else {
return y1;
}
}
return y;
}
private float iterate(String text, int len, float x, float y, int space, PDPageContentStream stream) throws IOException {
int rowHeight = 0;
List<String> wordList = Lists.newArrayList();
wordList = wordLines(text, len);
stream.setFont(PDType1Font.TIMES_BOLD, 10);
for (String word : wordList) {
stream.beginText();
stream.moveTextPositionByAmount(x, y - rowHeight);
stream.drawString(word);
stream.endText();
if (wordList.size() != 1)
rowHeight = rowHeight + 10;
}
if (rowHeight >= space) {
y = y - (rowHeight + 10);
} else {
y = y - space;
}
return y;
}
感谢您的建议
【问题讨论】: