'This method generates and returns pdf version of a report.'

@api.model
def get_pdf(self, docids, report_name, html=None, data=None):

    if (self._check_wkhtmltopdf() == 'install'):
        raise UserError(_('Unable    to    find    Wkhtmltopdf    on    this    system.    The    PDF    can    not    be    created.'))
    context = dict(self.env.context)
    if (not config['test_enable']):
        context['commit_assetsbundle'] = True
    context['debug'] = False
    if (html is None):
        html = self.with_context(context).get_html(docids, report_name, data=data)
    if isinstance(self.env.cr, TestCursor):
        return html
    html = html.decode('utf-8')
    report = self._get_report_from_name(report_name)
    save_in_attachment = self._check_attachment_use(docids, report)
    if (not report.paperformat_id):
        user = self.env['res.users'].browse(self.env.uid)
        paperformat = user.company_id.paperformat_id
    else:
        paperformat = report.paperformat_id
    headerhtml = []
    contenthtml = []
    footerhtml = []
    irconfig_obj = self.env['ir.config_parameter'].sudo()
    base_url = (irconfig_obj.get_param('report.url') or irconfig_obj.get_param('web.base.url'))
    view_obj = self.env['ir.ui.view']
    render_minimal = partial(view_obj.with_context(context).render_template, 'report.minimal_layout')
    try:
        root = lxml.html.fromstring(html)
        match_klass = "//div[contains(concat('    ',    normalize-space(@class),    '    '),    '    {}    ')]"
        for node in root.xpath(match_klass.format('header')):
            body = lxml.html.tostring(node)
            header = render_minimal(dict(subst=True, body=body, base_url=base_url))
            headerhtml.append(header)
        for node in root.xpath(match_klass.format('footer')):
            body = lxml.html.tostring(node)
            footer = render_minimal(dict(subst=True, body=body, base_url=base_url))
            footerhtml.append(footer)
        for node in root.xpath(match_klass.format('page')):
            if (docids and (len(docids) == 1)):
                reportid = docids[0]
            else:
                oemodelnode = node.find((".//*[@data-oe-model='%s']" % report.model))
                if (oemodelnode is not None):
                    reportid = oemodelnode.get('data-oe-id')
                    if reportid:
                        reportid = int(reportid)
                else:
                    reportid = False
            body = lxml.html.tostring(node)
            reportcontent = render_minimal(dict(subst=False, body=body, base_url=base_url))
            contenthtml.append(tuple([reportid, reportcontent]))
    except lxml.etree.XMLSyntaxError:
        contenthtml = []
        contenthtml.append(html)
        save_in_attachment = {}
    specific_paperformat_args = {}
    for attribute in root.items():
        if attribute[0].startswith('data-report-'):
            specific_paperformat_args[attribute[0]] = attribute[1]
    return self._run_wkhtmltopdf(headerhtml, footerhtml, contenthtml, context.get('landscape'), paperformat, specific_paperformat_args, save_in_attachment, context.get('set_viewport_size'))
