Wednesday, November 19, 2014

Matlab: Compile all open figures as a single pdf

As part of my network status log processing script, I needed a way to export weekly overview plots in a format that could be used to convey problems to other people at a glance.  The larger body of the script is a block-mode kludge which does the actual log file processing and plotting in whatever manner I choose.  The final block is a brief bit which rolls the current figure windows into a single pdf.
%% print plots to pdfs; use pdfshuffler to cat or fix rotations

filebasename='/home/ikilledsuperman/plot_%d.pdf'
outputname='/home/ikilledsuperman/outputlogfile.pdf'

m=length(findall(0,'type','figure'));
filelist=cell(m,1);
for n=1:1:m
    figure(n);
    set(n,'PaperUnits','normalized');
    set(n,'PaperPosition', [0 0 1 1]);  %fit to page
    filelist(n)=cellstr(sprintf(filebasename,n));
    print(gcf, '-dpdf', sprintf(filebasename,n));
end

delete(outputname)
append_pdfs(outputname, filelist{:});
delete(filelist{:})
As the comment says, pdfshuffler can be used to put the finishing touches on any generated pdfs.  Close any unneeded figure windows with 'close all'.  This script makes use of append_pdfs.  

No comments:

Post a Comment