mwshinn / CanD

6 stars 3 forks source link

Save pdf error #10

Closed syncrostone closed 3 years ago

syncrostone commented 3 years ago

I get this issue when I save as a pdf. It seems to save anyhow, but I'm not sure why I’m getting it:

File "gp_intro_fig.py", line 63, in main() File "gp_intro_fig.py", line 60, in main make_figure() File "gp_intro_fig.py", line 54, in make_figure c.save("../ThesisLatex/Chapter1/gp_intro.pdf") File "/Users/jasminestone/anaconda3/envs/tf1py36/lib/python3.6/site-packages/paranoid/decorators.py", line 126, in _decorated returnvalue = func(*args, **kwargs) File "/Users/jasminestone/anaconda3/envs/tf1py36/lib/python3.6/site-packages/CanD-0.0.1-py3.6.egg/cand/canvas.py", line 866, in save File "/Users/jasminestone/anaconda3/envs/tf1py36/lib/python3.6/site-packages/fitz/fitz.py", line 2686, in save return _fitz.Document_save(self, filename, garbage, clean, deflate, incremental, ascii, expand, linear, pretty, encryption, permissions, owner_pw, user_pw) RuntimeError: Can't do incremental writes when changing encryption

mwshinn commented 3 years ago

Are you using the add_image command anywhere? If so, does removing this command fix the problem?

syncrostone commented 3 years ago

I'm not using the add_image command, but I am using imshow, I tried removing that and it still gets the same error.

I do use add_colorbar, add_grid and add_figure_labels.

mwshinn commented 3 years ago

Looks like the new version of PyMuPDF introduced a new function argument which was required to be set to something different than the default. Should be fixed with this commit.

jankaWIS commented 3 years ago

I started getting the same error now. It didn't use to be and I do not remember doing anything except for updating my packages but now I'm getting:

---> 36 c.save(os.path.join(path_results, 'random.pdf'), dpi=150, bbox_inches="tight")
     37
     38 

~/anaconda3/lib/python3.8/site-packages/paranoid/decorators.py in _decorated(*args, **kwargs)
    124         _check_accepts(func, argvals)
    125         _check_requires(func, argvals)
--> 126         returnvalue = func(*args, **kwargs)
    127         _check_returns(func, returnvalue)
    128         _check_ensures(func, returnvalue, argvals)

~/anaconda3/lib/python3.8/site-packages/CanD-0.0.1-py3.8.egg/cand/canvas.py in save(self, filename, dpi, *args, **kwargs)
    857             pdf.metadata['producer'] = f"{_idstr}; {pdf.metadata['producer']}"
    858             pdf.setMetadata(pdf.metadata)
--> 859             pdf.save(pdf.name, deflate=True, incremental=True)
    860             pdf.close()
    861     @pns.accepts(pns.Self, Vector, Point)

~/anaconda3/lib/python3.8/site-packages/fitz/fitz.py in save(self, filename, garbage, clean, deflate, deflate_images, deflate_fonts, incremental, ascii, expand, linear, pretty, encryption, permissions, owner_pw, user_pw)
   4268                 raise ValueError("incremental needs original file")
   4269 
-> 4270         return _fitz.Document_save(
   4271             self,
   4272             filename,

RuntimeError: Can't do incremental writes when changing encryption

nevertheless, the pdf is still produced. For fitz, I have:

Type:        module
String form: <module 'fitz' from '/Users/jan/anaconda3/lib/python3.8/site-packages/fitz/__init__.py'>
File:        ~/anaconda3/lib/python3.8/site-packages/fitz/__init__.py
Docstring:  
PyMuPDF 1.18.9: Python bindings for the MuPDF 1.18.0 library.
Version date: 2021-02-26 13:46:32.
Built for Python 3.8 on darwin (64-bit).
mwshinn commented 3 years ago

This bug was fixed in the latest version of CanD, which isn't on pip yet. Try installing directly from the github repo. It is due to PyMuPDF changing the names of some function arguments.

jankaWIS commented 3 years ago

Hi @mwshinn, in which version was it fixed? I have now 0.0.1 and I was installing it directly from your repo, I did not use pip (and for my last update I also did not use pip but rather conda).

mwshinn commented 3 years ago

I have not yet incremented the version yet, so both the fixed version and the unfixed version are version 0.0.1. :/ Conda will install the version from pip which is outdated. To install from github, download the repo (either using git clone or else by downloading the zip from github) and run "python setup.py install --force".

jankaWIS commented 2 years ago

This might be a stupid question but I'm not sure how exactly it works. I have your repo forked and have a pull request there (sorry, I didn't have much time to finish it and a lot of deadlines lately it but next month should work...) and I'm unsure what will happen to it if I reinstall. Also, shouldn't it just get updated by itself if I pull it? Or what's the correct and proper way of doing it?

mwshinn commented 2 years ago

Okay, I just incremented the version to 0.0.2 so you can install from pip if you would like. Hopefully that makes things easier!