Source for PDF-export

Do you know of a line of code that will include the URL of the exported page in the PDF? I’d like to include the source of the PDF file on the cover page.

Thanks.

Hi,

You can create a custom PDF template for this. See https://extensions.xwiki.org/xwiki/bin/view/Extension/PDF%20Export%20Application/#HCustomPDFTemplates . But note that a PDF export can include multiple wiki pages. On the cover section of the PDF template you can use $tdoc to access the “main” page that is exported (i.e. the page from where you trigger the PDF export).

URL: $tdoc.getURL() / $tdoc.getExternalURL()

Alternatively, you can use:

#set ($pdfExportJobId = $request.jobId.split('/'))
#set ($pdfExportJobStatus = $services.job.getJobStatus($pdfExportJobId))
#set ($pdfExportJobRequest = $pdfExportJobStatus.request)
#foreach ($exportedDocument in $pdfExportJobRequest.documents)
  URL: $xwiki.getURL($exportedDocument)
#end

Hope this helps,
Marius

1 Like

Thanks Marius.

URL: $tdoc.getURL() / $tdoc.getExternalURL() did the trick!

Long URLs need a linebreak, so this is my solution:

<p>
This document can be found at the following URL:
<span style="word-break: break-all; overflow-wrap: break-word;">
$tdoc.getExternalURL()
</span>
</p>
1 Like