• 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
Drawing to a PDF image representation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Drawing to a PDF image representation


  • Subject: Drawing to a PDF image representation
  • From: "ad veloper" <email@hidden>
  • Date: Mon, 25 Feb 2008 22:42:05 +0000

List,


How do I draw NSBezierPaths to my pdf representation?


This method only seems to capture the last NSBezierPath in the saved .pdf,
and none of the previous ones, even though they are successfully being drawn
to the image using the [image lockFocus] method.




Here's some of the implementation file:


- (id)initWithFrame:(NSRect)frame {

    self = [super initWithFrame:frame];

    if (self) {

      _pdfRep = [[NSPDFImageRep imageRepWithContentsOfFile:
@"/path/to/file.pdf"] retain];


      image = [[NSImage alloc] initWithSize:[_pdfRep size]];

      [image setDataRetained:YES]; // ensure vector data is kept

      [image addRepresentation:_pdfRep];

    }

    return self;

}



- (void)drawRect:(NSRect)aRect

{

[[NSColor grayColor] set];

NSRectFill( aRect );


        // other code here that sets viewSize etc. has been removed for
brevity


        // if saving, get the best, i.e. pdf representation, otherwise
redraw the cached image.

if (needToUseRealPDFData == YES) {

needToUseRealPDFData = NO;


         [[image bestRepresentationForDevice:nil] drawInRect:NSMakeRect(0.0,
0.0, viewSize.width, viewSize.height)];

// [_pdfRep drawInRect:NSMakeRect(0.0,0.0, viewSize.width, viewSize.height
)];


 } else

[image drawInRect:NSMakeRect(0.0,0.0,viewSize.width,viewSize.height)
fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];


        // when saving the .pdf only the last line appears in the file

[[NSColor redColor] set];

[NSBezierPath strokeLineFromPoint:previousLocation toPoint:location];


        // add a path for the updated mouse positions

[image lockFocus];

[[NSColor redColor] set];

[NSBezierPath strokeLineFromPoint:previousLocation toPoint:location];

[image unlockFocus];

}



- (void)keyDown:(NSEvent *)theEvent

{

    NSString *keyChar = [theEvent characters];

    if ( [keyChar isEqualToString:@"s"] ) {

 needToUseRealPDFData = YES;


 NSRect r = [self bounds];

NSData *data = [self dataWithPDFInsideRect:r];

[data writeToFile:@"/path/to/test.pdf" atomically:NO];

}

}



Thanks,
_______________________________________________

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

  • Follow-Ups:
    • Re: Drawing to a PDF image representation
      • From: "I. Savant" <email@hidden>
  • Prev by Date: Re: Table column index
  • Next by Date: Re: NSInvocation question
  • Previous by thread: NSTreeController with Garbage Collection without CoreData causes problems
  • Next by thread: Re: Drawing to a PDF image representation
  • Index(es):
    • Date
    • Thread