简体   繁体   English

将句子字符串正确拆分为新行(JAVA)

[英]Split sentences string into new line properly (JAVA)

I want to split sentence (thai language) in proper way in pdf report (by JAVA) Please see my code below as.我想在 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()

This is result.这是结果。 在此处输入图像描述

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.但是我想得到以正确方式吐出的句子,就像我在 Microsoft Word 中键入的句子一样。

This is expected result.这是预期的结果。 在此处输入图像描述

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.贝尔,在段落写作 PdfWriter 中,如果句子不适合一行,它会自动移动到空格后的下一行,因为我们的正式语言句子是由点“.”完成的,所以有可能的方法来完成这项工作。

1) Assign complete sentence to para1 = new Paragraph(20,"this is sentence."); 1) 将完整句子赋给 para1 = new Paragraph(20,"this is sentence."); and then move to next line and assign new paragraph.然后移动到下一行并分配新段落。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM