PdfFocusToWord(Int32, Int32) Method |
Saves a specific PDF page or diapason of pages to a Word (Docx or RTF) document and returns it as array of bytes.
Namespace: SautinSoftAssembly: SautinSoft.PdfFocus (in SautinSoft.PdfFocus.dll) Version: 2025.4.23
Syntaxpublic byte[] ToWord(
int fromPage,
int toPage
)
Public Function ToWord (
fromPage As Integer,
toPage As Integer
) As Byte()
Parameters
- fromPage Int32
- The starting page for exporting to Word
- toPage Int32
- The ending page for exporting to Word
Return Value
Byte
Array of bytes with Word document - in case of converting successful.
null - in case of converting failed. Please email this PDF document at
support@sautinsoft.com.
ExampleHow to convert each PDF page to separate Docx documents in C#
using System;
using System.IO;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
string pdfPath = Path.GetFullPath(@"..\..\..\simple text.pdf");
string docxDir = Directory.GetCurrentDirectory();
SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
f.OpenPdf(pdfPath);
for (int page = 1; page <= f.PageCount; page++)
{
f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx;
byte [] docxBytes = f.ToWord(page, page);
string tempName = Path.GetFileNameWithoutExtension(pdfPath) + String.Format(" - page {0}.docx", page);
string docxPath = Path.Combine(docxDir, tempName);
File.WriteAllBytes(docxPath, docxBytes);
if (page == 1 || page==f.PageCount)
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(docxPath) { UseShellExecute = true });
}
}
}
}
How to convert each PDF page to separate Docx documents in VB.Net
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Collections.Generic
Imports SautinSoft
Module Sample
Sub Main()
Dim pdfPath As String = Path.GetFullPath("..\..\..\simple text.pdf")
Dim docxDir As String = Directory.GetCurrentDirectory()
Dim f As New SautinSoft.PdfFocus()
f.OpenPdf(pdfPath)
For page As Integer = 1 To f.PageCount
f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx
Dim docxBytes() As Byte = f.ToWord(page, page)
Dim tempName As String = Path.GetFileNameWithoutExtension(pdfPath) & String.Format(" - page {0}.docx", page)
Dim docxPath As String = Path.Combine(docxDir, tempName)
File.WriteAllBytes(docxPath, docxBytes)
If page = 1 OrElse page = f.PageCount Then
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(docxPath) With {.UseShellExecute = True})
End If
Next page
End Sub
End Module
See Also