When combining 2 (or more) documents, each one with it’s own page numbers, how can we keep the original page numbering?
For example, document A has 3 pages, document B has 2 pages. Currently, the page numbering is 1,2,3,4,5, but our users want to have 1,2,3,1,2 when the two documents are combined into one.
This is the code that I am using to combine documents:
Private Sub cmd_CombineForms()
Dim TL As cSelectTemplateList = CType(Session("SelectForms_TemplateList"), cSelectTemplateList)
Dim GeneratedPath As String = CType(Session("GeneratedPath"), String)
Dim FilesAdded As Boolean = False
Dim FirstDoc As Boolean = True
Dim doc As Aspose.Words.Document = Nothing
For Each TI As cSelectTemplateList.cTemplateInfo In TL.TemplateList
If TI.GeneratedFileName.Length() > 0 AndAlso System.IO.File.Exists(GeneratedPath & TI.GeneratedFileName) Then
If FirstDoc Then
doc = New Aspose.Words.Document(GeneratedPath & TI.GeneratedFileName)
FirstDoc = False
Else
Dim append_doc As Aspose.Words.Document = New Aspose.Words.Document(GeneratedPath & TI.GeneratedFileName)
For Each srcSection As Aspose.Words.Section In append_doc
Dim dstSection As Aspose.Words.Node = doc.ImportNode(srcSection, True, Aspose.Words.ImportFormatMode.KeepSourceFormatting)
doc.AppendChild(dstSection)
Next srcSection
append_doc = Nothing
End If
FilesAdded = True
End If
Next
If FilesAdded AndAlso doc IsNot Nothing Then
Response.ContentType = "application/vnd.ms-word.document"
Dim FileName As String = Split(Me.txtFileName.Text.Trim(), " ")(0) & ".docx"
Response.AddHeader("content-disposition", "attachment;filename=" & Context.Server.HtmlEncode(FileName))
doc.Save(Response.OutputStream, Aspose.Words.SaveFormat.Docx)
Response.Flush()
Response.End()
End If
doc = Nothing
End Sub