Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting to pdf (to_pdf()) stopped working on xlwings (macOS)? #2390

Open
febin-j opened this issue Feb 3, 2024 · 3 comments
Open

Converting to pdf (to_pdf()) stopped working on xlwings (macOS)? #2390

febin-j opened this issue Feb 3, 2024 · 3 comments

Comments

@febin-j
Copy link

febin-j commented Feb 3, 2024

macOS 14.2.1.

xlwings 0.30.13, Office 365, Python 3.8.0

I made a excel workbook via openpyxl and xlwings, and converted it to pdf via xlwings in the following code:

    desktop = os.path.join(os.path.join(os.path.expanduser('~')), 'Desktop') 
    xlsx_name = str(year) + " Planner.xlsx"

    wb = xw.Book(desktop + "/" + xlsx_name)
 
    for a in range(12):
        sheet = wb.sheets[a]
        sheet.page_setup.print_area = '$A$1:$E$37'

    desktop = os.path.join(os.path.expanduser('~'), 'Desktop') 
    pdf_name = f"{year} Planner_YOLOAHID.pdf"
    pdf_output_path = os.path.join(desktop, pdf_name)
    pdf_output_path = pdf_output_path.replace(os.sep, '/')
   
    wb.to_pdf(pdf_output_path)

    wb.save()
    wb.close()

It used to work fine (a year ago, I think) but now excel is giving me an "Error while printing error" and the program is giving me an OS error (-50). I am using macOS 14.2.1. The following is the OS Error:

Error: Command failed:
        OSERROR: -50
        MESSAGE: Parameter error.
        COMMAND: app(pid=38341).workbooks[1].save(in_='Macintosh HD:Users:febinjose:Desktop:2024 Planner_YOLOAHID.pdf', as_=k.PDF_file_format)
Traceback (most recent call last):
  File "/Users/febinjose/Documents/Projects/Python Projects/v1.6/venv-v1.6/lib/python3.8/site-packages/aeosa/appscript/reference.py", line 479, in __call__
    return self.AS_appdata.target().event(self._code, params, atts, codecs=self.AS_appdata).send(timeout, sendflags)
  File "/Users/febinjose/Documents/Projects/Python Projects/v1.6/venv-v1.6/lib/python3.8/site-packages/aeosa/aem/aemsend.py", line 92, in send
    raise EventError(errornum, errormsg, eventresult)
aem.aemsend.EventError: Command failed: Parameter error. (-50)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/febinjose/Documents/Projects/Python Projects/v1.6/start_window.py", line 140, in making_planner
    creating_planner(data[0][0], data[0][1], data[0][2], data[0][3], data[0][4], data[0][5], data[0][6], data[0][7], data[0][8], data[0][9], data[0][10], data[0][11])
  File "/Users/febinjose/Documents/Projects/Python Projects/v1.6/make_planner.py", line 1014, in creating_planner
    to_pdf(year)
  File "/Users/febinjose/Documents/Projects/Python Projects/v1.6/prettifying.py", line 317, in to_pdf
    wb.to_pdf(pdf_output_path)
  File "/Users/febinjose/Documents/Projects/Python Projects/v1.6/venv-v1.6/lib/python3.8/site-packages/xlwings/main.py", line 1275, in to_pdf
    return utils.to_pdf(
  File "/Users/febinjose/Documents/Projects/Python Projects/v1.6/venv-v1.6/lib/python3.8/site-packages/xlwings/utils.py", line 662, in to_pdf
    obj.impl.to_pdf(os.path.realpath(report_path), quality=quality)
  File "/Users/febinjose/Documents/Projects/Python Projects/v1.6/venv-v1.6/lib/python3.8/site-packages/xlwings/_xlmac.py", line 602, in to_pdf
    self.xl.save(in_=hfs_path, as_=kw.PDF_file_format)
  File "/Users/febinjose/Documents/Projects/Python Projects/v1.6/venv-v1.6/lib/python3.8/site-packages/aeosa/appscript/reference.py", line 515, in __call__
    raise CommandError(self, (args, kargs), e, self.AS_appdata) from e
appscript.reference.CommandError: Command failed:
        OSERROR: -50
        MESSAGE: Parameter error.
        COMMAND: app(pid=38341).workbooks[1].save(in_='Macintosh HD:Users:febinjose:Desktop:2024 Planner_YOLOAHID.pdf', as_=k.PDF_file_format)
@fzumstein
Copy link
Member

Can you try if you can print to PDF manually? i.e. File > Print > PDF via Excel's menu.

@febin-j
Copy link
Author

febin-j commented Feb 3, 2024

@fzumstein I tried that and it works

@fzumstein
Copy link
Member

In can't repro this using

import xlwings as xw
xw.books.active.to_pdf("/Users/felix/Downloads/test.pdf")

But I haven't upgraded to Sonoma yet, so maybe there's an issue with that. You could also try with another folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants