diff --git a/PDF-to-image/Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size.slnx b/PDF-to-image/Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size.slnx new file mode 100644 index 0000000..edf41bd --- /dev/null +++ b/PDF-to-image/Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size.slnx @@ -0,0 +1,3 @@ + + + diff --git a/PDF-to-image/Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size.csproj b/PDF-to-image/Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size.csproj new file mode 100644 index 0000000..7450e53 --- /dev/null +++ b/PDF-to-image/Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size.csproj @@ -0,0 +1,15 @@ + + + + Exe + net10.0 + Crop_coverted_image_with_exact_size + enable + enable + + + + + + + diff --git a/PDF-to-image/Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size/Input.pdf b/PDF-to-image/Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size/Input.pdf new file mode 100644 index 0000000..83aa682 Binary files /dev/null and b/PDF-to-image/Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size/Input.pdf differ diff --git a/PDF-to-image/Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size/Program.cs b/PDF-to-image/Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size/Program.cs new file mode 100644 index 0000000..030d914 --- /dev/null +++ b/PDF-to-image/Crop-coverted-image-with-exact-size/Crop-coverted-image-with-exact-size/Program.cs @@ -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!"); \ No newline at end of file