Main Content

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.

  1. Unzip the template package containing the part template library file.

  2. Open the document part templates file, named docpart_templates.html by default, in an HTML or text editor.

  3. Edit the file as needed using the elements described in PDF Document Part Template Library Structure.

  4. Add any styles that support the document part templates in a .css file in the template package. See Modify Styles in PDF Templates.

  5. Save the library files you edited.

  6. 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.

PurposeElementAttributesValues
Page layoutlayoutstyle

page-margin: top left bottom right header footer gutter; page-size: height width orientation; page-border: width style color margin surround-header surround-footer

first-page-numberNumber of first page in the layout
page-number-format n or N for numeric, a, A, i, I
section-breakWhere to start section for this layout: Odd Page, Even Page, or Next Page
Page headerpheadertypedefault, first, even
template-nameDocument part template that defines the header
Page footerpfootertypedefault, first, even
template-nameDocument part template that defines the footer
Page number format (same as first-page-number and page-number-format on layout)pnumberformatn or N for numeric, a, A, i, I
initial-valueThe number for the first page in the layout that uses this element
HoleholeidID that identifies hole by name
default-style-nameStyle sheet style to use when style is not set programmatically
Table of contentstocnumber-of-levelsNumber of heading levels to include in TOC
leader-patternLeader pattern to use: dots, space, period, or space
Automatic numberingautonumberstream-nameName of the stream specified by a counter-increment style
Current page number pageNo attributes 
Total number of pages in documentnumpagesNo attributes 
Page breakpagebreakNo attributes 
Numeric reference to page where target is located pagereftargetID 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)stylerefNo attributesInserts content of nearest h1 element
style-nameName of the style with content to insert in the header or footer
outline-levelOutline level of style with content to insert in the header or footer
Insert a watermark image in a page layoutwatermarksrcPath 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 valueUnits. Possible values for units are px, in, cm, mm, pc, and pt.

heightHeight 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 ElementAttributes
aclass, style, href, name
addressclass, style
bclass, style
bigclass, style
blockquoteclass, style
bodyclass, style
brn/a
centerclass, style
citeclass, style
codeclass, style
ddclass, style
delclass, style
dfnclass, style
divclass, style
dlclass, style
dtclass, style
emclass, style
fontclass, style, color, face, size
h1, h2, h3, h4, h5, h6class, style, align
hrclass, style, align
iclass, style
insclass, style
imgclass, style, src, height, width
kbdclass, style
liclass, style
markclass, style
nobrclass, style
olclass, style
pclass, style, align
preclass, style
sclass, style
sampclass, style
smallclass, style
spanclass, style
strikeclass, style
strongclass, style
subclass, style
supclass, style
tableclass, style, align, bgcolor, border, cellspacing, cellpadding, frame, rules, width
tbodyclass, style, align, valign
tfootclass, style, align, valign
theadclass, style, align, valign
tdclass, style, bgcolor, height, width, colspan, rowspan,align, valign, nowrap
thclass, style, bgcolor, height, width, colspan, rowspan,align, valign, nowrap
trclass, style, align,bgcolor, valign
ttclass, style
uclass, style
ulclass, style
varclass, style

For information about these elements, see https://developer.mozilla.org/en-US/docs/Web/HTML/Element.

See Also

|

Related Topics