diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Excel-to-PDF-Conversion.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Excel-to-PDF-Conversion.md index 869b8edea..e5be51930 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Excel-to-PDF-Conversion.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Excel-to-PDF-Conversion.md @@ -25,8 +25,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIO renderer. XlsIORenderer renderer = new XlsIORenderer(); @@ -36,13 +35,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/WorkbookToPDF.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/WorkbookToPDF.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -102,8 +96,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; //Initialize XlsIO renderer. @@ -114,13 +107,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/WorksheetToPDF.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/WorksheetToPDF.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -174,8 +162,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIO renderer. XlsIORenderer renderer = new XlsIORenderer(); @@ -187,20 +174,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(sheet.Name +".pdf", FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(sheet.Name + ".pdf"); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); - - System.Diagnostics.Process process = new System.Diagnostics.Process(); - process.StartInfo = new System.Diagnostics.ProcessStartInfo(sheet.Name + ".pdf") - { - UseShellExecute = true - }; - process.Start(); } } {% endhighlight %} @@ -262,8 +237,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; IChart chart = worksheet.Charts[0]; @@ -276,13 +250,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ChartToPDF.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/ChartToPDF.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -347,8 +316,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; //Set print location to comments @@ -362,13 +330,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/CommentsInPlaceToPDF.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/CommentsInPlaceToPDF.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -440,8 +403,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; //Set print location to comments @@ -455,13 +417,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/CommentsToPDFAtEnd.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/CommentsToPDFAtEnd.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -534,8 +491,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; //Set print location to comments @@ -549,13 +505,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/NoCommentsInPDF.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/NoCommentsInPDF.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -632,8 +583,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream("CommentsTemplate.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open("CommentsTemplate.xlsx"); IWorksheet worksheet = workbook.Worksheets[0]; //Add threaded comment @@ -651,9 +601,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Convert Excel document into PDF document PdfDocument pdfDocument = renderer.ConvertToPDF(worksheet); - Stream stream = new FileStream("ExcelComments.pdf", FileMode.Create, FileAccess.ReadWrite); - pdfDocument.Save(stream); - stream.Dispose(); + pdfDocument.Save("ExcelComments.pdf"); } {% endhighlight %} @@ -761,17 +709,12 @@ namespace FontSubstitution //Initialize XlsIO renderer. XlsIORenderer renderer = new XlsIORenderer(); - FileStream excelStream = new FileStream("Template.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("Template.xlsx"); //Convert Excel document with charts into PDF document PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - Stream stream = new FileStream("ExcelToPDF.pdf", FileMode.Create, FileAccess.ReadWrite); - pdfDocument.Save(stream); - - excelStream.Dispose(); - stream.Dispose(); + pdfDocument.Save("ExcelToPDF.pdf"); } } @@ -1207,8 +1150,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(fileStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORenderer application.XlsIORenderer = new XlsIORenderer(); @@ -1222,13 +1164,11 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Convert Excel document into PDF document PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - //Save the converted PDF document to stream. - FileStream stream = new FileStream("Sample.pdf", FileMode.Create, FileAccess.ReadWrite); - pdfDocument.Save(stream); + //Save the converted PDF document + pdfDocument.Save("Sample.pdf"); //Close and Dispose workbook.Close(); - stream.Dispose(); } {% endhighlight %} @@ -1288,8 +1228,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(fileStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORenderer application.XlsIORenderer = new XlsIORenderer(); @@ -1312,13 +1251,11 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Convert Excel document into PDF document PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - //Save the converted PDF document to stream. - FileStream stream = new FileStream("Sample.pdf", FileMode.Create, FileAccess.ReadWrite); - pdfDocument.Save(stream); + //Save the converted PDF document + pdfDocument.Save("Sample.pdf"); //Close and Dispose workbook.Close(); - stream.Dispose(); } {% endhighlight %} @@ -1398,8 +1335,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(fileStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORenderer application.XlsIORenderer = new XlsIORenderer(); @@ -1423,12 +1359,10 @@ using (ExcelEngine excelEngine = new ExcelEngine()) PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); //Excel to PDF - Stream stream = new FileStream("Sample.pdf", FileMode.Create, FileAccess.ReadWrite); - pdfDocument.Save(stream); + pdfDocument.Save("Sample.pdf"); //Close and Dispose workbook.Close(); - stream.Dispose(); } {% endhighlight %} @@ -1506,8 +1440,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(fileStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORenderer application.XlsIORenderer = new XlsIORenderer(); @@ -1529,13 +1462,11 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Convert Excel document into PDF document PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - //Save the PDF document to stream - FileStream stream = new FileStream("Sample.pdf", FileMode.Create, FileAccess.ReadWrite); - pdfDocument.Save(stream); + //Save the PDF document + pdfDocument.Save("Sample.pdf"); //Close and Dispose workbook.Close(); - stream.Dispose(); } {% endhighlight %} diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Excel-to-PDF-Converter-Settings.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Excel-to-PDF-Converter-Settings.md index a2f43ed04..c7a914728 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Excel-to-PDF-Converter-Settings.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Excel-to-PDF-Converter-Settings.md @@ -22,8 +22,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -39,13 +38,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ComplexScriptToPDF.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/ComplexScriptToPDF.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -111,8 +105,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -128,13 +121,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/CustomPaperSize.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/CustomPaperSize.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -201,8 +189,7 @@ Gridlines will not be rendered in the output PDF document, when display style is using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; - FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -216,17 +203,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Convert the Excel document to PDF with renderer settings PdfDocument document = renderer.ConvertToPDF(workbook, settings); - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - document.Save(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf"); - fileStreamResult.FileDownloadName = "Output.pdf"; - return fileStreamResult; + //Save the PDF document + document.Save("Output.pdf"); } {% endhighlight %} @@ -287,8 +265,7 @@ Gridlines will not be rendered in the output PDF document, when display style is using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; - FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -302,17 +279,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Convert the Excel document to PDF with renderer settings PdfDocument document = renderer.ConvertToPDF(workbook, settings); - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - document.Save(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf"); - fileStreamResult.FileDownloadName = "Output.pdf"; - return fileStreamResult; + //Save the PDF document + document.Save("Output.pdf"); } {% endhighlight %} @@ -374,8 +342,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -391,13 +358,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Gridlines.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/Gridlines.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -463,8 +425,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -480,13 +441,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/EmbedFonts.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/EmbedFonts.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -552,8 +508,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -569,13 +524,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/BookmarksInPDF.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/BookmarksInPDF.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -641,8 +591,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -658,13 +607,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/DocumentProperties.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/DocumentProperties.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -730,8 +674,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -747,13 +690,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/QualityImageInPDF.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/QualityImageInPDF.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -820,8 +758,7 @@ Document header will be rendered to PDF document by default. This can be skipped using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; - FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -835,17 +772,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Convert the Excel document to PDF with renderer settings PdfDocument document = renderer.ConvertToPDF(workbook, settings); - //Saving the Excel to the MemoryStream - MemoryStream stream = new MemoryStream(); - document.Save(stream); - - //Set the position as '0' - stream.Position = 0; - - //Download the PDF file in the browser - FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf"); - fileStreamResult.FileDownloadName = "Output.pdf"; - return fileStreamResult; + //Save the PDF document + document.Save("Output.pdf"); } {% endhighlight %} @@ -907,8 +835,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -927,13 +854,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/HeaderFooterInPDF.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/HeaderFooterInPDF.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -999,8 +921,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -1016,13 +937,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/BlankPageToPDF.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/BlankPageToPDF.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -1088,8 +1004,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -1105,13 +1020,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/BlankSheetToPDF.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/BlankSheetToPDF.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -1179,8 +1089,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -1196,13 +1105,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Automatic.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/Automatic.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -1266,8 +1170,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -1283,13 +1186,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/CustomScaling.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/CustomScaling.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -1353,8 +1251,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -1370,13 +1267,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/FitAllColumnsOnOnePage.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/FitAllColumnsOnOnePage.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -1440,8 +1332,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -1457,13 +1348,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/FitAllRowsOnOnePage.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/FitAllRowsOnOnePage.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -1527,8 +1413,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -1544,13 +1429,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/FitSheetOnOnePage.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/FitSheetOnOnePage.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -1614,8 +1494,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -1631,13 +1510,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/NoScaling.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/NoScaling.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -1708,8 +1582,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIO renderer. XlsIORenderer renderer = new XlsIORenderer(); @@ -1725,13 +1598,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/PDFConformance.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/PDFConformance.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -1799,11 +1667,9 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream1 = new FileStream(Path.GetFullPath(@"Data/Template1.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook1 = application.Workbooks.Open(inputStream1); + IWorkbook workbook1 = application.Workbooks.Open(Path.GetFullPath(@"Data/Template1.xlsx")); - FileStream inputStream2 = new FileStream(Path.GetFullPath(@"Data/Template2.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook2 = application.Workbooks.Open(inputStream2); + IWorkbook workbook2 = application.Workbooks.Open(Path.GetFullPath(@"Data/Template2.xlsx")); //Initialize XlsIORenderer XlsIORenderer renderer = new XlsIORenderer(); @@ -1822,14 +1688,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/MultipleExcelToPDF.pdf"), FileMode.Create, FileAccess.Write); - newDocument.Save(outputStream); + newDocument.Save(Path.GetFullPath("Output/MultipleExcelToPDF.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream1.Dispose(); - inputStream2.Dispose(); } {% endhighlight %} @@ -1907,8 +1767,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) application.DefaultVersion = ExcelVersion.Xlsx; //Open an Excel document - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Get the first worksheet IWorksheet worksheet1 = workbook.Worksheets[0]; @@ -1933,13 +1792,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/SelectedSheetsToPDF.pdf"), FileMode.Create, FileAccess.Write); - newDocument.Save(outputStream); + newDocument.Save(Path.GetFullPath("Output/SelectedSheetsToPDF.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} @@ -2039,8 +1893,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream("../../../Data/InputTemplate.xlsx",FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize XlsIORendererSettings XlsIORendererSettings settings = new XlsIORendererSettings(); @@ -2055,8 +1908,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) PdfDocument pdfDocument = renderer.ConvertToPDF(workbook, settings); //Save the PDF document - FileStream outputStream = new FileStream("Output.pdf",FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save("Output.pdf"); } {% endhighlight %} @@ -2137,12 +1989,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/EmptyExcelToPDF.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/EmptyExcelToPDF.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); } {% endhighlight %} @@ -2227,8 +2075,7 @@ namespace Warnings IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; //Open the Excel document to convert. - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); //Initialize warning class to capture warnings during the conversion. Warning warning = new Warning(); @@ -2250,14 +2097,9 @@ namespace Warnings { #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ExceltoPDF.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/ExceltoPDF.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); } - inputStream.Dispose(); } } } @@ -2392,5 +2234,4 @@ End Namespace {% endhighlight %} {% endtabs %} -A complete working example to skip warning in Excel to PDF in C# is present on [this GitHub page](https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Excel%20to%20PDF/Warnings/.NET/Warnings). - +A complete working example to skip warning in Excel to PDF in C# is present on [this GitHub page](https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Excel%20to%20PDF/Warnings/.NET/Warnings). \ No newline at end of file diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img4.png b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img4.png index b4ee8df32..cd6c0e447 100644 Binary files a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img4.png and b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img4.png differ diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img5.png b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img5.png index 9811f3682..264f1e869 100644 Binary files a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img5.png and b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img5.png differ diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img6.png b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img6.png index 4a698ee2f..20acf632c 100644 Binary files a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img6.png and b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img6.png differ diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img7.png b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img7.png index 0fcc2bd8e..67ab816b6 100644 Binary files a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img7.png and b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/UWP_images/UWP_images_img7.png differ diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Windows-Forms_images/Windows-Forms_images_img5.png b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Windows-Forms_images/Windows-Forms_images_img5.png index bef4c758b..766c74072 100644 Binary files a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Windows-Forms_images/Windows-Forms_images_img5.png and b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Windows-Forms_images/Windows-Forms_images_img5.png differ diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Windows-Forms_images/Windows-Forms_images_img6.png b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Windows-Forms_images/Windows-Forms_images_img6.png index 68ee736fb..ca929eb53 100644 Binary files a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Windows-Forms_images/Windows-Forms_images_img6.png and b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Windows-Forms_images/Windows-Forms_images_img6.png differ diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Windows-Forms_images/Windows-Forms_images_img7.png b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Windows-Forms_images/Windows-Forms_images_img7.png index 0fcc2bd8e..67ab816b6 100644 Binary files a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Windows-Forms_images/Windows-Forms_images_img7.png and b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Windows-Forms_images/Windows-Forms_images_img7.png differ diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img4.png b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img4.png index 7a7902f1d..f9a468e12 100644 Binary files a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img4.png and b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img4.png differ diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img5.png b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img5.png index d6dd8fecc..878796e40 100644 Binary files a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img5.png and b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img5.png differ diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img6.png b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img6.png index 7fb54a8fb..e83bb005b 100644 Binary files a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img6.png and b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img6.png differ diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img7.png b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img7.png index 0fcc2bd8e..67ab816b6 100644 Binary files a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img7.png and b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/Wpf_images/Wpf_images_img7.png differ diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-asp-net-core.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-asp-net-core.md index 882e8b13c..099c57351 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-asp-net-core.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-asp-net-core.md @@ -66,8 +66,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); //Initialize XlsIO renderer. XlsIORenderer renderer = new XlsIORenderer(); @@ -146,8 +145,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); //Initialize XlsIO renderer. XlsIORenderer renderer = new XlsIORenderer(); diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-asp-net-mvc.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-asp-net-mvc.md index b9bff300a..c017f2f52 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-asp-net-mvc.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-asp-net-mvc.md @@ -60,8 +60,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); //Initialize ExcelToPdfConverter ExcelToPdfConverter converter = new ExcelToPdfConverter(workbook); @@ -93,4 +92,4 @@ By executing the program, you will get the **PDF document** as follows. Click [here](https://www.syncfusion.com/document-processing/excel-framework/net) to explore the rich set of Syncfusion® Excel library (XlsIO) features. -An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetmvc/Excel/ExcelToPDF#/material3) in ASP.NET MVC. +An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetmvc/Excel/ExcelToPDF#/material3) in ASP.NET MVC. \ No newline at end of file diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-asp-net.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-asp-net.md index c30031899..1afdb7fb1 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-asp-net.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-asp-net.md @@ -70,8 +70,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); //Initialize ExcelToPdfConverter ExcelToPdfConverter converter = new ExcelToPdfConverter(workbook); @@ -99,4 +98,4 @@ By executing the program, you will get the **PDF document** as follows. Click [here](https://www.syncfusion.com/document-processing/excel-framework/net) to explore the rich set of Syncfusion® Excel library (XlsIO) features. -An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetmvc/Excel/ExcelToPDF#/material3) in ASP.NET MVC. +An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetmvc/Excel/ExcelToPDF#/material3) in ASP.NET MVC. \ No newline at end of file diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-aws-lambda.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-aws-lambda.md index c430767ff..a35cdff86 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-aws-lambda.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-aws-lambda.md @@ -71,8 +71,7 @@ public string FunctionHandler(string input, ILambdaContext context) //Initializes the SubstituteFont event to perform font substitution during Excel-to-PDF conversion application.SubstituteFont += new SubstituteFontEventHandler(SubstituteFont); - FileStream excelStream = new FileStream(@"Data/Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Sample.xlsx")); //Initialize XlsIO renderer. XlsIORenderer renderer = new XlsIORenderer(); diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-azure-app-service-linux.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-azure-app-service-linux.md index b784c445f..5feef030a 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-azure-app-service-linux.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-azure-app-service-linux.md @@ -68,8 +68,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); //Initialize XlsIO renderer. XlsIORenderer renderer = new XlsIORenderer(); @@ -140,4 +139,4 @@ You can download a complete working sample from [GitHub](https://github.com/Sync Click [here](https://www.syncfusion.com/document-processing/excel-framework/net-core) to explore the rich set of Syncfusion® Excel library (XlsIO) features. -An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetcore/Excel/ExcelToPDF#/material3) in ASP.NET Core. +An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetcore/Excel/ExcelToPDF#/material3) in ASP.NET Core. \ No newline at end of file diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-azure-app-service-windows.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-azure-app-service-windows.md index a78c15da9..74976da2f 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-azure-app-service-windows.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-azure-app-service-windows.md @@ -60,8 +60,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); //Initialize XlsIO renderer. XlsIORenderer renderer = new XlsIORenderer(); @@ -132,4 +131,4 @@ You can download a complete working sample from [GitHub](https://github.com/Sync Click [here](https://www.syncfusion.com/document-processing/excel-framework/net-core) to explore the rich set of Syncfusion® Excel library (XlsIO) features. -An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetcore/Excel/ExcelToPDF#/material3) in ASP.NET Core. +An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetcore/Excel/ExcelToPDF#/material3) in ASP.NET Core. \ No newline at end of file diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-blazor.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-blazor.md index 4311f2abc..e03a29da1 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-blazor.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-blazor.md @@ -86,27 +86,23 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; + + // Open the workbook. + IWorkbook workbook = application.Workbooks.Open(@"wwwroot/InputTemplate.xlsx"); - //Load an existing file - using (FileStream sourceStreamPath = new FileStream(@"wwwroot/InputTemplate.xlsx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) - { - // Open the workbook. - IWorkbook workbook = application.Workbooks.Open(sourceStreamPath); + // Instantiate the Excel to PDF renderer. + XlsIORenderer renderer = new XlsIORenderer(); - // Instantiate the Excel to PDF renderer. - XlsIORenderer renderer = new XlsIORenderer(); + //Convert Excel document into PDF document + PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - //Convert Excel document into PDF document - PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); + //Create the MemoryStream to save the converted PDF. + MemoryStream pdfStream = new MemoryStream(); - //Create the MemoryStream to save the converted PDF. - MemoryStream pdfStream = new MemoryStream(); - - //Save the converted PDF document to MemoryStream. - pdfDocument.Save(pdfStream); - pdfStream.Position = 0; - return pdfStream; - } + //Save the converted PDF document to MemoryStream. + pdfDocument.Save(pdfStream); + pdfStream.Position = 0; + return pdfStream; } {% endhighlight %} {% endtabs %} @@ -245,26 +241,22 @@ using (ExcelEngine excelEngine = new ExcelEngine()) IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - //Load an existing file - using (FileStream sourceStreamPath = new FileStream(@"wwwroot/InputTemplate.xlsx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) - { - // Open the workbook. - IWorkbook workbook = application.Workbooks.Open(sourceStreamPath); + // Open the workbook. + IWorkbook workbook = application.Workbooks.Open(@"wwwroot/InputTemplate.xlsx"); - // Instantiate the Excel to PDF renderer. - XlsIORenderer renderer = new XlsIORenderer(); + // Instantiate the Excel to PDF renderer. + XlsIORenderer renderer = new XlsIORenderer(); - //Convert Excel document into PDF document - PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); + //Convert Excel document into PDF document + PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - //Create the MemoryStream to save the converted PDF. - MemoryStream pdfStream = new MemoryStream(); + //Create the MemoryStream to save the converted PDF. + MemoryStream pdfStream = new MemoryStream(); - //Save the converted PDF document to MemoryStream. - pdfDocument.Save(pdfStream); - pdfStream.Position = 0; - return pdfStream; - } + //Save the converted PDF document to MemoryStream. + pdfDocument.Save(pdfStream); + pdfStream.Position = 0; + return pdfStream; } {% endhighlight %} {% endtabs %} @@ -333,8 +325,8 @@ By executing the program, you will get the **PDF document** as follows. ![Output File in Blazor Server App](Blazor_images\Blazor_images_Server_and_Client_App_Output.png) Click [here](https://www.syncfusion.com/document-processing/excel-framework/blazor) to explore the rich set of Syncfusion® Excel library (XlsIO) features. - -An online sample link to [convert an Excel document to PDF](https://blazor.syncfusion.com/demos/excel/excel-to-pdf?theme=fluent) in Blazor. + +An online sample link to convert an Excel document to PDF in Blazor. ## Excel to PDF in Blazor WASM app @@ -663,8 +655,8 @@ By executing the program, you will get the **PDF document** as follows. N> To convert Excel to PDF, it is necessary to access the font stream internally. However, this cannot be done automatically in a Blazor WASM application. Therefore, we recommend using a Server app, even though Excel to PDF conversion works in a WASM app. Click [here](https://www.syncfusion.com/document-processing/excel-framework/blazor) to explore the rich set of Syncfusion® Excel library (XlsIO) features. - -An online sample link to [convert an Excel document to PDF](https://blazor.syncfusion.com/demos/excel/excel-to-pdf?theme=fluent) in Blazor. + +An online sample link to convert an Excel document to PDF in Blazor. ## Excel to PDF in .NET MAUI Blazor Hybrid App @@ -886,4 +878,4 @@ By executing the program, you will get the **PDF document** as follows. Click [here](https://www.syncfusion.com/document-processing/excel-framework/blazor) to explore the rich set of Syncfusion® Excel library (XlsIO) features. -An online sample link to [convert an Excel document to PDF](https://blazor.syncfusion.com/demos/excel/excel-to-pdf?theme=fluent) in Blazor. +An online sample link to convert an Excel document to PDF in Blazor. diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-console-application.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-console-application.md index 40f0aad4b..b63ff1229 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-console-application.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-console-application.md @@ -51,25 +51,16 @@ using (ExcelEngine excelEngine = new ExcelEngine()) application.DefaultVersion = ExcelVersion.Xlsx; //Load existing Excel file - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Sample.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Sample.xlsx")); //Convert to PDF XlsIORenderer renderer = new XlsIORenderer(); PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - //Create the MemoryStream to save the converted PDF. - MemoryStream pdfStream = new MemoryStream(); - #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Sample.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/Sample.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} {% endtabs %} @@ -119,25 +110,16 @@ using (ExcelEngine excelEngine = new ExcelEngine()) application.DefaultVersion = ExcelVersion.Xlsx; //Load existing Excel file - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Sample.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Sample.xlsx")); //Convert to PDF XlsIORenderer renderer = new XlsIORenderer(); PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - //Create the MemoryStream to save the converted PDF - MemoryStream pdfStream = new MemoryStream(); - #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Sample.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/Sample.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} {% endtabs %} @@ -187,8 +169,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); //Initialize ExcelToPdfConverter ExcelToPdfConverter converter = new ExcelToPdfConverter(workbook); diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-docker.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-docker.md index e2e7d68d7..b1c146a98 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-docker.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-docker.md @@ -50,8 +50,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream excelStream = new FileStream("InputTemplate.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx"); //Initialize XlsIO renderer. XlsIORenderer renderer = new XlsIORenderer(); @@ -59,9 +58,8 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Convert Excel document into PDF document PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - //Create the FileStream to save the converted PDF. - FileStream pdfStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite); - pdfDocument.Save(pdfStream); + //Save the converted PDF. + pdfDocument.Save("Output.pdf"); } {% endhighlight %} {% endtabs %} diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-google-app-engine.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-google-app-engine.md index b98869b69..c20bab45c 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-google-app-engine.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-google-app-engine.md @@ -102,8 +102,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); //Initialize XlsIO renderer. XlsIORenderer renderer = new XlsIORenderer(); diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-linux.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-linux.md index 92d36638b..7d624606d 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-linux.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-linux.md @@ -60,25 +60,16 @@ using (ExcelEngine excelEngine = new ExcelEngine()) application.DefaultVersion = ExcelVersion.Xlsx; //Load existing Excel file - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Sample.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Sample.xlsx")); //Convert to PDF XlsIORenderer renderer = new XlsIORenderer(); PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - //Create the MemoryStream to save the converted PDF. - MemoryStream pdfStream = new MemoryStream(); - #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Sample.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/Sample.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} {% endtabs %} @@ -135,25 +126,16 @@ using (ExcelEngine excelEngine = new ExcelEngine()) application.DefaultVersion = ExcelVersion.Xlsx; //Load existing Excel file - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Sample.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Sample.xlsx")); //Convert to PDF XlsIORenderer renderer = new XlsIORenderer(); PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - //Create the MemoryStream to save the converted PDF. - MemoryStream pdfStream = new MemoryStream(); - #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Sample.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/Sample.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} {% endtabs %} diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-mac.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-mac.md index 0e8b8b1f7..75d18f0e9 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-mac.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-mac.md @@ -50,25 +50,16 @@ using (ExcelEngine excelEngine = new ExcelEngine()) application.DefaultVersion = ExcelVersion.Xlsx; //Load existing Excel file - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Sample.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Sample.xlsx")); //Convert to PDF XlsIORenderer renderer = new XlsIORenderer(); PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - //Create the MemoryStream to save the converted PDF. - MemoryStream pdfStream = new MemoryStream(); - #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Sample.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/Sample.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} {% endtabs %} @@ -118,25 +109,16 @@ using (ExcelEngine excelEngine = new ExcelEngine()) application.DefaultVersion = ExcelVersion.Xlsx; //Load existing Excel file - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Sample.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Sample.xlsx")); //Convert to PDF XlsIORenderer renderer = new XlsIORenderer(); PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - //Create the MemoryStream to save the converted PDF. - MemoryStream pdfStream = new MemoryStream(); - #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Sample.pdf"), FileMode.Create, FileAccess.Write); - pdfDocument.Save(outputStream); + pdfDocument.Save(Path.GetFullPath("Output/Sample.pdf")); #endregion - - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); } {% endhighlight %} {% endtabs %} diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-uwp.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-uwp.md index 963bfa58a..c7d1cc753 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-uwp.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-uwp.md @@ -65,26 +65,24 @@ using (ExcelEngine excelEngine = new ExcelEngine()) //Load an existing file Assembly assembly = typeof(App).GetTypeInfo().Assembly; - using (Stream inputStream = assembly.GetManifestResourceStream("Convert_Excel_to_PDF.InputTemplate.xlsx")) - { - IWorkbook workbook =application.Workbooks.Open(inputStream); + + IWorkbook workbook =application.Workbooks.Open(assembly.GetManifestResourceStream("Convert_Excel_to_PDF.InputTemplate.xlsx")); - //Initialize XlsIO renderer. - XlsIORenderer renderer = new XlsIORenderer(); + //Initialize XlsIO renderer. + XlsIORenderer renderer = new XlsIORenderer(); - //Convert Excel document into PDF document - PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); + //Convert Excel document into PDF document + PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - //Create the MemoryStream to save the converted PDF. - MemoryStream pdfStream = new MemoryStream(); + //Create the MemoryStream to save the converted PDF. + MemoryStream pdfStream = new MemoryStream(); - //Save the converted PDF document to MemoryStream. - pdfDocument.Save(pdfStream); - pdfStream.Position = 0; + //Save the converted PDF document to MemoryStream. + pdfDocument.Save(pdfStream); + pdfStream.Position = 0; - // Save the PDF file or perform any other action with the PDF - SavePDF(pdfStream); - } + // Save the PDF file or perform any other action with the PDF + SavePDF(pdfStream); } {% endhighlight %} {% endtabs %} diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-windows-forms.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-windows-forms.md index c7feec1c9..f781fec94 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-windows-forms.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-windows-forms.md @@ -73,8 +73,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); //Initialize ExcelToPdfConverter ExcelToPdfConverter converter = new ExcelToPdfConverter(workbook); @@ -99,5 +98,4 @@ By executing the program, you will get the **PDF document** as follows. Click [here](https://www.syncfusion.com/document-processing/excel-framework/net) to explore the rich set of Syncfusion® Excel library (XlsIO) features. -An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetcore/Excel/ExcelToPDF#/material3) in ASP.NET Core. - +An online sample link to [convert an Excel document to PDF](https://ej2.syncfusion.com/aspnetcore/Excel/ExcelToPDF#/material3) in ASP.NET Core. \ No newline at end of file diff --git a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-wpf.md b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-wpf.md index 0b9fea57a..1c0826425 100644 --- a/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-wpf.md +++ b/Document-Processing/Excel/Conversions/Excel-to-PDF/NET/convert-excel-to-pdf-in-wpf.md @@ -60,8 +60,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(excelStream); + IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); //Initialize ExcelToPdfConverter ExcelToPdfConverter converter = new ExcelToPdfConverter(workbook);