-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20fc109
commit 1e3cea2
Showing
53 changed files
with
863 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/HtmlGenerator/IHtmlGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace ClassifiedAds.CrossCuttingConcerns.HtmlGenerator | ||
{ | ||
public interface IHtmlGenerator | ||
{ | ||
Task<string> GenerateAsync(string template, object model); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/PdfConverter/IPdfConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace ClassifiedAds.CrossCuttingConcerns.PdfConverter | ||
{ | ||
public interface IPdfConverter | ||
{ | ||
Stream Convert(string html, PdfOptions pdfOptions = null); | ||
|
||
Task<Stream> ConvertAsync(string html, PdfOptions pdfOptions = null); | ||
} | ||
|
||
public class PdfOptions | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/Microservices/Common/ClassifiedAds.Infrastructure/HtmlGenerators/HtmlGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using ClassifiedAds.CrossCuttingConcerns.HtmlGenerator; | ||
using RazorLight; | ||
using System.Threading.Tasks; | ||
|
||
namespace ClassifiedAds.Infrastructure.HtmlGenerators | ||
{ | ||
public class HtmlGenerator : IHtmlGenerator | ||
{ | ||
private readonly IRazorLightEngine _razorLightEngine; | ||
|
||
public HtmlGenerator(IRazorLightEngine razorLightEngine) | ||
{ | ||
_razorLightEngine = razorLightEngine; | ||
} | ||
|
||
public Task<string> GenerateAsync(string template, object model) | ||
{ | ||
return _razorLightEngine.CompileRenderAsync(template, model); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...s/Common/ClassifiedAds.Infrastructure/HtmlGenerators/HtmlGeneratorCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using ClassifiedAds.CrossCuttingConcerns.HtmlGenerator; | ||
using ClassifiedAds.Infrastructure.HtmlGenerators; | ||
using RazorLight; | ||
using System; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static class HtmlGeneratorCollectionExtensions | ||
{ | ||
public static IServiceCollection AddHtmlGenerator(this IServiceCollection services) | ||
{ | ||
var engine = new RazorLightEngineBuilder() | ||
.UseFileSystemProject(Environment.CurrentDirectory) | ||
.UseMemoryCachingProvider() | ||
.Build(); | ||
|
||
services.AddSingleton<IRazorLightEngine>(engine); | ||
services.AddSingleton<IHtmlGenerator, HtmlGenerator>(); | ||
|
||
return services; | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...ervices/Common/ClassifiedAds.Infrastructure/PdfConverters/DinkToPdf/DinkToPdfConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using ClassifiedAds.CrossCuttingConcerns.PdfConverter; | ||
using DinkToPdf; | ||
using DinkToPdf.Contracts; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace ClassifiedAds.Infrastructure.PdfConverters.DinkToPdf | ||
{ | ||
public class DinkToPdfConverter : IPdfConverter | ||
{ | ||
private readonly IConverter _converter; | ||
|
||
public DinkToPdfConverter(IConverter converter) | ||
{ | ||
_converter = converter; | ||
} | ||
|
||
public Stream Convert(string html, PdfOptions pdfOptions = null) | ||
{ | ||
var doc = new HtmlToPdfDocument() | ||
{ | ||
GlobalSettings = | ||
{ | ||
ColorMode = ColorMode.Color, | ||
Orientation = Orientation.Portrait, | ||
PaperSize = PaperKind.A4, | ||
Margins = new MarginSettings() { Top = 10, Bottom = 15, Left = 10, Right = 10 }, | ||
}, | ||
Objects = | ||
{ | ||
new ObjectSettings() | ||
{ | ||
PagesCount = true, | ||
HtmlContent = html, | ||
WebSettings = { DefaultEncoding = "utf-8", Background = true }, | ||
HeaderSettings = { FontSize = 9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 }, | ||
}, | ||
}, | ||
}; | ||
|
||
byte[] pdf = _converter.Convert(doc); | ||
|
||
return new MemoryStream(pdf); | ||
} | ||
|
||
public Task<Stream> ConvertAsync(string html, PdfOptions pdfOptions = null) | ||
{ | ||
return Task.FromResult(Convert(html, pdfOptions)); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ifiedAds.Infrastructure/PdfConverters/DinkToPdf/DinkToPdfConverterCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using ClassifiedAds.CrossCuttingConcerns.PdfConverter; | ||
using ClassifiedAds.Infrastructure.PdfConverters.DinkToPdf; | ||
using DinkToPdf; | ||
using DinkToPdf.Contracts; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static class DinkToPdfConverterCollectionExtensions | ||
{ | ||
public static IServiceCollection AddDinkToPdfConverter(this IServiceCollection services) | ||
{ | ||
services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); | ||
services.AddSingleton<IPdfConverter, DinkToPdfConverter>(); | ||
|
||
return services; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...mmon/ClassifiedAds.Infrastructure/PdfConverters/PuppeteerSharp/PuppeteerSharpConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using ClassifiedAds.CrossCuttingConcerns.PdfConverter; | ||
using PuppeteerSharp; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace ClassifiedAds.Infrastructure.PdfConverters.PuppeteerSharp | ||
{ | ||
public class PuppeteerSharpConverter : IPdfConverter | ||
{ | ||
public Stream Convert(string html, CrossCuttingConcerns.PdfConverter.PdfOptions pdfOptions = null) | ||
{ | ||
return ConvertAsync(html, pdfOptions).GetAwaiter().GetResult(); | ||
} | ||
|
||
public async Task<Stream> ConvertAsync(string html, CrossCuttingConcerns.PdfConverter.PdfOptions pdfOptions = null) | ||
{ | ||
await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }); | ||
await using var page = await browser.NewPageAsync(); | ||
await page.SetContentAsync(html); | ||
return new MemoryStream(await page.PdfDataAsync(new global::PuppeteerSharp.PdfOptions | ||
{ | ||
PrintBackground = true, | ||
})); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...nfrastructure/PdfConverters/PuppeteerSharp/PuppeteerSharpConverterCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using ClassifiedAds.CrossCuttingConcerns.PdfConverter; | ||
using ClassifiedAds.Infrastructure.PdfConverters.PuppeteerSharp; | ||
using PuppeteerSharp; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static class PuppeteerSharpConverterCollectionExtensions | ||
{ | ||
public static IServiceCollection AddPuppeteerSharpPdfConverter(this IServiceCollection services) | ||
{ | ||
var browserFetcher = new BrowserFetcher(); | ||
browserFetcher.DownloadAsync().GetAwaiter().GetResult(); | ||
|
||
services.AddSingleton<IPdfConverter, PuppeteerSharpConverter>(); | ||
|
||
return services; | ||
} | ||
} | ||
} |
Binary file added
BIN
+28.4 MB
src/Microservices/Common/libs/libwkhtmltox/libwkhtmltox-0.12.4-x64.dll
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+42.3 MB
src/Microservices/Common/libs/libwkhtmltox/libwkhtmltox-0.12.4-x86.dll
Binary file not shown.
Binary file added
BIN
+41.2 MB
src/Microservices/Common/libs/libwkhtmltox/libwkhtmltox-0.12.4-x86.so
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.