Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.