如何使用PDFBox drawString插入换行符 [英] How to Insert a Linefeed with PDFBox drawString

查看:372
本文介绍了如何使用PDFBox drawString插入换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须用表制作PDF。到目前为止它工作正常,但现在我想添加一个包装功能。所以我需要插入换行符。

I have to make a PDF with a Table. So far it work fine, but now I want to add a wrapping feature. So I need to insert a Linefeed.

contentStream.beginText();  
contentStream.moveTextPositionByAmount(x, y);  
contentStream.drawString("Some text to insert into a table.");  
contentStream.endText();  

我想添加一个 \ n 之前插入。我尝试了 \\\ 这是换行符的十六进制值,但Eclipse向我显示错误。

I want to add a "\n" before "insert". I tried "\u000A" which is the hex value for linefeed, but Eclipse shows me an error.

是否可以使用drawString添加换行符?

Is it possible to add linefeed with drawString?

推荐答案

pdf格式不知道换行符。你必须拆分字符串并使用moveTextPositionByAmount将文本位置移动到下一行。

The pdf format doesn't know line breaks. You have to split the string and move the text position to the next line, using moveTextPositionByAmount.

这不是一个特殊的pdfbox-feature,它是由于pdf格式定义;所以没有办法使用drawString,也没有其他方法可以调用支持换行。

This is not a special "pdfbox-feature", it is due to the pdf format definition; so there is no way for drawString and there are also no other methods to be called that support linefeeds.

这篇关于如何使用PDFBox drawString插入换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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