當前位置: 首頁>>代碼示例>>Python>>正文


Python pdfrw.PdfDict方法代碼示例

本文整理匯總了Python中pdfrw.PdfDict方法的典型用法代碼示例。如果您正苦於以下問題:Python pdfrw.PdfDict方法的具體用法?Python pdfrw.PdfDict怎麽用?Python pdfrw.PdfDict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pdfrw的用法示例。


在下文中一共展示了pdfrw.PdfDict方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: make_cid_to_gid_map_object

# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfDict [as 別名]
def make_cid_to_gid_map_object(tt_font):
        """Make a CID to GID map that is used to map character ids to glyph ids in the font.

        :param TrueTypeFont tt_font: Our utility class used to parse and calculate font metrics
        from a true type font.
        :returns PdfDict: CIDtoGID PdfDict object.
        """
        # Let's make this as large as possibly addressable for now, it will compress nicely.
        mapping_size = 256 * 256
        cid_to_gid_map = ["\x00"] * mapping_size * 2

        for cc, glyph_name in tt_font.metrics.cmap.items():
            # TODO: What is the expectation here since PDF only supports two bytes lookups?
            if cc >= mapping_size:
                continue
            glyph_id = tt_font.get_glyph_id(glyph_name)
            cid_to_gid_map[cc * 2] = chr(glyph_id >> 8)
            cid_to_gid_map[cc * 2 + 1] = chr(glyph_id & 0xFF)
        cid_to_gid_map = ''.join(cid_to_gid_map)

        # Let's let pdfrw handle the compressing of streams
        return IndirectPdfDict(stream=cid_to_gid_map) 
開發者ID:plangrid,項目名稱:pdf-annotate,代碼行數:24,代碼來源:text.py

示例2: make_font_descriptor_object

# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfDict [as 別名]
def make_font_descriptor_object(tt_font):
        """Make a Font Descriptor object containing some calculated metrics
        for the font.

        :param TrueTypeFont tt_font: Our utility class used to parse and calculate font metrics
        from a true type font.
        :returns PdfDict: Font Descriptor PdfDict object.
        """
        return IndirectPdfDict(
            Type=PdfName('FontDescriptor'),
            FontName=PdfName(tt_font.fontName),
            Flags=tt_font.metrics.flags,
            FontBBox=tt_font.metrics.bbox,
            ItalicAngle=int(tt_font.metrics.italicAngle),
            Ascent=int(round(tt_font.metrics.ascent, 0)),
            Descent=int(round(tt_font.metrics.descent, 0)),
            CapHeight=int(round(tt_font.metrics.capHeight, 0)),
            StemV=int(round(tt_font.metrics.stemV, 0)),
            MissingWidth=int(round(tt_font.metrics.defaultWidth, 0)),
            FontFile2=FreeText.make_font_file_object(tt_font)
        ) 
開發者ID:plangrid,項目名稱:pdf-annotate,代碼行數:23,代碼來源:text.py

示例3: make_cid_font_object

# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfDict [as 別名]
def make_cid_font_object(tt_font):
        """Make a CID Type 2 font object for including as a descendant of a composite
        Type 0 font object.

        :param TrueTypeFont tt_font: Our utility class used to parse and calculate font metrics
        from a true type font.
        :returns PdfDict: CID Font Type 2 PdfDict object.
        """
        return IndirectPdfDict(
            Type=PdfName('Font'),
            Subtype=PdfName('CIDFontType2'),
            BaseFont=PdfName(tt_font.fontName),
            CIDSystemInfo=FreeText.make_cid_system_info_object(),
            FontDescriptor=FreeText.make_font_descriptor_object(tt_font),
            DW=int(round(tt_font.metrics.defaultWidth, 0)),
            Widths=PdfArray(tt_font.metrics.widths),
            CIDToGIDMap=FreeText.make_cid_to_gid_map_object(tt_font),
        ) 
開發者ID:plangrid,項目名稱:pdf-annotate,代碼行數:20,代碼來源:text.py

示例4: make_composite_font_object

# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfDict [as 別名]
def make_composite_font_object(font_file_path):
        """Make a PDF Type0 composite font object for embedding in the annotation's
        Resources dict.

        :param str font_file_path: The path and filename to the true type font we want to embed.
        :returns PdfDict: Resources PdfDict object, ready to be included in the
            Resources 'Font' subdictionary.
        """
        # TODO: Get font name from font program itself
        tt_font = get_true_type_font(font_file_path, DEFAULT_BASE_FONT)

        return IndirectPdfDict(
            Type=PdfName('Font'),
            Subtype=PdfName('Type0'),
            BaseFont=PdfName(tt_font.fontName),
            Encoding=PdfName('Identity-H'),
            DescendantFonts=PdfArray([
                FreeText.make_cid_font_object(tt_font)
            ]),
            ToUnicode=FreeText.make_to_unicode_object()
        ) 
開發者ID:plangrid,項目名稱:pdf-annotate,代碼行數:23,代碼來源:text.py

示例5: test_graphics_state

# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfDict [as 別名]
def test_graphics_state(self):
        state = GraphicsState(
            line_width=2,
            line_cap=constants.LINE_CAP_ROUND,
            line_join=constants.LINE_JOIN_MITER,
            miter_limit=1.404,
            dash_array=[[1], 0],
            stroke_transparency=0.7,
            fill_transparency=0.5,
        )
        pdf_dict = state.as_pdf_dict()
        assert pdf_dict == PdfDict(
            Type=PdfName('ExtGState'),
            LW=2,
            LC=1,
            LJ=0,
            ML=1.404,
            D=[[1], 0],
            CA=0.7,
            ca=0.5,
        ) 
開發者ID:plangrid,項目名稱:pdf-annotate,代碼行數:23,代碼來源:test_graphics_state.py

示例6: drawOn

# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfDict [as 別名]
def drawOn(self, canv, x, y, _sW=0):
        if _sW > 0 and hasattr(self, 'hAlign'):
            a = self.hAlign
            if a in ('CENTER', 'CENTRE', TA_CENTER):
                x += 0.5*_sW
            elif a in ('RIGHT', TA_RIGHT):
                x += _sW
            elif a not in ('LEFT', TA_LEFT):
                raise ValueError("Bad hAlign value " + str(a))
        canv.saveState()
        img = self.img_data
        if isinstance(img, PdfDict):
            xscale = self.img_width / img.BBox[2]
            yscale = self.img_height / img.BBox[3]
            canv.translate(x, y)
            canv.scale(xscale, yscale)
            canv.doForm(makerl(canv, img))
        else:
            canv.drawImage(img, x, y, self.img_width, self.img_height)
        canv.restoreState() 
開發者ID:neuropower,項目名稱:neurodesign,代碼行數:22,代碼來源:report.py

示例7: as_pdf_dict

# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfDict [as 別名]
def as_pdf_dict(self):
        pdf_dict = PdfDict(Type=PdfName('ExtGState'))
        for attr_name, attr_value in self.__dict__.items():
            if attr_value is not None:
                pdf_name = NAME_TO_PDF_ATTR[attr_name]
                pdf_dict[PdfName(pdf_name)] = attr_value
        return pdf_dict 
開發者ID:plangrid,項目名稱:pdf-annotate,代碼行數:9,代碼來源:graphics_state.py

示例8: make_font_file_object

# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfDict [as 別名]
def make_font_file_object(tt_font):
        """Make an embedded font object from the true type font itself.

        :param TrueTypeFont tt_font: Our utility class used to parse and calculate font metrics
        from a true type font.
        :returns PdfDict: font file PdfDict object stream.
        """
        # TODO: make subset font here
        with open(tt_font.ttfPath, 'rb') as font_file:
            data = font_file.read()

        # Let's let pdfrw handle compressing streams
        return IndirectPdfDict(stream=data.decode('Latin-1')) 
開發者ID:plangrid,項目名稱:pdf-annotate,代碼行數:15,代碼來源:text.py

示例9: make_to_unicode_object

# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfDict [as 別名]
def make_to_unicode_object():
        """Make a toUnicode object which allows the PDF reader to derive content from the PDF
        with the CIDFont embedded.  This map converts from CIDs to Unicode code points.

        :returns PdfDict: toUnicode CMAP PdfDict object.
        """
        # See section 9.10.3 ToUnicode CMaps of PDF 1.6 Spec
        # TODO: For now we put an empty mapping in.
        return IndirectPdfDict(stream='\n'.join((
            "/CIDInit /ProcSet findresource begin",
            "12 dict begin",
            "begincmap",
            "/CIDSystemInfo",
            "<</Registry (Adobe)",
            "/Ordering (UCS)",
            "/Supplement 0",
            ">> def",
            "/CMapName /Adobe-Identity-UCS def",
            "/CMapType 2 def",
            "1 begincodespacerange",
            "<0000> <FFFF>",
            "endcodespacerange",
            "1 beginbfrange",
            "<0000> <FFFF> <0000>",
            "endbfrange",
            "endcmap",
            "CMapName currentdict /CMap defineresource pop",
            "end",
            "end"
        ))) 
開發者ID:plangrid,項目名稱:pdf-annotate,代碼行數:32,代碼來源:text.py

示例10: make_font_object

# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfDict [as 別名]
def make_font_object():
        """Make a PDF Type1 font object for embedding in the annotation's
        Resources dict. Only Helvetica is supported as a base font.

        :returns PdfDict: Resources PdfDict object, ready to be included in the
            Resources 'Font' subdictionary.
        """
        return PdfDict(
            Type=PdfName('Font'),
            Subtype=PdfName('Type1'),
            BaseFont=PdfName(DEFAULT_BASE_FONT),
            Encoding=PdfName('WinAnsiEncoding'),
        ) 
開發者ID:plangrid,項目名稱:pdf-annotate,代碼行數:15,代碼來源:text.py

示例11: add_additional_resources

# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfDict [as 別名]
def add_additional_resources(self, resources):
        font_dict = PdfDict()
        font_dict[PdfName(PDF_ANNOTATOR_FONT)] = self.make_font_object()
        resources[PdfName('Font')] = font_dict 
開發者ID:plangrid,項目名稱:pdf-annotate,代碼行數:6,代碼來源:text.py

示例12: add_additional_resources

# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfDict [as 別名]
def add_additional_resources(self, resources):
        resources.XObject = PdfDict(Image=self.image_xobject) 
開發者ID:plangrid,項目名稱:pdf-annotate,代碼行數:4,代碼來源:image.py

示例13: get_png_smask

# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfDict [as 別名]
def get_png_smask(image):
        width, height = image.size
        smask = Image.make_compressed_image_content(image.getchannel('A'))
        smask_xobj = PdfDict(
            stream=smask,
            Width=width,
            Height=height,
            BitsPerComponent=8,
            Filter=PdfName('FlateDecode'),
            ColorSpace=PdfName('DeviceGray'),
            Subtype=PdfName('Image'),
            Type=PdfName('XObject'),
        )
        smask_xobj.indirect = True
        return smask_xobj 
開發者ID:plangrid,項目名稱:pdf-annotate,代碼行數:17,代碼來源:image.py

示例14: pdfdict

# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfDict [as 別名]
def pdfdict(self):
        """Return a PageLabel entry to pe inserted in the root of a PdfReader object"""
        nums = (i for label in sorted(self)
                for i in label.pdfobjs())
        return PdfDict(Type=PdfName("Catalog"),
                       Nums=PdfArray(nums)) 
開發者ID:lovasoa,項目名稱:pagelabels-py,代碼行數:8,代碼來源:pagelabels.py

示例15: pdfobjs

# 需要導入模塊: import pdfrw [as 別名]
# 或者: from pdfrw import PdfDict [as 別名]
def pdfobjs(self):
        """Returns a tuple of two elements to insert in the PageLabels.Nums
        entry of a pdf"""
        page_num = PdfObject(self.startpage)
        opts = PdfDict(S=styles[self.style])
        if self.prefix != defaults["prefix"]:
            opts.P = PdfString.encode(self.prefix)
        if self.firstpagenum != defaults["firstpagenum"]:
            opts.St = PdfObject(self.firstpagenum)
        return page_num, opts 
開發者ID:lovasoa,項目名稱:pagelabels-py,代碼行數:12,代碼來源:pagelabelscheme.py


注:本文中的pdfrw.PdfDict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。