简体   繁体   English

在Java中打印多页JEditorPane html内容

[英]Print Multi page JEditorPane html contents in Java

I have developed a code in Java where I have embedded HTML content into a JEditorPane by setting its content type to text / html. 我已经开发了一个Java代码,我通过将其内容类型设置为text / html将HTML内容嵌入到JEditorPane中。

However this content spills over to the second page and so on. 但是,此内容会溢出到第二页,依此类推。 I know that the JEditorPane has a print() method that prints the contents of the JEditorPane and I know that the print() method of the JEditorPane prints all the contents of the JEditorPane and even prints multiple pages. 我知道JEditorPane有一个print()方法打印JEditorPane的内容,我知道JEditorPane的print()方法打印JEditorPane的所有内容,甚至打印多个页面。

What I want is that the top, left, right and bottom margins should be set to 0. 我想要的是顶部,左,右和底部边距应设置为0。

If I would simply leave the work of setting the margins to 0 at run-time by changing the print settings before printing, it would just not work. 如果我只是在运行时通过在打印前更改打印设置而将边距设置为0的工作,那就不起作用了。

Due to this I had to implement the Printable interface. 因此我必须实现Printable接口。 But when I used the Printable interface it allows to print only the first page of the JEditorPane. 但是当我使用Printable接口时,它只允许打印JEditorPane的第一页。

When I searched a lot for this solution I got this link on Google; 当我经常搜索这个解决方案时,我在Google上获得了这个链接;

http://download.oracle.com/javase/tutorial/displayCode.html?code=http://download.oracle.com/javase/tutorial/2d/printing/examples/PaginationExample.java http://download.oracle.com/javase/tutorial/displayCode.html?code=http://download.oracle.com/javase/tutorial/2d/printing/examples/PaginationExample.java

But the problem here is that I am using html contents in the JEditorPane. 但问题是我在JEditorPane中使用html内容。 I dont know how to integrate the above solution provided in the link with a JEditorPane that consists of HTML Code 我不知道如何将链接中提供的上述解决方案与包含HTML代码的JEditorPane集成

If you need real WYSIWYG use articles about paginated printing from here http://java-sl.com/articles.html 如果您需要真正的WYSIWYG,请使用http://java-sl.com/articles.html上有关分页打印的文章

If you need just print JEditorPane's content paginated use this http://java-sl.com/JEditorPanePrinter.html 如果您只需要打印JEditorPane的内容分页,请使用此http://java-sl.com/JEditorPanePrinter.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM