Code covered by the BSD License  

Highlights from
append_pdfs

5.0
5.0 | 9 ratings Rate this file 89 Downloads (last 30 days) File Size: 4.55 KB File ID: #31215 Version: 1.6

append_pdfs

by

 

27 Apr 2011 (Updated )

Append/concatenate multiple PDF files into a single file using Ghostscript.

| Watch this File

File Information
Description

This function appends multiple PDF files to an existing PDF file, or concatenates them into a PDF file if the output file doesn't yet exist. This can be much faster than appending PDFs one at at time.
This function requires that you have ghostscript installed on your system. Ghostscript can be downloaded from: http://www.ghostscript.com

It also includes code from the export_fig package to interface with Ghostcript.

This function is now included in the export_fig package:
http://www.mathworks.com/matlabcentral/fileexchange/23629
The version here will not be maintained.

Acknowledgements

Export Fig inspired this file.

MATLAB release MATLAB 7.11 (R2010b)
Other requirements Ghostscript
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (25)
28 Mar 2015 Shijin Thomas

Hi Oliver,
When i run the function it is showing an error
Error: /undefinedfilename in (Location S2 20 km Brake Data B3_0)
Operand stack:

Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
Dictionary stack:
--dict:1191/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 9.15: Unrecoverable error, exit code 1
can you please help on it.

Comment only
28 Jan 2015 David

David (view profile)

 
09 Jan 2015 Dehuan

Dehuan (view profile)

I modified this script to skip non-existant files instead of error and exit. I'm working on automated report generation and source PDFs are not guaranteed to be successfully generated so this feature is useful.

09 Dec 2014 Elad Assia

Hi Oliver,
The function does not wotk for me...
I'm using a computer that is connected to a network and i Don't know whether the Matlab is installed on this computer or another one on the netwotk.
Every time I'm using the function, it creates a pdf file with the name I want but the file is empty. Every time I get this message: "gs: /usr/local/MATLAB/R2013a/bin/glnxa64/libtiff.so.5: no version information available (required by /lib64/libgs.so.9)
Error: /undefinedfilename in (out1)
Operand stack:

Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
Dictionary stack:
--dict:1175/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 9.14: Unrecoverable error, exit code 1"

Do you know how to solve this problem?
Thanks!

Comment only
29 Aug 2014 Oliver Woodford

Andrea: You can't (unless you edit the code, of course). The solution is to delete the file beforehand if you want to overwrite it.

Comment only
29 Aug 2014 Andrea Rosso

This piece of software is awesome. Yet just a tiny question: how can I pass the -f option in order to overwrite already existing files?

29 Jul 2014 Laura

Laura (view profile)

So beautiful, thank you!

04 Jun 2014 Adam

Adam (view profile)

This is a great tool and works very nicely!

Does anyone have any examples where they generate Bookmarks as well? It seems like a relatively easy process. Below is a website that looks to be very useful, so I may try it myself.

http://blog.tremily.us/posts/PDF_bookmarks_with_Ghostscript/

Comment only
14 Oct 2013 Corey

Corey (view profile)

Hi Oliver,
Thank you for your response.
I am indeed using the functional form of the command. Apparently this is a limitation with using GhostScript in general. Was just curious if there was a sneaky workaround for paths that get too long.
http://ghostscript.com/doc/current/Language.htm

Comment only
03 Oct 2013 Oliver Woodford

Christa: To save to a particular folder, just specify the full or relative path in the output filename. I haven't seen the blank first page, so can't help there.

Corey: I haven't seen the 128 character limit problem, so can't really help. However, are you using the functional form of the command? E.g.:
output = 'test.pdf';
inputs = {'long_name1.pdf', 'long_name2.pdf'};
append_pdfs(output, inputs{:});

Comment only
02 Oct 2013 Corey

Corey (view profile)

This is great. I was wondering if you knew a good way to get around the 128 character limit on filename sizes? When you are appending to too many subfolders, the path can get too long, and cause the function to fail. Of course, one could reduce the length of the path, but if there is a sneaky way to get around this 128 character limit, it would be appreciated!

14 Sep 2013 Christa

Thanks for sharing this! It is very helpful. I have a couple questions though. I'd like to save the combined pdf into a specific folder, not just the general matlab folder that I'm working in. Also, it is outputting a blank white sheet as the first page of my pdf. Any idea how to correct either of these issues? Thanks in advance!

Comment only
02 Apr 2013 Courtney

Bitmap/vector problem appears to have resolved itself. Disregard my question. Thanks!

Comment only
02 Apr 2013 Courtney

Hi Oliver,
Thanks for your suite of image exporting functions. I'm having an issue with complex (large, ~15MB) vector-rendered pdfs being transformed to bitmaps when combined, and getting pixelated. Any way around this?

Comment only
26 Feb 2013 Claudia  
21 Aug 2012 Ben Noffke  
10 Apr 2012 Christoph david  
10 Apr 2012 Christoph david

Thank you very much! You were right. I created a cell array and now it works.

I apologize for the rate.
This was my first post on mathworks. When I clicked the "submit" button nothing happend so I thought I have to rate. Without thinking (and without reading) I rated 4 stars. Than I realised that I just had to reload the page to see my post.
Sorry for that.

Thank you for this tool!

Comment only
10 Apr 2012 Oliver Woodford

Christoph: This an issue with your use of MATLAB syntax, rather than anything else. Make a cell array, string1, of the input file names, then call
append_pdfs('output.pdf', string1{:});
It's not clear why gave the function 4 stars. Any suggestions?

Comment only
10 Apr 2012 Christoph david

It works when I write output, input1, input2 inside '' with .pdf extensions <== true.
+ I can't make it work if I stock all inputs during a loop in a string (the string includes the apostrophes and commas)
e.g. string1='input1','input2'
append_pdfs('output',string1) doesn't work.
Anyone an idea how to make it work?
Thx a lot!

03 Apr 2012 Hakan Çakan

Oliver,
Thank you very much. I solved it but in the help section it is written that:

% Example:
% append_pdfs(output, input1, input2, ...)

It works when I write output, input1, input2 inside '' with .pdf extensions. It would be beter if you update help file accordingly.

Thanks again.

Comment only
05 May 2011 Oliver Woodford

Michael: Fix submitted. Thanks for reporting the problem.

Comment only
04 May 2011 Michael Teo

I was trying to appends 200+pdfs to 1 pdf. It resulted in "The command line is too long." message.

Pls advise, thanks.

Comment only
04 May 2011 Oliver Woodford

Thanks, David. It'll be in the next version.

Comment only
28 Apr 2011 David Chorlian

Regarding ghostscript.m, in Linux /usr/bin/gs is the more likely path for gs.

Comment only
Updates
28 Apr 2011 1.1

Bug fix to ghostscript.m mostly affecting Linux (thanks to Paul Durack for reporting it).

05 May 2011 1.2

Fixed bug affecting long commands. Thanks to Michael Teo for reporting it.

01 Jun 2011 1.3

Improve quality of bitmaps. Thanks to Martin Wittmann for pointing out the issue.

10 Apr 2012 1.5

Added more syntax examples.

08 Jul 2014 1.6

Update description as added to export_fig package

Contact us