
PDF documents are widely used for sharing and presenting information, but sometimes you may need to edit or extract content from a PDF file. In such cases, converting a PDF to a Word document can be a handy solution. In this blog post, we’ll provide you with a powerful and flexible solution to easily convert PDF files to Word documents in C#.
- C# PDF to Word Converter
- Convert PDF to DOC in C#
- Convert PDF to DOCX in C#
- PDF to DOCX with Additional Settings
C# Library to Convert PDF to Word DOC
Aspose.PDF for .NET provides a powerful PDF to Word converter that lets you convert PDF files to DOC or DOCX in your .NET applications. You can either download the API or install it using the NuGet Package Manager in your project.
PM> Install-Package Aspose.PDF
Convert a PDF to Word DOC in C#
The following are the steps to convert PDF to Word DOC in C#.
- Load the PDF documents using the Document class.
- Save the document with .doc extension using Document.Save(string) method.
The following code sample shows how to convert PDF to Word DOC in C#.
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET | |
// 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 in C#
Converting PDF to DOCX is similar to PDF to DOC conversion as shown earlier. The API has the DocSaveOptions class that allows you to set the document format to DOCX. The following are the steps to convert PDF to DOCX:
- Load the PDF documents using the Document class.
- Set the output document format as DOCX using DocSaveOptions class.
- Save the document with .docx extension using Document.Save(string) method.
The following code sample shows how to save a PDF file to DOCX in C#.
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET | |
// 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); |
Customize PDF as Word Conversion in C#
Aspose.PDF for .NET provides various other options to customize the PDF to DOC or DOCX conversion. The DocSaveOptions class exposes the properties to improve or enhance the PDF to DOC conversions, such as image resolution, the distance between lines, etc.
The following code shows how to set additional properties when converting PDF to Word DOC in C#.
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET | |
// 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 using save options | |
// Create DocSaveOptions object | |
DocSaveOptions saveOptions = new DocSaveOptions(); | |
// Set the recognition mode as Flow | |
saveOptions.Mode = DocSaveOptions.RecognitionMode.Flow; | |
// Set the Horizontal proximity as 2.5 | |
saveOptions.RelativeHorizontalProximity = 2.5f; | |
// Enable the value to recognize bullets during conversion process | |
saveOptions.RecognizeBullets = true; | |
// Save the resultant DOC file | |
pdfDocument.Save(dataDir + "saveOptionsOutput_out.doc", saveOptions); |
Get Free PDF Library
You can get a free temporary license to convert PDF files to Word formats without evaluation limitations.
Explore C# PDF Library
If you want to know more about the powerful conversion features of Aspose.PDF for .NET then you can visit the documentation section, Conversion of PDF to other formats. 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.
Conclusion
Converting PDF to Word in C# using Aspose.PDF for .NET is a straightforward process that can be immensely useful when you need to work with PDF content in a more editable format. Aspose.PDF provides a powerful and reliable solution for this task. Feel free to explore more features of Aspose.PDF to further enhance your PDF manipulation capabilities in your C# applications.