Re: Problem with NSData to NSString to NSData
Re: Problem with NSData to NSString to NSData
- Subject: Re: Problem with NSData to NSString to NSData
- From: Rob Keniger <email@hidden>
- Date: Wed, 29 Oct 2008 14:58:15 +1000
On 29/10/2008, at 2:43 PM, Joel Norvell wrote:
I have a file with some metadata prepended to a pdf.
I want to strip the metadata off and display the pdf.
I was trying to do this:
- (void) loadFromPath: (NSString *) path
{
NSData *myData = [NSData dataWithContentsOfFile:path];
NSString *myStr = [[NSString alloc] initWithData:pdfData
encoding:NSASCIIStringEncoding];
// I strip off the metadata here, leaving the pdfStr.
// Nothing I've tried here has worked:
NSData * myNewData = [pdfStr dataUsingEncoding: ???];
// Display the pdf here...
}
How can I get this to work?
You can't treat a PDF file as a string, it isn't. You must use NSData
methods to work with the raw bytes of the PDF to do the stripping of
the metadata instead.
Then you would do something like:
PDFDocument* myPDF=[[PDFDocument alloc] initWithData:pdfData];
You can then display the PDFDocument in a PDFView.
--
Rob Keniger
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden