Custom Encoder for Tiff

14 posts, 1 answers
  1. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 10 May 2012 Link to this post

    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.
  2. Answer
    Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 14 May 2012 Link to this post

    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 >>

  3. DevCraft banner
  4. Daniel Kassell
    Daniel Kassell avatar
    7 posts
    Member since:
    May 2010

    Posted 01 Feb 2013 Link to this post

    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!
  5. Petya
    Admin
    Petya avatar
    975 posts

    Posted 05 Feb 2013 Link to this post

    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.

  6. Michael
    Michael avatar
    1 posts
    Member since:
    Jun 2012

    Posted 09 May 2013 Link to this post

    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.
  7. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 10 May 2013 Link to this post

    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.

  8. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 10 May 2013 Link to this post

    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.
  9. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 14 May 2013 Link to this post

    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.

  10. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 15 May 2013 Link to this post

    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.
  11. Thomas
    Thomas avatar
    6 posts
    Member since:
    May 2013

    Posted 20 Aug 2013 Link to this post

    Hello,

    I'm a little confused with the Encoder. I downloaded the sample code attached to this thread. Run the code and use my pdf file with tiff images embedded on it. The pdf document displayed perfectly, now I implement my the class to my own project and tested it. The same pdf file loads on the RadPDFViewer control but doesnt show the tiff files. Just the pdf files with some text inside the file, it doesn't show the tiff embedded on the file.

    Im guessis that this is related to the fact that when I view my pdf, i download it as a blob file then stream it to the pdf viewer. Also, the decode method on the class PDFAndTiffFilter does not fire.

    Any help would be appreciated.

    Regards,
    Erc
  12. Alexander
    Admin
    Alexander avatar
    41 posts

    Posted 23 Aug 2013 Link to this post

    Hi Eric,

    The sample project demonstrates how to implement the IPdfFilter interface, it is not meant to open tiff files. The decode method of the class will be executed only when the document contains tiff files. If this method is not executed, then your document does not require CCITTFaxDecode.

    I hope this helps. Please, get back to us if you need further assistance.

    Regards,
    Alexander
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  13. Thomas
    Thomas avatar
    6 posts
    Member since:
    May 2013

    Posted 26 Aug 2013 Link to this post

    Alexander,

    The thing is, with the sample code. I run it and use my .pdf file with Tiff embedded on it. Then, why i tried to apply the class to my project and use the same pdf file. The PdfViewer loads and shows the document but without the tiff files. just blank white pages with the text from the document, no images.

    Any ideas?

    Regards,
    Eric
  14. Alexander
    Admin
    Alexander avatar
    41 posts

    Posted 27 Aug 2013 Link to this post

    Hello Eric,

    The tiff files are not being displayed, because the sample project only demonstrates how to implement a custom decoder, it is not actually implementing one. It is up to you to implement the Encode and Decode methods of the IPdfFilter interface. 

    Regards,
    Alexander
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  15. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 27 Aug 2013 Link to this post

    Most 3rd party Document imaging add ons cost as much or more than all of Telerik's tools for the viewer (There's a reason why).  Some things can be done for free if you want to build a custom decoder, but I found it easier to buy a document imaging add on.  For my purpose I really need it because converting and reading all different compressions are important.
Back to Top
DevCraft banner