DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Sheraz has posted 65 posts at DZone. View Full User Profile

PDF to MS Word DOC or DOCX Conversion in .NET Applications

06.14.2013
| 4255 views |
  • submit to reddit
//Converting PDF to DOC

//[C#]
 
// Path of input PDF document
String filePath = @"d:\\Source.pdf";
// Instantiate the Document object
Aspose.Pdf.Document document = new Aspose.Pdf.Document(filePath);
// 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
document.Save(@"d:\\Resultant.doc", saveOptions);

//[VB.NET]

' Path of input PDF document
Dim filePath As String = "d:\\Source.pdf"
' Instantiate the Document object
Dim document As Aspose.Pdf.Document = New Aspose.Pdf.Document(filePath)
' Create DocSaveOptions object
Dim saveOptions As DocSaveOptions = 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 resultnat DOC file
document.Save("d:\\Resultant.doc", saveOptions)
 
//Converting PDF to Docx format

//[C#]

//open pdf document
Document pdfDocument = new Document("source.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("output.docx", saveOptions);
 
//[VB.NET]

'open pdf document
Dim pdfDocument As Document = New Document("source.pdf")
' instantiate DocSaveOptions object
Dim saveOptions As DocSaveOptions = New DocSaveOptions()
' specify the output format as DOCX
saveOptions.Format = DocSaveOptions.DocFormat.DocX
' save document in docx format
pdfDocument.Save("output.docx", saveOptions)
This technical tip shows how to convert PDF file to DOC or DOCX format. Aspose.Pdf for .NET is flexible and supports a wide variety of conversions. Converting pages from PDF documents to images, for example, is a very popular feature.  A conversion that many of our customers have requested is PDF to DOC: converting a PDF file to a Microsoft Word document. Customers want this because PDF files cannot easily be edited, whereas Word documents can. Some companies want their users to be able to manipulate text, tables and images in files that started as PDFs. Keeping alive the tradition of making things simple and understandable, Aspose.Pdf for .NET provides few lines code to transform source PDF file into a DOC file.  The DocSaveOptions class provides numerous properties that improve the process of converting PDF files to DOC format. Among these properties, Mode enables you to specify the recognition mode for PDF content. You can specify any value from the RecognitionMode enumeration for this property.