英文:
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()
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.
答案1
得分: 0
Bell,在段落编写的PdfWriter中,如果句子不适合一行,它会在空格后自动移到下一行,因为我们的正式语言句子以句号“。”结束,所以有可能的方法来完成这项工作。
- 将完整的句子分配给 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 .
- Assign complete sentence to para1 = new Paragraph(20,"this is sentence.");
and then move to next line and assign new paragraph.
专注分享java语言的经验与见解,让所有开发者获益!
评论