Search code examples
ioscgpdfdocument

Get CGPDFDocumentRef name of document


Is it possible to retrieve the name of a document from a CGPDFDocumentRef


Solution

  • By "name of a document", do you mean the document filename or title?

    If the document "title" is included in the metadata it can be retrieved like this:

        char *titleKey = "Title";
        CGPDFStringRef titleStringRef;
    
        CGPDFDictionaryRef info = CGPDFDocumentGetInfo(myDocumentRef);
        CGPDFDictionaryGetString(info, titleKey, &titleStringRef);
        const unsigned char *titleCstring = CGPDFStringGetBytePtr(titleStringRef);
    
        printf("title: %s", titleCstring);
    

    The other keys are listed in section 10.2 of the PDF 1.7 specification: Adobe PDF Reference Archives