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


Это простое консольное приложение показывает, как преобразовать указанный диапазон страниц (от 2 до 4) из PDF в RTF документ.

Полный код

using System;
using System.IO;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            string inpFile = Path.GetFullPath(@"..\..\..\Potato Beetle.pdf");
            string outFile = "Result.rtf";
            
                                             // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/

			
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

            f.OpenPdf(inpFile);

            if (f.PageCount > 0)
            {
                // You may set an output format to docx or rtf.
                f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Rtf;

                // Specify to convert these pages: 2 - 4  and 6.

                // Way 1:
                f.RenderPagesString = "2-4, 6";

                // Way 2 (do the same as Way 1):
                f.RenderPages = new int[][] {new int[] {2, 4},
                                             new int[] {6, 6}};

                int result = f.ToWord(outFile);

                // Open the result.
                if (result == 0)
                {
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                }
            }
        }
    }
}

Download

Imports System.IO
Imports System.Drawing.Imaging
Imports System.Collections.Generic
Imports SautinSoft

Module Sample

    Sub Main()
		Dim inpFile As String = Path.GetFullPath("..\..\..\Potato Beetle.pdf")
		Dim outFile As String = "Result.rtf"
                                ' Get your free 30-day key here: 
                                ' https://sautinsoft.com/start-for-free/
		
		Dim f As New SautinSoft.PdfFocus()
		f.OpenPdf(inpFile)

		If f.PageCount > 0 Then
			' You may set an output format to docx or rtf.
			f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Rtf

			' Specify to convert these pages: 2 - 4  and 6.

			' Way 1:
			f.RenderPagesString = "2-4, 6"

			' Way 2 (do the same as Way 1):
			f.RenderPages = New Integer()() {
					New Integer() {2, 4},
					New Integer() {6, 6}
				}

			Dim result As Integer = f.ToWord(outFile)

			' Open the result.
			If result = 0 Then
				System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
			End If
		End If
	End Sub
End Module

Download


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



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

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