Skip to content

Commit ff59f23

Browse files
988184-PageSetup
1 parent 54f4a04 commit ff59f23

File tree

2 files changed

+115
-195
lines changed

2 files changed

+115
-195
lines changed

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

Lines changed: 0 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,200 +1711,6 @@ Malgun Gothic, Batang
17111711
</tr>
17121712
</table>
17131713

1714-
## Page Setup Options
1715-
1716-
### Paper size
1717-
1718-
The following code illustrates how to convert an Excel workbook to PDF by setting the paper size for all worksheets.
1719-
1720-
{% tabs %}
1721-
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Excel%20to%20PDF/Page%20Setup%20Options/.NET/Paper%20Size/Paper%20Size/Program.cs,180" %}
1722-
using (ExcelEngine excelEngine = new ExcelEngine())
1723-
{
1724-
IApplication application = excelEngine.Excel;
1725-
application.DefaultVersion = ExcelVersion.Xlsx;
1726-
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1727-
1728-
//Set the paper size to A4 for all worksheets
1729-
foreach (IWorksheet worksheet in workbook.Worksheets)
1730-
{
1731-
worksheet.PageSetup.PaperSize = ExcelPaperSize.PaperA4;
1732-
}
1733-
1734-
//Initialize XlsIORendererSettings
1735-
XlsIORendererSettings settings = new XlsIORendererSettings();
1736-
1737-
//Set the layout option as FitAllColumnsOnOnePage
1738-
settings.LayoutOptions = LayoutOptions.FitAllColumnsOnOnePage;
1739-
1740-
//Initialize XlsIORenderer
1741-
XlsIORenderer renderer = new XlsIORenderer();
1742-
1743-
//Convert the Excel document to PDF with renderer settings
1744-
PdfDocument pdfDocument = renderer.ConvertToPDF(workbook, settings);
1745-
1746-
//Save the workbook as PDF
1747-
pdfDocument.Save(Path.GetFullPath("Output/Output.pdf"));
1748-
}
1749-
{% endhighlight %}
1750-
1751-
{% highlight c# tabtitle="C# [Windows-specific]" %}
1752-
using (ExcelEngine excelEngine = new ExcelEngine())
1753-
{
1754-
IApplication application = excelEngine.Excel;
1755-
application.DefaultVersion = ExcelVersion.Xlsx;
1756-
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
1757-
1758-
//Set the paper size to A4 for all worksheets
1759-
foreach (IWorksheet worksheet in workbook.Worksheets)
1760-
{
1761-
worksheet.PageSetup.PaperSize = ExcelPaperSize.PaperA4;
1762-
}
1763-
1764-
//Initialize ExcelToPdfConverterSettings
1765-
ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings();
1766-
1767-
//Set the layout option as FitAllColumnsOnOnePage
1768-
settings.LayoutOptions = LayoutOptions.FitAllColumnsOnOnePage;
1769-
1770-
//Load the Excel document into ExcelToPdfConverter
1771-
ExcelToPdfConverter converter = new ExcelToPdfConverter(workbook);
1772-
1773-
//Convert the Excel document to PDF with converter settings
1774-
PdfDocument pdfDocument = converter.Convert(settings);
1775-
1776-
//Save the PDF document
1777-
pdfDocument.Save("Output.pdf");
1778-
}
1779-
{% endhighlight %}
1780-
1781-
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
1782-
Using excelEngine As ExcelEngine = New ExcelEngine()
1783-
Dim application As IApplication = excelEngine.Excel
1784-
application.DefaultVersion = ExcelVersion.Xlsx
1785-
Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx")
1786-
1787-
'Set the paper size to A4 for all worksheets
1788-
For Each worksheet As IWorksheet In workbook.Worksheets
1789-
worksheet.PageSetup.PaperSize = ExcelPaperSize.PaperA4
1790-
Next
1791-
1792-
'Initialize ExcelToPdfConverterSettings
1793-
Dim settings As ExcelToPdfConverterSettings = New ExcelToPdfConverterSettings()
1794-
1795-
'Set the layout option as FitAllColumnsOnOnePage
1796-
settings.LayoutOptions = LayoutOptions.FitAllColumnsOnOnePage
1797-
1798-
'Load the Excel document into ExcelToPdfConverter
1799-
Dim converter As ExcelToPdfConverter = New ExcelToPdfConverter(workbook)
1800-
1801-
'Convert the Excel document to PDF with converter settings
1802-
Dim pdfDocument As PdfDocument = converter.Convert(settings)
1803-
1804-
'Save the workbook as PDF
1805-
pdfDocument.Save("Output.pdf")
1806-
End Using
1807-
{% endhighlight %}
1808-
{% endtabs %}
1809-
1810-
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>.
1811-
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-
19081714
## Supported elements
19091715

19101716
This feature supports the following elements:

Document-Processing/Excel/Excel-Library/NET/Worksheet/Page-Setup-Options.md

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,4 +1024,118 @@ End Using
10241024
{% endhighlight %}
10251025
{% endtabs %}
10261026

1027-
A complete working example to add headers and footers in an Excel document using C# is present on [this GitHub page.](https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Worksheet%20Features/Header%20and%20Footer/.NET/Header%20and%20Footer)
1027+
A complete working example to add headers and footers in an Excel document using C# is present on [this GitHub page.](https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Worksheet%20Features/Header%20and%20Footer/.NET/Header%20and%20Footer)
1028+
1029+
## Paper Size
1030+
1031+
The <a href="https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.Interfaces.IPageSetupBase.html#Syncfusion_XlsIO_Interfaces_IPageSetupBase_PaperSize">PaperSize</a> functionality allows you to specify the paper size for worksheet.
1032+
1033+
The following code snippet shows how to use PaperSize.
1034+
1035+
{% tabs %}
1036+
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Worksheet%20Features/PaperSize/.NET/PaperSize/PaperSize/Program.cs,180" %}
1037+
using (ExcelEngine excelEngine = new ExcelEngine())
1038+
{
1039+
IApplication application = excelEngine.Excel;
1040+
application.DefaultVersion = ExcelVersion.Xlsx;
1041+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1042+
IWorksheet worksheet = workbook.Worksheets[0];
1043+
1044+
//Set the paper size to A4
1045+
worksheet.PageSetup.PaperSize = ExcelPaperSize.PaperA4;
1046+
1047+
//Saving the workbook
1048+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
1049+
}
1050+
{% endhighlight %}
1051+
1052+
{% highlight c# tabtitle="C# [Windows-specific]" %}
1053+
using (ExcelEngine excelEngine = new ExcelEngine())
1054+
{
1055+
IApplication application = excelEngine.Excel;
1056+
application.DefaultVersion = ExcelVersion.Xlsx;
1057+
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
1058+
IWorksheet worksheet = workbook.Worksheets[0];
1059+
1060+
//Set the paper size to A4
1061+
worksheet.PageSetup.PaperSize = ExcelPaperSize.PaperA4;
1062+
1063+
//Saving the workbook
1064+
workbook.SaveAs("Output.xlsx");
1065+
}
1066+
{% endhighlight %}
1067+
1068+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
1069+
Using excelEngine As ExcelEngine = New ExcelEngine()
1070+
Dim application As IApplication = excelEngine.Excel
1071+
application.DefaultVersion = ExcelVersion.Xlsx
1072+
Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx")
1073+
Dim worksheet As IWorksheet = workbook.Worksheets(0)
1074+
1075+
'Set the paper size to A4
1076+
worksheet.PageSetup.PaperSize = ExcelPaperSize.PaperA4
1077+
1078+
'Saving the workbook
1079+
workbook.SaveAs("Output.xlsx")
1080+
End Using
1081+
{% endhighlight %}
1082+
{% endtabs %}
1083+
1084+
A complete working example to set the paper size in C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Worksheet%20Features/PaperSize/.NET/PaperSize">this GitHub page</a>.
1085+
1086+
## Orientation
1087+
1088+
The <a href="https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.Interfaces.IPageSetupBase.html#Syncfusion_XlsIO_Interfaces_IPageSetupBase_Orientation">Orientation</a> functionality allows you to specify the orientation for worksheet.
1089+
1090+
The following code snippet shows how to use Orientation.
1091+
1092+
{% tabs %}
1093+
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Worksheet%20Features/Orientation/.NET/Orientation/Orientation/Program.cs,180" %}
1094+
using (ExcelEngine excelEngine = new ExcelEngine())
1095+
{
1096+
IApplication application = excelEngine.Excel;
1097+
application.DefaultVersion = ExcelVersion.Xlsx;
1098+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1099+
IWorksheet worksheet = workbook.Worksheets[0];
1100+
1101+
//Set the page orientation
1102+
worksheet.PageSetup.Orientation = ExcelPageOrientation.Landscape;
1103+
1104+
//Saving the workbook
1105+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
1106+
}
1107+
{% endhighlight %}
1108+
1109+
{% highlight c# tabtitle="C# [Windows-specific]" %}
1110+
using (ExcelEngine excelEngine = new ExcelEngine())
1111+
{
1112+
IApplication application = excelEngine.Excel;
1113+
application.DefaultVersion = ExcelVersion.Xlsx;
1114+
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
1115+
IWorksheet worksheet = workbook.Worksheets[0];
1116+
1117+
//Set the page orientation
1118+
worksheet.PageSetup.Orientation = ExcelPageOrientation.Landscape;
1119+
1120+
//Saving the workbook
1121+
workbook.SaveAs("Output.xlsx");
1122+
}
1123+
{% endhighlight %}
1124+
1125+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
1126+
Using excelEngine As ExcelEngine = New ExcelEngine()
1127+
Dim application As IApplication = excelEngine.Excel
1128+
application.DefaultVersion = ExcelVersion.Xlsx
1129+
Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx")
1130+
Dim worksheet As IWorksheet = workbook.Worksheets(0)
1131+
1132+
'Set the page orientation
1133+
worksheet.PageSetup.Orientation = ExcelPageOrientation.Landscape
1134+
1135+
'Saving the workbook
1136+
workbook.SaveAs("Output.xlsx")
1137+
End Using
1138+
{% endhighlight %}
1139+
{% endtabs %}
1140+
1141+
A complete working example to set the page orientation in C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Worksheet%20Features/Orientation/.NET/Orientation">this GitHub page</a>.

0 commit comments

Comments
 (0)