We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Want to put Page Break if first character is 1

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


Hi Mike,

Thanks for your inquiry. Please use the following code example to get the desired output. If you still face problem, please share your expected output document here for our reference. We will then provide you more information about your query along with code.

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.

Hi Mike,

Thanks for your inquiry. In case, you are using old version of Aspose.Words, we suggest you please upgrade to the latest version of Aspose.Words for Java 16.12.0.

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.