This is a migrated thread and some comments may be shown as answers.

Custom Decoder for JBig2

9 Answers 29 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Arnaud
Top achievements
Rank 1
Arnaud asked on 16 Apr 2014, 12:54 PM
Hello
I am working on JBIG2DecodeFilter and I need some help
I have read this thread and this article in the documentation and I have write this class
01.public class JBIG2DecodeFilter : IPdfFilter
02.{
03.        private JBIG2StreamDecoder jBig2Decoder =  new JBIG2StreamDecoder();
04. 
05.        public byte[] Encode(PdfObject encodedObject, byte[] inputData)
06.        {
07.            throw new NotImplementedException();
08.        }
09. 
10.        public byte[] Decode(PdfObject decodedObject, byte[] inputData, DecodeParameters parms)
11.        {
12. 
13.            Debug.WriteLine("You are now in the Decode method of JBIG2Decode");  
14.            byte[] tiffData = jBig2Decoder.decodeJBIG2(inputData, ImageFormat.TIFF);
15.            System.IO.File.WriteAllBytes("c:\\image.tiff", tiffData);
16. 
17.            return tiffData;         
18.        }
19. 
20.        public string Name { get { return "JBIG2Decode"; }
21.}
I success to convert jbig2 images of my PDF in tiff format (my "image.tiff" is correctly displayed in XnView) and now I need to convert my tiff image to the correct format for the pdfViewer
I try to use CCITTFaxDecode but is an internal class.
How I can convert my Tiff image ?
Thanks

9 Answers, 1 is accepted

Sort by
0
Kammen
Telerik team
answered on 16 Apr 2014, 01:18 PM
Hi Arnaud,

Thank you for contacting us.

The CCITTFaxDecode filter has its limitations as well and that is why we do not recommend to use it. Moreover, converting from one format to another will slow your application unnecessary. The best way to use this decoder is to access the raw data (for example pixels) and return it as a byte array as described in the end of the this article.

It can be useful for us if you are able to tell us more about the capabilities of the JBIG2StreamDecoder you are using.

We are looking forward to your reply.

Regards,
Kammen
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Arnaud
Top achievements
Rank 1
answered on 16 Apr 2014, 02:14 PM
Hi Kammen
JBIG2StreamDecoder can directly decode jbig2 byte array to a tiff byte array (or jpeg) 
But it's not the correct byte array expected by pdfViewer.
At the end of your article you specify "The resulting byte array should contain exactly BitsPerComponent bits " my PdfObject expect a ColorSpace=Gray and BitsPerComponent=1, my byte array to return contain 1 dimension.
I am aware converting from one format to another will slow my application unnecessary butI do not have the skills for converting directly and I search a solution.
Thanks in advance
0
Accepted
Kammen
Telerik team
answered on 17 Apr 2014, 08:22 AM
Hello Arnaud,

We will consider you request about making the PdfFiters public.

Until then you can use some third party library to get the pixels from the image you have already converted.

We are sorry for the inconvenience.

Regards,
Kammen
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Arnaud
Top achievements
Rank 1
answered on 24 Apr 2014, 08:01 AM
Hello Kammen
For information, I success to implement a JBig2 filter.
I have dump this code link and I recreate a project (one for WPF and one for SL) with a lot of change I create my Filter :
public class JBIG2DecodeFilter : IPdfFilter
    {
        private JBIG2StreamDecoder jBig2Decoder =  new JBIG2StreamDecoder();
 
        public byte[] Encode(PdfObject encodedObject, byte[] inputData)
        {
            throw new NotImplementedException();
        }
 
        public byte[] Decode(PdfObject decodedObject, byte[] inputData, DecodeParameters parms)
        {
            return jBig2Decoder.decodeJBIG2(inputData);           
        }
 
        public string Name { get { return "JBIG2Decode"; } }
    }
Thanks again for help
Regards

PS : How I can mark this thread resolved ?
0
Arnaud
Top achievements
Rank 1
answered on 24 Apr 2014, 08:03 AM
Sorry I found how
0
Petya
Telerik team
answered on 24 Apr 2014, 02:57 PM
Hello Arnaud,

We're happy to hear you were able to implement the desired behavior. If you want to you can upload your code in our code libraries for the benefit of other users. Here are the instructions on how to create a code library.

Should you encounter any issues or have additional questions feel free to get back to us.

Regards,
Petya
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Kristoffer Rødseth
Top achievements
Rank 1
answered on 22 May 2014, 10:37 AM
Hi Arnaud,

We are also in need of a custom filter for this, so your solution looks promising. When I take a look at your code it only seems to include the WPF library. If you could make the SL implementation available that would be greatly appreciated. 

Regards,
Kristoffer
0
Arnaud
Top achievements
Rank 1
answered on 26 Jun 2014, 06:48 AM
Hi Kristoffer Rødseth and Petya
I am sorry for the late.
I post my project in code libraries, wait for validating.
Regards
0
Kammen
Telerik team
answered on 26 Jun 2014, 08:24 AM
Hello Arnaud,

Thank you for uploading code library. We really appreciate your effort.

Regards,
Kammen
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
PDFViewer
Asked by
Arnaud
Top achievements
Rank 1
Answers by
Kammen
Telerik team
Arnaud
Top achievements
Rank 1
Petya
Telerik team
Kristoffer Rødseth
Top achievements
Rank 1
Share this question
or