Skip to content

Commit 7d9bf6f

Browse files
committed
995158-1: Added performance metrics sample code.
1 parent a18aed2 commit 7d9bf6f

35 files changed

+375
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="Apply-watermark/Apply-watermark.csproj" />
3+
</Solution>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<RootNamespace>Apply_watermark</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="31.2.12" />
13+
</ItemGroup>
14+
15+
</Project>

Performance Metrics/Input/JavaScript_Succinctly.pdf renamed to Performance Metrics/.NET/Apply-watermark/Apply-watermark/Data/JavaScript_Succinctly.pdf

File renamed without changes.

Performance Metrics/Input/PDF_Succinctly.pdf renamed to Performance Metrics/.NET/Apply-watermark/Apply-watermark/Data/PDF_Succinctly.pdf

File renamed without changes.

Performance Metrics/.NET/Apply-watermark/Apply-watermark/Output/gitkeep.txt

Whitespace-only changes.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using Syncfusion.Pdf;
2+
using Syncfusion.Pdf.Graphics;
3+
using Syncfusion.Pdf.Parsing;
4+
using System.Diagnostics;
5+
using Syncfusion.Drawing;
6+
7+
class Program
8+
{
9+
private static readonly PdfFont WatermarkFont = new PdfStandardFont(PdfFontFamily.Helvetica, 60, PdfFontStyle.Bold);
10+
private static readonly PdfBrush WatermarkBrush = new PdfSolidBrush(Color.Gray);
11+
private const string WatermarkText = "CONFIDENTIAL";
12+
13+
static void Main()
14+
{
15+
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR LICENSE KEY");
16+
string inputFolder = Path.GetFullPath("../../../Data/");
17+
string outputFolder = Path.GetFullPath("../../../Output/");
18+
Directory.CreateDirectory(outputFolder);
19+
string[] files = Directory.GetFiles(inputFolder, "*.pdf");
20+
foreach (string inputPath in files)
21+
{
22+
string fileName = Path.GetFileName(inputPath);
23+
string outputPath = Path.Combine(outputFolder, fileName);
24+
Stopwatch stopwatch = Stopwatch.StartNew();
25+
try
26+
{
27+
PdfLoadedDocument document = new PdfLoadedDocument(inputPath);
28+
// Apply watermark to all pages
29+
foreach (PdfPageBase page in document.Pages)
30+
{
31+
AddWatermark(page.Graphics, page.Size);
32+
}
33+
document.Save(outputPath);
34+
stopwatch.Stop();
35+
Console.WriteLine($"{fileName} Apply watermark processed in {stopwatch.Elapsed.TotalSeconds:F2} seconds");
36+
document.Close(true);
37+
}
38+
catch (Exception ex)
39+
{
40+
stopwatch.Stop();
41+
Console.WriteLine($" Error processing {fileName}: {ex.Message}");
42+
}
43+
}
44+
}
45+
static void AddWatermark(PdfGraphics graphics, SizeF pageSize)
46+
{
47+
PdfGraphicsState state = graphics.Save();
48+
graphics.SetTransparency(0.3f);
49+
50+
SizeF textSize = WatermarkFont.MeasureString(WatermarkText);
51+
52+
graphics.TranslateTransform(pageSize.Width / 2, pageSize.Height / 2);
53+
graphics.RotateTransform(-45);
54+
graphics.TranslateTransform(-textSize.Width / 2, -textSize.Height / 2);
55+
56+
graphics.DrawString(WatermarkText, WatermarkFont, WatermarkBrush, 0, 0);
57+
graphics.Restore(state);
58+
}
59+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="Compress-pdf/Compress-pdf.csproj" />
3+
</Solution>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<RootNamespace>Compress_pdf</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Imaging.Net.Core" Version="31.2.12" />
13+
</ItemGroup>
14+
15+
</Project>
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)