Saves all pages of the PDF document into a Word (Docx or RTF) document and returns it as array of bytes

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

Syntax

      
 C#  Visual Basic 
public byte[] ToWord()
Public Function ToWord As Byte()

Return Value

Array of bytes with a Word (Docx or RTF) document document - in case of converting successful.
null - in case of converting failed. Please email this PDF document at support@sautinsoft.com.

Examples

CopyASP.Net - Export PDF to Word using C#
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Result.Text = "";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.PostedFile.FileName.Length == 0 || FileUpload1.FileBytes.Length == 0)
        {
            Result.Text = "Please select PDF file at first!";
            return;
        }
        byte[] rtf = null;

        SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
        //this property is necessary only for registered version
        //f.Serial = "XXXXXXXXXXX";
        f.OpenPdf(FileUpload1.FileBytes);

        if (f.PageCount > 0)
        {
            //Let's whole PDF document to Word (RTF)
            f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Rtf;

            // You may also set an output format to Docx.
            //f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx;
            rtf = f.ToWord();
        }

        //show Word/rtf
        if (rtf != null)
        {
            ShowResult(rtf, "Result.rtf", "application/msword");
        }
        else
        {
            Result.Text = "Converting failed!";
        }
    }
    private void ShowResult(byte[] data, string fileName, string contentType)
    {
        Response.Buffer = true;
        Response.Clear();
        Response.ContentType = contentType;
        Response.AddHeader("content-disposition", "inline; filename=\"" + fileName + "\"");
        Response.BinaryWrite(data);
        Response.Flush();
        Response.End();
    }
}
CopyASP.Net - Export PDF to Word using VB.Net
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO

Partial Public Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Result.Text = ""
    End Sub
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        If FileUpload1.PostedFile.FileName.Length = 0 OrElse FileUpload1.FileBytes.Length = 0 Then
            Result.Text = "Please select PDF file at first!"
            Return
        End If

        Dim rtf() As Byte = Nothing

        Dim f As New SautinSoft.PdfFocus()
        'this property is necessary only for registered version
        'f.Serial = "XXXXXXXXXXX";
        f.OpenPdf(FileUpload1.FileBytes)

        If f.PageCount > 0 Then
            'Let's whole PDF document to Word (RTF)
            f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Rtf

            ' You may also set an output format to Docx.
            'f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx;
            rtf = f.ToWord()
        End If

        'show Word/rtf
        If rtf IsNot Nothing Then
            ShowResult(rtf, "Result.rtf", "application/msword")
        Else
            Result.Text = "Converting failed!"
        End If

    End Sub
    Private Sub ShowResult(ByVal data() As Byte, ByVal fileName As String, ByVal contentType As String)
        Response.Buffer = True
        Response.Clear()
        Response.ContentType = contentType
        Response.AddHeader("content-disposition", "inline; filename=""" & fileName & """")
        Response.BinaryWrite(data)
        Response.Flush()
        Response.End()
    End Sub
End Class

See Also