Как преобразовать PDF файл в DOCX файл на C# и .NET

Полный код

using System;
using System.IO;
using System.Collections;
using SautinSoft;

namespace Sample
{
    class Test
    {
        static void Main(string[] args)
        {
            // Convert PDF file to DOCX file. Works only in Office 2013 and higher.

            // If you are looking for solution without MS Office
            // Please take a look at our PDF Focus .Net: https://www.sautinsoft.com/products/pdf-focus/index.php

            SautinSoft.UseOffice u = new SautinSoft.UseOffice();

            string inpFile = Path.GetFullPath(@"..\..\..\..\..\Testing files\example.pdf");
            string outFile = Path.GetFullPath("Result.docx");

            // Prepare UseOffice .Net, loads MS Word in memory
            if (u.InitWord() != 0)
            {
                Console.WriteLine("Error: Can't load MS Word in memory!");
                Console.WriteLine("Please contact SautinSoft's support Team: [email protected].");
                Console.ReadLine();
            }

            // Check MS Office version
            if (u.OfficeVersion >= UseOffice.eOfficeVersion.Office2013)
            {
                // Converting ...
                int result = u.ConvertFile(inpFile, outFile, UseOffice.eDirection.PDF_to_DOCX);

                if (result == 0)
                {
                    Console.WriteLine("Converting successfully!");
                    // Open the result.
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });

                }
                else
                    Console.WriteLine("Error! Please contact with SautinSoft support: [email protected].");
            }
            else
            {
                Console.WriteLine("To convert PDF documents, please install MS Office 2013 or higher.");                
            }
            u.CloseOffice();
        }
    }
}

Download

Imports System
Imports System.IO
Imports System.Collections
Imports SautinSoft

Namespace Sample
    Friend Class Test
        Shared Sub Main(ByVal args() As String)
            ' Convert PDF file to DOCX file. Works only in Office 2013 and higher.

            ' If you are looking for solution without MS Office
            ' Please take a look at our PDF Focus .Net: https://www.sautinsoft.com/products/pdf-focus/index.php

            Dim u As New SautinSoft.UseOffice()

            Dim inpFile As String = Path.GetFullPath("..\..\..\..\Testing files\example.pdf")
            Dim outFile As String = Path.GetFullPath("Result.docx")

            ' Prepare UseOffice .Net, loads MS Word in memory
            If u.InitWord() <> 0 Then
                Console.WriteLine("Error: Can't load MS Word in memory!")
                Console.WriteLine("Please contact SautinSoft's support Team: [email protected].")
                Console.ReadLine()
            End If

            ' Check MS Office version
            If u.OfficeVersion >= UseOffice.eOfficeVersion.Office2013 Then
                ' Converting ...
                Dim result As Integer = u.ConvertFile(inpFile, outFile, UseOffice.eDirection.PDF_to_DOCX)

                If result = 0 Then
                    Console.WriteLine("Converting successfully!")
                    ' Open the result.
                    System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})

                Else
                    Console.WriteLine("Error! Please contact with SautinSoft support: [email protected].")
                End If
            Else
                Console.WriteLine("To convert PDF documents, please install MS Office 2013 or higher.")
            End If
            u.CloseOffice()
        End Sub
    End Class
End Namespace

Download


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу [email protected] или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.