Last active
June 17, 2021 14:37
-
-
Save aspose-com-gists/3d84c7b9f7285728d5ad8da67a8b2a0a to your computer and use it in GitHub Desktop.
Extract Images from PDF in C# | https://blog.aspose.com/2021/06/15/extract-images-from-pdf-in-csharp/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read the article: https://blog.aspose.com/2021/06/15/extract-images-from-pdf-in-csharp/