Skip to content

Commit bba3ea5

Browse files
committed
Add PdfPig
1 parent 44fb235 commit bba3ea5

File tree

12 files changed

+122
-4
lines changed

12 files changed

+122
-4
lines changed

App/App.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<ProjectReference Include="..\Libs\IronPdfLib\IronPdfLib.csproj" />
1111
<ProjectReference Include="..\Libs\ITextSharpPdfLib\ITextSharpPdfLib.csproj" />
1212
<ProjectReference Include="..\Libs\MigraDocCoreLib\MigraDocCoreLib.csproj" />
13+
<ProjectReference Include="..\Libs\PdfPigLib\PdfPigLib.csproj" />
1314
<ProjectReference Include="..\Libs\PdfSharpLib\PdfSharpLib.csproj" />
1415
<ProjectReference Include="..\Libs\PugPdfLib\PugPdfLib.csproj" />
1516
<ProjectReference Include="..\Libs\PuppeteerPdfLib\PuppeteerPdfLib.csproj" />

App/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using ITextSharpPdfLib;
77
using Microsoft.Extensions.DependencyInjection;
88
using MigraDocCoreLib;
9+
using PdfPigLib;
910
using PdfSharpLib;
1011
using PugPdfLib;
1112
using PuppeteerPdfLib;
@@ -22,6 +23,7 @@
2223
.AddITextSharpPdfLib()
2324
.AddPdfSharpLib()
2425
.AddMigraDocCoreLib()
26+
.AddPdfPigLib()
2527
.AddPugPdfLib()
2628
.AddPuppeteerPdfLib()
2729
.AddQuestPdfLib()

Directory.Packages.props

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
55
</PropertyGroup>
66
<ItemGroup>
7-
<PackageVersion Include="Aspose.PDF" Version="25.8.0" />
7+
<PackageVersion Include="Aspose.PDF" Version="25.9.0" />
88
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
99
<PackageVersion Include="DinkToPdf" Version="1.0.8" />
1010
<PackageVersion Include="DinkToPdf.Standard" Version="1.1.0" />
@@ -16,10 +16,11 @@
1616
<PackageVersion Include="itext7" Version="9.3.0" />
1717
<PackageVersion Include="itext7.bouncy-castle-adapter" Version="9.3.0" />
1818
<PackageVersion Include="itext7.bouncy-castle-fips-adapter" Version="9.3.0" />
19-
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.8" />
20-
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.8" />
19+
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.9" />
20+
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.9" />
2121
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
2222
<PackageVersion Include="MigraDocCore.Rendering" Version="1.3.67" />
23+
<PackageVersion Include="PdfPig" Version="0.1.11" />
2324
<PackageVersion Include="PdfSharpCore" Version="1.3.67" />
2425
<PackageVersion Include="Polybioz.HtmlRenderer.PdfSharp.Core" Version="1.1.0" />
2526
<PackageVersion Include="PugPDF.Core" Version="1.0.9" />
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Contracts;
2+
using Microsoft.Extensions.DependencyInjection;
3+
4+
namespace PdfPigLib;
5+
6+
public static class DependencyInjection
7+
{
8+
public static IServiceCollection AddPdfPigLib(this IServiceCollection services)
9+
{
10+
services.AddTransient<IPdfGenerator, PdfGenerator>();
11+
return services;
12+
}
13+
}

Libs/PdfPigLib/PdfGenerator.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Contracts;
2+
using UglyToad.PdfPig.Content;
3+
using UglyToad.PdfPig.Core;
4+
using UglyToad.PdfPig.Fonts.Standard14Fonts;
5+
using UglyToad.PdfPig.Writer;
6+
7+
namespace PdfPigLib;
8+
9+
public sealed class PdfGenerator : IPdfGenerator
10+
{
11+
public async Task GenerateAsync(string text, string filename, CancellationToken cancellationToken)
12+
{
13+
using var builder = new PdfDocumentBuilder();
14+
var page = builder.AddPage(PageSize.A4);
15+
var font = builder.AddStandard14Font(Standard14Font.Helvetica);
16+
page.AddText(text, fontSize: 12, position: new PdfPoint(25, 700), font);
17+
var bytes = builder.Build();
18+
await File.WriteAllBytesAsync(filename, bytes, cancellationToken);
19+
}
20+
}

Libs/PdfPigLib/PdfPigLib.csproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="PdfPig" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\Contracts\Contracts.csproj" />
15+
</ItemGroup>
16+
17+
</Project>

PdfGeneratorDemo.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MigraDocCoreLib", "Libs\Mig
6969
EndProject
7070
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MigraDocCoreLibTests", "Tests\MigraDocCoreLibTests\MigraDocCoreLibTests.csproj", "{5164B7F5-C338-4693-9E38-59AD2FF54CF7}"
7171
EndProject
72+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PdfPigLib", "Libs\PdfPigLib\PdfPigLib.csproj", "{AC29F061-445D-4729-95CE-53D489EFD3E6}"
73+
EndProject
74+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PdfPigLibTests", "Tests\PdfPigLibTests\PdfPigLibTests.csproj", "{87FBC0C5-E4E9-4DFC-B33A-CAAFCAAF0AEB}"
75+
EndProject
7276
Global
7377
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7478
Debug|Any CPU = Debug|Any CPU
@@ -179,6 +183,14 @@ Global
179183
{5164B7F5-C338-4693-9E38-59AD2FF54CF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
180184
{5164B7F5-C338-4693-9E38-59AD2FF54CF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
181185
{5164B7F5-C338-4693-9E38-59AD2FF54CF7}.Release|Any CPU.Build.0 = Release|Any CPU
186+
{AC29F061-445D-4729-95CE-53D489EFD3E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
187+
{AC29F061-445D-4729-95CE-53D489EFD3E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
188+
{AC29F061-445D-4729-95CE-53D489EFD3E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
189+
{AC29F061-445D-4729-95CE-53D489EFD3E6}.Release|Any CPU.Build.0 = Release|Any CPU
190+
{87FBC0C5-E4E9-4DFC-B33A-CAAFCAAF0AEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
191+
{87FBC0C5-E4E9-4DFC-B33A-CAAFCAAF0AEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
192+
{87FBC0C5-E4E9-4DFC-B33A-CAAFCAAF0AEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
193+
{87FBC0C5-E4E9-4DFC-B33A-CAAFCAAF0AEB}.Release|Any CPU.Build.0 = Release|Any CPU
182194
EndGlobalSection
183195
GlobalSection(SolutionProperties) = preSolution
184196
HideSolutionNode = FALSE
@@ -208,6 +220,8 @@ Global
208220
{7FF6B45B-E376-4CA2-AA1F-7A41EF6C0AE7} = {A852D5D4-4528-424B-978C-B04CA6D9A4F2}
209221
{45ADA4FA-7ED0-4942-A2EE-887C5B1D226C} = {87F3D6C7-3C6B-41AD-94C0-A26C4D076CCF}
210222
{5164B7F5-C338-4693-9E38-59AD2FF54CF7} = {A852D5D4-4528-424B-978C-B04CA6D9A4F2}
223+
{AC29F061-445D-4729-95CE-53D489EFD3E6} = {87F3D6C7-3C6B-41AD-94C0-A26C4D076CCF}
224+
{87FBC0C5-E4E9-4DFC-B33A-CAAFCAAF0AEB} = {A852D5D4-4528-424B-978C-B04CA6D9A4F2}
211225
EndGlobalSection
212226
GlobalSection(ExtensibilityGlobals) = postSolution
213227
SolutionGuid = {B89CF2D0-E7E3-45A6-A487-1E4E2875AF75}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ In this demo, i m generating a pdf file using various libraries :
1313
- [SpirePdf](https://www.e-iceblue.com/Introduce/pdf-for-net-introduce.html)
1414
- [SelectPdf](https://selectpdf.com/community-edition)
1515
- [AsposePdf](https://products.aspose.com/pdf/net)
16+
- [PdfPig](https://github.com/UglyToad/PdfPig)
1617
- [PugPdf](https://github.com/pug-pelle-p/pugpdf)
1718
- [DinkToPdf](https://github.com/rdvojmoc/DinkToPdf)
1819
- [WkHtmlToPdf](https://github.com/HakanL/WkHtmlToPdf-DotNet)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using AwesomeAssertions;
2+
using PdfPigLib;
3+
4+
namespace PdfPigLibTests;
5+
6+
public class PdfGeneratorTests
7+
{
8+
[Fact]
9+
public async Task Should_Generate_Pdf_File()
10+
{
11+
// arrange
12+
var cancellationToken = CancellationToken.None;
13+
var filename = $"PdfPigLibTests-{DateTime.Now:yyMMddHHmmss}.pdf";
14+
var generator = new PdfGenerator();
15+
16+
// act
17+
await generator.GenerateAsync("Hello World", filename, cancellationToken);
18+
19+
// assert
20+
File.Exists(filename).Should().BeTrue();
21+
}
22+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<IsPackable>false</IsPackable>
5+
<IsTestProject>true</IsTestProject>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="AwesomeAssertions" />
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
11+
<PackageReference Include="xunit" />
12+
<PackageReference Include="xunit.runner.visualstudio">
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
<PrivateAssets>all</PrivateAssets>
15+
</PackageReference>
16+
<PackageReference Include="coverlet.collector">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<ProjectReference Include="..\..\Libs\PdfPigLib\PdfPigLib.csproj" />
24+
</ItemGroup>
25+
26+
</Project>

0 commit comments

Comments
 (0)