Error printing plot to PDF

23 vues (au cours des 30 derniers jours)
jloudis
jloudis le 27 Oct 2020
Commenté : jloudis le 28 Oct 2020
I am trying to save a plot to PDF, but getting an error. In particular, I have a Windows 10 machine running MATLAB 2019a.
I try the following:
plot(1:10,1:10)
set(gcf,'Units','inches');
screenposition = get(gcf,'Position');
set(gcf,...
'PaperPosition',[0 0 screenposition(3:4)],...
'PaperSize',[screenposition(3:4)]);
print -dpdf -painters 20201027_temp
And get the error:
Error using print (line 82)
There was a problem while generating the output: Problem while processing in an OutputHelper.
.\20201027_temp.pdf (A device which does not exist was specified)
com.mathworks.hg.util.OutputHelperProcessingException: Problem while processing in an OutputHelper.
.\20201027_temp.pdf (A device which does not exist was specified)
at com.mathworks.hg.util.HGVectorOutputHelper.open(HGVectorOutputHelper.java:74)
Caused by: com.mathworks.hg.print.OutputProcessingException: .\20201027_temp.pdf (A device which
does not exist was specified)
at com.mathworks.hg.print.BaseVectorStrategy.open(BaseVectorStrategy.java:30)
at com.mathworks.hg.util.HGVectorOutputHelper.open(HGVectorOutputHelper.java:64)
When I try using a different Windows 10 machine running MATLAB 2018b, the same exact code runs without error. The issue is that I need to use the machine running 2019a due to better processing power. I can't figure out what might be causing this error. Any ideas? Thanks!
  1 commentaire
jloudis
jloudis le 28 Oct 2020
Ok, there is egg on my face. I restarted MATLAB and my code above works without error.

Connectez-vous pour commenter.

Réponses (1)

David Hill
David Hill le 27 Oct 2020
x=0:.01:2*pi;
y=sin(x);
plot(x,y);
plot2pdf('sin')
Simple function below generates pdf.
function plot2pdf(NAME)
fig = gcf;
fig.Units=fig.PaperUnits;
fig.PaperSize= [fig.Position(3) fig.Position(4)];
print(fig, NAME, '-dpdf' );
end
  1 commentaire
jloudis
jloudis le 28 Oct 2020
Thanks for the reply. This is effectively the same function I used in my description ("print") and I get the same error that I listed above. I think it must be an issue with MATLAB settings.

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by