Ejemplo n.º 1
0
##  ColorSpace
##
class ColorSpace:
    def __init__(self, name, ncomponents):
        self.name = name
        self.ncomponents = ncomponents
        return

    def __repr__(self):
        return "<ColorSpace: %s, ncomponents=%d>" % (self.name, self.ncomponents)


##  Constants
##
LITERAL_PDF = PSLiteralTable.intern("PDF")
LITERAL_TEXT = PSLiteralTable.intern("Text")
LITERAL_FONT = PSLiteralTable.intern("Font")
LITERAL_FORM = PSLiteralTable.intern("Form")
LITERAL_IMAGE = PSLiteralTable.intern("Image")
LITERAL_STANDARD_ENCODING = PSLiteralTable.intern("StandardEncoding")
LITERAL_DEVICE_GRAY = PSLiteralTable.intern("DeviceGray")
LITERAL_DEVICE_RGB = PSLiteralTable.intern("DeviceRGB")
LITERAL_DEVICE_CMYK = PSLiteralTable.intern("DeviceCMYK")
KEYWORD_BI = PSKeywordTable.intern("BI")
KEYWORD_ID = PSKeywordTable.intern("ID")
KEYWORD_EI = PSKeywordTable.intern("EI")
MATRIX_IDENTITY = (1, 0, 0, 1, 0, 0)

PREDEFINED_COLORSPACE = dict(
    (name, ColorSpace(name, n))
Ejemplo n.º 2
0
from cmap import CMap, CMapDB, CMapParser, FontMetricsDB, EncodingDB
from utils import apply_matrix_norm

##  Fonts
##


class PDFFontError(PDFException):
    pass


class PDFUnicodeNotDefined(PDFFontError):
    pass


LITERAL_STANDARD_ENCODING = PSLiteralTable.intern('StandardEncoding')


# PDFFont
class PDFFont(object):
    def __init__(self, descriptor, widths, default_width=None):
        self.descriptor = descriptor
        self.widths = widths
        self.fontname = descriptor.get('FontName', 'unknown')
        if isinstance(self.fontname, PSLiteral):
            self.fontname = literal_name(self.fontname)
        self.ascent = num_value(descriptor.get('Ascent', 0))
        self.descent = num_value(descriptor.get('Descent', 0))
        self.default_width = default_width or descriptor.get('MissingWidth', 0)
        self.leading = num_value(descriptor.get('Leading', 0))
        self.bbox = list_value(descriptor.get('FontBBox', (0, 0, 0, 0)))
Ejemplo n.º 3
0
#!/usr/bin/env python
import sys
stderr = sys.stderr
#from pdflib.psparser import PSLiteralTable
from psparser import PSLiteralTable


##  ColorSpace
##
LITERAL_DEVICE_GRAY = PSLiteralTable.intern('DeviceGray')
LITERAL_DEVICE_RGB = PSLiteralTable.intern('DeviceRGB')
LITERAL_DEVICE_CMYK = PSLiteralTable.intern('DeviceCMYK')

class ColorSpace(object):
  
  def __init__(self, name, ncomponents):
    self.name = name
    self.ncomponents = ncomponents
    return
  
  def __repr__(self):
    return '<ColorSpace: %s, ncomponents=%d>' % (self.name, self.ncomponents)


PREDEFINED_COLORSPACE = dict(
  (name, ColorSpace(name,n)) for (name,n) in {
  'CalRGB': 3,
  'CalGray': 1,
  'Lab': 3,
  'DeviceRGB': 3,
  'DeviceCMYK': 4,
Ejemplo n.º 4
0
     PSStackParser, STRICT


##  PDF Exceptions
##
class PDFException(PSException): pass
class PDFSyntaxError(PDFException): pass
class PDFEncryptionError(PDFException): pass
class PDFPasswordIncorrect(PDFEncryptionError): pass
class PDFTypeError(PDFException): pass
class PDFValueError(PDFException): pass
class PDFNotImplementedError(PSException): pass


# some predefined literals and keywords.
LITERAL_OBJSTM = PSLiteralTable.intern('ObjStm')
LITERAL_XREF = PSLiteralTable.intern('XRef')
LITERAL_PAGE = PSLiteralTable.intern('Page')
LITERAL_PAGES = PSLiteralTable.intern('Pages')
LITERAL_CATALOG = PSLiteralTable.intern('Catalog')
LITERAL_CRYPT = PSLiteralTable.intern('Crypt')
LITERAL_FLATE_DECODE = PSLiteralTable.intern('FlateDecode')
LITERAL_LZW_DECODE = PSLiteralTable.intern('LZWDecode')
KEYWORD_R = PSKeywordTable.intern('R')
KEYWORD_OBJ = PSKeywordTable.intern('obj')
KEYWORD_ENDOBJ = PSKeywordTable.intern('endobj')
KEYWORD_STREAM = PSKeywordTable.intern('stream')
KEYWORD_XREF = PSKeywordTable.intern('xref')
KEYWORD_TRAILER = PSKeywordTable.intern('trailer')
KEYWORD_STARTXREF = PSKeywordTable.intern('startxref')
PASSWORD_PADDING = '(\xbfN^Nu\x8aAd\x00NV\xff\xfa\x01\x08..\x00\xb6\xd0h>\x80/\x0c\xa9\xfedSiz'
Ejemplo n.º 5
0
#!/usr/bin/env python
import sys, zlib
stderr = sys.stderr
#from pdflib.lzw import LZWDecoder
from lzw import LZWDecoder
#from pdflib.psparser import PSException, PSObject, \
from psparser import PSException, PSObject, \
     PSLiteral, PSKeyword, PSLiteralTable, PSKeywordTable, \
     literal_name, keyword_name, STRICT

LITERAL_CRYPT = PSLiteralTable.intern('Crypt')
LITERALS_FLATE_DECODE = (PSLiteralTable.intern('FlateDecode'), PSLiteralTable.intern('Fl'))
LITERALS_LZW_DECODE = (PSLiteralTable.intern('LZWDecode'), PSLiteralTable.intern('LZW'))
LITERALS_ASCII85_DECODE = (PSLiteralTable.intern('ASCII85Decode'), PSLiteralTable.intern('A85'))


##  PDF Objects
##
class PDFObject(PSObject): pass

class PDFException(PSException): pass
class PDFTypeError(PDFException): pass
class PDFValueError(PDFException): pass
class PDFNotImplementedError(PSException): pass


##  PDFObjRef
##
class PDFObjRef(PDFObject):
  
  def __init__(self, doc, objid, _):
Ejemplo n.º 6
0
from cmap import CMapDB


##  Exceptions
##
class PDFResourceError(PDFException):
    pass


class PDFInterpreterError(PDFException):
    pass


##  Constants
##
LITERAL_PDF = PSLiteralTable.intern('PDF')
LITERAL_TEXT = PSLiteralTable.intern('Text')
LITERAL_FONT = PSLiteralTable.intern('Font')
LITERAL_FORM = PSLiteralTable.intern('Form')
LITERAL_IMAGE = PSLiteralTable.intern('Image')


##  Resource Manager
##
class PDFResourceManager(object):
    '''
  ResourceManager facilitates reuse of shared resources
  such as fonts and images so that large objects are not
  allocated multiple times.
  '''
    debug = 0
Ejemplo n.º 7
0
#from pdflib.pdftypes import PDFException, \
from pdftypes import PDFException, \
     resolve1, int_value, float_value, num_value, \
     str_value, list_value, dict_value, stream_value
#from pdflib.cmap import CMap, CMapDB, CMapParser, FontMetricsDB, EncodingDB
from cmap import CMap, CMapDB, CMapParser, FontMetricsDB, EncodingDB
from utils import apply_matrix_norm


##  Fonts
##

class PDFFontError(PDFException): pass
class PDFUnicodeNotDefined(PDFFontError): pass

LITERAL_STANDARD_ENCODING = PSLiteralTable.intern('StandardEncoding')


# PDFFont
class PDFFont(object):
  
  def __init__(self, descriptor, widths, default_width=None):
    self.descriptor = descriptor
    self.widths = widths
    self.fontname = descriptor.get('FontName', 'unknown')
    if isinstance(self.fontname, PSLiteral):
      self.fontname = literal_name(self.fontname)
    self.ascent = num_value(descriptor.get('Ascent', 0))
    self.descent = num_value(descriptor.get('Descent', 0))
    self.default_width = default_width or descriptor.get('MissingWidth', 0)
    self.leading = num_value(descriptor.get('Leading', 0))
Ejemplo n.º 8
0
     STRICT
#from pdflib.pdftypes import PDFException, PDFTypeError, PDFNotImplementedError, \
from pdftypes import PDFException, PDFTypeError, PDFNotImplementedError, \
     PDFStream, PDFObjRef, resolve1, decipher_all, \
     int_value, float_value, num_value, str_value, list_value, dict_value, stream_value


##  Exceptions
##
class PDFSyntaxError(PDFException): pass
class PDFNoValidXRef(PDFSyntaxError): pass
class PDFEncryptionError(PDFException): pass
class PDFPasswordIncorrect(PDFEncryptionError): pass

# some predefined literals and keywords.
LITERAL_OBJSTM = PSLiteralTable.intern('ObjStm')
LITERAL_XREF = PSLiteralTable.intern('XRef')
LITERAL_PAGE = PSLiteralTable.intern('Page')
LITERAL_PAGES = PSLiteralTable.intern('Pages')
LITERAL_CATALOG = PSLiteralTable.intern('Catalog')


##  XRefs
##

##  PDFXRef
##
class PDFXRef(object):

  def __init__(self):
    self.offsets = None
Ejemplo n.º 9
0
from cmap import CMapDB


##  Exceptions
##
class PDFResourceError(PDFException):
    pass


class PDFInterpreterError(PDFException):
    pass


##  Constants
##
LITERAL_PDF = PSLiteralTable.intern("PDF")
LITERAL_TEXT = PSLiteralTable.intern("Text")
LITERAL_FONT = PSLiteralTable.intern("Font")
LITERAL_FORM = PSLiteralTable.intern("Form")
LITERAL_IMAGE = PSLiteralTable.intern("Image")


##  Resource Manager
##
class PDFResourceManager(object):

    """
  ResourceManager facilitates reuse of shared resources
  such as fonts and images so that large objects are not
  allocated multiple times.
  """