I'm currently reading and writing .EPS file to manipulate/add metadata (Keywords and Tags) in the file.
PS: File encoding is Windows-1251 or Cp1251 -Russian-
I'm reading EPS file like this: (String lines;
is a global variable)
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "Cp1251"))) {
String line;
while((line = br.readLine()) != null) {
if(line.contains("</xmpTPg:SwatchGroups>")) {
lines.add(line);
lines.add(descriptionKwrds);
}
else
lines.add(line);
System.out.println(line);
}
} catch (FileNotFoundException ex) {
Logger.getLogger(script.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(script.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(script.class.getName()).log(Level.SEVERE, null, ex);
}
In above descriptionKwrds
is the metadata (tags) that I want to manipulate an EPS file like:
String descriptionKwrds = "<photoshop:AuthorsPosition>icon vector illustration symbol bubble sign</photoshop:AuthorsPosition>";
And writing EPS file like this:
try {
try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file.getName()), "Cp1251"))) {
for(String s : lines)
out.write(s + "\n");
out.flush();
}
} catch (FileNotFoundException ex) {
Logger.getLogger(script.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(script.class.getName()).log(Level.SEVERE, null, ex);
}
File is reading and writing correctly, but when I open newly generated file. It says that the file is corrupted.
Files before and after manipulation are file1 and file2 respectively. And using ESP Converter to open EPS files online.
How I can achieve it?