ElementReader

Sample Obj-C code for using Apryse SDK to traverse the page display list using ElementReader. Learn more about our iOS SDK and PDF Data Extraction SDK Capabilities.

1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6#import <OBJC/PDFNetOBJC.h>
7#import <Foundation/Foundation.h>
8
9void ProcessReaderTestElements(PTElementReader *reader)
10{
11 PTElement *element;
12 for (element=[reader Next]; element != NULL; element = [reader Next]) // Read page contents
13 {
14 switch ([element GetType])
15 {
16 case e_ptpath: // Process path data...
17 {
18 PTPathData *data = [element GetPathData];
19 NSArray *points = [data GetPoints];
20 }
21 break;
22 case e_pttext_obj: // Process text strings...
23 {
24 NSString* nsdata = [element GetTextString];
25 unsigned char* data = (unsigned char *)[nsdata UTF8String];
26 printf("%s\n", data);
27 }
28 break;
29 case e_ptform: // Process form XObjects
30 {
31 [reader FormBegin];
32 ProcessReaderTestElements(reader);
33 [reader End];
34 }
35 break;
36 default:
37 ;
38 }
39 }
40}
41
42int main(int argc, char *argv[])
43{
44 @autoreleasepool {
45 int ret = 0;
46 [PTPDFNet Initialize: 0];
47
48 @try // Extract text data from all pages in the document
49 {
50 printf("-------------------------------------------------\n");
51 printf("Sample 1 - Extract text data from all pages in the document.\n");
52 printf("Opening the input pdf...\n");
53
54 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: @"../../TestFiles/newsletter.pdf"];
55 [doc InitSecurityHandler];
56
57 PTPageIterator *itr;
58 PTElementReader *page_reader = [[PTElementReader alloc] init];
59
60 for (itr = [doc GetPageIterator: 1]; [itr HasNext]; [itr Next]) // Read every page
61 {
62 [page_reader Begin: [itr Current]];
63 ProcessReaderTestElements(page_reader);
64 [page_reader End];
65 }
66
67 printf("Done.\n");
68 }
69 @catch(NSException *e)
70 {
71 NSLog(@"%@", e.reason);
72 ret = 1;
73 }
74 [PTPDFNet Terminate: 0];
75 return ret;
76 }
77
78}

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales