Skip to content

Commit

Permalink
DOC: Add some references to ISO 32000-2:2020 (PDF 2.0) (#2623)
Browse files Browse the repository at this point in the history
Add some references to ISO 32000-2:2020 (PDF 2.0)
Also reorder to match the PDF 2.0 table order.
Add fields to PageLayouts and CatalogDictionary.
  • Loading branch information
j-t-1 committed May 5, 2024
1 parent bcc8214 commit c73ad26
Showing 1 changed file with 70 additions and 27 deletions.
97 changes: 70 additions & 27 deletions pypdf/constants.py
Expand Up @@ -6,6 +6,8 @@
PDF Reference, third edition, Version 1.4, 2001. ISBN 0-201-75839-3.
PDF Reference, sixth edition, Version 1.7, 2006.
ISO 32000-2:2020 (PDF 2.0).
"""

from enum import IntFlag, auto
Expand Down Expand Up @@ -41,7 +43,8 @@ class EncryptionDictAttributes:
"""
Additional encryption dictionary entries for the standard security handler.
TABLE 3.19, Page 122
Table 3.19, Page 122.
Table 21 of the 2.0 manual.
"""

R = "/R" # number, required; revision of the standard security handler
Expand All @@ -52,7 +55,10 @@ class EncryptionDictAttributes:


class UserAccessPermissions(IntFlag):
"""TABLE 3.20 User access permissions."""
"""
Table 3.20 User access permissions.
Table 22 of the 2.0 manual.
"""

R1 = 1
R2 = 2
Expand Down Expand Up @@ -131,8 +137,10 @@ def all(cls) -> "UserAccessPermissions":

class Resources:
"""
TABLE 3.30 Entries in a resource dictionary.
Table 3.30 Entries in a resource dictionary.
used to be Ressources
Table 34 in the 2.0 reference.
"""

EXT_G_STATE = "/ExtGState" # dictionary, optional
Expand Down Expand Up @@ -202,16 +210,22 @@ def PROPERTIES(cls) -> str:


class PagesAttributes:
"""Page Attributes, Table 6.2, Page 52."""
"""
Page Attributes, Table 6.2, Page 52.
Page tree node, Table 30 in the 2.0 reference.
"""

TYPE = "/Type" # name, required; must be /Pages
PARENT = "/Parent" # dictionary, required; indirect reference to pages object
KIDS = "/Kids" # array, required; List of indirect references
COUNT = "/Count" # integer, required; the number of all nodes und this node
PARENT = "/Parent" # dictionary, required; indirect reference to pages object


class PageAttributes:
"""TABLE 3.27 Entries in a page object."""
"""
Table 3.27 Entries in a page object.
Table 31 in the 2.0 reference.
"""

TYPE = "/Type" # name, required; must be /Page
PARENT = "/Parent" # dictionary, required; a pages object
Expand Down Expand Up @@ -247,7 +261,7 @@ class PageAttributes:


class FileSpecificationDictionaryEntries:
"""TABLE 3.41 Entries in a file specification dictionary."""
"""Table 3.41 Entries in a file specification dictionary."""

Type = "/Type"
FS = "/FS" # The name of the file system to be used to interpret this file specification
Expand All @@ -265,7 +279,10 @@ class FileSpecificationDictionaryEntries:


class StreamAttributes:
"""Table 4.2."""
"""
Table 4.2.
Table 5 in the 2.0 reference.
"""

LENGTH = "/Length" # integer, required
FILTER = "/Filter" # name or array of names, optional
Expand All @@ -276,7 +293,9 @@ class FilterTypes:
"""
Table 4.3 of the 1.4 Manual.
Page 354 of the 1.7 Manual
Page 354 of the 1.7 Manual.
Table 6 of the 2.0 manual.
"""

ASCII_HEX_DECODE = "/ASCIIHexDecode" # abbreviation: AHx
Expand All @@ -290,7 +309,10 @@ class FilterTypes:


class FilterTypeAbbreviations:
"""Table 4.44 of the 1.7 Manual (page 353ff)."""
"""
Table 4.44 of the 1.7 Manual (page 353ff).
Table 92 of the 2.0 manual.
"""

AHx = "/AHx"
A85 = "/A85"
Expand All @@ -302,17 +324,23 @@ class FilterTypeAbbreviations:


class LzwFilterParameters:
"""Table 4.4."""
"""
Table 4.4.
Table 8 in the 2.0 reference.
"""

PREDICTOR = "/Predictor" # integer
COLUMNS = "/Columns" # integer
COLORS = "/Colors" # integer
BITS_PER_COMPONENT = "/BitsPerComponent" # integer
COLUMNS = "/Columns" # integer
EARLY_CHANGE = "/EarlyChange" # integer


class CcittFaxDecodeParameters:
"""Table 4.5."""
"""
Table 4.5.
Table 11 in the 2.0 reference.
"""

K = "/K" # integer
END_OF_LINE = "/EndOfLine" # boolean
Expand All @@ -325,7 +353,7 @@ class CcittFaxDecodeParameters:


class ImageAttributes:
"""Table 4.39 Pdf Reference 1.7 page 340+"""
"""Table 4.39 PDF Reference 1.7 page 340+"""

TYPE = "/Type" # name, required; must be /XObject
SUBTYPE = "/Subtype" # name, required; must be /Image
Expand Down Expand Up @@ -376,7 +404,7 @@ class GoToActionArguments:


class AnnotationDictionaryAttributes:
"""TABLE 8.15 Entries common to all annotation dictionaries."""
"""Table 8.15 Entries common to all annotation dictionaries."""

Type = "/Type"
Subtype = "/Subtype"
Expand Down Expand Up @@ -407,7 +435,7 @@ class InteractiveFormDictEntries:


class FieldDictionaryAttributes:
"""TABLE 8.69 Entries common to all field dictionaries (PDF 1.7 reference)."""
"""Table 8.69 Entries common to all field dictionaries (PDF 1.7 reference)."""

FT = "/FT" # name, required for terminal fields
Parent = "/Parent" # dictionary, required for children
Expand Down Expand Up @@ -503,7 +531,7 @@ def attributes_dict(cls) -> Dict[str, str]:


class CheckboxRadioButtonAttributes:
"""TABLE 8.76 Field flags common to all field types."""
"""Table 8.76 Field flags common to all field types."""

Opt = "/Opt" # Options, Optional

Expand Down Expand Up @@ -542,15 +570,15 @@ def attributes_dict(cls) -> Dict[str, str]:


class FieldFlag(IntFlag):
"""TABLE 8.70 Field flags common to all field types."""
"""Table 8.70 Field flags common to all field types."""

READ_ONLY = 1
REQUIRED = 2
NO_EXPORT = 4


class DocumentInformationAttributes:
"""TABLE 10.2 Entries in the document information dictionary."""
"""Table 10.2 Entries in the document information dictionary."""

TITLE = "/Title" # text string, optional
AUTHOR = "/Author" # text string, optional
Expand All @@ -564,12 +592,17 @@ class DocumentInformationAttributes:


class PageLayouts:
"""Page 84, PDF 1.4 reference."""
"""
Page 84, PDF 1.4 reference.
Page 115, PDF 2.0 reference.
"""

SINGLE_PAGE = "/SinglePage"
ONE_COLUMN = "/OneColumn"
TWO_COLUMN_LEFT = "/TwoColumnLeft"
TWO_COLUMN_RIGHT = "/TwoColumnRight"
TWO_PAGE_LEFT = "/TwoPageLeft" # (PDF 1.5)
TWO_PAGE_RIGHT = "/TwoPageRight" # (PDF 1.5)


class GraphicsStateParameters:
Expand Down Expand Up @@ -605,10 +638,14 @@ class GraphicsStateParameters:


class CatalogDictionary:
"""Table 3.25 in the 1.7 reference."""
"""
Table 3.25 in the 1.7 reference.
Table 29 in the 2.0 reference.
"""

TYPE = "/Type" # name, required; must be /Catalog
VERSION = "/Version" # name
EXTENSIONS = "/Extensions" # dictionary, optional; ISO 32000-1
PAGES = "/Pages" # dictionary, required
PAGE_LABELS = "/PageLabels" # number tree, optional
NAMES = "/Names" # dictionary, optional
Expand All @@ -635,6 +672,9 @@ class CatalogDictionary:
REQUIREMENTS = "/Requirements" # array, optional
COLLECTION = "/Collection" # dictionary, optional
NEEDS_RENDERING = "/NeedsRendering" # boolean, optional
DSS = "/DSS" # dictionary, optional
AF = "/AF" # array of dictionaries, optional
D_PART_ROOT = "/DPartRoot" # dictionary, optional


class OutlineFontFlag(IntFlag):
Expand All @@ -645,17 +685,20 @@ class OutlineFontFlag(IntFlag):


class PageLabelStyle:
"""Table 8.10 in the 1.7 reference."""
"""
Table 8.10 in the 1.7 reference.
Table 161 in the 2.0 reference.
"""

DECIMAL = "/D" # Decimal arabics
LOWERCASE_ROMAN = "/r" # Lowercase roman numbers
UPPERCASE_ROMAN = "/R" # Uppercase roman numbers
LOWERCASE_LETTER = "/a" # Lowercase letters
DECIMAL = "/D" # Decimal Arabic numerals
UPPERCASE_ROMAN = "/R" # Uppercase Roman numerals
LOWERCASE_ROMAN = "/r" # Lowercase Roman numerals
UPPERCASE_LETTER = "/A" # Uppercase letters
LOWERCASE_LETTER = "/a" # Lowercase letters


class AnnotationFlag(IntFlag):
"""See 12.5.3 "Annotation Flags"."""
"""See §12.5.3 "Annotation Flags"."""

INVISIBLE = 1
HIDDEN = 2
Expand Down

0 comments on commit c73ad26

Please sign in to comment.