PDF készítés DevExpressel.
This commit is contained in:
@@ -39,6 +39,30 @@ namespace WorkFlowCheck.API.Controllers
|
|||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
[HttpGet("CreatePDF/{id}")]
|
||||||
|
public async Task<ApiResponseDTO<byte[]>> CreatePDF(int id)
|
||||||
|
{
|
||||||
|
var retVal = new ApiResponseDTO<byte[]>()
|
||||||
|
{
|
||||||
|
IsSuccess = true,
|
||||||
|
};
|
||||||
|
var checkListHeader = await _checkListService.GetCheckListHeaderAsync(id);
|
||||||
|
var response = _checkListService.CreatePDF(id);
|
||||||
|
|
||||||
|
if (response != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
retVal.IsSuccess = true;
|
||||||
|
retVal.Data = response;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
retVal.IsSuccess = false;
|
||||||
|
retVal.Errors.Add("No data!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
[HttpGet("GetAllCheckListHeaders")]
|
[HttpGet("GetAllCheckListHeaders")]
|
||||||
public async Task<ApiResponseDTO<List<CheckListHeaderDTO>>> GetAllCheckListHeadersAsync()
|
public async Task<ApiResponseDTO<List<CheckListHeaderDTO>>> GetAllCheckListHeadersAsync()
|
||||||
{
|
{
|
||||||
|
|||||||
Binary file not shown.
@@ -1,108 +1,35 @@
|
|||||||
using Aspose.Words;
|
using DevExpress.XtraRichEdit;
|
||||||
using Aspose.Words.Tables;
|
|
||||||
using Serilog;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace WorkFlowCheck.BL.DocumentGenerator
|
namespace WorkFlowCheck.BL.DocumentGenerator
|
||||||
{
|
{
|
||||||
public class DokumentumGenerator
|
public class DokumentumGenerator
|
||||||
{
|
{
|
||||||
static DokumentumGenerator()
|
public static byte[] DocxToPdf(byte[] wordBytes)
|
||||||
{
|
{
|
||||||
Aspose.Words.License license = new Aspose.Words.License();
|
using (MemoryStream inputStream = new MemoryStream(wordBytes))
|
||||||
|
using (MemoryStream outputStream = new MemoryStream())
|
||||||
try
|
|
||||||
{
|
{
|
||||||
license.SetLicense("Aspose.Words.lic");
|
try
|
||||||
Log.Information("License set successfully.");
|
{
|
||||||
|
// RichEditDocumentServer használata a konverzióhoz
|
||||||
|
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
|
||||||
|
{
|
||||||
|
// Dokumentum betöltése a byte tömbből
|
||||||
|
wordProcessor.LoadDocument(inputStream, DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
|
||||||
|
|
||||||
|
// PDF formátumba mentés a memóriafolyamba
|
||||||
|
wordProcessor.ExportToPdf(outputStream);
|
||||||
|
|
||||||
|
// PDF byte tömb visszaadása
|
||||||
|
return outputStream.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hiba a konverzió során: " + ex.Message);
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Error(e, "\nThere was an error setting the license: " + e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] HtmlToDocx(string html)
|
|
||||||
{
|
|
||||||
byte[] generated = Encoding.UTF8.GetBytes(html);
|
|
||||||
var docHTML = new Aspose.Words.Document();
|
|
||||||
|
|
||||||
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(docHTML);
|
|
||||||
builder.InsertHtml(html);
|
|
||||||
|
|
||||||
docHTML.CompatibilityOptions.OptimizeFor(Aspose.Words.Settings.MsWordVersion.Word2016);
|
|
||||||
|
|
||||||
MemoryStream outStream = new MemoryStream();
|
|
||||||
docHTML.Save(outStream, Aspose.Words.SaveFormat.Docx);
|
|
||||||
|
|
||||||
generated = outStream.ToArray();
|
|
||||||
|
|
||||||
outStream.Dispose();
|
|
||||||
|
|
||||||
return generated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] HtmlToPdf(string html)
|
|
||||||
{
|
|
||||||
byte[] generated = Encoding.UTF8.GetBytes(html);
|
|
||||||
|
|
||||||
Stream inStream = new MemoryStream(generated);
|
|
||||||
var docHTML = new Aspose.Words.Document(inStream);
|
|
||||||
MemoryStream outStream = new MemoryStream();
|
|
||||||
docHTML.Save(outStream, Aspose.Words.SaveFormat.Pdf);
|
|
||||||
|
|
||||||
generated = outStream.ToArray();
|
|
||||||
|
|
||||||
inStream.Dispose();
|
|
||||||
outStream.Dispose();
|
|
||||||
|
|
||||||
return generated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] DocxToPdf(byte[] generated)
|
|
||||||
{
|
|
||||||
Stream inStream = new MemoryStream(generated);
|
|
||||||
var doc = new Aspose.Words.Document(inStream);
|
|
||||||
MemoryStream outStream = new MemoryStream();
|
|
||||||
doc.Save(outStream, Aspose.Words.SaveFormat.Pdf);
|
|
||||||
|
|
||||||
generated = outStream.ToArray();
|
|
||||||
|
|
||||||
inStream.Dispose();
|
|
||||||
outStream.Dispose();
|
|
||||||
|
|
||||||
return generated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] DocxToPdfForTopic(byte[] generated)
|
|
||||||
{
|
|
||||||
Stream inStream = new MemoryStream(generated);
|
|
||||||
var doc = new Aspose.Words.Document(inStream);
|
|
||||||
|
|
||||||
doc.Styles.DefaultFont.Name = "Times New Roman";
|
|
||||||
doc.Styles.DefaultFont.Size = 12;
|
|
||||||
|
|
||||||
var collection = doc.GetChildNodes(NodeType.Row, true);
|
|
||||||
|
|
||||||
foreach (Row row in collection)
|
|
||||||
{
|
|
||||||
row.RowFormat.Height = 40;
|
|
||||||
row.RowFormat.HeightRule = HeightRule.AtLeast;
|
|
||||||
}
|
|
||||||
|
|
||||||
MemoryStream outStream = new MemoryStream();
|
|
||||||
doc.Save(outStream, Aspose.Words.SaveFormat.Pdf);
|
|
||||||
|
|
||||||
generated = outStream.ToArray();
|
|
||||||
|
|
||||||
inStream.Dispose();
|
|
||||||
outStream.Dispose();
|
|
||||||
|
|
||||||
return generated;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -426,14 +426,22 @@ namespace WorkFlowCheck.BL.Services
|
|||||||
|
|
||||||
public byte[] CreatePDF(int checkListHeaderId)
|
public byte[] CreatePDF(int checkListHeaderId)
|
||||||
{
|
{
|
||||||
var location = System.Reflection.Assembly.GetEntryAssembly().Location;
|
try
|
||||||
var directory = System.IO.Path.GetDirectoryName(location);
|
{
|
||||||
byte[] byteArray = System.IO.File.ReadAllBytes(Path.Combine(directory, "DocumentGenerator", "CheckList_Template_V1.docx"));
|
string pdfDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Pdf");
|
||||||
SablonGenerator gen = new SablonGenerator(byteArray);
|
|
||||||
|
|
||||||
byte[] content = gen.CloseAndGetDocument();
|
byte[] byteArray = File.ReadAllBytes(Path.Combine(pdfDirectory, "CheckList_Template_V1.docx"));
|
||||||
|
SablonGenerator gen = new SablonGenerator(byteArray);
|
||||||
|
|
||||||
return DokumentumGenerator.DocxToPdf(content);
|
byte[] content = gen.CloseAndGetDocument();
|
||||||
|
|
||||||
|
return DokumentumGenerator.DocxToPdf(content);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex.Message);
|
||||||
|
}
|
||||||
|
return new byte[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Aspose.Words" Version="25.3.0" />
|
|
||||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||||
|
<PackageReference Include="DevExpress.Document.Processor" Version="24.2.6" />
|
||||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.3.0" />
|
<PackageReference Include="DocumentFormat.OpenXml" Version="3.3.0" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
|
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -115,7 +115,8 @@
|
|||||||
$('#tbCheckListHeadersPage').on('click', '.pdf-btn', function ()
|
$('#tbCheckListHeadersPage').on('click', '.pdf-btn', function ()
|
||||||
{
|
{
|
||||||
const row = table.row($(this).closest('tr')).data();
|
const row = table.row($(this).closest('tr')).data();
|
||||||
window.location.href = `@Url.Page("./CheckListHeaderEditPage")?id=${row.id}`;
|
window.location.href = `@Url.Page("./CheckListHeaderPage")?handler=CreatePDF&id=${row.id}`;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#tbCheckListHeadersPage').on('click', '.delete-btn', function ()
|
$('#tbCheckListHeadersPage').on('click', '.delete-btn', function ()
|
||||||
|
|||||||
+25
-2
@@ -22,14 +22,37 @@ namespace WorkFlowCheck.Web.Pages.CheckList.CheckListHeader
|
|||||||
}
|
}
|
||||||
public async Task OnGet()
|
public async Task OnGet()
|
||||||
{
|
{
|
||||||
CheckStatus = _checkListService.GetCheckStatus();
|
CheckStatus = _checkListService.GetCheckStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<JsonResult> OnGetLoadCheckListHeaders()
|
public async Task<JsonResult> OnGetLoadCheckListHeaders()
|
||||||
{
|
{
|
||||||
var results = await _checkListService.GetAllCheckListHeaderAsync();
|
var results = await _checkListService.GetAllCheckListHeaderAsync();
|
||||||
return new JsonResult(new { data = results });
|
return new JsonResult(new { data = results });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGetCreatePDF(int id)
|
||||||
|
{
|
||||||
|
var checkListHeaderDTO = await _checkListService.GetCheckListHeader(id);
|
||||||
|
|
||||||
|
var response = await _checkListService.CreatePDF(id);
|
||||||
|
|
||||||
|
if (response.IsSuccess)
|
||||||
|
{
|
||||||
|
var timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
|
||||||
|
var fileName = $"PH_{timestamp}_{checkListHeaderDTO.Id}.pdf";
|
||||||
|
var result = new FileContentResult(response.Data, "application/pdf")
|
||||||
|
{
|
||||||
|
FileDownloadName = fileName,
|
||||||
|
FileContents = response.Data
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new JsonResult(new { success = false });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace WorkFlowCheck.Web.Services
|
|||||||
public CheckListService(HttpClient httpClient, IConfiguration configuration, IHttpContextAccessor httpContextAccessor) : base(httpClient, configuration, httpContextAccessor)
|
public CheckListService(HttpClient httpClient, IConfiguration configuration, IHttpContextAccessor httpContextAccessor) : base(httpClient, configuration, httpContextAccessor)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<CheckListHeaderDTO>> GetAllCheckListHeaderAsync()
|
public async Task<List<CheckListHeaderDTO>> GetAllCheckListHeaderAsync()
|
||||||
{
|
{
|
||||||
var endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetAllCheckListHeaders";
|
var endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetAllCheckListHeaders";
|
||||||
@@ -60,6 +60,27 @@ namespace WorkFlowCheck.Web.Services
|
|||||||
}
|
}
|
||||||
public async Task<ApiResponseDTO<CheckListHeaderDTO>> UpdateCheckListHeader(CheckListHeaderDTO checkListHeaderDTO) => throw new NotImplementedException();
|
public async Task<ApiResponseDTO<CheckListHeaderDTO>> UpdateCheckListHeader(CheckListHeaderDTO checkListHeaderDTO) => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public async Task<ApiResponseDTO<byte[]>> CreatePDF(int id)
|
||||||
|
{
|
||||||
|
var retVal = new ApiResponseDTO<byte[]>();
|
||||||
|
var endpoint = $"{_httpClient.BaseAddress}api/CheckList/CreatePDF/{id}";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<byte[]>>(endpoint);
|
||||||
|
if (response != null)
|
||||||
|
{
|
||||||
|
if (response.IsSuccess)
|
||||||
|
{
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex.Message);
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateHeaderAsync()
|
public async Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateHeaderAsync()
|
||||||
{
|
{
|
||||||
@@ -250,5 +271,5 @@ namespace WorkFlowCheck.Web.Services
|
|||||||
.GetCustomAttribute<DisplayAttribute>()?.Name ?? enumValue.ToString();
|
.GetCustomAttribute<DisplayAttribute>()?.Name ?? enumValue.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace WorkFlowCheck.Web.Services.Interfaces
|
|||||||
Task<CheckListHeaderDTO> GetCheckListHeader(int id);
|
Task<CheckListHeaderDTO> GetCheckListHeader(int id);
|
||||||
Task<List<CheckListHeaderDTO>> GetAllCheckListHeaderAsync();
|
Task<List<CheckListHeaderDTO>> GetAllCheckListHeaderAsync();
|
||||||
Task<ApiResponseDTO<CheckListHeaderDTO>> UpdateCheckListHeader(CheckListHeaderDTO checkListHeaderDTO);
|
Task<ApiResponseDTO<CheckListHeaderDTO>> UpdateCheckListHeader(CheckListHeaderDTO checkListHeaderDTO);
|
||||||
|
Task<ApiResponseDTO<byte[]>> CreatePDF(int id);
|
||||||
|
|
||||||
Task<CheckListTemplateHeaderDTO> GetCheckListTemplateHeader(int id);
|
Task<CheckListTemplateHeaderDTO> GetCheckListTemplateHeader(int id);
|
||||||
Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateHeaderAsync();
|
Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateHeaderAsync();
|
||||||
|
|||||||
Reference in New Issue
Block a user