MATLAB: Can’t I open the PDF file generated using the ‘print’ function with default printer ‘Microsoft Print to PDF’

MATLAB

I use the following code to print a pdf file:
figure()
plot([0 1])
xlabel('Test')
ylabel('Test')
filename = 'Test.pdf';
if exist(filename,'file')
delete(filename)
end
print('-PMicrosoft Print to PDF',filename)
The resulting file 'Test.pdf' cannot be opened by Adobe.
How do I fix this issue?

Best Answer

Specifying the format flag as '-dpdf' resolves the issue.
figure()
plot([0 1])
xlabel('Test')
ylabel('Test')
filename = 'Test.pdf';
if exist(filename,'file')
delete(filename)
end
print('-PMicrosoft Print to PDF',filename,'-dpdf')