Sample Java 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 Android SDK.
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6package com.pdftron.android.pdfnetsdksamples.samples;
7
8import com.pdftron.android.pdfnetsdksamples.OutputListener;
9import com.pdftron.android.pdfnetsdksamples.PDFNetSample;
10import com.pdftron.android.pdfnetsdksamples.R;
11import com.pdftron.android.pdfnetsdksamples.util.Utils;
12import com.pdftron.pdf.ColorPt;
13import com.pdftron.pdf.Font;
14import com.pdftron.pdf.Image;
15import com.pdftron.pdf.PDFDoc;
16import com.pdftron.pdf.Page;
17import com.pdftron.pdf.PageSet;
18import com.pdftron.pdf.Rect;
19import com.pdftron.pdf.Stamper;
20import com.pdftron.sdf.SDFDoc;
21
22import java.util.ArrayList;
23
24/**
25 * The following sample shows how to add new content (or watermark) PDF pages
26 * using 'com.pdftron.pdf.Stamper' utility class.
27 * <p>
28 * Stamper can be used to PDF pages with text, images, or with other PDF content
29 * in only a few lines of code. Although Stamper is very simple to use compared
30 * to ElementBuilder/ElementWriter it is not as powerful or flexible. In case you
31 * need full control over PDF creation use ElementBuilder/ElementWriter to add
32 * new content to existing PDF pages as shown in the ElementBuilder sample project.
33 */
34public class StamperTest extends PDFNetSample {
35
36 private static OutputListener mOutputListener;
37
38 private static ArrayList<String> mFileList = new ArrayList<>();
39
40 public StamperTest() {
41 setTitle(R.string.sample_stamper_title);
42 setDescription(R.string.sample_stamper_description);
43 }
44
45 @Override
46 public void run(OutputListener outputListener) {
47 super.run(outputListener);
48 mOutputListener = outputListener;
49 mFileList.clear();
50 printHeader(outputListener);
51 String input_filename = "newsletter";
52
53 //--------------------------------------------------------------------------------
54 // Example 1) Add text stamp to all pages, then remove text stamp from odd pages.
55 try (PDFDoc doc = new PDFDoc(Utils.getAssetTempFile(INPUT_PATH + input_filename + ".pdf").getAbsolutePath())) {
56 doc.initSecurityHandler();
57 Stamper s = new Stamper(Stamper.e_relative_scale, 0.5, 0.5);
58 s.setAlignment(Stamper.e_horizontal_center, Stamper.e_vertical_center);
59 ColorPt red = new ColorPt(1, 0, 0); // set text color to red
60 s.setFontColor(red);
61 String msg = "If you are reading this\nthis is an even page";
62 PageSet ps = new PageSet(1, doc.getPageCount());
63 s.stampText(doc, msg, ps);
64 //delete all text stamps in even pages
65 PageSet ps1 = new PageSet(1, doc.getPageCount(), PageSet.e_odd);
66 Stamper.deleteStamps(doc, ps1);
67
68 doc.save(Utils.createExternalFile(input_filename + ".ex1.pdf", mFileList).getAbsolutePath(), SDFDoc.SaveMode.LINEARIZED, null);
69 } catch (Exception e) {
70 mOutputListener.printError(e.getStackTrace());
71 return;
72 }
73
74 //--------------------------------------------------------------------------------
75 // Example 2) Add Image stamp to first 2 pages.
76 try (PDFDoc doc = new PDFDoc(Utils.getAssetTempFile(INPUT_PATH + input_filename + ".pdf").getAbsolutePath())) {
77 doc.initSecurityHandler();
78
79 Stamper s = new Stamper(Stamper.e_relative_scale, .05, .05);
80 Image img = Image.create(doc, Utils.getAssetTempFile(INPUT_PATH + "peppers.jpg").getAbsolutePath());
81 s.setSize(Stamper.e_relative_scale, 0.5, 0.5);
82 //set position of the image to the center, left of PDF pages
83 s.setAlignment(Stamper.e_horizontal_left, Stamper.e_vertical_center);
84 ColorPt pt = new ColorPt(0, 0, 0, 0);
85 s.setFontColor(pt);
86 s.setRotation(180);
87 s.setAsBackground(false);
88 //only stamp first 2 pages
89 PageSet ps = new PageSet(1, 2);
90 s.stampImage(doc, img, ps);
91
92 doc.save(Utils.createExternalFile(input_filename + ".ex2.pdf", mFileList).getAbsolutePath(), SDFDoc.SaveMode.LINEARIZED, null);
93 } catch (Exception e) {
94 mOutputListener.printError(e.getStackTrace());
95 return;
96 }
97
98 //--------------------------------------------------------------------------------
99 // Example 3) Add Page stamp to all pages.
100 try (PDFDoc doc = new PDFDoc(Utils.getAssetTempFile(INPUT_PATH + input_filename + ".pdf").getAbsolutePath())) {
101 doc.initSecurityHandler();
102
103 try (PDFDoc fish_doc = new PDFDoc(Utils.getAssetTempFile(INPUT_PATH + "fish.pdf").getAbsolutePath())) {
104 fish_doc.initSecurityHandler();
105
106 Stamper s = new Stamper(Stamper.e_relative_scale, 0.5, 0.5);
107 Page src_page = fish_doc.getPage(1);
108 Rect page_one_crop = src_page.getCropBox();
109 // set size of the image to 10% of the original while keep the old aspect ratio
110 s.setSize(Stamper.e_absolute_size, page_one_crop.getWidth() * 0.1, -1);
111 s.setOpacity(0.4);
112 s.setRotation(-67);
113 //put the image at the bottom right hand corner
114 s.setAlignment(Stamper.e_horizontal_right, Stamper.e_vertical_bottom);
115 PageSet ps = new PageSet(1, doc.getPageCount());
116 s.stampPage(doc, src_page, ps);
117
118 doc.save(Utils.createExternalFile(input_filename + ".ex3.pdf", mFileList).getAbsolutePath(), SDFDoc.SaveMode.LINEARIZED, null);
119 }
120 } catch (Exception e) {
121 mOutputListener.printError(e.getStackTrace());
122 return;
123 }
124
125 //--------------------------------------------------------------------------------
126 // Example 4) Add Image stamp to first 20 odd pages.
127 try (PDFDoc doc = new PDFDoc(Utils.getAssetTempFile(INPUT_PATH + input_filename + ".pdf").getAbsolutePath())) {
128 doc.initSecurityHandler();
129
130 Stamper s = new Stamper(Stamper.e_absolute_size, 20, 20);
131 s.setOpacity(1);
132 s.setRotation(45);
133 s.setAsBackground(true);
134 s.setPosition(30, 40);
135 Image img = Image.create(doc, Utils.getAssetTempFile(INPUT_PATH + "peppers.jpg").getAbsolutePath());
136 PageSet ps = new PageSet(1, 20, PageSet.e_odd);
137 s.stampImage(doc, img, ps);
138
139 doc.save(Utils.createExternalFile(input_filename + ".ex4.pdf", mFileList).getAbsolutePath(), SDFDoc.SaveMode.LINEARIZED, null);
140 } catch (Exception e) {
141 mOutputListener.printError(e.getStackTrace());
142 return;
143 }
144
145 //--------------------------------------------------------------------------------
146 // Example 5) Add text stamp to first 20 even pages
147 try (PDFDoc doc = new PDFDoc(Utils.getAssetTempFile(INPUT_PATH + input_filename + ".pdf").getAbsolutePath())) {
148 doc.initSecurityHandler();
149
150 Stamper s = new Stamper(Stamper.e_relative_scale, .05, .05);
151 s.setPosition(0, 0);
152 s.setOpacity(0.7);
153 s.setRotation(90);
154 s.setSize(Stamper.e_font_size, 80, -1);
155 s.setTextAlignment(Stamper.e_align_center);
156 PageSet ps = new PageSet(1, 20, PageSet.e_even);
157 s.stampText(doc, "Goodbye\nMoon", ps);
158
159 doc.save(Utils.createExternalFile(input_filename + ".ex5.pdf", mFileList).getAbsolutePath(), SDFDoc.SaveMode.LINEARIZED, null);
160 } catch (Exception e) {
161 mOutputListener.printError(e.getStackTrace());
162 return;
163 }
164
165 //--------------------------------------------------------------------------------
166 // Example 6) Add first page as stamp to all even pages
167 try (PDFDoc doc = new PDFDoc(Utils.getAssetTempFile(INPUT_PATH + input_filename + ".pdf").getAbsolutePath())) {
168 doc.initSecurityHandler();
169
170 PDFDoc fish_doc = new PDFDoc(Utils.getAssetTempFile(INPUT_PATH + "fish.pdf").getAbsolutePath());
171 fish_doc.initSecurityHandler();
172
173 Stamper s = new Stamper(Stamper.e_relative_scale, 0.3, 0.3);
174 s.setOpacity(1);
175 s.setRotation(270);
176 s.setAsBackground(true);
177 s.setPosition(0.5, 0.5, true);
178 s.setAlignment(Stamper.e_horizontal_left, Stamper.e_vertical_bottom);
179 Page page_one = fish_doc.getPage(1);
180 PageSet ps = new PageSet(1, doc.getPageCount(), PageSet.e_even);
181 s.stampPage(doc, page_one, ps);
182
183 doc.save(Utils.createExternalFile(input_filename + ".ex6.pdf", mFileList).getAbsolutePath(), SDFDoc.SaveMode.LINEARIZED, null);
184 } catch (Exception e) {
185 mOutputListener.printError(e.getStackTrace());
186 return;
187 }
188
189 //--------------------------------------------------------------------------------
190 // Example 7) Add image stamp at top right corner in every pages
191 try (PDFDoc doc = new PDFDoc(Utils.getAssetTempFile(INPUT_PATH + input_filename + ".pdf").getAbsolutePath())) {
192 doc.initSecurityHandler();
193
194 Stamper s = new Stamper(Stamper.e_relative_scale, .1, .1);
195 s.setOpacity(0.8);
196 s.setRotation(135);
197 s.setAsBackground(false);
198 s.showsOnPrint(false);
199 s.setAlignment(Stamper.e_horizontal_left, Stamper.e_vertical_top);
200 s.setPosition(10, 10);
201
202 Image img = Image.create(doc, Utils.getAssetTempFile(INPUT_PATH + "peppers.jpg").getAbsolutePath());
203 PageSet ps = new PageSet(1, doc.getPageCount(), PageSet.e_all);
204 s.stampImage(doc, img, ps);
205
206 doc.save(Utils.createExternalFile(input_filename + ".ex7.pdf", mFileList).getAbsolutePath(), SDFDoc.SaveMode.LINEARIZED, null);
207 } catch (Exception e) {
208 mOutputListener.printError(e.getStackTrace());
209 return;
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 (PDFDoc doc = new PDFDoc(Utils.getAssetTempFile(INPUT_PATH + input_filename + ".pdf").getAbsolutePath())) {
217 doc.initSecurityHandler();
218
219 Stamper s = new Stamper(Stamper.e_relative_scale, 0.07, -0.1);
220 s.setAlignment(Stamper.e_horizontal_right, Stamper.e_vertical_bottom);
221 s.setAlignment(Stamper.e_horizontal_center, Stamper.e_vertical_top);
222 s.setFont(Font.create(doc, Font.e_courier, true));
223 ColorPt red = new ColorPt(1, 0, 0, 0);
224 s.setFontColor(red); //set color to red
225 s.setTextAlignment(Stamper.e_align_right);
226 s.setAsBackground(true); //set text stamp as background
227 PageSet ps = new PageSet(1, 2);
228 s.stampText(doc, "This is a title!", ps);
229
230 Image img = Image.create(doc, Utils.getAssetTempFile(INPUT_PATH + "peppers.jpg").getAbsolutePath());
231 s.setAsBackground(false); // set image stamp as foreground
232 PageSet first_page_ps = new PageSet(1);
233 s.stampImage(doc, img, first_page_ps);
234
235 doc.save(Utils.createExternalFile(input_filename + ".ex8.pdf", mFileList).getAbsolutePath(), SDFDoc.SaveMode.LINEARIZED, null);
236 } catch (Exception e) {
237 mOutputListener.printError(e.getStackTrace());
238 return;
239 }
240
241 for (String file : mFileList) {
242 addToFileList(file);
243 }
244 printFooter(outputListener);
245 }
246 //---------------------------------------------------------------------------------------
247 // The following sample shows how to add new content (or watermark) PDF pages
248 // using 'pdftron.PDF.Stamper' utility class.
249 //
250 // Stamper can be used to PDF pages with text, images, or with other PDF content
251 // in only a few lines of code. Although Stamper is very simple to use compared
252 // to ElementBuilder/ElementWriter it is not as powerful or flexible. In case you
253 // need full control over PDF creation use ElementBuilder/ElementWriter to add
254 // new content to existing PDF pages as shown in the ElementBuilder sample project.
255 //---------------------------------------------------------------------------------------
256
257}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6package com.pdftron.android.pdfnetsdksamples.samples
7
8import com.pdftron.android.pdfnetsdksamples.OutputListener
9import com.pdftron.android.pdfnetsdksamples.PDFNetSample
10import com.pdftron.android.pdfnetsdksamples.R
11import com.pdftron.android.pdfnetsdksamples.util.Utils
12import com.pdftron.pdf.*
13import com.pdftron.sdf.SDFDoc
14import java.util.*
15
16/**
17 * The following sample shows how to add new content (or watermark) PDF pages
18 * using 'com.pdftron.pdf.Stamper' utility class.
19 *
20 *
21 * Stamper can be used to PDF pages with text, images, or with other PDF content
22 * in only a few lines of code. Although Stamper is very simple to use compared
23 * to ElementBuilder/ElementWriter it is not as powerful or flexible. In case you
24 * need full control over PDF creation use ElementBuilder/ElementWriter to add
25 * new content to existing PDF pages as shown in the ElementBuilder sample project.
26 */
27class StamperTest : PDFNetSample() {
28 init {
29 setTitle(R.string.sample_stamper_title)
30 setDescription(R.string.sample_stamper_description)
31 }
32
33 override fun run(outputListener: OutputListener?) {
34 super.run(outputListener)
35 mOutputListener = outputListener
36 mFileList.clear()
37 printHeader(outputListener!!)
38 val input_filename = "newsletter"
39
40 //--------------------------------------------------------------------------------
41 // Example 1) Add text stamp to all pages, then remove text stamp from odd pages.
42 try {
43 PDFDoc(Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + input_filename + ".pdf")!!.absolutePath).use { doc ->
44 doc.initSecurityHandler()
45 val s = Stamper(Stamper.e_relative_scale, 0.5, 0.5)
46 s.setAlignment(Stamper.e_horizontal_center, Stamper.e_vertical_center)
47 val red = ColorPt(1.0, 0.0, 0.0) // set text color to red
48 s.setFontColor(red)
49 val msg = "If you are reading this\nthis is an even page"
50 val ps = PageSet(1, doc.pageCount)
51 s.stampText(doc, msg, ps)
52 //delete all text stamps in even pages
53 val ps1 = PageSet(1, doc.pageCount, PageSet.e_odd)
54 Stamper.deleteStamps(doc, ps1)
55
56 doc.save(Utils.createExternalFile("$input_filename.ex1.pdf", mFileList).absolutePath, SDFDoc.SaveMode.LINEARIZED, null)
57 }
58 } catch (e: Exception) {
59 mOutputListener!!.printError(e.stackTrace)
60 return
61 }
62
63 //--------------------------------------------------------------------------------
64 // Example 2) Add Image stamp to first 2 pages.
65 try {
66 PDFDoc(Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + input_filename + ".pdf")!!.absolutePath).use { doc ->
67 doc.initSecurityHandler()
68
69 val s = Stamper(Stamper.e_relative_scale, .05, .05)
70 val img = Image.create(doc, Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + "peppers.jpg")!!.absolutePath)
71 s.setSize(Stamper.e_relative_scale, 0.5, 0.5)
72 //set position of the image to the center, left of PDF pages
73 s.setAlignment(Stamper.e_horizontal_left, Stamper.e_vertical_center)
74 val pt = ColorPt(0.0, 0.0, 0.0, 0.0)
75 s.setFontColor(pt)
76 s.setRotation(180.0)
77 s.setAsBackground(false)
78 //only stamp first 2 pages
79 val ps = PageSet(1, 2)
80 s.stampImage(doc, img, ps)
81
82 doc.save(Utils.createExternalFile("$input_filename.ex2.pdf", mFileList).absolutePath, SDFDoc.SaveMode.LINEARIZED, null)
83 }
84 } catch (e: Exception) {
85 mOutputListener!!.printError(e.stackTrace)
86 return
87 }
88
89 //--------------------------------------------------------------------------------
90 // Example 3) Add Page stamp to all pages.
91 try {
92 PDFDoc(Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + input_filename + ".pdf")!!.absolutePath).use { doc ->
93 doc.initSecurityHandler()
94
95 PDFDoc(Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + "fish.pdf")!!.absolutePath).use { fish_doc ->
96 fish_doc.initSecurityHandler()
97
98 val s = Stamper(Stamper.e_relative_scale, 0.5, 0.5)
99 val src_page = fish_doc.getPage(1)
100 val page_one_crop = src_page.cropBox
101 // set size of the image to 10% of the original while keep the old aspect ratio
102 s.setSize(Stamper.e_absolute_size, page_one_crop.width * 0.1, -1.0)
103 s.setOpacity(0.4)
104 s.setRotation(-67.0)
105 //put the image at the bottom right hand corner
106 s.setAlignment(Stamper.e_horizontal_right, Stamper.e_vertical_bottom)
107 val ps = PageSet(1, doc.pageCount)
108 s.stampPage(doc, src_page, ps)
109
110 doc.save(Utils.createExternalFile("$input_filename.ex3.pdf", mFileList).absolutePath, SDFDoc.SaveMode.LINEARIZED, null)
111 }
112 }
113 } catch (e: Exception) {
114 mOutputListener!!.printError(e.stackTrace)
115 return
116 }
117
118 //--------------------------------------------------------------------------------
119 // Example 4) Add Image stamp to first 20 odd pages.
120 try {
121 PDFDoc(Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + input_filename + ".pdf")!!.absolutePath).use { doc ->
122 doc.initSecurityHandler()
123
124 val s = Stamper(Stamper.e_absolute_size, 20.0, 20.0)
125 s.setOpacity(1.0)
126 s.setRotation(45.0)
127 s.setAsBackground(true)
128 s.setPosition(30.0, 40.0)
129 val img = Image.create(doc, Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + "peppers.jpg")!!.absolutePath)
130 val ps = PageSet(1, 20, PageSet.e_odd)
131 s.stampImage(doc, img, ps)
132
133 doc.save(Utils.createExternalFile("$input_filename.ex4.pdf", mFileList).absolutePath, SDFDoc.SaveMode.LINEARIZED, null)
134 }
135 } catch (e: Exception) {
136 mOutputListener!!.printError(e.stackTrace)
137 return
138 }
139
140 //--------------------------------------------------------------------------------
141 // Example 5) Add text stamp to first 20 even pages
142 try {
143 PDFDoc(Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + input_filename + ".pdf")!!.absolutePath).use { doc ->
144 doc.initSecurityHandler()
145
146 val s = Stamper(Stamper.e_relative_scale, .05, .05)
147 s.setPosition(0.0, 0.0)
148 s.setOpacity(0.7)
149 s.setRotation(90.0)
150 s.setSize(Stamper.e_font_size, 80.0, -1.0)
151 s.setTextAlignment(Stamper.e_align_center)
152 val ps = PageSet(1, 20, PageSet.e_even)
153 s.stampText(doc, "Goodbye\nMoon", ps)
154
155 doc.save(Utils.createExternalFile("$input_filename.ex5.pdf", mFileList).absolutePath, SDFDoc.SaveMode.LINEARIZED, null)
156 }
157 } catch (e: Exception) {
158 mOutputListener!!.printError(e.stackTrace)
159 return
160 }
161
162 //--------------------------------------------------------------------------------
163 // Example 6) Add first page as stamp to all even pages
164 try {
165 PDFDoc(Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + input_filename + ".pdf")!!.absolutePath).use { doc ->
166 doc.initSecurityHandler()
167
168 PDFDoc(Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + "fish.pdf")!!.absolutePath).use { fish_doc ->
169 fish_doc.initSecurityHandler()
170
171 val s = Stamper(Stamper.e_relative_scale, 0.3, 0.3)
172 s.setOpacity(1.0)
173 s.setRotation(270.0)
174 s.setAsBackground(true)
175 s.setPosition(0.5, 0.5, true)
176 s.setAlignment(Stamper.e_horizontal_left, Stamper.e_vertical_bottom)
177 val page_one = fish_doc.getPage(1)
178 val ps = PageSet(1, doc.pageCount, PageSet.e_even)
179 s.stampPage(doc, page_one, ps)
180
181 doc.save(Utils.createExternalFile("$input_filename.ex6.pdf", mFileList).absolutePath, SDFDoc.SaveMode.LINEARIZED, null)
182 }
183 }
184 } catch (e: Exception) {
185 mOutputListener!!.printError(e.stackTrace)
186 return
187 }
188
189 //--------------------------------------------------------------------------------
190 // Example 7) Add image stamp at top right corner in every pages
191 try {
192 PDFDoc(Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + input_filename + ".pdf")!!.absolutePath).use { doc ->
193 doc.initSecurityHandler()
194
195 val s = Stamper(Stamper.e_relative_scale, .1, .1)
196 s.setOpacity(0.8)
197 s.setRotation(135.0)
198 s.setAsBackground(false)
199 s.showsOnPrint(false)
200 s.setAlignment(Stamper.e_horizontal_left, Stamper.e_vertical_top)
201 s.setPosition(10.0, 10.0)
202
203 val img = Image.create(doc, Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + "peppers.jpg")!!.absolutePath)
204 val ps = PageSet(1, doc.pageCount, PageSet.e_all)
205 s.stampImage(doc, img, ps)
206
207 doc.save(Utils.createExternalFile("$input_filename.ex7.pdf", mFileList).absolutePath, SDFDoc.SaveMode.LINEARIZED, null)
208 }
209 } catch (e: Exception) {
210 mOutputListener!!.printError(e.stackTrace)
211 return
212 }
213
214 //--------------------------------------------------------------------------------
215 // Example 8) Add Text stamp to first 2 pages, and image stamp to first page.
216 // Because text stamp is set as background, the image is top of the text
217 // stamp. Text stamp on the first page is not visible.
218 try {
219 PDFDoc(Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + input_filename + ".pdf")!!.absolutePath).use { doc ->
220 doc.initSecurityHandler()
221
222 val s = Stamper(Stamper.e_relative_scale, 0.07, -0.1)
223 s.setAlignment(Stamper.e_horizontal_right, Stamper.e_vertical_bottom)
224 s.setAlignment(Stamper.e_horizontal_center, Stamper.e_vertical_top)
225 s.setFont(Font.create(doc, Font.e_courier, true))
226 val red = ColorPt(1.0, 0.0, 0.0, 0.0)
227 s.setFontColor(red) //set color to red
228 s.setTextAlignment(Stamper.e_align_right)
229 s.setAsBackground(true) //set text stamp as background
230 val ps = PageSet(1, 2)
231 s.stampText(doc, "This is a title!", ps)
232
233 val img = Image.create(doc, Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + "peppers.jpg")!!.absolutePath)
234 s.setAsBackground(false) // set image stamp as foreground
235 val first_page_ps = PageSet(1)
236 s.stampImage(doc, img, first_page_ps)
237
238 doc.save(Utils.createExternalFile("$input_filename.ex8.pdf", mFileList).absolutePath, SDFDoc.SaveMode.LINEARIZED, null)
239 }
240 } catch (e: Exception) {
241 mOutputListener!!.printError(e.stackTrace)
242 return
243 }
244
245 for (file in mFileList) {
246 addToFileList(file)
247 }
248 printFooter(outputListener)
249 }
250
251 companion object {
252
253 private var mOutputListener: OutputListener? = null
254
255 private val mFileList = ArrayList<String>()
256 }
257 //---------------------------------------------------------------------------------------
258 // The following sample shows how to add new content (or watermark) PDF pages
259 // using 'pdftron.PDF.Stamper' utility class.
260 //
261 // Stamper can be used to PDF pages with text, images, or with other PDF content
262 // in only a few lines of code. Although Stamper is very simple to use compared
263 // to ElementBuilder/ElementWriter it is not as powerful or flexible. In case you
264 // need full control over PDF creation use ElementBuilder/ElementWriter to add
265 // new content to existing PDF pages as shown in the ElementBuilder sample project.
266 //---------------------------------------------------------------------------------------
267
268}
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales