Skip to content

Commit

Permalink
Added Thumbnail to the PdfWriteDefines.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Feb 28, 2024
1 parent b85bd76 commit f66b8aa
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Magick.NET/Formats/Pdf/PdfWriteDefines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public MagickFormat Format
/// </summary>
public string? Subject { get; set; }

/// <summary>
/// Gets or sets a value indicating wether a thumbnail should be added to the pdf document (pdf:thumbnail).
/// </summary>
public bool? Thumbnail { get; set; }

/// <summary>
/// Gets or sets the title of the pdf document (pdf:title).
/// </summary>
Expand Down Expand Up @@ -85,6 +90,9 @@ public IEnumerable<IDefine> Defines
if (Subject?.Length > 0)
yield return new MagickDefine(Format, "subject", Subject);

if (Thumbnail.HasValue)
yield return new MagickDefine(Format, "thumbnail", Thumbnail.Value);

if (Title?.Length > 0)
yield return new MagickDefine(Format, "title", Title);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void ShouldNotSetAnyDefine()
Assert.Null(image.Settings.GetDefine(MagickFormat.Pdf, "modify-epoch"));
Assert.Null(image.Settings.GetDefine(MagickFormat.Pdf, "producer"));
Assert.Null(image.Settings.GetDefine(MagickFormat.Pdf, "subject"));
Assert.Null(image.Settings.GetDefine(MagickFormat.Pdf, "thumbnail"));
Assert.Null(image.Settings.GetDefine(MagickFormat.Pdf, "title"));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

using ImageMagick;
using ImageMagick.Formats;
using Xunit;

namespace Magick.NET.Tests;

public partial class PdfWriteDefinesTests
{
public class TheThumbnailProperty
{
[Fact]
public void ShouldSetTheDefineWhenValueIsSet()
{
using var image = new MagickImage(MagickColors.Magenta, 1, 1);
image.Settings.SetDefines(new PdfWriteDefines
{
Thumbnail = true,
});

Assert.Equal("true", image.Settings.GetDefine(MagickFormat.Pdf, "thumbnail"));
}

[Fact]
public void ShouldNotSetTheDefineWhenValueIsNotSet()
{
using var image = new MagickImage();
image.Settings.SetDefines(new PdfWriteDefines
{
Thumbnail = null,
});

Assert.Null(image.Settings.GetDefine(MagickFormat.Pdf, "thumbnail"));
}
}
}

0 comments on commit f66b8aa

Please sign in to comment.