gpt4 book ai didi

来自 .txt 的 Java 收据文件

转载 作者:行者123 更新时间:2023-11-29 08:46:53 25 4
gpt4 key购买 nike

我正在创建一个程序,它将打印从商店购买的元素的 .txt 收据它打印成功,但我需要更改文本某些特定部分的字体,这可能吗?例如我想打印这样的东西

THIS SHOULD BE BOLD and BIGGER

this should be smaller than the first line

This should be italicized

有可能吗?

更新

这是打印过程的代码

    public static void main(String[] args) throws PrintException, IOException {
String defaultPrinter =PrintServiceLookup.lookupDefaultPrintService().getName();
System.out.println("Default printer: " + defaultPrinter);

PrintService service = PrintServiceLookup.lookupDefaultPrintService();

FileInputStream in = new FileInputStream(new File("sample.txt"));

PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));


DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc doc = new SimpleDoc(in, flavor, null);

DocPrintJob job = service.createPrintJob();
PrintJobWatcher pjw = new PrintJobWatcher(job);
job.print(doc, pras);
pjw.waitForDone();
in.close();

// send FF to eject the page
InputStream ff = new ByteArrayInputStream("\f".getBytes());
Doc docff = new SimpleDoc(ff, flavor, null);
DocPrintJob jobff = service.createPrintJob();
pjw = new PrintJobWatcher(jobff);
jobff.print(docff, null);
pjw.waitForDone();
}
}

class PrintJobWatcher {
boolean done = false;

PrintJobWatcher(DocPrintJob job) {
job.addPrintJobListener(new PrintJobAdapter() {
public void printJobCanceled(PrintJobEvent pje) {
allDone();
}
public void printJobCompleted(PrintJobEvent pje) {
allDone();
}
public void printJobFailed(PrintJobEvent pje) {
allDone();
}
public void printJobNoMoreEvents(PrintJobEvent pje) {
allDone();
}
void allDone() {
synchronized (PrintJobWatcher.this) {
done = true;
System.out.println("Printing done ...");
PrintJobWatcher.this.notify();
}
}
});
}
public synchronized void waitForDone() {
try {
while (!done) {
wait();
}
} catch (InterruptedException e) {
}
}

最佳答案

Bold 示例(假设您的打印机具有与链接到的代码相同的转义序列)。

public static final char ESC =  27;
public static final String BOLD_ON = ESC + "E";
public static final String BOLD_OFF = ESC + "F";

String textString = "some text";
String toPrintInBold = BOLD_ON + textString + BOLD_OFF;

现在 toPrintInBold 已准备好设置到打印机。

如果它有效,那么你就有了一个方法,只需要更多的控制代码。

关于来自 .txt 的 Java 收据文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24793655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com