I use apache.poi create doc, use aspose.words to save the doc but toc page num is error

@ssj123ssj Please try using the following code:

// move to the end of formula field.
builder.moveToField(formulaField, true);
builder.writeln();
builder.write("This is text at the end of footer");

Thank you, everything was correct this time.

1 Like

Can you help me take a look at this issue,
Can I put this font in the static file of my project, or I must have to put it on the server.

@ssj123ssj Unfortunately, Aspose.Words does not read fonts packed into JAR or WAR. So in your case you should either copy the fonts into the OS file system or use StreamFontSource or MemoryFontSource to get fonts from your JAR/WAR file and provide them to Aspose.Words.

Can you help me check this issue? The page number of the document table of contents I generated is incorrect. I used the following code to update its table of contents again, but the page number is still incorrect.
this is my code ;

  public static void main(String[] args) throws Exception {

    Document doc = new Document("C:\\Users\\hspcadmin\\Desktop\\合同\\测试文件\\0730.docx");
    doc.save("C:\\Users\\hspcadmin\\Desktop\\合同\\测试文件\\目录正确测试1.docx", SaveFormat.DOCX);
    doc.updateFields();
  }

This is the updated TOC

0730.docx (98.9 KB)

this is my genereated doc.

@ssj123ssj I cannot reproduce the problem on my side. You should note that PAGE field in the document header/footer are updated by the consumer application not by Aspose.Words. Also in your code you update field after saving the document.
Here is PDF document produced from your document on my side:
out.pdf (427.8 KB)

As you can see page number in TOC matches page number on the page.

Can you tell me how you to update the page number on your side

@ssj123ssj I used the following simple code for testing:

Document doc = new Document("C:\\Temp\\in.docx");
doc.updateFields();
doc.save("C:\\Temp\\out.docx");
doc.save("C:\\Temp\\out.pdf");

oh , I get it,thanks

1 Like

It seems that only PDF documents are normal, while doc documents are still incorrect

@ssj123ssj As I have mentioned PAGE fields in the document’s header/footer are update on the fly by the consumer application. To update these fields MS Word builds the document layout. The difference might be cause by different font set used on the machine where the document was generated and on the machine where the document is viewed.

Can you help me take a look at this issue.
I want to use aspose to load a piece of HTML, some of which have annotations added. How can I recognize these contents and create annotations when generating the doc.

@ssj123ssj Could you please attach your input HTML and expected output DOCX? We will check the documents and provide you more information.

it just like this:
this is my html:
html.docx (10.4 KB)

this is the doc I want to generate:
字体测试1 (8).docx (15.2 KB)

@ssj123ssj You should use the following HTML structure to insert content with comments:

<div>
    <p style="margin-top:0pt; margin-bottom:8pt">
        <span>Test </span><a name="_cmntref1"><span>commented text</span></a><a href="#_cmnt1" style="text-decoration:none"><span style="font-size:8pt">[AN1]</span></a><span> some other text</span>
    </p>
</div>
<div id="_cmnt1" style="-aw-comment-author:'Alex Noskov'; -aw-comment-datetime:'2024-09-03T14:41:00'; -aw-comment-initial:'AN'">
    <p style="margin-top:0pt; margin-bottom:8pt; line-height:normal; font-size:10pt">
        <a href="#_cmntref1" style="text-decoration:none"><span style="font-size:8pt">[AN1]</span></a><span>Comment text</span>
    </p>
</div>

thanks,could you tell me what this AN1 means.
and if I have multiple annotations and some of them have replies, how should I write this HTML.

I tried using this HTML and it also is okay, but I don’t know how to add annotations reply:

<div>
    <p style="margin-top:0pt; margin-bottom:8pt">
        <span>这是</span><a name="_cmntref1"><span>我的批注1</span></a><a href="#_cmnt1"></a><span>测试文档1</span>
    </p>
	<p style="margin-top:0pt; margin-bottom:8pt">
        <span>这是</span><a name="_cmntref2"><span>我的批注2</span></a><a href="#_cmnt2"></a><span>测试文档2</span>
    </p>
	<p style="margin-top:0pt; margin-bottom:8pt">
        <span>这是</span><a name="_cmntref3"><span>我的批注3</span></a><a href="#_cmnt3"></a><span>测试文档3</span>
    </p>
</div>
<div id="_cmnt1" style="-aw-comment-author:'SSJ'; -aw-comment-datetime:'2024-09-03T14:31:00'; -aw-comment-initial:'ssj'">
    <p style="margin-top:0pt; margin-bottom:8pt; line-height:normal; font-size:10pt">
        <a href="#_cmntref1"></a><span>批注1</span>
    </p>
</div>
<div id="_cmnt2" style="-aw-comment-author:'HGG'; -aw-comment-datetime:'2024-09-03T14:41:00'; -aw-comment-initial:'ssj'">
    <p style="margin-top:0pt; margin-bottom:8pt; line-height:normal; font-size:10pt">
        <a href="#_cmntref2"></a><span>批注2</span>
    </p>
</div>
<div id="_cmnt3" style="-aw-comment-author:'RML'; -aw-comment-datetime:'2024-09-03T14:51:00'; -aw-comment-initial:'ssj'">
    <p style="margin-top:0pt; margin-bottom:8pt; line-height:normal; font-size:10pt">
        <a href="#_cmntref3"></a><span>批注3</span>
    </p>
</div>

@ssj123ssj AN1 is initials. You can create the required content in MS Word document and save it to HTML using Aspose.Words. Such way you can see how Aspose.Words exports the roundtrip information. Here is HTML of comment with replies:

<div>
	<p style="margin-top:0pt; margin-bottom:8pt">
		<a name="_cmntref1"></a><a name="_cmntref2"><span>test</span><span style="-aw-comment-end:_cmntref1"></span></a><a href="#_cmnt1" style="text-decoration:none"><span style="font-size:8pt">[AN1]</span></a><span style="-aw-comment-end:_cmntref2"></span><a href="#_cmnt2" style="text-decoration:none"><span style="font-size:8pt">[AN2]</span></a>
	</p>
</div>
<hr style="width:33%; height:1px; text-align:left" />
<div id="_cmnt1" style="-aw-comment-author:'Alex Noskov'; -aw-comment-datetime:'2024-09-04T07:25:00'; -aw-comment-initial:'AN'">
	<p style="margin-top:0pt; margin-bottom:8pt; line-height:normal; font-size:10pt">
		<a href="#_cmntref1" style="text-decoration:none"><span style="font-size:8pt">[AN1]</span></a><span>This is comment</span>
	</p>
</div>
<div id="_cmnt2" style="-aw-comment-author:'Alex Noskov'; -aw-comment-datetime:'2024-09-04T07:26:00'; -aw-comment-initial:'AN'; -aw-comment-parent-id:_cmnt1">
	<p style="margin-top:0pt; margin-bottom:8pt; line-height:normal; font-size:10pt">
		<a href="#_cmntref2" style="text-decoration:none"><span style="font-size:8pt">[AN2]</span></a><span>This is reply</span>
	</p>
</div>

That’s OK. Thank you very much!

1 Like