Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language support for watermarks #645

Merged
merged 6 commits into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Storage/Controllers/ContentOnDemandController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
{
(Instance instance, _) = await _instanceRepository.GetOne(instanceGuid, true);
DataElement htmlElement = instance.Data.First(d => d.Id == dataGuid.ToString());
string htmlFormId = htmlElement.Metadata.First(m => m.Key == "formid").Value;

Check warning on line 150 in src/Storage/Controllers/ContentOnDemandController.cs

View workflow job for this annotation

GitHub Actions / Build, test & analyze

Define a constant instead of using this literal 'formid' 4 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
DataElement xmlElement = instance.Data.First(d => d.Metadata.First(m => m.Key == "formid").Value == htmlFormId && d.Id != htmlElement.Id);
string visiblePagesString = xmlElement.Metadata.FirstOrDefault(m => m.Key == "A2VisiblePages")?.Value;
List<int> visiblePages = !string.IsNullOrEmpty(visiblePagesString) ? visiblePagesString.Split(';').Select(int.Parse).ToList() : null;
Expand Down Expand Up @@ -183,8 +183,18 @@
MemoryStream pdfStream = new();
mergedDoc.Save(pdfStream);

instance.DataValues.TryGetValue("A2ArchRefTs", out string watermark);
watermark = (watermark ?? ((DateTime)instance.Created).ToLocalTime().ToString("dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture))
DateTime created;
if (instance.DataValues.TryGetValue("A2ArchRefTs", out string a2ArchRefTs))
{
created = DateTime.ParseExact(a2ArchRefTs, "dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture);
}
else
{
created = ((DateTime)instance.Created).ToLocalTime();
}

string timestampFormat = language == "en" ? "MM/dd/yyyy hh:mm:ss tt" : "dd.MM.yyyy HH:mm:ss";
string watermark = created.ToString(timestampFormat, CultureInfo.InvariantCulture)
+ $" AR{instance.DataValues["A2ArchRef"]}";

using var finalPdfDocument = PdfReader.Open(pdfStream, PdfDocumentOpenMode.Modify);
Expand Down
Loading