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

Free Support Forum - aspose.com

How to remove Paragragh Break

I have a problem when Remove paragraph break (\r) in the end paragraph
Currently I have document loaded from word file and want insert the text (continue) to the end paragraph ( This is the heading) and have a new style for it
The original

This is the heading
This is body

Then I have added the paragraph break and then I add function InsertStyleSeparator and style the new style for the text in that paragraph , but now I want to remove the Paragraph Break but it can’t do that
Expected

This is the heading (continue)
This is body

What i get currently

This is the heading
(continue)
This is body

Can anyone suggest a solution for this ?

@TanPham You do not need to insert a paragraph break before insertion of style separator. Style separator itself is a “specials” paragraph break. You can achieve what you need usign code like the following:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Write("This is the heading");

// Now insert style separator. styleseparator itself is a "spacial" paragraph break.
builder.InsertStyleSeparator();
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
builder.Writeln("(continue)");

// Not insert main body.
builder.Write("This is body");

doc.Save(@"C:\Temp\out.docx");

out.docx (7.2 KB)

hello @alexey.noskov thanks for helping
after i debug i see it will have 2 node like this

This is building \r

(continue)

and in some case it will break paragraph when it export to PDF , but in file DOC the \r still work ( it still in line not break paragraph)

The example

Word

This is the heading (continue)

PDF

This is the heading
(continue)

@TanPham I have checked on my side and style separator is properly exported to both MS Word formats and PDF. I use the same code to generate DOCX and PDF documents:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Write("This is the heading");

// Now insert style separator. styleseparator itself is a "spacial" paragraph break.
builder.InsertStyleSeparator();
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
builder.Writeln("(continue)");

// Not insert main body.
builder.Write("This is body");

doc.Save(@"C:\Temp\out.docx");
doc.Save(@"C:\Temp\out.pdf");

out.docx (7.2 KB)
out.pdf (33.2 KB)

Could you please provide code and documents that will allow us to reproduce the problem in PDF? We will check the issue and provide you more information.

its hard to provide my code , but im in another case when i use builder.InsertStyleSeparator() after the text existed in my word file and it doesn’t create a break paragraph anymore

@TanPham builder.InsertStyleSeparator() does not generate paragraph break (line break). It insert a style separator, like this:

If you need to insert a regular paragraph break, you can use either builder.Writeln() or builder.InsertBreak(BreakType.ParagraphBreak).

currently I want to add InsertStyleSeparator but it not work for existed text in Doc i loaded from file

@TanPham Could you please attach your input document, code that will allow us to reproduce the problem and expected output? We will check the issue and provide you more information.

COMP-274.docx (62.0 KB)

This is my input file
at Final page

FINANCIAL HIGHLIGHTS (continued)
RATIOS AND SUPPLEMENTAL DATA (continued)

but when I use asepose pdf convert it will render like this

FINANCIAL HIGHLIGHTS
(continued)
RATIOS AND SUPPLEMENTAL DATA
(continued)

and after I try on another online tool like
https://www.convertapi.com/docx-to-pdf#snippet=csharpI
It render the continued text in the same line with the heading like word file
i think the export pdf from word of Aspose have some issue
@alexey.noskov could you help me to check it please

@TanPham Thank you for additional information. I have managed to reproduce the problem on my side and logged it as WORDSNET-23974. We will keep you informed and let you know once it is resolved.

1 Like

Hi @alexey.noskov What is the status of this issue? hope you guys can respond me soon

@TanPham Our developers are currently analyzing the issue. We will be sure to inform you once the problem is resolved or we have more information for your.

1 Like

Hi @alexey.noskov i see the status of WORDSNET-23974 is Closed , has the problem been solved?

@TanPham Yes, the issue is already resolved in the current codebase. The fix will be included into the next 22.7 version of Aspose.Words. It will be available at the beginning of June 2022. We will be sure to notify you once it is released.

1 Like

The issues you have found earlier (filed as WORDSNET-23974) have been fixed in this Aspose.Words for .NET 22.7 update also available on NuGet.