-
Notifications
You must be signed in to change notification settings - Fork 313
Expand file tree
/
Copy pathExtractImages.cs
More file actions
40 lines (37 loc) · 1.24 KB
/
ExtractImages.cs
File metadata and controls
40 lines (37 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
namespace UglyToad.Examples
{
using System;
using PdfPig;
using PdfPig.Content;
using PdfPig.XObjects;
internal static class ExtractImages
{
public static void Run(string filePath)
{
using (var document = PdfDocument.Open(filePath))
{
foreach (var page in document.GetPages())
{
foreach (var image in page.GetImages())
{
if (!image.TryGetBytesAsMemory(out var b))
{
b = image.RawMemory;
}
var type = string.Empty;
switch (image)
{
case XObjectImage ximg:
type = "XObject";
break;
case InlineImage inline:
type = "Inline";
break;
}
Console.WriteLine($"Image with {b.Length} bytes of type '{type}' on page {page.Number}. Location: {image.Bounds}.");
}
}
}
}
}
}