Re: C *char representation of PDF into NSImage
Re: C *char representation of PDF into NSImage
- Subject: Re: C *char representation of PDF into NSImage
- From: Marcel Weiher <email@hidden>
- Date: Sun, 25 Feb 2007 15:06:06 -0800
On Feb 25, 2007, at 9:08 , Eric Brown wrote:
-(void) awakeFromNib
{
int PDFDataLength;
NSMutableData *PDFData;
char *PDFbuffer;
char *oneChar=" ";
NSPDFImageRep *pdfImage;
// obtain length of "%PDF...." The returned number is around
15000.
PDFDataLength=pdfbuf(oneChar,0);
// I've seen this method used for floats, ints, etc.
PDFData =[[NSMutableData alloc]
initWithCapacity: (unsigned int) PDFDataLength];
PDFbuffer=[PDFData mutableBytes];
// Here I try to slurp in the data
PDFDataLength=pdfbuf(PDFbuffer, PDFDataLength);
[PDFData setLength:PDFDataLength];
// I'm not sure if this is relevant yet!
pdfImage=[[NSPDFImageRep alloc] initWithData: PDFData];
image=[[NSImage alloc] initWithData: PDFData];
}
A couple of style pointers: classes are typically uppercase,
variables/instances lowercase. The pdfbuf() function appears a bit
magical. You don't need to initialize both an NSImage and a
NSPDFImageRep with the data. The NSImage will create an NSPDFImageRep
internally, while the NSPDFImageRep can be converted if necessary.
Marcel
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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