forked from py-pdf/pypdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This reverts commit f72745e.
- Loading branch information
Showing
9 changed files
with
113 additions
and
1,239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
from .pdf import PdfFileReader, PdfFileWriter | ||
from .generic import * | ||
from .merger import PdfFileMerger | ||
from .pagerange import PageRange | ||
from ._version import __version__ | ||
from pypdf.pdf import PdfFileReader, PdfFileWriter | ||
from pypdf.merger import PdfFileMerger | ||
from pypdf.pagerange import PageRange | ||
from pypdf._version import __version__ | ||
|
||
|
||
__all__ = [ | ||
# Basic PyPDF elements | ||
"PdfFileReader", "PdfFileWriter", "PdfFileMerger", "PageRange", | ||
# most used elements from generic | ||
"BooleanObject","ArrayObject","IndirectObject","FloatObject","NumberObject","createStringObject", | ||
"TextStringObject","NameObject","DictionaryObject","TreeObject","Destination","PageLabel","Bookmark", | ||
# PyPDF modules | ||
"pdf", "generic", "utils", "filters", "merger", "pagerange", "xmp" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '1.27.0PPzz' | ||
__version__ = '1.27.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,9 +38,8 @@ | |
import warnings | ||
from io import BytesIO | ||
|
||
#from . import utils | ||
from .utils import * | ||
from .utils import pypdfUnicode as u_, pypdfBytes as b_ | ||
from pypdf.utils import * | ||
from pypdf.utils import pypdfBytes as b_, pypdfUnicode as u_ | ||
|
||
__author__ = "Mathieu Fenniak" | ||
__author_email__ = "[email protected]" | ||
|
@@ -99,10 +98,6 @@ def getObject(self): | |
"""Resolves indirect references.""" | ||
return self | ||
|
||
def clone(self,pdfD): #PPzz | ||
""" clone object into pdfD """ | ||
raise Exception("clone PdfObject") | ||
return self | ||
|
||
# TO-DO Add __repr_() implementations to the *Object classes | ||
class NullObject(PdfObject): | ||
|
@@ -119,19 +114,10 @@ def readFromStream(stream): | |
return NullObject() | ||
|
||
|
||
def clone(self,pdfD): #PPzz | ||
""" clone object into pdfD """ | ||
return NullObject() | ||
|
||
|
||
class BooleanObject(PdfObject): | ||
def __init__(self, value): | ||
self.value = value | ||
|
||
def clone(self,pdfD): #PPzz | ||
""" clone object into pdfD """ | ||
return BooleanObject(self.value) | ||
|
||
def writeToStream(self, stream, encryption_key): | ||
if self.value: | ||
stream.write(b_("true")) | ||
|
@@ -153,17 +139,6 @@ def readFromStream(stream): | |
|
||
|
||
class ArrayObject(list, PdfObject): | ||
|
||
def clone(self,pdfD): #PPzz | ||
""" clone object into pdfD """ | ||
arr = ArrayObject() | ||
for data in self: | ||
if 'clone' in dir(data): | ||
arr.append(data.clone(pdfD)) | ||
else: | ||
arr.append(data) | ||
return arr | ||
|
||
def writeToStream(self, stream, encryption_key): | ||
stream.write(b_("[")) | ||
|
||
|
@@ -221,22 +196,6 @@ def __init__(self, idnum, generation, pdf): | |
self.generation = generation | ||
self.pdf = pdf | ||
|
||
def clone(self,pdfD): #PPzz | ||
""" clone object into pdfD """ | ||
try: pdfD._IdTranslated | ||
except: | ||
pdfD._IdTranslated={} | ||
try: | ||
n=pdfD._IdTranslated[self.idnum] | ||
except: | ||
n=len(pdfD._objects)+1 | ||
pdfD._IdTranslated[self.idnum]=n | ||
pdfD._objects.append("%d NotInit"%n) | ||
o=self.getObject().clone(pdfD) | ||
pdfD._objects[n-1]=o | ||
|
||
return IndirectObject(n,0,pdfD) | ||
|
||
def getObject(self): | ||
return self.pdf.getObject(self).getObject() | ||
|
||
|
@@ -306,10 +265,6 @@ def __new__(cls, value="0", context=None): | |
except: | ||
return decimal.Decimal.__new__(cls, str(value)) | ||
|
||
def clone(self,pdfD): #PPzz | ||
""" clone object into pdfD """ | ||
return FloatObject(self.asNumeric()) | ||
|
||
def __repr__(self): | ||
if self == self.to_integral(): | ||
return str(self.quantize(decimal.Decimal(1))) | ||
|
@@ -339,10 +294,6 @@ def __new__(cls, value): | |
except OverflowError: | ||
return int.__new__(cls, 0) | ||
|
||
def clone(self,pdfD): #PPzz | ||
""" clone object into pdfD """ | ||
return NumberObject(self.asNumeric()) | ||
|
||
def asNumeric(self): | ||
return int(b_(repr(self))) | ||
|
||
|
@@ -493,10 +444,6 @@ class ByteStringObject(bytes_type, PdfObject): | |
# returns self. | ||
original_bytes = property(lambda self: self) | ||
|
||
def clone(self,pdfD): #PPzz | ||
""" clone object into pdfD """ | ||
return ByteStringObject(self) | ||
|
||
def writeToStream(self, stream, encryption_key): | ||
bytearr = self | ||
|
||
|
@@ -524,10 +471,6 @@ class TextStringObject(string_type, PdfObject): | |
# back-calculate what the original encoded bytes were. | ||
original_bytes = property(lambda self: self.getOriginalBytes()) | ||
|
||
def clone(self,pdfD): #PPzz | ||
""" clone object into pdfD """ | ||
return createStringObject(self) | ||
|
||
def getOriginalBytes(self): | ||
# We're a text string object, but the library is trying to get our raw | ||
# bytes. This can happen if we auto-detected this string as text, but | ||
|
@@ -570,10 +513,6 @@ class NameObject(str, PdfObject): | |
delimiterPattern = re.compile(b_(r"\s+|[\(\)<>\[\]{}/%]")) | ||
surfix = b_("/") | ||
|
||
def clone(self,pdfD): #PPzz | ||
""" clone object into pdfD """ | ||
return NameObject(self) | ||
|
||
def writeToStream(self, stream, encryption_key): | ||
stream.write(b_(self)) | ||
|
||
|
@@ -610,15 +549,6 @@ def readFromStream(stream, pdf): | |
|
||
|
||
class DictionaryObject(dict, PdfObject): | ||
|
||
def clone(self,pdfD): #PPzz | ||
""" clone object into pdfD """ | ||
d=DictionaryObject() | ||
for k,v in self.items(): | ||
d.update({(k.clone(k) if 'clone' in dir(k) else k): | ||
(v.clone(pdfD) if 'clone' in dir(v) else v) }) | ||
return d | ||
|
||
def rawGet(self, key): | ||
return dict.__getitem__(self, key) | ||
|
||
|
@@ -804,15 +734,7 @@ def readFromStream(stream, pdf): | |
|
||
class TreeObject(DictionaryObject): | ||
def __init__(self): | ||
DictionaryObject.__init__(self) | ||
|
||
def clone(self,pdfD): #PPzz | ||
""" clone object into pdfD """ | ||
raise Exception("clone TreeObject",self) | ||
obj=TreeObject() | ||
for k,v in self.items(): | ||
obj.addChild(v.clone(pdfD),pdfD) | ||
return obj | ||
DictionaryObject.__init__() | ||
|
||
def hasChildren(self): | ||
return '/First' in self | ||
|
@@ -953,14 +875,6 @@ def __init__(self): | |
self._data = None | ||
self.decodedSelf = None | ||
|
||
def clone(self,pdfD): #PPzz | ||
""" clone object into pdfD """ | ||
st=self.__class__() | ||
st._data=self._data | ||
st.decodedSelf=self.decodedSelf | ||
st.update(self) | ||
return self | ||
|
||
def writeToStream(self, stream, encryption_key): | ||
self[NameObject("/Length")] = NumberObject(len(self._data)) | ||
DictionaryObject.writeToStream(self, stream, encryption_key) | ||
|
@@ -992,7 +906,7 @@ def initializeFromDictionary(data): | |
return retval | ||
|
||
def flateEncode(self): | ||
from .filters import FlateCodec | ||
from pypdf.filters import FlateCodec | ||
|
||
if "/Filter" in self: | ||
f = self["/Filter"] | ||
|
@@ -1020,7 +934,7 @@ def __init__(self): | |
self.decodedSelf = None | ||
|
||
def getData(self): | ||
from .filters import decodeStreamData | ||
from pypdf.filters import decodeStreamData | ||
|
||
if self.decodedSelf: | ||
# Cached version of decoded object | ||
|
@@ -2184,7 +2098,6 @@ def __init__(self, title, page, typ, *args): | |
self[NameObject("/Title")] = title | ||
self[NameObject("/Page")] = page | ||
self[NameObject("/Type")] = typ | ||
self.parent=None #PPzz | ||
|
||
# from table 8.2 of the PDF 1.7 reference. | ||
if typ == "/XYZ": | ||
|
@@ -2282,106 +2195,6 @@ def writeToStream(self, stream, encryption_key): | |
:rtype: ``int``, or ``None`` if not available. | ||
""" | ||
|
||
class PageLabel(): | ||
def __init__(self,pn=0,defObject=None): | ||
""" | ||
:param | ||
integer pn: 1st Page of the group | ||
defObject: tuple (1stPage,prefix,increment) or DictionnaryObject from the file | ||
""" | ||
|
||
if defObject is None: | ||
defObject = DictionaryObject() | ||
|
||
try: | ||
if type(defObject) != tuple: | ||
self.prefix=defObject['/P'] | ||
else: | ||
self.prefix=defObject[1]+""#None will induce and error and reach default value | ||
except: | ||
self.prefix='' | ||
|
||
try: | ||
if type(defObject) != tuple: | ||
self.numbering=defObject['/S'] | ||
else: | ||
self.numbering=defObject[2]+""#None will induce and error and reach default value | ||
except: | ||
self.numbering='/D' if self.prefix == "" else "" | ||
|
||
self.pn=pn #1st page of the range | ||
try: | ||
if type(defObject) != tuple: | ||
self.first=int(defObject['/St'])-pn | ||
else: | ||
self.first=max(1,int(defObject[0]))-pn #None will induce and error and reach default value | ||
except: | ||
self.first=1-pn | ||
|
||
def __repr__(self): | ||
return "PageLabel Obj(@%r :%s-%s)" % (self.first, self.prefix, self.numbering) | ||
|
||
def buildDefinition(self,pn=None): | ||
""" | ||
build the DictionnaryObjecgt to inject into the PDF | ||
""" | ||
o=DictionaryObject() | ||
if self.numbering!='/D' or self.prefix!='': | ||
o.update({ NameObject("/S"):NameObject(self.numbering) }) | ||
if self.prefix!='': | ||
o.update({ NameObject("/P"):NameObject(self.prefix) }) | ||
if pn==None: | ||
o.update({ NameObject("/St"):NumberObject(self.first+self.pn) }) | ||
elif pn==0: | ||
pass; #No start value | ||
else: | ||
o.update({ NameObject("/St"):NumberObject(pn) }) | ||
return o | ||
|
||
def getLabel(self,pn): | ||
def int_to_Roman(num): | ||
val = [ | ||
1000, 900, 500, 400, | ||
100, 90, 50, 40, | ||
10, 9, 5, 4, | ||
1 | ||
] | ||
syb = [ | ||
"M", "CM", "D", "CD", | ||
"C", "XC", "L", "XL", | ||
"X", "IX", "V", "IV", | ||
"I" | ||
] | ||
roman_num = '' | ||
i = 0 | ||
while num > 0: | ||
for _ in range(num // val[i]): | ||
roman_num += syb[i] | ||
num -= val[i] | ||
i += 1 | ||
return roman_num | ||
|
||
def int_to_Alpha(num): | ||
t="" | ||
while(num>0): | ||
num=num-1 | ||
t=chr(num%26+65)+t | ||
num=num//26 | ||
return t | ||
if self.numbering=='/D': | ||
st=str(pn+self.first) | ||
elif self.numbering=='/R': | ||
st=int_to_Roman(pn+self.first) | ||
elif self.numbering=='/r': | ||
st=int_to_Roman(pn+self.first).lower() | ||
elif self.numbering=='/A': | ||
st=int_to_Alpha(pn+self.first) | ||
elif self.numbering=='/a': | ||
st=int_to_Alpha(pn+self.first).lower() | ||
else: | ||
st='' | ||
return self.prefix+st | ||
|
||
|
||
class Bookmark(Destination): | ||
def writeToStream(self, stream, encryption_key): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.