custom controls: printing

Phil Race philip.race at
Thu Jan 29 07:01:14 UTC 2015

On 1/28/15 10:23 PM, Tom Eugelink wrote:
> Ok, I see my question is not quite clear: I'm not looking for how to 
> print, I am trying to figure out how to properly implement printing on 
> a custom control, more specifically JFxtras' Agenda. Agenda has the 
> same problem as the more recognizable usecase of a spreadsheet: it 
> uses a scrollpane in its skin, so when taking a screenshot this 
> scrollpane limits what is captured, but when printing -like a 
> spreadsheet- I need all the data.
> So first I was trying to grasp how printing in JavaFX works 
> conceptually, but from what I'm decuding so far this is very limited 
> and basically no more that screen capturing. Correct?

You can draw anything you like to the printer. It doesn't have to ever
be displayed on the screen. But any time you (eg) go beyond primitives
where you can define and control the extent and go into the realm
of content driven nodes, you need to deal with pagination and at
that point you need to go back to the data you want to display and
format it for the printer. Printing the list of items in a ComboBox is
very different than printing/draw the ComboBox control.
If the author of a control provides a means to do that for you
(like HtmlEditor does) then it becomes easy. If they don't you'll need
to do it yourself.

If you create an Agenda that is never displayed but has the same
data and set its size so that it can display all the data, I expect
it should be possible to scale it so that it fits on one page like
the example you referenced but once you have 500 items in
your agenda, someone is going to have to handle the magic
that splits that across pages and there's no way the core printing API
could know how to do that for a control. All it sees are Nodes ..


> Tom
> On 29-1-2015 05:53, Phil Race wrote:
>> That example is not great as it picked the one node type that knows 
>> how to do
>> something special with printing and completely overlooks it.
>> The print(Node) method it provides can print any node type but it is 
>> scaling
>> it to fit on a single side of paper. That's not ideal for a huge 
>> spreadsheet/table
>> as you won't be able to read the output without a microscope.
>> I was pointing to the method on webengine that you mention last below
>> as the one you should use and the example does not use that anywhere.
>> To get  proper pagination you need to explicitly call the 
>> WebEngine.print(PrinterJob) method
>> -phil.
>> On 1/27/15 10:22 PM, Tom Eugelink wrote:
>>> Ok, so looking at some examples like 
>>> where PrintJob is let lose on a node, JavaFX's PrintJob will either 
>>> use the screen rendering or -if present- call: public void 
>>> print(PrinterJob job)
>>> Correct?
>>> Tom
>>> On 28-1-2015 02:43, Phil Race wrote:
>>>> On 1/27/15 4:08 PM, Tom Eugelink wrote:
>>>>> Do I need to do something special to support printing of custom 
>>>>> controls? The use case is that on screen a spreadsheet can be 
>>>>> shown in a scrollpane, but when printing the whole spreadsheet 
>>>>> should be printed. 
>>>> Being a 'custom' control doesn't really make a difference here.
>>>> The same would apply if you wanted to print one of the built-in 
>>>> controls
>>>> that is in a scroll pane or otherwise not likely to fit on a page.
>>>> Spreadsheets, like TableView, TextArea and the like will need
>>>> to have their data laid out for the printer by the application.
>>>> In practice this means starting with the data contained in
>>>> the spreadsheet and iterating over it printing as much as fits
>>>> on each page in what ever way you want.
>>>> I am sure that something that can handle this this would
>>>> make a nice add-on to to the core API but it was not something
>>>> that was considered appropriate to be part of FX core.
>>>> We expected reporting packages to pop up from 3rd parties
>>>> The exception to this is HtmlEditor / WebEngine where you
>>>> cannot reasonably expect the application or such a package
>>>> to know how to properly print the data (HTML and other web content)
>>>> Hence that has a method to print its content to a PrinterJob
>>>> So one possibility for you is to throw your data into HTML table 
>>>> syntax, load
>>>> it into a web node and print that.
>>>> -phil.

More information about the openjfx-dev mailing list