Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active June 17, 2021 14:37
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 aspose-com-gists/3d84c7b9f7285728d5ad8da67a8b2a0a to your computer and use it in GitHub Desktop.
Save aspose-com-gists/3d84c7b9f7285728d5ad8da67a8b2a0a to your computer and use it in GitHub Desktop.
// Open document
Document pdfDocument = new Document("candy.pdf");
int imageCounter = 1;
// Loop through pages
foreach (var page in pdfDocument.Pages)
{
// Loop through all images
foreach (XImage image in page.Resources.Images)
{
// Create file stream for image
FileStream outputImage = new FileStream(String.Format("Page{0}_Image{1}.jpg", page.Number, imageCounter), FileMode.Create);
// Save output image
image.Save(outputImage, ImageFormat.Jpeg);
// Close stream
outputImage.Close();
imageCounter++;
}
// Reset counter
imageCounter = 1;
}
@aspose-com-gists
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment