Fast and Lean Pdf Viewer For Iphone/Ipad/Ios - Tips and Hints

Fast and Lean PDF Viewer for iPhone / iPad / iOS - tips and hints?

I have build such kind of application using approximatively the same approach except :

  • I cache the generated image on the disk and always generate two to three images in advance in a separate thread.
  • I don't overlay with a UIImage but instead draw the image in the layer when zooming is 1. Those tiles will be released automatically when memory warnings are issued.

Whenever the user start zooming, I acquire the CGPDFPage and render it using the appropriate CTM. The code in - (void)drawLayer: (CALayer*)layer inContext: (CGContextRef) context is like :

CGAffineTransform currentCTM = CGContextGetCTM(context);    
if (currentCTM.a == 1.0 && baseImage) {
//Calculate ideal scale
CGFloat scaleForWidth = baseImage.size.width/self.bounds.size.width;
CGFloat scaleForHeight = baseImage.size.height/self.bounds.size.height;
CGFloat imageScaleFactor = MAX(scaleForWidth, scaleForHeight);

CGSize imageSize = CGSizeMake(baseImage.size.width/imageScaleFactor, baseImage.size.height/imageScaleFactor);
CGRect imageRect = CGRectMake((self.bounds.size.width-imageSize.width)/2, (self.bounds.size.height-imageSize.height)/2, imageSize.width, imageSize.height);
CGContextDrawImage(context, imageRect, [baseImage CGImage]);
} else {
@synchronized(issue) {
CGPDFPageRef pdfPage = CGPDFDocumentGetPage(issue.pdfDoc, pageIndex+1);
pdfToPageTransform = CGPDFPageGetDrawingTransform(pdfPage, kCGPDFMediaBox, layer.bounds, 0, true);
CGContextConcatCTM(context, pdfToPageTransform);
CGContextDrawPDFPage(context, pdfPage);
}
}

issue is the object containg the CGPDFDocumentRef. I synchronize the part where I access the pdfDoc property because I release it and recreate it when receiving memoryWarnings. It seems that the CGPDFDocumentRef object do some internal caching that I did not find how to get rid of.

PDF Viewer iPad App

I've developed a custom reader like this which I've used for a handful of projects for clients. Search & Highlight was by far the most difficult, followed by text selection. Keeping memory usage low for large PDF's is tricky too.

I cant share my source. But here's someone who has a free library that looks promising:

http://mobfarm.eu/fastpdfkit

https://github.com/mobfarm/FastPdfKit

(it doesn't look as if the source code is available?)

How to open web link from pdf in UIWebView?

Lots of fun ahead of you :)

Here is the best on SO: Fast and Lean PDF Viewer for iPhone / iPad / iOs - tips and hints?. Contains lots of links to other questions based on topic.

Simple Pdf Viewer using CGPDF

This worked well for me. Given, it was on the Apple TV, but it does not use WebKit, and I'm sure it works just as well on iOS. It draws a PDF using CGPDF from either a local source or from a URL.

Rendering PDF in Apple TV tvOS

Also want to point out that where it says UIGraphicsBeginImageContext(pageRect.size), I replaced this with UIGraphicsBeginImageContextWithOptions(pageRect.size, NO, 5.0); because I found that the CGPDF image created is very fuzzy and blurry. By beginning the contxt with options, you can change the scale factor (5.0) and this increases the number of pictures, increasing the resolution.

Multimedia PDF viewer for iOS

After a long long research and discussions, unfortunately there is no free solution with these features. There are only paid solutions and Adobe Publishing Suite takes the head although it is one of the most expensive solutions

Pdf Reader+iphone

Yes someone did it before. I used this kit also and it is great to search pages and highlight the result. It's PDFKitten by KurtCode (on Github).



Related Topics



Leave a reply



Submit