The color in images gets lighter when converting to Pdf

We are converting source images and documents to PDF for archiving purposes. It is important that all information is stored in its original shape and form. I use Aspose.Total Version 22.2.0.0, runtime version v4.0.30319…

Input image:

image.jpg (177.7 KB)

Note: Grey = CCCCCC (RGB)

Output image:
image.jpg (184.6 KB)

Note: Grey = D6D6D6 (RGB)

All colors seem to be a bit “Lighter” after conversion to PDF. Now this image was part of an Excel document, but other types of conversion to PDF show the same behaviour (from JPG, from Word, etc).

Code:
// Open the Excel file
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(inputPath);

// create explicit SaveOptions
Aspose.Cells.PdfSaveOptions pdfSaveOptions = new Aspose.Cells.PdfSaveOptions();
pdfSaveOptions.OnePagePerSheet = true;

// Save the pdf file.
string outputFile = Path.GetFileNameWithoutExtension(inputPath) + “_out.pdf”;
string outputPath = System.IO.Path.Combine(_outDir, outputFile);
wb.Save(outputPath, pdfSaveOptions);

How can we prevent colors from changing?

@fransbloemen,

Thanks for the screenshots.

Could you please zip and attach your input Excel file, we will check your issue soon. Also, share output PDFs, i.e., one by Aspose.Cells and other by MS Excel

To render PDF from other types (e.g. from JPG, from Word, etc.), please also share your sample images and MS Word files and sample code segments, we will evaluate and assist you accordingly.

214553.zip (572.9 KB)

input: the .xls file
output: the .pdf files, also converted to A/3U format

@fransbloemen,

I do not think the issue is related to Aspose.Cells for .NET APIs. I used your template Excel file to convert to PDF using the following sample code, it works fine and I do not spot colors in your mentioned image/monogram are fading a bit. I zoomed to higher percentage value for the output PDF pages in Adobe acrobat and colors in the image are same.
e.g.
Sample code:

// Open the Excel file
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook("e:\\test2\\214553.xlsx");

// create explicit SaveOptions
Aspose.Cells.PdfSaveOptions pdfSaveOptions = new Aspose.Cells.PdfSaveOptions();
pdfSaveOptions.OnePagePerSheet = true;

// Save the pdf file.
wb.Save("e:\\test2\\out1.pdf", pdfSaveOptions);

Please find attached the output PDF for your reference. Do you see any issue in it?
out1.pdf (209.4 KB)

I also found you are using Aspose.PDF API to manipulate or re-save the PDF, so the issue might be in that step (re-saving by Aspose.PDF API). Could you check/confirm and share your sample code by Aspose.PDF so we could evaluate your issue further.

That is really sharp. You are correct! Examining the issue further, I find that the color changes only occur after changing the Pdf format (A/1A…A/3U). Please find my code below.

To choose the desired pdf format, my testprogram populates a listbox called “listBoxFormat”:

        List<string> pdfFormatNames = new List<string>();

        pdfFormatNames = Enum.GetValues(typeof(PdfFormat))
                        .Cast<PdfFormat>()
                        .Select(v => v.ToString())
                        .ToList();
        foreach (string pdfFormatName in pdfFormatNames)
        {
            listBoxFormat.Items.Add(pdfFormatName);
        }
        listBoxFormat.SelectedIndex = 0;

This function makes use of the “listBoxFormat”:

    private string ConvertToPdfFormat(string inputPath)
    {
        // open input Pdf
        Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(inputPath);

        // Convert to different PDF compliant document
        // During conversion process, the validation is also performed
        PdfFormat myPdfFormat;
        if (Enum.TryParse(listBoxFormat.SelectedItem.ToString(), out myPdfFormat))
        {
            uint value = (uint)myPdfFormat;
        }
        else { /* error: the string was not an enum member */ }
        pdfDocument.Convert(_outDir + "\\log.xml", myPdfFormat, ConvertErrorAction.Delete);

        // Save output document
        string outputFile = Path.GetFileNameWithoutExtension(inputPath) + "-" + listBoxFormat.SelectedItem.ToString() + "_out.pdf";
        string outputPath = System.IO.Path.Combine(_outDir, outputFile);
        pdfDocument.Save(outputPath);
        return outputFile;
    }

@fransbloemen

We have tested the scenario using Aspose.PDF for .NET 22.3 and have logged an investigation ticket as PDFNET-51587 in our issue tracking system. We will further look into its details and keep you posted with the status of ticket resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.