Codecs: How to convert PDF to DOCX?
In This Topic
VintaSoft Imaging .NET SDK allows to convert PDF document to a DOCX document using class
DocumentConverter,
ImageCollection or
PdfToDocxConverter. Usage of
DocumentConverter class provides the best performance because
DocumentConverter class uses multi-threading.
Here is C#/VB.NET code that shows how to convert PDF document to a DOCX document using
DocumentConverter class:
/// <summary>
/// Converts PDF file to a DOCX file using Vintasoft.Imaging.DocumentConverter class.
/// </summary>
public static void ConvertPdfToDocx_DocumentConverter(string pdfFileName, string docxFileName)
{
Vintasoft.Imaging.DocumentConverter.Convert(pdfFileName, docxFileName);
}
''' <summary>
''' Converts PDF file to a DOCX file using Vintasoft.Imaging.DocumentConverter class.
''' </summary>
Public Shared Sub ConvertPdfToDocx_DocumentConverter(pdfFileName As String, docxFileName As String)
Vintasoft.Imaging.DocumentConverter.Convert(pdfFileName, docxFileName)
End Sub
Here is C#/VB.NET code that shows how to convert PDF document to a DOCX document using
ImageCollection class:
/// <summary>
/// Converts PDF file to a DOCX file using Vintasoft.Imaging.ImageCollection class.
/// </summary>
public static void ConvertPdfToDocx_ImageCollection(string pdfFileName, string docxFileName)
{
// create image collection
using (Vintasoft.Imaging.ImageCollection imageCollection = new Vintasoft.Imaging.ImageCollection())
{
// add PDF document to collection
imageCollection.Add(pdfFileName);
// save images of image collection to a DOCX file
imageCollection.SaveSync(docxFileName);
// dispose images
imageCollection.ClearAndDisposeItems();
}
}
''' <summary>
''' Converts PDF file to a DOCX file using Vintasoft.Imaging.ImageCollection class.
''' </summary>
Public Shared Sub ConvertPdfToDocx_ImageCollection(pdfFileName As String, docxFileName As String)
' create image collection
Using imageCollection As New Vintasoft.Imaging.ImageCollection()
' add PDF document to collection
imageCollection.Add(pdfFileName)
' save images of image collection to a DOCX file
imageCollection.SaveSync(docxFileName)
' dispose images
imageCollection.ClearAndDisposeItems()
End Using
End Sub
Here is C#/VB.NET code that shows how to convert PDF document to a DOCX document using
PdfToDocxConverter class:
/// <summary>
/// Converts the PDF document to a DOCX document.
/// </summary>
/// <param name="inputPdfFilename">The name of input PDF file.</param>
/// <param name="outputDocxFilename">The name of output DOCX file.</param>
public static void ConvertPdfToDocx(string inputPdfFilename, string outputDocxFilename)
{
// create converter that allows to convert PDF to DOCX
using (Vintasoft.Imaging.Pdf.Office.PdfToDocxConverter converter = new Vintasoft.Imaging.Pdf.Office.PdfToDocxConverter())
{
// set output DOCX filename
converter.OutputFilename = outputDocxFilename;
// enable table detection
converter.DetectTables = true;
converter.TableDetectionCommand = new Vintasoft.Imaging.ImageProcessing.Info.TableDetection.TableWithBordersDetectionCommand();
// set rendering settings, which should be used for rendering graphics content on PDF page
converter.RenderingSettings = new Vintasoft.Imaging.Codecs.Decoders.RenderingSettings(new Vintasoft.Imaging.Resolution(96));
using (Vintasoft.Imaging.Processing.ProcessingState processingState = new Vintasoft.Imaging.Processing.ProcessingState(ProgressHandler))
{
// execute conversion from PDF to DOCX
converter.Execute(inputPdfFilename, processingState);
}
}
}
/// <summary>
/// Called when conversion progress is changing.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="Vintasoft.Imaging.ProgressEventArgs"/> instance containing the event data.</param>
private static void ProgressHandler(object sender, Vintasoft.Imaging.ProgressEventArgs e)
{
System.Console.WriteLine(string.Format("Conversion {0}%...", e.Progress));
}
''' <summary>
''' Converts the PDF document to a DOCX document.
''' </summary>
''' <param name="inputPdfFilename">The name of input PDF file.</param>
''' <param name="outputDocxFilename">The name of output DOCX file.</param>
Public Shared Sub ConvertPdfToDocx(inputPdfFilename As String, outputDocxFilename As String)
' create converter that allows to convert PDF to DOCX
Using converter As New Vintasoft.Imaging.Pdf.Office.PdfToDocxConverter()
' set output DOCX filename
converter.OutputFilename = outputDocxFilename
' enable table detection
converter.DetectTables = True
converter.TableDetectionCommand = New Vintasoft.Imaging.ImageProcessing.Info.TableDetection.TableWithBordersDetectionCommand()
' set rendering settings, which should be used for rendering graphics content on PDF page
converter.RenderingSettings = New Vintasoft.Imaging.Codecs.Decoders.RenderingSettings(New Vintasoft.Imaging.Resolution(96))
Using processingState As New Vintasoft.Imaging.Processing.ProcessingState(AddressOf ProgressHandler)
' execute conversion from PDF to DOCX
converter.Execute(inputPdfFilename, processingState)
End Using
End Using
End Sub
''' <summary>
''' Called when conversion progress is changing.
''' </summary>
''' <param name="sender">The sender.</param>
''' <param name="e">The <see cref="Vintasoft.Imaging.ProgressEventArgs"/> instance containing the event data.</param>
Private Shared Sub ProgressHandler(sender As Object, e As Vintasoft.Imaging.ProgressEventArgs)
System.Console.WriteLine(String.Format("Conversion {0}%...", e.Progress))
End Sub