Convert Excel file to PDF, Word file. PDF file will be created by component or overwritten if already exist

Namespace:  SautinSoft
Assembly:  SautinSoft.ExcelToPdf (in SautinSoft.ExcelToPdf.dll) Version: 4.2.7.24

Syntax

      
 C#  Visual Basic 
public void ConvertFile(
	string excelPath,
	string outPath
)
Public Sub ConvertFile ( _
	excelPath As String, _
	outPath As String _
)

Parameters

excelPath
String
Path to Excel file
outPath
String
Path to output document

Return Value

0 - converting succesfully
1 - can't open input Excel file, check the input path
2 - can't create output file, check the output path
3 - converting failed

Remarks

Examples

CopyHow to convert Excel file to PDF file in C#
using System;
using System.IO;
using SautinSoft;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            // Convert Excel file to PDF file
            ExcelToPdf x = new ExcelToPdf();

            // Set PDF as output format.
            x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf;

            string excelFile = Path.GetFullPath(@"D:\������\1\2.xlsx");
            string pdfFile = Path.ChangeExtension(excelFile, ".pdf");

            x.PageStyle.PageMarginBottom.mm(0);
            x.PageStyle.PageMarginRight.mm(0);
            x.PageStyle.PageMarginTop.mm(0);
            x.PageStyle.PageMarginLeft.mm(0);
            x.PageStyle.PageSize.A4();
            x.PageStyle.PageScale.Percent(300);

            try
            {
                x.ConvertFile(excelFile, pdfFile);
                System.Diagnostics.Process.Start(pdfFile);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }

        }
    }
}
CopyHow to convert Excel file to PDF file in VB.Net
Imports System
Imports System.IO
Imports SautinSoft

Module Sample

    Sub Main()
        ' Convert Excel file to PDF file
        Dim x As New ExcelToPdf()

        ' Set PDF as output format.
        x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf

        Dim excelFile As String = Path.GetFullPath("..\..\..\test.xls")
        Dim pdfFile As String = Path.ChangeExtension(excelFile, ".pdf")


        Try
            x.ConvertFile(excelFile, pdfFile)
            System.Diagnostics.Process.Start(pdfFile)
        Catch ex As Exception
            Console.WriteLine(ex.Message)
            Console.ReadLine()
        End Try

    End Sub
End Module

See Also