Simple C++ program to convert .eps files to .pdf files for LaTeX

Converting .eps figures to .pdf files and including them in LaTeX is the best way to keep the shapes of figures in their right resolutions and formats. The command for converting one .eps file to .pdf file is: epstopdf <.eps file name> <.pdf file name> , but I think it will be better if we could issue the command like that: epstopdf *.eps to convert all .eps files to their .pdf versions. So I write a very small C++ program to do it automatically:
// Program to convert all .eps (Matlab figures) to .pdf file for LaTeX
// Create date: 2/05/2012
// Author: NGUYEN Huu Tuan
// Compiler: DevCpp, Visual C++
// Using: copy this program to your .eps files' folder and run

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
system(“dir /b *.eps > list.txt”);
ifstream fi(“list.txt”);
ofstream fo(“done.bat”);
int ncount = 0;
clock_t t1, t2;
char str[255];
fo << “@echo off” << endl;
fo << “epstopdf \”” << str << “\”” << endl;
t1 = clock();
t2 = clock();
cout << ncount << ” files, elapsed time is: ” << (double)(t2-t1)/CLK_TCK << ” seconds.”;
system(“del done.bat”);
system(“del list.txt”);
return 0; // it is zero, of course

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: