


PS2PDF Converts a PostScript file into Adobe PDF format. PS2PDF(FILENAME), where FILENAME is a PostScript file, will convert a .ps file to an Adobe .pdf file. Although Matlab supports directly printing to a PDF driver, the PS driver has added flexibility (e.g., it allows pages to be appended to an existing file). PS2PDF eases the process of ending up with a PDF document after using the PS flexibility while creating a document. PS2PDF deletes the PostScript file after the PDF file is created. This function uses the GhostScript driver packaged with Matlab for portability. See also REPORT_ADDPAGE.


0001 function ps2pdf(filename) 0002 %PS2PDF Converts a PostScript file into Adobe PDF format. 0003 % PS2PDF(FILENAME), where FILENAME is a PostScript file, will convert a 0004 % .ps file to an Adobe .pdf file. Although Matlab supports directly 0005 % printing to a PDF driver, the PS driver has added flexibility (e.g., 0006 % it allows pages to be appended to an existing file). PS2PDF eases 0007 % the process of ending up with a PDF document after using the PS 0008 % flexibility while creating a document. 0009 % 0010 % PS2PDF deletes the PostScript file after the PDF file is created. 0011 % 0012 % This function uses the GhostScript driver packaged with Matlab 0013 % for portability. 0014 % 0015 % See also REPORT_ADDPAGE. 0016 0017 % Argument checking. 0018 if (~exist(filename)), error('File does not exist.'); end; 0019 [p,file,ext] = fileparts(filename); 0020 filename = fullfile(p, file); 0021 0022 % Standard locations for Matlab's GhostScript directories 0023 s = filesep; 0024 gs_root = [matlabroot s 'sys' s 'ghostscript']; 0025 gs_bin = [gs_root s 'bin' s 'win32' s 'gs']; 0026 gs_init = [gs_root s 'ps_files']; 0027 gs_font = [gs_root s 'fonts']; 0028 0029 % Set up a system call to GhostScript 0030 libraries = [' -I' gs_init ';' gs_font ' ']; 0031 nointeract = [' -dBATCH -dNOPAUSE ']; 0032 pdfoutput = [' -sDEVICE=pdfwrite -sOutputFile=' filename '.pdf ' ]; 0033 [s,w] = system([gs_bin libraries nointeract pdfoutput filename '.ps']); 0034 0035 % Delete the .ps file 0036 delete([filename '.ps']);