forked from josch/img2pdf
It is easy enough to create a separate class for the Py2 version.
This commit is contained in:
parent
719928f5f5
commit
06560cd0d4
1 changed files with 23 additions and 11 deletions
|
@ -29,6 +29,8 @@ from enum import Enum
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
PY3 = sys.version_info[0] >= 3
|
||||||
|
|
||||||
__version__ = "0.2.3"
|
__version__ = "0.2.3"
|
||||||
default_dpi = 96.0
|
default_dpi = 96.0
|
||||||
papersizes = {
|
papersizes = {
|
||||||
|
@ -269,6 +271,7 @@ class MyPdfWriter():
|
||||||
self.addobj(page)
|
self.addobj(page)
|
||||||
|
|
||||||
|
|
||||||
|
if PY3:
|
||||||
class MyPdfString():
|
class MyPdfString():
|
||||||
@classmethod
|
@classmethod
|
||||||
def encode(cls, string):
|
def encode(cls, string):
|
||||||
|
@ -280,6 +283,15 @@ class MyPdfString():
|
||||||
string = string.replace(b'(', b'\\(')
|
string = string.replace(b'(', b'\\(')
|
||||||
string = string.replace(b')', b'\\)')
|
string = string.replace(b')', b'\\)')
|
||||||
return b'(' + string + b')'
|
return b'(' + string + b')'
|
||||||
|
else:
|
||||||
|
class MyPdfString(object):
|
||||||
|
@classmethod
|
||||||
|
def encode(cls, string):
|
||||||
|
# This mimics exactely to what pdfrw does.
|
||||||
|
string = string.replace(b'\\', b'\\\\')
|
||||||
|
string = string.replace(b'(', b'\\(')
|
||||||
|
string = string.replace(b')', b'\\)')
|
||||||
|
return b'(' + string + b')'
|
||||||
|
|
||||||
|
|
||||||
class pdfdoc(object):
|
class pdfdoc(object):
|
||||||
|
|
Loading…
Reference in a new issue