2024-04-17 01:59:48 +02:00
|
|
|
"""
|
2021-09-01 19:41:10 +02:00
|
|
|
Loading the libpypcdf and libcpdf DLLs
|
|
|
|
--------------------------------------
|
2021-07-26 20:50:33 +02:00
|
|
|
|
2021-09-01 19:41:10 +02:00
|
|
|
Before using the library, you must load the ``libpycpdf`` and ``libcpdf`` DLLs.
|
2021-09-26 17:24:19 +02:00
|
|
|
This is achieved with the ``pycpdflib.loadDLL`` function, given the filename or
|
2021-09-01 19:41:10 +02:00
|
|
|
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
|
|
|
|
-----------
|
|
|
|
|
2024-04-17 01:59:48 +02:00
|
|
|
Any function may raise the exception ``CPDFError``, carrying a string
|
|
|
|
describing the error.
|
2021-09-01 19:41:10 +02:00
|
|
|
|
|
|
|
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
|
2024-04-17 01:59:48 +02:00
|
|
|
|
|
|
|
Line cap types:
|
|
|
|
|
|
|
|
capButt capRound capSquare
|
|
|
|
|
|
|
|
Line join types:
|
|
|
|
|
|
|
|
joinMiter joinRound joinBevel
|
2022-01-23 14:06:53 +01:00
|
|
|
"""
|
2021-08-10 14:40:37 +02:00
|
|
|
|
2024-04-17 01:59:48 +02:00
|
|
|
# CHAPTER 0. Preliminaries
|
|
|
|
|
2021-08-10 14:40:37 +02:00
|
|
|
class Pdf:
|
|
|
|
"""The type of PDF documents."""
|
|
|
|
|
2021-09-01 19:41:10 +02:00
|
|
|
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."""
|
|
|
|
|
2021-08-10 14:40:37 +02:00
|
|
|
class CPDFError(Exception):
|
|
|
|
"""Any function may raise an exception CPDFError, carrying a string
|
2021-09-01 19:41:10 +02:00
|
|
|
describing what went wrong."""
|
2021-08-10 14:40:37 +02:00
|
|
|
|
|
|
|
def lastError():
|
|
|
|
"""Return the last error. Not usually used directly, since pycpdflib
|
|
|
|
functions raise exceptions."""
|
|
|
|
|
|
|
|
def lastErrorString():
|
|
|
|
"""Return the last error string. Not usually used directly, since pycpdflib
|
|
|
|
functions raise exceptions."""
|
|
|
|
|
|
|
|
def checkerror():
|
|
|
|
"""Raise an exception if the last function call resulted in an error. Not
|
|
|
|
used directly, since pycpdflib functions will raise the exception
|
|
|
|
directly."""
|
|
|
|
|
|
|
|
def version():
|
2021-09-01 19:41:10 +02:00
|
|
|
"""Return the version number of the pycpdflib library."""
|
2021-08-10 14:40:37 +02:00
|
|
|
|
|
|
|
def setFast():
|
2024-04-17 01:59:48 +02:00
|
|
|
"""Set fast mode. Some operations have a fast mode. The default is 'slow'
|
2021-09-01 19:41:10 +02:00
|
|
|
mode, which works even on old-fashioned files. For more details, see
|
2024-04-17 01:59:48 +02:00
|
|
|
section 1.13 of the CPDF manual. This function sets the mode globally."""
|
2021-08-10 14:40:37 +02:00
|
|
|
|
|
|
|
def setSlow():
|
2024-04-17 01:59:48 +02:00
|
|
|
"""Set slow mode. Some operations have a fast mode. The default is 'slow'
|
2021-09-01 19:41:10 +02:00
|
|
|
mode, which works even on old-fashioned files. For more details, see
|
2024-04-17 01:59:48 +02:00
|
|
|
section 1.13 of the CPDF manual. This function sets the mode globally."""
|
|
|
|
|
|
|
|
def embedStd14(embed):
|
|
|
|
"""Calling this function with a true argument sets embedding for the
|
|
|
|
Standard 14 fonts. You must also set the directory to load them from with
|
|
|
|
the embedStd14Dir function. Default value: False."""
|
|
|
|
|
|
|
|
def embedStd14Dir(d):
|
|
|
|
"""Set the directory to load Standard 14 fonts for embedding."""
|
|
|
|
libc.pycpdf_embedStd14Dir(str.encode(d))
|
2021-08-10 14:40:37 +02:00
|
|
|
|
|
|
|
def clearError():
|
2024-04-17 01:59:48 +02:00
|
|
|
"""Clear the current error state."""
|
2021-08-10 14:40:37 +02:00
|
|
|
|
|
|
|
def onExit():
|
2024-04-17 01:59:48 +02:00
|
|
|
"""A debug function which prints some information about
|
2021-08-10 14:40:37 +02:00
|
|
|
resource usage. This can be used to detect if PDFs or ranges are being
|
|
|
|
deallocated properly."""
|