Articles in this section
Category / Section

What are the different layout options in ExceltoPDF conversion?

3 mins read

This article explains about the different layout options available in Excel to PDF conversion in XlsIO using C#/VB.NET.

What is layout?

In Excel to PDF conversion, layout defines scaling of the row and column of the worksheet. The following are the layout options in Excel to PDF conversion in XlsIO.

  • FitSheetOnOnePage
  • NoScaling
  • FitAllColumnsOnOnePage
  • FitAllRowsOnOnePage
  • CustomScaling
  • Automatic

By default, the layout option is Automatic.

FitSheetOnOnePage

When the FitSheetOnOnePage option is selected, the workbook will be converted into pdf with one page for each worksheet.

//Intialize the ExcelToPdfconverterSettings
ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings();
//Set the layout options
settings.LayoutOptions = LayoutOptions.FitSheetOnOnePage;

 

NoScaling

When NoScaling option is selected, the workbook will not use any scaling. Instead it will convert the worksheet based actual size of the column width and row height for entire workbook.

//Intialize the ExcelToPdfconverterSettings
ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings();
//Set the layout options
settings.LayoutOptions = LayoutOptions.NoScaling;

 

FitAllColumnsOnOnePage

FitAllColumnsOnOnePage option is will make all the columns in a worksheet fit into single page.

//Intialize the ExcelToPdfconverterSettings
ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings();
//Set the layout options
settings.LayoutOptions = LayoutOptions.FitAllColumnsOnOnePage;

 

FitAllRowsOnOnePage

All the rows in the worksheet will fit into single page when the FitAllRowsOnOnePage option is selected.

//Intialize the ExcelToPdfconverterSettings
ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings();
//Set the layout options
settings.LayoutOptions = LayoutOptions.FitAllRowsOnOnePage;

 

CustomScaling

CustomScaling option uses the page setup zoom option while conversion like MS-Excel shows the page setup dialog box to set the zoom level when the custom scaling is selected.

//Intialize the ExcelToPdfconverterSettings
ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings();
//Set the layout options
settings.LayoutOptions = LayoutOptions.CustomScaling;

 

Automatic

Automatic option will convert the workbook based on which layout option will suit for every worksheet in a workbook. The default value is NoScaling.

//Intialize the ExcelToPdfconverterSettings
ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings();
//Set the layout options
settings.LayoutOptions = LayoutOptions.Automatic;

 

Steps to use layout options in Excel to PDF conversion

  1. Initialize Excel to pdf converted setting and set the layout options.
    //Intialize the ExcelToPdfconverterSettings
    ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings();
    //Set the layout options
    settings.LayoutOptions = LayoutOptions.FitAllRowsOnOnePage;
    

 

  1. Instantiate Excel to PDF converter with workbook.
    //Open the Excel Document to Convert
    ExcelToPdfConverter converter = new ExcelToPdfConverter(book);
    

 

  1. Convert the workbook to PDF with the specified settings.
    //Intialize the PDFDocument
    PdfDocument pdfDoc = new PdfDocument();  
    //Convert Excel Document into PDF document
    pdfDoc = converter.Convert(settings);
    

 

  1. Save the PDF file.
    //Save the pdf file
    pdfDoc.Save("ExceltoPDF.pdf");
    

 

 To know more about Excel to PDF conversion in XlsIO, please refer the documentation.

Download Input file

Download Complete sample

The following C#/VB.NET complete code snippet shows how to use layout options in Excel to PDF conversion in XlsIO.

using Syncfusion.ExcelChartToImageConverter;
using Syncfusion.ExcelToPdfConverter;
using Syncfusion.Pdf;
using Syncfusion.XlsIO;
using Syncfusion.XlsIO.Implementation;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Reflection;
 
namespace XlsIO_Sample
{
    class Program
    {
        public static void Main(string[] args)
        {
            //Instantiate the spreadsheet creation engine
            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                IApplication application = excelEngine.Excel;
 
                //Instantiating the ChartToImageConverter
                application.ChartToImageConverter = new ChartToImageConverter();
 
                //Tuning Chart Image Quality
                application.ChartToImageConverter.ScalingMode = ScalingMode.Best;
 
                //Opening existing workbook
                Assembly assembly = typeof(Program).GetTypeInfo().Assembly;
                Stream workbookStream = assembly.GetManifestResourceStream("XlsIOSample.Sample.xlsx");
 
                IWorkbook workbook = application.Workbooks.Open(workbookStream);
                IWorksheet worksheet = workbook.Worksheets[0];
 
                //Excel to PDF converter settings
                ExcelToPdfConverterSettings setting = new ExcelToPdfConverterSettings();
                setting.LayoutOptions = LayoutOptions.Automatic;
 
                //Instantiate converter with the workbook
                ExcelToPdfConverter converter = new ExcelToPdfConverter(workbook);
 
                //Convert the workbook with conversion setting
                PdfDocument pdf = converter.Convert(setting);
                
                //Save and close the pdf
                Stream stream = File.Create("Output.pdf");
                pdf.Save(stream);
            }
        }
    }
}
 

 

Imports Syncfusion.ExcelChartToImageConverter
Imports Syncfusion.ExcelToPdfConverter
Imports Syncfusion.Pdf
Imports Syncfusion.XlsIO
Imports System.IO
Imports System.Reflection
 
Namespace XlsIO_Sample
 
    Class Program
 
        Public Shared Sub Main(ByVal args As String())
 
            'Instantiate spreadsheet creation engine
            Using excelEngine As ExcelEngine = New ExcelEngine()
 
                Dim application As IApplication = excelEngine.Excel
 
                'Instantiating the ChartToImageConverter
                application.ChartToImageConverter = New ChartToImageConverter()
 
                'Tuning Chart Image Quality
                application.ChartToImageConverter.ScalingMode = ScalingMode.Best
 
                'Opening existing workbook
                Dim assembly As Assembly = GetType(Program).GetTypeInfo().Assembly
                Dim workbookStream As Stream = assembly.GetManifestResourceStream("XlsIOSample.Sample.xlsx")
 
                Dim workbook As IWorkbook = application.Workbooks.Open(workbookStream)
                Dim worksheet As IWorksheet = workbook.Worksheets(0)
 
                'Excel to PDF converter settings
                Dim setting As ExcelToPdfConverterSettings = New ExcelToPdfConverterSettings()
                'Set the layout options
                setting.LayoutOptions = LayoutOptions.Automatic
 
                'Instantiate converter with the workbook
                Dim converter As ExcelToPdfConverter = New ExcelToPdfConverter(workbook)
 
                'Convert the workbook with conversion setting
                Dim pdf As PdfDocument = converter.Convert(setting)
 
                'Save and close the PDF
                Dim stream As Stream = File.Create("Output.pdf")
                pdf.Save(stream)
            End Using
        End Sub
    End Class
End Namespace

 

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied