Esempio n. 1
0
    def __init__(self, path, filename):
        super(PDFHandler, self).__init__(path, filename)
        warnings.simplefilter('ignore', DeprecationWarning)
        try:
            pdf = PdfFileReader(file(path, "rb"))
            info = pdf.getDocumentInfo()
            if info.title:
                self.title = info.title
            if info.subject:
                    self.subject = info.subject
            self.nb_pages = pdf.gtNumPages()
            # TODO : format
            page = pdf.getPage(0)
            page.mediaBox
            self._set_valid()
        except Exception, e:
            # load may raise several exceptions...
            self._set_invalid()
        warnings.simplefilter('default', DeprecationWarning)
    
    @property
    def attributes(self):
        res = []
        for attr in ("nb_pages", "title", "subject"):
            if hasattr(self, attr):
                res.append(attr)
        return res

HandlersManager.register(".pdf", PDFHandler)
Esempio n. 2
0
    def __init__(self, path, filename):
        super(PDFHandler, self).__init__(path, filename)
        warnings.simplefilter('ignore', DeprecationWarning)
        try:
            pdf = PdfFileReader(file(path, "rb"))
            info = pdf.getDocumentInfo()
            if info.title:
                self.title = info.title
            if info.subject:
                    self.subject = info.subject
            self.nb_pages = pdf.gtNumPages()
            # TODO : format
            page = pdf.getPage(0)
            page.mediaBox
            self._set_valid()
        except Exception, e:
            # load may raise several exceptions...
            self._set_invalid()
        warnings.simplefilter('default', DeprecationWarning)
    
    @property
    def attributes(self):
        res = []
        for attr in ("nb_pages", "title", "subject"):
            if hasattr(self, attr):
                res.append(attr)
        return res

HandlersManager.register(".pdf", PDFHandler)
Esempio n. 3
0
            number of pages of the file
        .. attribute:: format

            format of the file (``"A0"`` to ``"A4"`` or ``"Other"``)
    """

    def __init__(self, path, filename):
        super(ODFHandler, self).__init__(path, filename)
        try:
            doc = load(path)
            stat = doc.getElementsByType(DocumentStatistic)[0]
            page = doc.getElementsByType(PageLayoutProperties)[0]
            self.nb_pages = int(stat.getAttrNS(METANS, "page-count"))
            w = page.getAttrNS(FONS, 'page-width')
            h = page.getAttrNS(FONS, 'page-height')
            self.format = size_to_format(w, h)
            self._set_valid()
        except Exception, e:
            # load may raise several exceptions...
            self._set_invalid()
    
    @property
    def attributes(self):
        res = []
        for attr in ("nb_pages", "format"):
            if hasattr(self, attr):
                res.append(attr)
        return res

HandlersManager.register(".odt", ODFHandler)
Esempio n. 4
0
            number of pages of the file
        .. attribute:: format

            format of the file (``"A0"`` to ``"A4"`` or ``"Other"``)
    """
    def __init__(self, path, filename):
        super(ODFHandler, self).__init__(path, filename)
        try:
            doc = load(path)
            stat = doc.getElementsByType(DocumentStatistic)[0]
            page = doc.getElementsByType(PageLayoutProperties)[0]
            self.nb_pages = int(stat.getAttrNS(METANS, "page-count"))
            w = page.getAttrNS(FONS, 'page-width')
            h = page.getAttrNS(FONS, 'page-height')
            self.format = size_to_format(w, h)
            self._set_valid()
        except Exception, e:
            # load may raise several exceptions...
            self._set_invalid()

    @property
    def attributes(self):
        res = []
        for attr in ("nb_pages", "format"):
            if hasattr(self, attr):
                res.append(attr)
        return res


HandlersManager.register(".odt", ODFHandler)