1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697
|
.. default-domain:: js
.. highlight:: javascript
PDFAnnotation
#############
PDF Annotations belong to a specific `PDFPage` and may be
created/changed/removed. Because annotation appearances may change (for several
reasons) it is possible to scan through the annotations on a page and query
them to see whether a re-render is necessary.
Additionally redaction annotations can be applied to a `PDFPage`,
destructively removing content from the page.
Annotation Types
================
These are the annotation types, and which attributes they have.
Text
An icon with a popup of text.
Set the appearance with the Icon attribute.
Attributes: `Rect`_, :ref:`color-attribute`, :ref:`icon-attribute`.
FreeText
Text in a rectangle on the page.
The text font and color is defined by DefaultAppearance.
Attributes: :ref:`border-attribute`, :ref:`rect-attribute`, :ref:`default-appearance-attribute`.
Line
A line with optional arrow heads.
The line width is determined by the border attribute.
The end points are defined by the Line attribute.
Attributes: :ref:`border-attribute`, :ref:`color-attribute`, :ref:`line-attribute`, :ref:`line-ending-styles-attribute`.
Square
A rectangle.
Attributes: :ref:`rect-attribute`, :ref:`rect-attribute`, :ref:`color-attribute`, :ref:`interior-color-attribute`.
Circle
An ellipse.
Attributes: :ref:`rect-attribute`, :ref:`border-attribute`, :ref:`color-attribute`, :ref:`interior-color-attribute`.
Polygon, PolyLine
A polygon shape (closed and open).
The shape is defined by the Vertices attribute.
The line width is defined by the Border attribute.
Attributes: :ref:`vertices-attribute`, :ref:`border-attribute`, :ref:`color-attribute`, :ref:`interior-color-attribute`, LineEndingStyles.
Highlight, Underline, Squiggly, StrikeOut
Text markups.
The shape is defined by the :ref:`quadpoints-attribute`.
Stamp
A rubber stamp.
The appearance is either a stock name, or a :ref:`custom image <stamp-image-attribute>`.
Ink
A free-hand line.
The shape is defined by the :ref:`inklist-attribute` attribute.
FileAttachment
A file attachment.
The appearance is an icon on the page.
Set the attached file contents with the :ref:`filespec-attribute` attribute,
and the appearance with the :ref:`icon-attribute` attribute.
Redaction
A black box.
Redaction annotations are used to mark areas of the page that
can be redacted. They do NOT redact any content by themselves,
you MUST apply them using `PDFAnnotation.prototype.applyRedaction` or
`PDFPage.prototype.applyRedactions`.
These annotation types are special and handled with other APIs:
- `Link`
- Popup -- see `PDFAnnotation.prototype.setPopup()`
- Widget -- see `PDFWidget`
Constructors
============
.. class:: PDFAnnotation
|no_new|
To get the annotations on a page use `PDFPage.prototype.getAnnotations()`.
To create a new annotation call `PDFPage.prototype.createAnnotation()`.
Instance methods
================
.. method:: PDFAnnotation.prototype.getBounds()
Returns a rectangle containing the location and dimension of the annotation.
:returns: `Rect`
.. code-block::
var bounds = annotation.getBounds()
.. method:: PDFAnnotation.prototype.run(device, matrix)
Calls the device functions to draw the annotation.
:param Device device: The device to make device calls to while rendering the annotation.
:param Matrix matrix: The transformation matrix.
.. code-block::
annotation.run(device, mupdf.Matrix.identity)
.. method:: PDFAnnotation.prototype.toPixmap(matrix, colorspace, alpha)
Render the annotation into a `Pixmap`, using the
``transform``, ``colorspace`` and ``alpha`` parameters.
:param Matrix matrix: Transformation matrix.
:param ColorSpace colorspace: The desired colorspace of the returned pixmap.
:param boolean alpha: Whether the returned pixmap has transparency or not. If the pixmap handles transparency, it starts out transparent (otherwise it is filled white), before the contents of the display list are rendered onto the pixmap.
:returns: `Pixmap`
.. code-block::
var pixmap = annotation.toPixmap(mupdf.Matrix.identity, mupdf.ColorSpace.DeviceRGB, true)
.. method:: PDFAnnotation.prototype.toDisplayList()
Record the contents of the annotation into a `DisplayList`.
:returns: `DisplayList`
.. code-block::
var displayList = annotation.toDisplayList()
.. method:: PDFAnnotation.prototype.getObject()
Get the underlying `PDFObject` for an annotation.
:returns: `PDFObject`
.. code-block::
var obj = annotation.getObject()
.. method:: PDFAnnotation.prototype.setAppearance(appearance, state, transform, bbox, resources, contents)
Set the annotation appearance stream for the given appearance. The
desired appearance is given as a transform along with a bounding box, a
PDF dictionary of resources and a content stream.
:param string | null appearance: Appearance stream ("N" for normal, "R" for roll-over or "D" for down). Defaults to "N".
:param string | null state: The annotation state to set the appearance for or null for the current state. Only widget annotations of pushbutton, check box, or radio button type have states, which are "Off" or "Yes". For other types of annotations pass null.
:param Matrix transform: The transformation matrix.
:param Rect bbox: The bounding box.,
:param PDFObject resources: Resources object.
:param Buffer | ArrayBuffer | Uint8Array | string contents: Contents string.
.. code-block::
annotation.setAppearance(
"N",
null,
mupdf.Matrix.identity,
[0, 0, 100, 100],
resources,
contents
)
.. method:: PDFAnnotation.prototype.update()
Update the appearance stream to account for changes in the annotation.
Returns true if the annotation appearance changed during the call.
:returns: boolean
.. code-block::
annotation.update()
.. method:: PDFAnnotation.prototype.setAppearanceFromDisplayList(appearance, state, transform, list)
Set the annotation appearance stream for the given appearance. The
desired appearance is given as a transform along with a display list.
:param string appearance: Appearance stream ("N", "R" or "D").
:param string state: The annotation state to set the appearance for or null for the current state. Only widget annotations of pushbutton, check box, or radio button type have states, which are "Off" or "Yes". For other types of annotations pass null.
:param Matrix transform: The transformation matrix.
:param DisplayList list: The display list.
.. code-block::
annotation.setAppearanceFromDisplayList(
"N",
null,
mupdf.Matrix.identity,
displayList
)
.. method:: PDFAnnotation.prototype.getHiddenForEditing()
Get a special annotation hidden flag for editing. This flag prevents the annotation from being rendered.
:returns: boolean
.. code-block::
var hidden = annotation.getHiddenForEditing()
.. method:: PDFAnnotation.prototype.setHiddenForEditing(hidden)
Set a special annotation hidden flag for editing. This flag prevents the annotation from being rendered.
:param boolean hidden:
.. code-block::
annotation.setHiddenForEditing(true)
.. method:: PDFAnnotation.prototype.getHot()
|only_mutool|
Check if the annotation is hot, i.e. that the pointing device's cursor
is hovering over the annotation.
:returns: boolean
.. code-block::
annotation.getHot()
.. method:: PDFAnnotation.prototype.setHot(hot)
|only_mutool|
Set the annotation as being hot, i.e. that the pointing device's cursor
is hovering over the annotation.
:param boolean hot:
.. code-block::
annotation.setHot(true)
.. method:: PDFAnnotation.prototype.requestSynthesis()
|only_mutool|
Request that if an annotation does not have an appearance stream, flag
the annotation to have one generated. The appearance stream
will be created during future calls to
`PDFAnnotation.prototype.update()` on or
`PDFPage.prototype.update()`.
.. code-block::
annotation.requestSynthesis()
.. method:: PDFAnnotation.prototype.requestResynthesis()
|only_mutool|
Request that an appearance stream shall be re-generated for an
annotation next time update() is called on
`PDFAnnotation.prototype.update()` or
`PDFPage.prototype.update()`.
This is a side-effect of setting annotation attributes through
the PDFAnnotation interface, so normally this call does not
need to be done explicitly.
.. code-block::
annotation.requestResynthesis()
.. method:: PDFAnnotation.prototype.process(processor)
|only_mutool|
Run through the annotation appearance stream and call methods
on the supplied `PDFProcessor`.
:param PDFProcessor processor: User defined function.
.. code-block::
annotation.process(processor)
.. method:: PDFAnnotation.prototype.applyRedaction(blackBoxes, imageMethod, lineArtMethod, textMethod)
Applies a single Redaction annotation.
See `PDFPage.prototype.applyRedactions` for details.
Annotation attributes
=====================
PDF Annotations have many attributes. Some of these are common to all
annotations, and some only exist on specific annotation types.
Common
-------------
.. method:: PDFAnnotation.prototype.getType()
Return the :term:`annotation type` for this annotation.
:returns: string
.. code-block::
var type = annotation.getType()
.. method:: PDFAnnotation.prototype.getFlags()
Get the annotation flags.
See `PDFAnnotation.prototype.setFlags`.
:returns: number
.. code-block::
var flags = annotation.getFlags()
.. method:: PDFAnnotation.prototype.setFlags(flags)
Set the annotation flags.
:param number flags: A bit mask with the flags (see below).
.. table::
:align: left
======= ====================
Bit Name
======= ====================
1 Invisible
2 Hidden
3 Print
4 NoZoom
5 NoRotate
6 NoView
7 ReadOnly
8 Locked
9 ToggleNoView
10 LockedContents
======= ====================
.. code-block::
annotation.setFlags(4) // Clears all other flags and sets "NoZoom".
.. method:: PDFAnnotation.prototype.getContents()
Get the annotation contents.
:returns: string
.. code-block::
var contents = annotation.getContents()
.. method:: PDFAnnotation.prototype.setContents(text)
Set the annotation contents.
:param string text:
.. code-block::
annotation.setContents("Hello World")
.. method:: PDFAnnotation.prototype.getCreationDate()
Get the annotation creation date as a Date object.
:returns: Date
.. code-block::
var date = annotation.getCreationDate()
.. method:: PDFAnnotation.prototype.setCreationDate(date)
Set the creation date.
:param Date date: A Date object.
.. code-block::
annotation.setCreationDate(new Date())
.. method:: PDFAnnotation.prototype.getModificationDate()
Get the annotation modification date as a Date object.
:returns: Date
.. code-block::
var date = annotation.getModificationDate()
.. method:: PDFAnnotation.prototype.setModificationDate(date)
Set the modification date.
:param Date date:
.. code-block::
annotation.setModificationDate(new Date())
.. method:: PDFAnnotation.prototype.getLanguage()
Get the annotation :term:`language code` (or get the one
inherited from the document).
:returns: string | null
.. code-block::
var language = annotation.getLanguage()
.. method:: PDFAnnotation.prototype.setLanguage(language)
Set the annotation :term:`language code`.
:param string language: The desired language code.
.. code-block::
annotation.setLanguage("en")
.. _rect-attribute:
Rect
----
For annotations that can be resized by setting its bounding box rectangle
(e.g. Square and FreeText), `PDFAnnotation.prototype.hasRect()` returns ``true``.
Other annotation types, (e.g. Line, Polygon, and InkList)
change size by adding/removing vertices.
Yet other annotations (e.g. Highlight and StrikeOut)
change size by adding/removing QuadPoints.
The underlying Rect attribute on the PDF object is automatically updated as needed
for these other annotation types.
.. method:: PDFAnnotation.prototype.hasRect()
Checks whether the annotation can be resized by setting its
bounding box.
:returns: boolean
.. code-block::
var hasRect = annotation.hasRect()
.. method:: PDFAnnotation.prototype.getRect()
Get the annotation bounding box.
:returns: `Rect`
.. code-block::
var rect = annotation.getRect()
.. method:: PDFAnnotation.prototype.setRect(rect)
Set the annotation bounding box.
:param Rect rect: The new desired bounding box.
.. code-block::
annotation.setRect([0, 0, 100, 100])
.. _rich-contents-attribute:
Rich contents
-------------
.. method:: PDFAnnotation.prototype.hasRichContents()
Returns whether the annotation is capable of supporting rich text
contents.
:returns: boolean
.. code-block::
var hasRichContents = annotation.hasRichContents()
.. method:: PDFAnnotation.prototype.getRichContents()
Obtain the annotation's rich-text contents, as opposed to the plain
text contents obtained by `getContents()`.
:returns: string
.. code-block::
var richContents = annotation.getRichContents()
.. method:: PDFAnnotation.prototype.setRichContents(plainText, richText)
Set the annotation's rich-text contents, as opposed to the plain
text contents set by `setContents()`.
:param string plainText:
:param string richText:
.. code-block::
annotation.setRichContents("plain text", "<b><i>Rich-Text</i></b>")
.. method:: PDFAnnotation.prototype.getRichDefaults()
Get the default style used for the annotation's rich-text contents.
:returns: string
.. code-block::
var richDefaults = annotation.getRichDefaults()
.. method:: PDFAnnotation.prototype.setRichDefaults(style)
Set the default style used for the annotation's rich-text contents.
:param string style:
.. code-block::
annotation.setRichDefaults("font-size: 16pt")
.. _color-attribute:
Color
-----
The meaning of the color attribute depends on the annotation type. For some it is the color
of the border.
.. method:: PDFAnnotation.prototype.getColor()
Get the annotation color, represented as an array of 0, 1, 3, or 4 component values.
:returns: `Color`
.. code-block::
var color = annotation.getColor()
.. method:: PDFAnnotation.prototype.setColor(color)
Set the annotation color, represented as an array of 0, 1, 3, or 4 component values.
:param Color color: The new color.
:throws: TypeError if number of components is not 0, 1, 3, or 4.
.. code-block::
annotation.setColor([0, 1, 0])
.. _opacity-attribute:
Opacity
-------
.. method:: PDFAnnotation.prototype.getOpacity()
Get the annotation :term:`opacity`.
:returns: number
.. code-block::
var opacity = annotation.getOpacity()
.. method:: PDFAnnotation.prototype.setOpacity(opacity)
Set the annotation :term:`opacity`.
:param number opacity: The desired opacity.
.. code-block::
annotation.setOpacity(0.5)
.. _quadding-attribute:
Quadding
--------
.. method:: PDFAnnotation.prototype.hasQuadding()
|only_mutool|
Returns whether the annotation is capable of supporting
quadding (justification).
:returns: boolean
.. code-block::
var hasQuadding = annotation.hasQuadding()
.. method:: PDFAnnotation.prototype.getQuadding()
Get the annotation quadding (justification). Quadding value, 0
for left-justified, 1 for centered, 2 for right-justified
:returns: number
.. code-block::
var quadding = annotation.getQuadding()
.. method:: PDFAnnotation.prototype.setQuadding(value)
Set the annotation quadding (justification). Quadding value, 0
for left-justified, 1 for centered, 2 for right-justified.
:param number value: The desired quadding.
.. code-block::
annotation.setQuadding(1)
.. _author-attribute:
Author
------
.. method:: PDFAnnotation.prototype.hasAuthor()
Returns whether the annotation is capable of supporting an author.
:returns: boolean
.. code-block::
var hasAuthor = annotation.hasAuthor()
.. method:: PDFAnnotation.prototype.getAuthor()
Gets the annotation author.
:returns: string
.. code-block::
var author = annotation.getAuthor()
.. method:: PDFAnnotation.prototype.setAuthor(author)
Sets the annotation author.
:param string author:
.. code-block::
annotation.setAuthor("Jane Doe")
.. _border-attribute:
Border
------
.. method:: PDFAnnotation.prototype.hasBorder()
Returns whether the annotation is capable of supporting a border.
:returns: boolean
.. code-block::
var hasBorder = annotation.hasBorder()
.. method:: PDFAnnotation.prototype.getBorderStyle()
Get the annotation :term:`border style`.
:returns: string
.. code-block::
var borderStyle = annotation.getBorderStyle()
.. method:: PDFAnnotation.prototype.setBorderStyle(style)
Set the annotation :term:`border style`.
:param string style: The annotation style.
.. code-block::
annotation.setBorderStyle("Dashed")
.. method:: PDFAnnotation.prototype.getBorderWidth()
Get the border width in points.
:returns: number
.. code-block::
var w = annotation.getBorderWidth()
.. method:: PDFAnnotation.prototype.setBorderWidth(width)
Set the border width in points. Retains any existing border effects.
:param number width:
.. code-block::
annotation.setBorderWidth(1.5)
.. method:: PDFAnnotation.prototype.getBorderDashCount()
Returns the number of items in the border dash pattern.
:returns: number
.. code-block::
var dashCount = annotation.getBorderDashCount()
.. method:: PDFAnnotation.prototype.getBorderDashItem(idx)
Returns the length of dash pattern item idx.
:param number idx:
:returns: number
.. code-block::
var length = annotation.getBorderDashItem(0)
.. method:: PDFAnnotation.prototype.setBorderDashPattern(list)
Set the annotation border dash pattern to the given array of dash item lengths. The supplied array represents the respective line stroke and gap lengths, e.g. [1, 1] sets a small dash and small gap, [2, 1, 4, 1] would set a medium dash, a small gap, a longer dash and then another small gap.
:param Array of number dashPattern:
.. code-block::
annotation.setBorderDashPattern([2.0, 1.0, 4.0, 1.0])
.. method:: PDFAnnotation.prototype.clearBorderDash()
Clear the entire border dash pattern for an annotation.
.. code-block::
annotation.clearBorderDash()
.. method:: PDFAnnotation.prototype.addBorderDashItem(length)
Append an item (of the given length) to the end of the border dash pattern.
:param number length:
.. code-block::
annotation.addBorderDashItem(10.0)
.. method:: PDFAnnotation.prototype.hasBorderEffect()
Returns whether the annotation is capable of supporting a border
effect.
:returns: boolean
.. code-block::
var hasEffect = annotation.hasBorderEffect()
.. method:: PDFAnnotation.prototype.getBorderEffect()
Get the :term:`border effect`.
:returns: string
.. code-block::
var effect = annotation.getBorderEffect()
.. method:: PDFAnnotation.prototype.setBorderEffect(effect)
Set the :term:`border effect`.
:param string effect: The border effect.
.. code-block::
annotation.setBorderEffect("None")
.. method:: PDFAnnotation.prototype.getBorderEffectIntensity()
Get the annotation border effect intensity.
:returns: number
.. code-block::
var intensity = annotation.getBorderEffectIntensity()
.. method:: PDFAnnotation.prototype.setBorderEffectIntensity(intensity)
Set the annotation border effect intensity. Recommended values are between 0 and 2 inclusive.
:param number intensity: Border effect intensity.
.. code-block::
annotation.setBorderEffectIntensity(1.5)
.. _callout-attribute:
Callout
-------
Callouts are used with FreeText annotations and
allow for a graphical line to point to an area on a page.
.. image:: /images/callout-annot.png
:alt: Callout annotation
:width: 100%
.. method:: PDFAnnotation.prototype.hasCallout()
Returns whether the annotation is capable of supporting a callout.
:returns: boolean
.. method:: PDFAnnotation.prototype.setCalloutLine(line)
Takes an array of 2 or 3 `points <Point>`. Supply an empty array to
remove the callout line.
:param Array of Point points:
.. method:: PDFAnnotation.prototype.getCalloutLine()
Returns the array of points.
:returns: Array of `Point` | null
.. method:: PDFAnnotation.prototype.setCalloutPoint(p)
Takes a point where the callout should point to.
:param Point p:
.. method:: PDFAnnotation.prototype.getCalloutPoint()
Returns the callout point.
:returns: `Point`
.. method:: PDFAnnotation.prototype.setCalloutStyle(style)
Sets the :term:`line ending style` of the callout line.
:param string style:
.. method:: PDFAnnotation.prototype.getCalloutStyle()
Returns the callout style.
:returns: string
.. _default-appearance-attribute:
Default Appearance
------------------
.. method:: PDFAnnotation.prototype.hasDefaultAppearance()
|only_mutool|
Returns whether the annotation is capable of supporting a default
appearance.
:returns: boolean
.. code-block::
var hasRect = annotation.hasDefaultAppearance()
.. method:: PDFAnnotation.prototype.getDefaultAppearance()
Get the default text appearance used for free text annotations
as an object containing the font, size, and color.
:returns: ``{ font: string, size: number, color: Color }``
.. code-block::
var appearance = annotation.getDefaultAppearance()
console.log("DA font:", appearance.font, appearance.size)
console.log("DA color:", appearance.color)
.. method:: PDFAnnotation.prototype.setDefaultAppearance(font, size, color)
Set the default text appearance used for free text annotations.
:param string font: The desired default font: ``"Helv" | "TiRo" | "Cour"`` for Helvetica, Times Roman, and Courier respectively.
:param number size: The desired default font size.
:param Color color: The desired default font color.
.. code-block::
annotation.setDefaultAppearance("Helv", 16, [0, 0, 0])
.. _filespec-attribute:
Filespec
--------
.. method:: PDFAnnotation.prototype.hasFilespec()
Returns whether the annotation is capable of supporting a
:term:`file specification`.
:returns: boolean
.. code-block::
var hasFilespec = annotation.hasFilespec()
.. method:: PDFAnnotation.prototype.getFilespec()
Get the :term:`file specification` PDF object for the file attachment, or null if none set.
:returns: `PDFObject` | null
.. code-block::
var fs = annotation.getFilespec()
.. method:: PDFAnnotation.prototype.setFilespec(fs)
Set the :term:`file specification` PDF object for the file attachment.
:param `PDFObject` fs:
.. code-block::
annotation.setFilespec(fs)
.. _icon-attribute:
Icon
----
.. method:: PDFAnnotation.prototype.hasIcon()
Returns whether the annotation is capable of supporting an icon.
:returns: boolean
.. code-block::
var hasIcon = annotation.hasIcon()
.. method:: PDFAnnotation.prototype.getIcon()
Get the annotation :term:`icon name`, either a standard or custom name.
:returns: string
.. code-block::
var icon = annotation.getIcon()
.. method:: PDFAnnotation.prototype.setIcon(name)
Set the annotation :term:`icon name`.
Note that standard icon names can be used to resynthesize the annotation appearance, but custom names cannot.
:param string name: An :term:`icon name`.
.. code-block::
annotation.setIcon("Note")
.. _inklist-attribute:
Ink List
--------
Ink annotations consist of a number of strokes, each consisting of a sequence of vertices between which a smooth line will be drawn.
.. method:: PDFAnnotation.prototype.hasInkList()
Returns whether the annotation is capable of supporting an ink list.
:returns: boolean
.. code-block::
var hasInkList = annotation.hasInkList()
.. method:: PDFAnnotation.prototype.getInkList()
Get the annotation ink list, represented as an array of strokes.
Each stroke consists of an array of points.
:returns: Array of Array of `Point`
.. code-block::
var inkList = annotation.getInkList()
.. method:: PDFAnnotation.prototype.setInkList(inkList)
Set the annotation ink list, represented as an array of strokes.
Each stroke consists of an array of points.
:param Array of Array of Point inkList:
.. code-block::
// this draws a box with a cross in three strokes:
annotation.setInkList([
[
[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]
],
[
[10, 0], [0, 10]
],
[
[0, 0], [10, 10]
]
])
.. method:: PDFAnnotation.prototype.clearInkList()
Clear the list of ink strokes for the annotation.
.. code-block::
annotation.clearInkList()
.. method:: PDFAnnotation.prototype.addInkListStroke()
Add a new empty stroke to the ink annotation.
.. code-block::
annotation.addInkListStroke()
.. method:: PDFAnnotation.prototype.addInkListStrokeVertex(v)
Append a vertex to end of the last stroke in the ink annotation.
:param Point v:
.. code-block::
annotation.addInkListStrokeVertex([0, 0])
.. _interior-color-attribute:
Interior Color
--------------
.. method:: PDFAnnotation.prototype.hasInteriorColor()
Returns whether the annotation is capable of supporting an interior
color.
:returns: boolean
.. code-block::
var hasInteriorColor = annotation.hasInteriorColor()
.. method:: PDFAnnotation.prototype.getInteriorColor()
Get the annotation interior color, represented as an array of 0, 1, 3, or 4 component values.
:returns: `Color`
.. code-block::
var interiorColor = annotation.getInteriorColor()
.. method:: PDFAnnotation.prototype.setInteriorColor(color)
Sets the annotation interior color.
:param Color color: The new desired interior color.
:throws: TypeError if number of components is not 0, 1, 3, or 4.
.. code-block::
annotation.setInteriorColor([0, 1, 1])
.. _line-attribute:
Line
----
.. method:: PDFAnnotation.prototype.hasLine()
Returns whether the annotation is capable of supporting a line.
:returns: boolean
.. code-block::
var hasLine = annotation.hasLine()
.. method:: PDFAnnotation.prototype.getLine()
Get line end points, represented by an array of two points, each represented as an [x, y] array.
:returns: Array of `Point`
.. code-block::
var line = annotation.getLine()
.. method:: PDFAnnotation.prototype.setLine(a, b)
Set the two line end points, each represented as an [x, y] array.
:param Point a: The new point a.
:param Point b: The new point b.
.. code-block::
annotation.setLine([100, 100], [150, 175])
.. _line-ending-styles-attribute:
Line Ending Styles
------------------
.. method:: PDFAnnotation.prototype.hasLineEndingStyles()
Returns whether the annotation is capable of supporting
:term:`line ending style`.
:returns: boolean
.. code-block::
var hasLineEndingStyles = annotation.hasLineEndingStyles()
.. method:: PDFAnnotation.prototype.getLineEndingStyles()
Get the start and end :term:`line ending style` values for each end of the line annotation.
:returns: ``{ start: string, end: string }`` Returns an object with the key/value pairs
.. code-block::
var lineEndingStyles = annotation.getLineEndingStyles()
.. method:: PDFAnnotation.prototype.setLineEndingStyles(start, end)
Sets the :term:`line ending style` values for each end of the line annotation.
:param string start:
:param string end:
.. code-block::
annotation.setLineEndingStyles("Square", "OpenArrow")
.. _line-leaders-attribute:
Line Leaders
------------
In a PDF line leaders refer to two lines at the ends of the line annotation,
oriented perpendicular to the line itself. These are common in technical
drawings when illustrating distances.
.. image:: /images/leader-lines.png
:alt: Leader lines explained
:width: 100%
.. method:: PDFAnnotation.prototype.setLineLeader(v)
Sets the line leader length.
:param number v:
The length of leader lines that extend from each endpoint of
the line perpendicular to the line itself. A positive value
means that the leader lines appear in the direction that is
clockwise when traversing the line from its starting point to
its ending point a negative value indicates the opposite
direction.
Setting a value of 0 effectively removes the line leader.
.. method:: PDFAnnotation.prototype.getLineLeader()
Gets the line leader length.
:returns: number
.. method:: PDFAnnotation.prototype.setLineLeaderExtension(v)
Sets the line leader extension.
:param number v:
A non-negative number representing the length of leader line
extensions that extend from the line proper 180 degrees from
the leader lines.
Setting a value of 0 effectively removes the line leader extension.
.. method:: PDFAnnotation.prototype.getLineLeaderExtension()
Gets the line leader extension.
:returns: number
.. method:: PDFAnnotation.prototype.setLineLeaderOffset(v)
Sets the line leader offset.
:param number v:
A non-negative number representing the length of the leader
line offset, which is the amount of empty space between the
endpoints of the annotation and the beginning of the leader
lines.
Setting a value of 0 effectively removes the line leader offset.
.. method:: PDFAnnotation.prototype.getLineLeaderOffset()
Gets the line leader offset.
:returns: number
.. method:: PDFAnnotation.prototype.setLineCaption(on)
Sets whether line caption is enabled or not.
When line captions are enabled then calling the
`PDFAnnotation.prototype.setContents` on the line annotation will
render the contents onto the line as the caption text.
:param boolean on:
.. method:: PDFAnnotation.prototype.getLineCaption()
Returns whether the line caption is enabled or not.
:returns: boolean
.. method:: PDFAnnotation.prototype.setLineCaptionOffset(point)
Sets the line caption offset.
The x value of the offset point is the horizontal offset along the
annotation line from its midpoint, with a positive value indicating
offset to the right and a negative value indicating offset to the
left. The y value of the offset point is the vertical offset
perpendicular to the annotation line, with a positive value
indicating a shift up and a negative value indicating a shift down.
Setting a point of [0, 0] removes the caption offset.
.. image:: /images/offset-caption.png
:alt: Offset caption explained
:width: 100%
:param Point point: A point specifying the offset of the caption text from its normal position.
.. method:: PDFAnnotation.prototype.getLineCaptionOffset()
Returns the line caption offset as a point, [x, y].
:returns: `Point`
.. _open-attribute:
Open
----
Open refers to whether the annotation is display in an open state when the
page is loaded. A Text Note annotation is considered open if the user has
clicked on it to view its contents.
.. method:: PDFAnnotation.prototype.hasOpen()
Returns whether the annotation is capable of supporting annotation
open state.
:returns: boolean
.. code-block::
var hasOpen = annotation.hasOpen()
.. method:: PDFAnnotation.prototype.getIsOpen()
Get annotation open state.
:returns: boolean
.. code-block::
var isOpen = annotation.getIsOpen()
.. method:: PDFAnnotation.prototype.setIsOpen(state)
Set annotation open state.
:param boolean state:
.. code-block::
annotation.setIsOpen(true)
.. _popup-attribute:
Popup
-----
.. method:: PDFAnnotation.prototype.hasPopup()
|only_mutool|
Returns whether the annotation is capable of supporting a popup.
:returns: boolean
.. code-block::
var hasPopup = annotation.hasPopup()
.. method:: PDFAnnotation.prototype.getPopup()
Get annotation popup rectangle.
:returns: `Rect`
.. code-block::
var popupRect = annotation.getPopup()
.. method:: PDFAnnotation.prototype.setPopup(rect)
Set annotation popup rectangle.
:param Rect rect: The desired area where the popup should appear.
.. code-block::
annotation.setPopup([0, 0, 100, 100])
.. _quadpoints-attribute:
QuadPoints
----------
Text markup and redaction annotations consist of a set of
quadadrilaterals, or :term:`QuadPoints <QuadPoint>`.
These are used in e.g. Highlight
annotations to mark up several disjoint spans of text.
In Javascript QuadPoints are represented with `Quad` objects.
.. method:: PDFAnnotation.prototype.hasQuadPoints()
Returns whether the annotation is capable of supporting quadpoints.
:returns: boolean
.. code-block::
var hasQuadPoints = annotation.hasQuadPoints()
.. method:: PDFAnnotation.prototype.getQuadPoints()
Get the annotation's quadpoints, describing the areas affected by
text markup annotations and link annotations.
:returns: Array of `Quad`
.. code-block::
var quadPoints = annotation.getQuadPoints()
.. method:: PDFAnnotation.prototype.setQuadPoints(quadList)
Set the annotation quadpoints describing the areas affected by
text markup annotations and link annotations.
:param Array of Quad quadList: The quadpoints to set.
.. code-block::
// two quads, the first one wider than the second one
annotation.setQuadPoints([
[ 100, 100, 200, 100, 200, 150, 100, 150 ],
[ 125, 150, 175, 150, 175, 200, 125, 200 ]
])
.. method:: PDFAnnotation.prototype.clearQuadPoints()
Clear the list of quadpoints for the annotation.
.. code-block::
annotation.clearQuadPoints()
.. method:: PDFAnnotation.prototype.addQuadPoint(quad)
Append a single quadpoint to the annotation.
:param Quad quad: The quadpoint to add.
.. code-block::
annotation.addQuadPoint([1, 2, 3, 4, 5, 6, 7, 8])
.. _vertices-attribute:
Vertices
--------
Polygon and polyline annotations consist of a sequence of vertices with a straight line between them. Those can be controlled by:
.. method:: PDFAnnotation.prototype.hasVertices()
Returns whether the annotation is capable of supporting vertices.
:returns: boolean
.. code-block::
var hasVertices = annotation.hasVertices()
.. method:: PDFAnnotation.prototype.getVertices()
Get the annotation vertices, represented as an array of points.
:returns: Array of `Point`
.. code-block::
var vertices = annotation.getVertices()
.. method:: PDFAnnotation.prototype.setVertices(vertices)
Set the annotation vertices, represented as an array of points.
:param Array of Point vertices:
.. code-block::
annotation.setVertices([
[0, 0],
[10, 10],
[20, 20]
])
.. method:: PDFAnnotation.prototype.clearVertices()
Clear the list of vertices for the annotation.
.. code-block::
annotation.clearVertices()
.. method:: PDFAnnotation.prototype.addVertex(vertex)
Append a single vertex point to the annotation.
:param Point vertex:
.. code-block::
annotation.addVertex([0, 0])
.. _stamp-image-attribute:
Stamp image
-----------
.. method:: PDFAnnotation.prototype.getStampImageObject()
|only_mutool|
If the annotation is a stamp annotation and it consists of an
image, return the `PDFObject` representing that image.
:returns: `PDFObject` | null
.. code-block::
var pdfobj = annotation.getStampImageObject()
.. method:: PDFAnnotation.prototype.setStampImageObject(imgobj)
|only_mutool|
Create an appearance stream containing the image passed as
argument and set that as the normal appearance of the
annotation.
:param PDFObject imgobj: PDFObject corresponding to the desired image.
.. code-block::
annotation.setStampImageObject(imgobj)
.. method:: PDFAnnotation.prototype.setStampImage(img)
|only_mutool|
Add the image passed as argument to the document as a PDF
object, and pass a reference to that object to when setting the
normal appearance of the stamp annotation.
:param Image img: The image to become the stamp annotations appearance.
.. code-block::
annotation.setStampImage(img)
.. _intent-attribute:
Intent
------
.. method:: PDFAnnotation.prototype.hasIntent()
|only_mutool|
Returns whether the annotation is capable of supporting an intent.
:returns: boolean
.. code-block::
var hasIntent = annotation.hasIntent()
.. method:: PDFAnnotation.prototype.getIntent()
Get the annotation intent, one of the values below:
* "FreeTextCallout"
* "FreeTextTypeWriter"
* "LineArrow"
* "LineDimension"
* "PolyLineDimension"
* "PolygonCloud"
* "PolygonDimension"
* "StampImage"
* "StampSnapshot"
:returns: string
.. code-block::
var intent = annotation.getIntent()
.. method:: PDFAnnotation.prototype.setIntent(intent)
Set the annotation intent.
:param string intent: Intent value, see `getIntent()` for permissible values.
.. code-block::
annotation.setIntent("LineArrow")
Events
------
PDF annotations can have different appearances depending on whether
the pointing device's cursor is hovering over an annotation, or if the
pointing device's button is pressed.
PDF widgets, which is a type of annotation, may also have associated
Javascript functions that are executed when certain events occur.
Therefore it is important to tell an PDFAnnotation when the pointing
device's cursor enters/exits an annotation, when it's button is
clicked, or when an annotation gains/loses input focus.
.. method:: PDFAnnotation.prototype.eventEnter()
|only_mutool|
Trigger appearance changes and event handlers for
when the pointing device's cursor enters an
annotation's active area.
.. code-block::
annot.eventEnter()
.. method:: PDFAnnotation.prototype.eventExit()
|only_mutool|
Trigger appearance changes and event handlers for
when the pointing device's cursor exits an
annotation's active area.
.. code-block::
annot.eventExit()
.. method:: PDFAnnotation.prototype.eventDown()
|only_mutool|
Trigger appearance changes and event handlers for
when the pointing device's button is depressed within
an annotation's active area.
.. code-block::
widget.eventDown()
.. method:: PDFAnnotation.prototype.eventUp()
|only_mutool|
Trigger appearance changes and event handlers for
when the pointing device's button is released within
an annotation's active area.
.. code-block::
widget.eventUp()
.. method:: PDFAnnotation.prototype.eventFocus()
|only_mutool|
Trigger event handlers for when an annotation gains
input focus.
.. code-block::
widget.eventFocus()
.. method:: PDFAnnotation.prototype.eventBlur()
|only_mutool|
Trigger event handlers for when an annotation loses
input focus.
.. code-block::
widget.eventBlur()
|