Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > PDFViewer > Custom Encoder for Tiff

Answered Custom Encoder for Tiff

Feed from this thread
  • Posted on May 10, 2012 (permalink)

    In another thread in the general discussion, I got a response that said that I could view all tiff files if I used a custom encoder with the PDFViewer.  Is there any documentation or samples that can point me in the right direction?  I'm very new to working with images/pdf.

    Reply

  • Answer Kammen Kammen admin's avatar

    Posted on May 14, 2012 (permalink)

    Hi Dan,

    You should be aware that currently, RadPdfViewer has an implementation of the CCITTFaxDecoder (that opens tiff images). We are using a third party Tiff decoder in order to decode the bytes. However there are some limitations in it and not all the features that PDF supports are implemented in this decoder. Unfortunately, we could not find a lot of information and good specification how to implement this filter better.

    When it comes to creating a custom decoder for tiff images, you can do so by implementing the IPdfFilter interface and registering the new class by calling FiltersManager.RegisterFilter () method. RadPdfViewer uses the the Name property in order to recognize the filter. It must return one of following values: 
    • ASCIIHexDecode
    • ASCII85Decode
    • LZWDecode
    • FlateDecode
    • RunLengthDecode
    • CCITTFaxDecode
    • JBIG2Decode
    • DCTDecode
    • JPXDecode

    In your case that would be CCITTFaxDecode. If you register a PDF filter, it will override the default one.


    Greetings,
    Kammen
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.
  • Daniel Kassell avatar

    Posted on Feb 1, 2013 (permalink)

    Hi,

    I just stumbled upon this thread and got really excited about the fact that the RadPdfViewer can show TIF-files. Though, I don't really understand how you're supposed to do to achieve this.

    I'm quite new when it comes to these document files programatically.

    Could you perhaps give me an example on how you guys implement this IPdfFilter and use it?

    I just tried to do following code but the filter doesn't seem to run it's code at all i.e. no exception is thrown.

    public partial class DocumentView : UserControl
        {
            private PDFAndTiffFilter _filter;
     
            public DocumentView()
            {
                _filter = new PDFAndTiffFilter();
                FiltersManager.RegisterFilter(_filter);
                InitializeComponent();
            }
        }
     
        public class PDFAndTiffFilter : IPdfFilter
        {
            public byte[] Encode(PdfObject encodedObject, byte[] inputData)
            {
                throw new NotImplementedException();
            }
     
            public byte[] Decode(PdfObject decodedObject, byte[] inputData, DecodeParameters parms)
            {
                throw new NotImplementedException();
            }
     
            public string Name { get { return "CCITTFaxDecode"; } }
        }


    Am I missing something?

    Cheers!

    Reply

  • Petya Petya admin's avatar

    Posted on Feb 5, 2013 (permalink)

    Hi Daniel,

    A possible reason why you are not seeing the exception is that it is handled internally in order to prevent a crash.

    However, if you've tried debugging and your project never entered the Decode method, this is most likely due to the fact that the file you are opening does not need the CCITTFaxDecode filter in order to be shown. You can verify the latter by clicking the two buttons in the sample I am attaching.

    As for an actual implementation of the filter - unfortunately, we do not have such. My sample only shows how to plug a custom filter, but the filter itself is up to you to implement. You should be aware that this is not a trivial task.

    Regards,
    Petya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

    Reply

  • Michael avatar

    Posted on May 9, 2013 (permalink)

    Petya,

    I am using IPdfFilter to create a Filter for JBIG2Decode, most of our PDF documents contain this type of image.

    My question is:

    When creating the custom filter for JBIG2Decode what is PDFViewer expecting to be returned in the byte array.
    A different Byte [] of a simplar image? (e.g. jpg or png)
    Just the decoded Byte[]?

    Thank you.

    Reply

  • Kammen Kammen admin's avatar

    Posted on May 10, 2013 (permalink)

    Hello Michael,

    As it is described in our online help, the result that custom filter should return depends on the type of the filter. For the binary filters it is enough to decode the byte array into a decoded byte array using the respective algorithm. As for the filters listed in the article, additional transformation is required.

    RadPdfViewer expects these filters to return data that depends on the decoded object's color space and bits per component (there are such properties in the decodedObject). The resulting byte array should contain exactly BitsPerComponent bits for each color component in the color space.

    I hope this makes things clear!

    Kind regards,
    Kammen
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

    Reply

  • Posted on May 10, 2013 (permalink)

    I think iFilter is for indexing documents.  I don't think you can use that to decode the PDFs.

    I have a 3rd party GDPicture I use for converting PDFs, but I haven't found out how to decode yet.  I think it's possible, but I'm still trying to figure out how.  I haven't found any decode methods yet.  Converting from 1 document type to another is different than what the telerik viewer wants.  If you were converting from 1 format to another it would take too long anyway.  This isn't super high on my priority list, but I'll post a reply if I find anything out.

    Reply

  • Kammen Kammen admin's avatar

    Posted on May 14, 2013 (permalink)

    Hello Dan,

    We are not quite sure we properly understand what you are saying. Filters in PDF format are used to decode data from the PDF document. Different filters are used for different types of data. More information about filters can be found in the PDF format specification, 3.3 Filters.

    Regards,
    Kammen
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

    Reply

  • Posted on May 15, 2013 (permalink)

    Yeah, I don't think I fully understand filters.  I don't think the document imaging tools I have can do that.  I guess I need to read more about the filters if I want to do this.  For now, I'm just going to store my pdf files in a different compression format so the telerik pdf viewer can read it.

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > PDFViewer > Custom Encoder for Tiff