constants.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. """Various constants, enums, and flags to aid readability."""
  2. from enum import Enum, IntFlag, auto, unique
  3. class StrEnum(str, Enum): # Once we are on Python 3.11+: enum.StrEnum
  4. def __str__(self) -> str:
  5. return str(self.value)
  6. class Core:
  7. """Keywords that don't quite belong anywhere else."""
  8. OUTLINES = "/Outlines"
  9. THREADS = "/Threads"
  10. PAGE = "/Page"
  11. PAGES = "/Pages"
  12. CATALOG = "/Catalog"
  13. class TrailerKeys:
  14. SIZE = "/Size"
  15. PREV = "/Prev"
  16. ROOT = "/Root"
  17. ENCRYPT = "/Encrypt"
  18. INFO = "/Info"
  19. ID = "/ID"
  20. class CatalogAttributes:
  21. NAMES = "/Names"
  22. DESTS = "/Dests"
  23. class EncryptionDictAttributes:
  24. """
  25. Additional encryption dictionary entries for the standard security handler.
  26. Table 3.19, Page 122.
  27. Table 21 of the 2.0 manual.
  28. """
  29. R = "/R" # number, required; revision of the standard security handler
  30. O = "/O" # 32-byte string, required # noqa: E741
  31. U = "/U" # 32-byte string, required
  32. P = "/P" # integer flag, required; permitted operations
  33. ENCRYPT_METADATA = "/EncryptMetadata" # boolean flag, optional
  34. class UserAccessPermissions(IntFlag):
  35. """
  36. Table 3.20 User access permissions.
  37. Table 22 of the 2.0 manual.
  38. """
  39. R1 = 1
  40. R2 = 2
  41. PRINT = 4
  42. MODIFY = 8
  43. EXTRACT = 16
  44. ADD_OR_MODIFY = 32
  45. R7 = 64
  46. R8 = 128
  47. FILL_FORM_FIELDS = 256
  48. EXTRACT_TEXT_AND_GRAPHICS = 512
  49. ASSEMBLE_DOC = 1024
  50. PRINT_TO_REPRESENTATION = 2048
  51. R13 = 2**12
  52. R14 = 2**13
  53. R15 = 2**14
  54. R16 = 2**15
  55. R17 = 2**16
  56. R18 = 2**17
  57. R19 = 2**18
  58. R20 = 2**19
  59. R21 = 2**20
  60. R22 = 2**21
  61. R23 = 2**22
  62. R24 = 2**23
  63. R25 = 2**24
  64. R26 = 2**25
  65. R27 = 2**26
  66. R28 = 2**27
  67. R29 = 2**28
  68. R30 = 2**29
  69. R31 = 2**30
  70. R32 = 2**31
  71. @classmethod
  72. def _is_reserved(cls, name: str) -> bool:
  73. """Check if the given name corresponds to a reserved flag entry."""
  74. return name.startswith("R") and name[1:].isdigit()
  75. @classmethod
  76. def _is_active(cls, name: str) -> bool:
  77. """Check if the given reserved name defaults to 1 = active."""
  78. return name not in {"R1", "R2"}
  79. def to_dict(self) -> dict[str, bool]:
  80. """Convert the given flag value to a corresponding verbose name mapping."""
  81. result: dict[str, bool] = {}
  82. for name, flag in UserAccessPermissions.__members__.items():
  83. if UserAccessPermissions._is_reserved(name):
  84. continue
  85. result[name.lower()] = (self & flag) == flag
  86. return result
  87. @classmethod
  88. def from_dict(cls, value: dict[str, bool]) -> "UserAccessPermissions":
  89. """Convert the verbose name mapping to the corresponding flag value."""
  90. value_copy = value.copy()
  91. result = cls(0)
  92. for name, flag in cls.__members__.items():
  93. if cls._is_reserved(name):
  94. # Reserved names have a required value. Use it.
  95. if cls._is_active(name):
  96. result |= flag
  97. continue
  98. is_active = value_copy.pop(name.lower(), False)
  99. if is_active:
  100. result |= flag
  101. if value_copy:
  102. raise ValueError(f"Unknown dictionary keys: {value_copy!r}")
  103. return result
  104. @classmethod
  105. def all(cls) -> "UserAccessPermissions":
  106. return cls((2**32 - 1) - cls.R1 - cls.R2)
  107. class Resources:
  108. """
  109. Table 3.30 Entries in a resource dictionary.
  110. Table 34 in the 2.0 reference.
  111. """
  112. EXT_G_STATE = "/ExtGState" # dictionary, optional
  113. COLOR_SPACE = "/ColorSpace" # dictionary, optional
  114. PATTERN = "/Pattern" # dictionary, optional
  115. SHADING = "/Shading" # dictionary, optional
  116. XOBJECT = "/XObject" # dictionary, optional
  117. FONT = "/Font" # dictionary, optional
  118. PROC_SET = "/ProcSet" # array, optional
  119. PROPERTIES = "/Properties" # dictionary, optional
  120. class PagesAttributes:
  121. """§7.7.3.2 of the 1.7 and 2.0 reference."""
  122. TYPE = "/Type" # name, required; must be /Pages
  123. PARENT = "/Parent" # dictionary, required; indirect reference to pages object
  124. KIDS = "/Kids" # array, required; List of indirect references
  125. COUNT = "/Count"
  126. # integer, required; the number of leaf nodes (page objects)
  127. # that are descendants of this node within the page tree
  128. class PageAttributes:
  129. """§7.7.3.3 of the 1.7 and 2.0 reference."""
  130. TYPE = "/Type" # name, required; must be /Page
  131. PARENT = "/Parent" # dictionary, required; a pages object
  132. LAST_MODIFIED = (
  133. "/LastModified" # date, optional; date and time of last modification
  134. )
  135. RESOURCES = "/Resources" # dictionary, required if there are any
  136. MEDIABOX = "/MediaBox" # rectangle, required; rectangle specifying page size
  137. CROPBOX = "/CropBox" # rectangle, optional
  138. BLEEDBOX = "/BleedBox" # rectangle, optional
  139. TRIMBOX = "/TrimBox" # rectangle, optional
  140. ARTBOX = "/ArtBox" # rectangle, optional
  141. BOX_COLOR_INFO = "/BoxColorInfo" # dictionary, optional
  142. CONTENTS = "/Contents" # stream or array, optional
  143. ROTATE = "/Rotate" # integer, optional; page rotation in degrees
  144. GROUP = "/Group" # dictionary, optional; page group
  145. THUMB = "/Thumb" # stream, optional; indirect reference to image of the page
  146. B = "/B" # array, optional
  147. DUR = "/Dur" # number, optional
  148. TRANS = "/Trans" # dictionary, optional
  149. ANNOTS = "/Annots" # array, optional; an array of annotations
  150. AA = "/AA" # dictionary, optional
  151. METADATA = "/Metadata" # stream, optional
  152. PIECE_INFO = "/PieceInfo" # dictionary, optional
  153. STRUCT_PARENTS = "/StructParents" # integer, optional
  154. ID = "/ID" # byte string, optional
  155. PZ = "/PZ" # number, optional
  156. SEPARATION_INFO = "/SeparationInfo" # dictionary, optional
  157. TABS = "/Tabs" # name, optional
  158. TEMPLATE_INSTANTIATED = "/TemplateInstantiated" # name, optional
  159. PRES_STEPS = "/PresSteps" # dictionary, optional
  160. USER_UNIT = "/UserUnit" # number, optional
  161. VP = "/VP" # dictionary, optional
  162. AF = "/AF" # array of dictionaries, optional
  163. OUTPUT_INTENTS = "/OutputIntents" # array, optional
  164. D_PART = "/DPart" # dictionary, required, if this page is within the range of a DPart, not permitted otherwise
  165. class FileSpecificationDictionaryEntries:
  166. """Table 3.41 Entries in a file specification dictionary."""
  167. Type = "/Type"
  168. FS = "/FS" # The name of the file system to be used to interpret this file specification
  169. F = "/F" # A file specification string of the form described in §3.10.1
  170. UF = "/UF" # A Unicode string of the file as described in §3.10.1
  171. DOS = "/DOS"
  172. Mac = "/Mac"
  173. Unix = "/Unix"
  174. ID = "/ID"
  175. V = "/V"
  176. EF = "/EF" # dictionary, containing a subset of the keys F, UF, DOS, Mac, and Unix
  177. RF = "/RF" # dictionary, containing arrays of /EmbeddedFile
  178. DESC = "/Desc" # description of the file
  179. Cl = "/Cl"
  180. class StreamAttributes:
  181. """
  182. Table 4.2.
  183. Table 5 in the 2.0 reference.
  184. """
  185. LENGTH = "/Length" # integer, required
  186. FILTER = "/Filter" # name or array of names, optional
  187. DECODE_PARMS = "/DecodeParms" # variable, optional -- 'decodeParams is wrong
  188. @unique
  189. class FilterTypes(StrEnum):
  190. """§7.4 of the 1.7 and 2.0 references."""
  191. ASCII_HEX_DECODE = "/ASCIIHexDecode" # abbreviation: AHx
  192. ASCII_85_DECODE = "/ASCII85Decode" # abbreviation: A85
  193. LZW_DECODE = "/LZWDecode" # abbreviation: LZW
  194. FLATE_DECODE = "/FlateDecode" # abbreviation: Fl
  195. RUN_LENGTH_DECODE = "/RunLengthDecode" # abbreviation: RL
  196. CCITT_FAX_DECODE = "/CCITTFaxDecode" # abbreviation: CCF
  197. DCT_DECODE = "/DCTDecode" # abbreviation: DCT
  198. JPX_DECODE = "/JPXDecode"
  199. JBIG2_DECODE = "/JBIG2Decode"
  200. class FilterTypeAbbreviations:
  201. """§8.9.7 of the 1.7 and 2.0 references."""
  202. AHx = "/AHx"
  203. A85 = "/A85"
  204. LZW = "/LZW"
  205. FL = "/Fl"
  206. RL = "/RL"
  207. CCF = "/CCF"
  208. DCT = "/DCT"
  209. class LzwFilterParameters:
  210. """
  211. Table 4.4.
  212. Table 8 in the 2.0 reference.
  213. """
  214. PREDICTOR = "/Predictor" # integer
  215. COLORS = "/Colors" # integer
  216. BITS_PER_COMPONENT = "/BitsPerComponent" # integer
  217. COLUMNS = "/Columns" # integer
  218. EARLY_CHANGE = "/EarlyChange" # integer
  219. class CcittFaxDecodeParameters:
  220. """
  221. Table 4.5.
  222. Table 11 in the 2.0 reference.
  223. """
  224. K = "/K" # integer
  225. END_OF_LINE = "/EndOfLine" # boolean
  226. ENCODED_BYTE_ALIGN = "/EncodedByteAlign" # boolean
  227. COLUMNS = "/Columns" # integer
  228. ROWS = "/Rows" # integer
  229. END_OF_BLOCK = "/EndOfBlock" # boolean
  230. BLACK_IS_1 = "/BlackIs1" # boolean
  231. DAMAGED_ROWS_BEFORE_ERROR = "/DamagedRowsBeforeError" # integer
  232. class ImageAttributes:
  233. """§11.6.5 of the 1.7 and 2.0 references."""
  234. TYPE = "/Type" # name, required; must be /XObject
  235. SUBTYPE = "/Subtype" # name, required; must be /Image
  236. NAME = "/Name" # name, required
  237. WIDTH = "/Width" # integer, required
  238. HEIGHT = "/Height" # integer, required
  239. BITS_PER_COMPONENT = "/BitsPerComponent" # integer, required
  240. COLOR_SPACE = "/ColorSpace" # name, required
  241. DECODE = "/Decode" # array, optional
  242. INTENT = "/Intent" # string, optional
  243. INTERPOLATE = "/Interpolate" # boolean, optional
  244. IMAGE_MASK = "/ImageMask" # boolean, optional
  245. MASK = "/Mask" # 1-bit image mask stream
  246. S_MASK = "/SMask" # dictionary or name, optional
  247. class ColorSpaces:
  248. DEVICE_RGB = "/DeviceRGB"
  249. DEVICE_CMYK = "/DeviceCMYK"
  250. DEVICE_GRAY = "/DeviceGray"
  251. class TypArguments:
  252. """Table 8.2 of the PDF 1.7 reference."""
  253. LEFT = "/Left"
  254. RIGHT = "/Right"
  255. BOTTOM = "/Bottom"
  256. TOP = "/Top"
  257. class TypFitArguments:
  258. """Table 8.2 of the PDF 1.7 reference."""
  259. XYZ = "/XYZ"
  260. FIT = "/Fit"
  261. FIT_H = "/FitH"
  262. FIT_V = "/FitV"
  263. FIT_R = "/FitR"
  264. FIT_B = "/FitB"
  265. FIT_BH = "/FitBH"
  266. FIT_BV = "/FitBV"
  267. class GoToActionArguments:
  268. S = "/S" # name, required: type of action
  269. D = "/D" # name, byte string, or array, required: destination to jump to
  270. SD = "/SD" # array, optional: structure destination to jump to
  271. class AnnotationDictionaryAttributes:
  272. """Table 8.15 Entries common to all annotation dictionaries."""
  273. Type = "/Type"
  274. Subtype = "/Subtype"
  275. Rect = "/Rect"
  276. Contents = "/Contents"
  277. P = "/P"
  278. NM = "/NM"
  279. M = "/M"
  280. F = "/F"
  281. AP = "/AP"
  282. AS = "/AS"
  283. DA = "/DA"
  284. Border = "/Border"
  285. C = "/C"
  286. StructParent = "/StructParent"
  287. OC = "/OC"
  288. class InteractiveFormDictEntries:
  289. Fields = "/Fields"
  290. NeedAppearances = "/NeedAppearances"
  291. SigFlags = "/SigFlags"
  292. CO = "/CO"
  293. DR = "/DR"
  294. DA = "/DA"
  295. Q = "/Q"
  296. XFA = "/XFA"
  297. class FieldDictionaryAttributes:
  298. """
  299. Entries common to all field dictionaries (Table 8.69 PDF 1.7 reference)
  300. (*very partially documented here*).
  301. FFBits provides the constants used for `/Ff` from Table 8.70/8.75/8.77/8.79
  302. """
  303. FT = "/FT" # name, required for terminal fields
  304. Parent = "/Parent" # dictionary, required for children
  305. Kids = "/Kids" # array, sometimes required
  306. T = "/T" # text string, optional
  307. TU = "/TU" # text string, optional
  308. TM = "/TM" # text string, optional
  309. Ff = "/Ff" # integer, optional
  310. V = "/V" # text string or array, optional
  311. DV = "/DV" # text string, optional
  312. AA = "/AA" # dictionary, optional
  313. Opt = "/Opt" # array, optional
  314. class FfBits(IntFlag):
  315. """
  316. Ease building /Ff flags
  317. Some entries may be specific to:
  318. * Text (Tx) (Table 8.75 PDF 1.7 reference)
  319. * Buttons (Btn) (Table 8.77 PDF 1.7 reference)
  320. * Choice (Ch) (Table 8.79 PDF 1.7 reference)
  321. """
  322. ReadOnly = 1 << 0
  323. """common to Tx/Btn/Ch in Table 8.70"""
  324. Required = 1 << 1
  325. """common to Tx/Btn/Ch in Table 8.70"""
  326. NoExport = 1 << 2
  327. """common to Tx/Btn/Ch in Table 8.70"""
  328. Multiline = 1 << 12
  329. """Tx"""
  330. Password = 1 << 13
  331. """Tx"""
  332. NoToggleToOff = 1 << 14
  333. """Btn"""
  334. Radio = 1 << 15
  335. """Btn"""
  336. Pushbutton = 1 << 16
  337. """Btn"""
  338. Combo = 1 << 17
  339. """Ch"""
  340. Edit = 1 << 18
  341. """Ch"""
  342. Sort = 1 << 19
  343. """Ch"""
  344. FileSelect = 1 << 20
  345. """Tx"""
  346. MultiSelect = 1 << 21
  347. """Tx"""
  348. DoNotSpellCheck = 1 << 22
  349. """Tx/Ch"""
  350. DoNotScroll = 1 << 23
  351. """Tx"""
  352. Comb = 1 << 24
  353. """Tx"""
  354. RadiosInUnison = 1 << 25
  355. """Btn"""
  356. RichText = 1 << 25
  357. """Tx"""
  358. CommitOnSelChange = 1 << 26
  359. """Ch"""
  360. @classmethod
  361. def attributes(cls) -> tuple[str, ...]:
  362. """
  363. Get a tuple of all the attributes present in a Field Dictionary.
  364. This method returns a tuple of all the attribute constants defined in
  365. the FieldDictionaryAttributes class. These attributes correspond to the
  366. entries that are common to all field dictionaries as specified in the
  367. PDF 1.7 reference.
  368. Returns:
  369. A tuple containing all the attribute constants.
  370. """
  371. return (
  372. cls.TM,
  373. cls.T,
  374. cls.FT,
  375. cls.Parent,
  376. cls.TU,
  377. cls.Ff,
  378. cls.V,
  379. cls.DV,
  380. cls.Kids,
  381. cls.AA,
  382. )
  383. @classmethod
  384. def attributes_dict(cls) -> dict[str, str]:
  385. """
  386. Get a dictionary of attribute keys and their human-readable names.
  387. This method returns a dictionary where the keys are the attribute
  388. constants defined in the FieldDictionaryAttributes class and the values
  389. are their corresponding human-readable names. These attributes
  390. correspond to the entries that are common to all field dictionaries as
  391. specified in the PDF 1.7 reference.
  392. Returns:
  393. A dictionary containing attribute keys and their names.
  394. """
  395. return {
  396. cls.FT: "Field Type",
  397. cls.Parent: "Parent",
  398. cls.T: "Field Name",
  399. cls.TU: "Alternate Field Name",
  400. cls.TM: "Mapping Name",
  401. cls.Ff: "Field Flags",
  402. cls.V: "Value",
  403. cls.DV: "Default Value",
  404. }
  405. class CheckboxRadioButtonAttributes:
  406. """Table 8.76 Field flags common to all field types."""
  407. Opt = "/Opt" # Options, Optional
  408. @classmethod
  409. def attributes(cls) -> tuple[str, ...]:
  410. """
  411. Get a tuple of all the attributes present in a Field Dictionary.
  412. This method returns a tuple of all the attribute constants defined in
  413. the CheckboxRadioButtonAttributes class. These attributes correspond to
  414. the entries that are common to all field dictionaries as specified in
  415. the PDF 1.7 reference.
  416. Returns:
  417. A tuple containing all the attribute constants.
  418. """
  419. return (cls.Opt,)
  420. @classmethod
  421. def attributes_dict(cls) -> dict[str, str]:
  422. """
  423. Get a dictionary of attribute keys and their human-readable names.
  424. This method returns a dictionary where the keys are the attribute
  425. constants defined in the CheckboxRadioButtonAttributes class and the
  426. values are their corresponding human-readable names. These attributes
  427. correspond to the entries that are common to all field dictionaries as
  428. specified in the PDF 1.7 reference.
  429. Returns:
  430. A dictionary containing attribute keys and their names.
  431. """
  432. return {
  433. cls.Opt: "Options",
  434. }
  435. class FieldFlag(IntFlag):
  436. """Table 8.70 Field flags common to all field types."""
  437. READ_ONLY = 1
  438. REQUIRED = 2
  439. NO_EXPORT = 4
  440. class DocumentInformationAttributes:
  441. """Table 10.2 Entries in the document information dictionary."""
  442. TITLE = "/Title" # text string, optional
  443. AUTHOR = "/Author" # text string, optional
  444. SUBJECT = "/Subject" # text string, optional
  445. KEYWORDS = "/Keywords" # text string, optional
  446. CREATOR = "/Creator" # text string, optional
  447. PRODUCER = "/Producer" # text string, optional
  448. CREATION_DATE = "/CreationDate" # date, optional
  449. MOD_DATE = "/ModDate" # date, optional
  450. TRAPPED = "/Trapped" # name, optional
  451. class PageLayouts:
  452. """
  453. Page 84, PDF 1.4 reference.
  454. Page 115, PDF 2.0 reference.
  455. """
  456. SINGLE_PAGE = "/SinglePage"
  457. ONE_COLUMN = "/OneColumn"
  458. TWO_COLUMN_LEFT = "/TwoColumnLeft"
  459. TWO_COLUMN_RIGHT = "/TwoColumnRight"
  460. TWO_PAGE_LEFT = "/TwoPageLeft" # (PDF 1.5)
  461. TWO_PAGE_RIGHT = "/TwoPageRight" # (PDF 1.5)
  462. class GraphicsStateParameters:
  463. """Table 58 – Entries in a Graphics State Parameter Dictionary"""
  464. TYPE = "/Type" # name, optional
  465. LW = "/LW" # number, optional
  466. LC = "/LC" # integer, optional
  467. LJ = "/LJ" # integer, optional
  468. ML = "/ML" # number, optional
  469. D = "/D" # array, optional
  470. RI = "/RI" # name, optional
  471. OP = "/OP"
  472. op = "/op"
  473. OPM = "/OPM"
  474. FONT = "/Font" # array, optional
  475. BG = "/BG"
  476. BG2 = "/BG2"
  477. UCR = "/UCR"
  478. UCR2 = "/UCR2"
  479. TR = "/TR"
  480. TR2 = "/TR2"
  481. HT = "/HT"
  482. FL = "/FL"
  483. SM = "/SM"
  484. SA = "/SA"
  485. BM = "/BM"
  486. S_MASK = "/SMask" # dictionary or name, optional
  487. CA = "/CA"
  488. ca = "/ca"
  489. AIS = "/AIS"
  490. TK = "/TK"
  491. class CatalogDictionary:
  492. """§7.7.2 of the 1.7 and 2.0 references."""
  493. TYPE = "/Type" # name, required; must be /Catalog
  494. VERSION = "/Version" # name
  495. EXTENSIONS = "/Extensions" # dictionary, optional; ISO 32000-1
  496. PAGES = "/Pages" # dictionary, required
  497. PAGE_LABELS = "/PageLabels" # number tree, optional
  498. NAMES = "/Names" # dictionary, optional
  499. DESTS = "/Dests" # dictionary, optional
  500. VIEWER_PREFERENCES = "/ViewerPreferences" # dictionary, optional
  501. PAGE_LAYOUT = "/PageLayout" # name, optional
  502. PAGE_MODE = "/PageMode" # name, optional
  503. OUTLINES = "/Outlines" # dictionary, optional
  504. THREADS = "/Threads" # array, optional
  505. OPEN_ACTION = "/OpenAction" # array or dictionary or name, optional
  506. AA = "/AA" # dictionary, optional
  507. URI = "/URI" # dictionary, optional
  508. ACRO_FORM = "/AcroForm" # dictionary, optional
  509. METADATA = "/Metadata" # stream, optional
  510. STRUCT_TREE_ROOT = "/StructTreeRoot" # dictionary, optional
  511. MARK_INFO = "/MarkInfo" # dictionary, optional
  512. LANG = "/Lang" # text string, optional
  513. SPIDER_INFO = "/SpiderInfo" # dictionary, optional
  514. OUTPUT_INTENTS = "/OutputIntents" # array, optional
  515. PIECE_INFO = "/PieceInfo" # dictionary, optional
  516. OC_PROPERTIES = "/OCProperties" # dictionary, optional
  517. PERMS = "/Perms" # dictionary, optional
  518. LEGAL = "/Legal" # dictionary, optional
  519. REQUIREMENTS = "/Requirements" # array, optional
  520. COLLECTION = "/Collection" # dictionary, optional
  521. NEEDS_RENDERING = "/NeedsRendering" # boolean, optional
  522. DSS = "/DSS" # dictionary, optional
  523. AF = "/AF" # array of dictionaries, optional
  524. D_PART_ROOT = "/DPartRoot" # dictionary, optional
  525. class OutlineFontFlag(IntFlag):
  526. """A class used as an enumerable flag for formatting an outline font."""
  527. italic = 1
  528. bold = 2
  529. class PageLabelStyle:
  530. """
  531. Table 8.10 in the 1.7 reference.
  532. Table 161 in the 2.0 reference.
  533. """
  534. DECIMAL = "/D" # Decimal Arabic numerals
  535. UPPERCASE_ROMAN = "/R" # Uppercase Roman numerals
  536. LOWERCASE_ROMAN = "/r" # Lowercase Roman numerals
  537. UPPERCASE_LETTER = "/A" # Uppercase letters
  538. LOWERCASE_LETTER = "/a" # Lowercase letters
  539. class AnnotationFlag(IntFlag):
  540. """See §12.5.3 "Annotation Flags"."""
  541. INVISIBLE = 1
  542. HIDDEN = 2
  543. PRINT = 4
  544. NO_ZOOM = 8
  545. NO_ROTATE = 16
  546. NO_VIEW = 32
  547. READ_ONLY = 64
  548. LOCKED = 128
  549. TOGGLE_NO_VIEW = 256
  550. LOCKED_CONTENTS = 512
  551. PDF_KEYS = (
  552. AnnotationDictionaryAttributes,
  553. CatalogAttributes,
  554. CatalogDictionary,
  555. CcittFaxDecodeParameters,
  556. CheckboxRadioButtonAttributes,
  557. ColorSpaces,
  558. Core,
  559. DocumentInformationAttributes,
  560. EncryptionDictAttributes,
  561. FieldDictionaryAttributes,
  562. FileSpecificationDictionaryEntries,
  563. FilterTypeAbbreviations,
  564. FilterTypes,
  565. GoToActionArguments,
  566. GraphicsStateParameters,
  567. ImageAttributes,
  568. InteractiveFormDictEntries,
  569. LzwFilterParameters,
  570. PageAttributes,
  571. PageLayouts,
  572. PagesAttributes,
  573. Resources,
  574. StreamAttributes,
  575. TrailerKeys,
  576. TypArguments,
  577. TypFitArguments,
  578. )
  579. class ImageType(IntFlag):
  580. NONE = 0
  581. XOBJECT_IMAGES = auto()
  582. INLINE_IMAGES = auto()
  583. DRAWING_IMAGES = auto()
  584. ALL = XOBJECT_IMAGES | INLINE_IMAGES | DRAWING_IMAGES
  585. IMAGES = ALL # for consistency with ObjectDeletionFlag
  586. _INLINE_IMAGE_VALUE_MAPPING = {
  587. "/G": "/DeviceGray",
  588. "/RGB": "/DeviceRGB",
  589. "/CMYK": "/DeviceCMYK",
  590. "/I": "/Indexed",
  591. "/AHx": "/ASCIIHexDecode",
  592. "/A85": "/ASCII85Decode",
  593. "/LZW": "/LZWDecode",
  594. "/Fl": "/FlateDecode",
  595. "/RL": "/RunLengthDecode",
  596. "/CCF": "/CCITTFaxDecode",
  597. "/DCT": "/DCTDecode",
  598. "/DeviceGray": "/DeviceGray",
  599. "/DeviceRGB": "/DeviceRGB",
  600. "/DeviceCMYK": "/DeviceCMYK",
  601. "/Indexed": "/Indexed",
  602. "/ASCIIHexDecode": "/ASCIIHexDecode",
  603. "/ASCII85Decode": "/ASCII85Decode",
  604. "/LZWDecode": "/LZWDecode",
  605. "/FlateDecode": "/FlateDecode",
  606. "/RunLengthDecode": "/RunLengthDecode",
  607. "/CCITTFaxDecode": "/CCITTFaxDecode",
  608. "/DCTDecode": "/DCTDecode",
  609. "/RelativeColorimetric": "/RelativeColorimetric",
  610. }
  611. _INLINE_IMAGE_KEY_MAPPING = {
  612. "/BPC": "/BitsPerComponent",
  613. "/CS": "/ColorSpace",
  614. "/D": "/Decode",
  615. "/DP": "/DecodeParms",
  616. "/F": "/Filter",
  617. "/H": "/Height",
  618. "/W": "/Width",
  619. "/I": "/Interpolate",
  620. "/Intent": "/Intent",
  621. "/IM": "/ImageMask",
  622. "/BitsPerComponent": "/BitsPerComponent",
  623. "/ColorSpace": "/ColorSpace",
  624. "/Decode": "/Decode",
  625. "/DecodeParms": "/DecodeParms",
  626. "/Filter": "/Filter",
  627. "/Height": "/Height",
  628. "/Width": "/Width",
  629. "/Interpolate": "/Interpolate",
  630. "/ImageMask": "/ImageMask",
  631. }
  632. class AFRelationship:
  633. """
  634. Associated file relationship types, defining the relationship between
  635. the PDF component and the associated file.
  636. Defined in table 43 of the PDF 2.0 reference.
  637. """
  638. SOURCE = "/Source" # Original content source
  639. DATA = "/Data" # Base data for visual presentation
  640. ALTERNATIVE = "/Alternative" # Alternative content representation
  641. SUPPLEMENT = "/Supplement" # Supplemental representation of original source/data
  642. ENCRYPTED_PAYLOAD = "/EncryptedPayload" # Encrypted payload document
  643. FORM_DATA = "/FormData" # Data associated with AcroForm of this PDF
  644. SCHEMA = "/Schema" # Schema definition for associated object
  645. UNSPECIFIED = "/Unspecified" # Not known or cannot be described with values
  646. class BorderStyles:
  647. """
  648. A class defining border styles used in PDF documents.
  649. Defined in table 168 of the PDF 2.0 reference.
  650. """
  651. BEVELED = "/B"
  652. DASHED = "/D"
  653. INSET = "/I"
  654. SOLID = "/S"
  655. UNDERLINED = "/U"
  656. class FontFlags(IntFlag):
  657. """
  658. A class defining font flags in PDF document font descriptor resources.
  659. Defined in table 121 of the PDF 2.0 reference.
  660. """
  661. FIXED_PITCH = 1 << 0
  662. SERIF = 1 << 1
  663. SYMBOLIC = 1 << 2
  664. SCRIPT = 1 << 3
  665. NONSYMBOLIC = 1 << 5
  666. ITALIC = 1 << 6
  667. ALL_CAP = 1 << 16
  668. SMALL_CAP = 1 << 17
  669. FORCE_BOLD = 1 << 18