diff --git a/src/WorkFlowCheck.API/Pdf/515590b6-79a6-43fe-a866-4e6d099fc7d3.docx b/src/WorkFlowCheck.API/Pdf/515590b6-79a6-43fe-a866-4e6d099fc7d3.docx deleted file mode 100644 index d1f06b2..0000000 Binary files a/src/WorkFlowCheck.API/Pdf/515590b6-79a6-43fe-a866-4e6d099fc7d3.docx and /dev/null differ diff --git a/src/WorkFlowCheck.API/WorkFlowCheck.API.csproj b/src/WorkFlowCheck.API/WorkFlowCheck.API.csproj index 9b5fc97..45d5f36 100644 --- a/src/WorkFlowCheck.API/WorkFlowCheck.API.csproj +++ b/src/WorkFlowCheck.API/WorkFlowCheck.API.csproj @@ -28,6 +28,7 @@ + diff --git a/src/WorkFlowCheck.BL/DocumentGenerator/DokumentumGenerator.cs b/src/WorkFlowCheck.BL/DocumentGenerator/DokumentumGenerator.cs index dc2837c..4e96ef5 100644 --- a/src/WorkFlowCheck.BL/DocumentGenerator/DokumentumGenerator.cs +++ b/src/WorkFlowCheck.BL/DocumentGenerator/DokumentumGenerator.cs @@ -1,10 +1,13 @@ -using System.Diagnostics; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using System.Diagnostics; namespace WorkFlowCheck.BL.DocumentGenerator { public class DokumentumGenerator { - public static byte[] DocxToPdfL(byte[] wordBytes) + public static byte[] DocxToPdfL(byte[] wordBytes, List imagePaths = null) { string pdfDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Pdf"); string fileName = Guid.NewGuid().ToString(); @@ -17,6 +20,24 @@ namespace WorkFlowCheck.BL.DocumentGenerator // Word fájl mentése ideiglenes fájlba File.WriteAllBytes(tempWordPath, wordBytes); + if (imagePaths != null && imagePaths.Count > 0) + { + using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(tempWordPath, true)) + { + MainDocumentPart mainPart = wordDoc.MainDocumentPart; + foreach (string imagePath in imagePaths) + { + if (File.Exists(imagePath)) + { + InsertImageAsNewPage(mainPart, imagePath); + } + } + + wordDoc.MainDocumentPart.Document.Save(); + } + } + + // LibreOffice parancssori konverzió ProcessStartInfo startInfo = new ProcessStartInfo { @@ -54,6 +75,148 @@ namespace WorkFlowCheck.BL.DocumentGenerator return null; } } + private static void InsertImageAsNewPage(MainDocumentPart mainPart, string imagePath) + { + string fileName = Path.GetFileName(imagePath); + + // Kép méretezés – max szélesség/magasság A4 hasznos területhez igazítva + using var image = SixLabors.ImageSharp.Image.Load(imagePath); + int pixelWidth = image.Width; + int pixelHeight = image.Height; + + long maxWidth = 5760000L; // kb. 16 cm + long maxHeight = 7200000L; // kb. 20 cm + + double aspectRatio = (double)pixelHeight / pixelWidth; + long finalWidth = maxWidth; + long finalHeight = (long)(maxWidth * aspectRatio); + + if (finalHeight > maxHeight) + { + finalHeight = maxHeight; + finalWidth = (long)(maxHeight / aspectRatio); + } + + // Kép hozzáadása Word dokumentumhoz + ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); + using (FileStream stream = new FileStream(imagePath, FileMode.Open)) + { + imagePart.FeedData(stream); + } + + string imagePartId = mainPart.GetIdOfPart(imagePart); + Drawing drawing = CreateImageDrawing(imagePartId, finalWidth, finalHeight); + + // Kép beillesztése középre igazítva + Paragraph imageParagraph = new Paragraph(new Run(drawing)) + { + ParagraphProperties = new ParagraphProperties( + new Justification() { Val = JustificationValues.Center } + ) + }; + + TableCell imageCell = new TableCell(imageParagraph, + new TableCellProperties( + new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center }, + new TableCellWidth() { Type = TableWidthUnitValues.Pct, Width = "10000" } + )); + + // Képes sor (magas, kitölti az oldalt) + TableRow imageRow = new TableRow(imageCell); + imageRow.AppendChild(new TableRowProperties( + new TableRowHeight() { Val = 9000, HeightType = HeightRuleValues.Exact } + )); + + // Fájlnév beillesztése középre + Paragraph fileNamePara = new Paragraph(new Run(new Text(fileName))) + { + ParagraphProperties = new ParagraphProperties( + new Justification() { Val = JustificationValues.Center } + ) + }; + + TableCell fileNameCell = new TableCell(fileNamePara, + new TableCellProperties( + new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center }, + new TableCellWidth() { Type = TableWidthUnitValues.Pct, Width = "10000" } + )); + + // Fájlnév sor (normál magasság) + TableRow fileNameRow = new TableRow(fileNameCell); + fileNameRow.AppendChild(new TableRowProperties( + new TableRowHeight() { Val = 400, HeightType = HeightRuleValues.Auto } + )); + + // Táblázat – szegély nélkül, teljes oldalszélességben + Table table = new Table( + new TableProperties( + new TableWidth { Width = "10000", Type = TableWidthUnitValues.Pct }, + new TableBorders( + new TopBorder { Val = BorderValues.None }, + new BottomBorder { Val = BorderValues.None }, + new LeftBorder { Val = BorderValues.None }, + new RightBorder { Val = BorderValues.None }, + new InsideHorizontalBorder { Val = BorderValues.None }, + new InsideVerticalBorder { Val = BorderValues.None } + ) + ), + imageRow, + fileNameRow + ); + + // Új oldal és a táblázat beszúrása a dokumentum végére + Body body = mainPart.Document.Body; + body.Append(new Paragraph(new Run(new Break() { Type = BreakValues.Page }))); + body.Append(table); + } + + + private static Drawing CreateImageDrawing(string relationshipId, long width, long height) + { + return new Drawing( + new DocumentFormat.OpenXml.Drawing.Wordprocessing.Inline( + new DocumentFormat.OpenXml.Drawing.Wordprocessing.Extent() { Cx = width, Cy = height }, + new DocumentFormat.OpenXml.Drawing.Wordprocessing.EffectExtent() + { + LeftEdge = 0L, + TopEdge = 0L, + RightEdge = 0L, + BottomEdge = 0L + }, + new DocumentFormat.OpenXml.Drawing.Wordprocessing.DocProperties() + { + Id = (UInt32Value)1U, + Name = "Inserted Image" + }, + new DocumentFormat.OpenXml.Drawing.Graphic( + new DocumentFormat.OpenXml.Drawing.GraphicData( + new DocumentFormat.OpenXml.Drawing.Pictures.Picture( + new DocumentFormat.OpenXml.Drawing.Pictures.NonVisualPictureProperties( + new DocumentFormat.OpenXml.Drawing.Pictures.NonVisualDrawingProperties() + { + Id = (UInt32Value)0U, + Name = "Picture" + }, + new DocumentFormat.OpenXml.Drawing.Pictures.NonVisualPictureDrawingProperties()), + new DocumentFormat.OpenXml.Drawing.Pictures.BlipFill( + new DocumentFormat.OpenXml.Drawing.Blip() + { + Embed = relationshipId + }, + new DocumentFormat.OpenXml.Drawing.Stretch( + new DocumentFormat.OpenXml.Drawing.FillRectangle())), + new DocumentFormat.OpenXml.Drawing.Pictures.ShapeProperties( + new DocumentFormat.OpenXml.Drawing.Transform2D( + new DocumentFormat.OpenXml.Drawing.Offset() { X = 0L, Y = 0L }, + new DocumentFormat.OpenXml.Drawing.Extents() { Cx = width, Cy = height }), + new DocumentFormat.OpenXml.Drawing.PresetGeometry( + new DocumentFormat.OpenXml.Drawing.AdjustValueList()) + { Preset = DocumentFormat.OpenXml.Drawing.ShapeTypeValues.Rectangle })) + ) + { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" }) + ) + { DistanceFromTop = 0U, DistanceFromBottom = 0U, DistanceFromLeft = 0U, DistanceFromRight = 0U }); + } } } diff --git a/src/WorkFlowCheck.BL/Services/CheckListService.cs b/src/WorkFlowCheck.BL/Services/CheckListService.cs index 96145ce..518d2e6 100644 --- a/src/WorkFlowCheck.BL/Services/CheckListService.cs +++ b/src/WorkFlowCheck.BL/Services/CheckListService.cs @@ -27,8 +27,8 @@ namespace WorkFlowCheck.BL.Services private readonly IMapper _mapper; private readonly INumberGeneratorService _numberGeneratorService; - public CheckListService(AppDbContext dbContext, - IMapper mapper, + public CheckListService(AppDbContext dbContext, + IMapper mapper, INumberGeneratorService numberGeneratorService, IUserService userService) { @@ -288,7 +288,13 @@ namespace WorkFlowCheck.BL.Services byte[] content = gen.CloseAndGetDocument(); - return DokumentumGenerator.DocxToPdfL(content); + string imageDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Images"); + + var images = checkListHeader.CheckListRowDTO.Where(w => (w.CheckListTemplateRowDTO.AnswerType == "P" || w.CheckListTemplateRowDTO.AnswerType == "PN") && + string.IsNullOrEmpty(w.Answer) != true) + .Select(s => Path.Combine(imageDirectory, s.Answer)) + .ToList(); + return DokumentumGenerator.DocxToPdfL(content, images); } catch (Exception ex) { @@ -315,8 +321,8 @@ namespace WorkFlowCheck.BL.Services await _dbContext.SaveChangesAsync(); - - + + retVal = true; } } diff --git a/src/WorkFlowCheck.BL/WorkFlowCheck.BL.csproj b/src/WorkFlowCheck.BL/WorkFlowCheck.BL.csproj index ea0d8bb..08827ad 100644 --- a/src/WorkFlowCheck.BL/WorkFlowCheck.BL.csproj +++ b/src/WorkFlowCheck.BL/WorkFlowCheck.BL.csproj @@ -13,6 +13,7 @@ + diff --git a/src/WorkFlowCheck.Web/WorkFlowCheck.Web.csproj b/src/WorkFlowCheck.Web/WorkFlowCheck.Web.csproj index a1c750c..eace772 100644 --- a/src/WorkFlowCheck.Web/WorkFlowCheck.Web.csproj +++ b/src/WorkFlowCheck.Web/WorkFlowCheck.Web.csproj @@ -33,6 +33,7 @@ +