# Path: mfr/core/extension.py
# class BaseExporter(metaclass=abc.ABCMeta):
# class BaseRenderer(metaclass=abc.ABCMeta):
#     def __init__(self, ext, source_file_path, output_file_path, format, metadata):
#     def export(self):
#     def _get_module_name(self):
#     def __init__(self, metadata, file_path, url, assets_url, export_url):
#     def render(self):
#     def file_required(self):
#     def cache_result(self):
#     def _get_module_name(self):
# 
# Path: mfr/extensions/pdf/exceptions.py
# class PillowImageError(ExporterError):
#     __TYPE = 'pdf_pillow'
#     def __init__(self, message, *args, export_format: str='', detected_format: str='',
#                  original_exception: Exception=None, **kwargs):
# 
# Path: mfr/extensions/pdf/settings.py
# EXPORT_MAX_PAGES = int(config.get('EXPORT_MAX_PAGES', 40))


import os
import imghdr
import logging
from http import HTTPStatus
from PIL import Image, TiffImagePlugin
from reportlab.pdfgen import canvas
from mfr.core import extension
from mfr.extensions.pdf import exceptions
from mfr.extensions.pdf.settings import EXPORT_MAX_PAGES



logger = logging.getLogger(__name__)


class PdfExporter(extension.BaseExporter):

    def __init__(self, *args, **kwargs):

        super().__init__(*args, **kwargs)
        self.metrics.add('pil_version', Image.VERSION)

    def tiff_to_pdf(self, tiff_img, max_size):
        """ Turn a tiff into a pdf to support multipage tiffs"""

        c = canvas.Canvas(self.output_file_path)
        c.setPageSize((max_size[0], max_size[1]))

        page = 0

        # This seems to be the only way to write this loop at the moment

# Path: mfr/core/extension.py
# class BaseExporter(metaclass=abc.ABCMeta):
# class BaseRenderer(metaclass=abc.ABCMeta):
#     def __init__(self, ext, source_file_path, output_file_path, format, metadata):
#     def export(self):
#     def _get_module_name(self):
#     def __init__(self, metadata, file_path, url, assets_url, export_url):
#     def render(self):
#     def file_required(self):
#     def cache_result(self):
#     def _get_module_name(self):
# 
# Path: mfr/extensions/pdf/exceptions.py
# class PillowImageError(ExporterError):
#     __TYPE = 'pdf_pillow'
#     def __init__(self, message, *args, export_format: str='', detected_format: str='',
#                  original_exception: Exception=None, **kwargs):
# 
# Path: mfr/extensions/pdf/settings.py
# EXPORT_MAX_PAGES = int(config.get('EXPORT_MAX_PAGES', 40))


# Path: mfr/extensions/pdf/export.py
import os
import imghdr
import logging
from http import HTTPStatus
from PIL import Image, TiffImagePlugin
from reportlab.pdfgen import canvas
from mfr.core import extension
from mfr.extensions.pdf import exceptions
from mfr.extensions.pdf.settings import EXPORT_MAX_PAGES




logger = logging.getLogger(__name__)


class PdfExporter(extension.BaseExporter):

    def __init__(self, *args, **kwargs):

        super().__init__(*args, **kwargs)
        self.metrics.add('pil_version', Image.VERSION)

    def tiff_to_pdf(self, tiff_img, max_size):
        """ Turn a tiff into a pdf to support multipage tiffs"""

        c = canvas.Canvas(self.output_file_path)
        c.setPageSize((max_size[0], max_size[1]))

        page = 0

        # This seems to be the only way to write this loop at the moment

        while page < EXPORT_MAX_PAGES: