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


Python fitz.open方法代码示例

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


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

示例1: open_document

# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import open [as 别名]
def open_document(doc_fname):
    """Return the document opened by fitz (PyMuPDF)."""
    # TODO: Move the get_filename call to main_pdfCropMargins or
    # similar if actually used.
    if not doc_fname:
        doc_fname = get_filename()
    try:
        document = fitz.open(doc_fname)
    except RuntimeError:
        print("\nError in pdfCropMargins: The PyMuPDF program could not read"
              " the document\n   '{}'\nin order to display it in the GUI.   If you have"
              " Ghostscript installed\nconsider running pdfCropMargins with the"
              " '--gsFix' option to attempt to repair it."
              .format(doc_fname), file=sys.stderr)
        ex.cleanup_and_exit(1)
    page_count = len(document)
    return document, page_count 
开发者ID:abarker,项目名称:pdfCropMargins,代码行数:19,代码来源:gui.py

示例2: decrypt_doc

# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import open [as 别名]
def decrypt_doc(self):
        # let user enter document password
        pw = None
        dlg = wx.TextEntryDialog(self, 'Please enter password below:',
                 'Document needs password to open', '',
                 style = wx.TextEntryDialogStyle|wx.TE_PASSWORD)
        while pw is None:
            rc = dlg.ShowModal()
            if rc == wx.ID_OK:
                pw = str(dlg.GetValue().encode("utf-8"))
                self.doc.authenticate(pw)
            else:
                return
            if self.doc.isEncrypted:
                pw = None
                dlg.SetTitle("Wrong password. Enter correct one or cancel.")
        return

#==============================================================================
# main program
#------------------------------------------------------------------------------
# Show a standard FileSelect dialog to choose a file for display
#==============================================================================
# Wildcard: offer all supported filetypes for display 
开发者ID:pymupdf,项目名称:PyMuPDF-Utilities,代码行数:26,代码来源:PDFdisplay.py

示例3: decrypt_doc

# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import open [as 别名]
def decrypt_doc(self):
        # let user enter document password
        pw = None
        dlg = wx.TextEntryDialog(self, 'Please Enter Password',
                 'Document needs password to open', '',
                 style = wx.TextEntryDialogStyle|wx.TE_PASSWORD)
        while pw is None:
            rc = dlg.ShowModal()
            if rc == wx.ID_OK:
                pw = str(dlg.GetValue().encode("utf-8"))
                self.doc.authenticate(pw)
            else:
                return
            if self.doc.isEncrypted:
                pw = None
                dlg.SetTitle("Wrong password. Enter correct one or cancel.")
        return

#==============================================================================
# main program
#------------------------------------------------------------------------------
# Show a standard FileSelect dialog to choose a file
#==============================================================================
# Wildcard: only offer PDF files 
开发者ID:pymupdf,项目名称:PyMuPDF-Utilities,代码行数:26,代码来源:PDFLinkMaint.py

示例4: make_page

# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import open [as 别名]
def make_page(beta):
    """Create a dummy PDF with a page, put in a box filled with above text,
    and also insert some explanation. Then rotate the text box around
    its top-left corner by given angle beta. The resulting page's image
    is returned as a PNG stream, and the PDF discarded again.
    This functions execution time determines the overall "frames" per
    second ration.
    """
    doc = fitz.open()
    page = doc.newPage(width=pagerect.width, height=pagerect.height)
    mat = fitz.Matrix(beta)
    img = page.newShape()
    img.drawRect(r)
    img.finish(fill=gold, color=blue, width=0.3, morph=(r.tl, mat))
    img.insertText(textpoint, itext % beta, fontname="cobo", fontsize=20)
    img.insertTextbox(r, text, fontsize=15, rotate=90, morph=(r.tl, mat))
    img.commit()
    pix = page.getPixmap(alpha=False)
    return pix.getImageData("pgm")


# ------------------------------------------------------------------------------
# main program
# ------------------------------------------------------------------------------ 
开发者ID:pymupdf,项目名称:PyMuPDF-Utilities,代码行数:26,代码来源:morph-demo1.py

示例5: make_page

# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import open [as 别名]
def make_page(beta):
    """Create a dummy PDF with a page, put in a box filled with above text,
    and also insert some explanation. Then x-shear the text box around
    its top-left corner by given value beta. The resulting page's image
    is returned as a PNG stream, and the PDF discarded again.
    This functions execution time determines the overall "frames" per
    second ration.
    """
    doc = fitz.open()
    page = doc.newPage(width=pagerect.width, height=pagerect.height)
    mat = fitz.Matrix(beta * 0.01, 0, 1)
    img = page.newShape()
    img.drawRect(r)
    img.finish(fill=gold, color=blue, width=0.3, morph=(r.tl, mat))
    img.insertText(textpoint, itext % (beta * 0.01), fontname="cobo", fontsize=20)
    img.insertTextbox(r, text, fontsize=15, rotate=90, morph=(r.tl, mat))
    img.commit()
    pix = page.getPixmap(alpha=False)
    return pix.getImageData("pgm")


# ------------------------------------------------------------------------------
# main program
# ------------------------------------------------------------------------------ 
开发者ID:pymupdf,项目名称:PyMuPDF-Utilities,代码行数:26,代码来源:morph-demo2.py

示例6: setIcon

# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import open [as 别名]
def setIcon(self, fname):
        # 打开 PDF
        doc = fitz.open(fname)
        # 加载封面
        page = doc.loadPage(0)
        # 生成封面图像
        cover = render_pdf_page(page, True)
        label = QLabel(self)
        # 设置图片自动填充 label
        label.setScaledContents (True)
        # 设置封面图片
        label.setPixmap(QPixmap(cover))
        # 设置单元格元素为 label
        self.table.setCellWidget(self.x, self.y, label)
        # 删除 label 对象,防止后期无法即时刷新界面
        # 因为 label 的生存周期未结束
        del label
        # 设置当前行数与列数
        self.crow, self.ccol = self.x, self.y
        # 每 8 个元素换行
        if (not self.y % 7) and (self.y):
            self.x += 1
            self.y = 0
        else:
            self.y += 1 
开发者ID:xflywind,项目名称:Python-Application,代码行数:27,代码来源:__main__.py

示例7: read_book

# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import open [as 别名]
def read_book(self):
        self.book = fitz.open(self.filename) 
开发者ID:BasioMeusPuga,项目名称:Lector,代码行数:4,代码来源:pdf.py

示例8: update_model

# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import open [as 别名]
def update_model(self):
        # We're updating the underlying model to have real-time
        # updates on the read status

        # Set a baseline model index in case the item gets deleted
        # E.g It's open in a tab and deleted from the library
        model_index = None
        start_index = self.main_window.lib_ref.libraryModel.index(0, 0)

        # Find index of the model item that corresponds to the tab
        model_index = self.main_window.lib_ref.libraryModel.match(
            start_index,
            QtCore.Qt.UserRole + 6,
            self.pw.parent.metadata['hash'],
            1, QtCore.Qt.MatchExactly)

        if self.are_we_doing_images_only:
            position_percentage = (
                self.pw.parent.metadata['position']['current_chapter'] /
                self.pw.parent.metadata['position']['total_chapters'])
        else:
            position_percentage = (
                self.pw.parent.metadata['position']['current_block'] /
                self.pw.parent.metadata['position']['total_blocks'])

        # Update position percentage
        if model_index:
            self.main_window.lib_ref.libraryModel.setData(
                model_index[0], position_percentage, QtCore.Qt.UserRole + 7) 
开发者ID:BasioMeusPuga,项目名称:Lector,代码行数:31,代码来源:contentwidgets.py

示例9: get_filename

# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import open [as 别名]
def get_filename():
    """Get the filename of the PDF file via GUI if one was not passed in."""
    fname = sg.PopupGetFile("Select file and filetype to open:",
                            title="pdfCropMargins: Document Browser",
                            file_types=[ # Only PDF files.
                                          ("PDF Files", "*.pdf"),
                                       ],
                            )
    return fname # Might be None. 
开发者ID:abarker,项目名称:pdfCropMargins,代码行数:11,代码来源:gui.py

示例10: auto_save

# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import open [as 别名]
def auto_save(self):
        f_toc = open(spad.file + ".json", "w")
        d = {"toc": self.tocgrid.Table.data,
             "author": self.ausaut.Value, "title": self.austit.Value,
             "subject": self.aussub.Value, "keywords": self.keywords.Value}
        json.dump(d, f_toc)
        f_toc.close()
        spad.lastsave = time.clock()
        return

#==============================================================================
# display a PDF page
#============================================================================== 
开发者ID:pymupdf,项目名称:PyMuPDF-Utilities,代码行数:15,代码来源:PDFoutline.py

示例11: draw_links

# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import open [as 别名]
def draw_links(self):
        dc = wx.ClientDC(self.PDFimage)
        dc.SetPen(wx.Pen("BLUE", width=1))
        dc.SetBrush(wx.Brush("BLUE", style=wx.BRUSHSTYLE_TRANSPARENT))
        self.link_rects = []
        self.link_bottom_rects = []
        self.link_texts = []
        for lnk in self.page_links:
            if lnk.get("update", False):
                self.enable_update()
            wxr = self.Rect_to_wxRect(lnk["from"])
            dc.DrawRectangle(wxr[0], wxr[1], wxr[2], wxr[3])
            self.link_rects.append(wxr)
            p = wxr.BottomRight
            br = wx.Rect(p.x - self.sense, p.y - self.sense,
                         2*self.sense, 2*self.sense)
            self.link_bottom_rects.append(br)
            if lnk["kind"] == fitz.LINK_GOTO:
                if lnk["page"] >= 0:
                    txt = "page " + str(lnk["page"] + 1)
                else:
                    txt = "name " + str(lnk["to"])
            elif lnk["kind"] == fitz.LINK_GOTOR:
                txt = lnk["file"]
                if lnk["page"] >= 0:
                    txt += " p. " + str(lnk["page"] + 1)
                else:
                    txt += "(" + str(lnk["to"]) + ")"
            elif lnk["kind"] == fitz.LINK_URI:
                txt = lnk["uri"]
            elif lnk["kind"] == fitz.LINK_LAUNCH:
                txt = "open " + lnk["file"]
            elif lnk["kind"] == fitz.LINK_NONE:
                txt = "none"
            else:
                txt = "unkown destination"
            self.link_texts.append(txt)
        return 
开发者ID:pymupdf,项目名称:PyMuPDF-Utilities,代码行数:40,代码来源:PDFLinkMaint.py

示例12: make_oval

# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import open [as 别名]
def make_oval(f):
    """Make a PDF page and draw an oval inside a Quad.
    The upper left and the lower right quad points and the fill color are
    subject to a passed-in parameter. Effectively, they exchange their position,
    thus causing changes to the drawn shape.
    The resulting page picture is passed back as a PNG image and the PDF is
    discarded again. The execution speed of this function mainly determines
    the number of "frames" shown per second.
    """
    doc = fitz.open()  # dummy PDF
    page = doc.newPage(width=400, height=400)  # page dimensions as you like
    r = page.rect + (4, 4, -4, -4)
    q = r.quad  # full page rect as a quad
    q1 = fitz.Quad(
        q.lr + (q.ul - q.lr) * f, q.ur, q.ll, q.ul + (q.lr - q.ul) * f  # upper left
    )  # lower right
    # make an entertaining fill color - simulating rotation around
    # a diagonal
    c1 = min(1, f)
    c3 = min(1, max(1 - f, 0))
    fill = (c1, 0, c3)
    page.drawOval(
        q1, color=(0, 0, 1), fill=fill, width=0.3  # blue border  # variable fill color
    )  # border width
    pix = page.getPixmap(alpha=False)  # make pixmap, no alpha
    doc.close()  # discard PDF again
    return pix.getImageData("pgm")  # return a data stream


# ------------------------------------------------------------------------------
# main program
# ------------------------------------------------------------------------------ 
开发者ID:pymupdf,项目名称:PyMuPDF-Utilities,代码行数:34,代码来源:quad-show1.py

示例13: initUi

# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import open [as 别名]
def initUi(self):
        # 连接
        self._init_bookset()
        self.x = 0
        self.y = 0
        # 初始化
        self.crow = self.ccol = -1
        # 初始化表格类型
        self._set_table_style()
        # 将 toolbar + 号与 self.open 函数绑定
        self.addbar.triggered.connect(self.open)

    # 连接数据库 
开发者ID:xflywind,项目名称:Python-Application,代码行数:15,代码来源:__main__.py

示例14: open

# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import open [as 别名]
def open(self):
        # 打开文件
        fname = self.get_file()
        if self.filter_book(fname):
            self.set_icon(fname) 
开发者ID:xflywind,项目名称:Python-Application,代码行数:7,代码来源:__main__.py

示例15: set_icon

# 需要导入模块: import fitz [as 别名]
# 或者: from fitz import open [as 别名]
def set_icon(self, fname):
        # 打开 PDF
        doc = fitz.open(fname)
        # 加载封面
        page = doc.loadPage(0)
        # 生成封面图像
        cover = render_pdf_page(page)
        label = QLabel(self)
        label.resize(self.width, self.width * 4 // 3)
        # 设置图片自动填充 label
        label.setScaledContents(True)
        # 设置封面图片
        p = QPixmap(cover)
        p.scaled(self.width, self.width * 4 // 3, Qt.KeepAspectRatio)
        label.setPixmap(p)
        # 设置单元格元素为 label
        self.table.setCellWidget(self.x, self.y, label)
        # 删除 label 对象,防止后期无法即时刷新界面
        # 因为 label 的生存周期未结束
        del label
        # 设置当前行数与列数
        self.crow, self.ccol = self.x, self.y
        # 每 8 个元素换行
        if (not self.y % 7) and (self.y):
            self.x += 1
            self.y = 0
        else:
            self.y += 1 
开发者ID:xflywind,项目名称:Python-Application,代码行数:30,代码来源:__main__.py


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