1 | %PDF2EPS Convert a pdf file to eps format using pdftops |
---|
2 | % |
---|
3 | % Examples: |
---|
4 | % pdf2eps source dest |
---|
5 | % |
---|
6 | % This function converts a pdf file to eps format. |
---|
7 | % |
---|
8 | % This function requires that you have pdftops, from the Xpdf suite of |
---|
9 | % functions, installed on your system. This can be downloaded from: |
---|
10 | % http://www.foolabs.com/xpdf |
---|
11 | % |
---|
12 | %IN: |
---|
13 | % source - filename of the source pdf file to convert. The filename is |
---|
14 | % assumed to already have the extension ".pdf". |
---|
15 | % dest - filename of the destination eps file. The filename is assumed to |
---|
16 | % already have the extension ".eps". |
---|
17 | |
---|
18 | % Copyright (C) Oliver Woodford 2009 |
---|
19 | |
---|
20 | % pdf2eps.m,v 1.1 2012/05/08 08:00:33 nadolski Exp |
---|
21 | |
---|
22 | function pdf2eps(source, dest) |
---|
23 | % Construct the options string for pdftops |
---|
24 | if ispc |
---|
25 | options = ['-q -paper match -pagecrop -eps -level2 "' source '" "' dest '"']; |
---|
26 | else |
---|
27 | options = ['-q -paper match -eps -level2 "' source '" "' dest '"']; |
---|
28 | end |
---|
29 | % Convert to eps using pdftops |
---|
30 | pdftops(options); |
---|
31 | % Fix the DSC error created by pdftops |
---|
32 | fid = fopen(dest, 'r+'); |
---|
33 | if fid == -1 |
---|
34 | % Cannot open the file |
---|
35 | return |
---|
36 | end |
---|
37 | fgetl(fid); % Get the first line |
---|
38 | str = fgetl(fid); % Get the second line |
---|
39 | if strcmp(str(1:min(13, end)), '% Produced by') |
---|
40 | fseek(fid, -numel(str)-1, 'cof'); |
---|
41 | fwrite(fid, '%'); % Turn ' ' into '%' |
---|
42 | end |
---|
43 | fclose(fid); |
---|
44 | return |
---|
45 | |
---|