Hi Team,
When border is applied to a paragraph and a multiline text is written, a border is seen between the lines of the multiline texts. Is there any way to have a single border and the entire multiline text is completely within the border?
Below is the code I use to write a multiline text
builder.getParagraphFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.writeln(“Hello World! \n Expecting this multiline to be under single border”);
Thanks,
Kumar
------------------- Sample Code ----------------
import com.aspose.words.BuildVersionInfo;
import com.aspose.words.Document;
import com.aspose.words.DocumentBuilder;
import com.aspose.words.LineStyle;
public class BorderMultilineText {
public static void main(String[] args) throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
writeBorderMultitext(builder, doc);
save(doc);
System.out.println(“done”);
}
private static void writeBorderMultitext(DocumentBuilder builder,
Document doc) throws Exception {
builder.getParagraphFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.writeln(“Hello World! \n Expecting this multiline to be under single border \n Entire text should be under same border instead of separate horizontal border for each line.”);
builder.writeln(“This text is in the next complete border as expected.”);
builder.getParagraphFormat().clearFormatting();
builder.writeln("Version is " + BuildVersionInfo.getVersion());
}
private static void save(Document doc) throws Exception {
doc.save(“C:\test_old.doc”);
doc.save(“C:\test_old.pdf”);
}
}
To add on the issue, there is no border seen for PDF output. I had attached both word and doc outputs during the problem description.
Hi Kumaraswamy,
Thanks for sharing the details.
To set borders for a paragraph, you will have to set the TOP, BOTTOM, LEFT and RIGHT border styles correctly. Here is the code snippet which could be used inside your writeBorderMultitext function:
builder.writeln("Hello World! \n Expecting this multiline to be under single border \n Entire text should be under same border instead of separate horizontal border for each line."); builder.getParagraphFormat().clearFormatting();
builder.writeln("");
builder.getParagraphFormat().getBorders().setLineStyle(LineStyle.WAVE); builder.writeln("This text is in the next complete border as expected.");
builder.getParagraphFormat().clearFormatting(); builder.writeln("Version is " + BuildVersionInfo.getVersion());
Hope this helps. Apart from this, I was able to reproduce the issue with paragraph border display when save to PDF is performed. I have logged this issue as WORDSNET-7706 in our issue tracking system. I have also linked this forum thread to the issue so that you will be notified via this thread as soon as the issue is resolved.
We apologize for inconvenience. Please do let us know if you have any more queries.
Thanks Muhammad for the quick reply and the code. It helps.
Hi Kumaraswamy,
A word from development team is that they have started work on the reported issue. They have also advised that a possible workaround could be to specify width of borders as follows:
Hope this helps. Please do let us know if you have any more queries.
The issues you have found earlier (filed as WORDSNET-7706) have been fixed in this .NET update and this Java update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.
Hi Muhammad,
Another issue I see is that the border breadth size is the width of the page not the width of the text.
However, if you use the below, the border is applied upto the width of the text, which is what I’m looking for. But this has another defect of having multiple borders for multiline text.
docBuilder.getFont().getBorder().setLineStyle(LineStyle.SINGLE);
Thanks,
Kumar
Hi Kumar,
Hi Awais,
The above tests in my previous comment were run using Aspose.Words for Java v13.3. The issue is happening with the generated word document.
Thanks,
Kumar
Hi Kumar,
Hi Awais,
The concern is for both word and pdf document.
If I use builder.getFont().getBorder().setLineStyle(1); to set border for a multiline text, I see multiple border for multiple line (See test_2.doc and test_2.pdf).
If I use code as in writeBorderMultitext_1() method, I see single border, however, I see border width upto the page width. I want to limit the border width upto the text width (See test_1.doc and test_1.pdf).
What I’m looking for is that I see single border for multiline text and the width of the border should end where the text ends, not upto the page width.
Thanks,
Kumar
public static void main(String[] args) throws Exception {
Utils.setupLicense();
Utils.printAsposeVersion();
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
writeBorderMultitext_1(builder, doc);
save(doc);
System.out.println(“done”);
}
private static void writeBorderMultitext_1(DocumentBuilder builder,
Document doc) throws Exception {
builder.getParagraphFormat().getBorders()
.getByBorderType(BorderType.LEFT)
.setLineStyle(LineStyle.SINGLE);
builder.getParagraphFormat().getBorders()
.getByBorderType(BorderType.RIGHT)
.setLineStyle(LineStyle.SINGLE);
builder.getParagraphFormat().getBorders()
.getByBorderType(BorderType.TOP).setLineStyle(LineStyle.SINGLE);
builder.getParagraphFormat().getBorders()
.getByBorderType(BorderType.BOTTOM)
.setLineStyle(LineStyle.SINGLE);
builder.write(“Hello World! \n Expecting”);
}
private static void writeBorderMultitext_2(DocumentBuilder builder,
Document doc) throws Exception {
builder.getFont().getBorder().setLineStyle(1);
builder.write(“Hello World! \n Expecting”);
}
private static void save(Document doc) throws Exception {
doc.save(“C:\test_old.doc”);
doc.save(“C:\test_old.pdf”);
}
Hi Kumar,
private static void writeBorderMultitext_1(DocumentBuilder builder,
Document doc) throws Exception {
builder.getFont().getBorder().setLineStyle(LineStyle.SINGLE);}builder<font color="BLUE"><b>.</b></font>writeln<font color="BLUE"><b>(</b></font><font color="PURPLE">"Hello World!"</font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font> builder<font color="BLUE"><b>.</b></font>writeln<font color="BLUE"><b>(</b></font><font color="PURPLE">"Expecting"</font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
Hi Awais,
I’m looking for something as in the screenshot.
Thanks,
Kumar
Hi Kumar,