Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size.csproj" />
</Solution>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace>Crop_coverted_image_with_exact_size</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.PdfToImageConverter.Net" Version="*" />
</ItemGroup>

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Syncfusion.PdfToImageConverter;
using SkiaSharp;


PdfToImageConverter imageConverter = new PdfToImageConverter();

using (FileStream inputStream = new FileStream("../../../Input.pdf",FileMode.Open, FileAccess.Read))
{
imageConverter.Load(inputStream);
int pageCount = imageConverter.PageCount;
using (Stream stream = imageConverter.Convert(0, false, false))
{
stream.Position = 0;
using (SKBitmap originalBitmap = SKBitmap.Decode(stream))
{
int cropX = 400;
int cropY = 600;
int cropWidth = 400;
int cropHeight = 300;
SKRectI cropRect = new SKRectI(cropX, cropY, cropX + cropWidth, cropY + cropHeight);
using (SKBitmap croppedBitmap = new SKBitmap(cropWidth, cropHeight))
{
using (SKCanvas canvas = new SKCanvas(croppedBitmap))
{
canvas.DrawBitmap(
originalBitmap,
cropRect,
new SKRect(0, 0, cropWidth, cropHeight));
}

using (SKImage image = SKImage.FromBitmap(croppedBitmap))
using (SKData data = image.Encode(SKEncodedImageFormat.Png, 100))
{
string outputPath = $"Cropped.png";

using (FileStream fs = File.OpenWrite(outputPath))
{
data.SaveTo(fs);
}

Console.WriteLine($"Saved: {outputPath}");
}
}
}
}
}
Console.WriteLine("Cropping completed successfully!");
Loading