2012-01-27 29 views
1

我从NSTextview保存PDF并在标题中放置徽标。我忽略了pageHeader并且标志出现了,但它被裁剪了。是否可以更改NSTextView的标题高度?

是否可以更改NSTextView的标题高度?

谢谢!

部分代码:

-(IBAction)impLaudo:(id)sender 
{ 
    NSPrintInfo *printInfo; 
    NSPrintInfo *sharedInfo; 
    NSPrintOperation *printOp; 
    NSMutableDictionary *printInfoDict; 
    NSMutableDictionary *sharedDict; 

    sharedInfo = [NSPrintInfo sharedPrintInfo]; 
    sharedDict = [sharedInfo dictionary]; 
    printInfoDict = [NSMutableDictionary dictionaryWithDictionary:sharedDict]; 

    [printInfoDict setObject:NSPrintSaveJob forKey:NSPrintJobDisposition]; 
    [printInfoDict setObject:[[dirLaudos stringByAppendingString:[estudo stringValue]] stringByAppendingString:@".pdf"] forKey:NSPrintSavePath]; 

    printInfo = [[NSPrintInfo alloc] initWithDictionary: printInfoDict]; 
    [printInfo setHorizontalPagination: NSClipPagination]; 
    [printInfo setVerticalPagination: NSAutoPagination]; 
    [printInfo setVerticallyCentered:NO]; 
    [[printInfo dictionary] setValue:[NSNumber numberWithBool:YES] forKey:NSPrintHeaderAndFooter]; 

    printOp = [NSPrintOperation printOperationWithView:textView printInfo:printInfo]; 
    [printOp setShowsPrintPanel:NO]; 
    [printOp runOperation];  
} 


@implementation MyTextView 

- (NSAttributedString *)pageHeader 
{ 
    // Adicionando cabeçalho 
    NSAttributedString *theHeader = nil; 

    NSImage * pic = [[NSImage alloc] initWithContentsOfFile:[dirLayout stringByAppendingString:@"cabecalho.jpg"]]; 
    NSTextAttachmentCell *attachmentCell = [[NSTextAttachmentCell alloc] initImageCell:pic]; 
    NSTextAttachment *attachment = [[NSTextAttachment alloc] init]; 
    [attachment setAttachmentCell: attachmentCell ]; 
    theHeader = [NSAttributedString attributedStringWithAttachment: attachment]; 
    return theHeader; 
} 

@end  
+0

请发布您用于生成PDF的代码。 – 2012-01-27 21:42:51

回答

0

取而代之的首要-pageHeader,你应该重写-drawPageBorderWithSize:,它允许您在打印时在页面上吸引更多的标记。

Size参数是一个包含当前逻辑页面大小的NSSize结构。您需要做的只是在正确的位置绘制您的徽标:

- (void)drawPageBorderWithSize:(NSSize)pageSize 
{ 
    [super drawPageBorderWithSize:pageSize]; 
    //draw your logo 
    NSPoint offset = NSMakePoint(100.0, 100.0); 
    NSImage* logo = [NSImage imageNamed:@"logo"]; 
    NSSize logoSize = [logo size]; 
    NSPoint imageOrigin = NSMakePoint(offset.x, pageSize.height - (offset.y + logoSize.height)); 
    [logo drawInRect:NSMakeRect(imageOrigin.x, imageOrigin.y, logoSize.width, logoSize.height 
      fromRect:NSZeroRect 
      operation:NSCompositeSourceOver 
      fraction:1.0 
     respectFlipped:YES 
       hints:nil]; 
} 
+0

谢谢@ rob-keniger!代码发布。我会尝试你的建议。 – RinaldoSJr 2012-01-27 23:07:05

+0

它的工作原理!非常感谢@ rob-keniger! – RinaldoSJr 2012-01-28 22:45:22

+0

太好了。如果出现这种情况,您应该将问题标记为已回答。 – 2012-01-29 01:13:06

相关问题