简体   繁体   English

Java打印作业切断页面边缘

[英]java print job cutting off the edge of the page

An application uses a jEditorPane to display html pages, which also has the ability to print said html page. 应用程序使用jEditorPane来显示html页面,该页面也可以打印该html页面。 We construct the MediaPrintableArea for the printerJob attributeSet like so: 我们为printerJob attributeSet构造MediaPrintableArea,如下所示:

    float mediaWidth = mediaSize.getX(Size2DSyntax.MM);
    float mediaHeight = mediaSize.getY(Size2DSyntax.MM);
    float imageableX = 18;
    float imageableY = 25;
    float imageableWidth = (mediaWidth - (2 * imageableX));
    float imageableHeight = (mediaHeight - (2 * imageableY));
    MediaPrintableArea imageableArea = new MediaPrintableArea(imageableX, imageableY, imageableWidth, imageableHeight, Size2DSyntax.MM);

So we control the printable area of the page. 因此,我们控制页面的可打印区域。 However, when the moons align and a single line is just the right length, the end of the last character in the line is being cut off. 但是,当卫星对齐且单行恰好长度时,该行中最后一个字符的结尾将被切除。

EX: if a line ends with the word "to", there will only be the left-most half of the 'o' visible on the printed page. 例:如果一行以单词“ to”结尾,则在打印页面上只能看到“ o”的最左半部分。 I would expect if this were to run off the edge of the printable are, "to" would wrap to the next line, but its not. 我希望这是否超出了printable的范围,“ to”将换行到下一行,但不是。

Is there some other method of defining the printable area besides using the MediaPrintableArea? 除了使用MediaPrintableArea之外,还有其他方法来定义可打印区域吗? Is there anything that can be causing the words to not wrap or how java calculates the placement of the words? 有什么可能导致单词不自动换行或者java如何计算单词的位置?

We've also tested several other printers and printed from browsers where we can print beyond there our java print job is cutting off, so I don't think hardware problems should be considered. 我们还测试了其他几台打印机,并通过浏览器进行打印,这些浏览器可以在该处进行打印,因此我们的Java打印工作正在中断,因此我认为不应考虑硬件问题。

You're probably rendering the JEditorPane starting from (0, 0) instead of from PageFormat.getImageableX(), PageFormat.getImageableY(). 您可能正在从(0,0)开始而不是从PageFormat.getImageableX(),PageFormat.getImageableY()渲染JEditorPane。 See http://java.sun.com/developer/onlineTraining/Programming/JDCBook/advprint.html for more information. 有关更多信息,请参见http://java.sun.com/developer/onlineTraining/Programming/JDCBook/advprint.html

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

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