What are the different layout options in ExceltoPDF conversion?
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 the scaling of the rows and columns 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 a PDF with one page for each worksheet.
// Intialize the ExcelToPdfconverterSettings ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings(); // Set the layout options settings.LayoutOptions = LayoutOptions.FitSheetOnOnePage;
NoScaling
When the NoScaling option is selected, the workbook will not use any scaling. Instead, it will convert the worksheet based on the actual size of the column width and row height for the entire workbook.
// Intialize the ExcelToPdfconverterSettings ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings(); // Set the layout options settings.LayoutOptions = LayoutOptions.NoScaling;
FitAllColumnsOnOnePage
The FitAllColumnsOnOnePage option is will make all the columns in a worksheet fit into a 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
The CustomScaling option uses the page setup zoom option during conversion, similar to how MS Excel shows the page setup dialog box to set the zoom level when custom scaling is selected.
// Intialize the ExcelToPdfconverterSettings ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings(); // Set the layout options settings.LayoutOptions = LayoutOptions.CustomScaling;
Automatic
The Automatic option will convert the workbook based on which layout option suits 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
- 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;
- Instantiate Excel to PDF converter with workbook.
// Open the Excel Document to Convert ExcelToPdfConverter converter = new ExcelToPdfConverter(book);
- 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);
- 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.
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
Take a moment to peruse the documentation where you can find basic Excel document processing options along with the features like import and export data, chart, formulas, conditional formatting, data validation, tables, pivot tables and protect the Excel documents, and most importantly, the PDF, CSV and Image conversions with code examples.
Conclusion
I hope you enjoyed learning about what are the different layout options in ExceltoPDF conversion.
You can refer to our XIsIO’s feature tour page to learn about its other groundbreaking features. Explore our UG documentation and online demos to understand how to manipulate data in Excel documents.
If you are an existing user, you can access our latest components from the License and Downloads page. For new users, you can try our 30-day free trial to check out XlsIO and other Syncfusion® components.
If you have any queries or require clarification, please let us know in the comments below or contact us through our support forums, Support Tickets, or feedback portal. We are always happy to assist you!