XLS to PDF in C#, VB.NET

  • Demo
  • C# source
  • VB.Net source

The sample demonstrates how to convert Excel workbook to PDF file via Spire.XLS.

Get XLS-to-PDF.pdf.

static void Main()
{
    Spire.Xls.Workbook workbook = new Spire.Xls.Workbook();

    workbook.LoadFromFile(@"DataTableSample.xls");

    Spire.Xls.Converter.PdfConverter pdfConverter
        = new Spire.Xls.Converter.PdfConverter(workbook);
    Spire.Pdf.PdfDocument pdfDocument = new Spire.Pdf.PdfDocument();
    Spire.Xls.Converter.PdfConverterSettings settings
        = new Spire.Xls.Converter.PdfConverterSettings();
    settings.EmbedFonts = true;
    settings.TemplateDocument = pdfDocument;
    pdfDocument = pdfConverter.Convert(settings);

    pdfDocument.SaveToFile("XLS-to-PDF.pdf");
    pdfDocument.Close();
}

Shared Sub Main()
    Dim workbook As New Spire.Xls.Workbook()

    workbook.LoadFromFile("DataTableSample.xls")

    Dim pdfConverter As New Spire.Xls.Converter.PdfConverter(workbook)
    Dim pdfDocument As New Spire.Pdf.PdfDocument()
    Dim settings As New Spire.Xls.Converter.PdfConverterSettings()
    settings.EmbedFonts = True
    settings.TemplateDocument = pdfDocument
    pdfDocument = pdfConverter.Convert(settings)

    pdfDocument.SaveToFile("XLS-to-PDF.pdf")
    pdfDocument.Close()
End Sub