Convert PDF to Word (DOC, DOCX) in C#

Share on FacebookTweet about this on TwitterShare on LinkedIn
aspose-pdf-for-net

My previous article, Convert PDF to HTML in C#, showed how to convert a PDF file to HTML in your .NET applications using Aspose.PDF for .NET API. Today, I am going to demonstrate another interesting feature of the API to convert PDF files to Word documents i.e. DOC and DOCX. Earlier versions of Microsoft Word saved documents in binary format with .doc extension. With the release of Office 2007, Microsoft adopted the Office Open XML (OOXML) that is based on a combination of XML and binary files combined together as ZIP archives. Word now uses .docx as the default extension for saving documents.

Convert PDF to Word DOC

Aspose.PDF for .NET lets you read and convert PDF files to Word documents in your .NET applications with simple lines of code. The API can be used in both .NET WinForms and ASP.NET application using C# and other .NET programming languages.

// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();          
            
// Open the source PDF document
Document pdfDocument = new Document(dataDir + "PDFToDOC.pdf");

// Save the file into MS document format
pdfDocument.Save(dataDir + "PDFToDOC_out.doc", SaveFormat.Doc);

Convert PDF to DOCX

Converting PDF to DOCX is similar to conversion to DOC file format as shown earlier. The API has DocSaveOptions class that allows you to set other options in addition to setting the document format to DocX.

// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();

// Open the source PDF document
Document pdfDocument = new Document(dataDir + "PDFToDOC.pdf");

// Instantiate DocSaveOptions object
DocSaveOptions saveOptions = new DocSaveOptions();
// Specify the output format as DOCX
saveOptions.Format = DocSaveOptions.DocFormat.DocX;
// Save document in docx format
pdfDocument.Save("ConvertToDOCX_out.docx", saveOptions);

Want to know more about the powerful conversion features of Aspose.PDF for .NET? You can head-on to the API documentation section, Conversion of PDF to other formats, to know about a variety of conversion features that the API supports. Download your free copy of Aspose.PDF for .NET and you can get started in no time by following the API documentation. If you have any queries, feel free to post to Aspose.PDF forum. We’ll be glad to assist you with your queries and inquiries.