MATLAB Answers

Print figure to pdf -- file size too large

73 views (last 30 days)
Tom on 26 Feb 2015
Commented: Tom on 23 Mar 2015
I have a function which creates a plot that has roughly 500,000 data points on it. When I print this figure to a pdf and open the pdf file it takes slightly longer to open than a less complex plot (meaning less data points). A colleague of mine uses the same function to generate the same plot and print to pdf; when he opens this pdf file it may take 5 minutes to display the plot.
He can send me the pdf file generated on his machine and it still takes longer than expected to open the file on my machine.
I was under the impression that when printing to a pdf I was essentially saving an image. Why would a complex plot with more data points take longer to open (as a pdf) than a plot with less data on it if this is true?
Problem is occurring on a Windows 64-bit machine running Matlab 2014b. I am using a Windows 64-bit machine running Matlab 2013b.
I have tried specifying the resolution '-r300' but that does not seem to make a difference.
Is there a different way I can save this figure to a pdf file to avoid this problem?
I have included some sample code which reproduces the results:
t = linspace(0,10,500000);
A = 10;
for i=1:length(t)
x(i) = A*sin(40*pi*t(i))+rand(1)/2;
y(i) = A*cos(40*pi*t(i))+rand(1)/2;
hf = figure;
grid on
title('200 Circles','fontweight','bold','fontsize',14)
Thanks for the help!

Accepted Answer

Richard Quist
Richard Quist on 21 Mar 2015
Edited: Richard Quist on 21 Mar 2015
I would guess that the PDF is being saved with an embedded image in 13b, and as a fully vectorized file in 14b. Try adding '-opengl' to your print command to force the use of the OpenGL renderer which will embed the figure as an image.
print(hf,'-dpdf','Test_plot.pdf', '-opengl')
  1 Comment
Tom on 23 Mar 2015
Thanks! It looks like this is just what I was looking for.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!