将句子字符串适当地拆分为新行(JAVA)

huangapple 未分类评论48阅读模式
英文:

Split sentences string into new line properly (JAVA)

问题

以下是您提供的代码的中文翻译部分:

我想要在 PDF 报告中使用 JAVA以适当的方式拆分泰语句子请查看下面的代码示例

def document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(Constants.FILE));
document.open()
document.setMargins(1,1,1,1);
Font fontSarabunBold = new Font(BaseFont.createFont("fonts/THSarabun Bold.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
Paragraph para1 = new Paragraph(20, "ณ ป่าใหญ่แห่งหนึ่ง มีกระต่ายตัวหนึ่งมั่นใจในความเร็วของฝีเท้าตัวเองมาก และมักพูดโม้โอ้อวดว่าไม่มีใครเทียบเทียมได้ จนวันหนึ่งเจ้ากระต่ายได้พบกับเต่าที่กำลังเดินต้วมเตี้ยมผ่านมา เมื่อเห็นดังนั้น เจ้ากระต่ายก็หัวเราะเยาะและพูดล้อเลียนว่า นี่เจ้าเต่า มัวแต่เดินอืดอาดอย่างนี้ แล้วเมื่อไรจะถึงบ้านกันล่ะเนี่ย ต่อให้เจ้าเดินนำหน้าไปก่อนครึ่งวัน ข้ายังตามเจ้าทันเลย", fontSarabunBold)
document.add(para1);
document.close()

这是结果
[![enter image description here][1]][1]

看起来程序是通过空格来拆分句子的

但是我希望能够得到以与我在 Microsoft Word 中键入的句子相同的适当方式拆分的句子

这是预期结果
[![enter image description here][2]][2]

如您所要求,这是您提供的代码的翻译版本。如果您还有其他需要帮助的地方,请随时告诉我。

英文:

I want to split sentence (thai language) in proper way in pdf report (by JAVA) Please see my code below as.

def document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(Constants.FILE));
document.open()
document.setMargins(1,1,1,1);
Font fontSarabunBold = new Font(BaseFont.createFont("fonts/THSarabun Bold.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
Paragraph para1 = new Paragraph(20, "ณ ป่าใหญ่แห่งหนึ่ง มีกระต่ายตัวหนึ่งมั่นใจในความเร็วของฝีเท้าตัวเองมาก และมักพูดโม้โอ้อวดว่าไม่มีใครเทียบเทียมได้ จนวันหนึ่งเจ้ากระต่ายได้พบกับเต่าที่กำลังเดินต้วมเตี้ยมผ่านมา เมื่อเห็นดังนั้น เจ้ากระต่ายก็หัวเราะเยาะและพูดล้อเลียนว่า นี่เจ้าเต่า มัวแต่เดินอืดอาดอย่างนี้ แล้วเมื่อไรจะถึงบ้านกันล่ะเนี่ย ต่อให้เจ้าเดินนำหน้าไปก่อนครึ่งวัน ข้ายังตามเจ้าทันเลย", fontSarabunBold)
document.add(para1);
document.close()

This is result.
将句子字符串适当地拆分为新行(JAVA)

It seems that program split sentence by space.

But I want to get sentences which are spitted in proper way same as I typed sentences in Microsoft Word.

This is expected result.
将句子字符串适当地拆分为新行(JAVA)

答案1

得分: 0

Bell,在段落编写的PdfWriter中,如果句子不适合一行,它会在空格后自动移到下一行,因为我们的正式语言句子以句号“。”结束,所以有可能的方法来完成这项工作。

  1. 将完整的句子分配给 para1 = new Paragraph(20,"this is sentence.");
    然后换到下一行并分配新的段落。
英文:

Bell,in Paragraph writing PdfWriter , if sentence is not fitting in one line, it automatically move to next line after space as our formal language sentences are completed by dot "." , so there possible way to do this work .

  1. Assign complete sentence to para1 = new Paragraph(20,"this is sentence.");
    and then move to next line and assign new paragraph.

huangapple
  • 本文由 发表于 2020年5月30日 12:08:15
  • 转载请务必保留本文链接:https://java.coder-hub.com/62097707.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定