Reputation: 1
I have an NSView
with NSImage
instances as subviews that all show up correctly on the screen. I want to save them to a PDF file but the subviews are not included.
The routine works well and also saves to PDF. The resulting PDF file contains all that I draw on the NSView
, but the NSImage-subviews are only visible on screen but not in the PDF file.
Any suggestions?
NSString* savePath = [self getSavePath];
if (savePath != nil) {
NSData *pdfData = [_myCtDistView dataWithPDFInsideRect:_myCtDistView.bounds];
if ([pdfData writeToFile:savePath atomically:YES]) {
NSLog(@"Saved PDF successfully");
} else {
NSLog(@"Saved PDF failed");
}
}
View drawing code:
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
[[NSColor whiteColor] set];
NSRectFill(self.bounds);
[self drawBgImage];
}//end of drawRect
- (void)drawBgImage {
NSImageView *backgroundImageView = [[NSImageView alloc] initWithFrame:self.bounds];
backgroundImageView.image = _bgImage;
backgroundImageView.imageScaling = NSImageScaleProportionallyUpOrDown;
[self addSubview:backgroundImageView];
}// end of drawBgImage
Upvotes: 0
Views: 31