I’m using Aspose.Words to produce a word document and use builder.InsertField() to produce section page numbering in the footer. This works fine, however when converting to pdf using Aspose.pdf the SECTIONPAGES value is not being displayed. NUMPAGES works fine but not SECTIONPAGES.
My code is as follows:
...
builder.InsertCell()
builder.Write("Page ")
builder.InsertField("PAGE", "")
builder.Write(" of ")
builder.InsertField("SECTIONPAGES", "")
...
...
'Save the document in Aspose.Pdf.Xml format into a memory stream
Dim Stream As MemoryStream = New MemoryStream()
doc.SaveOptions.PdfExportFormFieldsAsText = False
doc.Save(Stream, SaveFormat.AsposePdf)
Stream.Seek(0, SeekOrigin.Begin)
'Load the document into an XmlDocument
Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.Load(Stream)
'Load the XML document into Aspose.Pdf
Dim pdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf()
pdf.BindXML(xmlDoc, Nothing)
'Now produce the PDF file
pdf.Save("ArrangementsReport.pdf", Aspose.Pdf.SaveType.OpenInAcrobat, Response)
I am unable to produce the problem you mentioned. Please find attached output after converting the document from the sample document. If your output is different then send your output PDF. Meanwhile, please try to set the IsPageNumberForDocument property to false. Hope it works.
I have attached my output PDF. As you can see the SECTIONCOUNT field gets omitted. I have tried setting the IsPageNumberForDocument = false, but this has no noticeable effect.
The following is my VB.NET code used to convert the word document:
'Save the document in Aspose.Pdf.Xml format into a memory stream
Dim Stream As MemoryStream = New MemoryStream()
doc.SaveOptions.PdfExportFormFieldsAsText = False
doc.Save(Stream, SaveFormat.AsposePdf)
Stream.Seek(0, SeekOrigin.Begin)
'Load the document into an XmlDocument
Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.Load(Stream)
'Load the XML document into Aspose.Pdf
Dim pdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf()
pdf.IsPageNumberForDocument = False
pdf.BindXML(xmlDoc, Nothing)
'Now produce the PDF file
pdf.Save("ArrangementsReport.pdf", Aspose.Pdf.SaveType.OpenInAcrobat, Response)
I have tried with Aspose.Pdf version 3.3.5.0 and Aspose.Words version 4.2.1.0 again by using the code you have posted and I am not been able to reproduce the problem. Please ensure that you are using the latest version.
I’ve made sure we’re using Aspose.Words v4.2.1.0 and Aspose.Pdf v3.3.5.0. I’ve stripped the report down to the bare minimum leaving this as my complete code:
<%@ Page trace="false" Language="VB" Inherits="SecurePage"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="Aspose.Words" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page\_Load(ByVal sender As Object, ByVal e As System.EventArgs)
'Word or PDF
Dim strFormat As String = Request.QueryString("format")
'### Create a License object & set license ###
Dim license\_word As Aspose.Words.License = New Aspose.Words.License()
license\_word.SetLicense(Server.MapPath(iSAMS.System.Aspose.licensefile))
Dim license\_pdf As Aspose.Pdf.License = New Aspose.Pdf.License()
license\_pdf.SetLicense(Server.MapPath(iSAMS.System.Aspose.licensefile))
'### Create document ###
'Create doc
Dim doc As Document = New Document()
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
'### Build footer ###
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary)
builder.StartTable()
builder.RowFormat.Borders.Top.LineWidth = "1"
builder.RowFormat.Height = "15"
builder.RowFormat.TopPadding = "10"
builder.Font.Name = "Arial"
builder.Font.Size = "10"
builder.InsertCell()
builder.CellFormat.Width = "200"
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center
builder.Write("Page ")
builder.InsertField("PAGE", "")
builder.Write(" of ")
builder.InsertField("SECTIONPAGES", "")
builder.EndRow()
builder.EndTable()
'### Move back to body ###
builder.MoveToSection(0)
If strFormat.ToUpper() = "PDF" Then
'Save the document in Aspose.Pdf.Xml format into a memory stream
Dim Stream As MemoryStream = New MemoryStream()
doc.SaveOptions.PdfExportFormFieldsAsText = False
doc.Save(Stream, SaveFormat.AsposePdf)
Stream.Seek(0, SeekOrigin.Begin)
'Load the document into an XmlDocument
Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.Load(Stream)
'Load the XML document into Aspose.Pdf
Dim pdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf()
pdf.IsPageNumberForDocument = False
pdf.BindXML(xmlDoc, Nothing)
'Now produce the PDF file
pdf.Save("ArrangementsReport.pdf", Aspose.Pdf.SaveType.OpenInAcrobat, Response)
Else
'Save document & prompt for download
doc.Save("ArrangementsReport.doc", Aspose.Words.SaveFormat.Doc, Aspose.Words.SaveType.OpenInWord, HttpContext.Current.Response)
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server" id="head">
<title>Report</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
I’ve attached the resulting word and pdf documents for you to see the output. Please advise.
You should update fields in your document before conversion to PDF (for example, by selecting the entire contents and pressing F9), otherwise they may contain no values or outdated values which leads to the result attached above. Aspose.Words does not update field values automatically (apart of few field types); we are planning to add support for this feature somewhere in 2007.