簡體   English   中英

PDFAnnotationText在10.12上不顯示彈出窗口

[英]PDFAnnotationText is not displaying pop-up on 10.12

PDFAnnotationText在macOS sierra 10.12.1 Beta(16B2548a)上未顯示彈出窗口。 PDFAnnotationText在10.12上已棄用,但新的API並未繪制注釋。

舊的API:

// display the PDF document
    [m_pdfView setDocument: [self pdfDocument]];

- (PDFDocument *)pdfDocument {
    // create a page

    PDFDocument *document = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:@"/Users/test/Downloads/Eticket.pdf"]];
    PDFAnnotationText* result = [[PDFAnnotationText alloc] initWithBounds:NSMakeRect(100, 100, 40, 40)];
    result.color = [NSColor redColor];
    result.contents = @"Hello";
    result.iconType = kPDFTextAnnotationIconNote;
    // add it to the PDF document
    [[document pageAtIndex:0] addAnnotation:result];
    return document;
}

10.12新的API:

- (PDFDocument *)pdfDocument {
    // create a page
    PDFDocument *document = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:@"/Users/test/Downloads/Eticket.pdf"]];

    NSMutableDictionary *popupDictionary = [[NSMutableDictionary alloc] init];

    [popupDictionary setObject:@"/Popup" forKey:kPDFAnnotationKey_Subtype];
    [popupDictionary setObject:[NSColor redColor] forKey:kPDFAnnotationKey_Color];
    [popupDictionary setObject:@"Hello" forKey:kPDFAnnotationKey_Contents];

    NSValue *rectValue = [NSValue valueWithRect:NSMakeRect(100, 100, 40, 40)];
    [popupDictionary setObject:rectValue forKey:kPDFAnnotationKey_Rect];

    PDFAnnotation *textAnnotation = [[PDFAnnotation alloc] initWithDictionary: popupDictionary forPage: [document pageAtIndex:0]];
    [[document pageAtIndex:0] addAnnotation:textAnnotation];    // add it to the PDF document
    return document;
}

我正在使用Xcode版本8.0(8A218a)。 有人可以幫我嗎?

我能夠這樣創建一個簡單的黑色字符串注釋(在Swift 3中):

let document = pdfView!.document
let page = document!.page(at:0)
let pageBounds = page!.bounds(for: PDFDisplayBox.artBox)
let annotation = PDFAnnotation()
annotation.setValue("/FreeText", forAnnotationKey: kPDFAnnotationKey_Subtype)
annotation.setValue("HELLO WORLD", forAnnotationKey: kPDFAnnotationKey_Contents)
annotation.setValue(NSColor.clear, forAnnotationKey: kPDFAnnotationKey_Color)
annotation.bounds = NSRect(x:10, y:pageBounds.height-50, width:400, height:40)
page!.addAnnotation(annotation)

它正在使用/ FreeText,但是如果您嘗試使用這些值,也許會對您有所幫助。 仍然不知道如何更改文本的顏色。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM