add data from docx file to pdf

hi 
I want to convert my docx file to pdf for which I want to load all the docx file data to pdf is this possible 


1 Reply

SB Suriya Balamurugan Syncfusion Team October 4, 2022 09:33 AM UTC

Hi niaz,

From the given details, we have found that your requirement is to combine all the docx file to PDF.

To achieve your requirement, we suggest you to merge all the Word documents and then convert merged document to PDF using DocIO library. Please refer the below code snippet to achieve your requirement,

//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);

}


Please refer our documentation links to know more about merging Word documents,
https://www.syncfusion.com/kb/12998/how-to-merge-multiple-word-documents-in-c-vb-net
https://help.syncfusion.com/file-formats/docio/word-document/merging-word-documents

Please refer our documentation links to know more about convert Word document to PDF,
https://www.syncfusion.com/kb/9645/how-to-convert-word-to-pdf-using-c-and-vb-net
https://help.syncfusion.com/file-formats/docio/word-to-pdf#converting-word-to-pdf
https://www.syncfusion.com/blogs/post/converting-word-docs-to-pdfs.aspx

Regards,
Suriya Balamurugan.


If this post is helpful, please consider accepting it as the solution so that other members can locate it more quickly.


Loader.
Up arrow icon