Search code examples
asposeaspose.words

How to include PageFields in HTML when converting using Aspose.Words


I am trying to include a field for the current page number in an HTML string. I was hoping that including the {{PAGE}} token in my string would be enough but it only gets converted to a MailMergeField instead of being replaced with the PageField.

Does anyone have any suggestions?


Solution

  • Please see the following HTML:

    <html>
    <head>
    </head>
    <body>
        <p>
            <span style="-aw-field-start:true"></span>
            <span style="-aw-field-code:' PAGE  '"></span>
            <span style="-aw-field-separator:true"></span>
            <span style="-aw-field-end:true"></span>
        </p>
    </body>
    </html>
    

    Aspose.Words will convert this HTML into a real PAGE field when using the following code:

    Document doc = new Document("D:\\temp\\in.html");
    doc.Save("D:\\Temp\\out.docx");
    

    I work with Aspose as Developer Evangelist.