Articles in this section
Category / Section

How to change the display mode of an Excel to PDF converted document?

3 mins read

This article explains how to set the display mode of a PDF document using XlsIO.

What is Display Mode?

Display mode or page orientation is the direction in which a document is displayed or printed. The two basic types of page orientation are portrait (vertical) and landscape (horizontal). Most monitors have a landscape display, while most documents are printed in portrait mode.

Note: Portrait orientation in Excel worksheet corresponds to “Fit to window width with enable scrolling” display mode in pdf and landscape orientation in Excel worksheet corresponds to "Fit one full page to window" display mode in pdf.

To know more about page settings using XlsIO, please refer documentation.

Code snippet to set the display mode of a PDF document

//Set display mode
worksheet.PageSetup.Orientation = ExcelPageOrientation.Landscape;

 

Download complete sample

Download input file with data

Orientation value gets or sets the display mode through the enumeration ExcelPageOrientation.

The following C#/VB complete code shows how to set the display mode of an Excel to PDF converted document using XlsIO.

C#

using Syncfusion.ExcelToPdfConverter;
using Syncfusion.Pdf;
using Syncfusion.XlsIO;
using System.IO;
using System.Reflection;
 
namespace Display_Mode
{
    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("Display_Mode.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 display mode
                worksheet.PageSetup.Orientation = ExcelPageOrientation.Landscape;
 
                //Create an ExcelToPDFConverter instance
                ExcelToPdfConverter converter = new ExcelToPdfConverter(worksheet);
 
                //Intialize 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 Display_Mode
 
    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("Display_Mode.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 display mode
                worksheet.PageSetup.Orientation = ExcelPageOrientation.Landscape
 
                'Create an ExcelToPDFConverter instance
                Dim converter As ExcelToPdfConverter = New ExcelToPdfConverter(worksheet)
 
                'Intialize 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)
 
                'Saving the PDF document
                Dim stream As Stream = File.Create("Output.pdf")
                pdfDocument.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