-
Notifications
You must be signed in to change notification settings - Fork 313
Support DecodeDCT and separation colorspace #484
Copy link
Copy link
Closed
Labels
Description
The attached pdf contains a picture that is read with inverted colors as shown here below

I started from your sample code and I just add the code for saving bmp file.
using System;
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.TryGetBytes(out var b))
{
b = image.RawBytes;
}
var type = string.Empty;
switch (image)
{
case XObjectImage ximg:
type = "XObject";
break;
case InlineImage inline:
type = "Inline";
break;
}
Console.WriteLine($"Image with {b.Count} bytes of type '{type}' on page {page.Number}. Location: {image.Bounds}.");
try
{
Image im = Image.FromStream(new MemoryStream(b.ToArray()));
string filename = "test.bmp";
if (File.Exists(filename))
File.Delete(filename);
im.Save(filename);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}
}
}
Reactions are currently unavailable