Announcement

Collapse
No announcement yet.

iOS, FSPDF_Doc_StartLoad Error -3 FSCRT_ERRCODE_INVALIDMODULE

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • iOS, FSPDF_Doc_StartLoad Error -3 FSCRT_ERRCODE_INVALIDMODULE

    A quick overview of what I'm working on. We are using an evaluation version of the SDK. I'm trying to open an existing PDF, and add Note (or text) annotations to specific pages.

    Here's my code:

    Code:
    if(!createdFoxit) {
        //create manager
        FSCRT_Library_CreateDefaultMgr();
        
        //set license
        FSCRT_BSTR licenseId;
        FSCRT_BStr_Init(&licenseId);
        const char * sn = "REDACTED";
        FSCRT_BStr_Set(&licenseId, sn, strlen(sn));
        
        //unlock code
        FSCRT_BSTR unlockCode;
        FSCRT_BStr_Init(&unlockCode);
        const char * unlock = "REDACTED";
        FSCRT_BStr_Set(&unlockCode, unlock, strlen(unlock));
        
        FS_RESULT ret = FSCRT_License_UnlockLibrary(&licenseId, &unlockCode);
        if(ret != FSCRT_ERRCODE_SUCCESS) {
            NSLog(@"failed to unlock");
        }
        
        //check license type
        FS_INT32 type;
        FSCRT_License_GetType(&type);
        if(type == FSCRT_LICENSETYPE_AUTHORIZED) {
            NSLog(@"authorize");
        }
        if(type == FSCRT_LICENSETYPE_EVALUATION) {
            NSLog(@"evaluation");
        }
        if(type == FSCRT_LICENSETYPE_EXPIRED) {
            NSLog(@"expired");
        }
        if(type == FSCRT_LICENSETYPE_INVALID) {
            NSLog(@"invalid");
        }
        
        //clear strings
        FSCRT_BStr_Clear(&licenseId);
        FSCRT_BStr_Clear(&unlockCode);
    }
    
    /* TRY AND OPEN A PDF, ADD ANNOTATIONS TO THEM */
    
    //create filename (THIS WORKS)
    FSCRT_BSTR filename;
    FSCRT_BStr_Init(&filename);
    FSCRT_BStr_Set(&filename, (char*)[self pdfURLForWorkbook].path.UTF8String, [self pdfURLForWorkbook].path.length);
    
    //open file (THIS WORKS)
    FSCRT_FILE file = NULL;
    FS_RESULT ret = FSCRT_File_CreateFromFileName(&filename, FSCRT_FILEMODE_WRITE, &file);
    if( ret != FSCRT_ERRCODE_SUCCESS ) {
        NSLog(@"can't open file");
        return;
    }
    
    //create document and load (THIS DOESN'T WORKS)
    FSCRT_DOCUMENT document;
    ret = FSPDF_Doc_StartLoad(file, NULL, &document, NULL);
    if( ret != FSCRT_ERRCODE_SUCCESS) {
        NSLog(@"can't start doc");
        return;
    }
    
    //Creating the document above doesn't work, so it returns early.
    
    //Is the rest of my code properly creating an annotation and setting it's type / content correctly? 
    
    //page storage
    FSCRT_PAGE pdfpage;
    
    //go through each page
    NSUInteger page = 0;
    for(MMNotationView * notationView in workbook.notationViews) {
        
        if(!notationView.shouldBeIncludedInPDF) {
            continue;
        }
        
        NSArray * notes = [notationView cellSubviewsOnlyNotes];
        if(notes.count < 1) {
            continue;
        }
        
        //get page
        ret = FSPDF_Doc_GetPage(document, page, &pdfpage);
        if( ret != FSCRT_ERRCODE_SUCCESS ) {
            NSLog(@"cant get page");
            return;
        }
        
        //go through notes in annotation view
        NSUInteger annotCount = 0;
        for(MMNotationNote * note in notes) {
            
            //create the rect
            FSCRT_RECTF noteRect = {note.center.x, notationView.height - note.center.y,1,1};
            
            //create the content string
            FSCRT_BSTR noteString;
            FSCRT_BStr_Init(&noteString);
            FSCRT_BStr_Set(&noteString, note.entry.text.UTF8String, note.entry.text.length);
            
            //annot
            FSCRT_ANNOT annot;
            
            //create annot type string
            FSCRT_BSTR annotType;
            FSCRT_BStr_Init(&annotType);
            FSCRT_BStr_Set(&annotType, FSPDF_ANNOTTYPE_TEXT, strlen(FSPDF_ANNOTTYPE_TEXT));
            
            //add annot to page
            ret = FSPDF_Annot_Add(pdfpage, &noteRect, &annotType, NULL, annotCount, &annot);
            if( ret != FSCRT_ERRCODE_SUCCESS ) {
                NSLog(@"cannot add annotation to page");
                continue;
            }
            
            //set annot content
            FSPDF_Annot_SetContents(annot, &noteString);
            
            //export the note to the document
            FSPDF_Annot_ExportToFDFDoc(annot, document);
            
            //clear strings
            FSCRT_BStr_Clear(&annotType);
            FSCRT_BStr_Clear(&noteString);
            
            annotCount++;
        }
        
        page++;
    }
    
    FSPDF_Doc_Close(document);
    FSCRT_File_Release(file);

    In the code above, the licensing code all works, it correctly reports that it's an evaluation license.

    What doesn't work is when I'm trying to open the document.

    Also can anyone read the rest of the code and tell me if I'm correctly adding an annotation to a page, and setting it's rect and content properly?


  • #2
    Dear gngrwzrd,

    Thanks for your post.For SDK questions or problems,please help to mail to adv.support@foxitsoftware.com directly and our SDK engineers will further help you via email.

    Comment

    Working...
    X