当前位置: 首页>>代码示例>>Python>>正文


Python OpenDocumentText.addPicture方法代码示例

本文整理汇总了Python中odf.opendocument.OpenDocumentText.addPicture方法的典型用法代码示例。如果您正苦于以下问题:Python OpenDocumentText.addPicture方法的具体用法?Python OpenDocumentText.addPicture怎么用?Python OpenDocumentText.addPicture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在odf.opendocument.OpenDocumentText的用法示例。


在下文中一共展示了OpenDocumentText.addPicture方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testAddPicture

# 需要导入模块: from odf.opendocument import OpenDocumentText [as 别名]
# 或者: from odf.opendocument.OpenDocumentText import addPicture [as 别名]
 def testAddPicture(self):
     """ Check that AddPicture works"""
     THUMBNAILNAME = "thumbnail.png"
     icon = thumbnail.thumbnail()
     f = open(THUMBNAILNAME, "wb")
     f.write(icon)
     f.close()
     textdoc = OpenDocumentText()
     textdoc.addPicture(THUMBNAILNAME)
     os.unlink(THUMBNAILNAME)
开发者ID:aq1,项目名称:odfpy,代码行数:12,代码来源:testpicture.py

示例2: OdtGenerator

# 需要导入模块: from odf.opendocument import OpenDocumentText [as 别名]
# 或者: from odf.opendocument.OpenDocumentText import addPicture [as 别名]
class OdtGenerator(DocumentGenerator):
    def __init__(self, name):
        self.name = name
        self.document = OpenDocumentText()
        self.current_page = None
        self.photo_style = Style(name="Photo", family="graphic")
        self.document.styles.addElement(self.photo_style)
        self.font_styles = []
        self.page_layouts = []
        self.page_masters = []
        self.page_styles = []
        self.temp_images = []
        frame_style = Style(name="FrameStyle", family="graphic")
        frame_style.addElement(GraphicProperties(borderlinewidth="none"))
        self.document.styles.addElement(frame_style)
        frame_style_rotated = Style(name="FrameStyleRotated", family="graphic")
        frame_style_rotated.addElement(
            GraphicProperties(fill="none", stroke="none", verticalpos="from-top", verticalrel="paragraph")
        )
        self.document.automaticstyles.addElement(frame_style_rotated)

    def addText(self, data_box):
        text = data_box.getText()
        frame_style = Style(name="FrameStyle", family="graphic")
        debug("Angle: ", data_box.text_data.angle)
        angle = data_box.text_data.angle
        if angle:
            frame_style = Style(name="FrameStyleRotated", family="graphic")
        x, y, width, height = data_box.getBoundsPrintSize(self.current_page_resolution)
        frame = Frame(
            stylename=frame_style,
            width=str(width) + "in",
            height=str(height) + "in",
            x=str(x) + "in",
            y=str(y) + "in",
            anchortype="paragraph",
        )
        if angle:
            frame.addAttribute("transform", "rotate (%s) translate (%scm %scm)" % (abs(math.radians(angle)), x, y))
        self.current_page.addElement(frame)
        textbox = TextBox()
        frame.addElement(textbox)
        for line in text.split("\n"):
            textbox.addElement(P(stylename=self.__handleFrameStyle(data_box.text_data), text=line))

    def addImage(self, data_box):
        format = "PNG"
        image_file = tempfile.mkstemp(suffix="." + format)[1]
        data_box.image.save(image_file, format=format)
        x, y, width, height = data_box.getBoundsPrintSize(self.current_page_resolution)
        photo_frame = Frame(
            stylename=self.photo_style,
            x="%sin" % x,
            y="%sin" % y,
            width="%sin" % width,
            height="%sin" % height,
            anchortype="paragraph",
        )
        self.current_page.addElement(photo_frame)
        location = self.document.addPicture(image_file)
        photo_frame.addElement(Image(href=location))
        self.temp_images.append(image_file)

    def newPage(self, page_data):
        master_name = self.__handlePageMaster(page_data)
        page_style_name = "%sPage" % master_name
        if not page_style_name in self.page_styles:
            page_style = Style(name=page_style_name, family="paragraph", masterpagename=master_name)
            page_style.addElement(ParagraphProperties(breakbefore="page"))
            self.document.automaticstyles.addElement(page_style)
        new_page = P(stylename=page_style_name)
        self.document.text.addElement(new_page)
        return new_page

    def addPage(self, page_data):
        self.current_page = self.newPage(page_data)
        self.current_page_resolution = page_data.resolution
        self.addBoxes(page_data.data_boxes)

    def save(self):
        name = self.name
        if not name.lower().endswith(".odt"):
            name += ".odt"
        self.document.save(name)
        for image in self.temp_images:
            try:
                os.unlink(image)
            except:
                debug("Error removing image: %s" % image)

    def __handlePageMaster(self, page_data):
        layout_name = "Page%s%s" % (page_data.width, page_data.height)
        if not layout_name in self.page_layouts:
            page_layout = PageLayout(name=layout_name)
            page_layout.addElement(
                PageLayoutProperties(
                    margintop="0in",
                    marginbottom="0in",
                    marginleft="0in",
                    marginright="0in",
#.........这里部分代码省略.........
开发者ID:ZhangXinNan,项目名称:ocrfeeder,代码行数:103,代码来源:documentGeneration.py

示例3: ODFWriter

# 需要导入模块: from odf.opendocument import OpenDocumentText [as 别名]
# 或者: from odf.opendocument.OpenDocumentText import addPicture [as 别名]

#.........这里部分代码省略.........

                return (w*scale, h*scale)
            else:
                return (wTarget, hTarget)

        if obj.colon == True:
            return # writes children

        if not self.env or not self.env.images:
            return

        imgPath = self.env.images.getDiskPath(obj.target)#, size=targetWidth) ????
        if not imgPath:
            log.warning('invalid image url')
            return
        imgPath = imgPath.encode('utf-8')
               
        (wObj,hObj) = (obj.width or 0, obj.height or 0)
        # sometimes our parser delivers only one value, w or h, so set the other = 0

        try:
            img = PilImage.open(imgPath)
            if img.info.get('interlace',0) == 1:
                log.warning("got interlaced PNG which can't be handeled by PIL")
                return
        except IOError:
            log.warning('img can not be opened by PIL')
            return
        
        (wImg,hImg) = img.size
        
        if wImg == 0 or wImg == 0:
            return
        
        aspectRatio = wImg/hImg                           

        if wObj>0 and not hObj>0:
            hObj = wObj / aspectRatio
        elif hObj>0 and not wObj>0:
            wObj = aspectRatio / hObj
        elif wObj==0 and hObj==0: 
            wObj, hObj = wImg, hImg

        # sometimes the parser delivers only one value, w or h, so set the other "by hand"       
        (width, height) = sizeImage( wObj, hObj)
        
        widthIn = "%.2fin" % (width)# * scale)
        heightIn= "%.2fin" % (height)# * scale)
                
        innerframe = draw.Frame(stylename=style.frmInner, width=widthIn, height=heightIn)
        href = self.doc.addPicture(imgPath)
        innerframe.addElement(draw.Image(href=href))

        if obj.isInline():
            return SkipChildren(innerframe) # FIXME something else formatting?
        else:
            innerframe.addAttribute( "anchortype", "paragraph")


        widthIn = "%.2fin" % (width + style.frmOuter.internSpacing)# * scale)
        heightIn= "%.2fin" % (height)
        
        # set image alignment
        attrs = dict(width=widthIn, anchortype="paragraph")
        floats = dict(right  = style.frmOuterRight,
                      center = style.frmOuterCenter,
                      left   = style.frmOuterLeft)
        attrs["stylename"] = floats.get(obj.align, style.frmOuterLeft) 
        stylename=style.frmOuterLeft,
        frame = draw.Frame(**attrs)
        
        tb = draw.TextBox()
        frame.addElement(tb)
        p = ParagraphProxy(stylename=style.imgCaption)
        tb.addElement(p)
        p.addElement(innerframe)
        frame.writeto = p
        return frame


    def owriteNode(self, n):
        pass # simply write children

    def owriteGallery(self, obj):
        pass # simply write children FIXME

    def owriteHorizontalRule(self, obj):
        p = ParagraphProxy(stylename=style.hr)
        return p


# UNIMPLEMENTED  -----------------------------------------------

    def writeTimeline(self, obj): 
        data = obj.caption
        pass # FIXME

    def writeHiero(self, obj): # FIXME parser support
        data = obj.caption
        pass # FIXME
开发者ID:cscott,项目名称:wikiserver,代码行数:104,代码来源:odfwriter.py

示例4: P

# 需要导入模块: from odf.opendocument import OpenDocumentText [as 别名]
# 或者: from odf.opendocument.OpenDocumentText import addPicture [as 别名]
"""
    <text:h text:outline-level="1">An Image</text:h>
     <text:p>
       <draw:frame draw:name="graphics1" text:anchor-type="paragraph"
         svg:width="5in"
         svg:height="6.6665in" draw:z-index="0">
         <draw:image xlink:href="Pictures/campanile_fog.jpg" xlink:type="simple"
           xlink:show="embed"
           xlink:actuate="onLoad"/>
       </draw:frame>
     </text:p>
"""

textdoc.text.addElement(H(outlinelevel=1,text='An Image'))
p = P()
textdoc.text.addElement(p)
# add the image
# img_path is the local path of the image to include
img_path = r'..\data\img\metadator.png';
#img_path = 'D:\Document\PersonalInfoRemixBook\examples\ch17\campanile_fog.jpg'
href = textdoc.addPicture(img_path)
f = Frame(name="graphics1", anchortype="paragraph", width="5in", height="6.6665in",
zindex="0")
p.addElement(f)
img = Image(href=href, type="simple", show="embed", actuate="onLoad")
f.addElement(img)



# save the document
textdoc.save(fname)
开发者ID:Guts,项目名称:Metadator,代码行数:33,代码来源:test_odf_genexample.py


注:本文中的odf.opendocument.OpenDocumentText.addPicture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。