Skip to content

Commit 54f4a04

Browse files
988184-PageSetup
1 parent ed38a22 commit 54f4a04

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Excel-to-PDF-Conversion.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,102 @@ End Using
18091809

18101810
A complete working example to convert an Excel workbook to PDF by setting the paper size for all worksheets in C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Excel%20to%20PDF/Page%20Setup%20Options/.NET/Paper%20Size">this GitHub page</a>.
18111811

1812+
### Orientation
1813+
1814+
The following code illustrates how to convert an Excel workbook to PDF by setting the page orientation.
1815+
1816+
{% tabs %}
1817+
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Excel%20to%20PDF/Page%20Setup%20Options/.NET/Orientation/Orientation/Program.cs,180" %}
1818+
using (ExcelEngine excelEngine = new ExcelEngine())
1819+
{
1820+
IApplication application = excelEngine.Excel;
1821+
application.DefaultVersion = ExcelVersion.Xlsx;
1822+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1823+
1824+
//Set the page orientation for all worksheets
1825+
foreach (IWorksheet worksheet in workbook.Worksheets)
1826+
{
1827+
worksheet.PageSetup.Orientation = ExcelPageOrientation.Portrait;
1828+
}
1829+
1830+
//Initialize XlsIORendererSettings
1831+
XlsIORendererSettings settings = new XlsIORendererSettings();
1832+
1833+
//Set the layout option as FitAllColumnsOnOnePage
1834+
settings.LayoutOptions = LayoutOptions.FitAllColumnsOnOnePage;
1835+
1836+
//Initialize XlsIORenderer
1837+
XlsIORenderer renderer = new XlsIORenderer();
1838+
1839+
//Convert the Excel document to PDF with renderer settings
1840+
PdfDocument pdfDocument = renderer.ConvertToPDF(workbook, settings);
1841+
1842+
//Save the workbook as PDF
1843+
pdfDocument.Save(Path.GetFullPath("Output/Output.pdf"));
1844+
}
1845+
{% endhighlight %}
1846+
1847+
{% highlight c# tabtitle="C# [Windows-specific]" %}
1848+
using (ExcelEngine excelEngine = new ExcelEngine())
1849+
{
1850+
IApplication application = excelEngine.Excel;
1851+
application.DefaultVersion = ExcelVersion.Xlsx;
1852+
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
1853+
1854+
//Set the page orientation for all worksheets
1855+
foreach (IWorksheet worksheet in workbook.Worksheets)
1856+
{
1857+
worksheet.PageSetup.Orientation = ExcelPageOrientation.Portrait;
1858+
}
1859+
1860+
//Initialize ExcelToPdfConverterSettings
1861+
ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings();
1862+
1863+
//Set the layout option as FitAllColumnsOnOnePage
1864+
settings.LayoutOptions = LayoutOptions.FitAllColumnsOnOnePage;
1865+
1866+
//Load the Excel document into ExcelToPdfConverter
1867+
ExcelToPdfConverter converter = new ExcelToPdfConverter(workbook);
1868+
1869+
//Convert the Excel document to PDF with converter settings
1870+
PdfDocument pdfDocument = converter.Convert(settings);
1871+
1872+
//Save the PDF document
1873+
pdfDocument.Save("Output.pdf");
1874+
}
1875+
{% endhighlight %}
1876+
1877+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
1878+
Using excelEngine As ExcelEngine = New ExcelEngine()
1879+
Dim application As IApplication = excelEngine.Excel
1880+
application.DefaultVersion = ExcelVersion.Xlsx
1881+
Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx")
1882+
1883+
'Set the page orientation for all worksheets
1884+
For Each worksheet As IWorksheet In workbook.Worksheets
1885+
worksheet.PageSetup.Orientation = ExcelPageOrientation.Portrait
1886+
Next
1887+
1888+
'Initialize ExcelToPdfConverterSettings
1889+
Dim settings As ExcelToPdfConverterSettings = New ExcelToPdfConverterSettings()
1890+
1891+
'Set the layout option as FitAllColumnsOnOnePage
1892+
settings.LayoutOptions = LayoutOptions.FitAllColumnsOnOnePage
1893+
1894+
'Load the Excel document into ExcelToPdfConverter
1895+
Dim converter As ExcelToPdfConverter = New ExcelToPdfConverter(workbook)
1896+
1897+
'Convert the Excel document to PDF with converter settings
1898+
Dim pdfDocument As PdfDocument = converter.Convert(settings)
1899+
1900+
'Save the workbook as PDF
1901+
pdfDocument.Save("Output.pdf")
1902+
End Using
1903+
{% endhighlight %}
1904+
{% endtabs %}
1905+
1906+
A complete working example to convert an Excel workbook to PDF by setting the page orientation in C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Excel%20to%20PDF/Page%20Setup%20Options/.NET/Orientation">this GitHub page</a>.
1907+
18121908
## Supported elements
18131909

18141910
This feature supports the following elements:

0 commit comments

Comments
 (0)