Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions Annotations/Custom_stamp/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="Custom_Stamp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Custom_Stamp"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
14 changes: 14 additions & 0 deletions Annotations/Custom_stamp/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Configuration;
using System.Data;
using System.Windows;

namespace Custom_Stamp
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

}
10 changes: 10 additions & 0 deletions Annotations/Custom_stamp/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
3 changes: 3 additions & 0 deletions Annotations/Custom_stamp/Custom_Stamp.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="Custom_Stamp.csproj" />
</Solution>
12 changes: 12 additions & 0 deletions Annotations/Custom_stamp/Custom_stamp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.PdfViewer.WPF" Version="*" />
<PackageReference Include="System.Drawing.Common" Version="10.0.1" />
</ItemGroup>
<Import Project="targets\MultiTargeting.targets" />
</Project>
Binary file added Annotations/Custom_stamp/Data/Approved.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Annotations/Custom_stamp/Data/Input.pdf
Binary file not shown.
19 changes: 19 additions & 0 deletions Annotations/Custom_stamp/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Window x:Class="Custom_Stamp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Custom_Stamp" xmlns:syncfusion="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<!-- Button in the first row -->
<Button Grid.Row="0" Content="Button" Width="100" Height="30" Margin="10" Click="Button_Click"/>
<syncfusion:PdfViewerControl Grid.Row="1" x:Name="pdfViewer"></syncfusion:PdfViewerControl>
</Grid>
</Window>
71 changes: 71 additions & 0 deletions Annotations/Custom_stamp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using Syncfusion.Windows.PdfViewer;
using System;
using System.Drawing;
using System.IO;
using System.Windows;
using System.Windows.Media.Imaging;

namespace Custom_Stamp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
pdfViewer.Load("../../../Data/Input.pdf");
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string authorName = "John Doe";
string dateTimeText = DateTime.Now.ToString("dd-MMM-yyyy HH:mm");
string metaText = $"{authorName} | {dateTimeText}";

// Load original stamp image
Bitmap originalStamp = new Bitmap("../../../Data/Approved.png");

using (Graphics g = Graphics.FromImage(originalStamp))
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

using (Font font = new Font("Arial", 9))
{
SizeF textSize = g.MeasureString(metaText, font);

// Position text at bottom-right inside the image
float x = originalStamp.Width - textSize.Width - 10; // 10px padding from right
float y = originalStamp.Height - textSize.Height - 5; // 5px padding from bottom

g.DrawString(metaText, font, System.Drawing.Brushes.Black, new PointF(x, y));
}
}

// Convert to BitmapImage for WPF PdfViewer
BitmapImage bitmapImage;
using (MemoryStream ms = new MemoryStream())
{
originalStamp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
ms.Position = 0;

bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = ms;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
}

// Create PdfStampAnnotation
System.Windows.Controls.Image stampImage = new System.Windows.Controls.Image() { Source = bitmapImage };
PdfStampAnnotation stampAnnotation = new PdfStampAnnotation(stampImage);

// Add stamp to PDF
System.Windows.Point position = new System.Windows.Point(125, 108);
System.Drawing.Size stampSize = new System.Drawing.Size(originalStamp.Width, originalStamp.Height);
pdfViewer.AddStamp(stampAnnotation, 1, position, stampSize);

}
}
}
10 changes: 10 additions & 0 deletions Annotations/Custom_stamp/targets/MultiTargeting.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>
<PropertyGroup>
<TargetFrameworks>net462;net8.0-windows;net9.0-windows;net10.0-windows</TargetFrameworks>
<UseWPF>true</UseWPF>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<EnableDefaultItems>True</EnableDefaultItems>
<EnableDefaultEmbeddedResourceItems>True</EnableDefaultEmbeddedResourceItems>
</PropertyGroup>
</Project>