Saves a specific PDF page or diapason of pages to a Word (Docx or RTF) document as a Stream object.

Namespace:  SautinSoft
Assembly:  SautinSoft.PdfFocus (in SautinSoft.PdfFocus.dll) Version: 6.6.9.7 (6.6.9.7)

Syntax

      
 C#  Visual Basic 
public int ToWord(
	Stream stream,
	int fromPage,
	int toPage
)
Public Function ToWord ( _
	stream As Stream, _
	fromPage As Integer, _
	toPage As Integer _
) As Integer

Parameters

stream
Stream
Stream object to save a Word document. Stream must be not null.
fromPage
Int32
The starting page for exporting to Word
toPage
Int32
The ending page for exporting to Word

Return Value

0 - saving successfully.
2 - problem with parsing of PDF document. Please email this PDF document at support@sautinsoft.com.
3 - problem with rendering of Word (Docx or RTF) document. Please email this PDF document at support@sautinsoft.com.

Examples

CopyHow to convert PDF to Word in memory using C#
using System;
using System.IO;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            ConvertPdfToDocxBytes();
            //ConvertPdfToRtfStream();
        }

        private static void ConvertPdfToDocxBytes()
        {
            string pdfFile = @"..\..\..\..\..\simple text.pdf";

            // Assume that we already have a PDF document as array of bytes.
            byte[] pdf = File.ReadAllBytes(pdfFile);
            byte[] docx = null;

            // Convert PDF to word in memory
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            //this property is necessary only for registered version
            //f.Serial = "XXXXXXXXXXX";

            f.OpenPdf(pdf);

            if (f.PageCount > 0)
            {
                // Convert pdf to word in memory.
                docx = f.ToWord();

                // Save word document to a file only for demonstration purposes.
                if (docx != null)
                {
                    //3. Save to DOCX document to a file for demonstration purposes.
                    string wordFile = Path.ChangeExtension(pdfFile, ".docx");
                    File.WriteAllBytes(wordFile, docx);
                    System.Diagnostics.Process.Start(wordFile);
                }
            }
        }
        private static void ConvertPdfToRtfStream()
        {
            string pdfFile = @"..\..\..\..\..\simple text.pdf";
            MemoryStream rtfStream = new MemoryStream();
            // Convert PDF to word in memory
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            //this property is necessary only for registered version
            //f.Serial = "XXXXXXXXXXX";


            // Assume that we already have a PDF document as stream.
            using (FileStream pdfStream = new FileStream(pdfFile, FileMode.Open, FileAccess.Read))
            {
                f.OpenPdf(pdfStream);

                if (f.PageCount > 0)
                {
                    f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Rtf;
                    int res = f.ToWord(rtfStream);

                    // Save rtfStream to a file for demonstration purposes.
                    if (res == 0)
                    {
                        string rtfFile = Path.ChangeExtension(pdfFile, ".rtf");
                        File.WriteAllBytes(rtfFile, rtfStream.ToArray());
                        System.Diagnostics.Process.Start(rtfFile);
                    }
                }
            }

        }
    }
}
CopyHow to convert PDF to Word in memory using VB.Net
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Collections.Generic
Imports SautinSoft

Module Sample

    Sub Main()
        ConvertPdfToDocxBytes()
        'ConvertPdfToRtfStream()
    End Sub
    Private Sub ConvertPdfToDocxBytes()
        Dim pdfFile As String = "..\..\..\..\simple text.pdf"

        ' Assume that we already have a PDF document as array of bytes.
        Dim pdf() As Byte = File.ReadAllBytes(pdfFile)
        Dim docx() As Byte = Nothing

        ' Convert PDF to word in memory
        Dim f As New SautinSoft.PdfFocus()
        'this property is necessary only for registered version
        'f.Serial = "XXXXXXXXXXX";


        f.OpenPdf(pdf)

        If f.PageCount > 0 Then
            ' Convert pdf to word in memory.
            docx = f.ToWord()

            ' Save word document to a file only for demonstration purposes.
            If docx IsNot Nothing Then
                '3. Save to DOCX document to a file for demonstration purposes.
                Dim wordFile As String = Path.ChangeExtension(pdfFile, ".docx")
                File.WriteAllBytes(wordFile, docx)
                System.Diagnostics.Process.Start(wordFile)
            End If
        End If
    End Sub
    Private Sub ConvertPdfToRtfStream()
        Dim pdfFile As String = "..\..\..\..\simple text.pdf"
        Dim rtfStream As New MemoryStream()
        ' Convert PDF to word in memory
        Dim f As New SautinSoft.PdfFocus()
        'this property is necessary only for registered version
        'f.Serial = "XXXXXXXXXXX";



        ' Assume that we already have a PDF document as stream.
        Using pdfStream As New FileStream(pdfFile, FileMode.Open, FileAccess.Read)
            f.OpenPdf(pdfStream)

            If f.PageCount > 0 Then
                f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Rtf
                Dim res As Integer = f.ToWord(rtfStream)

                ' Save rtfStream to a file for demonstration purposes.
                If res = 0 Then
                    Dim rtfFile As String = Path.ChangeExtension(pdfFile, ".rtf")
                    File.WriteAllBytes(rtfFile, rtfStream.ToArray())
                    System.Diagnostics.Process.Start(rtfFile)
                End If
            End If
        End Using

    End Sub

End Module

See Also