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

Custom Encoder for Tiff

13 Answers 190 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
danparker276
Top achievements
Rank 2
danparker276 asked on 11 May 2012, 12:08 AM
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.

13 Answers, 1 is accepted

Sort by
0
Accepted
Kammen
Telerik team
answered on 14 May 2012, 03:30 PM
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:

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

0
Daniel Kassell
Top achievements
Rank 1
answered on 01 Feb 2013, 03:13 PM
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!
0
Petya
Telerik team
answered on 05 Feb 2013, 06:54 PM
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.

0
Michael
Top achievements
Rank 1
answered on 10 May 2013, 02:00 AM
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.
0
Kammen
Telerik team
answered on 10 May 2013, 08:21 AM
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.

0
danparker276
Top achievements
Rank 2
answered on 10 May 2013, 05:03 PM
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.
0
Kammen
Telerik team
answered on 14 May 2013, 08:29 AM
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.

0
danparker276
Top achievements
Rank 2
answered on 15 May 2013, 09:43 PM
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.
0
Thomas
Top achievements
Rank 1
answered on 20 Aug 2013, 11:55 PM
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
0
Alexander
Telerik team
answered on 23 Aug 2013, 05:07 PM
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 >>
0
Thomas
Top achievements
Rank 1
answered on 26 Aug 2013, 03:53 PM
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
0
Alexander
Telerik team
answered on 27 Aug 2013, 01:09 PM
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 >>
0
danparker276
Top achievements
Rank 2
answered on 27 Aug 2013, 05:58 PM
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.
Tags
PDFViewer
Asked by
danparker276
Top achievements
Rank 2
Answers by
Kammen
Telerik team
Daniel Kassell
Top achievements
Rank 1
Petya
Telerik team
Michael
Top achievements
Rank 1
danparker276
Top achievements
Rank 2
Thomas
Top achievements
Rank 1
Alexander
Telerik team
Share this question
or