init
This commit is contained in:
15
PdfService/PdfService.csproj
Normal file
15
PdfService/PdfService.csproj
Normal file
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Stimulsoft.Reports.Net" Version="2025.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
48
PdfService/Program.cs
Normal file
48
PdfService/Program.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Newtonsoft.Json;
|
||||
using PdfService;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapPost("/Print", async (HttpContext context) =>
|
||||
{
|
||||
var request = context.Request;
|
||||
var boundary = request.ContentType.Split("boundary=")[1];
|
||||
var reader = new MultipartReader(boundary, request.Body);
|
||||
|
||||
MultipartSection section;
|
||||
var parts = new List<(string ContentType, string Content, string ConentDisposition)>();
|
||||
|
||||
while ((section = await reader.ReadNextSectionAsync()) != null)
|
||||
{
|
||||
using var sr = new StreamReader(section.Body);
|
||||
var content = await sr.ReadToEndAsync();
|
||||
var contentType = section.ContentType;
|
||||
var contentDisposition = section.ContentDisposition;
|
||||
|
||||
parts.Add((contentType, content, contentDisposition));
|
||||
}
|
||||
|
||||
string reportTemplate = "";
|
||||
string fileName = "";
|
||||
dynamic data = null;
|
||||
|
||||
foreach (var part in parts)
|
||||
{
|
||||
if (part.ContentType == "application/json")
|
||||
{
|
||||
data = JsonConvert.DeserializeObject(part.Content);
|
||||
}
|
||||
else if (part.ContentType == "application/xml")
|
||||
{
|
||||
reportTemplate = part.Content;
|
||||
fileName = part.ConentDisposition?.Split(".")[1];
|
||||
}
|
||||
}
|
||||
|
||||
var reportStream = Reporter.Print(reportTemplate, data);
|
||||
return Results.File(reportStream, "application/pdf", $"{fileName}.pdf");
|
||||
});
|
||||
|
||||
app.Run();
|
||||
38
PdfService/Properties/launchSettings.json
Normal file
38
PdfService/Properties/launchSettings.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:61601",
|
||||
"sslPort": 44358
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5155",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7054;http://localhost:5155",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
PdfService/Reporter.cs
Normal file
21
PdfService/Reporter.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Stimulsoft.Report;
|
||||
using Stimulsoft.Report.Export;
|
||||
|
||||
namespace PdfService;
|
||||
|
||||
public static class Reporter
|
||||
{
|
||||
public static Stream Print(string reportTemplate, object data)
|
||||
{
|
||||
var report = new StiReport();
|
||||
|
||||
report.LoadFromString(reportTemplate);
|
||||
report.RegBusinessObject("Data", data);
|
||||
report.Render(false);
|
||||
|
||||
var stream = new MemoryStream();
|
||||
report.ExportDocument(StiExportFormat.Pdf ,stream);
|
||||
stream.Position = 0;
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
8
PdfService/appsettings.Development.json
Normal file
8
PdfService/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
PdfService/appsettings.json
Normal file
9
PdfService/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user