Merge Word Documents As Pages Of A Single Document Using VB.NET

elizas's Avatar, Join Date: Feb 2010
Light Poster
Lets say we have a word template file and we need to populate the template for "n" number of records and display a single large word document , instead of "n" separate documents.

So after creating the separate documents we need to merge them and create a single document with multiple pages.

Hope this tip would add some value.Any suggestions are welcomed,
0
mialuzzatto's Avatar, Join Date: Aug 2015
Ambitious contributor
Hello,

Bit helpful.
0
alia123's Avatar, Join Date: Jan 2016
Contributor
Hey, try this code :
Code:
   Imports RasterEdge.Imaging.Basic
     Imports RasterEdge.Imaging.Basic.Core
     Imports RasterEdge.Imaging.Basic.Codec
     Imports RasterEdge.Imaging.MSWordDocx

     Namespace RE__Test
     Public Partial Class Form1
     Inherits Form
     Public Sub New()
     InitializeComponent()
     End Sub

     Public Shared FolderName As String = "c:/"

     Private Sub button1_Click(sender As Object, e As EventArgs)
     Dim fileName1 As String = FolderName & "Sample1.docx"
     Dim fileName2 As String = FolderName & "Sample2.docx"
     Dim fileNameMerged As String = FolderName & "Merged.docx"

     Dim doc1 As REDocument = REFile.OpenDocumentFile(fileName1, New DOCXDecoder())
     'use DOCXDecoder open one word file
     Dim doc2 As REDocument = REFile.OpenDocumentFile(fileName2, New DOCXDecoder())
     'use DOCXDecoder open another word file
     Dim docMerged As BaseDocument = doc1.MergeDocument(doc2)
     'merge two word
     REFile.SaveDocumentFile(DirectCast(docMerged, REDocument), fileNameMerged, New DOCXEncoder())
     'save new word
     End Sub

     End Class
     End Namespace