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

Error converting to PDF when outputfile is a pathlib.Path object #337

Closed
kencx opened this issue Aug 20, 2023 · 0 comments · Fixed by #338
Closed

Error converting to PDF when outputfile is a pathlib.Path object #337

kencx opened this issue Aug 20, 2023 · 0 comments · Fixed by #338

Comments

@kencx
Copy link
Contributor

kencx commented Aug 20, 2023

When trying to convert a file to PDF, passing a pathlib.Path object in the outputfile argument causes a TypeError:

>>> pypandoc.convert_file("README.md", to="pdf", outputfile=Path("test.pdf"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.10/site-packages/pypandoc/__init__.py", line 168, in convert_file
    return _convert_input(discovered_source_files, format, 'path', to, extra_args=extra_args,
  File "/usr/lib/python3.10/site-packages/pypandoc/__init__.py", line 328, in _convert_input
    format, to = _validate_formats(format, to, outputfile)
  File "/usr/lib/python3.10/site-packages/pypandoc/__init__.py", line 306, in _validate_formats
    if outputfile[-4:] != ".pdf":
TypeError: 'PosixPath' object is not subscriptable

because the _validate_formats function assumes outputfile is always a string.

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

Successfully merging a pull request may close this issue.

1 participant