Error printing plot to PDF

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 Comment

Ok, there is egg on my face. I restarted MATLAB and my code above works without error.

Sign in to comment.

Answers (1)

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 Comment

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.

Sign in to comment.

Categories

Find more on Graphics Objects in Help Center and File Exchange

Asked:

on 27 Oct 2020

Commented:

on 28 Oct 2020

Community Treasure Hunt

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

Start Hunting!