Annotation

Sample Java code to use Apryse SDK for adding or editing PDF annotations. The annotation types included in this sample are: hyperlink, intra-document link, stamp, rubber stamp, file attachment, sound, text, free-text, line, circle, square, polygon, polyline, highlight, squiggly, caret, and ink. Learn more about our Android SDK and PDF Annotation Library.

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.common.PDFNetException;
13import com.pdftron.pdf.Action;
14import com.pdftron.pdf.Annot;
15import com.pdftron.pdf.Annot.BorderStyle;
16import com.pdftron.pdf.ColorPt;
17import com.pdftron.pdf.Destination;
18import com.pdftron.pdf.Element;
19import com.pdftron.pdf.ElementBuilder;
20import com.pdftron.pdf.ElementWriter;
21import com.pdftron.pdf.FileSpec;
22import com.pdftron.pdf.Font;
23import com.pdftron.pdf.PDFDoc;
24import com.pdftron.pdf.Page;
25import com.pdftron.pdf.PageIterator;
26import com.pdftron.pdf.Point;
27import com.pdftron.pdf.QuadPoint;
28import com.pdftron.pdf.Rect;
29import com.pdftron.pdf.annots.Caret;
30import com.pdftron.pdf.annots.Circle;
31import com.pdftron.pdf.annots.FreeText;
32import com.pdftron.pdf.annots.Highlight;
33import com.pdftron.pdf.annots.Ink;
34import com.pdftron.pdf.annots.Line;
35import com.pdftron.pdf.annots.Link;
36import com.pdftron.pdf.annots.PolyLine;
37import com.pdftron.pdf.annots.Polygon;
38import com.pdftron.pdf.annots.RubberStamp;
39import com.pdftron.pdf.annots.Sound;
40import com.pdftron.pdf.annots.Square;
41import com.pdftron.pdf.annots.Squiggly;
42import com.pdftron.pdf.annots.Text;
43import com.pdftron.sdf.Obj;
44import com.pdftron.sdf.SDFDoc;
45
46import java.text.DecimalFormat;
47import java.util.ArrayList;
48
49public class AnnotationTest extends PDFNetSample {
50
51 private static OutputListener mOutputListener;
52
53 private static ArrayList<String> mFileList = new ArrayList<>();
54
55 public AnnotationTest() {
56 setTitle(R.string.sample_annotation_title);
57 setDescription(R.string.sample_annotation_description);
58 }
59
60 @Override
61 public void run(OutputListener outputListener) {
62 super.run(outputListener);
63 mOutputListener = outputListener;
64 mFileList.clear();
65 printHeader(outputListener);
66
67 try (PDFDoc doc = new PDFDoc((Utils.getAssetTempFile(INPUT_PATH + "numbered.pdf").getAbsolutePath()))) {
68 doc.initSecurityHandler();
69
70 // An example of using SDF/Cos API to add any type of annotations.
71 AnnotationLowLevelAPI(doc);
72 doc.save(Utils.createExternalFile("annotation_test1.pdf", mFileList).getAbsolutePath(), SDFDoc.SaveMode.LINEARIZED, null);
73 mOutputListener.println("Done. Results saved in annotation_test1.pdf");
74
75 // An example of using the high-level PDFNet API to read existing annotations,
76 // to edit existing annotations, and to create new annotation from scratch.
77 AnnotationHighLevelAPI(doc);
78 doc.save(Utils.createExternalFile("annotation_test2.pdf", mFileList).getAbsolutePath(), SDFDoc.SaveMode.LINEARIZED, null);
79 mOutputListener.println("Done. Results saved in annotation_test2.pdf");
80 } catch (Exception e) {
81 mOutputListener.printError(e.getStackTrace());
82 }
83
84 // an example of creating various annotations in a brand new document
85 try (PDFDoc doc1 = new PDFDoc()) {
86 CreateTestAnnots(doc1);
87 doc1.save(Utils.createExternalFile("new_annot_test_api.pdf", mFileList).getAbsolutePath(), SDFDoc.SaveMode.LINEARIZED, null);
88 mOutputListener.println("Saved new_annot_test_api.pdf");
89 } catch (Exception e) {
90 mOutputListener.printError(e.getStackTrace());
91 }
92
93 for (String file : mFileList) {
94 addToFileList(file);
95 }
96 printFooter(outputListener);
97 }
98
99 public static final DecimalFormat format = new DecimalFormat("0.#");
100
101 static void AnnotationHighLevelAPI(PDFDoc doc) throws PDFNetException {
102 // The following code snippet traverses all annotations in the document
103 mOutputListener.println("Traversing all annotations in the document...");
104
105 int page_num = 1;
106 for (PageIterator itr = doc.getPageIterator(); itr.hasNext(); ) {
107 mOutputListener.println("Page " + (page_num++) + ": ");
108
109 Page page = itr.next();
110 int num_annots = page.getNumAnnots();
111 for (int i = 0; i < num_annots; ++i) {
112 Annot annot = page.getAnnot(i);
113 if (annot.isValid() == false) continue;
114 mOutputListener.println("Annot Type: " + annot.getSDFObj().get("Subtype").value().getName());
115
116 double[] bbox = annot.getRect().get();
117 mOutputListener.println(" Position: " + format.format(bbox[0])
118 + ", " + format.format(bbox[1])
119 + ", " + format.format(bbox[2])
120 + ", " + format.format(bbox[3]));
121
122 switch (annot.getType()) {
123 case Annot.e_Link: {
124 com.pdftron.pdf.annots.Link link = new com.pdftron.pdf.annots.Link(annot);
125 Action action = link.getAction();
126 if (action.isValid() == false) continue;
127 if (action.getType() == Action.e_GoTo) {
128 Destination dest = action.getDest();
129 if (dest.isValid() == false) {
130 mOutputListener.println(" Destination is not valid.");
131 } else {
132 int page_link = dest.getPage().getIndex();
133 mOutputListener.println(" Links to: page number " + page_link + " in this document");
134 }
135 } else if (action.getType() == Action.e_URI) {
136 String uri = action.getSDFObj().get("URI").value().getAsPDFText();
137 mOutputListener.println(" Links to: " + uri);
138 }
139 // ...
140 }
141 break;
142 case Annot.e_Widget:
143 break;
144 case Annot.e_FileAttachment:
145 break;
146 // ...
147 default:
148 break;
149 }
150 }
151 }
152
153 // Use the high-level API to create new annotations.
154 Page first_page = doc.getPage(1);
155
156 // Create a hyperlink...
157 com.pdftron.pdf.annots.Link hyperlink = com.pdftron.pdf.annots.Link.create(doc, new Rect(85, 570, 503, 524), Action.createURI(doc, "http://www.pdftron.com"));
158 first_page.annotPushBack(hyperlink);
159
160 // Create an intra-document link...
161 Action goto_page_3 = Action.createGoto(Destination.createFitH(doc.getPage(3), 0));
162 com.pdftron.pdf.annots.Link link = com.pdftron.pdf.annots.Link.create(doc.getSDFDoc(),
163 new Rect(85, 458, 503, 502),
164 goto_page_3);
165 link.setColor(new ColorPt(0, 0, 1), 3);
166
167 // Add the new annotation to the first page
168 first_page.annotPushBack(link);
169
170 // Create a stamp annotation ...
171 com.pdftron.pdf.annots.RubberStamp stamp = com.pdftron.pdf.annots.RubberStamp.create(doc, new Rect(30, 30, 300, 200));
172 stamp.setIcon("Draft");
173 first_page.annotPushBack(stamp);
174
175 // Create a file attachment annotation (embed the 'peppers.jpg').
176 com.pdftron.pdf.annots.FileAttachment file_attach = com.pdftron.pdf.annots.FileAttachment.create(doc, new Rect(80, 280, 108, 320), (Utils.getAssetTempFile(INPUT_PATH + "peppers.jpg").getAbsolutePath()));
177 first_page.annotPushBack(file_attach);
178
179 com.pdftron.pdf.annots.Ink ink = com.pdftron.pdf.annots.Ink.create(doc, new Rect(110, 10, 300, 200));
180 Point pt3 = new Point(110, 10);
181 //pt3.x = 110; pt3.y = 10;
182 ink.setPoint(0, 0, pt3);
183 pt3.x = 150;
184 pt3.y = 50;
185 ink.setPoint(0, 1, pt3);
186 pt3.x = 190;
187 pt3.y = 60;
188 ink.setPoint(0, 2, pt3);
189 pt3.x = 180;
190 pt3.y = 90;
191 ink.setPoint(1, 0, pt3);
192 pt3.x = 190;
193 pt3.y = 95;
194 ink.setPoint(1, 1, pt3);
195 pt3.x = 200;
196 pt3.y = 100;
197 ink.setPoint(1, 2, pt3);
198 pt3.x = 166;
199 pt3.y = 86;
200 ink.setPoint(2, 0, pt3);
201 pt3.x = 196;
202 pt3.y = 96;
203 ink.setPoint(2, 1, pt3);
204 pt3.x = 221;
205 pt3.y = 121;
206 ink.setPoint(2, 2, pt3);
207 pt3.x = 288;
208 pt3.y = 188;
209 ink.setPoint(2, 3, pt3);
210 ink.setColor(new ColorPt(0, 1, 1), 3);
211 first_page.annotPushBack(ink);
212
213 }
214
215 static void AnnotationLowLevelAPI(PDFDoc doc) throws PDFNetException {
216 Page page = doc.getPageIterator().next();
217
218 Obj annots = page.getAnnots();
219
220 if (annots == null) {
221 // If there are no annotations, create a new annotation
222 // array for the page.
223 annots = doc.createIndirectArray();
224 page.getSDFObj().put("Annots", annots);
225 }
226
227 // Create a Text annotation
228 Obj annot = doc.createIndirectDict();
229 annot.putName("Subtype", "Text");
230 annot.putBool("Open", true);
231 annot.putString("Contents", "The quick brown fox ate the lazy mouse.");
232 annot.putRect("Rect", 266, 116, 430, 204);
233
234 // Insert the annotation in the page annotation array
235 annots.pushBack(annot);
236
237 // Create a Link annotation
238 Obj link1 = doc.createIndirectDict();
239 link1.putName("Subtype", "Link");
240 Destination dest = Destination.createFit(doc.getPage(2));
241 link1.put("Dest", dest.getSDFObj());
242 link1.putRect("Rect", 85, 705, 503, 661);
243 annots.pushBack(link1);
244
245 // Create another Link annotation
246 Obj link2 = doc.createIndirectDict();
247 link2.putName("Subtype", "Link");
248 Destination dest2 = Destination.createFit(doc.getPage(3));
249 link2.put("Dest", dest2.getSDFObj());
250 link2.putRect("Rect", 85, 638, 503, 594);
251 annots.pushBack(link2);
252
253 // Note that PDFNet APi can be used to modify existing annotations.
254 // In the following example we will modify the second link annotation
255 // (link2) so that it points to the 10th page. We also use a different
256 // destination page fit type.
257
258 // link2 = annots.GetAt(annots.Size()-1);
259 link2.put("Dest",
260 Destination.createXYZ(doc.getPage(10), 100, 792 - 70, 10).getSDFObj());
261
262 // Create a third link annotation with a hyperlink action (all other
263 // annotation types can be created in a similar way)
264 Obj link3 = doc.createIndirectDict();
265 link3.putName("Subtype", "Link");
266 link3.putRect("Rect", 85, 570, 503, 524);
267
268 // Create a URI action
269 Obj action = link3.putDict("A");
270 action.putName("S", "URI");
271 action.putString("URI", "http://www.pdftron.com");
272
273 annots.pushBack(link3);
274 }
275
276 static void CreateTestAnnots(PDFDoc doc) throws PDFNetException {
277 ElementWriter ew = new ElementWriter();
278 ElementBuilder eb = new ElementBuilder();
279 Element element;
280
281 Page first_page = doc.pageCreate(new Rect(0, 0, 600, 600));
282 doc.pagePushBack(first_page);
283 ew.begin(first_page, ElementWriter.e_overlay, false); // begin writing to this page
284 ew.end(); // save changes to the current page
285
286 //
287 // Test of a free text annotation.
288 //
289 {
290 FreeText txtannot = FreeText.create(doc, new Rect(10, 400, 160, 570));
291 txtannot.setContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." +
292 "\n\nAha!\n\nAnd there was much rejoicing!");
293 txtannot.setBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.e_solid, 1, 10, 20));
294 txtannot.setQuaddingFormat(0);
295 first_page.annotPushBack(txtannot);
296 txtannot.refreshAppearance();
297 }
298 {
299 FreeText txtannot = FreeText.create(doc, new Rect(100, 100, 350, 500));
300 txtannot.setContentRect(new Rect(200, 200, 350, 500));
301 txtannot.setContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." +
302 "\n\nAha!\n\nAnd there was much rejoicing!");
303 txtannot.setCalloutLinePoints(new Point(200, 300), new Point(150, 290), new Point(110, 110));
304 txtannot.setBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.e_solid, 1, 10, 20));
305 txtannot.setEndingStyle(Line.e_ClosedArrow);
306 txtannot.setColor(new ColorPt(0, 1, 0));
307 txtannot.setQuaddingFormat(1);
308 first_page.annotPushBack(txtannot);
309 txtannot.refreshAppearance();
310 }
311 {
312 FreeText txtannot = FreeText.create(doc, new Rect(400, 10, 550, 400));
313 txtannot.setContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." +
314 "\n\nAha!\n\nAnd there was much rejoicing!");
315 txtannot.setBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.e_solid, 1, 10, 20));
316 txtannot.setColor(new ColorPt(0, 0, 1));
317 txtannot.setOpacity(0.2);
318 txtannot.setQuaddingFormat(2);
319 first_page.annotPushBack(txtannot);
320 txtannot.refreshAppearance();
321 }
322
323 Page page = doc.pageCreate(new Rect(0, 0, 600, 600));
324 doc.pagePushBack(page);
325 ew.begin(page, ElementWriter.e_overlay, false); // begin writing to this page
326 eb.reset(); // Reset the GState to default
327 ew.end(); // save changes to the current page
328
329 {
330 //Create a Line annotation...
331 Line line = Line.create(doc, new Rect(250, 250, 400, 400));
332 line.setStartPoint(new Point(350, 270));
333 line.setEndPoint(new Point(260, 370));
334 line.setStartStyle(Line.e_Square);
335 line.setEndStyle(Line.e_Circle);
336 line.setColor(new ColorPt(.3, .5, 0), 3);
337 line.setContents("Dashed Captioned");
338 line.setShowCaption(true);
339 line.setCaptionPosition(Line.e_Top);
340 double[] dash = {2, 2.0};
341 line.setBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.e_dashed, 2, 0, 0, dash));
342 line.refreshAppearance();
343 page.annotPushBack(line);
344 }
345 {
346 Line line = Line.create(doc, new Rect(347, 377, 600, 600));
347 line.setStartPoint(new Point(385, 410));
348 line.setEndPoint(new Point(540, 555));
349 line.setStartStyle(Line.e_Circle);
350 line.setEndStyle(Line.e_OpenArrow);
351 line.setColor(new ColorPt(1, 0, 0), 3);
352 line.setInteriorColor(new ColorPt(0, 1, 0), 3);
353 line.setContents("Inline Caption");
354 line.setShowCaption(true);
355 line.setCaptionPosition(Line.e_Inline);
356 line.setLeaderLineExtensionLength(4.);
357 line.setLeaderLineLength(-12.);
358 line.setLeaderLineOffset(2.);
359 line.refreshAppearance();
360 page.annotPushBack(line);
361 }
362 {
363 Line line = Line.create(doc, new Rect(10, 400, 200, 600));
364 line.setStartPoint(new Point(25, 426));
365 line.setEndPoint(new Point(180, 555));
366 line.setStartStyle(Line.e_Circle);
367 line.setEndStyle(Line.e_Square);
368 line.setColor(new ColorPt(0, 0, 1), 3);
369 line.setInteriorColor(new ColorPt(1, 0, 0), 3);
370 line.setContents("Offset Caption");
371 line.setShowCaption(true);
372 line.setCaptionPosition(Line.e_Top);
373 line.setTextHOffset(-60);
374 line.setTextVOffset(10);
375 line.refreshAppearance();
376 page.annotPushBack(line);
377 }
378 {
379 Line line = Line.create(doc, new Rect(200, 10, 400, 70));
380 line.setStartPoint(new Point(220, 25));
381 line.setEndPoint(new Point(370, 60));
382 line.setStartStyle(Line.e_Butt);
383 line.setEndStyle(Line.e_OpenArrow);
384 line.setColor(new ColorPt(0, 0, 1), 3);
385 line.setContents("Regular Caption");
386 line.setShowCaption(true);
387 line.setCaptionPosition(Line.e_Top);
388 line.refreshAppearance();
389 page.annotPushBack(line);
390 }
391 {
392 Line line = Line.create(doc, new Rect(200, 70, 400, 130));
393 line.setStartPoint(new Point(220, 111));
394 line.setEndPoint(new Point(370, 78));
395 line.setStartStyle(Line.e_Circle);
396 line.setEndStyle(Line.e_Diamond);
397 line.setContents("Circle to Diamond");
398 line.setColor(new ColorPt(0, 0, 1), 3);
399 line.setInteriorColor(new ColorPt(0, 1, 0), 3);
400 line.setShowCaption(true);
401 line.setCaptionPosition(Line.e_Top);
402 line.refreshAppearance();
403 page.annotPushBack(line);
404 }
405 {
406 Line line = Line.create(doc, new Rect(10, 100, 160, 200));
407 line.setStartPoint(new Point(15, 110));
408 line.setEndPoint(new Point(150, 190));
409 line.setStartStyle(Line.e_Slash);
410 line.setEndStyle(Line.e_ClosedArrow);
411 line.setContents("Slash to CArrow");
412 line.setColor(new ColorPt(1, 0, 0), 3);
413 line.setInteriorColor(new ColorPt(0, 1, 1), 3);
414 line.setShowCaption(true);
415 line.setCaptionPosition(Line.e_Top);
416 line.refreshAppearance();
417 page.annotPushBack(line);
418 }
419 {
420 Line line = Line.create(doc, new Rect(270, 270, 570, 433));
421 line.setStartPoint(new Point(300, 400));
422 line.setEndPoint(new Point(550, 300));
423 line.setStartStyle(Line.e_RClosedArrow);
424 line.setEndStyle(Line.e_ROpenArrow);
425 line.setContents("ROpen & RClosed arrows");
426 line.setColor(new ColorPt(0, 0, 1), 3);
427 line.setInteriorColor(new ColorPt(0, 1, 0), 3);
428 line.setShowCaption(true);
429 line.setCaptionPosition(Line.e_Top);
430 line.refreshAppearance();
431 page.annotPushBack(line);
432 }
433 {
434 Line line = Line.create(doc, new Rect(195, 395, 205, 505));
435 line.setStartPoint(new Point(200, 400));
436 line.setEndPoint(new Point(200, 500));
437 line.refreshAppearance();
438 page.annotPushBack(line);
439 }
440 {
441 Line line = Line.create(doc, new Rect(55, 299, 150, 301));
442 line.setStartPoint(new Point(55, 300));
443 line.setEndPoint(new Point(155, 300));
444 line.setStartStyle(Line.e_Circle);
445 line.setEndStyle(Line.e_Circle);
446 line.setContents("Caption that's longer than its line.");
447 line.setColor(new ColorPt(1, 0, 1), 3);
448 line.setInteriorColor(new ColorPt(0, 1, 0), 3);
449 line.setShowCaption(true);
450 line.setCaptionPosition(Line.e_Top);
451 line.refreshAppearance();
452 page.annotPushBack(line);
453 }
454 {
455 Line line = Line.create(doc, new Rect(300, 200, 390, 234));
456 line.setStartPoint(new Point(310, 210));
457 line.setEndPoint(new Point(380, 220));
458 line.setColor(new ColorPt(0, 0, 0), 3);
459 line.refreshAppearance();
460 page.annotPushBack(line);
461 }
462
463 Page page3 = doc.pageCreate(new Rect(0, 0, 600, 600));
464 ew.begin(page3); // begin writing to the page
465 ew.end(); // save changes to the current page
466 doc.pagePushBack(page3);
467 {
468 Circle circle = Circle.create(doc, new Rect(300, 300, 390, 350));
469 circle.setColor(new ColorPt(0, 0, 0), 3);
470 circle.refreshAppearance();
471 page3.annotPushBack(circle);
472 }
473 {
474 Circle circle = Circle.create(doc, new Rect(100, 100, 200, 200));
475 circle.setColor(new ColorPt(0, 1, 0), 3);
476 circle.setInteriorColor(new ColorPt(0, 0, 1), 3);
477 double[] dash = {2, 4};
478 circle.setBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.e_dashed, 3, 0, 0, dash));
479 circle.setPadding(2);
480 circle.refreshAppearance();
481 page3.annotPushBack(circle);
482 }
483 {
484 Square sq = Square.create(doc, new Rect(10, 200, 80, 300));
485 sq.setColor(new ColorPt(0, 0, 0), 3);
486 sq.refreshAppearance();
487 page3.annotPushBack(sq);
488 }
489 {
490 Square sq = Square.create(doc, new Rect(500, 200, 580, 300));
491 sq.setColor(new ColorPt(1, 0, 0), 3);
492 sq.setInteriorColor(new ColorPt(0, 1, 1), 3);
493 double[] dash = {4, 2};
494 sq.setBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.e_dashed, 6, 0, 0, dash));
495 sq.setPadding(4);
496 sq.refreshAppearance();
497 page3.annotPushBack(sq);
498 }
499 {
500 Polygon poly = Polygon.create(doc, new Rect(5, 500, 125, 590));
501 poly.setColor(new ColorPt(1, 0, 0), 3);
502 poly.setInteriorColor(new ColorPt(1, 1, 0), 3);
503 poly.setVertex(0, new Point(12, 510));
504 poly.setVertex(1, new Point(100, 510));
505 poly.setVertex(2, new Point(100, 555));
506 poly.setVertex(3, new Point(35, 544));
507 poly.setBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.e_solid, 4, 0, 0));
508 poly.setPadding(4);
509 poly.refreshAppearance();
510 page3.annotPushBack(poly);
511 }
512 {
513 PolyLine poly = PolyLine.create(doc, new Rect(400, 10, 500, 90));
514 poly.setColor(new ColorPt(1, 0, 0), 3);
515 poly.setInteriorColor(new ColorPt(0, 1, 0), 3);
516 poly.setVertex(0, new Point(405, 20));
517 poly.setVertex(1, new Point(440, 40));
518 poly.setVertex(2, new Point(410, 60));
519 poly.setVertex(3, new Point(470, 80));
520 poly.setBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.e_solid, 2, 0, 0));
521 poly.setPadding(4);
522 poly.setStartStyle(Line.e_RClosedArrow);
523 poly.setEndStyle(Line.e_ClosedArrow);
524 poly.refreshAppearance();
525 page3.annotPushBack(poly);
526 }
527 {
528 Link lk = Link.create(doc, new Rect(5, 5, 55, 24));
529 lk.refreshAppearance();
530 page3.annotPushBack(lk);
531 }
532
533 Page page4 = doc.pageCreate(new Rect(0, 0, 600, 600));
534 ew.begin(page4); // begin writing to the page
535 ew.end(); // save changes to the current page
536 doc.pagePushBack(page4);
537
538 {
539 ew.begin(page4);
540 Font font = Font.create(doc, Font.e_helvetica);
541 element = eb.createTextBegin(font, 16);
542 element.setPathFill(true);
543 ew.writeElement(element);
544 element = eb.createTextRun("Some random text on the page", font, 16);
545 element.setTextMatrix(1, 0, 0, 1, 100, 500);
546 ew.writeElement(element);
547 ew.writeElement(eb.createTextEnd());
548 ew.end();
549 }
550 {
551 Highlight hl = Highlight.create(doc, new Rect(100, 490, 150, 515));
552 hl.setColor(new ColorPt(0, 1, 0), 3);
553 hl.refreshAppearance();
554 page4.annotPushBack(hl);
555 }
556 {
557 Squiggly sq = Squiggly.create(doc, new Rect(100, 450, 250, 600));
558 sq.setQuadPoint(0, new QuadPoint(new Point(122, 455), new Point(240, 545), new Point(230, 595), new Point(101, 500)));
559 sq.refreshAppearance();
560 page4.annotPushBack(sq);
561 }
562 {
563 Caret cr = Caret.create(doc, new Rect(100, 40, 129, 69));
564 cr.setColor(new ColorPt(0, 0, 1), 3);
565 cr.setSymbol("P");
566 cr.refreshAppearance();
567 page4.annotPushBack(cr);
568 }
569
570 Page page5 = doc.pageCreate(new Rect(0, 0, 600, 600));
571 ew.begin(page5); // begin writing to the page
572 ew.end(); // save changes to the current page
573 doc.pagePushBack(page5);
574 FileSpec fs = FileSpec.create(doc, Utils.getAssetTempFile(INPUT_PATH + "butterfly.png").getAbsolutePath(), false);
575 Page page6 = doc.pageCreate(new Rect(0, 0, 600, 600));
576 ew.begin(page6); // begin writing to the page
577 ew.end(); // save changes to the current page
578 doc.pagePushBack(page6);
579
580 {
581 Text txt = Text.create(doc, new Point(10, 20));
582 txt.setIcon("UserIcon");
583 txt.setContents("User defined icon, unrecognized by appearance generator");
584 txt.setColor(new ColorPt(0, 1, 0));
585 txt.refreshAppearance();
586 page6.annotPushBack(txt);
587 }
588 {
589 Ink ink = Ink.create(doc, new Rect(100, 400, 200, 550));
590 ink.setColor(new ColorPt(0, 0, 1));
591 ink.setPoint(1, 3, new Point(220, 505));
592 ink.setPoint(1, 0, new Point(100, 490));
593 ink.setPoint(0, 1, new Point(120, 410));
594 ink.setPoint(0, 0, new Point(100, 400));
595 ink.setPoint(1, 2, new Point(180, 490));
596 ink.setPoint(1, 1, new Point(140, 440));
597 ink.setBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.e_solid, 3, 0, 0));
598 ink.refreshAppearance();
599 page6.annotPushBack(ink);
600 }
601
602 Page page7 = doc.pageCreate(new Rect(0, 0, 600, 600));
603 ew.begin(page7); // begin writing to the page
604 ew.end(); // save changes to the current page
605 doc.pagePushBack(page7);
606
607 {
608 Sound snd = Sound.create(doc, new Rect(100, 500, 120, 520));
609 snd.setColor(new ColorPt(1, 1, 0));
610 snd.setIcon(Sound.e_Speaker);
611 snd.refreshAppearance();
612 page7.annotPushBack(snd);
613 }
614 {
615 Sound snd = Sound.create(doc, new Rect(200, 500, 220, 520));
616 snd.setColor(new ColorPt(1, 1, 0));
617 snd.setIcon(Sound.e_Mic);
618 snd.refreshAppearance();
619 page7.annotPushBack(snd);
620 }
621
622 Page page8 = doc.pageCreate(new Rect(0, 0, 600, 600));
623 ew.begin(page8); // begin writing to the page
624 ew.end(); // save changes to the current page
625 doc.pagePushBack(page8);
626
627 for (int ipage = 0; ipage < 2; ++ipage) {
628 double px = 5, py = 520;
629 for (int istamp = 0; istamp <= RubberStamp.e_Draft; ++istamp) {
630 RubberStamp st = RubberStamp.create(doc, new Rect(1, 1, 100, 100));
631 st.SetIcon(istamp);
632 st.setContents(st.getIconName());
633 st.setRect(new Rect(px, py, px + 100, py + 25));
634 py -= 100;
635 if (py < 0) {
636 py = 520;
637 px += 200;
638 }
639 if (ipage == 0)
640 //page7.AnnotPushBack( st );
641 ;
642 else {
643 page8.annotPushBack(st);
644 st.refreshAppearance();
645 }
646 }
647 }
648 RubberStamp st = RubberStamp.create(doc, new Rect(400, 5, 550, 45));
649 st.setIcon("UserStamp");
650 st.setContents("User defined stamp");
651 page8.annotPushBack(st);
652 st.refreshAppearance();
653 }
654
655
656}

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales