我试图从Java小程序打印自定义纸张大小.我已经设置了纸张尺寸,但它被忽略了.
我也试过使用书籍方法,因为我已经看到了一些有关这方面的帮助,但是当我使用它时,它只是打印一个空白页面,似乎仍然是A4(我打算打印检查显然很多较小(8"x 4")).
我试图从JEditorPane打印HTML,如果这有任何区别.
如果你有任何想法,我会非常感激,我正用这一个撕裂我的头发.
我还应该补充一点,就Java而言,我是一个初学者.
这是我到目前为止:
更新: 我现在已经有了正确的页面大小,但似乎无法获取我正在加载的HTML页面以适应或与页面大小对齐.
更新: 现在我无法让applet在浏览器中运行.它的工作原理是eclipse而不是浏览器.我还需要从参数传递URL.
这是我正在使用的HTML applet标签和更新的Java代码:
<!DOCTYPE html>
<html>
<head><title>Printing Cheque</title></head>
<body>
<applet width=100 height=100 code="HTMLPrinter"
archive="cheque_print.jar">
</applet>
</body>
</html>
package com.yunatech.pns.chequeprint;
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.swing.JEditorPane;
public class HTMLPrinter extends Applet {
/**
*
*/
private static final long serialVersionUID = 8065834484717197790L;
private static JEditorPane editor;
public HTMLPrinter() {
try {
editor = new JEditorPane();
editor.setPage("http://localhost/print_test/test.html");
PrinterJob …Run Code Online (Sandbox Code Playgroud)