from flask_restful import Resource, reqparse
from flask import make_response, jsonify
import pdfkit


class GetPDFFromHTML(Resource):
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument("html", required=True)
        parser.add_argument("file_name")
        args = parser.parse_args()
        html = args["html"]
        file_name = args['file_name']
        msg = html
        pdf = pdfkit.from_string(msg, False)
        options = {
            'margin-top': '0.4cm',
            'margin-right': '0.4cm',
            'margin-bottom': '0.0cm',
            'margin-left': '0.4cm',
            'page-width': '200',
            'page-height': '290'
        }
        print(file_name)
        pdf = pdfkit.from_string(msg, "html/api.quiits.com/static/" + file_name, options=options)

        return make_response(jsonify(status=1, result="https://api.quiits.com/templates/" + file_name), 200)
