2012-04-10 7 views
0

をお読みください。私はバイトを見つけるためにseekToFileOffsetを使用してそれが意味するこの機能は、私はpdfファイルを読み取ろうとpdfファイルでバイトを探し、ライン

databuffer = [file readDataOfLength : 7] but i want read all the byte in the line . 

を使用したいが、私はラインを読みたいです。

NSMutableArray  *nameArray = [[NSMutableArray alloc] initWithObjects:nil]; 

NSMutableArray  *nameArrayDict = [[NSMutableArray alloc] initWithObjects:nil]; 
NSString   *path   = [[NSBundle mainBundle] pathForResource:@"testpdf" ofType:@"pdf"]; 
NSString   *contents  = [NSString stringWithContentsOfFile:path encoding:NSASCIIStringEncoding error:nil]; 


    int var=[[nameArray objectAtIndex:[nameArray count]-2] intValue]; 

    NSFileHandle *file; 
    NSData *databuffer; 
    file = [NSFileHandle fileHandleForReadingAtPath: appFile]; 

    int i=0; 
    while (file!=nil) { 
     [file seekToFileOffset: var+i]; 

     databuffer = [file readDataOfLength : 7]; 
     NSString* aStr; 
     aStr = [[NSString alloc] initWithData: databuffer encoding:NSASCIIStringEncoding]; 

     NSLog(@"%@",aStr); 

     i=i+[databuffer length]; 
    } 

今私はあなたの解決策を試してみませんか?何も表示できません。

CGPDFPageRef page = CGPDFDocumentGetPage (myDocument, 1);// 2 

CGPDFDictionaryRef d; 

d = CGPDFPageGetDictionary(page); 


CGPDFScannerRef myScanner; 

CGPDFOperatorTableRef myTable; 
myTable = CGPDFOperatorTableCreate(); 



CGPDFContentStreamRef myContentStream = CGPDFContentStreamCreateWithPage (page);// 3 




myScanner = CGPDFScannerCreate (myContentStream, myTable, NULL);// 4 





CGPDFScannerScan (myScanner);// 5 


CGPDFOperatorTableSetCallback(myTable, "BT", &op_BT);//Begin text object 
CGPDFOperatorTableSetCallback(myTable, "ET", &op_ET);//End text object 
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); 
+0

PDFファイルはASCIIテキストではありません。それらの大部分はしばしばバイナリであり、圧縮さえすることさえある。 – JeremyP

答えて

0

あなたの望むようにあなたのpdfを解析しないことをお勧めします。 zlibの圧縮された多くのもののは、PDFファイル内にある:

はJeremyPが言うようにCGPDFScannerdocs here

を使用してみてください。行末を検索します。 CGPDFScannerを使用してフォントマップ、画像などを抽出します。

しかし、それほど簡単ではありません。教えられます。 :)

+0

私のリンクをご覧になれますか? – franck

+0

stackoverflow.com/questions/10042723/haw-i-can-parse-cgpdfarrayref-with-cgpdf – franck

関連する問題