เพิ่มลายน้ำในหนังสือเวียน
This commit is contained in:
parent
6a08791d00
commit
e02fa90614
10 changed files with 115 additions and 20 deletions
2
.github/workflows/release_Retirement.yaml
vendored
2
.github/workflows/release_Retirement.yaml
vendored
|
|
@ -16,7 +16,7 @@ env:
|
|||
TOKEN_LINE: uxuK5hDzS2DsoC5piJBrWRLiz8GgY7iMZZldOWsDDF0
|
||||
|
||||
jobs:
|
||||
# act workflow_dispatch -W .github/workflows/release_retirement.yaml --input IMAGE_VER=test-v6.1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
|
||||
# act workflow_dispatch -W .github/workflows/release_retirement.yaml --input IMAGE_VER=retirement-1.0.0 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
|
||||
release-dev:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
|
|
|||
2
.github/workflows/release_command.yaml
vendored
2
.github/workflows/release_command.yaml
vendored
|
|
@ -16,7 +16,7 @@ env:
|
|||
TOKEN_LINE: uxuK5hDzS2DsoC5piJBrWRLiz8GgY7iMZZldOWsDDF0
|
||||
|
||||
jobs:
|
||||
# act workflow_dispatch -W .github/workflows/release_command.yaml --input IMAGE_VER=test-v6.1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
|
||||
# act workflow_dispatch -W .github/workflows/release_command.yaml --input IMAGE_VER=command-1.0.0 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
|
||||
release-dev:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
|
|
|||
2
.github/workflows/release_insignia.yaml
vendored
2
.github/workflows/release_insignia.yaml
vendored
|
|
@ -16,7 +16,7 @@ env:
|
|||
TOKEN_LINE: uxuK5hDzS2DsoC5piJBrWRLiz8GgY7iMZZldOWsDDF0
|
||||
|
||||
jobs:
|
||||
# act workflow_dispatch -W .github/workflows/release_insignia.yaml --input IMAGE_VER=test-v6.1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
|
||||
# act workflow_dispatch -W .github/workflows/release_insignia.yaml --input IMAGE_VER=insignia-1.0.0 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
|
||||
release-dev:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
|
|
|||
2
.github/workflows/release_orgEmployee.yaml
vendored
2
.github/workflows/release_orgEmployee.yaml
vendored
|
|
@ -16,7 +16,7 @@ env:
|
|||
TOKEN_LINE: uxuK5hDzS2DsoC5piJBrWRLiz8GgY7iMZZldOWsDDF0
|
||||
|
||||
jobs:
|
||||
# act workflow_dispatch -W .github/workflows/release_ore-employee.yaml --input IMAGE_VER=test-v6.1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
|
||||
# act workflow_dispatch -W .github/workflows/release_ore-employee.yaml --input IMAGE_VER=orgEmployee-1.0.0 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
|
||||
release-dev:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
|
|
|||
2
.github/workflows/release_placement.yaml
vendored
2
.github/workflows/release_placement.yaml
vendored
|
|
@ -16,7 +16,7 @@ env:
|
|||
TOKEN_LINE: uxuK5hDzS2DsoC5piJBrWRLiz8GgY7iMZZldOWsDDF0
|
||||
|
||||
jobs:
|
||||
# act workflow_dispatch -W .github/workflows/release_placement.yaml --input IMAGE_VER=test-v6.1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
|
||||
# act workflow_dispatch -W .github/workflows/release_placement.yaml --input IMAGE_VER=placement-1.0.0 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
|
||||
release-dev:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
|
|
|||
2
.github/workflows/release_report.yaml
vendored
2
.github/workflows/release_report.yaml
vendored
|
|
@ -16,7 +16,7 @@ env:
|
|||
TOKEN_LINE: uxuK5hDzS2DsoC5piJBrWRLiz8GgY7iMZZldOWsDDF0
|
||||
|
||||
jobs:
|
||||
# act workflow_dispatch -W .github/workflows/release_report.yaml --input IMAGE_VER=test-v6.1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
|
||||
# act workflow_dispatch -W .github/workflows/release_report.yaml --input IMAGE_VER=report-1.0.0 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
|
||||
release-dev:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="iTextSharp" Version="5.5.13.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.21" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0" />
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ using Telerik.Reporting.Processing;
|
|||
using System.IO;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Report.Service.Requests;
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text;
|
||||
|
||||
namespace BMA.EHR.Report.Service.Controllers
|
||||
{
|
||||
|
|
@ -30,6 +32,8 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
private readonly GenericReportGenerator _reportGenerator;
|
||||
private readonly RetireReportRepository _repository;
|
||||
private readonly MinIOService _documentService;
|
||||
// for add watermark
|
||||
private BaseFont baseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -127,13 +131,13 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
/// 36-บันทึกเวียนแจ้งการถึงแก่กรรม
|
||||
/// </summary>
|
||||
/// <param name="id">Id รายการบันทึกเวียนแจ้งการถึงแก่กรรม</param>
|
||||
/// <param name="exportType">pdf, docx หรือ xlsx</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("copy/36/{exportType}/{id}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetDeceasedReportCopyAsync(Guid id, string exportType = "pdf")
|
||||
[HttpGet("copy/36/{id}")]
|
||||
[AllowAnonymous]
|
||||
public async Task<ActionResult<ResponseObject>> GetDeceasedReportCopyAsync(Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -156,13 +160,13 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
DeceasedNumber = data.GetType().GetProperty("Number").GetValue(data),
|
||||
Location = data.GetType().GetProperty("Location").GetValue(data),
|
||||
};
|
||||
var mimeType = "";
|
||||
switch (exportType.Trim().ToLower())
|
||||
{
|
||||
case "pdf": mimeType = "application/pdf"; break;
|
||||
case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
|
||||
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
|
||||
}
|
||||
// var mimeType = "";
|
||||
// switch (exportType.Trim().ToLower())
|
||||
// {
|
||||
// case "pdf": mimeType = "application/pdf"; break;
|
||||
// case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
|
||||
// case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
|
||||
// }
|
||||
|
||||
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"36-บันทึกเวียนแจ้งการถึงแก่กรรม.trdp");
|
||||
ReportPackager reportPacker = new ReportPackager();
|
||||
|
|
@ -178,8 +182,44 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
ReportDocument = report,
|
||||
};
|
||||
ReportProcessor reportProcessor = new ReportProcessor(_configuration);
|
||||
RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo);
|
||||
return File(result.DocumentBytes, mimeType, $"รายละเอียดบันทึกเวียนแจ้งการถึงแก่กรรม.{exportType.Trim().ToLower()}");
|
||||
RenderingResult result = reportProcessor.RenderReport($"pdf", instanceReportSource, deviceInfo);
|
||||
// return File(result.DocumentBytes, mimeType, $"รายละเอียดบันทึกเวียนแจ้งการถึงแก่กรรม.{exportType.Trim().ToLower()}");
|
||||
|
||||
var now = DateTime.Now.ToString("yyyyMMdd-HHmmss");
|
||||
var file = System.IO.Path.Combine(_hostingEnvironment.WebRootPath, "tmp", $"tmp-{now}.pdf");
|
||||
var file_copy = System.IO.Path.Combine(_hostingEnvironment.WebRootPath, "tmp", $"tmp-{now}-copy.pdf");
|
||||
|
||||
try
|
||||
{
|
||||
// Copy to File
|
||||
System.IO.File.WriteAllBytes(file, result.DocumentBytes);
|
||||
var watermark_text = "COPY COPY COPY COPY";
|
||||
var fName = $"รายละเอียดบันทึกเวียนแจ้งการถึงแก่กรรม.pdf";
|
||||
|
||||
AddWatermark(file, file_copy, watermark_text);
|
||||
|
||||
using (var fileStream = new System.IO.FileStream(file_copy, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
fileStream.CopyTo(ms);
|
||||
ms.Flush();
|
||||
return File(ms.ToArray(), "application/octet-stream", fName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (System.IO.File.Exists(file))
|
||||
System.IO.File.Delete(file);
|
||||
|
||||
if (System.IO.File.Exists(file_copy))
|
||||
System.IO.File.Delete(file_copy);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -226,5 +266,58 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Add Watermark "
|
||||
|
||||
private void AddWaterMarkText(PdfContentByte pdfData, string watermarkText, BaseFont font, float fontSize, float angle, BaseColor color, iTextSharp.text.Rectangle realPageSize)
|
||||
{
|
||||
var gstate = new PdfGState { FillOpacity = 0.5f, StrokeOpacity = 0.3f };
|
||||
pdfData.SaveState();
|
||||
pdfData.SetGState(gstate);
|
||||
pdfData.SetColorFill(color);
|
||||
pdfData.BeginText();
|
||||
pdfData.SetFontAndSize(font, fontSize);
|
||||
var x = (realPageSize.Right + realPageSize.Left) / 2;
|
||||
var y = (realPageSize.Bottom + realPageSize.Top) / 2;
|
||||
pdfData.ShowTextAligned(Element.ALIGN_CENTER, watermarkText, x, y, angle);
|
||||
pdfData.EndText();
|
||||
pdfData.RestoreState();
|
||||
}
|
||||
|
||||
private bool AddWatermark(string inputfilepath, string outputfilepath, string watermark_text)
|
||||
{
|
||||
PdfReader pdfReader = null;
|
||||
PdfStamper pdfStamper = null;
|
||||
try
|
||||
{
|
||||
|
||||
pdfReader = new PdfReader(inputfilepath);
|
||||
int numberOfPages = pdfReader.NumberOfPages;
|
||||
iTextSharp.text.Rectangle pagesize = pdfReader.GetPageSize(1);
|
||||
pdfStamper = new PdfStamper(pdfReader, new FileStream(outputfilepath, FileMode.Create));
|
||||
|
||||
for (int i = 1; i <= numberOfPages; i++)
|
||||
{
|
||||
var dc = pdfStamper.GetOverContent(i);
|
||||
AddWaterMarkText(dc, watermark_text, baseFont, 30, 45, BaseColor.DARK_GRAY, pdfReader.GetPageSizeWithRotation(i));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.Message.Trim();
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (pdfStamper != null)
|
||||
pdfStamper.Close();
|
||||
|
||||
if (pdfReader != null)
|
||||
pdfReader.Close();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -551,7 +551,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
payload_attach.Add(new PayloadAttachment
|
||||
{
|
||||
name = "หนังสือเวียนถึงแก่กรรม",
|
||||
url = $"{_configuration["API"]}/copy/36/pdf/{retirementDeceased.Id}"
|
||||
url = $"{_configuration["APIV2"]}/report/deceased/copy/36/{retirementDeceased.Id}"
|
||||
});
|
||||
|
||||
var payload = new CommandPayload()
|
||||
|
|
|
|||
|
|
@ -33,5 +33,6 @@
|
|||
"BucketName": "bma-recruit"
|
||||
},
|
||||
"Protocol": "HTTPS",
|
||||
"API": "https://bma-ehr.frappet.synology.me/api/v1"
|
||||
"API": "https://bma-ehr.frappet.synology.me/api/v1",
|
||||
"APIV2": "https://bma-ehr.frappet.synology.me/api/v2"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue