Create PDF Document Part Template Library
In the default template package, the file docpart_templates.html
defines the library and some default document part templates. In your document part
template library, create the document parts that you want to reuse throughout your
report. You can create a part template for any part of your document that you want to
repeat without redefining it programmatically.
A document part template typically consists of fixed content and holes. It can also include page layout elements that describe the page size, margins, and orientation as well as page headers and footers. You create PDF document part template libraries using DOM API HTML elements provided for this purpose and a subset of HTML elements.
Use this workflow to work on your document part template library.
Unzip the template package containing the part template library file.
Open the document part templates file, named
docpart_templates.html
by default, in an HTML or text editor.Edit the file as needed using the elements described in PDF Document Part Template Library Structure.
Add any styles that support the document part templates in a
.css
file in the template package. See Modify Styles in PDF Templates.Save the library files you edited.
Repackage the template using
ziptemplate
.
PDF Document Part Template Library Structure
You create your document part library using the
<dplibrary>
element. Add a
<dplibrary>
element inside a
<body>
element in your
docpart_template.html
file. Your template package can have
only one <dplibrary>
element.
Use <dptemplate>
elements inside a
<dplibrary>
element for each document part template
that you want to create. You can create as many document part templates as you need.
This code shows the basic structure of a document part library. The
<dptemplate>
element has the attribute
name
, which you set to the name that you use to call the
document part. The name is equivalent to the name of the part in the Quick Parts
Gallery in Word. If you are creating templates for multiple outputs, use the same
name in both places.
<body>
<dplibrary>
<dptemplate name="myFirstDocPartTemp">
[Document part template content here--
holes, fixed content, page layout information, and HTML]
</dptemplate>
</dplibrary>
</body>
Document Part Template Library Contents
You can use DOM API HTML elements and a subset of standard HTML elements to create PDF document part templates. For examples that show how to use the DOM API HTML elements, see:
DOM API HTML Elements
In addition to the <dplibrary>
and
<dptemplate>
elements that you use to define the
library and the document parts, you can use these DOM API HTML elements in your
PDF templates.
Purpose | Element | Attributes | Values |
---|---|---|---|
Page layout | layout | style
|
|
first-page-number | Number of first page in the layout | ||
page-number-format | n or N for numeric,
a , A ,
i , I
| ||
section-break | Where to start section for this layout: Odd
Page , Even Page , or
Next Page | ||
Page header | pheader | type | default , first ,
even |
template-name | Document part template that defines the header | ||
Page footer | pfooter | type | default , first ,
even |
template-name | Document part template that defines the footer | ||
Page number format (same as
first-page-number and
page-number-format on layout) | pnumber | format | n or N for numeric,
a , A ,
i , I
|
initial-value | The number for the first page in the layout that uses this element | ||
Hole | hole | id | ID that identifies hole by name |
default-style-name | Style sheet style to use when style is not set programmatically | ||
Table of contents | toc | number-of-levels | Number of heading levels to include in TOC |
leader-pattern | Leader pattern to use: dots ,
space , period, or space | ||
Automatic numbering | autonumber | stream-name | Name of the stream specified by a
counter-increment style |
Current page number | page | No attributes | |
Total number of pages in document | numpages | No attributes | |
Page break | pagebreak | No attributes | |
Numeric reference to page where target is located | pageref | target | ID of target; create target in your report using mlreportgen.dom.LinkTarget |
Insert content of a heading or other style into a page header or footer (for running headers and footers) | styleref | No attributes | Inserts content of nearest h1 element
|
style-name | Name of the style with content to insert in the header or footer | ||
outline-level | Outline level of style with content to insert in the header or footer | ||
Insert a watermark image in a page layout | watermark | src | Path of the source file to use as the watermark image. Store the watermark image in the template package. See Watermarks in PDF Page Layouts. |
width | Width to scale watermark image, in the form
| ||
height | Height to scale watermark image, in the form
valueUnits |
For detailed information on the attributes, see the properties for these corresponding DOM API classes.
Standard HTML Elements
You can use these standard HTML elements in PDF templates.
HTML Element | Attributes |
---|---|
a | class , style ,
href , name |
address | class , style |
b | class , style |
big | class , style |
blockquote | class , style |
body | class , style |
br | n/a |
center | class , style |
cite | class , style |
code | class , style |
dd | class , style |
del | class , style |
dfn | class , style |
div | class , style |
dl | class , style |
dt | class , style |
em | class , style |
font | class , style ,
color , face ,
size |
h1, h2, h3, h4, h5, h6 | class , style ,
align |
hr | class , style ,
align |
i | class , style |
ins | class , style |
img | class , style ,
src , height ,
width |
kbd | class , style |
li | class , style |
mark | class , style |
nobr | class , style |
ol | class , style |
p | class , style ,
align |
pre | class , style |
s | class , style |
samp | class , style |
small | class , style |
span | class , style |
strike | class , style |
strong | class , style |
sub | class , style |
sup | class , style |
table | class , style ,
align , bgcolor ,
border , cellspacing ,
cellpadding , frame ,
rules , width |
tbody | class , style ,
align , valign |
tfoot | class , style ,
align , valign |
thead | class , style ,
align , valign |
td | class , style ,
bgcolor , height ,
width , colspan ,
rowspan ,align ,
valign , nowrap |
th | class , style ,
bgcolor , height ,
width , colspan ,
rowspan ,align ,
valign , nowrap |
tr | class , style ,
align ,bgcolor ,
valign |
tt | class , style |
u | class , style |
ul | class , style |
var | class , style |
For information about these elements, see https://developer.mozilla.org/en-US/docs/Web/HTML/Element.