usmanazizgroupdocs
6/16/2016 - 8:06 AM

GetImageRepresentation.cs

// For complete examples and data files, please go to https://github.com/groupdocs-annotation/GroupDocs.Annotation-for-.NET
/// <summary>
/// Gets image representation of document
/// </summary>
/// <param name="filePath">Source file path</param> 
public static void GetImageRepresentation(string filePath)
{
    try 
    {
        Stream document = new FileStream(MapSourceFilePath(filePath), FileMode.Open);
        AnnotationConfig cfg = GetConfiguration();

        AnnotationImageHandler annotationHandler = new AnnotationImageHandler(cfg);

        List<PageImage> images = annotationHandler.GetPages(document, new ImageOptions());

        // Save result stream to file.
        using (FileStream fileStream = new FileStream(MapDestinationFilePath("image.png"), FileMode.Create))
        {
            byte[] buffer = new byte[images[0].Stream.Length];
            images[0].Stream.Seek(0, SeekOrigin.Begin);
            images[0].Stream.Read(buffer, 0, buffer.Length);
            fileStream.Write(buffer, 0, buffer.Length);
            fileStream.Close();
        }
    }
    catch (System.Exception exp)
    {
        Console.WriteLine(exp.Message); 
    }

}