PDF Export Template Creation: date of printing and other stuff

Hi everyone. So I was not understanding how to create my own PDF Templates, but I installed an extension called PDF Template Customization. Now, I am not sure this extension did something or not, but I noticed that when creating a new page, I can select PDF Template.

Then I get fields to fill
COVER
The information displayed on the first page. E.g. the title and the author

TABLE OF CONTENTS
Usually lists the content headings along with their page numbers.

HEADER
The information displayed at the top of each page, except for the cover page. E.g. the title

FOOTER
The information displayed at the bottom of each page, except for the cover page. E.g. the number of the page

image

The code I used however is not working

the footer is too distant from the bottom of the page
image

and the header is completely wrong. And part of it is cutting too.
image

How would I proceed to include the company logo, document name and code (my procedures have a code field)?

And keep a margin above the header?

The ā€œPDF Templateā€ from the Create Page dialog has nothing to do with the ā€œPDF Template Customizationā€ extension which doesnā€™t even work with the new PDF export available since XWiki 14.10+. The documentation for the new PDF export, including how to create a custom template is here https://extensions.xwiki.org/xwiki/bin/view/Extension/PDF%20Export%20Application/ .

Well, you need to play with CSS. Thereā€™s an information box at the top of the page that tells you about this. Just edit the page in object mode.

It looks to me that the Velocity code you put in the header is not evaluated. Itā€™s hard to know why without seeing the actual code. It could be because you donā€™t have script right, or because you have some mistake / typo in your wiki syntax. In any case, you should start from simple to complex. Iā€™d first put some static text in the header to see if it gets displayed. Iā€™m pretty sure itā€™s the case (since we have automated tests for this). Then move to scripting.

Hope this helps,
Marius

I am trying to do a few different things. And failing at all of them lol

1 - add the company logo to the export
2 - add the date of export.
3 - adjust the location of the header and foot (header cuts outside the page as itā€™s too close the margin, footer is too far from the bottom margin)

For date of export, I am trying to use this

Getting error messages when inserting the code below at the Object Edition of the PDF Template
{{velocity}}
#set ($authorName = ā€œ#displayUser($tdoc.authorReference {ā€˜useInlineHTMLā€™: true})ā€)
#set ($dateTool = $xwiki.context.getWiki().getComponentManager().getInstance(org.xwiki.platform.date.script.DateScriptService))
#set ($currentDate = $dateTool.displayTimeAgo(new Date()))

{{html clean=ā€œfalseā€}}

$escapetool.xml($tdoc.plainTitle) - Ver.: $tdoc.version | Autor: $authorName | Data de ExportaĆ§Ć£o: $currentDate
PAVICON | PĆ”g. de | VĆ”lido 7d a partir da data de impressĆ£o na capa
{{/html}} {{/velocity}}

at the CSS part, I added this line at the header part to try to increase distance to the top margin, but it didnĀ“t work eitherā€¦

  /**
   * Header
   */
  .pdf-chapter-name {
    margin-top: 2in; /* Add this line to increase the top margin of the header */
  }

@media print {
/**

  • Cover Page
    */
    .pdf-cover {
    border-top: 1px solid @nav-tabs-border-color;
    border-bottom: 1px solid @nav-tabs-border-color;
    margin-top: 3in;
    }
    .pdf-cover h1 {
    font-weight: bolder;
    }

/**

  • Table of Contents
    /
    /
    Distinguish the table of contents entries that correspond to document titles from those that correspond to headings
    found in the document content. */
    .pdf-toc > ul > li[data-xwiki-document-reference] {
    margin-top: 1em;
> span {
  font-weight: bolder;
}

}

/**

  • Header
    /
    .pdf-chapter-name {
    margin-top: 2in; /
    Add this line to increase the top margin of the header */
    }

.pdf-chapter-name:before {
content: string(chapter-name);
}

/**

  • Content
    /
    /
    Marks the beginning of a new XWiki document. /
    h1[data-xwiki-document-reference] {
    /
    Distinguish document titles from the rest of the level 1 headings that may appear in the document content. */
    font-weight: bolder;
    string-set: chapter-name content(text);
/* Start each XWiki document on a new print page. */
& ~ h1[data-xwiki-document-reference] {
  break-before: page;
}

}

// Make sure the content of the code macro is not cut when it exceeds the print page width by:
div.code {
// decreasing the font size when printing
font-size: 80%;
}
div.code, div.code * {
// and wrapping long lines, while still preserving the whitespace.
white-space: pre-wrap;
}
}

Thereā€™s an easy way to debug the page being exported, if you havenā€™t already seen it: https://extensions.xwiki.org/xwiki/bin/view/Extension/PDF%20Export%20Application/#HUnexpectedPDFOutput

I managed to add the logo to our exports, you may find some scripts here: Custom PDF template broken after upgrade to 14.10.18
Beware that:

  • when loading attachments from the template page, you need to specify the page full / absolute path
  • Iā€™m no expert at all on these things, hence youā€™re probably doing it better than me in editing the correct page CSS, instead of me adding styles inline with the HTML code, so take my examples with a pinch of salt
  • Iā€™m no expert at all on these things, hence youā€™re probably doing it better than me in editing the correct page CSS, instead of me adding styles inline with the HTML code, so take my examples with a pinch of salt

lol, itā€™s ChatGPT writing all that code. And failing. But still failing less than I would.

Script services are exposes as $services.* e.g. $services.date for the DateScriptService.

1 Like

It worked!

marked in yellow, date of printing.

however, the footer has an extra line that is being cut from the page. Alas, even a few pixels of that line are being cut

Well, you need to play with CSS. Thereā€™s an information box at the top of the page that tells you about this. Just edit the page in object mode.

I am already editing in Object mode. I suppose I should edit the StyleSheetExtension 0 object?