Пример #1
0
Файл: File.py Проект: poses/erp5
    def _convert(self, format, **kw):
        """File is only convertable if it is an image. 
    Only Image conversion, original format and text formats are allowed.
    However this document can migrate to another portal_type which support
    others conversions.
    """
        content_type = self.getContentType() or ''
        if (format in VALID_IMAGE_FORMAT_LIST + (None, "")) and \
              content_type.startswith("image/"):
            # The file should behave like it is an Image for convert
            # the content to target format.
            from Products.ERP5Type.Document import newTempImage
            return newTempImage(self,
                                self.getId(),
                                data=self.getData(),
                                content_type=content_type,
                                filename=self.getFilename())._convert(
                                    format, **kw)

        elif format in (None, ""):
            # No conversion is asked,
            # we can return safely the file content itself
            return content_type, self.getData()

        elif format in VALID_TEXT_FORMAT_LIST:
            # This is acceptable to return empty string
            # for a File we can not convert
            return 'text/plain', ''
        raise NotImplementedError
Пример #2
0
 def getPageImage(self, page, format, resolution, quality):
     """
 Return an instance of newTempImage containing the pape page of
 the pdf file
 width, height: attributes in pixel (px)
 format: jpg, png, etc...
 resolution: resolution of produced image for exemple 600
 quality: quality of produced image for exemple 200 raisonable quality
 more hight is quality more time it takes to be gererated
 """
     from Products.ERP5Type.Document import newTempPDFDocument
     from Products.ERP5Type.Document import newTempImage
     temp_pdf_document_name = "tmp%s.pdf" % str(
         random.random()).split('.')[-1]
     temp_pdf_document = newTempPDFDocument(self, temp_pdf_document_name)
     temp_pdf_document.setData(self.getData())
     display = 'xlarge'
     mime, image_data = temp_pdf_document.convert(format=format,
                                                  frame=page,
                                                  resolution=resolution,
                                                  quality=quality,
                                                  display=display)
     page_image = None
     if image_data is not None:
         page_image = newTempImage(self, "page_%s" % page)
         page_image.setData(page_image)
     return page_image
Пример #3
0
  def _convert(self, format, **kw):
    """File is only convertable if it is an image.
    Only Image conversion, original format and text formats are allowed.
    However this document can migrate to another portal_type which support
    others conversions.
    """
    content_type = self.getContentType() or ''
    if (format in VALID_IMAGE_FORMAT_LIST + (None, "")) and \
          content_type.startswith("image/"):
      # The file should behave like it is an Image for convert
      # the content to target format.
      from Products.ERP5Type.Document import newTempImage
      return newTempImage(self, self.getId(),
                 data=self.getData(),
                 content_type=content_type,
                 filename=self.getFilename())._convert(format, **kw)

    elif format in (None, ""):
      # No conversion is asked,
      # we can return safely the file content itself
      return content_type, self.getData()

    elif format in VALID_TEXT_FORMAT_LIST:
      # This is acceptable to return empty string
      # for a File we can not convert
      return 'text/plain', ''
    raise NotImplementedError
Пример #4
0
 def getPageImage(self, page, format, resolution, quality):
   """
   Return an instance of newTempImage containing the pape page of
   the pdf file
   width, height: attributes in pixel (px)
   format: jpg, png, etc...
   resolution: resolution of produced image for exemple 600
   quality: quality of produced image for exemple 200 raisonable quality
   more hight is quality more time it takes to be gererated
   """
   from Products.ERP5Type.Document import newTempPDFDocument
   from Products.ERP5Type.Document import newTempImage
   temp_pdf_document_name = "tmp%s.pdf" %  str(random.random()).split('.')[-1]
   temp_pdf_document = newTempPDFDocument(self, temp_pdf_document_name)
   temp_pdf_document.setData(self.getData())
   display = 'xlarge'
   mime, image_data = temp_pdf_document.convert(format = format,
                                                frame = page,
                                                resolution = resolution,
                                                quality = quality,
                                                display = display)
   page_image = None
   if image_data is not None:
     page_image = newTempImage(self, "page_%s" % page)
     page_image.setData(page_image)
   return page_image
Пример #5
0
    def getERP5FormImage(self, page):
        """
      Returns the background image for a given page
    """
        from Products.ERP5Type.Document import newTempImage

        import_pdf_file = self.getDefaultPdfFormValue()
        # depend on preferences, best xlargeheight = 1131
        mime, image_data = import_pdf_file.convert(
            format="jpg", frame=page, resolution=self.getResolution(), quality=600, display="xlarge"
        )
        if image_data is None:
            return
        page_image = newTempImage(self, "page_%s" % page)
        page_image.setData(image_data)
        self.REQUEST.RESPONSE.setHeader("Content-Type", mime)
        return page_image
Пример #6
0
 def getERP5FormImage(self, page):
   """
     Returns the background image for a given page
   """
   from Products.ERP5Type.Document import newTempImage
   import_pdf_file = self.getDefaultPdfFormValue()
   #depend on preferences, best xlargeheight = 1131
   mime, image_data = import_pdf_file.convert(format = 'jpg',
                                               frame = page,
                                               resolution = self.getResolution(),
                                               quality = 600,
                                               display = 'xlarge')
   if image_data is None:
     return
   page_image = newTempImage(self, "page_%s" % page)
   page_image.setData(image_data)
   self.REQUEST.RESPONSE.setHeader('Content-Type', mime)
   return page_image