我们在 .net 中为收据构建了一个 mvc。我们编写了一个小程序,它接收我们视图的 url,并将在该 url 生成的收据打印到用户的默认打印机。
有一个特定收据不使用我们的 mvc,因为它与销售无关,而只是服务的小费单。此收据之间的主要区别在于,显示其预览的页面(以及打印它的按钮)与小程序用于打印它的页面相同。因此,小程序本质上采用了预览的 url,但在查询字符串中有一个额外的参数,告诉它除了提示单内容之外不呈现任何内容。
这一切都可以在任何浏览器上的 Windows 上完美运行。然而,当我们切换到 Mac 时,tip slip 只打印大约 15% 的时间,其余时间它只打印一小块空白。就好像小程序没有从 url 获得任何内容,即使当我通过浏览器链接到那个确切的 url 时,我也得到了提示单内容。
我想这可能是一个时间问题。也许小程序没有等到提示单被呈现。
这是小程序的打印方法代码:
public void printDocument(final String url, final boolean ccInfo,
final boolean printDialog)
{
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run()
{
try
{
new ParserDelegator();
JEditorPane jEditorPane = new JEditorPane();
jEditorPane.setEditorKit(new HTMLEditorKit() {
@Override
public ViewFactory getViewFactory()
{
return new HTMLFactory() {
@Override
public View create(Element elem)
{
View view = super.create(elem);
if (view instanceof ImageView)
{
((ImageView) view)
.setLoadsSynchronously(true);
}
return view;
}
};
}
});
jEditorPane.setPage(url);
JeditorRendererer docRenderer = new JeditorRendererer();
}
catch (IOException e)
{
System.out.println("IO Exception");
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
}); }
如您所见,为了让我们的条形码不显示为损坏的图像图标,我重写了创建 ImageView 的方法,以便同步加载它。其余的html内容是否有类似的东西?收据都将是 html 中的文本和底部的图像标签。