IOS improves PDF rendering speed

I am writing an application that manages user documents and (ultimately) messages of PDF files served by a web service on an iPhone / iPad. These are almost exclusively scanned PDF files, and they seem REALLLLY afraid of the iOS device.

The first solution I came across was to simply place the PDF in a UIWebView. This works really, really well for "generated" PDF files, but NOT for scanned PDF files (I assume the difference is raster and vector?).

My next decision was to implement the UIDocumentInteractionController, which was said to increase vision. I can report that it really works faster than UIWebView, but it is still unacceptably slow, even on small, two-page PDF files. (On a side note, the auto-open-in-another-app function, as well as the built-in print, is super-smooth!)

I read a post or 2 on the QuickLook structure and I plan to study this, but I also came across a few posts talking about CGPDFDocument classes, etc. They seem to have finer control over document navigation (a la xPdf), but I don't know where to start. Also, I'm not even sure that it gives a performance advantage for what I am doing.

So, the first question: what is the fastest way to scan scanned PDF files on iPhone / iPad?

: PDF , PDF. - , PDF ?

!

( : 19 , , , , !))

+3
5

, . PDF iPad/iPhone . , , / PDF , .

. , pdf , , .

+2

- PDF, CGPDFDocument. PDF , :

  • .
  • CATiledLayer . pdf , CATiledLayer, . . , CATiledLayer.
  • pdf. , .
  • (iPhone 4 iPad 2 ) , .
  • pdf-, : , , ..
  • CGPDFPageRef. , . CGPDFDocumentRef .

PDFTouch SDK iOS, PDF-, !

+6

pdf , ( PDF), . , "pdf" . , .

script, . , . , , , pdf.

+1

UIWebView pdf, pdf. . .

CGPDF, CGPDFDocumentRef CGPDFPageRef, PDF.

, PDF . 1. PDF UIImageView. 2. CGPDFPageRef pdf - ( PDF )

.

-(UIImage *)getPage : (NSString*) filePath{

    const char *myBuffer           = (const char*)filePath;                        // PDF Path
    CFStringRef urlString          = (CFStringRef)myBuffer;
    CFURLRef url                   = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, urlString, 2, NO);  
    CGPDFDocumentRef myDocumentRef = CGPDFDocumentCreateWithURL(url);

    CGPDFPageRef myPageRef         = CGPDFDocumentGetPage(myDocumentRef, 1);
    CGRect pdfcropBox              = CGPDFPageGetBoxRect(myPageRef,kCGPDFCropBox); //kCGPDFCropBox

    UIGraphicsBeginImageContext      (pdfcropBox.size);
    CGContextRef context           = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM            (context,0,pdfcropBox.size.height);// [self pageRect].origin.x,[self pageRect].origin.y+[self pageRect].size.height); //320);
    // scale 1:1 100%
    CGContextScaleCTM                (context, 1.0, -1.0);
    CGContextSaveGState              (context);
    CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(myPageRef, kCGPDFCropBox, CGRectMake(0, 0, pdfcropBox.size.width,pdfcropBox.size.height), 0, true);  //
    CGContextConcatCTM               (context, pdfTransform);
    CGContextDrawPDFPage             (context, myPageRef);
    CGContextRestoreGState           (context);

    UIImage *resultingImage        = UIGraphicsGetImageFromCurrentImageContext();  
    UIGraphicsEndImageContext        ();
    CGPDFDocumentRelease             (myDocumentRef);

    //CGPDFPageRelease(myPageRef);
        //myPageRef   = nil;
    myDocumentRef = nil;
    urlString     = nil;
    url           = nil;
    return resultingImage;
}
+1

Here are my 2 cents about simple and quick pdf rendering in swift.

SwiftyPDF

  • Paging with UIPageViewController
  • Scaling with UIScrollView Scaling Functions
  • Fast PDF rendering by converting the page to a placeholder image
  • The PDF page is scaled and divided into small tiles. Tiles are cached into image files and rendered above the placeholder (using CATiledLayer).

More WIP

0
source

All Articles