Completed
Last Updated: 30 Mar 2020 13:24 by ADMIN
Release R2 2020
ADMIN
Boby
Created on: 13 Sep 2016 07:03
Category: PdfProcessing
Type: Bug Report
4
PdfProcessing: Importing DecodeParms containing null or stream object results in missing image

Exporting document with a missing image is caused by handled Exception on import for DecodeParms containing null or stream object. Currently, PdfProcessing supports only decode parameters containing simple types. The case when some dictionary value is null or stream object should be implemented.

Another case is when the whole dictionary/stream is null. In this case, an ArgumentNullException is thrown.
6 comments
ADMIN
Georgi
Posted on: 17 Sep 2019 13:46

Hello Hector,

I am sorry to hear that this issue causes such overhead for you. We understand the importance of this item and we have increased its priority.

In order to apply a fix, an appropriate fallback mechanism should be applied when the DecodeParams property of the filter is not defined. However, not each filter defines any default parameter values, which may increase the complexity of the item. We have estimated the item by taking these considerations into account and we have ensured that the item is with pretty high priority in the backlog. However, I cannot commit to a specific timeframe when it will be delivered. Please, make sure to click the Follow button to be notified when the status of the item changes.

Regards,
Georgi
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Hector
Posted on: 10 Sep 2019 14:10
Would really like a built in solution into the library for this coming release. I have an excessive amount of overhead because of this and this issue is quite old. Please see what you can do. Seems like a simple null check would be sufficient.
ADMIN
Tanya
Posted on: 05 Jun 2019 15:18
Hi Hector,

I checked the case and it seems like the issue is somehow related to the encoding of the content. Thank you once again for sharing the approach and updating the information. 

Regards,
Tanya
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Hector
Posted on: 02 Jun 2019 21:01

Wanted to amend my original solution. I found that when I used the solution below in an Asp.Net core solution that it would throw an error where my Console application would not. Not sure what the deal was, but I found that if I avoid the Encoding conversion part, and just stuck to working with the byte array then all was fine. Here is my new solution which involved creating a new Linq extension method to replace any given SEQUENCE of bytes with another sequence, as is needed in this scenario.

 

        // LINQ ReplaceSequence Extension Method
        public static IList<TSource> ReplaceSequence<TSource>(this IList<TSource> items, IList<TSource> replaceItems, IList<TSource> withItems, IEqualityComparer<TSource> comparer = null)
        {
            comparer = comparer ?? EqualityComparer<TSource>.Default;

            if (replaceItems.Count() != withItems.Count()) throw new Exception($"{nameof(replaceItems)} array and {nameof(withItems)} array must be of equal length.");

            for (var i = 0; i < items.Count(); i++)
            {
                var sequenceMatches = true;

                for (var j = 0; j < replaceItems.Count(); j++)
                {
                    var matchItem = replaceItems[j];

                    if (!comparer.Equals(items[i + j], matchItem))
                    {
                        sequenceMatches = false;
                        break;
                    }
                }

                if (!sequenceMatches) continue;

                for (var j = 0; j < withItems.Count(); j++)
                {
                    items[i + j] = withItems[j];
                }
            }

            return items;
        }

        public static void ApplyPDFFix(byte[] bytes)
        {
            var searchStr = "/DecodeParms[null]";
            var replaceStr = string.Join("", searchStr.Select(e => " "));

            var searchStr_Bytes = Encoding.Default.GetBytes(searchStr);
            var replaceStr_Bytes = Encoding.Default.GetBytes(replaceStr);

            bytes.ReplaceSequence(searchStr_Bytes, replaceStr_Bytes);
        }

 

As Tanya pointed out, this solution can come with any various number of side-affects, so use it with caution OR wait for Telerik to provide an official fix. For me, I needed a programmatic solution NOW. At least this way I don't have to meddle with the actual STORED pdf, and can just alter the bytes in memory.

ADMIN
Tanya
Posted on: 14 Mar 2019 11:45
Hi Hector,

Thank you for the update.

Something I would like to mention here is that this code should be used carefully and is not a universal workaround as it might lead to incomplete import of the data.

Regards,
Tanya
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Hector
Posted on: 07 Mar 2019 18:27

Quick fix to apply before importing:

 

        public byte[] ApplyPDFFix(byte[] bytes)
        {
            var searchStr = "/DecodeParms[null]";
            var replaceStr = string.Join("", searchStr.Select(e => " "));

            var ansiStr = Encoding.Default.GetString(bytes);

            ansiStr = ansiStr.Replace(searchStr, replaceStr);

            return Encoding.Default.GetBytes(ansiStr);
        }

 

Not sure if it's the "best" way, but it works. Turns out about 10% of the PDF files that I work with are afflicted by this bug.