File Exchange Pick of the Week

Our best user submissions

Creating Multi-Page PDFs 2

Posted by Jiro Doke,

Jiro's pick this week is append_pdfs (most up-to-date version included in export_fig) by Oliver Woodford.

Today, I'd like to highlight an entry that I mentioned during one of the customer trainings I gave a few months ago. It's from one of our regular MATLAB Central (and MATLAB) user, Oliver, whom many of you may know.

In the training, we were talking about exporting figures to various formats, and one of the attendees wanted to export them as multi-page PDFs. The print function has an option for exporting a figure as a single-page PDF. It also has an option for exporting multi-page PostScript files. So all you need to do is convert the multi-page PostScript file to a PDF. The initial solution I provided was to use an external program, like Ghostscript, to do the conversion. This is actually how I've always done this back when I was in grad school.

Just having learned about "automation" in the training, the attendee wanted to automate this process in MATLAB. I'm sure it's possible, I thought, but I went straight to the File Exchange. There were actually a few entries that looked promising. The one that met my needs was Oliver's. You still do need to install Ghostscript separately, but once you do that, the tool seemed to automatically find it and use it to combine multiple PDFs.

% Create 3 figures and save them individually to PDFs
figure
peaks
print -dpdf fig1.pdf

figure
spy
print -dpdf fig2.pdf

figure
plot(rand(10,3))
print -dpdf fig3.pdf

% Combine three PDFs into one
append_pdfs allfigs.pdf fig1.pdf fig2.pdf fig3.pdf

As I mentioned in the beginning, this functionality is rolled into the ever-so-popular export_fig, for which Oliver was the original author. Oliver mentions that the one in export_fig is the maintained version, so I suggest downloading export_fig.

I do want to put a plug in for Multiple Page PDF by James Herman and ps2pdf by Richard Quist. They both use ghostscript that comes with MATLAB, so you don't need to install anything additional. In R2015b, MATLAB changed how PDFs are generated, so these entries don't work any more, but if you're using an older release of MATLAB, definitely take a look.

Comments

Give this a try and let us know what you think here or leave a comment for Oliver.


Get the MATLAB code

Published with MATLAB® R2015b

Note

Comments are closed.

2 CommentsOldest to Newest

Oliver Woodford replied on : 2 of 2
I'd like to add that Yair Altman should share the credit, given his work maintaining and improving append_pdfs, as the GitHub "blame" shows: https://github.com/altmany/export_fig/blame/master/append_pdfs.m https://github.com/altmany/export_fig/blame/master/ghostscript.m I'm as grateful as all the other users of export_fig for his continued maintenance of that submission.