init
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
/packages/
|
||||||
|
riderModule.iml
|
||||||
|
/_ReSharper.Caches/
|
||||||
16
PdfService.sln
Normal file
16
PdfService.sln
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PdfService", "PdfService\PdfService.csproj", "{D3E404EC-0CF7-44B7-B08E-B32825C4B9EC}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{D3E404EC-0CF7-44B7-B08E-B32825C4B9EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D3E404EC-0CF7-44B7-B08E-B32825C4B9EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D3E404EC-0CF7-44B7-B08E-B32825C4B9EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D3E404EC-0CF7-44B7-B08E-B32825C4B9EC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
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