예제 #1
0
def attact_annotation(annot: Annotation, doc: fitz.Document):
    page: fitz.Page = doc.loadPage(annot.pageNum)
    atype = annot.annotType[0]
    ann_new = None
    if atype == fitz.ANNOT_FREETEXT:
        ann_new = page.addFreetextAnnot(annot.rect, annot.info['content'])
    elif atype == fitz.ANNOT_TEXT:
        ann_new = page.addTextAnnot(annot.point, annot.info['content'])
    elif atype == fitz.ANNOT_HIGHLIGHT:
        ann_new = page.addHighlightAnnot(annot.quads)
    elif atype == fitz.ANNOT_STRIKEOUT:
        ann_new = page.addStrikeOUTAnnot(annot.quads)
    elif atype == fitz.ANNOT_SQUIGGLY:
        ann_new = page.addSquigglyAnnot(annot.quads)
    elif atype == fitz.ANNOT_UNDERLINE:
        ann_new = page.addUnderlineAnnot(annot.quads)
    else:
        print(
            f'Annotation type {annot.annotType} is not supported. Ignore: {annot}'
        )

    if ann_new:
        ann_new: fitz.Annot
        ann_new.setInfo(annot.info)
        ann_new.setColors(annot.colors)
        ann_new.setBorder(annot.border)
        if annot.lineEnds:
            ann_new.setLineEnds(*annot.lineEnds)
        ann_new.setOpacity(annot.opacity)
예제 #2
0
    def update_preview(self):
        if self.pages is not None:
            pdf_file = self.pages[self.current_page - 1]
            pdf_file.seek(0)
            document = Document(stream=pdf_file, filetype="PDF")
            image = QPixmap()

            page = document.loadPage(0)

            container_size = self.preview_box.parent().size()

            normalized_zoom_factor = min(
                page.rect.height / container_size.height(),
                page.rect.width / container_size.width(),
            )
            scale_mat = Matrix(normalized_zoom_factor, normalized_zoom_factor)

            image.loadFromData(page.getPixmap(matrix=scale_mat).getPNGData())
            image_size = container_size * self.zoom_factor
            self.preview_box.setPixmap(
                image.scaled(image_size, Qt.KeepAspectRatio))
            self.preview_box.resize(image_size)
        else:
            self.preview_box.setTextFormat(Qt.RichText)
            self.preview_box.setStyleSheet("QLabel { color : darkgray; }")
            self.preview_box.setText(
                f'<center><img src="{appctxt.get_resource("logo.png")}") /><br />Wähle auf der rechten Seite<br />eine Datei und ein Papierformat<br />aus um die Vorschau anzuzeigen</center>'
            )

            self.preview_box.resize(QSize(200, 200))
예제 #3
0
def extract_info_from_pdf(doc: fitz.Document, user: str) -> [Train]:
    trains_list = list()
    for i in range(doc.pageCount):
        page = doc.loadPage(i)
        text = page.getText("text")
        train = extract_info_from_text(text, user)
        if train is not None:
            trains_list.append(train)
    return trains_list
예제 #4
0
def return_page(doc: Document, page_num=0):
    """
    This function allows you to read any page of your file in html format.

    :doc: Document with all pages.

    :page_num: Number of document page, default value = 0.
                Wrong number raise exception.
    """

    if page_num < 0 or page_num >= doc.page_count:
        raise Exception("Wrong page")

    page = doc.loadPage(page_num)
    return page
예제 #5
0
def show_page(doc: Document, page_num=0):
    """
    This function allows you to read any page of your file in html format.
    
    :doc: Document with all pages.
    
    :page_num: Number of document page, default value = 0.
                Wrong number raise exception.
    """

    if page_num < 0 or page_num >= doc.page_count:
        raise Exception("Wrong page")

    pix = doc.loadPage(page_num).get_pixmap()
    fmt = QImage.Format_RGBA8888 if pix.alpha else QImage.Format_RGB888
    qtimg = QImage(pix.samples, pix.width, pix.height, pix.stride, fmt)
    return qtimg