Convert Excel bytes array to PDF, Word, RTF bytes array

Namespace:  SautinSoft
Assembly:  SautinSoft.XlsToPdf (in SautinSoft.XlsToPdf.dll) Version: 2.0.4.13

Syntax

      
 C#  Visual Basic 
public int ConvertBytes(
	byte[] xlsByte,
	ref byte[] outBytes
)
Public Function ConvertBytes ( _
	xlsByte As Byte(), _
	ByRef outBytes As Byte() _
) As Integer

Parameters

xlsByte
array< Byte >[]()[]
Array of bytes containing Excel document
outBytes
array< Byte >[]()[] %
Bytes array where output document will be saved after converting. You don't have to allocate memory for this array

Return Value

0 - converting succesfully
3 - converting failed

Examples

CopyHow to convert Excel bytes array to PDF bytes array in C#
using System;
using System.IO;

namespace SampleConvert
{
    class Class1
    {
        static void Main(string[] args)
        {
            SautinSoft.XlsToPdf xtp = new SautinSoft.XlsToPdf();
            //this property is necessary only for registered version
            //xtp.Serial = "XXXXXXXXXXXXX";

            //specify some options
            xtp.PageStyle.PageOrientation.Landscape();
            //specify password for Excel workbook
            xtp.Password = "12345";
            //specify page numbers
            xtp.PageStyle.PageNumFormat = "Page {page} of {numpages}";

            string xlsFile = @"..\..\..\..\..\test.xls";
            string pdfFile = @"..\..\..\..\..\test.pdf";
            byte[] xlsBytes = null;
            byte[] pdfBytes = null;
            ReadFromFile(xlsFile,ref xlsBytes);
            int result = xtp.ConvertBytes(xlsBytes,ref pdfBytes);
            if (result == 0)
            {
                System.Console.WriteLine("Converted successfully!");
                WriteToFile(pdfFile,pdfBytes);
                System.Diagnostics.Process.Start(pdfFile);
            }
            else
                System.Console.WriteLine("Converting Error!");
        }

        public static int ReadFromFile(string fileName, ref byte[] arByte)
        {
            try
            {
                FileStream fi = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                arByte = new byte[fi.Length];
                fi.Read(arByte, 0, (int)fi.Length);
                fi.Close();
            }
            catch
            {
                return 1;
            }
            return 0;
        }
        public static int WriteToFile(string fileName, byte[] arByte)
        {
            try
            {
                if (arByte == null)
                    return 1;
                File.Delete(fileName);
                FileStream pdfFile = File.OpenWrite(fileName);
                pdfFile.Write(arByte, 0, arByte.Length);
                pdfFile.Close();
            }
            catch
            {
                return 2;
            }
            return 0;
        }
    }
}
CopyHow to convert Excel bytes array to PDF bytes array in VB.Net
Imports System.IO
Module Module1

    Sub Main()
        Dim xtp As New SautinSoft.XlsToPdf
        'this property is necessary only for registered version
        'xtp.Serial = "XXXXXXXXXXXXX";


        'specify some options
        xtp.PageStyle.PageOrientation.Landscape()
        'specify password for Excel workbook
        xtp.Password = "12345"
        'specify page numbers
        xtp.PageStyle.PageNumFormat = "Page {page} of {numpages}"

        Dim xlsFile As String = "..\..\..\..\test.xls"
        Dim pdfFile As String = "..\..\..\..\test.pdf"
        Dim xlsBytes() As Byte = Nothing
        Dim pdfBytes() As Byte = Nothing
        ReadFromFile(xlsFile, xlsBytes)
        Dim result As Integer = xtp.ConvertBytes(xlsBytes, pdfBytes)
        If result = 0 Then
            System.Console.WriteLine("Converted successfully!")
            WriteToFile(pdfFile, pdfBytes)
            System.Diagnostics.Process.Start(pdfFile)
        Else
            System.Console.WriteLine("Converting Error!")
        End If
    End Sub
    Public Function ReadFromFile(ByVal fileName As String, ByRef arByte() As Byte) As Integer
        Try
            Dim fi As New FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)
            arByte = New Byte(fi.Length - 1) {}
            fi.Read(arByte, 0, CInt(Fix(fi.Length)))
            fi.Close()
        Catch e As Exception
            Return 1
        End Try
        Return 0
    End Function
    Public Function WriteToFile(ByVal fileName As String, ByVal arByte() As Byte) As Integer
        Try
            If arByte Is Nothing Then
                Return 1
            End If
            File.Delete(fileName)
            Dim pdfFile As FileStream = File.OpenWrite(fileName)
            pdfFile.Write(arByte, 0, arByte.Length)
            pdfFile.Close()
        Catch
            Return 2
        End Try
        Return 0
    End Function


End Module

See Also