AttributeError: 'PageObject' 对象没有属性 'clone' pypdf

AttributeError: 'PageObject' object has no attribute 'clone' pypdf

提问人:tree em 提问时间:11/7/2023 更新时间:11/7/2023 访问量:22

问:

Server Error
Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 95, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 54, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 47, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1622, in call
    return fn(*args, **newargs)
  File "apps/diprint/diprint/customs/print_format.py", line 40, in download_multi_pdf
    output = get_print_all_in_one(
  File "apps/diprint/diprint/customs/print_format.py", line 27, in get_print_all_in_one
    return get_pdf(html, options=pdf_options, output=output) if as_pdf else html
  File "apps/frappe/frappe/utils/pdf.py", line 60, in get_pdf
    output.append_pages_from_reader(reader)
  File "env/lib/python3.10/site-packages/pypdf/_writer.py", line 829, in append_pages_from_reader
    writer_page = self.add_page(reader_page)
  File "env/lib/python3.10/site-packages/pypdf/_writer.py", line 418, in add_page
    return self._add_page(page, list.append, excluded_keys)
  File "env/lib/python3.10/site-packages/pypdf/_writer.py", line 331, in _add_page
    page = cast("PageObject", page_org.clone(self, False, excluded_keys))
AttributeError: 'PageObject' object has no attribute 'clone'
Status: 500

这是我正在尝试的代码

import os
from frappe.utils.print_format import read_multi_pdf
from frappe.website.serve import get_response_content

from pypdf import PdfWriter
from werkzeug.local import Local, release_local

import frappe
from frappe import _
from frappe.core.doctype.access_log.access_log import make_access_log
from frappe.translate import print_language

no_cache = 1
local = Local()
from frappe.www.printview import validate_print_permission

def get_print_all_in_one(doctype=None,print_format=None,style=None,as_pdf=False,doc=None,output=None,no_letterhead=0,password=None,pdf_options=None,letterhead=None):
    from frappe.utils.pdf import get_pdf
    from frappe.website.serve import get_response_content
    pdf_options = pdf_options or {}
    if password:
        pdf_options["password"] = password
    
    file_content_type = doctype.lower().replace(" ","_")
    #https://uat-aaaa.domain.software/advance_prints/item
    html = get_response_content(f"advance_prints/{file_content_type}")
    return get_pdf(html, options=pdf_options, output=output) if as_pdf else html


@frappe.whitelist()
def download_multi_pdf(doctype, name, format=None, no_letterhead=False, letterhead=None, options=None):
    import json
    output = PdfWriter()
    if isinstance(options, str):
        options = json.loads(options)
    if not isinstance(doctype, dict):
        result = json.loads(name)       
        if format =="Single Page":
            html = get_response_content("single_print")
            output = get_print_all_in_one(
                            doctype,
                            format,
                            as_pdf=True,
                            output=output,
                            no_letterhead=no_letterhead,
                            letterhead=letterhead,
                            pdf_options=options,
                        )
        else:
            # Concatenating pdf files
            for i, ss in enumerate(result):
                output = frappe.get_print(
                    doctype,
                    ss,
                    format,
                    as_pdf=True,
                    output=output,
                    no_letterhead=no_letterhead,
                    letterhead=letterhead,
                    pdf_options=options,
                )
        frappe.local.response.filename = "{doctype}.pdf".format(
            doctype=doctype.replace(" ", "-").replace("/", "-")
        )
    else:
        for doctype_name in doctype:
            for doc_name in doctype[doctype_name]:
                try:
                    output = frappe.get_print(
                        doctype_name,
                        doc_name,
                        format,
                        as_pdf=True,
                        output=output,
                        no_letterhead=no_letterhead,
                        letterhead=letterhead,
                        pdf_options=options,
                    )
                except Exception:
                    frappe.log_error(
                        title="Error in Multi PDF download",
                        message=f"Permission Error on doc {doc_name} of doctype {doctype_name}",
                        reference_doctype=doctype_name,
                        reference_name=doc_name,
                    )
        frappe.local.response.filename = f"{name}.pdf"

    frappe.local.response.filecontent = read_multi_pdf(output)
    frappe.local.response.type = "pdf"
PYPDF格式

评论


答: 暂无答案