|
//Open the
main document.
using (WordDocument mainDocument = new WordDocument(@"../../MainDocument.docx"))
{
//Get the Word document names from a folder.
string[]
subDocumentNames = Directory.GetFiles(@"../../Data/");
//Merge each Word document to the main document.
foreach (string subDocumentName in subDocumentNames)
{
//Open the sub document.
using (WordDocument subDocument = new WordDocument(subDocumentName))
{
//Import the contents of sub document at the end of main
document.
mainDocument.ImportContent(subDocument);
}
}
//Create an instance of the DocToPDFConverter.
DocToPDFConverter converter = new DocToPDFConverter();
//Convert Word document into PDF document.
PdfDocument pdfDocument =
converter.ConvertToPDF(mainDocument);
//Save the PDF file.
pdfDocument.Save("WordtoPDF.pdf");
//Close the instance of document objects.
pdfDocument.Close(true);
}
|