private void button1_Click(object sender, RoutedEventArgs e)
{
var path = @"AMS - MO - Closed End Lease-2.pdf";
var outputPath = Path.Combine("split", Path.GetDirectoryName(path));
using (var Doc = new PdfDocument(path))
{
string pattern = Path.Combine(outputPath, Path.GetFileNameWithoutExtension(path) + "_{0}.pdf");
Doc.Split(pattern, 1);
}
foreach (var doc in Directory.GetFiles(outputPath)) //used to get all the splitted docuemtns
{
using (var document = new PdfDocument())
{
document.LoadFromFile(doc);
SaveImage(document.SaveAsImage(0, 192D, 192D), doc.Remove(doc.Length - 4) + "_grf.Jpg");
}
}
}
private void SaveImage(BitmapSource image, string targetPath)
{
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(image));
using (var filestream = new FileStream(targetPath, FileMode.Create))
{
try
{
encoder.Save(filestream);
}
catch (Exception e)
{
}
}
}