Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active April 26, 2019 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/c659d025f32d195ad2ccf9263c531768 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/c659d025f32d195ad2ccf9263c531768 to your computer and use it in GitHub Desktop.
Getting Image Previews using GroupDocs.Metadata
// For complete examples and data files, please go to https://github.com/groupdocs-metadata/GroupDocs.Metadata-for-.NET
using (PreviewHandler handler = PreviewFactory.Load("sample.docx"))
{
// loop through the document pages
for (int i = 0; i < handler.Pages.Length; i++)
{
// get preview images
PreviewImageData[] pagePreviews = handler.GetPageImage(i);
for (int j = 0; j < pagePreviews.Length; j++)
{
// save images
File.WriteAllBytes(string.Format(@"D:\Documents\Previews\{0}-{1}.png",i, j), pagePreviews[j].Contents);
}
}
}
// For complete examples and data files, please go to https://github.com/groupdocs-metadata/GroupDocs.Metadata-for-Java
try (PreviewHandler handler = PreviewFactory.load("sample.docx"))
{
// loop through the document pages
for (int i = 0; i < handler.getPages().length; i++)
{
// get preview images
PreviewImageData[] pagePreviews = handler.getPageImage(i);
for (int j = 0; j < pagePreviews.length; j++)
{
// save images
try (FileOutputStream stream = new FileOutputStream("D:\\Documents\\Preview\\" + i + "-" + j + ".png"))
{
pagePreviews[j].writeTo(stream);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment