diff --git a/ZPDuszynska/Controllers/HomeController.cs b/ZPDuszynska/Controllers/HomeController.cs index a5f421d..ff1c346 100644 --- a/ZPDuszynska/Controllers/HomeController.cs +++ b/ZPDuszynska/Controllers/HomeController.cs @@ -71,42 +71,16 @@ namespace ZPDuszynska.Controllers public IActionResult Tabliczki() { Tabliczka1Model model = new Tabliczka1Model(); - model.Line1_1 = "Z głębokim żalem zawiadamiamy, że dnia "; - model.Line1_2 = "1 stycznia "; - model.Line1_3 = "2025 roku"; + model.Line1_1 = "ŚP. "; + model.Line1_2 = "Zbigniew"; - model.Line2_1 = "odszedł od nas na zawsze w wieku "; - model.Line2_2 = "66 "; - model.Line2_3 = "lat"; + model.Line2_1 = "KOWALSKI"; - model.Line3_1 = "ŚP. "; - model.Line3_2 = "JAN"; - - model.Line4_1 = "KOWALSKI"; - - model.Line11_1 = ""; - model.Line11_2 = ""; - - model.Line5_1 = "Dom Żałoby: "; - - model.Line6_1 = "Wystawienie Zmarłego w Kościele o godz. "; - model.Line6_2 = "13.30"; - - model.Line7_1 = "Msza Święta Żałobna odprawiona zostanie w Kościele w Milejowie"; - - model.Line8_1 = "dnia "; - model.Line8_2 = "8 marca "; - model.Line8_3 = "2025r. ("; - model.Line8_4 = "sobota"; - model.Line8_5 = ") o godz. "; - model.Line8_6 = "14.00"; - model.Line8_7 = ", po której nastąpi"; - - model.Line9_1 = "odprowadzenie Zmarłego na miejscowy cmentarz rzymskokatolicki"; - - model.Line10_1 = "Pogrążona w smutku "; - model.Line10_2 = "NAJBLIŻSZA RODZINA"; + model.Line3_1 = "żył lat "; + model.Line3_2 = "99 "; + model.Line3_3 = "zm. 01 I 2025"; + model.Line4_1 = "Prosi o modlitwę"; return View(model); } @@ -187,129 +161,6 @@ namespace ZPDuszynska.Controllers new MyText { text = model.Line10_2, fontBold = true, fontSize = 20 } } }; - if (!string.IsNullOrWhiteSpace(model.Line11_1+model.Line11_2)) - { - MyTextLine l4 = new MyTextLine - { - texts = new List() { - new MyText { text = model.Line4_1, fontBold = true, fontSize = 110 } } - }; - MyTextLine l11 = new MyTextLine - { - texts = new List() { - new MyText { text = model.Line11_1, fontBold = false, fontSize = 30 }, - new MyText { text = model.Line11_2, fontBold = true, fontSize = 40 } } - }; - AddTextToPdf(cb, PdfPCell.ALIGN_CENTER, 70, 415, 700, l4); - AddTextToPdf(cb, PdfPCell.ALIGN_CENTER, 70, 290, 700, l11); - } - else - { - MyTextLine l4 = new MyTextLine - { - texts = new List() { - new MyText { text = model.Line4_1, fontBold = true, fontSize = 150 } } - }; - AddTextToPdf(cb, PdfPCell.ALIGN_CENTER, 70, 415, 700, l4); - } - - AddTextToPdf(cb, PdfPCell.ALIGN_CENTER, 70, 550, 700, l1); - AddTextToPdf(cb, PdfPCell.ALIGN_CENTER, 70, 523, 700, l2); - AddTextToPdf(cb, PdfPCell.ALIGN_CENTER, 70, 490, 600, l3); - AddTextToPdf(cb, PdfPCell.ALIGN_CENTER, 70, 240, 700, l5); - AddTextToPdf(cb, PdfPCell.ALIGN_CENTER, 70, 215, 700, l6); - AddTextToPdf(cb, PdfPCell.ALIGN_CENTER, 70, 190, 700, l7); - AddTextToPdf(cb, PdfPCell.ALIGN_CENTER, 70, 165, 700, l8); - AddTextToPdf(cb, PdfPCell.ALIGN_CENTER, 70, 140, 700, l9); - AddTextToPdf(cb, PdfPCell.ALIGN_RIGHT, 70, 102, 720, l10); - - document.Close(); - var result = ms.ToArray(); - - ms.Close(); - writer.Close(); - reader.Close(); - - Response.Headers["Content-Disposition"] = "inline; filename=Nekrolog.pdf"; - return File(result.ToArray(), "application/pdf"); - } - - [HttpPost] - [Authorize] - public ActionResult Tabliczki(Tabliczka1Model model) - { - string inputPath = "nekrolog_template.pdf"; - - iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(inputPath); - Rectangle size = reader.GetPageSizeWithRotation(1); - iTextSharp.text.Document document = new iTextSharp.text.Document(size); - MemoryStream ms = new MemoryStream(); - PdfWriter writer = PdfWriter.GetInstance(document, ms); - document.Open(); - - PdfContentByte cb = writer.DirectContent; - PdfImportedPage page = writer.GetImportedPage(reader, 1); - cb.AddTemplate(page, 0, 0); - - MyTextLine l1 = new MyTextLine - { - texts = new List() { - new MyText { text = model.Line1_1, fontBold = false, fontSize = 34 }, - new MyText { text = model.Line1_2, fontBold = true, fontSize = 34 }, - new MyText { text = model.Line1_3, fontBold = false, fontSize = 34 } } - }; - MyTextLine l2 = new MyTextLine - { - texts = new List() { - new MyText { text = model.Line2_1, fontBold = false, fontSize = 34 }, - new MyText { text = model.Line2_2, fontBold = true, fontSize = 44 }, - new MyText { text = model.Line2_3, fontBold = false, fontSize = 34 } } - }; - MyTextLine l3 = new MyTextLine - { - texts = new List() { - new MyText { text = model.Line3_1, fontBold = false, fontSize = 50 }, - new MyText { text = model.Line3_2, fontBold = true, fontSize = 90 } } - }; - MyTextLine l5 = new MyTextLine - { - texts = new List() { - new MyText { text = model.Line5_1, fontBold = false, fontSize = 32 } } - }; - MyTextLine l6 = new MyTextLine - { - texts = new List() { - new MyText { text = model.Line6_1, fontBold = false, fontSize = 32 }, - new MyText { text = model.Line6_2, fontBold = true, fontSize = 32 } } - }; - MyTextLine l7 = new MyTextLine - { - texts = new List() { - new MyText { text = model.Line7_1, fontBold = false, fontSize = 32 } } - }; - MyTextLine l8 = new MyTextLine - { - texts = new List() { - new MyText { text = model.Line8_1, fontBold = false, fontSize = 32 }, - new MyText { text = model.Line8_2, fontBold = true, fontSize = 32 }, - new MyText { text = model.Line8_3, fontBold = false, fontSize = 32 }, - new MyText { text = model.Line8_4, fontBold = true, fontSize = 32 }, - new MyText { text = model.Line8_5, fontBold = false, fontSize = 32 }, - new MyText { text = model.Line8_6, fontBold = true, fontSize = 32 }, - new MyText { text = model.Line8_7, fontBold = false, fontSize = 32 } } - }; - MyTextLine l9 = new MyTextLine - { - texts = new List() { - new MyText { text = model.Line9_1, fontBold = false, fontSize = 32 } } - }; - MyTextLine l10 = new MyTextLine - { - texts = new List() { - new MyText { text = model.Line10_1, fontBold = false, fontSize = 20 }, - new MyText { text = model.Line10_2, fontBold = true, fontSize = 20 } } - }; - if (!string.IsNullOrWhiteSpace(model.Line11_1 + model.Line11_2)) { MyTextLine l4 = new MyTextLine @@ -357,7 +208,100 @@ namespace ZPDuszynska.Controllers return File(result.ToArray(), "application/pdf"); } + [HttpPost] + [Authorize] + public ActionResult Tabliczki(Tabliczka1Model model) + { + string inputPath = "tabliczka_template.pdf"; + iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(inputPath); + Rectangle size = reader.GetPageSizeWithRotation(1); + iTextSharp.text.Document document = new iTextSharp.text.Document(size); + MemoryStream ms = new MemoryStream(); + PdfWriter writer = PdfWriter.GetInstance(document, ms); + document.Open(); + + PdfContentByte cb = writer.DirectContent; + PdfImportedPage page = writer.GetImportedPage(reader, 1); + cb.AddTemplate(page, 0, 0); + + MyTextLine l1 = new MyTextLine + { + texts = new List() { + new MyText { text = model.Line1_1, fontBold = false, fontSize = 40 }, + new MyText { text = model.Line1_2, fontBold = true, fontSize = 90 }} + }; + MyTextLine l2 = new MyTextLine + { + texts = new List() { + new MyText { text = model.Line2_1, fontBold = true, fontSize = 130 }} + }; + MyTextLine l3 = new MyTextLine + { + texts = new List() { + new MyText { text = model.Line3_1, fontBold = false, fontSize = 60 }, + new MyText { text = model.Line3_2, fontBold = true, fontSize = 60 }, + new MyText { text = model.Line3_3, fontBold = false, fontSize = 60 } } + }; + MyTextLine l4 = new MyTextLine + { + texts = new List() { + new MyText { text = model.Line4_1, fontBold = false, fontSize = 50 } } + }; + + AddTextToPdf(cb, PdfPCell.ALIGN_CENTER, 270, 480, 515-70, l1); + AddTextToPdf(cb, PdfPCell.ALIGN_CENTER, 210, 400, 500, l2); + AddTextToPdf(cb, PdfPCell.ALIGN_CENTER, 145, 250, 550, l3); + AddTextToPdf(cb, PdfPCell.ALIGN_CENTER, 125, 170, 590, l4); + + document.Close(); + var result = ms.ToArray(); + + ms.Close(); + writer.Close(); + reader.Close(); + + Response.Headers["Content-Disposition"] = "inline; filename=Tabliczka.pdf"; + //return File(result.ToArray(), "application/pdf"); + return File(CreateMirroredPdf(result.ToArray()), "application/pdf"); + } + + byte[] CreateMirroredPdf(byte[] pdfBytes) + { + using (MemoryStream inputStream = new MemoryStream(pdfBytes)) + using (MemoryStream outputStream = new MemoryStream()) + { + PdfReader reader = new PdfReader(inputStream); + Document document = new Document(reader.GetPageSizeWithRotation(1)); + + try + { + PdfWriter writer = PdfWriter.GetInstance(document, outputStream); + document.Open(); + PdfContentByte cb = writer.DirectContent; + + for (int i = 1; i <= reader.NumberOfPages; i++) + { + document.NewPage(); + PdfImportedPage page = writer.GetImportedPage(reader, i); + float pageWidth = reader.GetPageSize(i).Width; + + // **🔹 Lustrzane odbicie strony w poziomie** + cb.SaveState(); + cb.ConcatCTM(-1, 0, 0, 1, pageWidth, 0); + cb.AddTemplate(page, 0, 0); + cb.RestoreState(); + } + } + finally + { + document.Close(); // Musimy jawnie zamknąć dokument! + reader.Close(); + } + + return outputStream.ToArray(); // Zwracamy PDF jako `byte[]` + } + } public IActionResult Privacy() { return View(); @@ -414,6 +358,7 @@ namespace ZPDuszynska.Controllers // cell.MinimumHeight = height; // cell.FixedHeight = height; cell.Border = PdfPCell.NO_BORDER; + //cell.Border = PdfPCell.BOTTOM_BORDER|PdfPCell.LEFT_BORDER | PdfPCell.RIGHT_BORDER | PdfPCell.TOP_BORDER; table.AddCell(cell); table.TotalWidth = width; table.WriteSelectedRows(0, -1, x, y, cb); diff --git a/ZPDuszynska/Models/Tabliczka1Model.cs b/ZPDuszynska/Models/Tabliczka1Model.cs index 7722722..673e8d9 100644 --- a/ZPDuszynska/Models/Tabliczka1Model.cs +++ b/ZPDuszynska/Models/Tabliczka1Model.cs @@ -4,39 +4,13 @@ { public string Line1_1 { get; set; } public string Line1_2 { get; set; } - public string Line1_3 { get; set; } public string Line2_1 { get; set; } - public string Line2_2 { get; set; } - public string Line2_3 { get; set; } public string Line3_1 { get; set; } public string Line3_2 { get; set; } + public string Line3_3 { get; set; } public string Line4_1 { get; set; } - - public string Line11_1 { get; set; } - public string Line11_2 { get; set; } - - public string Line5_1 { get; set; } - - public string Line6_1 { get; set; } - public string Line6_2 { get; set; } - - public string Line7_1 { get; set; } - - public string Line8_1 { get; set; } - public string Line8_2 { get; set; } - public string Line8_3 { get; set; } - public string Line8_4 { get; set; } - public string Line8_5 { get; set; } - public string Line8_6 { get; set; } - public string Line8_7 { get; set; } - - public string Line9_1 { get; set; } - - public string Line10_1 { get; set; } - public string Line10_2 { get; set; } - } } diff --git a/ZPDuszynska/Properties/launchSettings.json b/ZPDuszynska/Properties/launchSettings.json index 3d7a2b1..1549c80 100644 --- a/ZPDuszynska/Properties/launchSettings.json +++ b/ZPDuszynska/Properties/launchSettings.json @@ -35,6 +35,16 @@ }, "publishAllPorts": true, "useSSL": true + }, + "WSL": { + "commandName": "WSL2", + "launchBrowser": true, + "launchUrl": "https://localhost:7223", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_URLS": "https://localhost:7223;http://localhost:5169" + }, + "distributionName": "" } }, "$schema": "http://json.schemastore.org/launchsettings.json", diff --git a/ZPDuszynska/Views/Home/Tabliczki.cshtml b/ZPDuszynska/Views/Home/Tabliczki.cshtml index 4dc39dd..286d69e 100644 --- a/ZPDuszynska/Views/Home/Tabliczki.cshtml +++ b/ZPDuszynska/Views/Home/Tabliczki.cshtml @@ -10,55 +10,22 @@
-
+
-
- - - +
+
- +
-
- - -
-
- -
-
- - -
-
- -
-
- - - - - - - -
-
- -
-
- - -
-
diff --git a/ZPDuszynska/Views/Shared/_Layout.cshtml b/ZPDuszynska/Views/Shared/_Layout.cshtml index 6a5823a..a7d1470 100644 --- a/ZPDuszynska/Views/Shared/_Layout.cshtml +++ b/ZPDuszynska/Views/Shared/_Layout.cshtml @@ -24,7 +24,7 @@ - } diff --git a/ZPDuszynska/ZPDuszynska.csproj b/ZPDuszynska/ZPDuszynska.csproj index c65c608..e4d03d7 100644 --- a/ZPDuszynska/ZPDuszynska.csproj +++ b/ZPDuszynska/ZPDuszynska.csproj @@ -35,6 +35,9 @@ Always + + Always + Always diff --git a/ZPDuszynska/tabliczka_template.pdf b/ZPDuszynska/tabliczka_template.pdf new file mode 100644 index 0000000..06cac02 Binary files /dev/null and b/ZPDuszynska/tabliczka_template.pdf differ