forked from mapfish/mapfish-print-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jasperreports.html
772 lines (722 loc) · 33.5 KB
/
jasperreports.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MapFish Print 3 Documentation - Jasper Reports</title>
<link rel="stylesheet" href="css/sphinx_rtd_theme.css" type="text/css" />
<link rel="stylesheet" href="css/readthedocs-doc-embed.css" type="text/css" />
<link rel="stylesheet" href="css/custom.css" type="text/css" />
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="index.html" class="icon icon-home"> MapFish Print 3</a>
</div>
<div
class="wy-menu wy-menu-vertical"
data-spy="affix"
role="navigation"
aria-label="main navigation"
>
<ul class="current">
<li class="toctree-l1 ">
<a class="reference internal " href="index.html">Introduction</a>
</li>
<li class="toctree-l1 current">
<a class="reference internal current" href="jasperreports.html"
>JasperReports</a
>
</li>
<li class="toctree-l1 ">
<a class="reference internal " href="api.html">Web API</a>
</li>
<li class="toctree-l1 ">
<a class="reference internal " href="attributes.html">Attributes</a>
</li>
<li class="toctree-l1 ">
<a class="reference internal " href="configuration.html"
>Configuration</a
>
</li>
<li class="toctree-l1 ">
<a class="reference internal " href="layers.html">Map Layers</a>
</li>
<li class="toctree-l1 ">
<a class="reference internal " href="processors.html">Processors</a>
</li>
<li class="toctree-l1 ">
<a class="reference internal " href="fileloaders.html">File-Loaders</a>
</li>
<li class="toctree-l1 ">
<a class="reference internal " href="outputformats.html"
>Output Formats</a
>
</li>
<li class="toctree-l1 ">
<a class="reference internal " href="styles.html">Styles</a>
</li>
<li class="toctree-l1 ">
<a class="reference internal " href="tableimages.html"
>Images in tables</a
>
</li>
<li class="toctree-l1 ">
<a class="reference internal " href="download.html">Download</a>
</li>
<li class="toctree-l1 ">
<a class="reference internal " href="docker.html">Docker</a>
</li>
<li class="toctree-l1 ">
<a class="reference internal " href="scaling.html">Horizontal scaling</a>
</li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">MapFish Print 3</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li>Jasper Reports</li>
<li class="wy-breadcrumbs-aside">
<a href="https://github.com/mapfish/mapfish-print" class="fa fa-github">
mapfish/mapfish-print</a
>
</li>
</ul>
<hr />
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Jasper Reports</h1>
<div class="section"><p>
For generating reports Mapfish Print uses
<a href="http://community.jaspersoft.com/project/jasperreports-library">Jasper Reports</a>. Jasper Reports
is a mature library generating reports. From the website:
</p>
<blockquote>
The JasperReports Library is the world's most popular open source reporting engine. It is entirely written
in Java and it is able to use data coming from any kind of data source and produce pixel-perfect documents
that can be viewed, printed or exported in a variety of document formats including HTML, PDF, Excel,
OpenOffice and Word.
</blockquote>
<p>
The central part of Jasper reports are the templates. A template is the layout of the report. It contains
branding, styling and the definition/layout of the report data. Once a template is created, it can be
compiled and ran to generate the report. In certain cases, all the required data (database connection
parameters, url to images, etc...) are present in the template but it can also contain parameters that need
to be set by the executor of the template. In the case of Mapfish print, the latter pattern is used. The
output of the <a href="processors.html">processors</a> and <a href="attributes.html">attributes</a> defined
in the configuration file(config.yaml) will be passed to the jasper report template for execution. The
values can be used by the template to as the parameters.
</p>
<p>
When designing the template, the trick is to know the type of object that will be passed to the template
from Mapfish print. For example, the <a href="processors.html#!createMap">createMap processor</a> will pass
a sub-report to the template, which will need to be embedded into the template. This information should be
provided in the documentation of the various <a href="processors.html">processors</a>.
</p>
<p>
In addition to needing to know how to embed the output of processors, all the other input parameters of the
template must be added to the attributes section in the config.yaml
</p>
<h2>Practical guide to Jaspersoft Studio</h2>
<h3>Basics</h3>
<p>
Templates for jasper reports can be created by hand. However, you may be interested to use a pleasant
interface since we are talking about visual products.
<a href="https://community.jaspersoft.com/project/jaspersoft-studio/releases"> Jaspersoft Studio</a> is the
software we recommend to use. It has an active community and a good support. Jaspersoft Studio will help you
creating a jrxml file, which is a template layout. It is the main and sometimes only file needed for a
printed report. This file will be compiled as a .jasper file before creating the print output. Used with
Mapfish Print, the jrxml file will take the role of a "container", waiting for data to produce a nice and
useful PDF report. If you are deeply interested in the way reports Studio are created with Jaspersoft, you
can follow this
<a
href="https://community.jaspersoft.com/
wiki/designing-report-jaspersoft-studio"
>tutorial</a
>. However, the Mapfish Print pipe allow us to leave out huge parts of the report creation workflow (we can
at least skip the chapter about loading data in the report). <br />
<br />
On the following file, you can observe the principle parts of Jaspersoft Studio:
</p>
<img src="images/jaspersoft.png" alt="Jaspersoft Studio, overview" style="max-height: 300px" />
<ol>
<li>
The report template (what your are currently editing), through either a gui view or a text view (tabs at
the bottom left corner)
</li>
<li>Outline for managing bands, parameters, variables etc.</li>
<li>Property window of selected item. Appearance, content properties and advanced properties.</li>
<li>Elements available for insertion in the report (do not use the map element).</li>
<li>Shortcut to preconfigure fields</li>
<li>Console for information and errors</li>
<li>Data connection (not used with Mapfish Print)</li>
</ol>
<p>
Jasper reports have a "band logic": different data will fall in different bands. The report will be
structured in many bands, which have each one particular behaviors. Moreover, the data themselves affect how
the bands will be printed. This is shown on the next graphic. What you see in Jaspersoft Studio is therefore
not what you will get. The preview tab in the main window allows to pass through this inconvenience when
working on a report template. Unfortunately, the introduction of maps by Mapfish Print doesn't allow to use
directly the preview tab in Jaspersoft Studio.
</p>
<h4>Mapfish Print, jasper reports and Jaspersoft Studio</h4>
<p>
One of the most important change from version 2 to 3 of Mapfish Print, at least for users, is the use of
jasper template (jrxml) as basis of layout. The chapter "General workflow for adapting existing templates"
provides enough information for working with Jaspersoft Studio. The key point stands in the fact that
Mapfish Print as NOT been developed for enhancing the Studio software, but the Jasper Report Library. This
remark involves some sort of incompatibility with Studio, however being easily solved by small
manipulations. When editing template in Jaspersoft Studio, keep in mind this last point.
</p>
<img src="images/jasperbands.png" alt="Band logic representation" style="max-height: 300px" />
<h3>Elements vs Content</h3>
<p>
An important concept is the differentiation between the containers you add to your template and all the
things with which you can populate them. Containers are called "elements" in Jaspersoft Studio and are
visible under the number 4 in the previous image. The main elements are static text, text field and
subreport. With Mapfish Print, all special elements (maps, scale bar, etc.) are placed as subreport. Apart
from maps elements, we are here mainly focused on the text fields. Text fields have dynamic text thanks to
the expressions. An expression can use parameters, variables or functions (we don't discuss the fields since
we are not interesting in loading data directly from database).
</p>
<ol>
<li>
Parameters : set at the compiling. They can be string, integer, boolean etc. The map elements are passed
by parameters, as well as scale bar, north arrow, etc. More standard parameters can also be used with
Mapfish Print, as title or comments for example
</li>
<li>
Variables : they are calculated at the compiling. They are not given by an external source of the report,
as parameters. Variables are typically page numbers or current date. They can also represent a value
calculated on parameters.
</li>
<li>Functions : java functions, for example String.format("static text: %.0f", parameter)</li>
</ol>
<h3>The bands</h3>
<p>
The table below comes from this
<a href="http://www.jasperassistant.com/docs/guide/ch06s10.html">website</a>. More than description of
bands, it provides a broad and clear idea of the logic behind jasper reporting. <br />
<br />
Take a look at the most important bands : Title, page header, detail, background.
</p>
<table>
<tr>
<td>Title</td>
<td>This section appears only once at the beginning of the report.</td>
</tr>
<tr>
<td>Page Header</td>
<td>This section appears at the beginning of each page in the generated document.</td>
</tr>
<tr>
<td>Column Header</td>
<td>
This section appears at the beginning of each column in the generated document. If the report has only
one column defined, then column header and footer sections are ignored.
</td>
</tr>
<tr>
<td>Group Header</td>
<td>
This section is introduced by a report group (chapter Groups). Each time the grouping expression changes
its value, the group header section is printed above the detail section. In case, if more than one group
is defined, the group header is printed in the order of group definition.
</td>
</tr>
<tr>
<td>Detail</td>
<td>
This section is repeated for each line of data supplied by the report's data source. The detail section
can be made of multiple bands.
</td>
</tr>
<tr>
<td>Group Footer</td>
<td>
This section is introduced by a report group (chapter Groups). The group footer section is printed below
the detail section before the value of the grouping expression changes. The group footer is always
printed for the last line of data in data source. In case, if more than one group is defined, the group
footer is printed in the reverse order of group definition.
</td>
</tr>
<tr>
<td>Column Footer</td>
<td>
This section appears at the bottom of each column. If the report's column count is 1, then column header
and footer sections are ignored.
</td>
</tr>
<tr>
<td>Page Footer</td>
<td>This section appears at the bottom of each page.</td>
</tr>
<tr>
<td>Last Page Fotter</td>
<td>
This section replaces the regular page footer on the last page of the report. In case the summary
section is also present, then this might not be the very last page of the document. This section is
sometimes useful when summary information has to be displayed at the bottom of the last page.
</td>
</tr>
<tr>
<td>Summary</td>
<td>This section appears only once at the end of the report.</td>
</tr>
<tr>
<td>No Data</td>
<td>
This section is printed when the When No Data Print report property is set to No Data Section. If the
<noData> section is defined in the report template, and if the data source is empty, then the
<noData> section will be the only one taken into account at fill time, and its content will
produce the report output.
</td>
</tr>
<tr>
<td>Background</td>
<td>
The background section is displayed on every page and cannot overflow to the next page. Elements placed
on this section are evaluated at page initialization time and are displayed in the background. All other
page objects are displayed on top of the background objects. This section is useful for creating page
watermarks.
</td>
</tr>
</table>
<h3>Parameters, Variables and Expressions</h3>
<p>
Above is a brief description of differences between parameters, variables and functions. We will see here in
more details how to fill elements of template with parameters and variables.
<br />
<br />
As described, parameters are values given by an external source of the report. In an ordinary application,
parameters are often transmitted through a web service. It is therefore complex (but possible) to add or
delete new parameters. Good news is that once you have you service running, you will not require parameters
other than those already in place, at least in most cases. New parameters can be created in the outline
window of Jaspersoft Studio by right-clicking on "Parameters". Another way is to create directly the
parameter in the source code by adding a line on the top of the document, near the other parameter
declarations. For example, declaring the new "title" parameter is done as follow :
</p>
<div class="highlight">
<pre>
<parameter name="title" class="java.lang.String" isForPrompting="false">
<parameterDescription><![CDATA[Title of map]]></parameterDescription>
</parameter>
</pre
>
</div>
<p>
<i>name</i> is the name of the parameter, <i>class</i> is the java class (String, Integer, Float, Boolean,
etc.), <i>isForPrompting</i> (see further) will be ignore outside Jaspersoft Studio. Last,
<i>parameterDescription</i> is optional. Once again, you don't have to add more parameters and this
explanation is more for understanding parameters than for manipulation purposes. <br />
<br />
the title parameter will be called with the following expression:
</p>
<blockquote>$P{title}</blockquote>
<p>
$P{title} would be for a parameter, $V{title} would be for a variable, $F{title} would be for a database
field.
<br />
<br />
It's already known that parameters and variables are reporting values, but are not displayed by their own on
the printed report. A container needs to be set for displaying them. For a simple text parameter, we can use
a text field container. Back to the title example :
</p>
<div class="highlight">
<pre>
<textField>
<reportElement x="179" y="0" width="375" height="12"/>
<textFieldExpression><![CDATA[$P{title}]]></textFieldExpression>
</textField>
</pre
>
</div>
<p>
<i>textField</i> is the container in which we will add content. <i>reportElement</i> describes where and how
the field will be displayed. It's the property of the container. Contents are added to the container through
an expression. It may be a good habit to use the expression editor of Jaspersoft Studio since it has useful
error messages.
</p>
<img src="images/expression.png" alt="expression edito" style="max-height: 300px" />
<p>
After the selection of a report element, click on 1 to open content properties and then on 2 to open the
editor. The expression editor will open for customization of the expression in 3.
<br />
<br />
All the same goes for variables usage, with the difference that a variable has its own expression (recall:
variables are not passed to the report but calculated directly at print generation time).
</p>
<h3>Appearance</h3>
<p>
Visual settings of report elements are found in the Appearance tab of the property window. The location
refers to the top left corner position of the element. ⚠ Location is given in reference to the band
beginning without the margins. Margins of the documents are set in the page format settings:
<br />
<br />
Outline -> select main document (top) -> property window -> tab "report" -> edit page format (bottom)
<br />
<br />
It's here that behavior of fields are set. For example, you can allow a text field to be multiline and to
extend if the text (passed as parameter) is very long. In this case, you will tell the rest of the
documents, below the extension, to shift down. Since such behaviors are not easy to manage, it's recommended
to set elements not stretchable and fixed relative to the top. In case you implement other behaviors, it
would be worth to extract the best of all the sections (header, details, summary, etc.) for managing many
pages.
</p>
<h4>PDF fonts</h4>
<p>
⚠ The number of fonts supported by PDF documents are limited. There is a special method of setting PDF
fonts for text fields. This is done under the ui path: select element -> property window -> tab "advanced"
-> tree: font -> PDF font name. It may be easier to set the PDF font directly in the source code. All the
care must be taken, on the other hand, for setting a valid PDF font name. Such code can looks like the
following:
</p>
<div class="highlight">
<pre>
<staticText>
<reportElement x="0" y="0" width="100" height="19"/>
<textElement textAlignment="Center">
<font pdfFontName="Helvetica-Bold" pdfEncoding=""/>
</textElement>
<text><![CDATA[Printed through GeoMapFish]]></text>
</staticText>
</pre
>
</div>
<h3>Tips</h3>
<h4>Snapping on the grid</h4>
<p>
One of the most important tool in Jaspersoft Studio is the snapping tool. Snapping is available on elements,
on rulers or on the grid. You can customize snapping behaviors by clicking on the arrow next to the
"settings" button at the top right corner of the central window. Snapping on grid can be enabled or
disabled, but most importantly, grid size can be adjusted there.
</p>
<h3>Jaspersoft Studio peculiarity</h3>
<p>
Jaspersoft Studio, even if it's easily accessible and usable, suffers from many drawbacks. It's important to
know about drawbacks, so lots of trouble can be avoided:
<i> know your enemies and know yourself, you will not be imperiled in a hundred battles. Sun Tzu </i> <br />
I will illustrate this affirmation with some examples. The main purpose is recognition of such mechanisms
when encountered. One already known example is the font with PDF documents (see previous chapter).
</p>
<h4>Example 1: background color and transparency</h4>
<p>
In a usual software, some settings are disabled when it's senseless to give a settings. This logic does not
apply to Jaspersoft Studio. For example, you can set the color of a text field background in window property
-> appearance -> color. Just below, there is a transparent check box, which makes the background fully
transparent. If you check the box, you can still set any color but this will have no effect.
<br /><br />
Such behavior can be observed for different tools in Jaspersoft Studio.
</p>
<h4>Example 2: page numbering</h4>
<p>
Page number can be accessed through the variable $V{PAGE_NUMBER}. In the palette window, you can observe the
Page X of Y tools. The same variable (page number) is used two times, but has different values. The
difference comes from the evaluation time property (property window -> text field -> evaluation time), which
leads to different values of the variable. It's not a problem of the software, just a very confusing
implementation of a simple page counter.
</p>
<h2>General workflow for adapting existing templates</h2>
<p>
Here is a short description of steps required for being able to create a new template from another already
existing. This is particularly useful for Mapfish Print users having the willingness of customizing their
template without the need of calling an IT expert.
</p>
<ol>
<li>Install Jaspersoft Studio</li>
<li>Copy the template to your local machine</li>
<li>
Open the template in Jaspersoft Studio; following editions are easily done:
<ul>
<li>Change size of report elements</li>
<li>Change color, size and font of text</li>
<li>Change, add or remove static texts</li>
</ul>
</li>
<li>Save your changes, copy the file to the server</li>
<li>Update the print setup</li>
</ol>
What you see in Jaspersoft Studio is not exactly how printed reports will look like. Therefore, a "preview"
tool is available. However, Mapfish Print adds special elements that are not recognized by Jaspersoft Studio.
This leads to generation of errors at the preview opening. For being able to use the preview in Jaspersoft
studio, you will need to adapt slightly the template. The principle is to keep safe notes of your original
state, then apply adaptation for removing Mapfish Print dependencies, and eventually to reset the original
state after the edition of your template. In the following chapter are listed adaptation require in Jaspersoft
Studio for preview usage.
<p></p>
<h3>Removing Mapfish Print dependencies</h3>
<p>
An example will be treated for illustration of almost an exhaustive dependencies list. We can see below, on
the left, a print example and the print template opened in Jaspersoft Studio. Below on the right, we can see
the preview result once all checks and adaptations have been applied to the template:
</p>
<table>
<tr>
<td>
<img src="images/adapt1.png" alt="Comparison pdf-gui edition" style="max-width: 500px" />
</td>
<td>
<img src="images/preview.png" alt="Comparison pdf-preview" style="max-width: 500px" />
</td>
</tr>
</table>
<h4>1: static text</h4>
<p>
With static text, it compiles easily and will often be printed as it looks like. Font difference can be
observed. Information about pdf fonts can be found near the end of this documentation.
</p>
<p></p>
<h4>2 and 3: text field</h4>
<p>
Text fields are report elements with text that are not static. Parts of the text field element is
calculating at the generation time of the printed report. Calculation of the fields is either with some
functions depending on the environment (date, language, etc.) or depending on parameters passed to the print
template (title, map, etc. ). When a preview is created on Jaspersoft Studio, parameters need to be set,
because text fields are calculated. Parameters will be asked in Jaspersoft Studio as on the next image for
generating reports.
</p>
<img src="images/prompt.png" alt="Jaspersoft Studio, overview" style="max-height: 200px" />
<p>
There is a parameter option which has to be true (or checked) for allowing the prompt to be used. This
option will be critical for map elements. Parameters for map elements need to be ignored, so NOT asked. If
parameters are asked in the prompt window, check the state under:
<br /><br />
Outline window -> right-click on the parameters -> open property window -> isForPrompt -> set
Checked/Unchecked
<br /><br />
The difference between arrow 2 and 3 is the presence of parameters in the text field. In case of arrow N°3,
no parameters will be asked and it must compiled without error without changes.
</p>
<h4>4: map</h4>
<p>
Maps are included in the report by the means of subreports. In standard jasper reports, subreports are as
named : reports inside report. With them, it's possible to access many data from different data source
inside the same report. It's also with subreport that multiple database entries will be repeated (<a
href="https://community.jaspersoft.com/wiki/subreports-jaspersoft-studio"
>example</a
>) <br /><br />
Mapfish Print uses subreport elements for including maps, but doesn't use "standard" subreport. A
requirement is therefore to disable the map subreports for being able to see the preview. In general, all
the parameters related to Mapfish Print must have false prompting behavior. You can check all the parameters
values, or directly open the source code. Near the top of the code, parameters must be declared as
<i>isForPrompting="false"</i>:
</p>
<div class="highlight">
<pre>
<parameter name="mapSubReport" class="java.lang.String" isForPrompting="false"/>
</pre
>
</div>
<p>
This option must be set for all parameters related to Mapfish Print (but must be set by default). Here is a
list of parameter which must have the setting <i>isForPrompting</i> as false:
</p>
<ul>
<li>mapContext</li>
<li>mapSubReport</li>
<li>numberOfTableRows</li>
<li>tableSubReport</li>
<li>tableDataSource</li>
<li>numberOfLegendRows</li>
<li>legend</li>
<li>scalebarSubReport</li>
<li>northArrowSubReport</li>
</ul>
<h4>5: logo</h4>
<p>
The logo is usually placed on the server in the same folder as the template. For seeing the logo (and fixing
the error related to it), it has to be copied from the server to the same folder as the local copy of the
template.
</p>
<h4>6: others</h4>
<p>In order to add a numeric scale you have to create a text field with the following expression:</p>
<div class="highlight">
<pre>
String.format("Massstab 1: %.0f", $P{mapContext}.getRoundedScaleDenominator())
</pre
>
</div>
<p>Finally add the missing mapContext parameter with the following properties:</p>
<ul>
<li>Name: mapContext</li>
<li>Class: org.mapfish.print.attribute.map.MapfishMapContext</li>
</ul>
<h4>Preview issues</h4>
<p>
Some problems arise making the preview unusable. In our example, a problem will appear due to a special
parameter related to Mapfish Print used in text field. In this case, you will have to change the text field
for removing the problematic element. This manipulation have to be undo just before releasing the new
template to the server. For such manipulation, open the source tab, copy the problematic part of code to a
text file, keep and safe it for resetting it later. Concretely, you will do such modification for fixing
this type of error:
</p>
<div class="highlight">
<pre>
<parameter name="mapSubReport" class="java.lang.String"
isForPrompting="false"/>
...
<textFieldExpression><![CDATA[String.format("Massstab 1: %.0f", $P{mapContext}.getRoundedScaleDenominator())]]></textFieldExpression>
...
==>
...
<textFieldExpression><![CDATA[String.format("Massstab 1: scale")]]></textFieldExpression>
...
</pre
>
</div>
<h3>Without Jaspersoft Studio</h3>
<p>
It is possible to change directly the source code on the server. It's useful for small modifications. It is
also a good way to work on visual details, since it can be quickly compiled to the finished printed report.
</p>
<h3>Configuration of Mapfish Print</h3>
<p>
Once the new template is created and updated on the server, Mapfish Print needs to be told that a new
template has been created and needs to know which parameters to give to it. Under the assumption that only
visual modifications have been done to the template, we can enumerate the modifications to do to the file
<i>config.yaml</i>, which is found in the same directory that the templates.
</p>
<div class="highlight">
<pre>
#===========================================================================
3 A3 portrait: !template
#===========================================================================
reportTemplate: Baselland_A3_Portrait.jrxml
attributes:
title: !string {}
comment: !string {}
map: !map
maxDpi: 400
width: 802
height: 1033
...
</pre
>
</div>
<h2>small FAQ</h2>
<h4>What is a subreport for?</h4>
<p>
Maps are included in the report through subreports. In standard jasper reports, subreports are as named :
reports inside report. With them, it's possible to access many data different data source inside the same
report. Also, with subreports, multiple database entries will be repeated (<a
href="https://community.jaspersoft.com/wiki/subreports-jaspersoft-studio"
>example</a
>) <br /><br />
Mapfish Print uses subreport element for including maps, but doesn't use "standard" subreport.
</p>
<h4>How do I add/remove a Subreport?</h4>
<p>
You're not supposed to add a subreport in a template. You can delete subreports if, for example, you want to
remove the north arrow, scale bar, etc. You will have to do different manipulations:
<br />
</p>
<ul>
<li>remove the subreports element in Jaspersoft Studio</li>
<li>remove the linked parameter</li>
<li>
remove the element in the file config.yaml for example remove the two lines :
<div class="highlight">
<pre>
northArrow: !northArrow,
size: 51
</pre
>
</div>
</li>
</ul>
<h4>What is a variable ?</h4>
<p>
Variables are calculated at compiling using an expression each. There are not given by an external source of
the report, as parameters. Variables are typically page numbers or current date. They can also represent a
value calculated based on parameters.
</p>
<h4>What is a parameter ?</h4>
<p>
Parameter are objects set at the compiling. They can be string, integer, subreport etc. there are one the of
of keys of Mapfish Print. The map elements are passed by parameters, as well as scale bar, north arrow, etc.
More standard parameters can also be used with Mapfish Print, as title or comments for example.
</p>
<h4>How do I add/remove a Variable/Parameters?</h4>
<p>In the Outline window, right-click on variables or parameters.</p>
<h4>What variables are available ?</h4>
<p>
A small list of built-in variables is available in the Palette window, under tools. You can create as many
variables as you wish.
</p>
</div>
</div>
</div>
<footer>
<hr />
<div role="contentinfo">
<p>
<a href="https://www.camptocamp.com/geospatial_solutions" target="_blank" rel="noopener"
>Camptocamp</a
>
<br />
<span class="commit">
Revision
<code
><a
href="https://github.com/mapfish/mapfish-print/commit/d6145343031f75e02a79141e1b4bfe152161b262"
target="_blank"
>d6145343</a
></code
>.
</span>
</p>
</div>
Theme based on a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">template</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script
type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"
integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<script
type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/jquery-migrate/3.4.1/jquery-migrate.min.js"
integrity="sha512-KgffulL3mxrOsDicgQWA11O6q6oKeWcV00VxgfJw4TcM8XRQT8Df9EsrYxDf7tpVpfl3qcYD96BpyPvA4d1FDQ=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<script
type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.6/underscore-min.js"
integrity="sha512-2V49R8ndaagCOnwmj8QnbT1Gz/rie17UouD9Re5WxbzRVUGoftCu5IuqqtAM9+UC3fwfHCSJR1hkzNQh/2wdtg=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<script
type="text/javascript"
src="js/theme.js"
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>