Java没有';t使用Windows上打印机设置中定义的纸张大小
我在windows打印机设置上定义了一个自定义纸张大小,该设置被以下java代码忽略:Java没有';t使用Windows上打印机设置中定义的纸张大小,java,windows,printing,size,Java,Windows,Printing,Size,我在windows打印机设置上定义了一个自定义纸张大小,该设置被以下java代码忽略: public class Test { final static String fileName = "C:\\test.txt"; public static void main(String[] args) throws FileNotFoundException, PrintException { java.util.Hashtable printers = new j
public class Test {
final static String fileName = "C:\\test.txt";
public static void main(String[] args) throws FileNotFoundException, PrintException {
java.util.Hashtable printers = new java.util.Hashtable();
PrintService ps = PrintServiceLookup.lookupDefaultPrintService();
printers.put("##DefaultPrinter##", ps);
String printerToUse = "##DefaultPrinter##";
printDoc(fileName, ps);
}
private static void printDoc(String fileName, PrintService ps) throws FileNotFoundException, PrintException {
FileInputStream fInput = null;
DocFlavor[] docFlavor = ps.getSupportedDocFlavors();
DocFlavor flavor = null;
if (fileName.endsWith("txt")) {
flavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8;
if (!ps.isDocFlavorSupported(flavor)) {
File bomFile = new File(fileName);
}
}
if (flavor == null || !ps.isDocFlavorSupported(flavor)) {
flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
}
fInput = new FileInputStream(fileName);
DocPrintJob pj = ps.createPrintJob();
Doc doc = new SimpleDoc(fInput, flavor, null);
pj.print(doc, null);
}
}
当我使用此代码打印“C:\test.txt”的内容时,内容将以默认纸张大小A4打印。当使用记事本++或记事本选择java获得的同一打印机打印同一文件时,内容将按照打印机上定义的自定义纸张大小打印
自定义纸张尺寸的高度为7.5 cm。内容为30行,每行带有word test,当在java上打印时,内容连续打印,一行在另一行的下方,不考虑页面划分,当使用notepad++打印时,内容拆分为3页,涉及打印机设置上的页面定义
要使用打印机上定义的自定义纸张大小,我必须在java代码中做哪些更改