Convert PDF to All in .NET Core
на C# и .NET


How to use SautinSoft.PdfFocus to Converts PDF to DOCX, RTF, HTML, XML, Excel (XLS), PNG, Multipage TIFF, Text formats in .NET Core.

using System;
using System.IO;
using SautinSoft;
using System.DrawingCore.Imaging;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            ConvertPdfToAll();
        }
        /// <summary>
        /// Converts PDF to DOCX, RTF, HTML, XML, Excel (XLS), PNG, Text.
        /// </summary>
        public static void ConvertPdfToAll()
        {
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

            string pdfFile = @"..\..\..\simple text.pdf";
            string outFile = String.Empty;

            f.OpenPdf(pdfFile);
            if (f.PageCount > 0)
            {
                // To Docx.
                outFile = Path.ChangeExtension(pdfFile, ".docx");
                f.WordOptions.Format = PdfFocus.CWordOptions.eWordDocument.Docx;
                if (f.ToWord(outFile) == 0)
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });

                // To Rtf.
                outFile = Path.ChangeExtension(pdfFile, ".rtf");
                f.WordOptions.Format = PdfFocus.CWordOptions.eWordDocument.Rtf;
                if (f.ToWord(outFile) == 0)
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });

                // To Excel.
                outFile = Path.ChangeExtension(pdfFile, ".xls");
                f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true;
                if (f.ToExcel(outFile) == 0)
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });

                // To HTML.
                outFile = Path.ChangeExtension(pdfFile, ".html");
                f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true;
                if (f.ToHtml(outFile) == 0)
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });

                // To XML.
                outFile = Path.ChangeExtension(pdfFile, ".xml");
                f.XmlOptions.ConvertNonTabularDataToSpreadsheet = true;
                if (f.ToXml(outFile) == 0)
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });

                // To Image.
                outFile = Path.ChangeExtension(pdfFile, ".png");
                f.ImageOptions.Dpi = 300;
                f.ImageOptions.ImageFormat = ImageFormat.Png;
                if (f.ToImage(outFile, 1) == 0)
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });                       

                // To Text.
                outFile = Path.ChangeExtension(pdfFile, ".txt");
                if (f.ToText(outFile) == 0)
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
            }
            else
            {
                Console.WriteLine("Error: {0}!", f.Exception.Message);
                Console.ReadLine();
            }
        }
    }
}

Скачать

        
            Imports System.IO
Imports SautinSoft
Imports System.DrawingCore.Imaging

Module Sample
    Sub Main()
        ConvertPdfToAll()
    End Sub
    ''' <summary>
    ''' Converts PDF to DOCX, RTF, HTML, XML, Excel (XLS), PNG, Text.
    ''' </summary>
    Public Sub ConvertPdfToAll()
        Dim f As New SautinSoft.PdfFocus()

        Dim pdfFile As String = "..\..\..\simple text.pdf"
        Dim outFile As String = String.Empty

        f.OpenPdf(pdfFile)
        If f.PageCount > 0 Then
            ' To Docx.
            outFile = Path.ChangeExtension(pdfFile, ".docx")
            f.WordOptions.Format = PdfFocus.CWordOptions.eWordDocument.Docx
            If f.ToWord(outFile) = 0 Then
                System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
            End If

            ' To Rtf.
            outFile = Path.ChangeExtension(pdfFile, ".rtf")
            f.WordOptions.Format = PdfFocus.CWordOptions.eWordDocument.Rtf
            If f.ToWord(outFile) = 0 Then
                System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
            End If

            ' To Excel.
            outFile = Path.ChangeExtension(pdfFile, ".xls")
            f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = True
            If f.ToExcel(outFile) = 0 Then
                System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
            End If

            ' To HTML.
            outFile = Path.ChangeExtension(pdfFile, ".html")
            f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = True
            If f.ToHtml(outFile) = 0 Then
                System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
            End If

            ' To XML.
            outFile = Path.ChangeExtension(pdfFile, ".xml")
            f.XmlOptions.ConvertNonTabularDataToSpreadsheet = True
            If f.ToXml(outFile) = 0 Then
                System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
            End If

            ' To Image.
            outFile = Path.ChangeExtension(pdfFile, ".png")
            f.ImageOptions.Dpi = 300
            f.ImageOptions.ImageFormat = ImageFormat.Png
            If f.ToImage(outFile, 1) = 0 Then
                System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
            End If

            ' To Text.
            outFile = Path.ChangeExtension(pdfFile, ".txt")
            If f.ToText(outFile) = 0 Then
                System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
            End If
        Else
            Console.WriteLine("Error: {0}!", f.Exception.Message)
            Console.ReadLine()
        End If
    End Sub
End Module

Скачать


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу support@sautinsoft.com или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



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

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