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

Free Support Forum - aspose.com

Aspose.Words can not insert correctly line-feed characters into footnote of PDF

Hi Support,

Aspose.Words can not insert correctly line-feed characters into footnote for PDF, The line-feed characters have been converted into special characters as below. But it works very well for Word document. Please see my screen shots:

I wonder if it is a defect of Aspose.Words?

Thank you.
Vincent

PDF:

Word:


Sample code for your reference:

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

builder.writeln(“the first paragraph.”);
builder.writeln(“the second paragraph.”);

Run run1 = new Run(doc);
run1.setText(“comment 1: good\r\nvery good\r\nvery very good”);
Footnote ft1 = builder.insertFootnote(FootnoteType.FOOTNOTE, “”);
ft1.getFirstParagraph().getRuns().add(run1);

Run run2 = new Run(doc);
run2.setText(“comment#2: good?”);
Footnote ft2 = builder.insertFootnote(FootnoteType.FOOTNOTE, “”);
ft2.getFirstParagraph().getRuns().add(run2);

Run run3 = new Run(doc);
run3.setText(“comment#3: ??”);
Footnote ft3 = builder.insertFootnote(FootnoteType.FOOTNOTE, “”);
ft3.getFirstParagraph().getRuns().add(run3);

doc.save(“c:\test.doc”);
doc.save(“c:\test.pdf”);

Hi Vincent,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

The problem is reproducible with Aspose.Words for Java 10.5.0 and it needs to be corrected. I hope aspose staff will be able to correct this problem.

Hi Vincent,


Thanks for your inquiry.

I would like to highlight a few points here. First of all Aspose.Words treats \r as ControlChar.ParagraphBreak Field that represents the end of current paragraph. A Run can only
be a child of Paragraph so paragraph breaks within a run text would have caused the problem.

So, in your case, the work around would be to replace \r with Unicode Line Tabulation character (\u000b). Please see the following code snippet that I have modified:
Run run1 = new Run(doc);
run1.setText
(“comment 1: good\u000bvery good\u000bvery very good”);
Footnote ft1
= builder.insertFootnote(FootnoteType.FOOTNOTE, “”);
ft1.getFirstParagraph
().getRuns().add(run1);
I hope, this will help.

Best Regards,

Thank for you workaround, but I wonder why Word display the footnote correctly?

Hi

Thanks for your request. Actually, this is valid scenario, but it is not very good. As Awais correctly noticed it would be better to use line breaks within a Run instead of paragraphs breaks. But anyways, your request has been linked to the appropriate issue and we will let you know once it is resolved.

Best regards,

The issues you have found earlier (filed as WORDSNET-5167) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(7)

I tested it with above sample code, seems like the issue not get fixed in the latest release. Please confirm.

Thanks.
Vincent

Hi
Vincent,


Thanks for your inquiry. I managed to reproduce this issue on my side. I have logged this issue in our bug tracking system. Your request has also been linked to the appropriate issue and you will be notified as soon as it is resolved. Sorry for inconvenience.

Hi Vincent,

I’m a developer working on the issue attached to the tread.

Actually, I just closed the issue, and the fix will be available in the next release.

However, I’d like to make a few comments, because the fix is not as universal as I’d like to. And it cannot be made universal.

With the code like this

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

Run runWithCRs = new Run(doc);

runWithCRs.Text = "text before CRLF\r\ntext after CRLF\r\n\n\n \n\nmore text after another CRLF";

Paragraph par = builder.InsertParagraph();

par.Runs.Add(runWithCRs);

a document is created with bare line feeds ('\n') characters in the run text. Aspose.Words treats carriage returns ('\r') characters specially (converts them to tags in the output). But it leaves line feeds intact.

If you save such document to different MS Word formats, you will see that line feeds in the line text are displayed differently even by MS Word. For example, on saving to .doc, line feeds are displayed as a blank space (but not the space character actually). On saving to docx, line feeds in the example above do not display at all in MS Word.

So there is no way to "correctly" render a run with bare line feeds in pdf, because it will differ either from .doc output or from .docx output, as MS Word displays it.


To avoid rendering of unrecognizable characters in pdf, I chose to implement the behavior similar to MS Word’s in .doc case. The line feeds are rendered as a blank space.

However I would suggest you to avoid using line feeds in the run text as it still will lead to visual differences with docx output.

Thanks and Best Regards,

The issues you have found earlier (filed as WORDSNET-5705) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Run the below two tests on the latest Aspose release, looks like the issue still exist. Please run them on your side and investigate:

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

builder.writeln(“the first paragraph.”);
builder.writeln(“the second paragraph.”);

//this footnote will display line feed characters as square
Run run1 = new Run(doc);
run1.setText(“comment 1: good\r\nvery good\r\nvery very good”);
Footnote ft1 = builder.insertFootnote(FootnoteType.FOOTNOTE, “”);
ft1.getFirstParagraph().getRuns().add(run1);

builder.insertFootnote(FootnoteType.FOOTNOTE, “comment 1: good\r\nvery good\r\nvery very good”);

//this footnote will display line feed characters as square
Run run2 = new Run(doc);
run2.setText(“comment#2: good?\r\nof course\r\nhaha”);
Footnote ft2 = builder.insertFootnote(FootnoteType.FOOTNOTE, “”);
ft2.getFirstParagraph().getRuns().add(run2);

Run run3 = new Run(doc);
run3.setText(“comment#3: ??”);
Footnote ft3 = builder.insertFootnote(FootnoteType.FOOTNOTE, “”);
ft3.getFirstParagraph().getRuns().add(run3);

doc.save(“c:\test.doc”);
doc.save(“c:\test.pdf”);



Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write(“This paragraph will have a comment.”);
Run runObject = new Run(doc);
Comment comment = new Comment(doc);
comment.setAuthor("");
comment.setInitial("");
comment.getParagraphs().add(new Paragraph(doc));
runObject.setText(“This is very good.\r\nhkhjkljl\r\njkll”);
comment.getFirstParagraph().getRuns().add(runObject);
builder.getCurrentParagraph().appendChild(comment);
builder.writeln();
builder.getDocument().save(“c:\test.doc”);
builder.getDocument().save(“c:\test.pdf”);


Thanks.
Vincent

Hi Vincent,

Thank you for your inquiry.

I was not able to reproduce the issue with the code you provided in your latest post and Aspose.Words for Java 11.0. I used Aspose.Words.jdk16.jar.

As far as I understand, the issue was that line feed characters were rendered as squares. I don’t see such issue in the test output on my side.

Could you please describe the issue you are experiencing with the latest Aspose.Words for Java?


Thanks && Best Regards,