Skip to content

Commit

Permalink
add logo to pdf - add scale
Browse files Browse the repository at this point in the history
  • Loading branch information
jurczewski committed May 31, 2024
1 parent 1990057 commit 68c6d4c
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/PrivatePdfConverter/Commands/AddLogoToPdf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace PrivatePdfConverter.Commands;

public static class AddLogoToPdf
{
public static void Run(string path, string logoPath, string position, int? opacity, string? output)
public static void Run(string path, string logoPath, string position, int? scale, int? opacity, string? output)
{
if (!File.Exists(path))
{
Expand All @@ -27,14 +27,14 @@ public static void Run(string path, string logoPath, string position, int? opaci
using var pdfDoc = OpenPdfAndPrepareExportFile(path, output, out var exportFullPath);

var logo = LoadImage(logoPath);
SetScale(logo);
SetOpacity(opacity, logo);
SetScale(logo, scale);
SetOpacity(logo, opacity);
AddLogoToPages(pdfDoc, logo);

Log.Logger.Information("Created a new pdf at {ExportFullPath}", exportFullPath);
}

private static void SetOpacity(int? opacity, Image logo)
private static void SetOpacity(Image logo, int? opacity)
{
if (opacity.HasValue)
{
Expand All @@ -43,10 +43,19 @@ private static void SetOpacity(int? opacity, Image logo)
}
}

private static void SetScale(Image logo)
private static void SetScale(Image logo, int? scaleInPercent)
{
logo.SetAutoScaleWidth(true);
logo.SetAutoScaleHeight(true);
if (scaleInPercent.HasValue)
{
var scaleFloat = scaleInPercent.Value / 100f;
logo.Scale(scaleFloat, scaleFloat);
Log.Logger.Information("Scale: {Scale}%", scaleInPercent);
}
else
{
logo.SetAutoScaleWidth(true);
logo.SetAutoScaleHeight(true);
}
}

private static Image LoadImage(string logoPath)
Expand Down

0 comments on commit 68c6d4c

Please sign in to comment.