from _typeshed import Incomplete
from abc import abstractmethod
from collections.abc import Callable, Iterable, Mapping
from typing import Any, Final, Literal, TypeVar, overload

_T = TypeVar("_T")

__version__: Final[str]

class PDFError(Exception): ...

__InternalName__: Final[str]
__RefOnly__: Final[str]
__Comment__: Final[str]
BasicFonts: Final[str]
Pages: Final[str]
PDF_VERSION_DEFAULT: Final[tuple[int, int]]
PDF_SUPPORT_VERSION: Final[Mapping[str, tuple[int, int]]]

def pdfdocEnc(x: str | _T) -> bytes | _T: ...
def format(element, document, toplevel: bool | Literal[0, 1] = 0): ...
def xObjectName(externalname: str) -> str: ...

formName = xObjectName

class NoEncryption:
    def encode(self, t): ...
    def prepare(self, document) -> None: ...
    def register(self, objnum, version) -> None: ...
    def info(self) -> None: ...

class PDFObject: ...

class DummyDoc(PDFObject):
    encrypt: NoEncryption

class PDFDocument(PDFObject):
    defaultStreamFilters: Incomplete
    encrypt: NoEncryption
    objectcounter: int
    shadingCounter: int
    inObject: str | None
    pageCounter: int
    invariant: bool | Literal[0, 1]
    idToObjectNumberAndVersion: dict[str, tuple[int, int]]
    idToObject: dict[str, PDFObject]
    idToOffset: dict[Incomplete, Incomplete]
    numberToId: dict[int, str]
    outline: PDFOutlines0 | PDFOutlines
    Outlines: PDFOutlines0 | PDFOutlines
    info: PDFInfo
    fontMapping: dict[Incomplete, Incomplete]
    delayedFonts: list[Incomplete]
    def __init__(
        self,
        dummyoutline: bool | Literal[0, 1] | None = 0,
        compression: bool | Literal[0, 1] | None = 1,
        invariant: bool | Literal[0, 1] | None = 0,
        filename=None,
        pdfVersion=(1, 3),
        lang=None,
    ) -> None: ...
    compression: bool | Literal[0, 1] | None
    def setCompression(self, onoff: bool | Literal[0, 1] | None) -> None: ...
    def ensureMinPdfVersion(self, *keys: str) -> None: ...
    def updateSignature(self, thing) -> None: ...
    def ID(self) -> bytes: ...
    def SaveToFile(self, filename, canvas) -> None: ...
    def GetPDFData(self, canvas) -> bytes: ...
    def inPage(self) -> None: ...
    def inForm(self) -> None: ...
    def getInternalFontName(self, psfontname: str): ...
    def thisPageName(self) -> str: ...
    def thisPageRef(self) -> PDFObjectReference: ...
    def addPage(self, page) -> None: ...
    def addForm(self, name, form) -> None: ...
    def annotationName(self, externalname) -> str: ...
    def addAnnotation(self, name, annotation) -> None: ...
    def refAnnotation(self, name) -> PDFObjectReference: ...
    def addShading(self, shading) -> str: ...
    def addColor(self, cmyk) -> tuple[Incomplete, Incomplete]: ...
    def setTitle(self, title) -> None: ...
    def setAuthor(self, author) -> None: ...
    def setSubject(self, subject) -> None: ...
    def setCreator(self, creator) -> None: ...
    def setProducer(self, producer) -> None: ...
    def setKeywords(self, keywords) -> None: ...
    def setDateFormatter(self, dateFormatter) -> None: ...
    def getAvailableFonts(self) -> list[Incomplete]: ...
    __accum__: PDFFile
    def format(self) -> bytes: ...
    def hasForm(self, name: str) -> bool: ...
    def getFormBBox(self, name: str, boxType: str = "MediaBox"): ...
    def getXObjectName(self, name: str) -> str: ...
    def xobjDict(self, formnames: Iterable[str]) -> PDFDictionary: ...
    def Reference(self, obj, name=None): ...

PDFtrue: Final = "true"
PDFfalse: Final = "false"
PDFnull: Final = "null"

class PDFText(PDFObject):
    t: Incomplete
    enc: str
    def __init__(self, t, enc: str = "utf-8") -> None: ...
    def format(self, document) -> bytes: ...

def PDFnumber(n: _T) -> _T: ...

class PDFString(PDFObject):
    unicodeEncValid: bool
    s: str | bytes
    escape: int
    enc: str
    def __init__(self, s: str | bytes | PDFString, escape: int = 1, enc: str = "auto") -> None: ...
    def format(self, document) -> bytes: ...

def PDFName(data, lo="!", hi="~") -> str: ...

class PDFDictionary(PDFObject):
    multiline: bool
    dict: Incomplete
    def __init__(self, dict=None) -> None: ...
    def __setitem__(self, name, value) -> None: ...
    def __getitem__(self, a): ...
    def __contains__(self, a) -> bool: ...
    def Reference(self, name, document) -> None: ...
    def format(self, document, IND: bytes = b"\n ") -> bytes: ...
    def copy(self) -> PDFDictionary: ...
    def normalize(self) -> None: ...

class checkPDFNames:
    names: list[str]
    def __init__(self, *names) -> None: ...
    def __call__(self, value: str) -> str | None: ...

@overload
def checkPDFBoolean(value: Literal["true"]) -> Literal["true"]: ...
@overload
def checkPDFBoolean(value: Literal["false"]) -> Literal["false"]: ...
@overload
def checkPDFBoolean(value: Any) -> None: ...

class CheckedPDFDictionary(PDFDictionary):
    validate: dict[str, Incomplete]
    def __init__(self, dict=None, validate: dict[str, Incomplete] | None = None) -> None: ...
    def __setitem__(self, name, value) -> None: ...

class ViewerPreferencesPDFDictionary(CheckedPDFDictionary):
    validate: dict[str, Incomplete]

class PDFStreamFilterZCompress:
    pdfname: str
    def encode(self, text) -> bytes: ...
    def decode(self, encoded) -> bytes: ...

PDFZCompress: PDFStreamFilterZCompress

class PDFStreamFilterBase85Encode:
    pdfname: str
    def encode(self, text) -> str: ...
    def decode(self, text) -> bytes: ...

PDFBase85Encode: PDFStreamFilterBase85Encode

class PDFStream(PDFObject):
    __RefOnly__: int
    dictionary: Incomplete
    content: Incomplete
    filters: Incomplete
    def __init__(self, dictionary=None, content=None, filters=None) -> None: ...
    def format(self, document) -> bytes: ...

def teststream(content=None) -> PDFStream: ...

teststreamcontent: str

class PDFArray(PDFObject):
    multiline: bool
    sequence: list[Incomplete]
    def __init__(self, sequence) -> None: ...
    def References(self, document) -> None: ...
    def format(self, document, IND: bytes = b"\n ") -> bytes: ...

class PDFArrayCompact(PDFArray):
    multiline: bool

class PDFIndirectObject(PDFObject):
    __RefOnly__: int
    name: str
    content: Incomplete
    def __init__(self, name: str, content) -> None: ...
    def format(self, document) -> bytes: ...

class PDFObjectReference(PDFObject):
    name: str
    def __init__(self, name: str) -> None: ...
    def format(self, document) -> bytes: ...

class PDFFile(PDFObject):
    strings: list[bytes]
    write: Callable[[bytes], None]
    offset: int
    def __init__(self, pdfVersion: tuple[int, int] = (1, 3)) -> None: ...
    def closeOrReset(self) -> None: ...
    def add(self, s) -> int: ...
    def format(self, document) -> bytes: ...

class PDFCrossReferenceSubsection(PDFObject):
    firstentrynumber: Incomplete
    idsequence: Incomplete
    def __init__(self, firstentrynumber, idsequence) -> None: ...
    def format(self, document) -> bytes: ...

class PDFCrossReferenceTable(PDFObject):
    sections: list[PDFCrossReferenceSubsection]
    def __init__(self) -> None: ...
    def addsection(self, firstentry, ids) -> None: ...
    def format(self, document) -> bytes: ...

class PDFTrailer(PDFObject):
    startxref: Incomplete
    def __init__(self, startxref, Size=None, Prev=None, Root=None, Info=None, ID=None, Encrypt=None) -> None: ...
    def format(self, document) -> bytes: ...

class PDFCatalog(PDFObject):
    __Comment__: str
    __RefOnly__: int
    __Defaults__: dict[str, str | None]
    __NoDefault__: list[str]
    __Refs__ = __NoDefault__
    def format(self, document) -> bytes: ...
    def showOutline(self) -> None: ...
    def showFullScreen(self) -> None: ...
    PageLayout: Incomplete
    def setPageLayout(self, layout) -> None: ...
    PageMode: Incomplete
    def setPageMode(self, mode) -> None: ...
    def check_format(self, document) -> None: ...

class PDFPages(PDFCatalog):
    __Comment__: str
    __RefOnly__: int
    __Defaults__: Incomplete
    __NoDefault__: list[str]
    __Refs__: Incomplete
    pages: Incomplete
    def __init__(self) -> None: ...
    def __getitem__(self, item): ...
    def addPage(self, page) -> None: ...
    Kids: PDFArray
    Count: int
    def check_format(self, document) -> None: ...

class PDFPage(PDFCatalog):
    __Comment__: str
    Override_default_compilation: int
    __RefOnly__: int
    __Defaults__: Incomplete
    __NoDefault__: list[str]
    __Refs__: Incomplete
    pagewidth: int
    pageheight: int
    stream: Incomplete
    hasImages: bool | Literal[0, 1]
    compression: bool | Literal[0, 1]
    XObjects: Incomplete
    Trans: Incomplete
    def __init__(self) -> None: ...
    def setCompression(self, onoff) -> None: ...
    def setStream(self, code) -> None: ...
    def setPageTransition(self, tranDict) -> None: ...
    MediaBox: Incomplete
    Annots: Incomplete
    Contents: Incomplete
    Resources: Incomplete
    Parent: Incomplete
    def check_format(self, document) -> None: ...

class DuplicatePageLabelPage(Exception): ...

class PDFPageLabels(PDFCatalog):
    __comment__: Incomplete
    __RefOnly__: int
    __Defaults__: Incomplete
    __NoDefault__: list[str]
    __Refs__: Incomplete
    labels: Incomplete
    def __init__(self) -> None: ...
    def addPageLabel(self, page, label) -> None: ...
    Nums: Incomplete
    def format(self, document) -> bytes: ...

class PDFPageLabel(PDFCatalog):
    __Comment__: Incomplete
    __RefOnly__: int
    __Defaults__: Incomplete
    __NoDefault__: list[str]
    __convertible__: str
    ARABIC: str
    ROMAN_UPPER: str
    ROMAN_LOWER: str
    LETTERS_UPPER: str
    LETTERS_LOWER: str
    S: Incomplete
    St: Incomplete
    P: Incomplete
    def __init__(self, style=None, start=None, prefix=None) -> None: ...
    def __lt__(self, oth): ...

def testpage(document) -> None: ...

DUMMYOUTLINE: str

class PDFOutlines0(PDFObject):
    __Comment__: str
    text: str
    __RefOnly__: int
    def format(self, document) -> bytes: ...

class OutlineEntryObject(PDFObject):
    Title: Incomplete
    Dest: Incomplete
    Parent: Incomplete
    Prev: Incomplete
    Next: Incomplete
    First: Incomplete
    Last: Incomplete
    Count: Incomplete
    def format(self, document) -> bytes: ...

class PDFOutlines(PDFObject):
    mydestinations: Incomplete
    ready: int | None
    counter: int
    currentlevel: int
    destinationnamestotitles: Incomplete
    destinationstotitles: Incomplete
    levelstack: Incomplete
    buildtree: Incomplete
    closedict: Incomplete
    def __init__(self) -> None: ...
    def addOutlineEntry(self, destinationname, level: int = 0, title=None, closed=None) -> None: ...
    def setDestinations(self, destinationtree) -> None: ...
    def format(self, document) -> bytes: ...
    def setNames(self, canvas, *nametree) -> None: ...
    def setNameList(self, canvas, nametree) -> None: ...
    def translateNames(self, canvas, object): ...
    first: Incomplete
    last: Incomplete
    count: int
    def prepare(self, document, canvas) -> None: ...
    def maketree(
        self, document, destinationtree, Parent=None, toplevel: bool | Literal[0, 1] = 0
    ) -> tuple[Incomplete, Incomplete]: ...

def count(tree, closedict=None) -> int: ...

class PDFInfo(PDFObject):
    producer: Incomplete
    creator: str
    title: str
    author: str
    subject: str
    keywords: str
    trapped: str
    def __init__(self) -> None: ...
    def digest(self, md5object) -> None: ...
    def format(self, document) -> bytes: ...
    def copy(self): ...

class Annotation(PDFObject):
    defaults: Incomplete
    required: tuple[str, ...]
    permitted: tuple[str, ...]
    def cvtdict(self, d: dict[str, Incomplete], escape: int = 1) -> dict[str, Incomplete]: ...
    def AnnotationDict(self, **kw) -> PDFDictionary: ...
    @abstractmethod
    def Dict(self) -> PDFDictionary: ...
    def format(self, document) -> bytes: ...

class FreeTextAnnotation(Annotation):
    permitted: tuple[str, ...]
    Rect: Incomplete
    Contents: Incomplete
    DA: Incomplete
    otherkw: dict[str, Incomplete]
    def __init__(self, Rect, Contents, DA, **kw) -> None: ...
    def Dict(self) -> PDFDictionary: ...

class LinkAnnotation(Annotation):
    permitted: tuple[str, ...]
    Border: Incomplete
    Rect: Incomplete
    Contents: Incomplete
    Destination: Incomplete
    otherkw: dict[str, Incomplete]
    def __init__(self, Rect, Contents, Destination, Border: str = "[0 0 1]", **kw) -> None: ...
    def dummyDictString(self) -> str: ...
    def Dict(self) -> PDFDictionary: ...

class HighlightAnnotation(Annotation):
    permitted: tuple[str, ...]
    Rect: Incomplete
    Contents: Incomplete
    otherkw: dict[str, Incomplete]
    QuadPoints: Incomplete
    Color: Incomplete
    def __init__(self, Rect, Contents, QuadPoints, Color=[0.83, 0.89, 0.95], **kw) -> None: ...
    def cvtdict(self, d: dict[str, Incomplete], escape: int = 1) -> dict[str, Incomplete]: ...
    def Dict(self) -> PDFDictionary: ...

class TextAnnotation(HighlightAnnotation):
    permitted: tuple[str, ...]
    def __init__(self, Rect, Contents, **kw) -> None: ...
    def Dict(self) -> PDFDictionary: ...

def rect_to_quad(Rect) -> list[Incomplete]: ...

class PDFRectangle(PDFObject):
    def __init__(self, llx, lly, urx, ury) -> None: ...
    def format(self, document) -> bytes: ...

class PDFDate(PDFObject):
    dateFormatter: Incomplete
    def __init__(self, ts=None, dateFormatter=None) -> None: ...
    def format(self, doc) -> bytes: ...

class Destination(PDFObject):
    representation: None
    page: None
    name: Incomplete
    fmt: Incomplete
    def __init__(self, name) -> None: ...
    def format(self, document) -> bytes: ...
    def xyz(self, left, top, zoom) -> None: ...
    def fit(self) -> None: ...
    def fitb(self) -> None: ...
    def fith(self, top) -> None: ...
    def fitv(self, left) -> None: ...
    def fitbh(self, top) -> None: ...
    def fitbv(self, left) -> None: ...
    def fitr(self, left, bottom, right, top) -> None: ...
    def setPage(self, page) -> None: ...

class PDFDestinationXYZ(PDFObject):
    typename: str
    page: Incomplete
    top: Incomplete
    zoom: Incomplete
    left: Incomplete
    def __init__(self, page, left, top, zoom) -> None: ...
    def format(self, document) -> bytes: ...

class PDFDestinationFit(PDFObject):
    typename: str
    page: Incomplete
    def __init__(self, page) -> None: ...
    def format(self, document) -> bytes: ...

class PDFDestinationFitB(PDFDestinationFit):
    typename: str

class PDFDestinationFitH(PDFObject):
    typename: str
    page: Incomplete
    top: Incomplete
    def __init__(self, page, top) -> None: ...
    def format(self, document) -> bytes: ...

class PDFDestinationFitBH(PDFDestinationFitH):
    typename: str

class PDFDestinationFitV(PDFObject):
    typename: str
    page: Incomplete
    left: Incomplete
    def __init__(self, page, left) -> None: ...
    def format(self, document) -> bytes: ...

class PDFDestinationFitBV(PDFDestinationFitV):
    typename: str

class PDFDestinationFitR(PDFObject):
    typename: str
    page: Incomplete
    left: Incomplete
    bottom: Incomplete
    right: Incomplete
    top: Incomplete
    def __init__(self, page, left, bottom, right, top) -> None: ...
    def format(self, document) -> bytes: ...

class PDFResourceDictionary(PDFObject):
    ProcSet: Incomplete
    def __init__(self, **kwds) -> None: ...
    stdprocs: Incomplete
    dict_attributes: Incomplete
    def allProcs(self) -> None: ...
    def basicProcs(self) -> None: ...
    Font: Incomplete
    def basicFonts(self) -> None: ...
    def setColorSpace(self, colorsUsed) -> None: ...
    def setShading(self, shadingUsed) -> None: ...
    def format(self, document) -> bytes: ...

class PDFType1Font(PDFObject):
    __RefOnly__: int
    name_attributes: Incomplete
    Type: str
    Subtype: str
    local_attributes: Incomplete
    def format(self, document) -> bytes: ...

class PDFTrueTypeFont(PDFType1Font):
    Subtype: str

class PDFFormXObject(PDFObject):
    XObjects: Incomplete
    Annots: Incomplete
    BBox: Incomplete
    Matrix: Incomplete
    Contents: Incomplete
    stream: Incomplete
    Resources: Incomplete
    hasImages: bool | Literal[0, 1]
    compression: bool | Literal[0, 1]
    lowerx: Incomplete
    lowery: Incomplete
    upperx: Incomplete
    uppery: Incomplete
    def __init__(self, lowerx, lowery, upperx, uppery) -> None: ...
    def setStreamList(self, data) -> None: ...
    def BBoxList(self) -> list[Incomplete]: ...
    def format(self, document) -> bytes: ...

class PDFPostScriptXObject(PDFObject):
    content: Incomplete
    def __init__(self, content=None) -> None: ...
    def format(self, document) -> bytes: ...

class PDFImageXObject(PDFObject):
    name: Incomplete
    width: int
    height: int
    bitsPerComponent: int
    colorSpace: str
    streamContent: str
    mask: Incomplete
    def __init__(self, name, source=None, mask=None) -> None: ...
    def loadImageFromA85(self, source) -> None: ...
    def loadImageFromJPEG(self, imageFile) -> bool: ...
    def loadImageFromRaw(self, source) -> None: ...
    def loadImageFromSRC(self, im) -> None: ...
    def format(self, document) -> bytes: ...

class PDFSeparationCMYKColor:
    cmyk: Incomplete
    def __init__(self, cmyk) -> None: ...
    def value(self) -> PDFArrayCompact: ...

class PDFFunction(PDFObject):
    defaults: Incomplete
    required: tuple[str, ...]
    permitted: tuple[str, ...]
    def FunctionDict(self, **kw) -> PDFDictionary: ...
    @abstractmethod
    def Dict(self, document) -> PDFDictionary: ...
    def format(self, document) -> bytes: ...

class PDFExponentialFunction(PDFFunction):
    defaults: Incomplete
    required: tuple[str, ...]
    permitted: tuple[str, ...]
    C0: Incomplete
    C1: Incomplete
    N: Incomplete
    otherkw: dict[str, Incomplete]
    def __init__(self, C0, C1, N, **kw) -> None: ...
    def Dict(self, document) -> PDFDictionary: ...

class PDFStitchingFunction(PDFFunction):
    required: tuple[str, ...]
    permitted: tuple[str, ...]
    Functions: Incomplete
    Bounds: Incomplete
    Encode: Incomplete
    otherkw: dict[str, Incomplete]
    def __init__(self, Functions, Bounds, Encode, **kw) -> None: ...
    def Dict(self, document) -> PDFDictionary: ...

class PDFShading(PDFObject):
    required: tuple[str, ...]
    permitted: tuple[str, ...]
    def ShadingDict(self, **kw) -> PDFDictionary: ...
    @abstractmethod
    def Dict(self, document) -> PDFDictionary: ...
    def format(self, document) -> bytes: ...

class PDFFunctionShading(PDFShading):
    required: tuple[str, ...]
    permitted: tuple[str, ...]
    Function: Incomplete
    ColorSpace: Incomplete
    otherkw: dict[str, Incomplete]
    def __init__(self, Function, ColorSpace, **kw) -> None: ...
    def Dict(self, document) -> PDFDictionary: ...

class PDFAxialShading(PDFShading):
    required: tuple[str, ...]
    permitted: tuple[str, ...]
    Coords: Incomplete
    Function: Incomplete
    ColorSpace: Incomplete
    otherkw: dict[str, Incomplete]
    def __init__(self, x0, y0, x1, y1, Function, ColorSpace, **kw) -> None: ...
    def Dict(self, document) -> PDFDictionary: ...

class PDFRadialShading(PDFShading):
    required: tuple[str, ...]
    permitted: tuple[str, ...]
    Coords: Incomplete
    Function: Incomplete
    ColorSpace: Incomplete
    otherkw: dict[str, Incomplete]
    def __init__(self, x0, y0, r0, x1, y1, r1, Function, ColorSpace, **kw) -> None: ...
    def Dict(self, document) -> PDFDictionary: ...

class XMP(PDFStream):
    def __init__(self, path=None, creator=None) -> None: ...
    def makeContent(self, doc): ...
    # Param name is changed from the base class:
    def format(self, doc) -> bytes: ...
