通过iPhone应用程序读取PDF文件作为字符串

通过iPhone应用程序读取PDF文件作为字符串,第1张

概述我在iPhone阅读PDF中面临一些问题。 我已经尝试了以下代码。我知道我使用错误的方法来解析 – 解析方法只是用于搜索目的。但是我想将整个pdf文本转换成字符串。说例如苹果的MobileHIG.pdf – 我在这段代码中使用过。 @implementation NetPDFViewControllersize_t totalPages; // a variable to store tot 我在iPhone阅读pdf中面临一些问题。
我已经尝试了以下代码。我知道我使用错误的方法来解析 – 解析方法只是用于搜索目的。但是我想将整个pdf文本转换成字符串。说例如苹果的MobileHIG.pdf – 我在这段代码中使用过。

@implementation NetpdfVIEwControllersize_t totalPages;  // a variable to store total pages// a method to get the pdf refCGpdfdocumentRef MyGetpdfdocumentRef (const char *filename) {    CFStringRef path;    CFURLRef url;    CGpdfdocumentRef document;    path = CFStringCreateWithCString (NulL,filename,kcfStringEnCodingUTF8);    url = CFURLCreateWithfileSystemPath (NulL,path,kcfURLPOSIXPathStyle,0);    CFRelease (path);    document = CGpdfdocumentCreateWithURL (url);// 2    CFRelease(url);    int count = CGpdfdocumentGetNumberOfPages (document);// 3    if (count == 0) {        printf("`%s' needs at least one page!",filename);        return NulL;    }    return document;}// table methods to parse pdfstatic voID op_MP (CGpdfScannerRef s,voID *info) {    const char *name;    if (!CGpdfScannerPopname(s,&name))        return;    printf("MP /%s\n",name);   }static voID op_DP (CGpdfScannerRef s,&name))        return;    printf("DP /%s\n",name);   }static voID op_BMC (CGpdfScannerRef s,&name))        return;    printf("BMC /%s\n",name);  }static voID op_BDC (CGpdfScannerRef s,&name))        return;    printf("BDC /%s\n",name);  }static voID op_EMC (CGpdfScannerRef s,&name))        return;    printf("EMC /%s\n",name);  }// a method to display pdf page.voID Mydisplaypdfpage (CGContextRef myContext,size_t pageNumber,const char *filename) {    CGpdfdocumentRef document;    CGpdfpageRef page;    document = MyGetpdfdocumentRef (filename);// 1    totalPages=CGpdfdocumentGetNumberOfPages(document);    page = CGpdfdocumentGetPage (document,pageNumber);// 2    CGpdfDictionaryRef d;    d = CGpdfpageGetDictionary(page);// ----- edit   problem here - CGpdfDictionary is completely unkNown // ----- as we don't kNow keys & values of it.    CGpdfScannerRef myScanner;     CGpdfOperatortableRef mytable;    mytable = CGpdfOperatortableCreate();    CGpdfOperatortableSetCallback (mytable,"MP",&op_MP);    CGpdfOperatortableSetCallback (mytable,"DP",&op_DP);    CGpdfOperatortableSetCallback (mytable,"BMC",&op_BMC);    CGpdfOperatortableSetCallback (mytable,"BDC",&op_BDC);    CGpdfOperatortableSetCallback (mytable,"EMC",&op_EMC);    CGPdfcontentStreamRef myContentStream = CGPdfcontentStreamCreateWithPage (page);// 3    myScanner = CGpdfScannerCreate (myContentStream,mytable,NulL);// 4    CGpdfScannerScan (myScanner);// 5//  CGpdfDictionaryRef d;    CGpdfStringRef str; // represents a sequence of bytes    d = CGpdfpageGetDictionary(page);    if (CGpdfDictionaryGetString(d,"Thumb",&str)){        CFStringRef s;        s = CGpdfStringcopyTextString(str);        if (s != NulL) {            //need something in here in case it cant find anything            NSLog(@"%@ testing it",s);        }        CFRelease(s);       //      CFDataRef data = CGpdfStreamcopyData (stream,CGpdfDataFormatRaw);    }// -----------------------------------      CGContextDrawpdfpage (myContext,page);// 3    CGContextTranslateCTM(myContext,20);    CGContextScaleCTM(myContext,1.0,-1.0);    CGpdfdocumentRelease (document);// 4}- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];// -------------------------------------------------------- // code for simple direct image from pdf docs.    UIGraphicsBeginImageContext(CGSizeMake(320,460));    initialPage=28;    Mydisplaypdfpage(UIGraphicsGetCurrentContext(),initialPage,[[[NSBundle mainBundle] pathForResource:@"MobileHIG" ofType:@"pdf"] UTF8String]);    imgV.image=UIGraphicsGetimageFromCurrentimageContext();    imgV.image=[imgV.image rotate:UIImageOrIEntationDownMirrored];  }- (voID)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    UItouch *touch = [touches anyObject];    CGPoint LasttouchPoint =  [touch locationInVIEw:self.vIEw];    int LasttouchX = LasttouchPoint.x;    startpoint=LasttouchX;}- (voID)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{}- (voID)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{    UItouch *touch = [touches anyObject];    CGPoint LasttouchPoint =  [touch locationInVIEw:self.vIEw];    int LasttouchX = LasttouchPoint.x;    endpoint=LasttouchX;    if(startpoint>(endpoint+75)){        initialPage++;        [self loadPage:initialPage nextOne:YES];    } else if((startpoint+75)<endpoint){        initialPage--;        [self loadPage:initialPage nextOne:NO];    }}-(voID)loadPage:(NSUInteger)page nextOne:(BOol)yesOrNo{    if(page<=totalPages && page>0){        UIGraphicsBeginImageContext(CGSizeMake(720,720));          Mydisplaypdfpage(UIGraphicsGetCurrentContext(),page,[[[NSBundle mainBundle] pathForResource:@"MobileHIG" ofType:@"pdf"] UTF8String]);        CATransition *Transition = [CATransition animation];        Transition.duration = 0.75;        Transition.timingFunction = [camediatimingFunction functionWithname:kcamediatimingFunctionEaseInEaSEOut];        Transition.type=kCATransitionPush;        if(yesOrNo){            Transition.subtype=kCATransitionFromright;        } else {            Transition.subtype=kCATransitionFromleft;        }        Transition.delegate = self;        [imgV.layer addAnimation:Transition forKey:nil];        imgV.image=UIGraphicsGetimageFromCurrentimageContext();        imgV.image=[imgV.image rotate:UIImageOrIEntationDownMirrored];    }}

但是,从pdf文档中我没有看到一条直线的成功。
还缺少什么

解决方法 我有一个图书馆,可以做这个确切的事情链接在这里: Extracting pdf text in Objective C 总结

以上是内存溢出为你收集整理的通过iPhone应用程序读取PDF文件作为字符串全部内容,希望文章能够帮你解决通过iPhone应用程序读取PDF文件作为字符串所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1073664.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存