2021-08-10 15:41:18 +02:00
|
|
|
def isLinearized(filename):
|
2024-04-17 02:14:40 +02:00
|
|
|
"""Finds out if a document is linearized as quickly as possible without
|
|
|
|
loading it."""
|
|
|
|
|
|
|
|
def hasAcroForm(pdf):
|
|
|
|
"""Returns True if the document has an AcroForm."""
|
|
|
|
|
|
|
|
def getSubformats(pdf):
|
|
|
|
"""Returns a list of the subformats of the PDF, if any."""
|
|
|
|
|
|
|
|
def hasObjectStreams(pdf):
|
|
|
|
"""Returns True if a document was written using object streams."""
|
|
|
|
|
|
|
|
def id1(pdf):
|
|
|
|
"""Return the first ID string of the PDF, if any, in hexadecimal string
|
|
|
|
format."""
|
|
|
|
|
|
|
|
def id2(pdf):
|
|
|
|
"""Return the second ID string of the PDF, if any, in hexadecimal string
|
|
|
|
format."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getVersion(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the minor version number of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getMajorVersion(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the minor version number of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getTitle(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the title of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getAuthor(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the subject of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getSubject(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the subject of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getKeywords(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the keywords of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getCreator(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the creator of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getProducer(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the producer of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getCreationDate(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the creation date of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getModificationDate(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the modification date of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getTitleXMP(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the XMP title of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getAuthorXMP(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the XMP author of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getSubjectXMP(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the XMP subject of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getKeywordsXMP(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the XMP keywords of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getCreatorXMP(pdf):
|
2022-01-23 14:06:53 +01:00
|
|
|
"""Return the XMP creator of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getProducerXMP(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the XMP producer of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getCreationDateXMP(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the XMP creation date of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getModificationDateXMP(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the XMP modification date of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setTitle(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the title of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setAuthor(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the author of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setSubject(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the subject of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setKeywords(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the keywords of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setCreator(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the creator of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setProducer(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the producer of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setCreationDate(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the creation date of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setModificationDate(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the modifcation date of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setTitleXMP(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the XMP title of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setAuthorXMP(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the XMP author of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setSubjectXMP(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the XMP subject of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setKeywordsXMP(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the XMP keywords of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setCreatorXMP(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the XMP creator of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setProducerXMP(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the XMP producer of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setCreationDateXMP(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the XMP creation date of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setModificationDateXMP(pdf, s):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the XMP modification date of a document."""
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def getDateComponents(string):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the components (year, month, day, hour, minute, second,
|
|
|
|
hour_offset, minute_offset) from a PDF date string.
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2024-04-17 02:14:40 +02:00
|
|
|
Month 1-31, day 1-31, hours (0-23), minutes (0-59), seconds (0-59),
|
|
|
|
hour_offset is the offset from UT in hours (-23 to 23); minute_offset is
|
|
|
|
the offset from UT in minutes (-59 to 59)."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def dateStringOfComponents(cs):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Build a PDF date string a (year, month, day, hour, minute, second,
|
|
|
|
hour_offset, minute_offset) tuple.
|
2022-01-23 14:06:53 +01:00
|
|
|
|
2024-04-17 02:14:40 +02:00
|
|
|
Dates: Month 1-31, day 1-31, hours (0-23), minutes (0-59), seconds (0-59),
|
|
|
|
hour_offset is the offset from UT in hours (-23 to 23); minute_offset is
|
|
|
|
the offset from UT in minutes (-59 to 59)."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def getPageRotation(pdf, pagenumber):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Get the viewing rotation for a given page."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def hasBox(pdf, pagenumber, boxname):
|
2024-04-17 02:14:40 +02:00
|
|
|
"""Returns True, if the page has the given box. E.g "/CropBox"."""
|
|
|
|
|
|
|
|
def numAnnots(pdf, pagenumber):
|
|
|
|
"""Return the number of annotations on the given page in the given PDF."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def getMediaBox(pdf, pagenumber):
|
2024-04-17 02:14:40 +02:00
|
|
|
"""Get a mediabox box given the document, page range, min x, max x, min y,
|
|
|
|
max y in points. Only suceeds if such a box exists, as checked by
|
|
|
|
hasBox."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def getCropBox(pdf, pagenumber):
|
2024-04-17 02:14:40 +02:00
|
|
|
"""Get a crop box given the document, page range, min x, max x, min y, max
|
|
|
|
y in points. Only suceeds if such a box exists, as checked by hasBox."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def getTrimBox(pdf, pagenumber):
|
2024-04-17 02:14:40 +02:00
|
|
|
"""Get a trim box given the document, page range, min x, max x, min y, max
|
|
|
|
y in points. Only suceeds if such a box exists, as checked by hasBox."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def getArtBox(pdf, pagenumber):
|
2024-04-17 02:14:40 +02:00
|
|
|
"""Get an art box given the document, page range, min x, max x, min y, max
|
|
|
|
y in points. Only suceeds if such a box exists, as checked by hasBox."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def getBleedBox(pdf, pagenumber):
|
2024-04-17 02:14:40 +02:00
|
|
|
"""Get a bleed box given the document, page range, min x, max x, min y, max
|
|
|
|
y in points. Only suceeds if such a box exists, as checked by hasBox."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def setMediaBox(pdf, r, minx, maxx, miny, maxy):
|
2024-04-17 02:14:40 +02:00
|
|
|
"""Set the media box given the document, page range, min x, max x, min y,
|
|
|
|
max y in points."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def setCropBox(pdf, r, minx, maxx, miny, maxy):
|
2024-04-17 02:14:40 +02:00
|
|
|
"""Set the crop box given the document, page range, min x, max x, min y,
|
|
|
|
max y in points."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def setTrimBox(pdf, r, minx, maxx, miny, maxy):
|
2024-04-17 02:14:40 +02:00
|
|
|
"""Set the trim box given the document, page range, min x, max x, min y,
|
|
|
|
max y in points."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def setArtBox(pdf, r, minx, maxx, miny, maxy):
|
2024-04-17 02:14:40 +02:00
|
|
|
"""Set the art box given the document, page range, min x, max x, min y, max
|
|
|
|
y in points."""
|
|
|
|
|
|
|
|
def pageInfoJSON(pdf):
|
|
|
|
"""Returns JSON data for the page information."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def setBleedBox(pdf, r, minx, maxx, miny, maxy):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the bleed box given the document, page range, min x, max x,
|
2021-08-10 15:41:18 +02:00
|
|
|
min y, max y in points."""
|
|
|
|
|
|
|
|
def markTrapped(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Mark a document as trapped."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def markUntrapped(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Mark a document as untrapped."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def markTrappedXMP(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Mark a document as trapped in XMP metadata."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def markUntrappedXMP(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Mark a document as untrapped in XMP metadata."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def setPageLayout(pdf, layout):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the page layout for a document."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
2024-04-17 02:14:40 +02:00
|
|
|
def getPageLayout(pdf):
|
|
|
|
"""Get the page layout for a document."""
|
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setPageMode(pdf, mode):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the page mode for a document."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
2024-04-17 02:14:40 +02:00
|
|
|
def getPageMode(pdf):
|
|
|
|
"""Get the page mode for a document"""
|
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def hideToolbar(pdf, flag):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Sets the hide toolbar flag."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
2024-04-17 02:14:40 +02:00
|
|
|
def getHideToolbar(pdf):
|
|
|
|
"""Get the hide toolbar flag."""
|
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def hideMenubar(pdf, flag):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the hide menu bar flag."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
2024-04-17 02:14:40 +02:00
|
|
|
def getHideMenubar(pdf):
|
|
|
|
"""Get the hide menubar flag."""
|
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def hideWindowUi(pdf, flag):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the hide window UI flag."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
2024-04-17 02:14:40 +02:00
|
|
|
def getHideWindowUi(pdf):
|
|
|
|
"""Get the hide window UI flag."""
|
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def fitWindow(pdf, flag):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the fit window flag."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
2024-04-17 02:14:40 +02:00
|
|
|
def getFitWindow(pdf):
|
|
|
|
"""Get the fit window flag."""
|
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def centerWindow(pdf, flag):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the center window flag."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
2024-04-17 02:14:40 +02:00
|
|
|
def getCenterWindow(pdf):
|
|
|
|
"""Get the center window flag."""
|
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def displayDocTitle(pdf, flag):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the display document title flag."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
2024-04-17 02:14:40 +02:00
|
|
|
def getDisplayDocTitle(pdf):
|
|
|
|
"""Get the display document title flag."""
|
|
|
|
|
|
|
|
def nonFullScreenPageMode(pdf, flag):
|
|
|
|
"""set the non full screen page mode flag."""
|
|
|
|
|
|
|
|
def getNonFullScreenPageMode(pdf):
|
|
|
|
"""get the non full screen page mode flag."""
|
|
|
|
|
2021-09-01 19:41:10 +02:00
|
|
|
def openAtPage(pdf, fitflag, pagenumber):
|
2022-01-23 14:06:53 +01:00
|
|
|
"""Set the PDF to open, possibly with zoom-to-fit, at the given page number.
|
|
|
|
"""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
2024-04-17 02:14:40 +02:00
|
|
|
def openAtPageCustom(pdf, custom):
|
|
|
|
"""Set a custom openAtPage description."""
|
|
|
|
|
2021-08-10 15:41:18 +02:00
|
|
|
def setMetadataFromFile(pdf, filename):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the XMP metadata of a document, given a file name."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def setMetadataFromByteArray(pdf, data):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the XMP metadata from an array of bytes."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def getMetadata(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the XMP metadata as a byte array of type bytes"""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def removeMetadata(pdf):
|
2024-04-17 02:14:40 +02:00
|
|
|
"""Remove the XMP metadata from a document."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def createMetadata(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Builds fresh XMP metadata as good as possible from existing
|
2021-08-10 15:41:18 +02:00
|
|
|
metadata in the document."""
|
|
|
|
|
|
|
|
def setMetadataDate(pdf, date):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Set the metadata date for a PDF. The date is given in PDF date format --
|
|
|
|
cpdf will convert it to XMP format. The date 'now' means now."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def getPageLabels(pdf):
|
|
|
|
"""Get page labels as a list of tuples (style, prefix, offset, startvalue)
|
|
|
|
|
|
|
|
For example, a document might have five pages of introduction with roman
|
|
|
|
numerals, followed by the rest of the pages in decimal arabic, numbered
|
2021-09-01 19:41:10 +02:00
|
|
|
from one. First label:
|
2021-08-10 15:41:18 +02:00
|
|
|
|
2021-09-01 19:41:10 +02:00
|
|
|
* labelstyle = LowercaseRoman
|
|
|
|
* labelprefix = ""
|
|
|
|
* startpage = 1
|
|
|
|
* startvalue = 1
|
2021-08-10 15:41:18 +02:00
|
|
|
|
2021-09-01 19:41:10 +02:00
|
|
|
Second label:
|
2021-08-10 15:41:18 +02:00
|
|
|
|
2021-09-01 19:41:10 +02:00
|
|
|
* labelstyle = DecimalArabic
|
|
|
|
* labelprefix = ""
|
|
|
|
* startpage = 6
|
2024-04-17 02:14:40 +02:00
|
|
|
* startvalue = 1"""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
2021-09-01 19:41:10 +02:00
|
|
|
def addPageLabels(pdf, label, progress):
|
|
|
|
"""Add one group of page labels from a tuple (style, prefix, offset, range).
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
The prefix is prefix text for each label. The range is the page range the
|
|
|
|
labels apply to. Offset can be used to shift the numbering up or down."""
|
|
|
|
|
|
|
|
def removePageLabels(pdf):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Removes all page labels from the document."""
|
2021-08-10 15:41:18 +02:00
|
|
|
|
|
|
|
def getPageLabelStringForPage(pdf, pagenumber):
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Calculate the full label string for a given page, and return it."""
|
2024-04-17 02:14:40 +02:00
|
|
|
|
|
|
|
def compositionJSON(filesize, pdf):
|
|
|
|
"""Get the composition in JSON format."""
|