How to change the display mode of an Excel to PDF converted document?
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 worksheets corresponds to "Fit to window width with enable scrolling" display mode in PDF, and landscape orientation in Excel worksheets corresponds to "Fit one full page to window" display mode in PDF.
To know more about page settings using XlsIO, please refer to the documentation.
Code snippet to set the display mode of a PDF document
// Set display mode worksheet.PageSetup.Orientation = ExcelPageOrientation.Landscape;
The orientation value gets or sets the display mode through the enumeration ExcelPageOrientation.
The following C#/VB.NET 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);
// 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 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)
'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)
'Saving the PDF document
Dim stream As Stream = File.Create("Output.pdf")
pdfDocument.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 how to change the display mode of an Excel to PDF converted document.
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!