PDF grayscale conversion massively inflating file size

We are utilizing the Aspose.PDF grayscale conversion process described here:

The grayscale conversion itself works as expected, but the resulting files are roughly 30x larger (ie, a 500 KB file turns into a 15 MB file).

Our files consist of a Word document that is saved as a PDF within Word itself, and a TIF file which is converted to PDF using Aspose. The Word PDF and the TIF PDF are then merged and saved into one PDF using Aspose. At this point, the merged PDF has the expected/appropriate file size. Once the grayscale operation is completed, the file size inflates significantly.

We’ve tried this operation using Aspose.PDF versions 18.6.1 and 21.4.0. Both versions exhibit the same behavior. Any advice would be appreciated!

@kefka95

Can you please provide your sample source file(s) and sample code snippet that you are using for conversion. We will test the scenario in our environment and address it accordingly.

Thanks for the reply. I will try to dummy up some files that I can attach here. Our “real” documents contain PHI and other sensitive information, so I can’t attach them as-is.

@kefka95

Sure, please take your time to gather the information and share with us. We will further proceed to assist you accordingly.

IA 8721074001000 one page.pdf (64 KB)

Sorry for the late reply. Please see attached, and also our grayscale conversion method below. When I execute this code against the attached PDF, the file size goes from 64 KB to 1,975 KB.

        > public static void convertPDFGrayScale(string license, string inputPDF, bool createNewFile, out bool conversionResult, out string conversionMsg)
        {
            try
            {
                Aspose.Pdf.License pdfLic = new Aspose.Pdf.License();
                pdfLic.SetLicense(license);

                conversionResult = true;

                Document doc = new Document(inputPDF);
                RgbToDeviceGrayConversionStrategy rgbStrategy = new RgbToDeviceGrayConversionStrategy();

                //Convert pages
                for (int idxPage = 1; idxPage <= doc.Pages.Count; idxPage++)
                {
                    Aspose.Pdf.Page page = doc.Pages[idxPage];
                    rgbStrategy.Convert(page);
                }

                //Save the result
                if (createNewFile)
                {
                    doc.Save(inputPDF.Replace(".pdf", "_converted.pdf"));
                }
                else
                {
                    doc.Save(inputPDF);
                }

                conversionMsg = "successfully saved: " + inputPDF;
            }
            catch (Exception ex)
            {
                conversionResult = false;
                conversionMsg = "Error converting PDF: " + ex.Message;
            }
        }

@kefka95

We were able to replicate the issue in our environment using 21.5 version of the API. Therefore, we have logged an issue as PDFNET-49937 in our issue management system. We will further investigate the ticket in details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thank you for taking the time to look into this. We appreciate it!

1 Like

The issues you have found earlier (filed as PDFNET-49937) have been fixed in Aspose.PDF for .NET 21.10.