Print Templates: Going Beyond Layout

advertisement
Print Templates
Going Beyond Layout
Richard V. Jackson
Huntington Library, Art Collections, and Botanical Gardens
San Marino, California
Print templates can be a real pain …
 Steep learning curve
 iReport can be difficult
 Many ways things can go
wrong — can be hard to
troubleshoot problems
 Information is scattered among several sources
(Sierra documentation, CSDirect wiki, IUG List, etc.)
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
2
… but there are advantages
 More control (page size, font, color, layout)
 More fields available
 Images and graphical elements
 Scannable barcodes
 Hyperlinks (in email notices)
 Save output to a PDF file
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
3
Yet another advantage
 Data manipulation and conditional printing
Using Java string methods, you can:
– Print “Call of the wild” as “CALL OF THE WILD”
– Print the last 4 digits of a barcode
– Automate call number pre-stamps
– Print “Jackson, Richard” as “Richard Jackson”
– Print “Jackson, Richard” as “JACK/R”
– Convert fixed-length codes to corresponding text
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
4
Purpose of this presentation
 Detailed explanation of the use of Java string
methods in Text Fields, including:
– Conditional printing
– Data manipulation
– Many practical examples
 A method for reformatting Due Dates in notices
 Changing text formatting
Everything applies to both Millennium and Sierra
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
5
Handout
 Supplementary handout on
Java string methods
available
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
6
Print templates overview
For help getting started:
 “Print Templates 101 & 102,” a LibGuide
created by Shad Harder and Carla Myers
http://libguides.uccs.edu/PrintTemplates101
http://libguides.uccs.edu/PrintTemplates102
 Print templates on CSDirect (login required)
http://csdirect.iii.com/documentation/
print_templates.php
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
7
Print templates overview
 iReport 4.0.2 used to create/edit templates
 Download from CSDirect:
http://csdirect.iii.com/downloads/ireport.shtml
iReport requires a Java Runtime Environment.
Unfortunately, the current version of Java for Windows
(version 8) is incompatible with iReport 4.0.2. Detailed
instructions for downloading and installing version 7 are
in the “Print Templates 101” LibGuide at:
http://libguides.uccs.edu/ld.php?content_id=9608837
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
8
Print templates overview
 Print template = a .jrxml file
– Edit using iReport
– Start with default
template
 Define page and
margins
 Define bands
 Add report elements
– Static text
– Text fields
– Images
– Lines, boxes, etc.
Page Header
Title
Detail
Title:
$F{Item_Title}
Page Footer
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
9
The palette in iReport
 Click and drag report elements from the palette
to the document
 If the palette isn’t visible, click Window > Palette
(or type Ctrl+Shift+8)
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
10
Static Text vs. Text Fields
 Static Text (or label)
– Text doesn’t change
– No double-quotes needed
 Text Field
Title:
$F{Item_Title}
– Is dynamic
– Contains a single Java expression that results in
a string value
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
11
Editing the Text Field expression
Expression editor window
Available fields
String methods
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
12
Terminology clarification: “Fields”
 “Fields” in Millennium/Sierra
– Fixed-length fields
– Variable-length fields
e.g.: COPY#, LOCATION
e.g.: CALL NO.
 Print template “fields” (“data elements”)
$F{itemFix58}
$F{itemFix58c}
$F{itemFix79}
$F{Item_Location}
$F{callAlphaStart}
$F{callNumericStart}
$F{callNumericAfterDec}
[etc.]
 “Text field”
– Report element occupying space on the layout
and containing a Java expression
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
13
Text Fields
 Simple text
field
 Concatenation
of multiple
text elements
$F{callEntire}
$F{callEntire} + " " +
$F{itemv}
- OR -
$F{callEntire} + "\n" +
– Use “+” to
join elements $F{itemv}
– Literal text in quotes
– "\n" means carriage return
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
14
A complex text field expression
($F{itemFix79}.equals("gcrf ")?"REF"+"\n":
$F{itemFix79}.equals("gcrff")?"REF"+"\n"+"folio"+"\n":
$F{itemFix79}.equals("bot ")?"BOT"+"\n"+"LIBRARY"+"\n":
$F{itemFix79}.substring(4).equals("f")?"folio"+"\n":"")
+$F{callAlphaStart}+($F{callAlphaStart}.equals("")?"":"\n")
+$F{callNumericStart}+$F{callNumericAfterDec}+"\n"
+$F{callEndCR}+($F{callEndCR}.equals("")?"":"\n")
+$F{callSubbCR}+($F{itemv}.trim().isEmpty()?"":"\n"
+$F{itemv}.trim().replace(" ","\n"))
+($F{itemFix58c}.equals("c.1")?"" : "\n"+$F{itemFix58c})
 Don’t do this — it works, but is difficult to
decipher and maintain
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
15
A more readable complex expression
// Print pre-stamps for select locations:
(
$F{itemFix79}.equals( "gcrf " )
? "REF" + "\n"
:
$F{itemFix79}.equals( "gcrff" )
? "REF" + "\n" + "folio" + "\n"
:
$F{itemFix79}.equals( "bot " )
? "BOT" + "\n" + "LIBRARY" + "\n"
:
$F{itemFix79}.substring(4).equals( "f" )
? "folio" + "\n"
// Print ‘folio’ if Loc ends in 'f'
: ""
)
// Print LC call number:
+ $F{callAlphaStart}
+ ($F{callAlphaStart}.equals( "" ) ? "" : "\n")
+ $F{callNumericStart} + $F{callNumericAfterDec} + "\n"
+ $F{callEndCR}
+ ($F{callEndCR}.equals( "" ) ? "" : "\n")
+ $F{callSubbCR}
// Print Volume if present. Convert 2 spaces to Carriage Return:
+ ( $F{itemv}.trim( ).isEmpty( )
? ""
: "\n" + $F{itemv}.trim( ).replace( " " , "\n" ) )
// Print copy number except for "c.1":
+ ( $F{itemFix58c}.equals( "c.1" ) ? "" : "\n" + $F{itemFix58c} )
 Use spaces and line
breaks to make the
expression more
readable
 Comments can also
be added
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
16
Comments in text field expressions
/*
Comment
block
*/
Use “// …”
or “/* … */”
to enter comments
Expression
anywhere in the
text field expression // Comment
Expression
Expression
Expression
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
// Comment
17
Conditional printing
 Conditional statements use a trinary operator:
(
(
[If]
Boolean
expression
?
[Then]
?
Expression
to execute
if true
:
[Else]
)
:
Expression
to execute
if false
)
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
18
Conditional printing
$F{itemv}.equals("") ? "" : "\n" + $F{itemv}
Boolean
expression
Expression
to execute
if true
Expression
to execute
if false
If the Item Volume field is empty, print nothing,
otherwise, print the Item Volume + <CR>
This avoids a blank line when there is no Volume.
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
19
Conditional printing: another example
Print the copy number (on a spine label) unless
the copy number is “1”
If
Then
(
$F{itemFix58}.equals("1")
? ""
: "copy " + $F{itemFix58}
Else
)
Alternatively, you can use the field “$F{itemFix58c}”,
which automatically puts “c.” in front of the copy no.
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
20
Automating call number pre-stamps
 Certain special locations
require a location “stamp”
above the call number
MSS REF
CD
1879.5
C64
G37
folio
TR
647
W395
2010
c.2
 These had been generated using a locallydefined “LABEL LOC” field in the Item record
 Problem: The location code and LABEL LOC are
logically dependent but functionally
independent — errors and inconsistencies can
easily occur
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
21
Automating call number pre-stamps
Mismatch: Is the book in the
Gen. Coll. East Basement or
the Manuscript Reference
Reading Room?
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
22
Automating call number pre-stamps
 Checking for a single case:
( $F{itemFix79}.equals("hmrf ")
? "MSS REF" + "\n"
: "" )
+ [rest of the call number]
 Parentheses around the conditional expression
are crucial. Otherwise, the call number itself
would only print under the “else” condition
 Note that the location code is padded out to 5
characters with trailing spaces ("hmrf ")
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
23
Automating call number pre-stamps
 To cover multiple pre-stamps, use nested
conditional statements:
(
Else
Else
Else
Else
Else
)
+
If Location="gcrf ",
if Location="hmrf ",
if Location="hcons",
if Location="botr ",
if Location="href ",
print ""
print
print
print
print
print
"REF"
"MSS REF"
"CONSERV."
"BOT RARE"
"INVALID!“
[rest of the call number]
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
24
Nested conditional statements
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
25
A closer look at Java string methods
$F{itemFix79}.equals("hmrf ")
Field name (or
other string expression)
Method name
Argument(s)
 This string method returns a Boolean value
(true or false)
 Used in the first part of conditional statements
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
26
Examples of Java string methods
 These string methods return Boolean values:
$F{Item_Barcode}.startsWith("2123")
Returns true if Item barcode starts with “2123”
$F{itemFix79}.endsWith("f")
Returns true for locations “gccbf”, “gcn3f”, “hconf”,
etc. (but false for “hmrf ”)
$F{Patron_Name}.contains(", ")
Returns true if the Patron name contains “, ”
(comma followed by space)
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
27
Examples of Java string methods
 These string methods return Boolean values:
$F{callAlphaStart}.matches("^[HJK]")
Returns true if the call number starts with H, J, or K
(The argument is a regular expression)
$F{biba}.isEmpty( )
Returns true if there is no a-tagged field (author) in
the bib record. Same as .equals("").
Avoid using the .isEmpty method with fields that
draw data from the fixed-length fields
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
28
Examples of Java string methods
 These string methods return string values:
$F{bib245}.toUpperCase( )
Converts lower case letters to upper case
(“Call of the wild” would become “CALL OF THE WILD”)
$F{Patron_Name}.trim( )
Removes leading and trailing spaces
(“ Jackson, R. V. ” would become “Jackson, R. V.”)
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
29
Examples of Java string methods
 These string methods return string values:
$F{callEntire}.replace( " " , "\n" )
Replaces all occurrences of the space character
with carriage returns
$F{itemFix58}.replaceAll( "^0*" , "" )
The .replaceAll method allows you to use a regular
expression in the first argument
In this example, leading zeroes are removed
(“002” would become “2”; “010” would become “10”)
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
30
Examples of Java string methods
 These string methods return string values:
$F{Patron_Barcode}.substring( 10 )
Returns a substring of the patron’s barcode, from
character position 10 to the end (e.g., last 4 digits
of a 14-digit barcode)
$F{Patron_Name_C}.substring( 0 , 4 )
Returns the first 4 characters of the patron’s name
More details given in the examples to come
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
31
Examples of Java string methods
 These string methods return integer values:
$F{Item_Barcode}.length( )
Returns the length of the string
$F{Patron_Name}.indexOf(",")
Returns the character position of the first
occurrence of the specified character or string
(counting starts at 0)
Smith, J.
0 1 2 3 4 5 6 7 8
In this example, the method
would return 5
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
32
Examples of Java string methods
 Arithmetic and comparison operations can be
done on integer string methods:
$F{Patron_Name}.indexOf(",") + 2
Smith, J.
0 1 2 3 4 5 6 7 8
Returns the character position
2 characters after the first
comma (7 in this example)
$F{Item_Barcode}.trim( ).length( ) < 14
Returns a Boolean true if the barcode is shorter
than 14 characters
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
33
Examples of Java string methods
 Boolean expressions can be joined with
Boolean operators:
&& (and)
|| (or)
! (not)
$F{itemFix79}.equals("main ")
&& $F{callSubf}.equals("Large print") ? … : …
Returns true if both the Item Location = “main”
AND the call number subfield f = “Large print”
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
34
Examples of Java string methods
$F{Patron_Type}.equals("Staff")
|| $F{Patron_Type}.equals("Intern") ? … : …
Returns true if either the Patron Type = “Staff”
OR the Patron Type = “Intern”
!($F{Patron_Address_Line3}.contains("91108") )
Returns true if patron address line 3 does NOT
contain “91108”. You can also do this:
!( ($F{Patron_Address_Line2} + " " +
$F{Patron_Address_Line3}).contains("91108") )
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
35
Example: Using the .replace method
 Problem: The print template wraps a long field
as far to the right as possible
 Solution: Make it possible to manually set line
breaks in a long Volume field
Volume:
n.s. v.11-12
VM
1
S32
n.s. v.1112
Volume:
ser.3 v.29-30
VM
1
S32
ser.3 v.
29-30
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
36
Example: Using the .replace method
 Solution: Add a string method that convert 2
spaces in a Volume field to a carriage return
$F{itemv}.replace( "
Volume:
n.s.
" , "\n" )
Volume:
^^
v.11-12
VM
1
S32
n.s.
v.11-12
ser.3 v.29-30
^^
VM
1
S32
ser.3
v.29-30
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
37
Example: Using the .substring method
 Print only the last 6 digits of a 14-digit barcode
3 0 0 0 6 2 0 0 5 0 1 6 3 4
0
1
2
3
4
5
6
7
8
9
10
11
12
13
$F{Item_Barcode}.substring( 8 )
.substring method
A single argument specifies the
starting character position,
returning a substring from that
character to the end of the field
“501634”
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
38
Example: Using the .substring method
 Print the last 4 digits of variable-length barcodes
3 1 2 3 4 5 6 7 8 9
0
1
2
3
4
5
6
7
8
9
$F{Item_Barcode}.substring(
$F{Item_Barcode}.length( ) - 4
Subtracting 4 from the length of
the field gives the correct
starting character position
In this example: 10 – 4 = 6
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
)
“6789”
39
A more complex example
 Create an abbreviation form of the patron
name for printing on Hold Slips
Jackson, Richard V.
JAC/R
( $F{v_p_name}.substring(0,3)
+ "/"
+ $F{v_p_name}.substring(
$F{v_p_name}.indexOf(",") + 2,
$F{v_p_name}.indexOf(",") + 3 )
).toUpperCase( )
Result:
Jackson,
JAC/R
Richard V.
Jac/R
Jac/
Jac
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
40
A more complex example
 This does not account for last names shorter than
3 characters, or names that lack a comma or vary
in the number of spaces following the comma
( $F{v_p_name}.substring(0,3)
+ "/"
+ $F{v_p_name}.substring(
$F{v_p_name}.indexOf(",") + 2,
$F{v_p_name}.indexOf(",") + 3 )
).toUpperCase( )
 See the handout (p. 2) for a more complex
expression that deals with all these situations
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
41
Formatting dates
 To add today’s date to a notice:
new java.util.Date( )
 04/30/2014
 To format the date:
– Right-click the field
– Select “Field pattern”
– Select a format
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
42
Formatting dates
 Dates from records such as Item Due Date are
string fields and cannot be formatted this way
$F{Item_Due_Date}
 07–09–14
 A more complex expression is needed to
format such dates
new SimpleDateFormat("MMMM d, yyyy")
.format(new SimpleDateFormat("MM-dd-yy")
.parse($F{Item_Due_Date}))
See the Handout p. 6
for more information

Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
July 9, 2014
43
Changing text styles within a report element
 Text properties (font
name, size, bold, italic,
etc.) normally apply to
the entire Report
element
 With the Markup
property, markup tags
can be added to change
text styles for a portion
of the text
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
44
Changing text styles within a report element
 For simple changes (e.g., boldfacing some
text), using html tags
– Set the Markup property to “html”
– Tags are still text and must be in quotes
"You currently have "
+ "<b>" + $F{Patron_Checked_Out_Number} + "</b>"
+ " items checked out."
Note: With HTML markup, "\n" doesn’t work; use "<p>" instead
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
45
Changing text styles within a report element
 You can also set Markup to “styled” and use
the <style> tag with various attributes
 Problem: The
pre-stamp
AHMANSON
READING RM.
wouldn’t fit on
the spine label
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
46
Changing text styles within a report element
"<style fontName='Arial Narrow' size='10'>"
+ "AHMANSON" + "\n" + "Reading Rm."
+ "</style>" + "\n"
Double quotes
around the
<style> tag
Single quotes
around attribute values
– Since the <style> tag must
be in double quotes, use
single quotes around
attribute values
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
47
Changing text styles within a report element
 Some attributes used with the <style> tag
– fontName
– size
– isBold
– isItalic
– isUnderline
– forecolor
– backcolor
(examples)
fontName='Verdana'
size='10.5'
isBold='true'
isItalic='false'
isUnderline='true'
forecolor='#DDDDDD'
backcolor='#3E75AD'
 For more information, see The JasperReports Ultimate
Guide, 3rd ed. (p. 122+, especially p. 134-35)
(http://jasperreports.sourceforge.net/JasperReports-Ultimate-Guide-3.pdf)
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
48
More information
 Reference page on Java string methods
(http://docs.oracle.com/javase/6/docs/api/java/lang/String.html)
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
49
More information
 Jasper Reports Ultimate Guide (PDF, 333 p.)
(http://jasperreports.sourceforge.net/JasperReportsUltimate-Guide-3.pdf)
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
50
Questions?
Thank
you!
Richard V. Jackson
Supervising Librarian / System Coordinator
Huntington Library, Art Collections, and Botanical Gardens
San Marino, California
rjackson@huntington.org
http://www.huntington.org/
Print Templates: Going Beyond Layout / WILIUG 2015 / Milwaukee
51
Download