Finishing python comments

This commit is contained in:
John Whitington 2021-09-01 19:41:10 +02:00
parent 301346f23b
commit 0965d8ee54
18 changed files with 371 additions and 406 deletions

View File

@ -2,8 +2,8 @@
let demo = false let demo = false
let noncomp = false let noncomp = false
let major_version = 2 let major_version = 2
let minor_version = 4 let minor_version = 5
let version_date = "(21st June 2021)" let version_date = "(devel, 1st Sept 2021)"
open Pdfutil open Pdfutil
open Pdfio open Pdfio

Binary file not shown.

View File

@ -2951,7 +2951,7 @@ In a PDF file, optional content groups are used to group graphical elements toge
\clearpage \clearpage
\section*{C Interface} \section*{C Interface}
\begin{small}\tt \begin{small}\tt
\lstinputlisting{splits/c16} \lstinputlisting{splits/c17}
\end{small} \end{small}
\end{cpdflib} \end{cpdflib}
@ -2959,7 +2959,7 @@ In a PDF file, optional content groups are used to group graphical elements toge
\clearpage \clearpage
\section*{Python Interface} \section*{Python Interface}
\begin{small}\tt \begin{small}\tt
\lstinputlisting{pysplits/c16} \lstinputlisting{pysplits/c17}
\end{small} \end{small}
\end{pycpdflib} \end{pycpdflib}

View File

@ -12,5 +12,4 @@ A 'range' is a list of integers specifying page numbers.
Text arguments and results are in UTF8. Text arguments and results are in UTF8.
Any function may raise the exception CPDFError, carrying a string describing Any function may raise the exception CPDFError, carrying a string describing
the error. the error. """
"""

View File

@ -1,14 +1,98 @@
# CHAPTER 0. Preliminaries Loading the libpypcdf and libcpdf DLLs
--------------------------------------
def loadDLL(f): Before using the library, you must load the ``libpycpdf`` and ``libcpdf`` DLLs.
"""Load the libpycpdf DLL from a given file, and set up pycpdflib.""" This is achieved with the ``pycpdf.loadDLL`` function, given the filename or
full path of the ``libpycpdf`` DLL.
On Windows, you may have to call ``os.add_dll_directory`` first. On MacOS, you
may need to give the full path, and you may need to install ``libcpdf.so`` in a
standard location ``/usr/local/lib/``, or use the ``install_name_tool`` command
to tell ``libpycpdf.so`` where to find ``libcpdf.so``.
Conventions
-----------
Any function may raise the exception ``CPDFError``, carrying a string describing
the error.
A 'range' is a list of integers specifying page numbers. Page numbers start at
1. Range arguments are called `r`.
Text arguments and results are in UTF8.
Units are in PDF points (1/72 inch).
Angles are in degrees.
Built-in values
---------------
Paper sizes:
a0portrait a1portrait a2portrait a3portrait a4portrait a5portrait a0landscape
a1landscape a2landscape a3landscape a4landscape a5landscape usletterportrait
usletterlandscape uslegalportrait uslegallandscape
Permissions:
noEdit noPrint noCopy noAnnot noForms noExtract noAssemble noHqPrint
Encryption methods:
pdf40bit pdf128bit aes128bitfalse aes128bittrue aes256bitfalse aes256bittrue
aes256bitisofalse aes256bitisotrue
Positions:
Positions with two numbers in a tuple e.g (posLeft, 10.0, 20.0)
posCentre posLeft posRight
Positions with one number in a tuple e.g (top, 5.0)
top topLeft topRight left bottomLeft bottomRight right
Positions with no numbers e.g diagonal
diagonal reverseDiagonal
Fonts:
timesRoman timesBold timesItalic timesBoldItalic helvetica helveticaBold
helveticaOblique helveticaBoldOblique courier courierBold courierOblique
courierBoldOblique
Justification:
leftJustify centreJustify rightJustify
Page layouts:
singlePage oneColumn twoColumnLeft twoColumnRight twoPageLeft twoPageRight
Page modes:
useNone useOutlines useThumbs useOC useAttachments
Page label styles:
decimalArabic uppercaseRoman lowercaseRoman uppercaseLetters lowercaseLetters
# CHAPTER 0. Preliminaries
class Pdf: class Pdf:
"""The type of PDF documents.""" """The type of PDF documents."""
def loadDLL(f):
"""Load the libpycpdf DLL from a given file, and set up pycpdflib. Must be
called prior to using any other function in the library."""
class CPDFError(Exception): class CPDFError(Exception):
"""Any function may raise an exception CPDFError, carrying a string """Any function may raise an exception CPDFError, carrying a string
describing what went wrong""" describing what went wrong."""
def lastError(): def lastError():
"""Return the last error. Not usually used directly, since pycpdflib """Return the last error. Not usually used directly, since pycpdflib
@ -24,22 +108,22 @@ def checkerror():
directly.""" directly."""
def version(): def version():
"""Returns the version number of the pycpdflib library.""" """Return the version number of the pycpdflib library."""
def setFast(): def setFast():
""" Some operations have a fast mode. The default is 'slow' mode, which """ Set fast mode. Some operations have a fast mode. The default is 'slow'
works even on old-fashioned files. For more details, see section 1.13 of mode, which works even on old-fashioned files. For more details, see
the CPDF manual. These functions set the mode globally. """ section 1.13 of the CPDF manual. This function sets the mode globally. """
def setSlow(): def setSlow():
""" Some operations have a fast mode. The default is 'slow' mode, which """ Set slow mode. Some operations have a fast mode. The default is 'slow'
works even on old-fashioned files. For more details, see section 1.13 of mode, which works even on old-fashioned files. For more details, see
the CPDF manual. These functions set the mode globally. """ section 1.13 of the CPDF manual. This function sets the mode globally. """
def clearError(): def clearError():
""" clearError clears the current error state. """ """ Clear the current error state. """
def onExit(): def onExit():
""" onExit is a debug function which prints some information about """ A debug function which prints some information about
resource usage. This can be used to detect if PDFs or ranges are being resource usage. This can be used to detect if PDFs or ranges are being
deallocated properly.""" deallocated properly."""

View File

@ -1,209 +1,174 @@
# CHAPTER 1. Basics # CHAPTER 1. Basics
def fromFile(filename, userpw): def fromFile(filename, userpw):
""" fromFile(filename, userpw) loads a PDF file from a given file. """ Load a PDF file from a given file.
Supply a user password (possibly blank) in case the file is encypted. It Supply a user password (possibly blank) in case the file is encypted. It
won't be decrypted, but sometimes the password is needed just to load the won't be decrypted, but sometimes the password is needed just to load the
file.""" file."""
def fromFileLazy(filename, userpw): def fromFileLazy(filename, userpw):
""" fromFileLazy(pdf, userpw) loads a PDF from a file, doing only """ Loads a PDF from a file, doing only
minimal parsing. The objects will be read and parsed when they are actually minimal parsing. The objects will be read and parsed when they are actually
needed. Use this when the whole file won't be required. Also supply a user needed. Use this when the whole file won't be required. Also supply a user
password (possibly blank) in case the file is encypted. It won't be password (possibly blank) in case the file is encypted. It won't be
decrypted, but sometimes the password is needed just to load the file.""" decrypted, but sometimes the password is needed just to load the file."""
def fromMemory(data, userpw): def fromMemory(data, userpw):
""" fromMemory(data, length, userpw) loads a file from memory, given a """ Load a file from a byte array and the user password (blank if none)."""
pointer and a length, and the user password."""
def fromMemoryLazy(data, userpw): def fromMemoryLazy(data, userpw):
""" fromMemoryLazy(data, length, userpw) loads a file from memory, given a """ Load a file from from a byte array and the user password (blank if
pointer and a length, and the user password, but lazily like none), but lazily like fromFileLazy."""
fromFileLazy."""
def blankDocument(w, h, pages): def blankDocument(w, h, pages):
""" blankDocument(width, height, num_pages) creates a blank document """ Create a blank document
with pages of the given width (in points), height (in points), and number with pages of the given width (in points), height (in points), and number
of pages.""" of pages."""
"""Paper sizes."""
a0portrait
a1portrait
a2portrait
a3portrait
a4portrait
a5portrait
a0landscape
a1landscape
a2landscape
a3landscape
a4landscape
a5landscape
usletterportrait
usletterlandscape
uslegalportrait
uslegallandscape
def blankDocumentPaper(papersize, pages): def blankDocumentPaper(papersize, pages):
"""blankDocument(width, height, num_pages) creates a blank document """Create a blank document with pages of the given paper size, and number
with pages of the given width (in points), height (in points), and number
of pages. """ of pages. """
def ptOfCm(i): def ptOfCm(i):
"""Convert a figure in centimetres to points (72 points to 1 inch)""" """Convert a figure in centimetres to points (72 points to 1 inch)."""
def ptOfMm(i): def ptOfMm(i):
"""Convert a figure in millimetres to points (72 points to 1 inch)""" """Convert a figure in millimetres to points (72 points to 1 inch)."""
def ptOfIn(i): def ptOfIn(i):
"""Convert a figure in inches to points (72 points to 1 inch)""" """Convert a figure in inches to points (72 points to 1 inch)."""
def cmOfPt(i): def cmOfPt(i):
"""Convert a figure in points to centimetres (72 points to 1 inch)""" """Convert a figure in points to centimetres (72 points to 1 inch)."""
def mmOfPt(i): def mmOfPt(i):
"""Convert a figure in points to millimetres (72 points to 1 inch)""" """Convert a figure in points to millimetres (72 points to 1 inch)."""
def inOfPt(i): def inOfPt(i):
"""Convert a figure in points to inches (72 points to 1 inch)""" """Convert a figure in points to inches (72 points to 1 inch)."""
def parsePagespec(pdf, pagespec): def parsePagespec(pdf, pagespec):
"""parsePagespec(pdf, pagespec) parses a page specification with reference to """Parse a page specification such as "1-3,8-end" to a range with reference to
a given PDF (the PDF is supplied so that page ranges which reference pages a given PDF (the PDF is supplied so that page ranges which reference pages
which do not exist are rejected).""" which do not exist are rejected)."""
def validatePagespec(pagespec): def validatePagespec(pagespec):
"""validatePagespec(range) validates a page specification so far as is """Validate a page specification, returning True or False, so far as is
possible in the absence of the actual document.""" possible in the absence of the actual document."""
def stringOfPagespec(pdf, r): def stringOfPagespec(pdf, r):
"""stringOfPagespec(pdf, range) builds a page specification from a page """Build a page specification from a page
range. For example, the range containing 1,2,3,6,7,8 in a document of 8 range. For example, the range containing 1,2,3,6,7,8 in a document of 8
pages might yield "1-3,6-end" """ pages might yield "1-3,6-end" """
def blankRange(): def blankRange():
"""blankRange() creates a range with no pages in.""" """Create a range with no pages in."""
def pageRange(f, t): def pageRange(f, t):
""" pageRange(from, to) build a range from one page to another inclusive. """ Nuild a range from one page to another inclusive.
For example, pageRange(3,7) gives the range 3,4,5,6,7 """ For example, pageRange(3,7) gives the range 3,4,5,6,7. """
def all(pdf): def all(pdf):
"""all(pdf) is the range containing all the pages in a given document.""" """The range containing all the pages in a given document."""
def even(r): def even(r):
"""even(range) makes a range which contains just the even pages of another """A range which contains just the even pages of another
range""" range."""
def odd(r): def odd(r):
"""odd(range) makes a range which contains just the odd pages of another """A range which contains just the odd pages of another
range""" range."""
def rangeUnion(a, b): def rangeUnion(a, b):
"""rangeUnion(a, b) makes the union of two ranges giving a range containing """The union of two ranges giving a range containing
the pages in range a and range b.""" the pages in range a and range b."""
def difference(a, b): def difference(a, b):
"""difference(a, b) makes the difference of two ranges, giving a range """The difference of two ranges, giving a range
containing all the pages in a except for those which are also in b.""" containing all the pages in a except for those which are also in b."""
def removeDuplicates(r): def removeDuplicates(r):
"""removeDuplicates(range) deduplicates a range, making a new one.""" """Deduplicates a range, returning a new one."""
def rangeLength(r): def rangeLength(r):
"""rangeLength gives the number of pages in a range.""" """The number of pages in a range."""
def rangeGet(r, n): def rangeGet(r, n):
"""rangeGet(range, n) gets the page number at position n in a range, where """Get the page number at position n in a range, where
n runs from 0 to rangeLength - 1."""
def rangeAdd(r, p): def rangeAdd(r, p):
"""rangeAdd(range, page) adds the page to a range, if it is not already """Add the page to a range, if it is not already
there.""" there."""
def isInRange(r, p): def isInRange(r, p):
"""isInRange(range, page) returns True if the page is in the range, False """Returns True if the page p is in the range r, False otherwise."""
otherwise."""
def pages(pdf): def pages(pdf):
"""pages(pdf) returns the number of pages in a PDF.""" """Return the number of pages in a PDF."""
r = libc.pycpdf_pages(pdf.pdf)
checkerror()
return r
def pagesFast(userpw, filename): def pagesFast(userpw, filename):
"""pagesFast(password, filename) returns the number of pages in a given """Return the number of pages in a given
PDF, with given user encryption password. It tries to do this as fast as PDF, with given user password. It tries to do this as fast as
possible, without loading the whole file.""" possible, without loading the whole file."""
def toFile(pdf, filename, linearize, make_id): def toFile(pdf, filename, linearize, make_id):
"""toFile (pdf, filename, linearize, make_id) writes the file to a given """Write the file to a given filename. If linearize is True, it will be
filename. If linearize is True, it will be linearized. If make_id is True, linearized, if supported by libcpdf. If make_id is True, it will be given a
it will be given a new ID.""" new ID."""
def toFileExt(pdf, filename, linearize, make_id, preserve_objstm, def toFileExt(pdf, filename, linearize, make_id, preserve_objstm,
generate_objstm, compress_objstm): generate_objstm, compress_objstm):
"""toFileExt (pdf, filename, linearize, make_id, preserve_objstm, """Write the file to a given filename. If linearize is True, it will be
generate_objstm, compress_objstm) writes the file to a given filename. If linearized, if supported by libcpdf. If make_id is True, it will be given a
make_id is True, it will be given a new ID. If preserve_objstm is True, new ID. If preserve_objstm is True, existing object streams will be
existing object streams will be preserved. If generate_objstm is True, preserved. If generate_objstm is True, object streams will be generated
object streams will be generated even if not originally present. If even if not originally present. If compress_objstm is True, object streams
compress_objstm is True, object streams will be compressed (what we usually will be compressed (what we usually want). WARNING: the pdf argument will
want). WARNING: the pdf argument will be invalid after this call and should be invalid after this call and should not be used again."""
not be used again."""
def toMemory(pdf, linearize, make_id): def toMemory(pdf, linearize, make_id):
"""Given a buffer of the correct size, toMemory (pdf, linearize, """Write a file to memory, returning the buffer as a byte array of type
make_id) writes it and returns the buffer as a byte array of type bytes.""" bytes."""
def isEncrypted(pdf): def isEncrypted(pdf):
"""isEncrypted(pdf) returns True if a documented is encrypted, False """Returns True if a documented is encrypted, False otherwise."""
otherwise.""" r = libc.pycpdf_isEncrypted(pdf.pdf)
checkerror()
"""Permissions.""" return r
noEdit
noPrint
noCopy
noAnnot
noForms
noExtract
noAssemble
noHqPrint
"""Encryption Methods."""
pdf40bit
pdf128bit
aes128bitfalse
aes128bittrue
aes256bitfalse
aes256bittrue
aes256bitisofalse
aes256bitisotrue
def toFileEncrypted(pdf, method, permissions, ownerpw, userpw, linearize, def toFileEncrypted(pdf, method, permissions, ownerpw, userpw, linearize,
makeid, filename): makeid, filename):
"""toFileEncrypted(pdf, encryption_method, permissions, permission_length, """Write the file to a given filename encrypted with the given encryption
owner_password, user password, linearize, makeid, filename) writes a file method, permissions list, and owener and user passwords. If linearize is
as encrypted.""" True, it will be linearized, if supported by libcpdf. If make_id is True,
it will be given a new ID."""
def toFileEncryptedExt(pdf, method, permissions, ownerpw, userpw, linearize, def toFileEncryptedExt(pdf, method, permissions, ownerpw, userpw, linearize,
makeid, preserve_objstm, generate_objstm, makeid, preserve_objstm, generate_objstm,
compress_objstm, filename): compress_objstm, filename):
"""toFileEncryptedExt(pdf, encryption_method, permissions, """Write the file to a given filename encrypted with the given encryption
permission_length, owner_password, user_password, linearize, makeid, method, permissions list, and owener and user passwords. If linearize is
preserve_objstm, generate_objstm, compress_objstm, filename) WARNING: the True, it will be linearized, if supported by libcpdf. If make_id is True,
pdf argument will be invalid after this call, and should be discarded.""" it will be given a new ID. If preserve_objstm is True, existing object
streams will be preserved. If generate_objstm is True, object streams will
be generated even if not originally present. If compress_objstm is True,
object streams will be compressed (what we usually want). WARNING: the pdf
argument will be invalid after this call and should not be used again."""
def decryptPdf(pdf, userpw): def decryptPdf(pdf, userpw):
"""decryptPdf(pdf, userpw) attempts to decrypt a PDF using the given user """Attempts to decrypt a PDF using the given user password. An exception is
password.""" raised in the event of a bad password."""
def decryptPdfOwner(pdf, ownerpw): def decryptPdfOwner(pdf, ownerpw):
"""decryptPdfOwner(pdf, ownerpw) attempts to decrypt a PDF using the given """Attempts to decrypt a PDF using the given owner password. An exception
owner password.""" is raised in the event of a bad password."""
def hasPermission(pdf, perm): def hasPermission(pdf, perm):
"""hasPermission(pdf, permission) returns True if the given permission """Returns True if the given permission (restriction) is present."""
(restriction) is present."""
def encryptionKind(pdf): def encryptionKind(pdf):
"""encryptionMethod(pdf) return the encryption method currently in use on """Return the encryption method currently in use on a document."""
a document."""

View File

@ -1,23 +1,20 @@
# CHAPTER 2. Merging and Splitting # CHAPTER 2. Merging and Splitting
def mergeSimple(pdfs): def mergeSimple(pdfs):
"""mergeSimple(pdfs), given a list of PDFs, """Given a list of PDFs, merges the documents into a new PDF, which is
merges the files into a new one, which is returned.""" returned."""
def merge(pdfs, retain_numbering, remove_duplicate_fonts): def merge(pdfs, retain_numbering, remove_duplicate_fonts):
"""merge(pdfs, retain_numbering, remove_duplicate_fonts) merges """Merges the list of PDFs. If retain_numbering is True page labels are not
the list of PDFs. If retain_numbering is True page labels are not
rewritten. If remove_duplicate_fonts is True, duplicate fonts are merged. rewritten. If remove_duplicate_fonts is True, duplicate fonts are merged.
This is useful when the source documents for merging originate from the This is useful when the source documents for merging originate from the
same source.""" same source."""
def mergeSame(pdfs, retain_numbering, remove_duplicate_fonts, ranges): def mergeSame(pdfs, retain_numbering, remove_duplicate_fonts, ranges):
"""mergeSame(pdfs, retain_numbering, remove_duplicate_fonts, ranges) """The same as merge, except that it has an additional argument
is the same as merge, except that it has an additional argument - a list of page ranges. This is used to select the pages to pick from
- an array of page ranges. This is used to select the pages to pick from
each PDF. This avoids duplication of information when multiple discrete each PDF. This avoids duplication of information when multiple discrete
parts of a source PDF are included.""" parts of a single source PDF are included."""
def selectPages(pdf, r): def selectPages(pdf, r):
""" selectPages(pdf, range) returns a new document which just those pages """ Returns a new document which just those pages in the page range."""
in the page range."""

View File

@ -1,89 +1,70 @@
# CHAPTER 3. Pages # CHAPTER 3. Pages
def scalePages(pdf, r, sx, sy): def scalePages(pdf, r, sx, sy):
"""scalePages(pdf, range, x scale, y scale) scales the page dimensions """Scale the page dimensions and content of the given range of pages by
and content by the given scale, about (0, 0). Other boxes (crop etc. are the given scale (sx, sy), about (0, 0). Other boxes (crop etc. are altered
altered as appropriate)""" as appropriate)."""
def scaleToFit(pdf, r, sx, sy, scale_to_fit_scale): def scaleToFit(pdf, r, w, h, scale_to_fit_scale):
"""scaleToFit(pdf, range, width height, scale) scales the content to fit """Scales the pages in the range to fit new page dimensions (w and h)
new page dimensions (width x height) multiplied by scale (typically 1.0). multiplied by scale_to_fit_scale (typically 1.0). Other boxes (crop etc.)
Other boxed (crop etc. are altered as appropriate)""" are altered as appropriate."""
def scaleToFitPaper(pdf, r, papersize, scale_to_fit_scale): def scaleToFitPaper(pdf, r, papersize, scale_to_fit_scale):
"""scaleToFitPaper(pdf, range, papersize, scale) scales the page content """Scales the given pages to fit the given page size, possibly multiplied
to fit the given page size, possibly multiplied by scale (typically 1.0)""" by scale_to_fit_scale (typically 1.0)"""
"""Positions with two numbers in a tuple e.g (posLeft, 10.0, 20.0):"""
posCentre = 0
posLeft = 1
posRight = 2
"""Positions with one number in a tuple e.g (top, 5.0):"""
top = 3
topLeft = 4
topRight = 5
left = 6
bottomLeft = 7
bottomRight = 8
right = 9
"""Positions with no numbers e.g diagonal:"""
diagonal = 10
reverseDiagonal = 11
def scaleContents(pdf, r, pos, scale): def scaleContents(pdf, r, pos, scale):
"""scaleContents(pdf, range, position, scale) scales the contents of the """Scales the contents of the pages in the range about the point given by
pages in the range about the point given by the position, by the the position, by the scale given."""
scale given."""
def shiftContents(pdf, r, dx, dy): def shiftContents(pdf, r, dx, dy):
"""shiftContents(pdf, range, dx, dy) shifts the content of the pages in """Shift the content of the pages in the range by (dx, dy)."""
the range."""
def rotate(pdf, r, rotation): def rotate(pdf, r, rotation):
"""rotate(pdf, range, rotation) changes the viewing rotation to an """Change the viewing rotation of the pages in the range to an
absolute value. Appropriate rotations are 0, 90, 180, 270.""" absolute value. Appropriate rotations are 0, 90, 180, 270."""
def rotateBy(pdf, r, rotation): def rotateBy(pdf, r, rotation):
"""rotateBy(pdf, range, rotation) changes the viewing rotation by a """Change the viewing rotation of the pages in the range by a
given number of degrees. Appropriate values are 90, 180, 270.""" given number of degrees. Appropriate values are 90, 180, 270."""
def rotateContents(pdf, r, rotation): def rotateContents(pdf, r, rotation):
"""rotateContents(pdf, range, angle) rotates the content about the centre """Rotate the content about the centre
of the page by the given number of degrees, in a clockwise direction.""" of the page by the given number of degrees, in a clockwise direction."""
def upright(pdf, r): def upright(pdf, r):
"""upright(pdf, range) changes the viewing rotation of the pages in the """Change the viewing rotation of the pages in the range, counter-rotating
range, counter-rotating the dimensions and content such that there is no the dimensions and content such that there is no visual change."""
visual change."""
def hFlip(pdf, r): def hFlip(pdf, r):
"""hFlip(pdf, range) flips horizontally the pages in the range.""" """Flip horizontally the pages in the range."""
def vFlip(pdf, r): def vFlip(pdf, r):
"""vFlip(pdf, range) flips vertically the pages in the range.""" """Flip vertically the pages in the range."""
def crop(pdf, r, x, y, w, h): def crop(pdf, r, x, y, w, h):
"""crop(pdf, range, x, y, w, h) crops a page, replacing any existing """Crop a page to the box defined by (x, y, w, h), replacing any existing
crop box. The dimensions are in points.""" crop box."""
def removeCrop(pdf, r): def removeCrop(pdf, r):
"""removeCrop(pdf, range) removes any crop box from pages in the range.""" """Remove any crop box from pages in the range."""
def removeTrim(pdf, r): def removeTrim(pdf, r):
"""removeTrim(pdf, range) removes any crop box from pages in the range.""" """Remove any trim box from pages in the range."""
def removeArt(pdf, r): def removeArt(pdf, r):
"""removeArt(pdf, range) removes any crop box from pages in the range.""" """Remove any art box from pages in the range."""
def removeBleed(pdf, r): def removeBleed(pdf, r):
"""removeBleed(pdf, range) removes any crop box from pages in the range.""" """Remove any bleed box from pages in the range."""
def trimMarks(pdf, r): def trimMarks(pdf, r):
"""trimMarks(pdf, range) adds trim marks to the given pages, if the trimbox """Add trim marks to the given pages, if the trimbox exists."""
exists."""
def showBoxes(pdf, r): def showBoxes(pdf, r):
"""showBoxes(pdf, range) shows the boxes on the given pages, for debug.""" """Show the boxes on the given pages, for debug."""
def hardBox(pdf, r, boxname): def hardBox(pdf, r, boxname):
"""hardBox make a given box a 'hard box' i.e clips it explicitly.""" """Make a given box a 'hard box' i.e clip it explicitly. Boxname could be,
for example "/TrimBox"."""

View File

@ -1,12 +1,13 @@
# CHAPTER 5. Compression # CHAPTER 5. Compression
def compress(pdf): def compress(pdf):
"""compress(pdf) compresses any uncompressed streams in the given PDF """Compress any uncompressed streams in the given PDF using the Flate
using the Flate algorithm.""" algorithm."""
def decompress(pdf): def decompress(pdf):
"""uncompress(pdf) uncompresses any streams in the given PDF, so long as """Decompress any streams in the given PDF, so long as the compression
the compression method is supported.""" method is supported."""
def squeezeInMemory(pdf): def squeezeInMemory(pdf):
"""squeezeToMemory(pdf) squeezes a pdf in memory.""" """squeezeToMemory(pdf) squeezes a pdf in memory. Squeezing is a lossless
compression method which works be rearrangement of a PDFs internal

View File

@ -1,9 +1,9 @@
# CHAPTER 6. Bookmarks # CHAPTER 6. Bookmarks
def getBookmarks(pdf): def getBookmarks(pdf):
"""Get the bookmarks for a PDF as a list of tuples. """Get the bookmarks for a PDF as a list of tuples of the form:
(level : int, page : int, text : string, openstatus : bool)""" (level : int, page : int, text : string, openstatus : bool)"""
def setBookmarks(pdf, marks): def setBookmarks(pdf, marks):
"""Set the bookmarks for a PDF as a list of tuples. """Set the bookmarks for a PDF as a list of tuples of the form:
(level : int, page : int, text : string, openstatus : bool)""" (level : int, page : int, text : string, openstatus : bool)"""

View File

@ -1,47 +1,25 @@
# CHAPTER 8. Logos, Watermarks and Stamps # CHAPTER 8. Logos, Watermarks and Stamps
def stampOn(pdf, pdf2, r): def stampOn(pdf, pdf2, r):
"""stampOn(stamp_pdf, pdf, range) stamps stamp_pdf on top of all the """Stamps pdf on top of all the pages in pdf2 which are in the range. The
pages in the document which are in the range. The stamp is placed with its stamp is placed with its origin at the origin of the target document."""
origin at the origin of the target document."""
def stampUnder(pdf, pdf2, r): def stampUnder(pdf, pdf2, r):
"""stampUnder(stamp_pdf, pdf, range) stamps stamp_pdf under all the pages """Stamps pdf under under all the pages in pdf2 which are in the range. The
in the document which are in the range. The stamp is placed with its origin stamp is placed with its origin at the origin of the target document."""
at the origin of the target document."""
def stampExtended(pdf, pdf2, r, isover, scale_stamp_to_fit, pos, def stampExtended(pdf, pdf2, r, isover, scale_stamp_to_fit, pos,
relative_to_cropbox): relative_to_cropbox):
"""stampExtended(pdf, pdf2, range, isover, scale_stamp_to_fit, pos, """A stamping function with extra features:
relative_to_cropbox) is a stamping function with extra features.
- isover True, pdf goes over pdf2, isover False, pdf goes under pdf2 - isover True, pdf goes over pdf2, isover False, pdf goes under pdf2
- scale_stamp_to_fit scales the stamp to fit the page - scale_stamp_to_fit scales the stamp to fit the page
- pos gives the position to put the stamp - pos gives the position to put the stamp
- relative_to_cropbox: if True, pos is relative to cropbox not mediabox""" - relative_to_cropbox: if True, pos is relative to crop box not media box"""
def combinePages(pdf, pdf2): def combinePages(pdf, pdf2):
"""combinePages(under, over) combines the PDFs page-by-page, putting """Combines the PDFs page-by-page, putting each page of pdf2 over each page
each page of 'over' over each page of 'under'""" of pdf."""
"""Fonts."""
timesRoman
timesBold
timesItalic
timesBoldItalic
helvetica
helveticaBold
helveticaOblique
helveticaBoldOblique
courier
courierBold
courierOblique
courierBoldOblique
"""Jusitifications."""
leftJustify
centreJustify
rightJustify
def addText(metrics, pdf, r, text, p, line_spacing, bates, font, size, red, def addText(metrics, pdf, r, text, p, line_spacing, bates, font, size, red,
green, blue, underneath, relative_to_cropbox, outline, opacity, green, blue, underneath, relative_to_cropbox, outline, opacity,
@ -105,26 +83,28 @@ def addText(metrics, pdf, r, text, p, line_spacing, bates, font, size, red,
def addTextSimple(pdf, r, text, p, font, size): def addTextSimple(pdf, r, text, p, font, size):
"""like addText, but with most parameters default """like addText, but with most parameters default
* pdf = the document * pdf = the document
* r = the range * r = the range
* text = the text
* p = the position * p = the position
* font = the font * font = the font
* size = the font size""" * size = the font size"""
def removeText(pdf, r): def removeText(pdf, r):
"""removeText(pdf, range) will remove any text added by libcpdf from the """Remove any text added by libcpdf from the given pages."""
given pages.""" r = range_of_list(r)
def textWidth(font, string): def textWidth(font, string):
"""Return the width of a given string in the given font in thousandths of a """Return the width of a given string in the given font in thousandths of a
point.""" point."""
def addContent(content, before, pdf, r): def addContent(content, before, pdf, r):
"""addContent(content, before, range, pdf) adds page content before (if """Add page content before (if True) or after (if False) the existing
True) or after (if False) the existing content to pages in the given range content to pages in the given range in the given PDF. Warning: this a low
in the given PDF.""" level function requiring understanding of the PDF format."""
def stampAsXObject(pdf, r, stamp_pdf): def stampAsXObject(pdf, r, stamp_pdf):
"""stampAsXObject(pdf, range, stamp_pdf) stamps stamp_pdf onto the pages """Stamps stamp_pdf onto the pages in the given range in pdf as a shared
in the given range in pdf as a shared Form XObject. The name of the Form XObject. The name of the newly-created XObject is returned, for use
newly-created XObject is returned.""" with addContent. """

View File

@ -1,30 +1,26 @@
# CHAPTER 9. Mulitpage facilities # CHAPTER 9. Mulitpage facilities
def twoUp(pdf): def twoUp(pdf):
"""Impose a document two up. twoUp does so by retaining the existing page """Impose a document two up by retaining the existing page
size, scaling pages down. twoUpStack does so by doubling the page size, size, scaling pages down."""
to fit two pages on one."""
def twoUpStack(pdf): def twoUpStack(pdf):
"""Impose a document two up. twoUp does so by retaining the existing page """Impose a document two up by doubling the page size,
size, scaling pages down. twoUpStack does so by doubling the page size,
to fit two pages on one.""" to fit two pages on one."""
def padBefore(pdf, r): def padBefore(pdf, r):
"""padBefore(pdf, range) adds a blank page before each page in the given """Adds a blank page before each page in the given range."""
range"""
def padAfter(pdf, r): def padAfter(pdf, r):
"""padAfter(pdf, range) adds a blank page after each page in the given """Adds a blank page after each page in the given range."""
range"""
def padEvery(pdf, n): def padEvery(pdf, n):
"""pageEvery(pdf, n) adds a blank page after every n pages""" """Adds a blank page after every n pages."""
def padMultiple(pdf, n): def padMultiple(pdf, n):
"""padMultiple(pdf, n) adds pages at the end to pad the file to a multiple """Adds pages at the end to pad the file to a multiple of n pages in
of n pages in length.""" length."""
def padMultipleBefore(pdf, n): def padMultipleBefore(pdf, n):
"""padMultiple(pdf, n) adds pages at the beginning to pad the file to a """Adds pages at the beginning to pad the file to a
multiple of n pages in length.""" multiple of n pages in length."""

View File

@ -1,298 +1,265 @@
# CHAPTER 11. Document Information and Metadata # CHAPTER 11. Document Information and Metadata
def isLinearized(filename): def isLinearized(filename):
"""isLinearized(filename) finds out if a document is linearized as quickly """Finds out if a document is linearized as quickly
as possible without loading it.""" as possible without loading it."""
def getVersion(pdf): def getVersion(pdf):
"""vetVersion(pdf) returns the minor version number of a document.""" """Return the minor version number of a document."""
def getMajorVersion(pdf): def getMajorVersion(pdf):
"""getMajorVersion(pdf) returns the minor version number of a document.""" """Return the minor version number of a document."""
def getTitle(pdf): def getTitle(pdf):
"""getTitle(pdf) returns the title of a document.""" """Return the title of a document."""
def getAuthor(pdf): def getAuthor(pdf):
"""getSubject(pdf) returns the subject of a document.""" """Return the subject of a document."""
def getSubject(pdf): def getSubject(pdf):
"""getSubject(pdf) returns the subject of a document.""" """Return the subject of a document."""
def getKeywords(pdf): def getKeywords(pdf):
"""getKeywords(pdf) returns the keywords of a document.""" """Return the keywords of a document."""
def getCreator(pdf): def getCreator(pdf):
"""getCreator(pdf) returns the creator of a document.""" """Return the creator of a document."""
def getProducer(pdf): def getProducer(pdf):
"""getProducer(pdf) returns the producer of a document.""" """Return the producer of a document."""
def getCreationDate(pdf): def getCreationDate(pdf):
"""getCreationDate(pdf) returns the creation date of a document.""" """Return the creation date of a document."""
def getModificationDate(pdf): def getModificationDate(pdf):
"""getModificationDate(pdf) returns the modification date of a document.""" """Return the modification date of a document."""
def getTitleXMP(pdf): def getTitleXMP(pdf):
"""getTitleXMP(pdf) returns the XMP title of a document.""" """Return the XMP title of a document."""
def getAuthorXMP(pdf): def getAuthorXMP(pdf):
"""getAuthorXMP(pdf) returns the XMP author of a document.""" """Return the XMP author of a document."""
def getSubjectXMP(pdf): def getSubjectXMP(pdf):
"""getSubjectXMP(pdf) returns the XMP subject of a document.""" """Return the XMP subject of a document."""
def getKeywordsXMP(pdf): def getKeywordsXMP(pdf):
"""getKeywordsXMP(pdf) returns the XMP keywords of a document.""" """Return the XMP keywords of a document."""
def getCreatorXMP(pdf): def getCreatorXMP(pdf):
"""getCreatorXMP(pdf) returns the XMP creator of a document.""" """Returs the XMP creator of a document."""
def getProducerXMP(pdf): def getProducerXMP(pdf):
"""getProducerXMP(pdf) returns the XMP producer of a document.""" """Return the XMP producer of a document."""
def getCreationDateXMP(pdf): def getCreationDateXMP(pdf):
"""getCreationDateXMP(pdf) returns the XMP creation date of a document.""" """Return the XMP creation date of a document."""
def getModificationDateXMP(pdf): def getModificationDateXMP(pdf):
"""getModificationDateXMP(pdf) returns the XMP modification date of a """Return the XMP modification date of a document."""
document."""
def setTitle(pdf, s): def setTitle(pdf, s):
"""setTitle(pdf) sets the title of a document.""" """Set the title of a document."""
def setAuthor(pdf, s): def setAuthor(pdf, s):
"""setAuthor(pdf) sets the author of a document.""" """Set the author of a document."""
def setSubject(pdf, s): def setSubject(pdf, s):
"""setSubject(pdf) sets the subject of a document.""" """Set the subject of a document."""
def setKeywords(pdf, s): def setKeywords(pdf, s):
"""setKeywords(pdf) sets the keywords of a document.""" """Set the keywords of a document."""
def setCreator(pdf, s): def setCreator(pdf, s):
"""setCreator(pdf) sets the creator of a document.""" """Set the creator of a document."""
def setProducer(pdf, s): def setProducer(pdf, s):
"""setProducer(pdf) sets the producer of a document.""" """Set the producer of a document."""
def setCreationDate(pdf, s): def setCreationDate(pdf, s):
"""setCreationDate(pdf) sets the creation date of a document.""" """Set the creation date of a document."""
def setModificationDate(pdf, s): def setModificationDate(pdf, s):
"""setModificationDate(pdf) sets the modifcation date of a document.""" """Set the modifcation date of a document."""
def setTitleXMP(pdf, s): def setTitleXMP(pdf, s):
"""setTitleXMP(pdf) set the XMP title of a document.""" """Set the XMP title of a document."""
def setAuthorXMP(pdf, s): def setAuthorXMP(pdf, s):
"""setAuthorXMP(pdf) set the XMP author of a document.""" """Set the XMP author of a document."""
def setSubjectXMP(pdf, s): def setSubjectXMP(pdf, s):
"""setSubjectXMP(pdf) set the XMP subject of a document.""" """Set the XMP subject of a document."""
def setKeywordsXMP(pdf, s): def setKeywordsXMP(pdf, s):
"""setKeywordsXMP(pdf) set the XMP keywords of a document.""" """Set the XMP keywords of a document."""
def setCreatorXMP(pdf, s): def setCreatorXMP(pdf, s):
"""setCreatorXMP(pdf) set the XMP creator of a document.""" """Set the XMP creator of a document."""
def setProducerXMP(pdf, s): def setProducerXMP(pdf, s):
"""setProducerXMP(pdf) set the XMP producer of a document.""" """Set the XMP producer of a document."""
def setCreationDateXMP(pdf, s): def setCreationDateXMP(pdf, s):
"""setCreationDateXMP(pdf) set the XMP creation date of a document.""" """Set the XMP creation date of a document."""
def setModificationDateXMP(pdf, s): def setModificationDateXMP(pdf, s):
"""setModificationDateXMP(pdf) set the XMP modification date of a """Set the XMP modification date of a document."""
document."""
def getDateComponents(string): def getDateComponents(string):
"""Dates: Month 1-31, day 1-31, hours (0-23), minutes (0-59), seconds """Return the components (year, month, day, hour, minute, second,
(0-59), hour_offset is the offset from UT in hours (-23 to 23); hour_offset, minute_offset) from a PDF date string.
minute_offset is the offset from UT in minutes (-59 to 59).
getDateComponents(datestring, year, month, day, hour, minute, second, Month 1-31, day 1-31, hours (0-23), minutes (0-59), seconds
hour_offset, minute_offset) returns the components from a PDF date (0-59), hour_offset is the offset from UT in hours (-23 to 23);
string.""" minute_offset is the offset from UT in minutes (-59 to 59)."""
def dateStringOfComponents(cs): def dateStringOfComponents(cs):
"""Dates: Month 1-31, day 1-31, hours (0-23), minutes (0-59), seconds """Build a PDF date string a (year, month, day, hour, minute, second,
hour_offset, minute_offset) tuple.
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); (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). minute_offset is the offset from UT in minutes (-59 to 59)."""
dateStringOfComponents(year, month, day, hour, minute, second,
hour_offset, minute_offset) builds a PDF date string from individual
components."""
def getPageRotation(pdf, pagenumber): def getPageRotation(pdf, pagenumber):
"""getPageRotation(pdf, pagenumber) gets the viewing rotation for a given """Get the viewing rotation for a given page."""
page."""
def hasBox(pdf, pagenumber, boxname): def hasBox(pdf, pagenumber, boxname):
"""hasBox(pdf, pagenumber, boxname) returns True, if that page has the """Returns True, if the page has the given box. E.g "/CropBox" """
given box. E.g "/CropBox" """
def getMediaBox(pdf, pagenumber): def getMediaBox(pdf, pagenumber):
"""These functions get a box given the document, page range, min x, max x, """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 min y, max y in points. Only suceeds if such a box exists, as checked by
hasBox""" hasBox"""
def getCropBox(pdf, pagenumber): def getCropBox(pdf, pagenumber):
"""These functions get a box given the document, page range, min x, max x, """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 min y, max y in points. Only suceeds if such a box exists, as checked by
hasBox""" hasBox"""
def getTrimBox(pdf, pagenumber): def getTrimBox(pdf, pagenumber):
"""These functions get a box given the document, page range, min x, max x, """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 min y, max y in points. Only suceeds if such a box exists, as checked by
hasBox""" hasBox"""
def getArtBox(pdf, pagenumber): def getArtBox(pdf, pagenumber):
"""These functions get a box given the document, page range, min x, max x, """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 min y, max y in points. Only suceeds if such a box exists, as checked by
hasBox""" hasBox"""
def getBleedBox(pdf, pagenumber): def getBleedBox(pdf, pagenumber):
"""These functions get a box given the document, page range, min x, max x, """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 min y, max y in points. Only suceeds if such a box exists, as checked by
hasBox""" hasBox"""
def setMediaBox(pdf, r, minx, maxx, miny, maxy): def setMediaBox(pdf, r, minx, maxx, miny, maxy):
"""These functions set a box given the document, page range, min x, max x, """Set the media box given the document, page range, min x, max x,
min y, max y in points.""" min y, max y in points."""
def setCropBox(pdf, r, minx, maxx, miny, maxy): def setCropBox(pdf, r, minx, maxx, miny, maxy):
"""These functions set a box given the document, page range, min x, max x, """Set the crop box given the document, page range, min x, max x,
min y, max y in points.""" min y, max y in points."""
def setTrimBox(pdf, r, minx, maxx, miny, maxy): def setTrimBox(pdf, r, minx, maxx, miny, maxy):
"""These functions set a box given the document, page range, min x, max x, """Set the trim box given the document, page range, min x, max x,
min y, max y in points.""" min y, max y in points."""
def setArtBox(pdf, r, minx, maxx, miny, maxy): def setArtBox(pdf, r, minx, maxx, miny, maxy):
"""These functions set a box given the document, page range, min x, max x, """Set the art box given the document, page range, min x, max x,
min y, max y in points.""" min y, max y in points."""
def setBleedBox(pdf, r, minx, maxx, miny, maxy): def setBleedBox(pdf, r, minx, maxx, miny, maxy):
"""These functions set a box given the document, page range, min x, max x, """Set the bleed box given the document, page range, min x, max x,
min y, max y in points.""" min y, max y in points."""
def markTrapped(pdf): def markTrapped(pdf):
"""markTrapped(pdf) marks a document as trapped.""" """Mark a document as trapped."""
def markUntrapped(pdf): def markUntrapped(pdf):
"""markUntrapped(pdf) marks a document as untrapped.""" """Mark a document as untrapped."""
def markTrappedXMP(pdf): def markTrappedXMP(pdf):
"""markTrappedXMP(pdf) marks a document as trapped in XMP metadata.""" """Mark a document as trapped in XMP metadata."""
def markUntrappedXMP(pdf): def markUntrappedXMP(pdf):
"""markUntrappedXMP(pdf) marks a document as untrapped in XMP metadata.""" """Mark a document as untrapped in XMP metadata."""
"""Page layouts."""
singlePage
oneColumn
twoColumnLeft
twoColumnRight
twoPageLeft
twoPageRight
def setPageLayout(pdf, layout): def setPageLayout(pdf, layout):
"""setPageLayout(pdf, layout) sets the page layout for a document.""" """Set the page layout for a document."""
"""Page modes."""
useNone
useOutlines
useThumbs
useOC
useAttachments
def setPageMode(pdf, mode): def setPageMode(pdf, mode):
"""setPageMode(pdf, mode) sets the page mode for a document.""" """Set the page mode for a document."""
def hideToolbar(pdf, flag): def hideToolbar(pdf, flag):
"""hideToolbar(pdf, flag) sets the hide toolbar flag""" """Sets the hide toolbar flag."""
def hideMenubar(pdf, flag): def hideMenubar(pdf, flag):
"""hideMenubar(pdf, flag) sets the hide menu bar flag""" """Set the hide menu bar flag."""
def hideWindowUi(pdf, flag): def hideWindowUi(pdf, flag):
"""hideWindowUi(pdf, flag) sets the hide window UI flag""" """Set the hide window UI flag."""
def fitWindow(pdf, flag): def fitWindow(pdf, flag):
"""fitWindow(pdf, flag) sets the fit window flag""" """Set the fit window flag."""
def centerWindow(pdf, flag): def centerWindow(pdf, flag):
"""centerWindow(pdf, flag) sets the center window flag""" """Set the center window flag."""
def displayDocTitle(pdf, flag): def displayDocTitle(pdf, flag):
"""displayDocTitle(pdf, flag) sets the display doc title flag""" """Set the display document title flag."""
def openAtPage(pdf, flag, pagenumber): def openAtPage(pdf, fitflag, pagenumber):
"""openAtPage(pdf, fit, pagenumber)""" """Set the PDF to open, possibly with zoom-to-fit, at the given page
number. """
def setMetadataFromFile(pdf, filename): def setMetadataFromFile(pdf, filename):
"""setMetadataFromFile(pdf, filename) set the XMP metadata of a document, """Set the XMP metadata of a document, given a file name."""
given a file name."""
def setMetadataFromByteArray(pdf, data): def setMetadataFromByteArray(pdf, data):
"""setMetadataFromByteArray(pdf, data, length) set the XMP metadata from """Set the XMP metadata from an array of bytes."""
an array of bytes."""
def getMetadata(pdf): def getMetadata(pdf):
"""getMetadata(pdf, &length) returns the XMP metadata as a byte array of """Return the XMP metadata as a byte array of type bytes"""
type bytes"""
def removeMetadata(pdf): def removeMetadata(pdf):
"""removeMetadata(pdf) removes the XMP metadata from a document""" """Remove the XMP metadata from a document"""
def createMetadata(pdf): def createMetadata(pdf):
"""createMetadata(pdf) builds fresh metadata as best it can from existing """Builds fresh XMP metadata as good as possible from existing
metadata in the document.""" metadata in the document."""
def setMetadataDate(pdf, date): def setMetadataDate(pdf, date):
"""setMetadataDate(pdf, date) sets the metadata date for a PDF. The date """Set the metadata date for a PDF. The date is given in PDF date format --
is given in PDF date format -- cpdf will convert it to XMP format. The date cpdf will convert it to XMP format. The date 'now' means now."""
'now' means now."""
"""Label styles."""
decimalArabic
uppercaseRoman
lowercaseRoman
uppercaseLetters
lowercaseLetters
def getPageLabels(pdf): def getPageLabels(pdf):
"""Get page labels as a list of tuples (style, prefix, offset, startvalue) """Get page labels as a list of tuples (style, prefix, offset, startvalue)
For example, a document might have five pages of introduction with roman For example, a document might have five pages of introduction with roman
numerals, followed by the rest of the pages in decimal arabic, numbered numerals, followed by the rest of the pages in decimal arabic, numbered
from one: from one. First label:
labelstyle = LowercaseRoman * labelstyle = LowercaseRoman
labelprefix = "" * labelprefix = ""
startpage = 1 * startpage = 1
startvalue = 1 * startvalue = 1
labelstyle = DecimalArabic Second label:
labelprefix = ""
startpage = 6 * labelstyle = DecimalArabic
startvalue = 1 """ * labelprefix = ""
* startpage = 6
* startvalue = 1 """
def addPageLabels(pdf, label, progress): def addPageLabels(pdf, label, progress):
"""Add page labels. """Add one group of page labels from a tuple (style, prefix, offset, range).
addPageLabels(pdf, style, prefix, offset, range, progress)
The prefix is prefix text for each label. The range is the page range the 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.""" labels apply to. Offset can be used to shift the numbering up or down."""
def removePageLabels(pdf): def removePageLabels(pdf):
"""removePageLabels(pdf) removes the page labels from the document.""" """Removes all page labels from the document."""
def getPageLabelStringForPage(pdf, pagenumber): def getPageLabelStringForPage(pdf, pagenumber):
"""getPageLabelStringForPage(pdf, page number) calculates the full label """Calculate the full label string for a given page, and return it."""

View File

@ -1,24 +1,23 @@
# CHAPTER 12. File Attachments # CHAPTER 12. File Attachments
def attachFile(filename, pdf): def attachFile(filename, pdf):
"""attachFile(filename, pdf) attaches a file to the pdf. It is attached at """Attach a file to the pdf. It is attached at document level."""
document level."""
def attachFileToPage(filename, pdf, pagenumber): def attachFileToPage(filename, pdf, pagenumber):
"""attachFileToPage(filename, pdf, pagenumber) attaches a file, given its """Attach a file, given its file name, pdf, and the page number to which
file name, pdf, and the page number to which it should be attached.""" it should be attached."""
def attachFileFromMemory(data, filename, pdf): def attachFileFromMemory(data, filename, pdf):
"""attachFileFromMemory(memory, length, filename, pdf) attaches from """Attach a file from a byte array. It is attached at document level."""
memory, just like attachFile."""
def attachFileToPageFromMemory(data, filename, pdf, pagenumber): def attachFileToPageFromMemory(data, filename, pdf, pagenumber):
"""attachFileToPageFromMemory(memory, length, filename, pdf, pagenumber) """Attach a file to a given pag from a byte array. It is attached at
attaches from memory, just like attachFileToPage.""" document level."""
def removeAttachedFiles(pdf): def removeAttachedFiles(pdf):
"""Remove all page- and document-level attachments from a document""" """Remove all page- and document-level attachments from a document."""
def getAttachments(pdf): def getAttachments(pdf):
"""List information about attachements. Returns a list of tuples """List information about attachements. Returns a list of tuples
(name, page number, byte array of data)""" (name, page number, byte array of data). Page 0 = document-level
attachment."""

View File

@ -5,9 +5,8 @@ def getFontInfo(pdf):
showing each font used on each page.""" showing each font used on each page."""
def removeFonts(pdf): def removeFonts(pdf):
"""removeFonts(pdf) removes all font data from a file.""" """Remove all font data from a file."""
def copyFont(pdf, pdf2, r, pagenumber, fontname): def copyFont(pdf, pdf2, r, pagenumber, fontname):
"""copyFont(from, to, range, pagenumber, fontname) copies the given font """Copy the given font from the given page in the pdf PDF to every page in
from the given page in the 'from' PDF to every page in the 'to' PDF. The the pdf2 PDF. The new font is stored under its font name."""
new font is stored under it's font name."""

View File

@ -1,7 +1,6 @@
# CHAPTER 15. PDF and JSON # CHAPTER 15. PDF and JSON
def outputJSON(filename, parse_content, no_stream_data, pdf): def outputJSON(filename, parse_content, no_stream_data, pdf):
"""outputJSON(filename, parse_content, no_stream_data, pdf) outputs a PDF """Output a PDF in JSON format to the given filename. If parse_content is
in JSON format to the given filename. If parse_content is True, page True, page content is parsed. If no_stream_data is True, all stream data is
content is parsed. If no_stream_data is True, all stream data is suppressed suppressed entirely."""
entirely."""

View File

@ -1,10 +1,10 @@
# CHAPTER 16. Optional Content Groups # CHAPTER 16. Optional Content Groups
def getOCGList(pdf): def getOCGList(pdf):
"""Return a list of Optional Content Groups in the given pdf.""" """Return a list of Optional Content Groups in the given pdf as strings."""
def OCGRename(pdf, n_from, n_to): def OCGRename(pdf, n_from, n_to):
"""OCGRename(pdf, n_from, n_to) will rename an optional content group.""" """Rename an optional content group."""
def OCGOrderAll(pdf): def OCGOrderAll(pdf):
"""Ensure that every optional content group appears in the OCG order list.""" """Ensure that every optional content group appears in the OCG order list."""

View File

@ -1,43 +1,41 @@
# CHAPTER 17. Miscellaneous # CHAPTER 17. Miscellaneous
def draft(pdf, r, boxes): def draft(pdf, r, boxes):
"""draft(pdf, range, boxes) removes images on the given pages, replacing """Remove images on the given pages, replacing
them with crossed boxes if 'boxes' is true""" them with crossed boxes if 'boxes' is True."""
def removeAllText(pdf, r): def removeAllText(pdf, r):
"""removeAllText(pdf, range) removes all text from the given pages in a """Remove all text from the given pages in a document."""
given document."""
def blackText(pdf, r): def blackText(pdf, r):
"""blackText(pdf, range) blackens all text on the given pages.""" """Blacken all text on the given pages."""
def blackLines(pdf, r): def blackLines(pdf, r):
"""blackLines(pdf, range) blackens all lines on the given pages.""" """Blacken all lines on the given pages."""
def blackFills(pdf, r): def blackFills(pdf, r):
"""blackFills(pdf, range) blackens all fills on the given pages.""" """Blacken all fills on the given pages."""
def thinLines(pdf, r, linewidth): def thinLines(pdf, r, linewidth):
"""thinLines(pdf, range, min_thickness) thickens every line less than """Thicken every line less than
min_thickness to min_thickness. Thickness given in points.""" linewidth to linewidth. Thickness given in points."""
def copyId(pdf, pdf2): def copyId(pdf, pdf2):
"""copyId(from, to) copies the /ID from one document to another.""" """Copy the /ID from one pdf to pdf2."""
def removeId(pdf): def removeId(pdf):
"""removeId(pdf) removes a document's /ID""" """Remove a document's /ID"""
def setVersion(pdf, version): def setVersion(pdf, version):
"""setVersion(pdf, version) sets the minor version number of a document.""" """Set the minor version number of a document."""
def setFullVersion(pdf, major, minor): def setFullVersion(pdf, major, minor):
"""setFullVersion(pdf, version) sets the major and minor version number of """Set the major and minor version number of
a document.""" a document."""
def removeDictEntry(pdf, key): def removeDictEntry(pdf, key):
"""removeDictEntry(pdf, key) removes any dictionary entry with the given """Remove any dictionary entry with the given
key anywhere in the document""" key anywhere in the document."""
def removeClipping(pdf, r): def removeClipping(pdf, r):
"""removeClipping(pdf, range) removes all clipping from pages in the given """Remove all clipping from pages in the given range"""
range"""