I want to put page break if the first character is 1 followed by space.
But when I print Paragraph text the below code do not print first character, if the first character is 1 followed by space.
Below is code snippet
License wordsLicense = new License();
wordsLicense.setLicense("/usr1/pdfconverter-batch/Aspose.Words.lic");
Document d = new Document(“new 2.txt”);
for(Section s:d.getSections()){
Body b = s.getBody();
for(Paragraph pp:b.getParagraphs()){
System.out.println(pp.getText());
}
}
d.save(“test.docx”);
Thanks & Regards
Document doc = new Document(MyDir + "input.txt");
Paragraph paragraph = doc.getFirstSection().getBody().getFirstParagraph();
if(paragraph.getRuns().getCount() > 0 &&
paragraph.getRuns().get(0).getText().startsWith("1"))
{
//Your code...
DocumentBuilder builder = new DocumentBuilder(doc);;
builder.moveToDocumentStart();
builder.insertBreak(BreakType.PAGE_BREAK);
}
doc.save(MyDir + "out v16.12.0.docx");
Thanks Tahir
But I am not able to print 1 in Sysout logs
Document doc = new Document( mydir+ “new 2.txt”);
Paragraph paragraph = doc.getFirstSection().getBody().getFirstParagraph();
if(paragraph.getRuns().getCount() > 0 &&
paragraph.getRuns().get(0).getText().startsWith(“1”))
{
System.out.println(“1 Found” + paragraph.getRuns().get(0).getText());
/* DocumentBuilder builder = new DocumentBuilder(doc);;
builder.moveToDocumentStart();
builder.insertBreak(BreakType.PAGE_BREAK);*/
}
I have used simple text file with three lines.
1 POC
1 POC
1 Test POC
Thanks
Asponse consider this type of data as list. I am able to put page break based on this.
You can close this .
Thanks.