Re: Problem with NSData to NSString to NSData
Dear Cocoa-dev People, I wanted to thank everyone for their helpful replies to my question: How to save metadata for a PDF file? Graham, thank you for confirming and clarifying the Cocoa way. Your caveat (problem with other pdf readers) was also well taken! Ricky, thank you for your trenchant analysis and commentary. The reification of your suggested approach, by mentioning the TextEdit example, was way helpful! Michael, you've identified additional (and compelling) approaches that I'd have never quantified on my own! They bear looking into; part of my continuing Cocoa education :-) Dave, you know a lot about the PDF format! Thanks for quantifing a PDF compatible way to append metadata to a PDF! Jeff, you also know a lot about the PDF format! Thanks for clarifying another PDF compatible way to append metadata to a PDF! Marcel, thanks for your reply! My conclusion is that The Cocoa Way would be to use NSFileWrappers. (Not to deprecate the suggested PDF approaches – there's nothing wrong with them.) I've looked at using NSFileWrappers, but still have some questions. My plan is to take them to NSCoder Night (in Campbell) and flesh out the recipe, part of my ongoing Cocoa education :-) As an aside, I want to strongly recommend Eric Buck's Cocoa Design Patterns which led me toward the NSFileWrapper approach in the first place! (It's available through Safari Books Online Rough Cuts.) Many thanks, Joel Norvell ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Problem with NSData to NSString to NSData
From your original implementation of putting the metadata directly into the PDF file, you'll now end up with obviously a proprietary file. i.e. No application that works with PDF will be able to work with that file. That is not at all true. You can embed the data into a PDF stream but never reference it. You'll have to check for an available stream ID and also correct the cross reference table. You could in fact leave the original cross reference table intact, add a new stream with your metadata after the original %%EOF marker, construct the cross-reference table with only one entry (the stream containing the metadata), and adding another %%EOF marker. This is perfectly legit PDF and in fact is the recommended way to use incremental updates as per page 70 of the PDF reference. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Problem with NSData to NSString to NSData
On Wed, Oct 29, 2008 at 4:46 PM, Joel Norvell [EMAIL PROTECTED] wrote: Dear Cocoa-dev People, First, I wanted to thank Aki Inoue and Rob Keniger for pointing out the problem with my NSData-NSString-NSData approach. As an alternative, would it be fruitful to use a Directory Wrapper to represent the data as two files; one the metadata and the other the pdf? Then I could work with the metadata file, but just display the pdf file. In the What could go wrong here? department, would my compound file end up behaving like a directory (or worse)? Better yet, why not just insert the metadata into the PDF directly as comments? The PDF format is basically a postscript file (with some missing features and, I think, optional compression) and you should be able to insert comments (lines starting with %%) after the first line (which is a required header comment) with no problem. Reliably detecting PDF files that contain your meta data and extracting it may be a bit of a challenge, in the general case, but not really all that hard. Before writing a lot of custom code to do this, I'd have a look at the documentation for PDFKit and PDFDocument. you can get references on the PDF format here: http://www.adobe.com/devnet/pdf/pdf_reference_archive.html -- Jeff Dutky ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Problem with NSData to NSString to NSData
Dear Cocoa-dev People, First, I wanted to thank Aki Inoue and Rob Keniger for pointing out the problem with my NSData-NSString-NSData approach. As an alternative, would it be fruitful to use a Directory Wrapper to represent the data as two files; one the metadata and the other the pdf? Then I could work with the metadata file, but just display the pdf file. In the What could go wrong here? department, would my compound file end up behaving like a directory (or worse)? Many thanks, Joel Norvell On 2008/10/28, at 21:43, Joel Norvell email_removed wrote: Dear Cocoa-dev People, 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? Sincerely, Joel Norvell ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Problem with NSData to NSString to NSData
On 30 Oct 2008, at 7:46 am, Joel Norvell wrote: As an alternative, would it be fruitful to use a Directory Wrapper to represent the data as two files; one the metadata and the other the pdf? Then I could work with the metadata file, but just display the pdf file. In the What could go wrong here? department, would my compound file end up behaving like a directory (or worse)? What could be worse? ;-) As long as you set the package bit it will look like a file, as least on OS X. On other file systems it will look like a directory. The problem I think is that your file would cease to be directly openable by any other program that reads PDFs unless they are aware of your package layout, or can drill down into packages, which isn't common. hth, Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Problem with NSData to NSString to NSData
On Oct 29, 2008, at 3:46 PM, Joel Norvell wrote: Dear Cocoa-dev People, First, I wanted to thank Aki Inoue and Rob Keniger for pointing out the problem with my NSData-NSString-NSData approach. As an alternative, would it be fruitful to use a Directory Wrapper to represent the data as two files; one the metadata and the other the pdf? Then I could work with the metadata file, but just display the pdf file. In the What could go wrong here? department, would my compound file end up behaving like a directory (or worse)? From your original implementation of putting the metadata directly into the PDF file, you'll now end up with obviously a proprietary file. i.e. No application that works with PDF will be able to work with that file. By having a separate file, things can become fragile. However, the solution here is to use a package type for a custom document. Just as TextEdit does for the rtfd type. Your package folder would then contain the original PDF and a separate file (or files) for your metadata. This document type would most likely not be openable in any app that opens PDF (unless their open dialogs have the 'allow navigation of packages' option set). But, advanced users could your package via Finder and work with the PDF directly if they need to. ___ Ricky A. Sharp mailto:[EMAIL PROTECTED] Instant Interactive(tm) http://www.instantinteractive.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Problem with NSData to NSString to NSData
Dear Cocoa-dev People, 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? Sincerely, Joel Norvell ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Problem with NSData to NSString to NSData
Joel, The PDF is a binary data format. So, trying to decode with an ASCII encoding vonverter would result in data loss. I recommend processing it as mere bytes without mapping to a string. Aki from iPhone On 2008/10/28, at 21:43, Joel Norvell [EMAIL PROTECTED] wrote: Dear Cocoa-dev People, 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? Sincerely, Joel Norvell ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/aki%40apple.com This email sent to [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Problem with NSData to NSString to NSData
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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]