update python splits

This commit is contained in:
John Whitington 2022-01-23 13:06:53 +00:00
parent 3988de1cea
commit 0f52366328
9 changed files with 71 additions and 23 deletions

View File

@ -79,9 +79,7 @@ useNone useOutlines useThumbs useOC useAttachments
Page label styles:
decimalArabic uppercaseRoman lowercaseRoman uppercaseLetters lowercaseLetters
# CHAPTER 0. Preliminaries
"""
class Pdf:
"""The type of PDF documents."""

View File

@ -25,6 +25,16 @@ def blankDocument(w, h, pages):
with pages of the given width (in points), height (in points), and number
of pages."""
def textToPDF(w, h, font, fontsize, filename):
"""textToPDF(w, h, font, fontsize, filename) typesets a UTF8 text file
ragged right on a page of size w * h in points in the given font and font
size."""
def textToPDFPaper(papersize, font, fontsize, filename):
"""textToPDF(papersize font, fontsize, filename) typesets a UTF8 text file
ragged right on a page of the given size in the given font and font
size."""
def blankDocumentPaper(papersize, pages):
"""Create a blank document with pages of the given paper size, and number
of pages. """
@ -48,9 +58,9 @@ def inOfPt(i):
"""Convert a figure in points to inches (72 points to 1 inch)."""
def parsePagespec(pdf, pagespec):
"""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
which do not exist are rejected)."""
"""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 which do not exist are rejected)."""
def validatePagespec(pagespec):
"""Validate a page specification, returning True or False, so far as is
@ -95,6 +105,7 @@ def rangeLength(r):
def rangeGet(r, n):
"""Get the page number at position n in a range, where
n runs from 0 to rangeLength - 1."""
def rangeAdd(r, p):
"""Add the page to a range, if it is not already
@ -105,9 +116,6 @@ def isInRange(r, p):
def pages(pdf):
"""Return the number of pages in a PDF."""
r = libc.pycpdf_pages(pdf.pdf)
checkerror()
return r
def pagesFast(userpw, filename):
"""Return the number of pages in a given
@ -129,16 +137,12 @@ def toFileExt(pdf, filename, linearize, make_id, preserve_objstm,
will be compressed (what we usually want). WARNING: the pdf argument will
be invalid after this call and should not be used again."""
def toMemory(pdf, linearize, make_id):
"""Write a file to memory, returning the buffer as a byte array of type
bytes."""
def isEncrypted(pdf):
"""Returns True if a documented is encrypted, False otherwise."""
r = libc.pycpdf_isEncrypted(pdf.pdf)
checkerror()
return r
def toFileEncrypted(pdf, method, permissions, ownerpw, userpw, linearize,
makeid, filename):

View File

@ -7,3 +7,14 @@ def getBookmarks(pdf):
def setBookmarks(pdf, marks):
"""Set the bookmarks for a PDF as a list of tuples of the form:
(level : int, page : int, text : string, openstatus : bool)"""
def getBookmarksJSON(pdf):
"""Get the bookmarks in JSON format."""
def setBookmarksJSON(pdf, data):
"""setBookmarksJSON(pdf, data) sets the bookmarks from JSON bookmark data."""
def tableOfContents(pdf, font, fontsize, title, bookmark):
"""tableOfContents(pdf, font, fontsize, title, bookmark) typesets a table
of contents from existing bookmarks and prepends it to the document. If
bookmark is set, the table of contents gets its own bookmark."""

View File

@ -93,7 +93,6 @@ def addTextSimple(pdf, r, text, p, font, size):
def removeText(pdf, r):
"""Remove any text added by libcpdf from the given pages."""
r = range_of_list(r)
def textWidth(font, string):
"""Return the width of a given string in the given font in thousandths of a

View File

@ -1,4 +1,4 @@
# CHAPTER 9. Mulitpage facilities
# CHAPTER 9. Multipage facilities
def twoUp(pdf):
"""Impose a document two up by retaining the existing page
@ -8,6 +8,14 @@ def twoUpStack(pdf):
"""Impose a document two up by doubling the page size,
to fit two pages on one."""
def impose(pdf, x, y, fit, columns, rtl, btt, center, margin, spacing, linewidth):
"""impose(pdf, x, y, fit, columns, rtl, btt, center, margin, spacing,
linewidth) imposes a PDF. There are two modes: imposing x * y, or imposing
to fit a page of size x * y. This is controlled by fit. Columns imposes by
columns rather than rows. rtl is right-to-left, btt bottom-to-top. Center
is unused for now. Margin is the margin around the output, spacing the
spacing between imposed inputs."""
def padBefore(pdf, r):
"""Adds a blank page before each page in the given range."""

View File

@ -1,3 +1,4 @@
# CHAPTER 10. Annotations
# Not in the library version.
def annotationsJSON(pdf):
"""Get the annotations in JSON format."""

View File

@ -47,7 +47,7 @@ def getKeywordsXMP(pdf):
"""Return the XMP keywords of a document."""
def getCreatorXMP(pdf):
"""Returs the XMP creator of a document."""
"""Return the XMP creator of a document."""
def getProducerXMP(pdf):
"""Return the XMP producer of a document."""
@ -117,7 +117,7 @@ def getDateComponents(string):
def dateStringOfComponents(cs):
"""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);
minute_offset is the offset from UT in minutes (-59 to 59)."""
@ -210,8 +210,8 @@ def displayDocTitle(pdf, flag):
"""Set the display document title flag."""
def openAtPage(pdf, fitflag, pagenumber):
"""Set the PDF to open, possibly with zoom-to-fit, at the given page
number. """
"""Set the PDF to open, possibly with zoom-to-fit, at the given page number.
"""
def setMetadataFromFile(pdf, filename):
"""Set the XMP metadata of a document, given a file name."""

View File

@ -1,6 +1,17 @@
# CHAPTER 15. PDF and JSON
def outputJSON(filename, parse_content, no_stream_data, pdf):
def outputJSON(filename, parse_content, no_stream_data, decompress_streams, pdf):
"""Output a PDF in JSON format to the given filename. If parse_content is
True, page content is parsed. If no_stream_data is True, all stream data is
suppressed entirely."""
True, page content is parsed. If decompress_streams is True, streams are
decompressed. If no_stream_data is True, all stream data is suppressed
entirely."""
def outputJSONMemory(pdf, parse_content, no_stream_data, decompress_streams):
"""outputJSONMemory(pdf, parse_content, no_stream_data, decompress_stream)
is like outputJSON, but it write to a buffer in memory)."""
def fromJSON(filename):
"""Load a PDF from a JSON file given its filename."""
def fromJSONMemory(data):
""" Load a PDF from JSON data in memory."""

View File

@ -37,5 +37,21 @@ def removeDictEntry(pdf, key):
"""Remove any dictionary entry with the given
key anywhere in the document."""
def removeDictEntrySearch(pdf, key, searchterm):
"""Remove any dictionary entry with the given
key anywhere in the document, if its value matches the given search term."""
def replaceDictEntry(pdf, key, newvalue):
"""Replace any dictionary entry with the given
key anywhere in the document using the new value given."""
def replaceDictEntrySearch(pdf, key, newvalue, searchterm):
"""Replace any dictionary entry with the given key anywhere in the
document, if its value matches the given search term, with the new value
given."""
def getDictEntries(pdf, key):
"""Return JSON of any dict entries with the given key."""
def removeClipping(pdf, r):
"""Remove all clipping from pages in the given range"""