altmany / export_fig

A MATLAB toolbox for exporting publication quality figures
BSD 3-Clause "New" or "Revised" License
1.28k stars 368 forks source link

Unable to open the initial device, quitting. #361

Closed mrkento11 closed 2 years ago

mrkento11 commented 2 years ago

Hi Altmany. I am fairly new at coding, and I am trying to use both export_fig and append_pdfs to create some reports. When running the following code:

Route = 'G:\\My Drive\\IMEPE Courses\\IMPE5011_Power System Planning\\Project\\BDD\\Reports';
pRF = 0.1;
append_pdfs(Route + "\\GEP_pRF"+num2str(pRF*100)+".pdf",Fig_Naams_list);

I get this error :

Error using append_pdfs (line 131)
GPL Ghostscript 9.56.1: **** Could not open the file
"C:\Users\newsu\AppData\Local\Temp\tp80f2c0bd_7573_4a0a_a16b_0304327f0f8f.pdf" .
**** Unable to open the initial device, quitting.`

In some other instances, the error reads:

Error using append_pdfs (line 131)
GPL Ghostscript 9.56.1: **** Could not open the file "C:\\Users\\newsu\\Desktop\\GEP1.pdf" .
**** Unable to open the initial device, quitting.

I have tried:

Also, in case the problem is related, when trying to append several figures in a single file using export_fig I have the following problem:

for i = 1:size(Output_G_exist,3)
      [fig,Fig_Naam] = graph_EnergyProduction(Output_G_exist(:,:,i),Output_G_cand(:,:,i),num2str(i+2020),"GEP",pRF,"");
      export_fig(Figures_Route + "\" + Naam + ".pdf",[fig],-append);
      Fig_Naams_list = [Fig_Naams_list;strcat(Figures_Route +"\"+ Fig_Naam +".pdf")];
end

The following error pops up:

Error using append (line 46)
Not enough input arguments.

Error in GraphingModule_Script (line 33)
        export_fig(Figures_Route + "\" + "GEP" + ".pdf",[fig],-append);

Perhaps it is a foolish error I might be making, but I need the help because I've run out of ideas on how to fix it. In case you need more details, or outright need me to send you my code, I will gladly do so. Thanks.

altmany commented 2 years ago

why are you using \\ instead of \ in your paths??? C:\\Users\\newsu\\Desktop\\GEP1.pdf" is not a valid Windows path name

mrkento11 commented 2 years ago

I used to write codes in Python, so in Python I was taught to use double backslash ("\") when dealing with strings so as the interpreter to not confuse it with a different command. For instance, the string "\n" will create a new line. So as to prevent any kind of misinterpretation when using append_pdfs I also tried with double backslash instead of just single. Given the error that append_pdfs is displaying, I just tried many things including adding double backslash after single didn't work. However, apparently MatLab correctly interprets the double backslash: image So, the path name C:\\Users\\newsu\\Desktop\\GEP1.pdf" should be as valid as C:\Users\newsu\Desktop\GEP1.pdf". Moreover, I tried both, and the output error is exactly the same. image

So, I was considering that that is not really the problem so something else. Thanks for your time.

altmany commented 2 years ago

I don't know what's going on with your code and if all the file paths are correct - you will need to debug this on your own.

One error for certain in your code is that your command export_fig(Figures_Route + "\" + Naam + ".pdf",[fig],-append); is wrong - you need to put the -append in a string, otherwise Matlab will think that you want to do the negative value of the append variable or function which is obviously silly.

mrkento11 commented 2 years ago

That actually did help. Thanks for your help and time.