0

i need to get the width and height of the eps file.

i tried https://github.com/drewnoakes/metadata-extractor

but it doesn't work for eps file.

so i used the exiftool.exe and run it on the program.

but the program is slow. because it runs the program(exiftool.exe) for every eps file.

is there any method to use in order to get the width and height of the eps file faster? thank you

below is my code for getting width and height of an image

System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
                            string filename = tempPath;
                            pProcess.StartInfo.FileName = System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]) + "\\exiftool.exe";
                            string toolPath = @"" + "\"" + filename + "\"";
                            pProcess.StartInfo.Arguments = toolPath;
                            pProcess.StartInfo.CreateNoWindow = true;
                            pProcess.StartInfo.UseShellExecute = false;
                            pProcess.StartInfo.RedirectStandardOutput = true;
                            pProcess.Start();
                            string strOutput = pProcess.StandardOutput.ReadToEnd();
                            pProcess.WaitForExit();
                            string source = strOutput;

sir if i convert it to eps file i need to set its density for a good quality converted image. if i do that. the height and width of the converted image will not be the same. i used ImageMagick dll. for that. and the link also runs an exe file. which will also slow down the program

pdf asker
  • 59
  • 2
  • 11

1 Answers1

2

I'm not sure if this would work for you, but an EPS has a tag

%%BoundingBox: 0 0 350 350

If you read the file you can use this.

eg

var eps = File.ReadAllLines(path).FirstOrDefault(l => l.StartsWith("%%BoundingBox:"));
if (eps != null)
{
    var dimensions = eps.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries)
        .ToList()
        .Skip(1)
        .Select(s => Convert.ToInt32(s))
        .ToList();
    var width = dimensions[2] - dimensions[0];
    var height = dimensions[3] - dimensions[1];
    Console.WriteLine($"{width} {height}");
}

you could optimize this not to read the whole file as the bounding box is at the beginning.

Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156