Objective-C & macOS PDF library integration

This guide will help you run Apryse samples and integrate a free trial of the Apryse SDK into Obj-C applications on macOS. Your free trial includes unlimited trial usage and support from solution engineers.

Prerequisites

  • Xcode
  • Apryse's Objective-C PDF library for macOS:

Download the SDK

Download

Run Apryse SDK in production

A commercial license key is required for use in a production environment. Please contact sales to purchase a commercial key or if you need any other license key assistance.

Keep your commercial license key confidential.

License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).

Initial setup

  1. Download the Apryse SDK.
  2. Extract the downloaded zip file and navigate to it.
  3. Get your Apryse trial key.

License Key

Apryse collects some data regarding your usage of the SDK for product improvement.

If you wish to continue without data collection, contact us and we will email you a no-tracking trial key for you to get started.

Run the samples

Run a specific sample

  1. Navigate to the OBJC folder in a sample project, for example /Samples/AddImageTest/OBJC and run the sample with

sh

1./RunTest.sh

Run all samples

  1. Navigate to /Samples and run

sh

1./runall_objc.sh

The tests will run one by one.

Output files will be in /Samples/TestFiles/Output

Integrate into your application

This section will show you how to use our SDK to create a simple Apryse "Hello World!" application. It will create a document with one blank page and save it as a linearized PDF in its running directory.

  1. Navigate to the /Samples directory of the Apryse SDK and create a directory called myApp if it does not exist already. This guide will assume your project is named myApp.
  2. Enter your myApp directory and create a OBJC directory for organization. Then create a myApp.m file. Open this file in your favorite text editor and paste:

Obj-C

1#import <OBJC/PDFNetOBJC.h>
2#import <Foundation/Foundation.h>
3
4int main (int argc, const char * argv[])
5{
6 @autoreleasepool {
7 int ret = 0;
8 [PTPDFNet Initialize: 0]; // PDFNet must be initialized before accessing any Apryse API
9
10 PTPDFDoc* doc = [[PTPDFDoc alloc] init];
11 PTPDFRect * rect = [[PTPDFRect alloc] init];
12 [rect Set: 0 y1: 0 x2: 612 y2: 792];
13 PTPage* page = [doc PageCreate: rect]; // Start a new page
14 [doc PagePushBack: page]; // Add the page to the document
15 [doc SaveToFile: @"output.pdf" flags: e_ptlinearized];
16 NSLog(@"Hello World!");
17 return ret;
18 }
19}
  1. In that same OBJC directory inside your myApp project folder add a makefile called Makefile and paste this inside:

shell

1TESTNAME=myApp
2CC=clang
3TARGET=$(TESTNAME)
4INCLUDES=-I../../../Headers
5CFLAGS=-fobjc-exceptions -fobjc-arc
6LIBS=-L../../../Lib -lPDFNetC -framework Foundation
7LDFLAGS=-Wl,-rpath,../../../Lib
8
9$(TARGET): $(TARGET).m.o
10 @echo "Linking target: $(TARGET)"
11 $(CC) -o $@ $< $(LIBS) $(LDFLAGS)
12
13$(TARGET).m.o: $(TARGET).m
14 @echo "Compiling target: $(TARGET)"
15 $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES)
16
17all: $(TARGET)
18
19clean:
20 rm -fr $(TARGET) *.o
21
22rebuild: clean all
23
24.PHONY: all clean rebuild
  1. Run the project by executing:followed by:If all goes well, your terminal should output:

sh

1make

sh

1./myApp

sh

1PDFNet is running in demo mode.
2Permission: write
3Hello World!

Check the output.pdf that the program output in the same directory. It should be a PDF with one blank page.

Next step

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales