Hi Team,
When I write “line 1”, “insert page break”, “apply style” and then write “line 2”, the style is being applied to “line 1” as well. The page break is not being considered as end of the paragraph. “Line 1” should be one paragraph and “Line 2” should be a new paragraph.
As a workaround, insert blank line before applying style will fix the issue. However, the extra line is seen in the second page.
Please find the code below and other necessary attachment along with output.
This issue is seen in Aspose Words for Java 11.3.0.0 as well as in 11.10.
Thanks,
Kumar
import java.io.FileInputStream;
import java.io.InputStream;
import com.aspose.words.BreakType;
import com.aspose.words.BuildVersionInfo;
import com.aspose.words.Document;
import com.aspose.words.DocumentBuilder;
import com.aspose.words.License;
public class PreviousParagraph
{
public static void main(String[] args) throws Exception
{
printAsposeVersion();
setupLicense();
Document doc = new Document("c:\abc.dot");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Aspose product and version is = "\ + BuildVersionInfo.getProduct() + " : "\ + BuildVersionInfo.getVersion());
builder.writeln();
paragraphStyleIndent(builder, doc);
save(doc);
System.out.println("done");
}
private static void save(Document doc) throws Exception
{
doc.save("C:\test_old.doc");
doc.save("C:\test_old.pdf");
}
private static void printAsposeVersion()
{
System.out.println("Aspose product and version is = "\ + BuildVersionInfo.getProduct() + " : "\ + BuildVersionInfo.getVersion());
}
private static void setupLicense() throws Exception
{
InputStream licstream = null;
try
{
License license = new License();
licstream = new FileInputStream("src/Aspose.Words.lic"); //$NON-NLS-1$
license.setLicense(licstream);
}
finally
{
if (licstream != null)
{
licstream.close();
}
}
}
private static void paragraphStyleIndent(DocumentBuilder docBuilder,
Document doc) throws Exception
{
docBuilder.write("This is line 1");
docBuilder.insertBreak(BreakType.PAGE_BREAK);
docBuilder.getParagraphFormat().setStyleName("Heading 1");
docBuilder.write("This is line 2");
}
}