Skip to content

Commit 1b0b534

Browse files
Merge pull request #1 from SyncfusionExamples/InvoicePdf
EJDOTNETCORE-4737 updated sample and README.md file in .NET
2 parents 4002469 + 0306f8e commit 1b0b534

File tree

6 files changed

+334
-0
lines changed

6 files changed

+334
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33417.168
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InvoicePDFSample", "InvoicePDFSample\InvoicePDFSample.csproj", "{577565CF-FEE8-45FA-A31F-0A990FCF6439}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{577565CF-FEE8-45FA-A31F-0A990FCF6439}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{577565CF-FEE8-45FA-A31F-0A990FCF6439}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{577565CF-FEE8-45FA-A31F-0A990FCF6439}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{577565CF-FEE8-45FA-A31F-0A990FCF6439}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {0F428328-8D38-4322-8906-FC97CA5A0D6C}
24+
EndGlobalSection
25+
EndGlobal
3.38 KB
Loading
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="20.4.0.53" />
12+
</ItemGroup>
13+
14+
</Project>
219 KB
Loading
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
using Syncfusion.Drawing;
2+
using Syncfusion.Pdf;
3+
using Syncfusion.Pdf.Graphics;
4+
using Syncfusion.Pdf.Grid;
5+
6+
namespace InvoicePDFSample {
7+
internal class Program {
8+
static void Main(string[] args)
9+
{
10+
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Mgo+DSMBPh8sVXJ0S0J+XE9Hd1RDX3xKf0x/TGpQb19xflBPallYVBYiSV9jS3xSdEVkWHhfcnVTRGNbWQ==");
11+
12+
PdfDocument pdfDocument = new PdfDocument();
13+
PdfPage currentPage = pdfDocument.Pages.Add();
14+
SizeF clientSize = currentPage.GetClientSize();
15+
FileStream imageStream = new FileStream("../../../Data/icon.png", FileMode.Open, FileAccess.Read);
16+
PdfImage icon= new PdfBitmap(imageStream);
17+
SizeF iconSize = new SizeF(40, 40);
18+
PointF iconLocation = new PointF(14, 13);
19+
PdfGraphics graphics= currentPage.Graphics;
20+
graphics.DrawImage(icon,iconLocation,iconSize);
21+
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20, PdfFontStyle.Bold);
22+
var text = new PdfTextElement("INVOICE", font, new PdfSolidBrush(Color.FromArgb(1, 53, 67, 168)));
23+
text.StringFormat = new PdfStringFormat(PdfTextAlignment.Right);
24+
PdfLayoutResult result = text.Draw(currentPage, new PointF(clientSize.Width - 25, iconLocation.Y + 10));
25+
26+
font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
27+
text = new PdfTextElement("To ", font);
28+
result = text.Draw(currentPage, new PointF(14, result.Bounds.Bottom + 30));
29+
font = new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold);
30+
text = new PdfTextElement("John Smith,", font);
31+
result = text.Draw(currentPage, new PointF(14, result.Bounds.Bottom + 3));
32+
font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
33+
text = new PdfTextElement(string.Format("{0}, {1}", "398 W Broadway, Evanston Ave Fargo,", "\nNorth Dakota, 10012"), font);
34+
result = text.Draw(currentPage, new PointF(14, result.Bounds.Bottom + 3));
35+
36+
font = new PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Bold);
37+
text = new PdfTextElement("Invoice No.#23698720 ", font);
38+
text.StringFormat = new PdfStringFormat(PdfTextAlignment.Right);
39+
text.Draw(currentPage, new PointF(clientSize.Width - 25, result.Bounds.Y - 20));
40+
41+
PdfGrid grid=new PdfGrid();
42+
font= new PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Regular);
43+
grid.Style.Font = font;
44+
grid.Columns.Add(4);
45+
grid.Columns[1].Width = 70;
46+
grid.Columns[2].Width = 70;
47+
grid.Columns[3].Width = 70;
48+
49+
grid.Headers.Add(1);
50+
PdfStringFormat stringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
51+
PdfGridRow header = grid.Headers[0];
52+
53+
header.Cells[0].Value = "Item & description";
54+
header.Cells[0].StringFormat.LineAlignment = PdfVerticalAlignment.Middle;
55+
header.Cells[1].Value = "Hrs/Qty";
56+
header.Cells[1].StringFormat = stringFormat;
57+
header.Cells[2].Value = "Rate($)";
58+
header.Cells[2].StringFormat = stringFormat;
59+
header.Cells[3].Value = "Amount($)";
60+
header.Cells[3].StringFormat = stringFormat;
61+
62+
PdfGridRow row = grid.Rows.Add();
63+
row.Cells[0].Value = "API Development";
64+
row.Cells[0].StringFormat.LineAlignment = PdfVerticalAlignment.Middle;
65+
66+
row.Cells[1].Value = $"{25}";
67+
row.Cells[1].StringFormat = stringFormat;
68+
69+
row.Cells[2].Value = $"{24.46}";
70+
row.Cells[2].StringFormat = stringFormat;
71+
72+
decimal amount=(decimal)(25*24.46);
73+
row.Cells[3].Value = String.Format("{0:0.##}", amount);
74+
row.Cells[3].StringFormat = stringFormat;
75+
76+
decimal sum = 0;
77+
sum += amount;
78+
79+
row = grid.Rows.Add();
80+
row.Cells[0].Value = "Desktop Software Development";
81+
row.Cells[0].StringFormat.LineAlignment = PdfVerticalAlignment.Middle;
82+
row.Cells[1].Value = $"{25}";
83+
row.Cells[1].StringFormat = stringFormat;
84+
row.Cells[2].Value = $"{47.83}";
85+
row.Cells[2].StringFormat = stringFormat;
86+
amount = (decimal)(25 * 47.83);
87+
row.Cells[3].Value = String.Format("{0:0.##}", amount);
88+
row.Cells[3].StringFormat = stringFormat;
89+
90+
sum += amount;
91+
92+
row = grid.Rows.Add();
93+
row.Cells[0].Value = "Site admin development";
94+
row.Cells[0].StringFormat.LineAlignment = PdfVerticalAlignment.Middle;
95+
row.Cells[1].Value = $"{33}";
96+
row.Cells[1].StringFormat = stringFormat;
97+
row.Cells[2].Value = $"{85.1}";
98+
row.Cells[2].StringFormat = stringFormat;
99+
amount = (decimal)(33 * 85.1);
100+
row.Cells[3].Value = String.Format("{0:0.##}", amount);
101+
row.Cells[3].StringFormat = stringFormat;
102+
103+
sum += amount;
104+
105+
grid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent5);
106+
PdfGridStyle gridStyle = new PdfGridStyle();
107+
gridStyle.CellPadding=new PdfPaddings(5, 5, 5, 5);
108+
grid.Style = gridStyle;
109+
110+
PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();
111+
layoutFormat.Layout = PdfLayoutType.Paginate;
112+
result = grid.Draw(currentPage, 14, result.Bounds.Bottom + 30, clientSize.Width - 35, layoutFormat);
113+
114+
currentPage.Graphics.DrawRectangle(new PdfSolidBrush(Color.FromArgb(255, 239, 242, 255)),
115+
new RectangleF(result.Bounds.Right - 100, result.Bounds.Bottom + 20, 100, 20));
116+
117+
PdfTextElement element = new PdfTextElement("Total", font);
118+
element.Draw(currentPage, new RectangleF(result.Bounds.Right - 100, result.Bounds.Bottom + 22, result.Bounds.Width, result.Bounds.Height));
119+
120+
var totalPrice = $"$ {Math.Round(sum, 2)}";
121+
element = new PdfTextElement(totalPrice, font);
122+
element.StringFormat = new PdfStringFormat(PdfTextAlignment.Right);
123+
element.Draw(currentPage, new RectangleF(15, result.Bounds.Bottom + 22, result.Bounds.Width, result.Bounds.Height));
124+
125+
MemoryStream stream = new MemoryStream();
126+
pdfDocument.Save(stream);
127+
pdfDocument.Close(true);
128+
stream.Position = 0;
129+
File.WriteAllBytes("Output.pdf",stream.ToArray());
130+
}
131+
}
132+
}

README.md

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,165 @@
11
# How to Create a PDF Document in .NET Using the Syncfusion PDF Library
2+
3+
## Introduction
24
A quick start .NET console project that shows how to create a PDF document and add text, image, and table to it using the Syncfusion PDF Library.
5+
6+
## System requirement
7+
**Framework and SDKs**
8+
* .NET SDK (version 5.0 or later)
9+
10+
**IDEs**
11+
* Visual Studio 2019/ Visual Studio 2022
12+
13+
## Code snippet for simple PDF document with text, images, and tables
14+
we will create a new .NET console application, add the Syncfusion PDF library package, and write the code
15+
16+
```csharp
17+
PdfDocument pdfDocument = new PdfDocument();
18+
PdfPage currentPage = pdfDocument.Pages.Add();
19+
SizeF clientSize = currentPage.GetClientSize();
20+
FileStream imageStream = new FileStream("../../../Data/icon.png", FileMode.Open, FileAccess.Read);
21+
PdfImage icon= new PdfBitmap(imageStream);
22+
SizeF iconSize = new SizeF(40, 40);
23+
PointF iconLocation = new PointF(14, 13);
24+
PdfGraphics graphics= currentPage.Graphics;
25+
graphics.DrawImage(icon,iconLocation,iconSize);
26+
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20, PdfFontStyle.Bold);
27+
var text = new PdfTextElement("INVOICE", font, new PdfSolidBrush(Color.FromArgb(1, 53, 67, 168)));
28+
text.StringFormat= new PdfStringFormat(PdfTextAlignment.Right);
29+
PdfLayoutResult result = text.Draw(currentPage, new PointF(clientSize.Width - 25, iconLocation.Y + 10));
30+
31+
font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
32+
text = new PdfTextElement("To ", font);
33+
result = text.Draw(currentPage, new PointF(14, result.Bounds.Bottom + 30));
34+
font = new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold);
35+
text = new PdfTextElement("John Smith,", font);
36+
result = text.Draw(currentPage, new PointF(14, result.Bounds.Bottom + 3));
37+
font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
38+
text = new PdfTextElement(string.Format("{0}, {1}", "398 W Broadway, Evanston Ave Fargo,", "\nNorth Dakota, 10012"), font);
39+
result = text.Draw(currentPage, new PointF(14, result.Bounds.Bottom + 3));
40+
41+
font = new PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Bold);
42+
text = new PdfTextElement("Invoice No.#23698720 ", font);
43+
text.StringFormat = new PdfStringFormat(PdfTextAlignment.Right);
44+
text.Draw(currentPage, new PointF(clientSize.Width - 25, result.Bounds.Y - 20));
45+
46+
PdfGrid grid=new PdfGrid();
47+
font= new PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Regular);
48+
grid.Style.Font = font;
49+
grid.Columns.Add(4);
50+
grid.Columns[1].Width = 70;
51+
grid.Columns[2].Width = 70;
52+
grid.Columns[3].Width = 70;
53+
54+
grid.Headers.Add(1);
55+
PdfStringFormat stringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
56+
PdfGridRow header = grid.Headers[0];
57+
58+
header.Cells[0].Value= "Item & description";
59+
header.Cells[0].StringFormat.LineAlignment = PdfVerticalAlignment.Middle;
60+
header.Cells[1].Value = "Hrs/Qty";
61+
header.Cells[1].StringFormat = stringFormat;
62+
header.Cells[2].Value = "Rate($)";
63+
header.Cells[2].StringFormat = stringFormat;
64+
header.Cells[3].Value = "Amount($)";
65+
header.Cells[3].StringFormat = stringFormat;
66+
67+
PdfGridRow row = grid.Rows.Add();
68+
row.Cells[0].Value = "API Development";
69+
row.Cells[0].StringFormat.LineAlignment = PdfVerticalAlignment.Middle;
70+
71+
row.Cells[1].Value = $"{25}";
72+
row.Cells[1].StringFormat = stringFormat;
73+
74+
row.Cells[2].Value = $"{24.46}";
75+
row.Cells[2].StringFormat = stringFormat;
76+
77+
decimal amount = (decimal)(25 * 24.46);
78+
row.Cells[3].Value = String.Format("{0:0.##}", amount);
79+
row.Cells[3].StringFormat = stringFormat;
80+
81+
decimal sum = 0;
82+
sum += amount;
83+
84+
row = grid.Rows.Add();
85+
row.Cells[0].Value = "Desktop Software Development";
86+
row.Cells[0].StringFormat.LineAlignment = PdfVerticalAlignment.Middle;
87+
row.Cells[1].Value = $"{25}";
88+
row.Cells[1].StringFormat = stringFormat;
89+
row.Cells[2].Value = $"{47.83}";
90+
row.Cells[2].StringFormat = stringFormat;
91+
amount = (decimal)(25 * 47.83);
92+
row.Cells[3].Value = String.Format("{0:0.##}", amount);
93+
row.Cells[3].StringFormat = stringFormat;
94+
95+
sum += amount;
96+
97+
row = grid.Rows.Add();
98+
row.Cells[0].Value = "Site admin development";
99+
row.Cells[0].StringFormat.LineAlignment = PdfVerticalAlignment.Middle;
100+
row.Cells[1].Value = $"{33}";
101+
row.Cells[1].StringFormat = stringFormat;
102+
row.Cells[2].Value = $"{85.1}";
103+
row.Cells[2].StringFormat = stringFormat;
104+
amount = (decimal)(33 * 85.1);
105+
row.Cells[3].Value = String.Format("{0:0.##}", amount);
106+
row.Cells[3].StringFormat = stringFormat;
107+
108+
sum += amount;
109+
110+
grid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent5);
111+
PdfGridStyle gridStyle = new PdfGridStyle();
112+
gridStyle.CellPadding = new PdfPaddings(5, 5, 5, 5);
113+
grid.Style= gridStyle;
114+
115+
PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();
116+
layoutFormat.Layout = PdfLayoutType.Paginate;
117+
result = grid.Draw(currentPage, 14, result.Bounds.Bottom + 30, clientSize.Width - 35, layoutFormat);
118+
119+
currentPage.Graphics.DrawRectangle(new PdfSolidBrush(Color.FromArgb(255, 239, 242, 255)),
120+
new RectangleF(result.Bounds.Right - 100, result.Bounds.Bottom + 20, 100, 20));
121+
122+
PdfTextElement element = new PdfTextElement("Total", font);
123+
element.Draw(currentPage, new RectangleF(result.Bounds.Right - 100, result.Bounds.Bottom + 22, result.Bounds.Width, result.Bounds.Height));
124+
125+
var totalPrice = $"$ {Math.Round(sum, 2)}";
126+
element=new PdfTextElement(totalPrice, font);
127+
element.StringFormat = new PdfStringFormat(PdfTextAlignment.Right);
128+
element.Draw(currentPage, new RectangleF(15, result.Bounds.Bottom + 22, result.Bounds.Width, result.Bounds.Height));
129+
130+
MemoryStream stream = new MemoryStream();
131+
pdfDocument.Save(stream);
132+
pdfDocument.Close(true);
133+
stream.Position = 0;
134+
File.WriteAllBytes("Output.pdf",stream.ToArray());
135+
```
136+
137+
**Output Image**
138+
<img src="InvoicePDFSample/InvoicePDFSample/Output_images/Invoice.jpg" alt="output_image" width="100%" Height="Auto"/>
139+
140+
## How to run the examples
141+
* Download this project to a location in your disk.
142+
* Open the solution file using Visual Studio.
143+
* Rebuild the solution to install the required NuGet package.
144+
* Run the application.
145+
146+
## Resources
147+
* **Product page:** [Syncfusion PDF Framework](https://www.syncfusion.com/document-processing/pdf-framework/net)
148+
* **Documentation page:** [Syncfusion .NET PDF library](https://help.syncfusion.com/file-formats/pdf/overview)
149+
* **Online demo:** [Syncfusion .NET PDF library - Online demos](https://ej2.syncfusion.com/aspnetcore/PDF/CompressExistingPDF#/bootstrap5)
150+
* **Blog:** [Syncfusion .NET PDF library - Blog](https://www.syncfusion.com/blogs/category/pdf)
151+
* **Knowledge Base:** [Syncfusion .NET PDF library - Knowledge Base](https://www.syncfusion.com/kb/windowsforms/pdf)
152+
* **EBooks:** [Syncfusion .NET PDF library - EBooks](https://www.syncfusion.com/succinctly-free-ebooks)
153+
* **FAQ:** [Syncfusion .NET PDF library - FAQ](https://www.syncfusion.com/faq/)
154+
155+
## Support and feedback
156+
* For any other queries, reach our [Syncfusion support team](https://www.syncfusion.com/support/directtrac/incidents/newincident?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples) or post the queries through the [community forums](https://www.syncfusion.com/forums?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples).
157+
* Request new feature through [Syncfusion feedback portal](https://www.syncfusion.com/feedback?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples).
158+
159+
## License
160+
This is a commercial product and requires a paid license for possession or use. Syncfusion’s licensed software, including this component, is subject to the terms and conditions of [Syncfusion's EULA](https://www.syncfusion.com/eula/es/?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples). You can purchase a licnense [here](https://www.syncfusion.com/sales/products?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples) or start a free 30-day trial [here](https://www.syncfusion.com/account/manage-trials/start-trials?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples).
161+
162+
## About Syncfusion
163+
Founded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion has more than 26,000+ customers and more than 1 million users, including large financial institutions, Fortune 500 companies, and global IT consultancies.
164+
165+
Today, we provide 1600+ components and frameworks for web ([Blazor](https://www.syncfusion.com/blazor-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [ASP.NET Core](https://www.syncfusion.com/aspnet-core-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [ASP.NET MVC](https://www.syncfusion.com/aspnet-mvc-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [ASP.NET WebForms](https://www.syncfusion.com/jquery/aspnet-webforms-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [JavaScript](https://www.syncfusion.com/javascript-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Angular](https://www.syncfusion.com/angular-ui-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [React](https://www.syncfusion.com/react-ui-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Vue](https://www.syncfusion.com/vue-ui-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), and [Flutter](https://www.syncfusion.com/flutter-widgets?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples)), mobile ([Xamarin](https://www.syncfusion.com/xamarin-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Flutter](https://www.syncfusion.com/flutter-widgets?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [UWP](https://www.syncfusion.com/uwp-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), and [JavaScript](https://www.syncfusion.com/javascript-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples)), and desktop development ([WinForms](https://www.syncfusion.com/winforms-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [WPF](https://www.syncfusion.com/wpf-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [WinUI(Preview)](https://www.syncfusion.com/winui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Flutter](https://www.syncfusion.com/flutter-widgets?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples) and [UWP](https://www.syncfusion.com/uwp-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples)). We provide ready-to-deploy enterprise software for dashboards, reports, data integration, and big data processing. Many customers have saved millions in licensing fees by deploying our software.

0 commit comments

Comments
 (0)