2012-01-27 59 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

相關問題