0

pdfファイルを読み込もうとしています。この機能を使いたい

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

つまり、バイトを見つけるために使用seekToFileOffsetしますが、行を読みたいのです。

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);
4

1 に答える 1

0

私はあなたがそれをするのが好きな方法であなたのpdfを解析しないことをお勧めします。

使用してみてくださいCGPDFScannerドキュメントはこちら

JeremyPが言うように:多くのzlib圧縮されたものはPDFファイルにあります。行末を検索してください。CGPDFScannerを使用して、フォントマップ、画像などを抽出します。

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

于 2012-04-10T10:51:06.167 に答える