Ejemplo n.º 1
0
def add_char_blocks(stack: PDFStateStack, seq: bytearray) -> PDFStateStack:
    if stack.text.font is None:
        raise InvalidOperation("No Font Specified")
    if stack.current_textblock is None:
        raise InvalidOperation("No TextBlock initilized")
    stack.current_textblock.add_char_block(seq, stack.t_matrix,
                                           stack.text.copy(),
                                           stack.graphics.ncolor.copy())
    return stack
Ejemplo n.º 2
0
def insert_xobject(stack: PDFStateStack, xobjid) -> PDFStateStack:
    xobjid = literal_name(xobjid)
    try:
        xobj = PDFStream.validated_stream(stack.xobjmap[xobjid])
    except KeyError:
        raise InvalidOperation('Undefined xobject id: %r' % xobjid)
    # log.info('Processing xobj: %r', xobj)
    subtype = xobj.get('Subtype')
    if subtype is LITERAL_FORM and 'BBox' in xobj:
        bbox = list_value(xobj['BBox'])
        matrix = list_value(xobj.get('Matrix', MATRIX_IDENTITY))
        # According to PDF reference 1.7 section 4.9.1, XObjects in
        # earlier PDFs (prior to v1.2) use the page's Resources entry
        # instead of having their own Resources entry.
        xobjres = xobj.get('Resources')
        resources = dict_value(xobjres) if xobjres else stack.resources.copy()
        stack.complete_layout_items.append(
            make_xobject(obj=xobj,
                         bbox=bbox,
                         ctm=stack.t_matrix,
                         matrix=matrix,
                         resources=resources))
    elif subtype is LITERAL_IMAGE and 'Width' in xobj and 'Height' in xobj:
        stack.complete_layout_items.append(make_image(xobj, stack.t_matrix))
    else:
        # unsupported xobject type.
        pass
    return stack
Ejemplo n.º 3
0
def set_font(stack: PDFStateStack, fontid, fontsize) -> PDFStateStack:
    stack.text.fontsize = fontsize
    try:
        stack.text.font = stack.fontmap[literal_name(fontid)]
        return stack
    except KeyError:
        raise InvalidOperation('Undefined Font id: %r' % fontid)
Ejemplo n.º 4
0
def begin_text(stack: PDFStateStack) -> PDFStateStack:
    stack.text.matrix = MATRIX_IDENTITY
    stack.text.linematrix = [0, 0]
    if stack.current_textblock is None:
        stack.current_textblock = LTTextBlock()
    else:
        raise InvalidOperation("Last TextBlock did not clear")
    return stack
Ejemplo n.º 5
0
def set_nonstroke_colorspace_custom(stack: PDFStateStack) -> PDFStateStack:
    if stack.graphics.ncolspace is None:
        raise InvalidOperation('No colorspace specified!')
    components = stack.pop(stack.graphics.ncolspace.ncomponents)
    stack.graphics.set_nostroke_color(stack.graphics.ncolspace, *components)
    return stack
Ejemplo n.º 6
0
def set_nonstroke_colorspace(stack: PDFStateStack, name: str) -> PDFStateStack:
    try:
        stack.graphics.ncolspace = stack.colorspace_map[literal_name(name)]
        return stack
    except KeyError:
        raise InvalidOperation('Undefined ColorSpace: %r' % name)