Colorspace is wrong when convert jpg to pdf in C#

Hi,
I got wrong color when I try to convert this image to pdf.

Tested OSs were Win7 and Win10
.NET target platform is .net 6.0
Using SDK: Aspose.PDF for .Net 24.3

Test code

void testJpgToPdf(string filename)
{
    // Load input JPG image file
    System.Drawing.Image srcImage = System.Drawing.Image.FromFile(filename);

    // Read Height of input image
    int h = srcImage.Height;

    // Read Height of input image
    int w = srcImage.Width;

    // Initialize a new PDF document
    Document doc = new Document();

    // Add an empty page
    Page page = doc.Pages.Add();
    Aspose.Pdf.Image image = new Aspose.Pdf.Image();
    image.File = (filename);

    // Set page dimensions and margins
    page.PageInfo.Height = (h);
    page.PageInfo.Width = (w);
    page.PageInfo.Margin.Bottom = (0);
    page.PageInfo.Margin.Top = (0);
    page.PageInfo.Margin.Right = (0);
    page.PageInfo.Margin.Left = (0);
    page.Paragraphs.Add(image);

    // Save output PDF file
    doc.Save(filename + ".ImagetoPDF.pdf");

}

Testing file
0-1(1).jpg (270.5 KB)

@kngstr

Please check the attached output PDF that was generated in our environment using Aspose.Pdf.Drawing 24.4. We could not notice any issues in it:
ImagetoPDF.pdf (272.2 KB)

@asad.ali

This is a comparison between the PDF you provided and the original image.
Please check the position of the arrow.
There is indeed a color difference
图片.jpg (237.7 KB)

This output pdf is generated from Aspose.pdf for .net 24.4, with the same code.
And it has different color too.
0-1(1).jpg.ImagetoPDF.pdf (2.0 MB)

@kngstr

It looks strange. Please check the comparison of image and generated PDF in our environment. They both look same:

image.jpg (237.4 KB)

@asad.ali

The colors were different from these viewer:
Windows photos, WPS图片, Edge image Viewer, PhotoShop.

viewers.jpg (207.8 KB)
viewers.ps.jpg (177.3 KB)

@kngstr

Please share which viewer is it that you prefer so that we can use the same to observe the issues in our environment and address it accordingly.

@asad.ali
The images displayed by these viewers above are consistent. Personally, I usually use Windows Photos or WPS to view images.
But from what you previously sent, the Windows photos on your end show something different from mine.
So WPS or PhotoShop is OK.

@kngstr

This is how the photo is rendered in Edge, Photos (MS) and WPS in our environment.
image.jpg (285.2 KB)

You can notice that we are seeing same color in each photo viewer that we have tried. It is quite possible that you are noticing this color because of different color profile on your machine or OS. Also, color temperature on your device may take part in showing different color shades. Can you please try to use another system to view the image?

@asad.ali
That’s strange.

It seems when color is cmyk, something like below should to be setting in pdf.

/Decode[1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0]

These are my testing OS list:

Windows 7 Professional sp1 64-bit Edition 6.1.7601
Windows 10 Enterprise 1909 64-bit Edition 10.0.18363.1679
Windows 10 Home 22H2 64-bit Edition 10.0.19045.4170
Windows 10 Professional 22H2 64-bit Edition 10.0.19045.2846

I tested another code, it still got black.

void testJpgToPdfAddImage(string filename)
{
    // Load input JPG image file
    System.Drawing.Image srcImage = System.Drawing.Image.FromFile(filename);

    // Read Height of input image
    int h = srcImage.Height;

    // Read Height of input image
    int w = srcImage.Width;

    // Initialize a new PDF document
    Document doc = new Document();

    // Add an empty page
    Page page = doc.Pages.Add();

    // Set page dimensions and margins
    page.PageInfo.Height = (h);
    page.PageInfo.Width = (w);
    page.PageInfo.Margin.Bottom = (0);
    page.PageInfo.Margin.Top = (0);
    page.PageInfo.Margin.Right = (0);
    page.PageInfo.Margin.Left = (0);
    page.SetPageSize(w, h);
    page.AddImage(filename, new Rectangle(0, 0, w, h));

    // Save output PDF file
    doc.Save(filename + ".AddImage.ImagetoPDF.pdf");

}

@kngstr

Maybe the image is being changed after you are uploading it here to share it. Is it possible if you can upload the image to some public file sharer and share the link with us?

@asad.ali

You are right. Try this file.
0-1(1).7z (975.9 KB)

@kngstr

We were now able to replicate the issue in our environment as shown in the screenshot.
picture886-1.jpg (229.8 KB)

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-57099

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@asad.ali

OK. Thanks.

1 Like