I just tried getting a thumbnail from a page in a PDFDoc, but it just returns nil. What gives?
- (UIImage*)thumbnailOfPage:(NSUInteger)pageNumber {
PDFDoc *activePDF = [self GetDoc];
Page* page = [activePDF GetPage:pageNumber];
NSObject *thumbnail = [page GetThumb];
return (UIImage*)thumbnail;
}
Also, how do I get from the return Image object class back to a UIImage that I can use on iOS, the casting I do above is probably incorrect
------------
A:
You are getting Nil because the PDF does not appear to contain a thumbnail for the page. A PDF document may contain a thumbnail for a page, which if it exists, is what GetThumb returns. The call does not create a thumbnail. If you wish to generate a thumbnail, your best bet would be to use an instance of PDFDraw to rasterize the page at a small resolution.
Finally, yes the cast is incorrect, GetThumb returns an Obj*, not an NSObject*. You could use the Obj* that it returns to create a new Image (a PDFNet type), read out the pixel data from the Image and use the raw pixel data to create a new UIImage. Let me know if you would like some example code on how to do this.
Would love to see some example code on this...Thanks a lot in advance!
Function GetThumb(CurPag As pdftron.PDF.Page) As pdftron.PDF.Image
Dim Itr As DictIterator = CurPag.GetSDFObj.Find("Thumb")
If Itr.HasNext Then Return New pdftron.PDF.Image(Itr.Value)
Return Nothing
End Function