This question is locked. New answers and comments are not allowed.
Hello,
I'm trying to use a RadDocument to import 2 DOCX byte arrays into a single document. Once imported, the idea is to export the results into a single document of any specified type. In this case, I'm choosing PDF.
I've noticed the following:
1) The 2nd file works flawlessly, but does not have header information
2) The 1st file imports the details of the file, but does not import the page header/footer (necessary)
3) Instead of merging Doc1 with Doc2 into a NewDoc, if I set NewDoc = Doc1 and then insert Doc2 it includes the Header/Footer, but ruins the formatting of Doc2
Here is the code used:
I'm trying to use a RadDocument to import 2 DOCX byte arrays into a single document. Once imported, the idea is to export the results into a single document of any specified type. In this case, I'm choosing PDF.
I've noticed the following:
1) The 2nd file works flawlessly, but does not have header information
2) The 1st file imports the details of the file, but does not import the page header/footer (necessary)
3) Instead of merging Doc1 with Doc2 into a NewDoc, if I set NewDoc = Doc1 and then insert Doc2 it includes the Header/Footer, but ruins the formatting of Doc2
Here is the code used:
Public Shared Function MergeDocuments(ByVal Document1 As Byte(), ByVal Document2 As Byte()) As Byte() Dim iProvider As IDocumentFormatProvider = New DocxFormatProvider ' Create RadDocuments from the byte arrays (NOTE: currently only accepts DOCX) Dim iDoc1 As RadDocument = iProvider.Import(Document1) Dim iDoc2 As RadDocument = iProvider.Import(Document2) Dim iNewDocument As New RadDocument ' Have to do this to work with API of RadDocument iNewDocument.MeasureAndArrangeInDefaultSize() iDoc1.MeasureAndArrangeInDefaultSize() iDoc2.MeasureAndArrangeInDefaultSize() ' Create Document Fragments of each document 'TODO: The header/footer is not getting selected iDoc1.Selection.SelectAll() Dim iDoc1Fragment As DocumentFragment = iDoc1.Selection.CopySelectedDocumentElements() iDoc2.Selection.SelectAll() Dim iDoc2Fragment As DocumentFragment = iDoc2.Selection.CopySelectedDocumentElements() ' Track the position of the New Document and insert the Fragments Dim iPosition As DocumentPosition = New DocumentPosition(iNewDocument) ' Move to the last charater of the new doc and paste Doc1 iPosition.MoveToLastPositionInDocument() iNewDocument.InsertFragment(iDoc1Fragment, iPosition) ' Then insert a page break iNewDocument.InsertPageBreak() ' Finally move to the last character again and paste Doc2 iPosition.MoveToLastPositionInDocument() iNewDocument.InsertFragment(iDoc2Fragment, iPosition) ' Export the files as a PDF and return it Dim iPDFProvider As IDocumentFormatProvider = New PdfFormatProvider Dim iPDFBytes As Byte() = iPDFProvider.Export(iNewDocument) Return iPDFBytes End Function