Skip to content

Support DecodeDCT and separation colorspace #484

@ilCosmico

Description

@ilCosmico

The attached pdf contains a picture that is read with inverted colors as shown here below
image

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);
                        
                    }
                }
            }
        }
    }
}

test.pdf

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions