Hi,
I have to create a Postscript for a project that I am working on. The file that I create can not be opened by any application. I would be grateful for any help that anyone can give.
public class PostScriptTest {
public static void main(String[] args) throws IOException {
File file = File.createTempFile("test", ".ps");
OutputStream os = new FileOutputStream (file);
os.write(createHeader().toString().getBytes());
os.close();
}
private static String getTodaysDate() {
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
return sdf.format(now);
}
private static StringBuffer createHeader() {
StringBuffer sb = new StringBuffer();
sb.append("%!PS-Adobe-2.0 EPSF-2.0\n"
+ "%%Creator: Page @VERSION@\n"
+ "%%Title: Page \n"
+ "%%CreationDate: "
+ getTodaysDate()
+ "\n"
+ "%%Origin: 0 0\n"
+ "%%BoundingBox: "
+ 0
+ " "
+ 0
+ " "
+ "\n"
+ "%%EndComments\n"
+ "%%BeginProlog\n"
+ "100 dict begin\n"
+ "/wordbreak ( ) def\n"
+ "/linebreak (\\n) def\n"
+ "/doLine {\n"
+ "% <line> <width> <height> <x> <y> doLine <width> <height> <x> <y>\n"
+ "2 copy moveto 5 -1 roll\n"
+ "wordbreak\n"
+ "{\n"
+ " search {\n"
+ " dup stringwidth pop currentpoint pop add 7 index 6 index " +
"add gt {\n"
+ " 6 3 roll 2 index sub 2 copy moveto 6 3 roll\n"
+ " } if\n"
+ " show wordbreak show\n"
+ " }{\n"
+ " dup stringwidth pop currentpoint pop add 5 index 4 index " +
"add gt {\n"
+ " 3 1 roll 3 index sub 2 copy moveto 3 -1 roll\n"
+ " } if\n" + " show exit\n" + " } ifelse\n"
+ "} loop\n" + "2 index sub 2 copy moveto\n" + "} def\n"
+ "/BreakIntoLines{\n"
+ "% <width> <height> <x> <y> <text> BreakIntoLines\n"
+ "linebreak\n" + "{\n" + " search {\n"
+ " 7 3 roll doLine 6 -2 roll\n" + " }{\n"
+ " 5 1 roll doLine exit\n" + " } ifelse\n"
+ " } loop\n" + "pop pop pop pop\n" + "} def\n" + "/to (" +
"14355120438" + ") def\n" + "show"/*+ "/to-adress (" + "Page" + ") def\n"
+ "/from (" + from + ") def\n" + "/todays-date ("
+ getTodaysDate() + ") def\n" + "/regarding (" + regarding
+ ") def\n" + "/comments (" + generateComments()
+ ") def\n"*/);
sb.append("%%EndProlog\n");
return sb;
}
}