From c7cdfbbb1b67f98e94efdf3466339553614c0135 Mon Sep 17 00:00:00 2001 From: "anburasan.saravanan@syncfusion.com" Date: Tue, 6 Feb 2024 16:23:41 +0530 Subject: [PATCH 01/10] Added the KB links --- File-Formats/DocIO/word-to-pdf.md | 1 + File-Formats/Presentation/Charts/Chart-Data-Labels.md | 6 +++++- File-Formats/Presentation/Charts/Chart-Legend.md | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/File-Formats/DocIO/word-to-pdf.md b/File-Formats/DocIO/word-to-pdf.md index e7d20ee68..6be6e3f3f 100644 --- a/File-Formats/DocIO/word-to-pdf.md +++ b/File-Formats/DocIO/word-to-pdf.md @@ -2549,3 +2549,4 @@ You can download a complete working sample from [GitHub](https://github.com/Sync * [How to add signature field in the PDF converted from Word](https://support.syncfusion.com/kb/article/11438/how-to-add-signature-field-in-the-pdf-converted-from-word) * [How to convert Word to PDF in Blazor WebAssembly (WASM)?](https://support.syncfusion.com/kb/article/12239/how-to-convert-word-to-pdf-in-blazor-webassembly-wasm) * [How to perform Word to PDF conversion in WinForms ?](https://support.syncfusion.com/kb/article/8848/how-to-perform-word-to-pdf-conversion-in-winforms-?isInternalRefresh=False) +* [How to preserve track changes markup in Word to PDF conversion](https://support.syncfusion.com/kb/article/14997/how-to-preserve-simple-markup-all-markup-and-no-markup-of-track-changes-during-word-to-pdf-conversion) diff --git a/File-Formats/Presentation/Charts/Chart-Data-Labels.md b/File-Formats/Presentation/Charts/Chart-Data-Labels.md index 86abc3c9b..92b0ab417 100644 --- a/File-Formats/Presentation/Charts/Chart-Data-Labels.md +++ b/File-Formats/Presentation/Charts/Chart-Data-Labels.md @@ -245,4 +245,8 @@ chart.Series(0).DataPoints(0).DataLabels.Layout.ManualLayout.Left = 3 chart.Series(0).DataPoints(0).DataLabels.Layout.ManualLayout.Top = 3 {% endhighlight %} -{% endtabs %} \ No newline at end of file +{% endtabs %} + +## See Also + +* [How to change text of data labels for Chart in Presentation](https://support.syncfusion.com/kb/article/13828/how-to-change-the-text-in-data-labels-inside-a-chart-in-presentation-using-c-in-aspnet-core) diff --git a/File-Formats/Presentation/Charts/Chart-Legend.md b/File-Formats/Presentation/Charts/Chart-Legend.md index d71ee242f..ad911c5e2 100644 --- a/File-Formats/Presentation/Charts/Chart-Legend.md +++ b/File-Formats/Presentation/Charts/Chart-Legend.md @@ -465,3 +465,7 @@ End Using {% endtabs %} You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PowerPoint-Examples/tree/master/Charts/Format-Legend/.NET). + +## See Also + +* [How to remove legend for Chart in Presentation](https://support.syncfusion.com/kb/article/13832/how-to-remove-legend-of-chart-in-powerpoint-using-c-in-aspnet-core) From 44f4848c5e54e047ed04a61dd20c1bb16f019841 Mon Sep 17 00:00:00 2001 From: KurmithaSF4004 Date: Wed, 7 Feb 2024 22:06:28 +0530 Subject: [PATCH 02/10] 868251-DisplayUnit-XlsIO --- File-Formats/XlsIO/Working-with-Charts.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/File-Formats/XlsIO/Working-with-Charts.md b/File-Formats/XlsIO/Working-with-Charts.md index a3fd1c100..fe172d5b3 100644 --- a/File-Formats/XlsIO/Working-with-Charts.md +++ b/File-Formats/XlsIO/Working-with-Charts.md @@ -455,6 +455,9 @@ chart.PrimaryValueAxis.MaximumValue = 14.0; //Number format for axis chart.PrimaryValueAxis.NumberFormat = "0.0"; + +//Display unit for axis +chart.PrimaryValueAxis.DisplayUnit = ExcelChartDisplayUnit.Hundreds; {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} @@ -469,6 +472,9 @@ chart.PrimaryValueAxis.MaximumValue = 14.0; //Number format for axis chart.PrimaryValueAxis.NumberFormat = "0.0"; + +//Display unit for axis +chart.PrimaryValueAxis.DisplayUnit = ExcelChartDisplayUnit.Hundreds; {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} @@ -483,6 +489,9 @@ chart.PrimaryValueAxis.MaximumValue = 14.0 'Number format for axis chart.PrimaryValueAxis.NumberFormat = "0.0" + +'Display unit for axis +chart.PrimaryValueAxis.DisplayUnit = ExcelChartDisplayUnit.Hundreds {% endhighlight %} {% endtabs %} From 21d50ab0c907fd5c7806bcd8ed999f009ad48142 Mon Sep 17 00:00:00 2001 From: KurmithaSF4004 Date: Wed, 7 Feb 2024 22:53:45 +0530 Subject: [PATCH 03/10] 868249-LargeRowColumn-FAQ --- File-Formats-toc.html | 1 + File-Formats/XlsIO/FAQ.md | 3 +- ...3-with-large-number-of-row-column-index.md | 30 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 File-Formats/XlsIO/faqs/how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index.md diff --git a/File-Formats-toc.html b/File-Formats-toc.html index 21e48d0bc..bc122e82f 100644 --- a/File-Formats-toc.html +++ b/File-Formats-toc.html @@ -1670,6 +1670,7 @@
  • How to upload a file to Azure blob and download as stream
  • How to set rounded corner for chart in Excel document
  • How to find and replace text in hyperlinks
  • +
  • How to resolve exception when using Excel97 to 2003 with large number of row column index
  • diff --git a/File-Formats/XlsIO/FAQ.md b/File-Formats/XlsIO/FAQ.md index 1ae4bb5a4..6db242655 100644 --- a/File-Formats/XlsIO/FAQ.md +++ b/File-Formats/XlsIO/FAQ.md @@ -79,4 +79,5 @@ The frequently asked questions in Essential XlsIO are listed below. * [Why cone chart shows itself as column or bar chart?](faqs/why-cone-chart-shows-itself-as-colum-or-bar-chart) * [How to vary colors by point for line and column chart?](faqs/how-to-vary-colors-by-point-for-line-and-column-chart) * [How to upload a file to Azure blob and download as stream?](faqs/how-to-upload-a-file-to-azure-blob-and-download-as-stream) -* [How to find and replace text in hyperlinks](faqs/how-to-find-and-replace-text-in-hyperlinks) \ No newline at end of file +* [How to find and replace text in hyperlinks](faqs/how-to-find-and-replace-text-in-hyperlinks) +* [How to resolve Exception when using Excel97 to 2003 with large number of row column index](faqs/how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index) \ No newline at end of file diff --git a/File-Formats/XlsIO/faqs/how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index.md b/File-Formats/XlsIO/faqs/how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index.md new file mode 100644 index 000000000..a2187e044 --- /dev/null +++ b/File-Formats/XlsIO/faqs/how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index.md @@ -0,0 +1,30 @@ +--- +title: Avoid exception when using Excel97 to 2003 with large number of row column index. +description: This page helps to avoid exception when using Excel97 to 2003 with large number of row column index in Syncfusion .NET Excel library (XlsIO). +platform: file-formats +control: XlsIO +documentation: UG +--- + +# How to avoid exception when using Excel97 to 2003 with large number of rows column index? + +When creating a new workbook, it defaults to the Excel97to2003 version, which supports only 65,536 rows and 256 columns. If the row or column index exceeds this limit, an ArgumentException is thrown. To avoid this exception, we recommend setting the default version of the IApplication to Xlsx. + +The following code snippet shows how to set the default version of IApplication to Xlsx. + +{% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +IApplication application = excelEngine.Excel; +application.DefaultVersion = ExcelVersion.Xlsx; +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +IApplication application = excelEngine.Excel; +application.DefaultVersion = ExcelVersion.Xlsx; +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +IApplication application = excelEngine.Excel +application.DefaultVersion = ExcelVersion.Xlsx +{% endhighlight %} +{% endtabs %} \ No newline at end of file From 1e3a87afd96e406f24c6c57a1c2f3442e5a1ff54 Mon Sep 17 00:00:00 2001 From: Sharly-Atieno Date: Thu, 8 Feb 2024 08:47:34 +0300 Subject: [PATCH 04/10] SEO-179773-File-Format-docs-changes --- File-Formats/DocIO/Convert-Word-Document-to-PDF-in-MAUI.md | 2 +- File-Formats/DocIO/Convert-Word-Document-to-PDF-in-UWP.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/File-Formats/DocIO/Convert-Word-Document-to-PDF-in-MAUI.md b/File-Formats/DocIO/Convert-Word-Document-to-PDF-in-MAUI.md index dbd4f8a9b..c60e9500b 100644 --- a/File-Formats/DocIO/Convert-Word-Document-to-PDF-in-MAUI.md +++ b/File-Formats/DocIO/Convert-Word-Document-to-PDF-in-MAUI.md @@ -183,4 +183,4 @@ Refer the below helper files and add them into the mentioned project. These help Click [here](https://www.syncfusion.com/document-processing/word-framework/maui) to explore the rich set of Syncfusion Word library (DocIO) features. -An online sample link to [convert Word document to PDF](https://ej2.syncfusion.com/aspnetcore/Word/WordToPDF#/material3) in ASP.NET Core. \ No newline at end of file +An online sample link to [convert Word document to PDF](https://ej2.syncfusion.com/aspnetcore/Word/WordToPDF#/bootstrap5) in ASP.NET Core. \ No newline at end of file diff --git a/File-Formats/DocIO/Convert-Word-Document-to-PDF-in-UWP.md b/File-Formats/DocIO/Convert-Word-Document-to-PDF-in-UWP.md index 251ac3271..ff464f486 100644 --- a/File-Formats/DocIO/Convert-Word-Document-to-PDF-in-UWP.md +++ b/File-Formats/DocIO/Convert-Word-Document-to-PDF-in-UWP.md @@ -151,4 +151,4 @@ N> As per [MSDN announcement](https://devblogs.microsoft.com/dotnet/announcing-u Click [here](https://www.syncfusion.com/document-processing/word-framework/uwp) to explore the rich set of Syncfusion Word library (DocIO) features. -An online sample link to [convert Word document to PDF](https://ej2.syncfusion.com/aspnetcore/Word/WordToPDF#/material3) in ASP.NET Core. +An online sample link to [convert Word document to PDF](https://ej2.syncfusion.com/aspnetcore/Word/WordToPDF#/bootstrap5) in ASP.NET Core. From 22cf13d585de246dfe198854053225ae57a31a2a Mon Sep 17 00:00:00 2001 From: KurmithaSF4004 Date: Thu, 8 Feb 2024 20:27:38 +0530 Subject: [PATCH 05/10] 868245-Notes-for-AutoFitRowColumn --- File-Formats/XlsIO/Worksheet-Rows-and-Columns-Manipulation.md | 1 + 1 file changed, 1 insertion(+) diff --git a/File-Formats/XlsIO/Worksheet-Rows-and-Columns-Manipulation.md b/File-Formats/XlsIO/Worksheet-Rows-and-Columns-Manipulation.md index cf8d96a6f..5c6266cc8 100644 --- a/File-Formats/XlsIO/Worksheet-Rows-and-Columns-Manipulation.md +++ b/File-Formats/XlsIO/Worksheet-Rows-and-Columns-Manipulation.md @@ -686,6 +686,7 @@ A complete working example to autofit rows and columns in an Excel worksheet in N> 1) If a Range is text wrapped, the [AutoFitColumn](https://help.syncfusion.com/cr/file-formats/Syncfusion.XlsIO.IWorksheet.html#Syncfusion_XlsIO_IWorksheet_AutofitColumn_System_Int32_) method will not be applied on it. N> 2) If a Range is merged, the Auto-Fit methods will not be applied on it. Note that this is the behavior of Excel as well. N> 3) Auto fitting is a time consuming process so, it might cause performance issues when used excessively. +N> 4) When using Auto-Fit methods after hiding a column or row, the column or row width will be adjusted based on the cell content, causing the width to increase from 0 and making the columns or rows visible. Note that this is the behavior of Excel as well. ## Group or Ungroup Rows and ColumnsĀ  From 6e6ee4fde8f4520d0f233c42e0e8037e72e9f8da Mon Sep 17 00:00:00 2001 From: KurmithaSF4004 Date: Fri, 9 Feb 2024 11:40:55 +0530 Subject: [PATCH 06/10] 868245-Notes-for-AutoFitRowColumn --- File-Formats/XlsIO/Worksheet-Rows-and-Columns-Manipulation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/File-Formats/XlsIO/Worksheet-Rows-and-Columns-Manipulation.md b/File-Formats/XlsIO/Worksheet-Rows-and-Columns-Manipulation.md index 5c6266cc8..df132bf0a 100644 --- a/File-Formats/XlsIO/Worksheet-Rows-and-Columns-Manipulation.md +++ b/File-Formats/XlsIO/Worksheet-Rows-and-Columns-Manipulation.md @@ -686,7 +686,7 @@ A complete working example to autofit rows and columns in an Excel worksheet in N> 1) If a Range is text wrapped, the [AutoFitColumn](https://help.syncfusion.com/cr/file-formats/Syncfusion.XlsIO.IWorksheet.html#Syncfusion_XlsIO_IWorksheet_AutofitColumn_System_Int32_) method will not be applied on it. N> 2) If a Range is merged, the Auto-Fit methods will not be applied on it. Note that this is the behavior of Excel as well. N> 3) Auto fitting is a time consuming process so, it might cause performance issues when used excessively. -N> 4) When using Auto-Fit methods after hiding a column or row, the column or row width will be adjusted based on the cell content, causing the width to increase from 0 and making the columns or rows visible. Note that this is the behavior of Excel as well. +N> 4) When using [AutoFitRows](https://help.syncfusion.com/cr/file-formats/Syncfusion.XlsIO.IRange.html#Syncfusion_XlsIO_IRange_AutofitRows) or [AutofitColumns](https://help.syncfusion.com/cr/file-formats/Syncfusion.XlsIO.IRange.html#Syncfusion_XlsIO_IRange_AutofitColumns), the hidden rows or columns in the range will be adjusted based on the cell content which makes the row height or column width increase from zero. So, the hidden rows or columns will be visible. This is the behavior of XlsIO. ## Group or Ungroup Rows and ColumnsĀ  From 10920e86030859c5f93677543584e0378050893f Mon Sep 17 00:00:00 2001 From: KurmithaSF4004 Date: Fri, 9 Feb 2024 11:46:13 +0530 Subject: [PATCH 07/10] 868249-LargeRowColumn-FAQ --- File-Formats-toc.html | 2 +- ...using-Excel97to2003-with-large-number-of-row-column-index.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/File-Formats-toc.html b/File-Formats-toc.html index bc122e82f..fe4c78653 100644 --- a/File-Formats-toc.html +++ b/File-Formats-toc.html @@ -1670,7 +1670,7 @@
  • How to upload a file to Azure blob and download as stream
  • How to set rounded corner for chart in Excel document
  • How to find and replace text in hyperlinks
  • -
  • How to resolve exception when using Excel97 to 2003 with large number of row column index
  • +
  • How to fix the ArgumentOutOfRangeException when accessing a large number of rows and columns?
  • diff --git a/File-Formats/XlsIO/faqs/how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index.md b/File-Formats/XlsIO/faqs/how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index.md index a2187e044..dc3bfc9b4 100644 --- a/File-Formats/XlsIO/faqs/how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index.md +++ b/File-Formats/XlsIO/faqs/how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index.md @@ -8,7 +8,7 @@ documentation: UG # How to avoid exception when using Excel97 to 2003 with large number of rows column index? -When creating a new workbook, it defaults to the Excel97to2003 version, which supports only 65,536 rows and 256 columns. If the row or column index exceeds this limit, an ArgumentException is thrown. To avoid this exception, we recommend setting the default version of the IApplication to Xlsx. +By default, when creating a new workbook, it is set to Excel97to2003 version which supports only 65536 rows and 256 columns. When the row and column index exceeds this limit, an ArgumentOutOfRange exception is thrown. To fix this, the DefaultVersion needs to be set as Xlsx. This version supports 1048576 rows and 16384 columns. The following code snippet shows how to set the default version of IApplication to Xlsx. From 8b5973dc9023a76b930617e3e4b5a1af35b0ea04 Mon Sep 17 00:00:00 2001 From: KurmithaSF4004 Date: Fri, 9 Feb 2024 11:48:26 +0530 Subject: [PATCH 08/10] 868249-LargeRowColumn-FAQ --- File-Formats/XlsIO/FAQ.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/File-Formats/XlsIO/FAQ.md b/File-Formats/XlsIO/FAQ.md index 6db242655..eb7f36c26 100644 --- a/File-Formats/XlsIO/FAQ.md +++ b/File-Formats/XlsIO/FAQ.md @@ -80,4 +80,4 @@ The frequently asked questions in Essential XlsIO are listed below. * [How to vary colors by point for line and column chart?](faqs/how-to-vary-colors-by-point-for-line-and-column-chart) * [How to upload a file to Azure blob and download as stream?](faqs/how-to-upload-a-file-to-azure-blob-and-download-as-stream) * [How to find and replace text in hyperlinks](faqs/how-to-find-and-replace-text-in-hyperlinks) -* [How to resolve Exception when using Excel97 to 2003 with large number of row column index](faqs/how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index) \ No newline at end of file +* [How to fix the ArgumentOutOfRangeException when accessing a large number of rows and columns?](faqs/how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index) \ No newline at end of file From f5a079425c05a5fe6bb37eef2d99c631acdc54fa Mon Sep 17 00:00:00 2001 From: KurmithaSF4004 Date: Fri, 9 Feb 2024 12:24:07 +0530 Subject: [PATCH 09/10] 868249-LargeRowColumn-FAQ --- File-Formats-toc.html | 2 +- File-Formats/XlsIO/FAQ.md | 2 +- ...-when-accessing-a-large-number-of-rows-and-columns.md} | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) rename File-Formats/XlsIO/faqs/{how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index.md => how-to-fix-the-argument-out-of-range-exception-when-accessing-a-large-number-of-rows-and-columns.md} (55%) diff --git a/File-Formats-toc.html b/File-Formats-toc.html index fe4c78653..dc3aa649d 100644 --- a/File-Formats-toc.html +++ b/File-Formats-toc.html @@ -1670,7 +1670,7 @@
  • How to upload a file to Azure blob and download as stream
  • How to set rounded corner for chart in Excel document
  • How to find and replace text in hyperlinks
  • -
  • How to fix the ArgumentOutOfRangeException when accessing a large number of rows and columns?
  • +
  • How to fix the ArgumentOutOfRangeException when accessing a large number of rows and columns?
  • diff --git a/File-Formats/XlsIO/FAQ.md b/File-Formats/XlsIO/FAQ.md index eb7f36c26..b7f8315c7 100644 --- a/File-Formats/XlsIO/FAQ.md +++ b/File-Formats/XlsIO/FAQ.md @@ -80,4 +80,4 @@ The frequently asked questions in Essential XlsIO are listed below. * [How to vary colors by point for line and column chart?](faqs/how-to-vary-colors-by-point-for-line-and-column-chart) * [How to upload a file to Azure blob and download as stream?](faqs/how-to-upload-a-file-to-azure-blob-and-download-as-stream) * [How to find and replace text in hyperlinks](faqs/how-to-find-and-replace-text-in-hyperlinks) -* [How to fix the ArgumentOutOfRangeException when accessing a large number of rows and columns?](faqs/how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index) \ No newline at end of file +* [How to fix the ArgumentOutOfRangeException when accessing a large number of rows and columns?](faqs/how-to-fix-the-argument-out-of-range-exception-when-accessing-a-large-number-of-rows-and-columns) \ No newline at end of file diff --git a/File-Formats/XlsIO/faqs/how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index.md b/File-Formats/XlsIO/faqs/how-to-fix-the-argument-out-of-range-exception-when-accessing-a-large-number-of-rows-and-columns.md similarity index 55% rename from File-Formats/XlsIO/faqs/how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index.md rename to File-Formats/XlsIO/faqs/how-to-fix-the-argument-out-of-range-exception-when-accessing-a-large-number-of-rows-and-columns.md index dc3bfc9b4..42219af65 100644 --- a/File-Formats/XlsIO/faqs/how-to-resolve-exception-when-using-Excel97to2003-with-large-number-of-row-column-index.md +++ b/File-Formats/XlsIO/faqs/how-to-fix-the-argument-out-of-range-exception-when-accessing-a-large-number-of-rows-and-columns.md @@ -1,14 +1,14 @@ --- -title: Avoid exception when using Excel97 to 2003 with large number of row column index. -description: This page helps to avoid exception when using Excel97 to 2003 with large number of row column index in Syncfusion .NET Excel library (XlsIO). +title: Fix the ArgumentOutOfRangeException when accessing a large number of rows and columns. +description: This page helps how to fix the ArgumentOutOfRangeException when accessing a large number of rows and columns in Syncfusion .NET Excel library (XlsIO). platform: file-formats control: XlsIO documentation: UG --- -# How to avoid exception when using Excel97 to 2003 with large number of rows column index? +# How to fix the ArgumentOutOfRangeException when accessing a large number of rows and columns? -By default, when creating a new workbook, it is set to Excel97to2003 version which supports only 65536 rows and 256 columns. When the row and column index exceeds this limit, an ArgumentOutOfRange exception is thrown. To fix this, the DefaultVersion needs to be set as Xlsx. This version supports 1048576 rows and 16384 columns. +By default, when creating a new workbook, it is set to Excel97to2003 version which supports only 65536 rows and 256 columns. When the row and column index exceeds this limit, an ArgumentOutOfRange exception is thrown. To fix this, the [DefaultVersion](https://help.syncfusion.com/cr/file-formats/Syncfusion.XlsIO.IApplication.html#Syncfusion_XlsIO_IApplication_DefaultVersion) needs to be set as [Xlsx](https://help.syncfusion.com/cr/file-formats/Syncfusion.XlsIO.ExcelVersion.html). This version supports 1048576 rows and 16384 columns. The following code snippet shows how to set the default version of IApplication to Xlsx. From 1444659afa9caf84f81a00feebbd08ddcf2debc5 Mon Sep 17 00:00:00 2001 From: Srihariharan Date: Fri, 9 Feb 2024 15:02:32 +0530 Subject: [PATCH 10/10] 869450: Update the github sample project to .NET 8.0 in NET MAUI Platform. --- File-Formats/PDF/Create-PDF-file-in-MaUI.md | 547 +++++++++++--------- 1 file changed, 294 insertions(+), 253 deletions(-) diff --git a/File-Formats/PDF/Create-PDF-file-in-MaUI.md b/File-Formats/PDF/Create-PDF-file-in-MaUI.md index 121456f7f..3fe5beba7 100644 --- a/File-Formats/PDF/Create-PDF-file-in-MaUI.md +++ b/File-Formats/PDF/Create-PDF-file-in-MaUI.md @@ -65,12 +65,13 @@ Step 5: Include the following namespaces in the *MainWindow.xaml.cs* file. {% highlight c# tabtitle="C#" %} -using Syncfusion.Pdf; -using Syncfusion.Pdf.Graphics; -using Syncfusion.Pdf.Grid; -using Syncfusion.Drawing; -using System.Reflection; -using System.Xml.Linq; + using CreatePdfDemoSample.Services; + using Syncfusion.Pdf; + using Syncfusion.Pdf.Graphics; + using Syncfusion.Pdf.Grid; + using Syncfusion.Drawing; + using System.Reflection; + using System.Xml.Linq; {% endhighlight %} @@ -84,260 +85,300 @@ Step 6: Add a new action method *createPdf_Click* in *MainWindow.xaml.cs* and in {% highlight c# tabtitle="C#" %} -//Create a new PDF document. -PdfDocument document = new PdfDocument(); -//Add a page to the document. -PdfPage page = document.Pages.Add(); -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; - -//Get the page width and height. -float pageWidth = page.GetClientSize().Width; -float pageHeight = page.GetClientSize().Height; -RectangleF TotalPriceCellBounds = RectangleF.Empty; -RectangleF QuantityCellBounds = RectangleF.Empty; -//Set the header height. -float headerHeight = 90; -//Create a brush with a light blue color. -PdfColor lightBlue = Color.FromArgb(255, 91, 126, 215); -PdfBrush lightBlueBrush = new PdfSolidBrush(lightBlue); -//Create a brush with a dark blue color. -PdfColor darkBlue = Color.FromArgb(255, 65, 104, 209); -PdfBrush darkBlueBrush = new PdfSolidBrush(darkBlue); -//Create a brush with a white color. -PdfBrush whiteBrush = new PdfSolidBrush(Color.FromArgb(255, 255, 255, 255)); - -//Get the font file stream from the assembly. -Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly; -string basePath = "CreatePdfDemoSample.Resources.Fonts."; -Stream fontStream = assembly.GetManifestResourceStream(basePath + "OpenSans-Regular.ttf"); -//Create a PdfTrueTypeFont from the stream with the different sizes. -PdfTrueTypeFont headerFont = new PdfTrueTypeFont(fontStream, 30, PdfFontStyle.Regular); -PdfTrueTypeFont arialRegularFont = new PdfTrueTypeFont(fontStream, 18, PdfFontStyle.Regular); -PdfTrueTypeFont arialBoldFont = new PdfTrueTypeFont(fontStream, 9, PdfFontStyle.Bold); -//Create a string format. -PdfStringFormat format = new PdfStringFormat(); -format.Alignment = PdfTextAlignment.Center; -format.LineAlignment = PdfVerticalAlignment.Middle; - -float y = 0; -float x = 0; -//Set the margins of the address. -float margin = 30; -//Set the line space. -float lineSpace = 10; -//Create a border pen and draw the border to on the PDF page. -PdfColor borderColor = Color.FromArgb(255, 142, 170, 219); -PdfPen borderPen = new PdfPen(borderColor, 1f); -graphics.DrawRectangle(borderPen, new RectangleF(0, 0, pageWidth, pageHeight)); - -//Create a new PdfGrid. -PdfGrid grid = new PdfGrid(); -//Add five columns to the grid. -grid.Columns.Add(5); -//Create the header row of the grid. -PdfGridRow[] headerRow = grid.Headers.Add(1); -//Set style to the header row and set value to the header cells. -headerRow[0].Style.BackgroundBrush = new PdfSolidBrush(new PdfColor(68, 114, 196)); -headerRow[0].Style.TextBrush = PdfBrushes.White; -headerRow[0].Cells[0].Value = "Product ID"; -headerRow[0].Cells[0].StringFormat.Alignment = PdfTextAlignment.Center; -headerRow[0].Cells[1].Value = "Product Name"; -headerRow[0].Cells[2].Value = "Price ($)"; -headerRow[0].Cells[3].Value = "Quantity"; -headerRow[0].Cells[4].Value = "Total ($)"; -//Add products to the grid table. -AddProducts("CA-1098", "AWC Logo Cap", 8.99, 2, 17.98, grid); -AddProducts("LJ-0192", "Long-Sleeve Logo Jersey,M", 49.99, 3, 149.97, grid); -AddProducts("So-B909-M", "Mountain Bike Socks,M", 9.50, 2, 19, grid); -AddProducts("LJ-0192", "Long-Sleeve Logo Jersey,M", 49.99, 4, 199.96, grid); -AddProducts("FK-5136", "ML Fork", 175.49, 6, 1052.94, grid); -AddProducts("HL-U509", "Sports-100 Helmet,Black", 34.99, 1, 34.99, grid); - -#region Header -//Fill the header with a light blue brush. -graphics.DrawRectangle(lightBlueBrush, new RectangleF(0, 0, pageWidth, headerHeight)); -string title = "INVOICE"; -//Specificy the bounds for the total value. -RectangleF headerTotalBounds = new RectangleF(400, 0, pageWidth - 400, headerHeight); -//Measure the string size using the font. -SizeF textSize = headerFont.MeasureString(title); -graphics.DrawString(title, headerFont, whiteBrush, new RectangleF(0, 0, textSize.Width + 50, headerHeight), format); -//Draw a rectangle in the PDF page. -graphics.DrawRectangle(darkBlueBrush, headerTotalBounds); -//Draw the total value to the PDF page. -graphics.DrawString("$" + GetTotalAmount(grid).ToString(), arialRegularFont, whiteBrush, new RectangleF(400, 0, pageWidth - 400, headerHeight + 10), format); -//Create a font from the font stream. -arialRegularFont = new PdfTrueTypeFont(fontStream, 9, PdfFontStyle.Regular); -//Set the bottom line alignment and draw the text to the PDF page. -format.LineAlignment = PdfVerticalAlignment.Bottom; -graphics.DrawString("Amount", arialRegularFont, whiteBrush, new RectangleF(400, 0, pageWidth - 400, headerHeight / 2 - arialRegularFont.Height), format); -#endregion - -//Measure the string size using the font. -SizeF size = arialRegularFont.MeasureString("Invoice Number: 2058557939"); -y = headerHeight + margin; -x = (pageWidth - margin) - size.Width; -//Draw text to a PDF page with the provided font and location. -graphics.DrawString("Invoice Number: 2058557939", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); -//Measure the string size using the font. -size = arialRegularFont.MeasureString("Date :" + DateTime.Now.ToString("dddd dd, MMMM yyyy")); -x = (pageWidth - margin) - size.Width; -y += arialRegularFont.Height + lineSpace; -//Draw text to a PDF page with the provided font and location. -graphics.DrawString("Date: " + DateTime.Now.ToString("dddd dd, MMMM yyyy"), arialRegularFont, PdfBrushes.Black, new PointF(x, y)); - -y = headerHeight + margin; -x = margin; -//Draw text to a PDF page with the provided font and location. -graphics.DrawString("Bill To:", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); -y += arialRegularFont.Height + lineSpace; -graphics.DrawString("Abraham Swearegin,", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); -y += arialRegularFont.Height + lineSpace; -graphics.DrawString("United States, California, San Mateo,", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); -y += arialRegularFont.Height + lineSpace; -graphics.DrawString("9920 BridgePointe Parkway,", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); -y += arialRegularFont.Height + lineSpace; -graphics.DrawString("9365550136", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); - -#region Grid -//Set the width of theto grid columns. -grid.Columns[0].Width = 110; -grid.Columns[1].Width = 150; -grid.Columns[2].Width = 110; -grid.Columns[3].Width = 70; -grid.Columns[4].Width = 100; -for (int i = 0; i < grid.Headers.Count; i++) -{ - //Set the height ofto the grid header row. - grid.Headers[i].Height = 20; - for (int j = 0; j < grid.Columns.Count; j++) + //Create a new PDF document. + PdfDocument document = new(); + //Add a page to the document. + PdfPage page = document.Pages.Add(); + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; + + RectangleF TotalPriceCellBounds = RectangleF.Empty; + RectangleF QuantityCellBounds = RectangleF.Empty; + + //Get the page width and height + float pageWidth = page.GetClientSize().Width; + float pageHeight = page.GetClientSize().Height; + + //Set the header height + float headerHeight = 90; + //Create brush with light blue color. + PdfColor lightBlue = Color.FromArgb(255, 91, 126, 215); + PdfBrush lightBlueBrush = new PdfSolidBrush(lightBlue); + //Create brush with dark blue color. + PdfColor darkBlue = Color.FromArgb(255, 65, 104, 209); + PdfBrush darkBlueBrush = new PdfSolidBrush(darkBlue); + //Create brush with white color. + PdfBrush whiteBrush = new PdfSolidBrush(Color.FromArgb(255, 255, 255, 255)); + + //Get the font file stream from assembly. + Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly; + string basePath = "CreatePdfDemoSample.Resources.Pdf."; + Stream fontStream = assembly.GetManifestResourceStream(basePath + "arial.ttf"); + + //Create PdfTrueTypeFont from stream with different size. + PdfTrueTypeFont headerFont = new(fontStream, 30, PdfFontStyle.Regular); + PdfTrueTypeFont arialRegularFont = new(fontStream, 18, PdfFontStyle.Regular); + PdfTrueTypeFont arialBoldFont = new(fontStream, 9, PdfFontStyle.Bold); + + //Create string format. + PdfStringFormat format = new(); + format.Alignment = PdfTextAlignment.Center; + format.LineAlignment = PdfVerticalAlignment.Middle; + + float y = 0; + float x = 0; + + //Set the margins of address. + float margin = 30; + + //Set the line space. + float lineSpace = 10; + + //Create border pen and draw the border to PDF page. + PdfColor borderColor = Color.FromArgb(255, 142, 170, 219); + PdfPen borderPen = new(borderColor, 1f); + graphics.DrawRectangle(borderPen, new RectangleF(0, 0, pageWidth, pageHeight)); + + //Create a new PdfGrid + PdfGrid grid = new(); + + //Add five columns to the grid. + grid.Columns.Add(5); + + //Create the header row of the grid. + PdfGridRow[] headerRow = grid.Headers.Add(1); + + //Set style to the header row and set value to the header cells. + headerRow[0].Style.BackgroundBrush = new PdfSolidBrush(new PdfColor(68, 114, 196)); + headerRow[0].Style.TextBrush = PdfBrushes.White; + headerRow[0].Cells[0].Value = "Product ID"; + headerRow[0].Cells[0].StringFormat.Alignment = PdfTextAlignment.Center; + headerRow[0].Cells[1].Value = "Product Name"; + headerRow[0].Cells[2].Value = "Price ($)"; + headerRow[0].Cells[3].Value = "Quantity"; + headerRow[0].Cells[4].Value = "Total ($)"; + + //Add products to the grid table. + AddProducts("CA-1098", "AWC Logo Cap", 8.99, 2, 17.98, grid); + AddProducts("LJ-0192", "Long-Sleeve Logo Jersey,M", 49.99, 3, 149.97, grid); + AddProducts("So-B909-M", "Mountain Bike Socks,M", 9.50, 2, 19, grid); + AddProducts("LJ-0192", "Long-Sleeve Logo Jersey,M", 49.99, 4, 199.96, grid); + AddProducts("FK-5136", "ML Fork", 175.49, 6, 1052.94, grid); + AddProducts("HL-U509", "Sports-100 Helmet,Black", 34.99, 1, 34.99, grid); + + #region Header + + //Fill the header with light blue brush + graphics.DrawRectangle(lightBlueBrush, new RectangleF(0, 0, pageWidth, headerHeight)); + + string title = "INVOICE"; + + //Specificy the bounds for total value. + RectangleF headerTotalBounds = new(400, 0, pageWidth - 400, headerHeight); + + //Measure the string size using font. + SizeF textSize = headerFont.MeasureString(title); + graphics.DrawString(title, headerFont, whiteBrush, new RectangleF(0, 0, textSize.Width + 50, headerHeight), format); + //Draw rectangle in PDF page. + graphics.DrawRectangle(darkBlueBrush, headerTotalBounds); + //Draw the toal value to PDF page. + graphics.DrawString("$" + GetTotalAmount(grid).ToString(), arialRegularFont, whiteBrush, new RectangleF(400, 0, pageWidth - 400, headerHeight + 10), format); + //Create font from font stream. + arialRegularFont = new PdfTrueTypeFont(fontStream, 9, PdfFontStyle.Regular); + //Set bottom line alignment and draw the text to PDF page. + format.LineAlignment = PdfVerticalAlignment.Bottom; + graphics.DrawString("Amount", arialRegularFont, whiteBrush, new RectangleF(400, 0, pageWidth - 400, headerHeight / 2 - arialRegularFont.Height), format); + #endregion + //Measure the string size using font. + SizeF size = arialRegularFont.MeasureString("Invoice Number: 2058557939"); + y = headerHeight + margin; + x = (pageWidth - margin) - size.Width; + //Draw text to PDF page with provided font and location. + graphics.DrawString("Invoice Number: 2058557939", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); + //Measure the string size using font. + size = arialRegularFont.MeasureString("Date :" + DateTime.Now.ToString("dddd dd, MMMM yyyy")); + x = (pageWidth - margin) - size.Width; + y += arialRegularFont.Height + lineSpace; + //Draw text to PDF page with provided font and location. + graphics.DrawString("Date: " + DateTime.Now.ToString("dddd dd, MMMM yyyy"), arialRegularFont, PdfBrushes.Black, new PointF(x, y)); + + y = headerHeight + margin; + x = margin; + //Draw text to PDF page with provided font and location. + graphics.DrawString("Bill To:", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); + y += arialRegularFont.Height + lineSpace; + graphics.DrawString("Abraham Swearegin,", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); + y += arialRegularFont.Height + lineSpace; + graphics.DrawString("United States, California, San Mateo,", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); + y += arialRegularFont.Height + lineSpace; + graphics.DrawString("9920 BridgePointe Parkway,", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); + y += arialRegularFont.Height + lineSpace; + graphics.DrawString("9365550136", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); + + #region Grid + //Set width to grid columns. + grid.Columns[0].Width = 110; + grid.Columns[1].Width = 150; + grid.Columns[2].Width = 110; + grid.Columns[3].Width = 70; + grid.Columns[4].Width = 100; + + for (int i = 0; i < grid.Headers.Count; i++) { - //Create a string format for the header cell. - PdfStringFormat pdfStringFormat = new PdfStringFormat(); - pdfStringFormat.LineAlignment = PdfVerticalAlignment.Middle; - pdfStringFormat.Alignment = PdfTextAlignment.Left; - //Set cell padding for header cell. - if (j == 0 || j == 2) - grid.Headers[i].Cells[j].Style.CellPadding = new PdfPaddings(30, 1, 1, 1); - //Set a string format to the grid header cell. - grid.Headers[i].Cells[j].StringFormat = pdfStringFormat; - //Set font to the grid header cell. - grid.Headers[i].Cells[j].Style.Font = arialBoldFont; + //Set height to the grid header row. + grid.Headers[i].Height = 20; + for (int j = 0; j < grid.Columns.Count; j++) + { + //Create string format for header cell. + PdfStringFormat pdfStringFormat = new(); + pdfStringFormat.LineAlignment = PdfVerticalAlignment.Middle; + pdfStringFormat.Alignment = PdfTextAlignment.Left; + + //Set cell padding for header cell. + if (j == 0 || j == 2) + grid.Headers[i].Cells[j].Style.CellPadding = new PdfPaddings(30, 1, 1, 1); + //Set string format to grid header cell. + grid.Headers[i].Cells[j].StringFormat = pdfStringFormat; + //Set font to the grid header cell. + grid.Headers[i].Cells[j].Style.Font = arialBoldFont; + + } + //Set value to the grid header cell. + grid.Headers[0].Cells[0].Value = "Product ID"; } - //Set the value ofto the grid header cell. - grid.Headers[0].Cells[0].Value = "Product ID"; -} -for (int i = 0; i < grid.Rows.Count; i++) -{ - //Set the height ofto the grid row. - grid.Rows[i].Height = 23; - for (int j = 0; j < grid.Columns.Count; j++) + for (int i = 0; i < grid.Rows.Count; i++) { - //Create a string format for the grid row. - PdfStringFormat pdfStringFormat = new PdfStringFormat(); - pdfStringFormat.LineAlignment = PdfVerticalAlignment.Middle; - pdfStringFormat.Alignment = PdfTextAlignment.Left; - - //Set cell padding for grid row cell. - if (j == 0 || j == 2) - grid.Rows[i].Cells[j].Style.CellPadding = new PdfPaddings(30, 1, 1, 1); - - //Seta string format to the grid row cell. - grid.Rows[i].Cells[j].StringFormat = pdfStringFormat; - //Set the font to the grid row cell. - grid.Rows[i].Cells[j].Style.Font = arialRegularFont; + //Set height to the grid row. + grid.Rows[i].Height = 23; + for (int j = 0; j < grid.Columns.Count; j++) + { + //Create string format for grid row. + PdfStringFormat pdfStringFormat = new(); + pdfStringFormat.LineAlignment = PdfVerticalAlignment.Middle; + pdfStringFormat.Alignment = PdfTextAlignment.Left; + + //Set cell padding for grid row cell. + if (j == 0 || j == 2) + grid.Rows[i].Cells[j].Style.CellPadding = new PdfPaddings(30, 1, 1, 1); + + //Set string format to grid row cell. + grid.Rows[i].Cells[j].StringFormat = pdfStringFormat; + //Set font to the grid row cell. + grid.Rows[i].Cells[j].Style.Font = arialRegularFont; + } } -} - -//Apply built-in table style to the grid. -grid.ApplyBuiltinStyle(PdfGridBuiltinStyle.ListTable4Accent5); -//Subscribeing to begin the cell layout event. -grid.BeginCellLayout += Grid_BeginCellLayout; -//Draw the PDF grid to the PDF page and get the layout result. -PdfGridLayoutResult result = grid.Draw(page, new PointF(0, y + 40)); - -//Using the layout result, continue to draw the text. -y = result.Bounds.Bottom + lineSpace; -format = new PdfStringFormat(); -format.Alignment = PdfTextAlignment.Center; -RectangleF bounds = new RectangleF(QuantityCellBounds.X, y, QuantityCellBounds.Width, QuantityCellBounds.Height); -//Draw the text to the PDF page based on the layout result. -page.Graphics.DrawString("Grand Total:", arialBoldFont, PdfBrushes.Black, bounds, format); -//Draw the total amount value to the PDF page based on the layout result. -bounds = new RectangleF(TotalPriceCellBounds.X, y, TotalPriceCellBounds.Width, TotalPriceCellBounds.Height); -page.Graphics.DrawString("$" + GetTotalAmount(grid).ToString(), arialBoldFont, PdfBrushes.Black, bounds); - -//Create a border pen with the custom dash style and draw the border to the page. -borderPen.DashStyle = PdfDashStyle.Custom; -borderPen.DashPattern = new float[] { 3, 3 }; -graphics.DrawLine(borderPen, new PointF(0, pageHeight - 100), new PointF(pageWidth, pageHeight - 100)); - -basePath = "CreatePdfDemoSample.Resources.Images."; -//Get the image file stream from the assembly. -Stream imageStream = assembly.GetManifestResourceStream(basePath + "AdventureWork.png"); - -//Create a PDF bitmap image from the stream. -PdfBitmap bitmap = new PdfBitmap(imageStream); -//Draw the image to the PDF page. -graphics.DrawImage(bitmap, new RectangleF(10, pageHeight - 90, 80, 80)); - -//Calculate the text position and draw the text to the PDF page. -y = pageHeight - 100 + margin; -size = arialRegularFont.MeasureString("800 Interchange Blvd."); -x = pageWidth - size.Width - margin; -graphics.DrawString("800 Interchange Blvd.", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); - -//Calculate the text position and draw the text to the PDF page. -y += arialRegularFont.Height + lineSpace; -size = arialRegularFont.MeasureString("Suite 2501, Austin, TX 78721"); -x = pageWidth - size.Width - margin; -graphics.DrawString("Suite 2501, Austin, TX 78721", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); - -//Calculate the text position and draw the text to the PDF page. -y += arialRegularFont.Height + lineSpace; -size = arialRegularFont.MeasureString("Any Questions? support@adventure-works.com"); -x = pageWidth - size.Width - margin; -graphics.DrawString("Any Questions? support@adventure-works.com", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); - -using MemoryStream ms = new (); -//Saves the presentation to the memory stream. -document.Save(ms); -//Close the PDF document -document.Close(true); -ms.Position = 0; -//Saves the memory stream as file. -SaveService saveService = new (); -saveService.SaveAndView("Invoice.pdf", "application/pdf", ms); - -#region Helper Methods -//Create and row for the grid. -void AddProducts(string productId, string productName, double price, int quantity, double total, PdfGrid grid) -{ - //Add a new row and set the product value to the grid row cells. - PdfGridRow row = grid.Rows.Add(); - row.Cells[0].Value = productId; - row.Cells[1].Value = productName; - row.Cells[2].Value = price.ToString(); - row.Cells[3].Value = quantity.ToString(); - row.Cells[4].Value = total.ToString(); -} -/// -/// Get the Total amount of the purcharsed items. -/// -private float GetTotalAmount(PdfGrid grid) -{ - float Total = 0f; - for (int i = 0; i < grid.Rows.Count; i++) + //Apply built-in table style to the grid. + grid.ApplyBuiltinStyle(PdfGridBuiltinStyle.ListTable4Accent5); + //Subscribing to begin cell layout event. + grid.BeginCellLayout += Grid_BeginCellLayout; + //Draw the PDF grid to PDF page and get the layout result. + PdfGridLayoutResult result = grid.Draw(page, new PointF(0, y + 40)); + + //Using the layout result, continue to draw the text. + y = result.Bounds.Bottom + lineSpace; + format = new PdfStringFormat + { + Alignment = PdfTextAlignment.Center + }; + RectangleF bounds = new(QuantityCellBounds.X, y, QuantityCellBounds.Width, QuantityCellBounds.Height); + //Draw text to PDF page based on the layout result. + page.Graphics.DrawString("Grand Total:", arialBoldFont, PdfBrushes.Black, bounds, format); + //Draw the total amount value to PDF page based on the layout result. + bounds = new RectangleF(TotalPriceCellBounds.X, y, TotalPriceCellBounds.Width, TotalPriceCellBounds.Height); + page.Graphics.DrawString("$" + GetTotalAmount(grid).ToString(), arialBoldFont, PdfBrushes.Black, bounds); + #endregion + //Create border pen with custom dash style and draw the border to page. + borderPen.DashStyle = PdfDashStyle.Custom; + borderPen.DashPattern = new float[] { 3, 3 }; + graphics.DrawLine(borderPen, new PointF(0, pageHeight - 100), new PointF(pageWidth, pageHeight - 100)); + + //Get the image file stream from assembly. + Stream imageStream = assembly.GetManifestResourceStream(basePath + "AdventureWork.png"); + + //Create PDF bitmap image from stream. + PdfBitmap bitmap = new(imageStream); + //Draw the image to PDF page. + graphics.DrawImage(bitmap, new RectangleF(10, pageHeight - 90, 80, 80)); + + //Calculate the text position and draw the text to PDF page. + y = pageHeight - 100 + margin; + size = arialRegularFont.MeasureString("800 Interchange Blvd."); + x = pageWidth - size.Width - margin; + graphics.DrawString("800 Interchange Blvd.", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); + + //Calculate the text position and draw the text to PDF page. + y += arialRegularFont.Height + lineSpace; + size = arialRegularFont.MeasureString("Suite 2501, Austin, TX 78721"); + x = pageWidth - size.Width - margin; + graphics.DrawString("Suite 2501, Austin, TX 78721", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); + + //Calculate the text position and draw the text to PDF page. + y += arialRegularFont.Height + lineSpace; + size = arialRegularFont.MeasureString("Any Questions? support@adventure-works.com"); + x = pageWidth - size.Width - margin; + graphics.DrawString("Any Questions? support@adventure-works.com", arialRegularFont, PdfBrushes.Black, new PointF(x, y)); + + + //Add a new blank PDF page. + PdfPage page1 = document.Pages.Add(); + + //Draw the image to the PDF page. + page1.Graphics.DrawImage(bitmap, 0, 0, 200, 200); + + using MemoryStream ms = new(); + //Save the PDF document to MemoryStream. + document.Save(ms); + //Close the PDF document. + document.Close(true); + ms.Position = 0; + //Saves the memory stream as file using the SaveService instance. + SaveService save = new SaveService(); + save.SaveAndView("output.pdf", "application/pdf", ms); + + void Grid_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args) + { + PdfGrid grid = sender as PdfGrid; + if (args.CellIndex == grid.Columns.Count - 1) + { + //Get the bounds of price cell in grid row. + TotalPriceCellBounds = args.Bounds; + } + else if (args.CellIndex == grid.Columns.Count - 2) + { + //Get the bounds of quantity cell in grid row. + QuantityCellBounds = args.Bounds; + } + } + #region Helper Methods + //Create and row for the grid. + void AddProducts(string productId, string productName, double price, int quantity, double total, PdfGrid grid) { - string cellValue = grid.Rows[i].Cells[grid.Columns.Count - 1].Value.ToString(); - float result = float.Parse(cellValue, System.Globalization.CultureInfo.InvariantCulture); - Total += result; + //Add a new row and set the product value to grid row cells. + PdfGridRow row = grid.Rows.Add(); + row.Cells[0].Value = productId; + row.Cells[1].Value = productName; + row.Cells[2].Value = price.ToString(); + row.Cells[3].Value = quantity.ToString(); + row.Cells[4].Value = total.ToString(); } - return Total; + /// + /// Get the Total amount of purcharsed items. + /// + private float GetTotalAmount(PdfGrid grid) + { + float Total = 0f; + for (int i = 0; i < grid.Rows.Count; i++) + { + string cellValue = (grid.Rows[i].Cells[grid.Columns.Count - 1].Value as string)!.ToString(); + float result = float.Parse(cellValue, System.Globalization.CultureInfo.InvariantCulture); + Total += result; + } + return Total; + + } + #endregion + -} -#endregion {% endhighlight %}