• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Optimizing PDFKit
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Optimizing PDFKit


  • Subject: Re: Optimizing PDFKit
  • From: Shaun Wexler <email@hidden>
  • Date: Wed, 5 Oct 2005 02:59:37 -0700

On Oct 4, 2005, at 2:11 PM, Ricky Sharp wrote:

All images for my app are now PDF and I'd like to encrypt them to protect my artwork.

Anyhow, I wanted to make sure my image loading times would not suffer. I kept all my PDFs unencrypted and changed this line:

NSImage* theImage = [[NSImage alloc] initWithContentsOfFile:theImagePath];

to...

NSURL* thePDFURL = [[[NSURL alloc] initFileURLWithPath:theImagePath] autorelease];
PDFDocument* thePDFDocument = [[[PDFDocument alloc] initWithURL:thePDFURL] autorelease];


    if ([thePDFDocument isEncrypted])
        {
        // not yet implemented
        }

NSImage* theImage = [[NSImage alloc] initWithData: [thePDFDocument dataRepresentation]];


For the same run of a test script, the PDFKit code is a full order of magnitude slower. I'm running 10.4.2 on a dual 2GHz G5 and am concerned about users with slower machines.

You're performing two stages of unnecessary+expensive data conversion!!!

Does anyone know of a different (faster) path to decrypt PDFs and ultimately create NSImage instances out of them?

All you need to do is sniff the raw data and decrypt the binary if necessary:


NSData *data = [NSMutableData dataWithContentsOfFile:theImagePath];
NSImage *theImage = nil;
UInt32 magic, *bytes;
if ((bytes = [data bytes])) {
if ((magic = *bytes) == NSSwapBigIntToHost('cryp')) {
theImage = [[NSImage alloc] initWithEncryptedData:data]; // my method
} else // if (magic == NSSwapBigIntToHost('%PDF')) {
theImage = [[NSImage alloc] initWithData:data];
// }
}


Email me if you need me to write you an implementation, plus my encrypting tool (which you can script into a Deployment build phase).
--
Shaun Wexler
MacFOH
http://www.macfoh.com



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Optimizing PDFKit
      • From: Shaun Wexler <email@hidden>
References: 
 >Optimizing PDFKit (From: Ricky Sharp <email@hidden>)

  • Prev by Date: Re: Live resizing strategies for custom views
  • Next by Date: Re: Live resizing strategies for custom views
  • Previous by thread: Re: Optimizing PDFKit
  • Next by thread: Re: Optimizing PDFKit
  • Index(es):
    • Date
    • Thread