Skip to content

Commit e3bf024

Browse files
990137-ExcelToPdfUG
1 parent 5e48fbc commit e3bf024

15 files changed

+69
-147
lines changed

Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-asp-net-core.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
6666
{
6767
IApplication application = excelEngine.Excel;
6868
application.DefaultVersion = ExcelVersion.Xlsx;
69-
FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
70-
IWorkbook workbook = application.Workbooks.Open(excelStream);
69+
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
7170

7271
//Initialize XlsIO renderer.
7372
XlsIORenderer renderer = new XlsIORenderer();
@@ -146,8 +145,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
146145
{
147146
IApplication application = excelEngine.Excel;
148147
application.DefaultVersion = ExcelVersion.Xlsx;
149-
FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
150-
IWorkbook workbook = application.Workbooks.Open(excelStream);
148+
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
151149

152150
//Initialize XlsIO renderer.
153151
XlsIORenderer renderer = new XlsIORenderer();

Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-asp-net-mvc.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
6060
{
6161
IApplication application = excelEngine.Excel;
6262
application.DefaultVersion = ExcelVersion.Xlsx;
63-
FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
64-
IWorkbook workbook = application.Workbooks.Open(excelStream);
63+
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
6564

6665
//Initialize ExcelToPdfConverter
6766
ExcelToPdfConverter converter = new ExcelToPdfConverter(workbook);
@@ -93,4 +92,4 @@ By executing the program, you will get the **PDF document** as follows.
9392

9493
Click [here](https://www.syncfusion.com/document-processing/excel-framework/net) to explore the rich set of Syncfusion<sup>&reg;</sup> Excel library (XlsIO) features.
9594

96-
An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetmvc/Excel/ExcelToPDF#/material3) in ASP.NET MVC.
95+
An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetmvc/Excel/ExcelToPDF#/material3) in ASP.NET MVC.

Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-asp-net.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
7070
{
7171
IApplication application = excelEngine.Excel;
7272
application.DefaultVersion = ExcelVersion.Xlsx;
73-
FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
74-
IWorkbook workbook = application.Workbooks.Open(excelStream);
73+
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
7574

7675
//Initialize ExcelToPdfConverter
7776
ExcelToPdfConverter converter = new ExcelToPdfConverter(workbook);
@@ -99,4 +98,4 @@ By executing the program, you will get the **PDF document** as follows.
9998

10099
Click [here](https://www.syncfusion.com/document-processing/excel-framework/net) to explore the rich set of Syncfusion<sup>&reg;</sup> Excel library (XlsIO) features.
101100

102-
An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetmvc/Excel/ExcelToPDF#/material3) in ASP.NET MVC.
101+
An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetmvc/Excel/ExcelToPDF#/material3) in ASP.NET MVC.

Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-aws-lambda.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ public string FunctionHandler(string input, ILambdaContext context)
7171
//Initializes the SubstituteFont event to perform font substitution during Excel-to-PDF conversion
7272
application.SubstituteFont += new SubstituteFontEventHandler(SubstituteFont);
7373

74-
FileStream excelStream = new FileStream(@"Data/Sample.xlsx", FileMode.Open, FileAccess.Read);
75-
IWorkbook workbook = application.Workbooks.Open(excelStream);
74+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Sample.xlsx"));
7675

7776
//Initialize XlsIO renderer.
7877
XlsIORenderer renderer = new XlsIORenderer();

Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-azure-app-service-linux.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
6868
{
6969
IApplication application = excelEngine.Excel;
7070
application.DefaultVersion = ExcelVersion.Xlsx;
71-
FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
72-
IWorkbook workbook = application.Workbooks.Open(excelStream);
71+
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
7372

7473
//Initialize XlsIO renderer.
7574
XlsIORenderer renderer = new XlsIORenderer();
@@ -140,4 +139,4 @@ You can download a complete working sample from [GitHub](https://github.com/Sync
140139

141140
Click [here](https://www.syncfusion.com/document-processing/excel-framework/net-core) to explore the rich set of Syncfusion<sup>&reg;</sup> Excel library (XlsIO) features.
142141

143-
An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetcore/Excel/ExcelToPDF#/material3) in ASP.NET Core.
142+
An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetcore/Excel/ExcelToPDF#/material3) in ASP.NET Core.

Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-azure-app-service-windows.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
6060
{
6161
IApplication application = excelEngine.Excel;
6262
application.DefaultVersion = ExcelVersion.Xlsx;
63-
FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
64-
IWorkbook workbook = application.Workbooks.Open(excelStream);
63+
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
6564

6665
//Initialize XlsIO renderer.
6766
XlsIORenderer renderer = new XlsIORenderer();
@@ -132,4 +131,4 @@ You can download a complete working sample from [GitHub](https://github.com/Sync
132131

133132
Click [here](https://www.syncfusion.com/document-processing/excel-framework/net-core) to explore the rich set of Syncfusion<sup>&reg;</sup> Excel library (XlsIO) features.
134133

135-
An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetcore/Excel/ExcelToPDF#/material3) in ASP.NET Core.
134+
An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetcore/Excel/ExcelToPDF#/material3) in ASP.NET Core.

Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-blazor.md

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,23 @@ using (ExcelEngine excelEngine = new ExcelEngine())
8686
{
8787
IApplication application = excelEngine.Excel;
8888
application.DefaultVersion = ExcelVersion.Xlsx;
89+
90+
// Open the workbook.
91+
IWorkbook workbook = application.Workbooks.Open(@"wwwroot/InputTemplate.xlsx");
8992

90-
//Load an existing file
91-
using (FileStream sourceStreamPath = new FileStream(@"wwwroot/InputTemplate.xlsx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
92-
{
93-
// Open the workbook.
94-
IWorkbook workbook = application.Workbooks.Open(sourceStreamPath);
95-
96-
// Instantiate the Excel to PDF renderer.
97-
XlsIORenderer renderer = new XlsIORenderer();
93+
// Instantiate the Excel to PDF renderer.
94+
XlsIORenderer renderer = new XlsIORenderer();
9895

99-
//Convert Excel document into PDF document
100-
PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);
96+
//Convert Excel document into PDF document
97+
PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);
10198

102-
//Create the MemoryStream to save the converted PDF.
103-
MemoryStream pdfStream = new MemoryStream();
99+
//Create the MemoryStream to save the converted PDF.
100+
MemoryStream pdfStream = new MemoryStream();
104101

105-
//Save the converted PDF document to MemoryStream.
106-
pdfDocument.Save(pdfStream);
107-
pdfStream.Position = 0;
108-
return pdfStream;
109-
}
102+
//Save the converted PDF document to MemoryStream.
103+
pdfDocument.Save(pdfStream);
104+
pdfStream.Position = 0;
105+
return pdfStream;
110106
}
111107
{% endhighlight %}
112108
{% endtabs %}
@@ -245,26 +241,22 @@ using (ExcelEngine excelEngine = new ExcelEngine())
245241
IApplication application = excelEngine.Excel;
246242
application.DefaultVersion = ExcelVersion.Xlsx;
247243

248-
//Load an existing file
249-
using (FileStream sourceStreamPath = new FileStream(@"wwwroot/InputTemplate.xlsx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
250-
{
251-
// Open the workbook.
252-
IWorkbook workbook = application.Workbooks.Open(sourceStreamPath);
244+
// Open the workbook.
245+
IWorkbook workbook = application.Workbooks.Open(@"wwwroot/InputTemplate.xlsx");
253246

254-
// Instantiate the Excel to PDF renderer.
255-
XlsIORenderer renderer = new XlsIORenderer();
247+
// Instantiate the Excel to PDF renderer.
248+
XlsIORenderer renderer = new XlsIORenderer();
256249

257-
//Convert Excel document into PDF document
258-
PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);
250+
//Convert Excel document into PDF document
251+
PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);
259252

260-
//Create the MemoryStream to save the converted PDF.
261-
MemoryStream pdfStream = new MemoryStream();
253+
//Create the MemoryStream to save the converted PDF.
254+
MemoryStream pdfStream = new MemoryStream();
262255

263-
//Save the converted PDF document to MemoryStream.
264-
pdfDocument.Save(pdfStream);
265-
pdfStream.Position = 0;
266-
return pdfStream;
267-
}
256+
//Save the converted PDF document to MemoryStream.
257+
pdfDocument.Save(pdfStream);
258+
pdfStream.Position = 0;
259+
return pdfStream;
268260
}
269261
{% endhighlight %}
270262
{% endtabs %}

Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-console-application.md

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,16 @@ using (ExcelEngine excelEngine = new ExcelEngine())
5151
application.DefaultVersion = ExcelVersion.Xlsx;
5252

5353
//Load existing Excel file
54-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Sample.xlsx"), FileMode.Open, FileAccess.Read);
55-
IWorkbook workbook = application.Workbooks.Open(inputStream);
54+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Sample.xlsx"));
5655

5756
//Convert to PDF
5857
XlsIORenderer renderer = new XlsIORenderer();
5958
PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);
6059

61-
//Create the MemoryStream to save the converted PDF.
62-
MemoryStream pdfStream = new MemoryStream();
63-
6460
#region Save
6561
//Saving the workbook
66-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Sample.pdf"), FileMode.Create, FileAccess.Write);
67-
pdfDocument.Save(outputStream);
62+
pdfDocument.Save(Path.GetFullPath("Output/Sample.pdf"));
6863
#endregion
69-
70-
//Dispose streams
71-
outputStream.Dispose();
72-
inputStream.Dispose();
7364
}
7465
{% endhighlight %}
7566
{% endtabs %}
@@ -119,25 +110,16 @@ using (ExcelEngine excelEngine = new ExcelEngine())
119110
application.DefaultVersion = ExcelVersion.Xlsx;
120111

121112
//Load existing Excel file
122-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Sample.xlsx"), FileMode.Open, FileAccess.Read);
123-
IWorkbook workbook = application.Workbooks.Open(inputStream);
113+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Sample.xlsx"));
124114

125115
//Convert to PDF
126116
XlsIORenderer renderer = new XlsIORenderer();
127117
PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);
128118

129-
//Create the MemoryStream to save the converted PDF
130-
MemoryStream pdfStream = new MemoryStream();
131-
132119
#region Save
133120
//Saving the workbook
134-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Sample.pdf"), FileMode.Create, FileAccess.Write);
135-
pdfDocument.Save(outputStream);
121+
pdfDocument.Save(Path.GetFullPath("Output/Sample.pdf"));
136122
#endregion
137-
138-
//Dispose streams
139-
outputStream.Dispose();
140-
inputStream.Dispose();
141123
}
142124
{% endhighlight %}
143125
{% endtabs %}
@@ -187,8 +169,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
187169
{
188170
IApplication application = excelEngine.Excel;
189171
application.DefaultVersion = ExcelVersion.Xlsx;
190-
FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
191-
IWorkbook workbook = application.Workbooks.Open(excelStream);
172+
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
192173

193174
//Initialize ExcelToPdfConverter
194175
ExcelToPdfConverter converter = new ExcelToPdfConverter(workbook);

Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-docker.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,16 @@ using (ExcelEngine excelEngine = new ExcelEngine())
5050
{
5151
IApplication application = excelEngine.Excel;
5252
application.DefaultVersion = ExcelVersion.Xlsx;
53-
FileStream excelStream = new FileStream("InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
54-
IWorkbook workbook = application.Workbooks.Open(excelStream);
53+
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
5554

5655
//Initialize XlsIO renderer.
5756
XlsIORenderer renderer = new XlsIORenderer();
5857

5958
//Convert Excel document into PDF document
6059
PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);
6160

62-
//Create the FileStream to save the converted PDF.
63-
FileStream pdfStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite);
64-
pdfDocument.Save(pdfStream);
61+
//Save the converted PDF.
62+
pdfDocument.Save("Output.pdf");
6563
}
6664
{% endhighlight %}
6765
{% endtabs %}

Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-google-app-engine.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
102102
{
103103
IApplication application = excelEngine.Excel;
104104
application.DefaultVersion = ExcelVersion.Xlsx;
105-
FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
106-
IWorkbook workbook = application.Workbooks.Open(excelStream);
105+
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
107106

108107
//Initialize XlsIO renderer.
109108
XlsIORenderer renderer = new XlsIORenderer();

0 commit comments

Comments
 (0)