Category / Section
How to adjust zoom ratio in Excel to PDF conversion?
1 min read
This article explains how to adjust zoom ratio in Excel to PDF conversion using XlsIO.
What is Zoom Ratio?
Zoom value gets or sets the percentage (between 10 and 400) by which Microsoft Excel will scale the worksheet for printing. This property applies only to worksheets.
To know more about other page settings in XlsIO, please refer documentation.
Code snippet to adjust the zoom ratio in Excel to PDF conversion
//Set zoom value worksheet.PageSetup.Zoom = 50;
Note: To adjust zoom ratio for a PDF document, firstly the zoom value is set to worksheet and then converted into PDF.
The following C#/VB complete code snippet shows how to adjust zoom ratio in Excel to PDF conversion using XlsIO.
C#
using Syncfusion.XlsIO; using System.IO; using System.Reflection; using Syncfusion.ExcelToPdfConverter; using Syncfusion.Pdf; namespace Zoom_Ratio { class Program { static void Main(string[] args) { using (ExcelEngine excelEngine = new ExcelEngine()) { //Instantiate the excel application object IApplication application = excelEngine.Excel; //The workbook is opened IWorkbook workbook; //Open existing workbook with data entered Assembly assembly = typeof(Program).GetTypeInfo().Assembly; Stream fileStream = assembly.GetManifestResourceStream("Zoom_Ratio.Sample.xlsx"); workbook = application.Workbooks.Open(fileStream, ExcelOpenType.Automatic); //The first worksheet object in the worksheets collection is accessed IWorksheet worksheet = workbook.Worksheets[0]; //Set zoom value worksheet.PageSetup.Zoom = 50; //Create an ExcelToPDFConverter instance ExcelToPdfConverter converter = new ExcelToPdfConverter(worksheet); //Initialize PDF Document PdfDocument pdfDocument = new PdfDocument(); //Initialize converter settings ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings(); //Convert Excel document into PDF document with the specified settings pdfDocument = converter.Convert(settings); //Save the PDF document Stream stream = File.Create("Output.pdf"); pdfDocument.Save(stream); } } } }
VB
Imports Syncfusion.XlsIO Imports System.IO Imports System.Reflection Imports Syncfusion.ExcelToPdfConverter Imports Syncfusion.Pdf Namespace Zoom_Ratio Class Program Private Shared Sub Main(ByVal args() As String) Using excelEngine As ExcelEngine = New ExcelEngine() 'Instantiate the excel application object Dim application As IApplication = excelEngine.Excel 'The workbook is opened Dim workbook As IWorkbook 'Open existing workbook with data entered Dim assembly As Assembly = GetType(Program).GetTypeInfo.Assembly Dim fileStream As Stream = assembly.GetManifestResourceStream("Zoom_Ratio.Sample.xlsx") workbook = application.Workbooks.Open(fileStream, ExcelOpenType.Automatic) 'The first worksheet object in the worksheets collection is accessed Dim worksheet As IWorksheet = workbook.Worksheets(0) 'Set zoom value worksheet.PageSetup.Zoom = 50 'Create an ExcelToPDFConverter instance Dim converter As ExcelToPdfConverter = New ExcelToPdfConverter(worksheet) 'Initialize PDF Document Dim pdfDocument As PdfDocument = New PdfDocument 'Initialize converter settings Dim settings As ExcelToPdfConverterSettings = New ExcelToPdfConverterSettings 'Convert Excel Document into PDF document with the specified settings pdfDocument = converter.Convert(settings) 'Save the PDF file Dim stream As Stream = File.Create("Output.pdf") pdfDocument.Save(stream) End Using End Sub End Class End Namespace