Sample Obj-C code for using Apryse SDK to programmatically stamp PDF pages with text, images, or with other PDF pages. ElementBuilder and ElementWriter should be used for more complex PDF stamping operations. Learn more about our iOS SDK.
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
9//---------------------------------------------------------------------------------------
10// The following sample shows how to add new content (or watermark) PDF pages
11// using 'pdftron.PDF.Stamper' utility class.
12//
13// Stamper can be used to PDF pages with text, images, or with other PDF content
14// in only a few lines of code. Although Stamper is very simple to use compared
15// to ElementBuilder/ElementWriter it is not as powerful or flexible. In case you
16// need full control over PDF creation use ElementBuilder/ElementWriter to add
17// new content to existing PDF pages as shown in the ElementBuilder sample project.
18//---------------------------------------------------------------------------------------
19int main(int argc, char * argv[])
20{
21 @autoreleasepool {
22
23 int ret = 0;
24
25 [PTPDFNet Initialize: 0];
26
27 //--------------------------------------------------------------------------------
28 // Example 1) Add text stamp to all pages, then remove text stamp from odd pages.
29 @try
30 {
31 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: @"../../TestFiles/newsletter.pdf"];
32 [doc InitSecurityHandler];
33 PTStamper *s = [[PTStamper alloc] initWithSize_type: e_ptrelative_scale a: 0.5 b: 0.5];
34 [s SetAlignment: e_pthorizontal_center vertical_alignment: e_ptvertical_center];
35 PTColorPt *red = [[PTColorPt alloc] initWithX: 1 y: 0 z: 0 w: 0]; // set text color to red
36 [s SetFontColor: red];
37 PTPageSet *set = [[PTPageSet alloc] initWithRange_start: 1 range_end: [doc GetPageCount] filter: e_ptall];
38 [s StampText: doc src_txt: @"If you are reading this\nthis is an even page" dest_pages: set];
39 //delete all text stamps in even pages
40 PTPageSet *set2 = [[PTPageSet alloc] initWithRange_start: 1 range_end: [doc GetPageCount] filter: e_ptodd];
41 [PTStamper DeleteStamps: doc page_set: set2];
42
43 [doc SaveToFile: @"../../TestFiles/Output/newsletter.ex1.pdf" flags: e_ptlinearized];
44 }
45 @catch (NSException *e)
46 {
47 NSLog(@"%@", e.reason);
48 ret = 1;
49 }
50
51 //--------------------------------------------------------------------------------
52 // Example 2) Add Image stamp to first 2 pages.
53 @try
54 {
55 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: @"../../TestFiles/newsletter.pdf"];
56 [doc InitSecurityHandler];
57
58 PTStamper *s = [[PTStamper alloc] initWithSize_type: e_ptrelative_scale a: 0.05 b: 0.05];
59 PTImage *img = [PTImage Create: [doc GetSDFDoc] filename: @"../../TestFiles/peppers.jpg"];
60 [s SetSize: e_ptrelative_scale a: 0.5 b: 0.5];
61 //set position of the image to the center, left of PDF pages
62 [s SetAlignment: e_pthorizontal_left vertical_alignment: e_ptvertical_center];
63 PTColorPt *pt = [[PTColorPt alloc] initWithX: 0 y: 0 z: 0 w: 0];
64 [s SetFontColor: pt];
65 [s SetRotation: 180];
66 [s SetAsBackground: NO];
67 //only stamp first 2 pages
68 PTPageSet *ps = [[PTPageSet alloc] initWithRange_start: 1 range_end: 2 filter: e_ptall];
69 [s StampImage: doc src_img: img dest_pages: ps];
70
71 [doc SaveToFile: @"../../TestFiles/Output/newsletter.ex2.pdf" flags: e_ptlinearized];
72 }
73 @catch (NSException *e)
74 {
75 NSLog(@"%@", e.reason);
76 ret = 1;
77 }
78
79 //--------------------------------------------------------------------------------
80 // Example 3) Add Page stamp to all pages.
81 @try
82 {
83 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: @"../../TestFiles/newsletter.pdf"];
84 [doc InitSecurityHandler];
85
86 PTPDFDoc *fish_doc = [[PTPDFDoc alloc ] initWithFilepath: @"../../TestFiles/fish.pdf"];
87 [fish_doc InitSecurityHandler];
88
89 PTStamper *s = [[PTStamper alloc] initWithSize_type: e_ptrelative_scale a: 0.5 b: 0.5];
90 PTPage *src_page = [fish_doc GetPage: 1];
91 PTPDFRect * page_one_crop = [src_page GetCropBox];
92 // set size of the image to 10% of the original while keep the old aspect ratio
93 [s SetSize: e_ptabsolute_size a: [page_one_crop Width] * 0.1 b: -1];
94 [s SetOpacity: 0.4];
95 [s SetRotation: -67];
96 //put the image at the bottom right hand corner
97 [s SetAlignment: e_pthorizontal_right vertical_alignment: e_ptvertical_bottom];
98 PTPageSet *ps = [[PTPageSet alloc] initWithRange_start: 2 range_end: [doc GetPageCount] filter: e_ptall];
99 [s StampPage: doc src_page: src_page dest_pages: ps];
100
101 [doc SaveToFile: @"../../TestFiles/Output/newsletter.ex3.pdf" flags: e_ptlinearized];
102 }
103 @catch (NSException *e)
104 {
105 NSLog(@"%@", e.reason);
106 ret = 1;
107 }
108
109 //--------------------------------------------------------------------------------
110 // Example 4) Add Image stamp to first 20 odd pages.
111 @try
112 {
113 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: @"../../TestFiles/newsletter.pdf"];
114 [doc InitSecurityHandler];
115
116 PTStamper *s = [[PTStamper alloc] initWithSize_type: e_ptabsolute_size a: 20 b: 20];
117 [s SetOpacity: 1];
118 [s SetRotation: 45];
119 [s SetAsBackground: YES];
120 [s SetPosition: 30 vertical_distance: 40 use_percentage: NO];
121 PTImage *img = [PTImage Create: [doc GetSDFDoc] filename: @"../../TestFiles/peppers.jpg"];
122 PTPageSet *ps = [[PTPageSet alloc] initWithRange_start: 1 range_end: 20 filter: e_ptodd];
123 [s StampImage: doc src_img: img dest_pages: ps];
124
125 [doc SaveToFile: @"../../TestFiles/Output/newsletter.ex4.pdf" flags: e_ptlinearized];
126 }
127 @catch (NSException *e)
128 {
129 NSLog(@"%@", e.reason);
130 ret = 1;
131 }
132
133 //--------------------------------------------------------------------------------
134 // Example 5) Add text stamp to first 20 even pages
135 @try
136 {
137 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: @"../../TestFiles/newsletter.pdf"];
138 [doc InitSecurityHandler];
139
140 PTStamper *s = [[PTStamper alloc] initWithSize_type: e_ptrelative_scale a: 0.5 b: 0.5];
141 [s SetPosition: 0 vertical_distance: 0 use_percentage: NO];
142 [s SetOpacity: 0.7];
143 [s SetRotation: 90];
144 [s SetSize: e_pts_font_size a: 80 b: -1];
145 [s SetTextAlignment: e_ptalign_center];
146 PTPageSet *ps = [[PTPageSet alloc] initWithRange_start: 1 range_end: 20 filter: e_pteven];
147 [s StampText: doc src_txt: @"Goodbye\nMoon" dest_pages: ps];
148
149 [doc SaveToFile: @"../../TestFiles/Output/newsletter.ex5.pdf" flags: e_ptlinearized];
150 }
151 @catch (NSException* e)
152 {
153 NSLog(@"%@", e.reason);
154 ret = 1;
155 }
156
157 //--------------------------------------------------------------------------------
158 // Example 6) Add first page as stamp to all even pages
159 @try
160 {
161 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: @"../../TestFiles/newsletter.pdf"];
162 [doc InitSecurityHandler];
163
164 PTPDFDoc *fish_doc = [[PTPDFDoc alloc ] initWithFilepath: @"../../TestFiles/fish.pdf"];
165 [fish_doc InitSecurityHandler];
166
167 PTStamper *s = [[PTStamper alloc] initWithSize_type: e_ptrelative_scale a: 0.3 b: 0.3];
168 [s SetOpacity: 1];
169 [s SetRotation: 270];
170 [s SetAsBackground: YES];
171 [s SetPosition: 0.5 vertical_distance: 0.5 use_percentage: YES];
172 [s SetAlignment: e_pthorizontal_left vertical_alignment: e_ptvertical_bottom];
173 PTPage *page_one = [fish_doc GetPage: 1];
174 PTPageSet *ps = [[PTPageSet alloc] initWithRange_start: 1 range_end: [doc GetPageCount] filter: e_pteven];
175 [s StampPage: doc src_page: page_one dest_pages: ps];
176
177 [doc SaveToFile: @"../../TestFiles/Output/newsletter.ex6.pdf" flags: e_ptlinearized];
178 }
179 @catch (NSException* e)
180 {
181 NSLog(@"%@", e.reason);
182 ret = 1;
183 }
184
185 //--------------------------------------------------------------------------------
186 // Example 7) Add image stamp at top right corner in every pages
187 @try
188 {
189 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: @"../../TestFiles/newsletter.pdf"];
190 [doc InitSecurityHandler];
191
192 PTStamper *s = [[PTStamper alloc] initWithSize_type: e_ptrelative_scale a: 0.1 b: 0.1];
193 [s SetOpacity: 0.8];
194 [s SetRotation: 135];
195 [s SetAsBackground: NO];
196 [s ShowsOnPrint: NO];
197 [s SetAlignment: e_pthorizontal_left vertical_alignment: e_ptvertical_top];
198 [s SetPosition: 10 vertical_distance: 10 use_percentage: YES];
199
200 PTImage *img = [PTImage Create: [doc GetSDFDoc] filename: @"../../TestFiles/peppers.jpg"];
201 PTPageSet *ps = [[PTPageSet alloc] initWithRange_start: 1 range_end: [doc GetPageCount] filter: e_ptall];
202 [s StampImage: doc src_img: img dest_pages: ps];
203
204 [doc SaveToFile: @"../../TestFiles/Output/newsletter.ex7.pdf" flags: e_ptlinearized];
205 }
206 @catch (NSException* e)
207 {
208 NSLog(@"%@", e.reason);
209 ret = 1;
210 }
211
212 //--------------------------------------------------------------------------------
213 // Example 8) Add Text stamp to first 2 pages, and image stamp to first page.
214 // Because text stamp is set as background, the image is top of the text
215 // stamp. Text stamp on the first page is not visible.
216 @try
217 {
218 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: @"../../TestFiles/newsletter.pdf"];
219 [doc InitSecurityHandler];
220
221 PTStamper *s = [[PTStamper alloc] initWithSize_type: e_ptrelative_scale a: 0.07 b: -0.1];
222 [s SetAlignment: e_pthorizontal_right vertical_alignment: e_ptvertical_bottom];
223 [s SetAlignment: e_pthorizontal_center vertical_alignment: e_ptvertical_top];
224 [s SetFont: [PTFont Create: [doc GetSDFDoc] type: e_ptcourier embed: YES]];
225 PTColorPt *red = [[PTColorPt alloc] initWithX: 1 y: 0 z: 0 w: 0];
226 [s SetFontColor: red]; //set color to red
227 [s SetTextAlignment: e_ptalign_right];
228 [s SetAsBackground: YES]; //set text stamp as background
229 PTPageSet *ps = [[PTPageSet alloc] initWithRange_start: 1 range_end: 2 filter: e_ptall];
230 [s StampText: doc src_txt: @"This is a title!" dest_pages: ps];
231
232 PTImage *img = [PTImage Create: [doc GetSDFDoc] filename: @"../../TestFiles/peppers.jpg"];
233 [s SetAsBackground: NO]; // set image stamp as foreground
234 PTPageSet *first_page_ps = [[PTPageSet alloc] initWithOne_page: 1];
235 [s StampImage: doc src_img: img dest_pages: first_page_ps];
236
237 [doc SaveToFile: @"../../TestFiles/Output/newsletter.ex8.pdf" flags: e_ptlinearized];
238 }
239 @catch (NSException* e)
240 {
241 NSLog(@"%@", e.reason);
242 ret = 1;
243 }
244 [PTPDFNet Terminate: 0];
245 //NSLog(@"Done.");
246 return ret;
247 }
248}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6import PDFNet
7import Foundation
8
9//---------------------------------------------------------------------------------------
10// The following sample shows how to add new content (or watermark) PDF pages
11// using 'pdftron.PDF.Stamper' utility class.
12//
13// Stamper can be used to PDF pages with text, images, or with other PDF content
14// in only a few lines of code. Although Stamper is very simple to use compared
15// to ElementBuilder/ElementWriter it is not as powerful or flexible. In case you
16// need full control over PDF creation use ElementBuilder/ElementWriter to add
17// new content to existing PDF pages as shown in the ElementBuilder sample project.
18//---------------------------------------------------------------------------------------
19func runStamperTest() -> Int {
20 return autoreleasepool {
21 var ret = 0
22
23
24
25 //--------------------------------------------------------------------------------
26 // Example 1) Add text stamp to all pages, then remove text stamp from odd pages.
27 do {
28 try PTPDFNet.catchException {
29 let doc: PTPDFDoc = PTPDFDoc(filepath: Bundle.main.path(forResource: "newsletter", ofType: "pdf"))
30 doc.initSecurityHandler()
31
32 let s: PTStamper = PTStamper(size_type: e_ptrelative_scale, a: 0.5, b: 0.5)
33 s.setAlignment(e_pthorizontal_center, vertical_alignment: e_ptvertical_center)
34 let red = PTColorPt(x: 1, y: 0, z: 0, w: 0)
35 // set text color to red
36 s.setFontColor(red)
37 let set = PTPageSet(range_start: 1, range_end: doc.getPageCount(), filter: e_ptall)
38 s.stampText(doc, src_txt: "If you are reading this\nthis is an even page\n", dest_pages: set)
39 //delete all text stamps in even pages
40 let set2 = PTPageSet(range_start: 1, range_end: doc.getPageCount(), filter: e_ptodd)
41 PTStamper.deleteStamps(doc, page_set: set2)
42
43 doc.save(toFile: URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("newsletter.ex1.pdf").path, flags: e_ptlinearized.rawValue)
44 }
45 } catch let e as NSError {
46 print("\(e)")
47 ret = 1
48 }
49
50 //--------------------------------------------------------------------------------
51 // Example 2) Add Image stamp to first 2 pages.
52 do {
53 try PTPDFNet.catchException {
54 let doc: PTPDFDoc = PTPDFDoc(filepath: Bundle.main.path(forResource: "newsletter", ofType: "pdf"))
55 doc.initSecurityHandler()
56
57 let s: PTStamper = PTStamper(size_type: e_ptrelative_scale, a: 0.05, b: 0.05)
58 let img = PTImage.create(doc.getSDFDoc(), filename: Bundle.main.path(forResource: "peppers", ofType: "jpg"))
59 s.setSize(e_ptrelative_scale, a: 0.5, b: 0.5)
60 //set position of the image to the center, left of PDF pages
61 s.setAlignment(e_pthorizontal_left, vertical_alignment: e_ptvertical_center)
62 let pt = PTColorPt(x: 0, y: 0, z: 0, w: 0)
63 s.setFontColor(pt)
64 s.setRotation(180)
65 s.setAsBackground(false)
66 //only stamp first 2 pages
67 let ps = PTPageSet(range_start: 1, range_end: 2, filter: e_ptall)
68 s.stampImage(doc, src_img: img, dest_pages: ps)
69
70 doc.save(toFile: URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("newsletter.ex2.pdf").path, flags: e_ptlinearized.rawValue)
71 }
72 } catch let e as NSError {
73 print("\(e)")
74 ret = 1
75 }
76
77 //--------------------------------------------------------------------------------
78 // Example 3) Add Page stamp to all pages.
79 do {
80 try PTPDFNet.catchException {
81 let doc: PTPDFDoc = PTPDFDoc(filepath: Bundle.main.path(forResource: "newsletter", ofType: "pdf"))
82 doc.initSecurityHandler()
83
84 let fish_doc: PTPDFDoc = PTPDFDoc(filepath: Bundle.main.path(forResource: "fish", ofType: "pdf"))
85 fish_doc.initSecurityHandler()
86
87 let s: PTStamper = PTStamper(size_type: e_ptrelative_scale, a: 0.5, b: 0.5)
88 let src_page: PTPage = fish_doc.getPage(1)
89 let page_one_crop: PTPDFRect = src_page.getCropBox()
90 // set size of the image to 10% of the original while keep the old aspect ratio
91 s.setSize(e_ptabsolute_size, a: page_one_crop.width() * 0.1, b: -1)
92 s.setOpacity(0.4)
93 s.setRotation(-67)
94 //put the image at the bottom right hand corner
95 s.setAlignment(e_pthorizontal_right, vertical_alignment: e_ptvertical_bottom)
96 let ps = PTPageSet(range_start: 2, range_end: doc.getPageCount(), filter: e_ptall)
97 s.stampPage(doc, src_page: src_page, dest_pages: ps)
98
99 doc.save(toFile: URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("newsletter.ex3.pdf").path, flags: e_ptlinearized.rawValue)
100 }
101 } catch let e as NSError {
102 print("\(e)")
103 ret = 1
104 }
105
106 //--------------------------------------------------------------------------------
107 // Example 4) Add Image stamp to first 20 odd pages.
108 do {
109 try PTPDFNet.catchException {
110 let doc: PTPDFDoc = PTPDFDoc(filepath: Bundle.main.path(forResource: "newsletter", ofType: "pdf"))
111 doc.initSecurityHandler()
112
113 let s: PTStamper = PTStamper(size_type: e_ptabsolute_size, a: 20, b: 20)
114 s.setOpacity(1)
115 s.setRotation(45)
116 s.setAsBackground(true)
117 s.setPosition(30, vertical_distance: 40, use_percentage: false)
118 let img = PTImage.create(doc.getSDFDoc(), filename: Bundle.main.path(forResource: "peppers", ofType: "jpg"))
119 let ps = PTPageSet(range_start: 1, range_end: 20, filter: e_ptodd)
120 s.stampImage(doc, src_img: img, dest_pages: ps)
121
122 doc.save(toFile: URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("newsletter.ex4.pdf").path, flags: e_ptlinearized.rawValue)
123 }
124 } catch let e as NSError {
125 print("\(e)")
126 ret = 1
127 }
128
129 //--------------------------------------------------------------------------------
130 // Example 5) Add text stamp to first 20 even pages
131 do {
132 try PTPDFNet.catchException {
133 let doc: PTPDFDoc = PTPDFDoc(filepath: Bundle.main.path(forResource: "newsletter", ofType: "pdf"))
134 doc.initSecurityHandler()
135
136 let s: PTStamper = PTStamper(size_type: e_ptrelative_scale, a: 0.5, b: 0.5)
137 s.setPosition(0, vertical_distance: 0, use_percentage: false)
138 s.setOpacity(0.7)
139 s.setRotation(90)
140 s.setSize(e_pts_font_size, a: 80, b: -1)
141 s.setTextAlignment(e_ptalign_center)
142 let ps = PTPageSet(range_start: 1, range_end: 20, filter: e_pteven)
143 s.stampText(doc, src_txt: "Goodbye\nMoon", dest_pages: ps)
144
145 doc.save(toFile: URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("newsletter.ex5.pdf").path, flags: e_ptlinearized.rawValue)
146 }
147 } catch let e as NSError {
148 print("\(e)")
149 ret = 1
150 }
151
152 //--------------------------------------------------------------------------------
153 // Example 6) Add first page as stamp to all even pages
154 do {
155 try PTPDFNet.catchException {
156 let doc: PTPDFDoc = PTPDFDoc(filepath: Bundle.main.path(forResource: "newsletter", ofType: "pdf"))
157 doc.initSecurityHandler()
158
159 let fish_doc: PTPDFDoc = PTPDFDoc(filepath: Bundle.main.path(forResource: "fish", ofType: "pdf"))
160 fish_doc.initSecurityHandler()
161
162 let s: PTStamper = PTStamper(size_type: e_ptrelative_scale, a: 0.3, b: 0.3)
163 s.setOpacity(1)
164 s.setRotation(270)
165 s.setAsBackground(true)
166 s.setPosition(0.5, vertical_distance: 0.5, use_percentage: true)
167 s.setAlignment(e_pthorizontal_left, vertical_alignment: e_ptvertical_bottom)
168 let page_one: PTPage = fish_doc.getPage(1)
169 let ps = PTPageSet(range_start: 1, range_end: doc.getPageCount(), filter: e_pteven)
170 s.stampPage(doc, src_page: page_one, dest_pages: ps)
171
172 doc.save(toFile: URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("newsletter.ex6.pdf").path, flags: e_ptlinearized.rawValue)
173 }
174 } catch let e as NSError {
175 print("\(e)")
176 ret = 1
177 }
178
179 //--------------------------------------------------------------------------------
180 // Example 7) Add image stamp at top right corner in every pages
181 do {
182 try PTPDFNet.catchException {
183 let doc: PTPDFDoc = PTPDFDoc(filepath: Bundle.main.path(forResource: "newsletter", ofType: "pdf"))
184 doc.initSecurityHandler()
185
186 let s: PTStamper = PTStamper(size_type: e_ptrelative_scale, a: 0.1, b: 0.1)
187 s.setOpacity(0.8)
188 s.setRotation(135)
189 s.setAsBackground(false)
190 s.shows(onPrint: false)
191 s.setAlignment(e_pthorizontal_left, vertical_alignment: e_ptvertical_top)
192 s.setPosition(10, vertical_distance: 10, use_percentage: true)
193
194 let img = PTImage.create(doc.getSDFDoc(), filename: Bundle.main.path(forResource: "peppers", ofType: "jpg"))
195 let ps = PTPageSet(range_start: 1, range_end: doc.getPageCount(), filter: e_ptall)
196 s.stampImage(doc, src_img: img, dest_pages: ps)
197
198 doc.save(toFile: URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("newsletter.ex7.pdf").path, flags: e_ptlinearized.rawValue)
199 }
200 } catch let e as NSError {
201 print("\(e)")
202 ret = 1
203 }
204
205 //--------------------------------------------------------------------------------
206 // Example 8) Add Text stamp to first 2 pages, and image stamp to first page.
207 // Because text stamp is set as background, the image is top of the text
208 // stamp. Text stamp on the first page is not visible.
209 do {
210 try PTPDFNet.catchException {
211 let doc: PTPDFDoc = PTPDFDoc(filepath: Bundle.main.path(forResource: "newsletter", ofType: "pdf"))
212 doc.initSecurityHandler()
213
214 let s: PTStamper = PTStamper(size_type: e_ptrelative_scale, a: 0.07, b: -0.1)
215 s.setAlignment(e_pthorizontal_right, vertical_alignment: e_ptvertical_bottom)
216 s.setAlignment(e_pthorizontal_center, vertical_alignment: e_ptvertical_top)
217 s.setFont(PTFont.create(doc.getSDFDoc(), type: e_ptcourier, embed: true))
218 let red = PTColorPt(x: 1, y: 0, z: 0, w: 0)
219 s.setFontColor(red) //set color to red
220 s.setTextAlignment(e_ptalign_right)
221 s.setAsBackground(true) //set text stamp as background
222 let ps = PTPageSet(range_start: 1, range_end: 2, filter: e_ptall)
223 s.stampText(doc, src_txt: "This is a title!", dest_pages: ps)
224
225 let img = PTImage.create(doc.getSDFDoc(), filename: Bundle.main.path(forResource: "peppers", ofType: "jpg"))
226 s.setAsBackground(false) // set image stamp as foreground
227 let first_page_ps = PTPageSet(one_page: 1)
228 s.stampImage(doc, src_img: img, dest_pages: first_page_ps)
229
230 doc.save(toFile: URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("newsletter.ex8.pdf").path, flags: e_ptlinearized.rawValue)
231 }
232 } catch let e as NSError {
233 print("\(e)")
234 ret = 1
235 }
236
237 print("Done.")
238
239 return ret
240 }
241}
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales