cpdf-source/pysplits/c01.tex

130 lines
3.7 KiB
TeX
Raw Normal View History

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.
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
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():
2021-09-01 19:41:10 +02:00
""" Set fast mode. Some operations have a fast mode. The default is 'slow'
mode, which works even on old-fashioned files. For more details, see
section 1.13 of the CPDF manual. This function sets the mode globally. """
2021-08-10 14:40:37 +02:00
def setSlow():
2021-09-01 19:41:10 +02:00
""" Set slow mode. Some operations have a fast mode. The default is 'slow'
mode, which works even on old-fashioned files. For more details, see
section 1.13 of the CPDF manual. This function sets the mode globally. """
2021-08-10 14:40:37 +02:00
def clearError():
2021-09-01 19:41:10 +02:00
""" Clear the current error state. """
2021-08-10 14:40:37 +02:00
def onExit():
2021-09-01 19:41:10 +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."""