java,以粗体打印
java, print in bold
如何在 printf 中以粗体打印输出? "[1m testing bold"
什么都不做。
String format = "%-20s %-15s %-20s %-15s %-10s";
System.out.printf(format, "Name", "Group_name", "Java_Prof_Level", "Cpr_Nr", "Gender", "[1m testing bold");
这实际上取决于所使用的控制台类型。对于像 Netbeans 和 Eclipse 这样的 IDE,我不确定你是否可以影响字体。但对于大多数终端,以下转义字符有效:
String textInBold = "Java_Prof_Level";
System.out.print("3[0;1m" + textInBold);
您不能使用 Java System.out
打印粗体。它只是流式传输到标准输出流,因此原则上它只是未格式化的文本。
但是,一些软件包解释特殊字符序列(所谓的 ANSI 转义序列)以允许格式化。
请注意,ANSI 转义序列以转义字符开头,因此您还需要将其添加到您的字符串中。 (尝试 "\u001B[1m I am bold"
或 "3[0;1m" + "I am bold"
。)
大多数 Unix 终端默认解释 ANSI 转义序列。在旧的 DOS 时代,您需要使用 ANSI.SYS 才能使转义序列起作用。
在 Windows 和 Eclipse 终端中,代码不起作用。
我找到了这个。适用于爱普生 ECS/POS
string ESC = "\u001B";
string GS = "\u001D";
string InitializePrinter = ESC + "@";
string BoldOn = ESC + "E" + "\u0001";
string BoldOff = ESC + "E" + "[=10=]";
string DoubleOn = GS + "!" + "\u0011"; // 2x sized text (double-high + double-wide)
string DoubleOff = GS + "!" + "[=10=]";
printJob.Print(InitializePrinter);
printJob.PrintLine("Here is some normal text.");
printJob.PrintLine(BoldOn + "Here is some bold text." + BoldOff);
printJob.PrintLine(DoubleOn + "Here is some large text." + DoubleOff);
pdf 的第一页
here a reference link
我必须在命令前加上“”。否则无效:
oStream.print(""+(char)27+(char)97+(char)1);//for center text
如何在 printf 中以粗体打印输出? "[1m testing bold"
什么都不做。
String format = "%-20s %-15s %-20s %-15s %-10s";
System.out.printf(format, "Name", "Group_name", "Java_Prof_Level", "Cpr_Nr", "Gender", "[1m testing bold");
这实际上取决于所使用的控制台类型。对于像 Netbeans 和 Eclipse 这样的 IDE,我不确定你是否可以影响字体。但对于大多数终端,以下转义字符有效:
String textInBold = "Java_Prof_Level";
System.out.print("3[0;1m" + textInBold);
您不能使用 Java System.out
打印粗体。它只是流式传输到标准输出流,因此原则上它只是未格式化的文本。
但是,一些软件包解释特殊字符序列(所谓的 ANSI 转义序列)以允许格式化。
请注意,ANSI 转义序列以转义字符开头,因此您还需要将其添加到您的字符串中。 (尝试 "\u001B[1m I am bold"
或 "3[0;1m" + "I am bold"
。)
大多数 Unix 终端默认解释 ANSI 转义序列。在旧的 DOS 时代,您需要使用 ANSI.SYS 才能使转义序列起作用。
在 Windows 和 Eclipse 终端中,代码不起作用。
我找到了这个。适用于爱普生 ECS/POS
string ESC = "\u001B";
string GS = "\u001D";
string InitializePrinter = ESC + "@";
string BoldOn = ESC + "E" + "\u0001";
string BoldOff = ESC + "E" + "[=10=]";
string DoubleOn = GS + "!" + "\u0011"; // 2x sized text (double-high + double-wide)
string DoubleOff = GS + "!" + "[=10=]";
printJob.Print(InitializePrinter);
printJob.PrintLine("Here is some normal text.");
printJob.PrintLine(BoldOn + "Here is some bold text." + BoldOff);
printJob.PrintLine(DoubleOn + "Here is some large text." + DoubleOff);
pdf 的第一页 here a reference link
我必须在命令前加上“”。否则无效:
oStream.print(""+(char)27+(char)97+(char)1);//for center text