SORU
2 Kasım 2010, Salı


Kuvars ile iOS PDF köprüler olsun

Bütün gün köprüler iPad uygulamam PDF meta veri almak için harcadım. Bu CGPDF* API gerçek bir kabus, ve tek parça bilgi buldum net hakkında bu olduğuna bakmam lazım "Annots" sözlük, ama ben sadece bulamıyorum benim PDF'leri.

Ben bile Voyeur Xcode sample benim test PDF dosyası, ama bu hiçbir iz incelemek için kullanılan eski "Annots" sözlük...

Bu her PDF okuyucu üzerinde gördüğüm bir özelliktir - bu aynı soruyu burada gerçek bir pratik cevaplar* asked multiple times *4 var. Ben genelde hiç örnek kod için doğrudan sormak ama görünüşe göre bu sefer gerçekten ihtiyacım var... herkes bu, muhtemelen örnek kod ile çalışan var mı?

GüncellemeBen benim test PDF yapan adam sadece metin ve gerçek bir açıklama değil, bir URL takılı olmadığını fark ettim. Şimdi bir açıklama ve benim kod çalışır koyarak çalıştı... Ama ihtiyacım olan bu değil, metin ve URL için arama analiz etmek zorunda kalacağım gibi görünüyor. Ama bu başka bir hikaye...

Güncelleme 2: Sonunda çalışan bir kod ile geldi. Burada birileri yardımcı olur umarım post ediyorum. PDF belge aslında ek açıklamalar içeren varsayar.

for(int i=0; i<pageCount; i  ) {
    CGPDFPageRef page = CGPDFDocumentGetPage(doc, i 1);

    CGPDFDictionaryRef pageDictionary = CGPDFPageGetDictionary(page);

    CGPDFArrayRef outputArray;
    if(!CGPDFDictionaryGetArray(pageDictionary, "Annots", &outputArray)) {
        return;
    }

    int arrayCount = CGPDFArrayGetCount( outputArray );
    if(!arrayCount) {
        continue;
    }

    for( int j = 0; j < arrayCount;   j ) {
        CGPDFObjectRef aDictObj;
        if(!CGPDFArrayGetObject(outputArray, j, &aDictObj)) {
            return;
        }

        CGPDFDictionaryRef annotDict;
        if(!CGPDFObjectGetValue(aDictObj, kCGPDFObjectTypeDictionary, &annotDict)) {
            return;
        }

        CGPDFDictionaryRef aDict;
        if(!CGPDFDictionaryGetDictionary(annotDict, "A", &aDict)) {
            return;
        }

        CGPDFStringRef uriStringRef;
        if(!CGPDFDictionaryGetString(aDict, "URI", &uriStringRef)) {
            return;
        }

        CGPDFArrayRef rectArray;
        if(!CGPDFDictionaryGetArray(annotDict, "Rect", &rectArray)) {
            return;
        }

        int arrayCount = CGPDFArrayGetCount( rectArray );
        CGPDFReal coords[4];
        for( int k = 0; k < arrayCount;   k ) {
            CGPDFObjectRef rectObj;
            if(!CGPDFArrayGetObject(rectArray, k, &rectObj)) {
                return;
            }

            CGPDFReal coord;
            if(!CGPDFObjectGetValue(rectObj, kCGPDFObjectTypeReal, &coord)) {
                return;
            }

            coords[k] = coord;
        }               

        char *uriString = (char *)CGPDFStringGetBytePtr(uriStringRef);

        NSString *uri = [NSString stringWithCString:uriString encoding:NSUTF8StringEncoding];
        CGRect rect = CGRectMake(coords[0],coords[1],coords[2],coords[3]);

        CGPDFInteger pageRotate = 0;
        CGPDFDictionaryGetInteger( pageDictionary, "Rotate", &pageRotate ); 
        CGRect pageRect = CGRectIntegral( CGPDFPageGetBoxRect( page, kCGPDFMediaBox ));
        if( pageRotate == 90 || pageRotate == 270 ) {
            CGFloat temp = pageRect.size.width;
            pageRect.size.width = pageRect.size.height;
            pageRect.size.height = temp;
        }

        rect.size.width -= rect.origin.x;
        rect.size.height -= rect.origin.y;

        CGAffineTransform trans = CGAffineTransformIdentity;
        trans = CGAffineTransformTranslate(trans, 0, pageRect.size.height);
        trans = CGAffineTransformScale(trans, 1.0, -1.0);

        rect = CGRectApplyAffineTransform(rect, trans);

        // do whatever you need with the coordinates.
        // e.g. you could create a button and put it on top of your page
        // and use it to open the URL with UIApplication's openURL
    }
}

CEVAP
2 Kasım 2010, Salı


işte her sayfa için en az annots bu CGPDFDictionary ulaşmak için temel fikir. sonra PDF spec yardımıyla anlamaya gerekir.

1.) bu CGPDFDocumentRef.

2.) her bir sayfa olsun.

3.) her sayfada, pageDictionary bu CGPDFDictionary bu CGPDFPage temsil eden ve outputArray değişken (CGPDFArrayRef) Bu sayfanın Annots dizi store nerede CGPDFDictionaryGetArray(pageDictionary, "Annots", &outputArray) kullanın.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Branboy3

    Branboy3

    12 AĞUSTOS 2012
  • Julian Smith

    Julian Smith

    31 EKİM 2006
  • Major FX

    Major FX

    6 HAZİRAN 2012