The PDF export aims to create a page-oriented output of XWiki pages. A number of practical problems come to light in the process.
For example:
- how to print a large table
- how to print graphics
a) which have been created by Javascript and possibly even modified in the browser by input?
b) which should appear in a better resolution when printed. - how to get sensible page breaks?
- how to print in a different style?
- the scaling problem caused by the browser
- watermarks
Some things can be done with macros:
If the actual print job is to be generated via the browser, the document must first be displayed in “print preview” mode. (So branch into its macros using ’ request.xpage.equals(“print”) ').
To (1)
If tables are to be displayed by default in a macro call, for example
{{supertable}}
|= …
| … | …
{{/supertable}}
you can modify the output so that you break the table into individual blocks, as in Excel. (In my case the additional parameter to supertable is called 'printsplit="1-10 / 1,11- # 1-21 / 1,22-40"
'e.g.) to define row and column blocks).
to (2)
Constructions like
{{velocity}} #set ($discard=$xwiki.linkx.use("data:text/css, @media print{ .noprint{ display:none;}} @media screen{ .noscreen {display:none; }}" {'type': 'text/css', 'rel': 'stylesheet'})) {{/velocity}}
and later
(% class="noprint" %)will not print (%%) (% class="noscreen" %)does not appear on the screen(%%)
to (3)
Forcing page breaks with style specifications
Examples:
Page break after the table of contents - example
(% style="page-break-after:always;" %) ((( {{toc start="4"/}} )))
Page break now
> (% style="page-break-before:always;" %)
Prevent page break
(% style="page-break-inside:avoid;" %) ((( . . Stuff that should stay on the same page . )))
to (4)
You can change parts of the print style.
For example:
@media print { page { height : 29.7cm; width : 21.0cm; margin-left: 1cm ; margin-right:0.8cm ; } h1,h2,h3,h4 { color:red !important;} body { font-size:90%; } h1,h2,h3.h4 { page-break-after:avoid;} #back-top {display:none !important;} a[href^="/xwiki/bin/temp"]:after{content:"";} .breadcrumb { display:none !important;} }
Unfortunately, the style specifications for "@media print" in the XWiki are not neatly placed in “print.css
”, so that you can not cleanly replace @media specifications.
to (5)
The browser scales or cuts off information when printing.
In order to identify problem areas (tables or graphics) where the page becomes too wide, which means that the font would be reduced when “adjusting” later, you can create an overlay frame that shows these areas:
{{html clean="false"}}
<div style="width:184.6mm; height:50vh;border:1px solid red;position:fixed;bottom:25vh;z-index:9999"></div>
{{/html}}
to (6)
A watermark when printing provides
(% class="visible-print-block" style="position:fixed; left:30px; top:300px;z-index:999; opacity:0.3;colour:grey; font-size:75pt; border:10pt solid grey; border-radius:20pt; padding:20pt;" %)Temporary(%%)
Basically, however, it should be said that in the draft “CSS Paged Module” (see
CSS Paged Media Module Level 3 )we will probably be offered print support in the browser in the future. Page-oriented output will then become easier.
It would be nice if these things could be easily accessed in the XWiki in the future.
Comments and hints are very welcome.
Norbert