# Error #outputMetadata From Target Document() when trying to Export as PDF

**URL:** <https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460>\
**Category:** Help / Discuss\
**Created:** [September 3, 2024, 3:05pm UTC](https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460 "2024-09-03T15:05:57Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerpenna](https://forum.xwiki.org/user_avatar/forum.xwiki.org/rogerpenna/32/5264_2.png) [@rogerpenna](https://forum.xwiki.org/u/rogerpenna)\
**Post date:** [September 3, 2024, 3:05pm UTC](https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460/1 "2024-09-03T15:05:57Z")

</div>

#outputMetadataFromTargetDocument()

 ![image](https://forum.xwiki.org/uploads/default/original/2X/b/b0b445cf823c1e284272f7a2e61faf2aeeda38fa.png)

I sincerely don´t remember this error last time I exported pages.

Here is the PDF Template CSS

```auto
@media print {
  /* General page margins setup */
  @page {
    margin: 35mm 20mm 20mm; /* top, right/left, bottom margins for all pages */
  }

  /* Specific setup for the first page */
  @page :first {
    margin-top: 35mm 20mm 20mm; /* Larger top margin for the first page only */
  }

  /* Ensure the footer does not get cut off */
  body {
    font-family: Arial, sans-serif; /* Consistent font for readability */
    margin: 0; /* Reset body margin to work within page margins */
  }
  
  
    /* Adjust header padding */
  .pdf-header {
    padding-bottom: 0mm; /* Reduced padding below the header */
    /* Other styles... */
  }

  /* Paged.js Specific Styles */
  .pagedjs_pagebox {
    --pagedjs-pagebox-width: 210mm; /* Standard A4 page width */
    --pagedjs-pagebox-height: 297mm; /* Standard A4 page height */
    box-sizing: border-box; /* Include padding and borders within dimensions */
  }

  /* Content Styling */
  .main-content {
    background-color: transparent !important;
    padding-top: 10mm; /* Reduced top padding for main content */
    padding-bottom: 10mm; /* Consistent padding for the bottom */
    padding-left: 20mm; /* Consistent padding on the left */
    padding-right: 20mm; /* Consistent padding on the right */
    page-break-inside: avoid; /* Avoid breaking inside content */
  }

  /* Handling Images */
  img {
    max-width: 100%; /* Ensure images don't overflow pages */
    height: auto; /* Maintain aspect ratio */
  }
  
  /* Footer Styling */
  .pdf-footer {
    width: 100%;
    text-align: center;
    font-size: 10px;
    padding: 5mm; /* Adjust as needed */
  }

}

```

I could post the header but I don´t think it’s the header since it happens even if I don´t export it.

---

<div class="post-metadata">

**Author:** ![mflorea](https://forum.xwiki.org/user_avatar/forum.xwiki.org/mflorea/32/49_2.png) [@mflorea](https://forum.xwiki.org/u/mflorea)\
**Post date:** [September 4, 2024, 11:38am UTC](https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460/2 "2024-09-04T11:38:54Z")

</div>

The `outputMetadataFromTargetDocument` Velocity macro is defined and used only in [xwiki-platform/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Sheet.xml at master · xwiki/xwiki-platform · GitHub](https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Sheet.xml#L160) . The fact that the macro name is printed in the output suggests that the macro is missing, but I don’t see how it could be possible. Have you tried to modify the PDF export sheet? Are you calling the `outputMetadataFromTargetDocument` macro yourself somewhere? Do you see this behavior also when exporting multiple wiki pages at once (multi-page export)?

---

<div class="post-metadata">

**Author:** ![rogerpenna](https://forum.xwiki.org/user_avatar/forum.xwiki.org/rogerpenna/32/5264_2.png) [@rogerpenna](https://forum.xwiki.org/u/rogerpenna)\
**Post date:** [September 4, 2024, 12:14pm UTC](https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460/3 "2024-09-04T12:14:28Z")

</div>

> Have you tried to modify the PDF export sheet

What do you mean? Anyway, I recently created a new PDF export template and it’s also giving me the same error.

> Are you calling the `outputMetadataFromTargetDocument` macro yourself somewhere?

I have no clue. I suppose not. I don´t even know what that is.

> Do you see this behavior also when exporting multiple wiki pages at once (multi-page export)?

you mean, like this?  
 ![image](https://forum.xwiki.org/uploads/default/original/2X/2/2c7724cd9c1f779320068d585401d26cfae5ba99.png)

It’s not working. It stays over 2 minutes “exporting as pdf” until it time outs.

---

<div class="post-metadata">

**Author:** ![rogerpenna](https://forum.xwiki.org/user_avatar/forum.xwiki.org/rogerpenna/32/5264_2.png) [@rogerpenna](https://forum.xwiki.org/u/rogerpenna)\
**Post date:** [September 4, 2024, 12:35pm UTC](https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460/4 "2024-09-04T12:35:50Z")

</div>

While exporting those mains AWM pages selecting one or more documents isn´t working, I tried exporting a page (create with AWM) and it’s subpage.

 ![image](https://forum.xwiki.org/uploads/default/original/2X/1/1f6f8ba406ae2cec84f9a6e5cf50bb7c5375459e.png)

and INDEED, the error message did not appear

 ![image](https://forum.xwiki.org/uploads/default/original/2X/2/25582de17787dd6fabcf1ef032060388068ae759.png)

trying to export ONLY one document (the same one) results in the message again  
 ![image](https://forum.xwiki.org/uploads/default/original/2X/b/bb7e92c0f39e4576f67e001b9f502b2ce84cdb22.png)

---

<div class="post-metadata">

**Author:** ![rogerpenna](https://forum.xwiki.org/user_avatar/forum.xwiki.org/rogerpenna/32/5264_2.png) [@rogerpenna](https://forum.xwiki.org/u/rogerpenna)\
**Post date:** [September 4, 2024, 2:10pm UTC](https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460/5 "2024-09-04T14:10:17Z")

</div>

any suggestion on how to proceed?

---

<div class="post-metadata">

**Author:** ![mflorea](https://forum.xwiki.org/user_avatar/forum.xwiki.org/mflorea/32/49_2.png) [@mflorea](https://forum.xwiki.org/u/mflorea)\
**Post date:** [September 4, 2024, 2:44pm UTC](https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460/6 "2024-09-04T14:44:04Z")

</div>

What XWiki version are you using? I’d check if the code of the `XWiki.PDFExport.Sheet` page matches the code from the XWiki version you’re using ( e.g. [xwiki-platform/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Sheet.xml at xwiki-platform-15.10.12 · xwiki/xwiki-platform · GitHub](https://github.com/xwiki/xwiki-platform/blob/xwiki-platform-15.10.12/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Sheet.xml) ). You can do this by looking at the page history and comparing the current version with the version coming from the PDF Export Application extension.

---

<div class="post-metadata">

**Author:** ![rogerpenna](https://forum.xwiki.org/user_avatar/forum.xwiki.org/rogerpenna/32/5264_2.png) [@rogerpenna](https://forum.xwiki.org/u/rogerpenna)\
**Post date:** [September 4, 2024, 6:09pm UTC](https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460/8 "2024-09-04T18:09:51Z")

</div>

16.4 but I am just now upgrading to 16.7

ok, finished upgrading to 16.7. The problem persists.

 ![image](https://forum.xwiki.org/uploads/default/original/2X/5/507b56cd92b91b8751b6c0135c59fe6639051ba8.png)

---

<div class="post-metadata">

**Author:** ![mflorea](https://forum.xwiki.org/user_avatar/forum.xwiki.org/mflorea/32/49_2.png) [@mflorea](https://forum.xwiki.org/u/mflorea)\
**Post date:** [September 5, 2024, 7:04am UTC](https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460/9 "2024-09-05T07:04:08Z")

</div>

I just checked with a clean 16.7.0, and I can’t reproduce your problem. Can you try to edit the `XWiki.PDFExport.Sheet` with the Wiki editor (you need to enable advanced user in your profile) and rename the `outputMetadataFromTargetDocument` Velocity macro. There should be two occurrences: one where the macro is called and another one where the macro is defined. Add some suffix to the macro name in both places. You can also write some text before and after the macro call, to see if it appears in the PDF export. Does it change anything?

---

<div class="post-metadata">

**Author:** ![rogerpenna](https://forum.xwiki.org/user_avatar/forum.xwiki.org/rogerpenna/32/5264_2.png) [@rogerpenna](https://forum.xwiki.org/u/rogerpenna)\
**Post date:** [September 5, 2024, 11:29am UTC](https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460/10 "2024-09-05T11:29:43Z")

</div>

> [@mflorea](#):
>
> outputMetadataFromTargetDocument

 ![image](https://forum.xwiki.org/uploads/default/original/2X/2/2698a3be59beff0f805721b3fb8629ef43315519.png)

Only a SINGLE ocurrence appears to me… weird…

```auto
{{velocity output="false"}}
#set ($sheetReference = 'XWiki.PDFExport.Sheet')
#set ($pdfElements = ['cover', 'toc', 'header', 'footer'])
#set ($pdfExportJobId = $request.jobId.split('/'))
#if ($pdfExportJobId)
  #set ($pdfExportJobStatus = $services.job.getJobStatus($pdfExportJobId))
  #set ($pdfExportJobRequest = $pdfExportJobStatus.request)
#else
  #set ($pdfExportJobStatus = $NULL)
  #set ($pdfExportJobRequest = $NULL)
#end

#macro (getPDFExportConfigFromRequest $pdfExportConfig)
  #if ($pdfExportJobRequest)
    #set ($discard = $pdfExportConfig.putAll({
      'template': $pdfExportJobRequest.template,
      'cover': $pdfExportJobRequest.isWithCover(),
      'toc': $pdfExportJobRequest.isWithToc(),
      'header': $pdfExportJobRequest.isWithHeader(),
      'footer': $pdfExportJobRequest.isWithFooter()
    }))
  #end
#end

#macro (renderPDFSheet $pdfExportConfig)
  #set ($discard = $response.setContentType('text/html'))
  #set ($discard = $xwiki.ssx.use($sheetReference))
  ## Temporarily disable the JavaScript minification until we find a way to fix the following Closure Compiler error:
  ## [JSC_DYNAMIC_IMPORT_USAGE] Dynamic import expressions cannot be transpiled.
  ## See https://github.com/google/closure-compiler/wiki/JS-Modules#dynamic-import-expressions
  ## See also https://github.com/google/closure-compiler/issues/2770 ([FEATURE] Support dynamic import)
  ## This error is unexpected considering that we disable the transpiling here
  ## https://github.com/xwiki/xwiki-platform/blob/xwiki-platform-15.7/xwiki-platform-core/xwiki-platform-skin/xwiki-platform-skin-skinx/src/main/java/com/xpn/xwiki/web/sx/JsExtension.java#L91-L97
  ## We're using STABLE as input ECMAScript version, see https://github.com/xwiki/xwiki-commons/blob/xwiki-commons-15.7/pom.xml#L2585
  ## which is probably lower than ECMAScript 2020 (ES11) when support for dynamic imports was introduced.
  ## See also https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import
  ## and https://caniuse.com/?search=import()
  #set ($discard = $xwiki.jsx.use($sheetReference, {'minify': false}))
  #set ($discard = $xwiki.ssx.use($pdfExportConfig.template))
  #set ($discard = $xwiki.jsx.use($pdfExportConfig.template))
  ## Use the specified PDF file name as the title of the HTML page in order to have it suggested as file name when
  ## saving the PDF from the browser's Print Preview dialog.
  #if ($pdfExportJobRequest)
    #set ($title = $pdfExportJobRequest.fileName)
  #end
  ## Output the HTML header but without the garbage from the start of the BODY tag.
  #set ($htmlHeader = "#template('htmlheader.vm')")
  ## The PDF export doesn't target only the paper paged media, and we want to preserve the styles from the XWiki skin as
  ## much as possible.
  #set ($htmlHeader = $htmlHeader.replace('data-xwiki-paged-media="paper"', ''))
  #set ($headTagEnd = $htmlHeader.indexOf('</head>'))
  #set ($bodyTagStart = $htmlHeader.indexOf('<body'))
  #set ($bodyContentStart = $htmlHeader.indexOf('>', $bodyTagStart) + 1)
  $htmlHeader.substring(0, $headTagEnd)
  <script>
  requirejs.config({
    ## When performing large multi-page exports the RequireJS timeout can be reached because there are many HTTP
    ## requests and the browser uses a limited pool to handle them. We noticed this problem on a PDF export with many
    ## live tables because they fetch their results pretty early, before many RequireJS modules are requested. In any
    ## case, we have the page ready timeout to stop the export in case it takes too much time to load the print preview
    ## page. We don't need another timeout for RequrieJS modules.
    waitSeconds: 0,
    ## PagedJS uses some utility functions that are not exposed by the RequireJS module, so we have to import them
    ## ourselves from the WebJar in order to be able to patch PagedJS bugs.
    config: {
      'pagedjs-module': {
        baseURL: $jsontool.serialize($services.webjars.url('org.webjars.npm:pagedjs', ''))
      }
    }
  });
  </script>
  ## Inject the required skin extensions.
  $!pdfExportJobStatus.requiredSkinExtensions
  #clientSidePDFExportConfiguration()
  ## Start the BODY tag.
  $htmlHeader.substring($headTagEnd, $bodyContentStart)
  #set ($pdfTemplateObj = $xwiki.getDocument($pdfExportConfig.template).getObject('XWiki.PDFExport.TemplateClass'))
  #foreach ($element in $pdfElements)
    #if ($pdfExportConfig.get($element))
      #set ($output = "#renderPDFElement($pdfTemplateObj $element)")
      #set ($output = $output.trim())
      #if ($output != '')
        <div class="pdf-$element">$output</div>
      #end
    #end
  #end
  <div id="xwikicontent">
    #renderPDFContent()
  </div>
  ## Close the tags opened in htmlheader.vm
    </body>
  </html>
#end

#macro (clientSidePDFExportConfiguration)
  #set ($clientSideConfig = {
    'documents': [],
    'baseURL': $pdfExportJobRequest.baseURL
  })
  #foreach ($renderingResult in $pdfExportJobStatus.documentRenderingResults)
    #set ($discard = $clientSideConfig.documents.add({
      'reference': $services.model.serialize($renderingResult.documentReference, 'default'),
      'idMap': $renderingResult.idMap
    }))
  #end
  <script id="pdfExportConfig" type="application/json">$jsontool.serialize($clientSideConfig).replace(
    '<', '\u003C')</script>
#end

#macro (renderPDFElement $pdfTemplateObj $element)
  #unwrapXPropertyDisplay($tdoc.display($element, $pdfTemplateObj))
#end

#macro (renderPDFContent)
  #if (!$pdfExportJobRequest.isWithTitle())
    ## The document renderer includes the document metadata in the rendering results only when document titles are
    ## displayed (because we should have a single metadata on a print page and the document title starts on a new print
    ## page, but also because the metadata can be used to tweak how the document title is displayed, e.g. to skip or
    ## reset heading numbering). We may still want to display the metadata for a single page export or for a multipage
    ## export without titles, but in this case the same metadata is going to be displayed on all print pages, and it
    ## comes from the target document on which the PDF export was triggered.
    #outputMetadataFromTargetDocument()
  #end
  #foreach ($renderingResult in $pdfExportJobStatus.documentRenderingResults)
    $renderingResult.getHTML()
  #end
#end
{{/velocity}}

{{velocity wiki="false"}}
#if ($request.sheet == $sheetReference)
  ## Default PDF Export configuration.
  #set ($pdfExportConfig = {
    'template': 'XWiki.PDFExport.Template',
    'cover': true,
    'toc': true,
    'header': true,
    'footer': true
  })
  #getPDFExportConfigFromRequest($pdfExportConfig)
  #renderPDFSheet($pdfExportConfig)
#end
{{/velocity}}

```

making your test  
 ![image](https://forum.xwiki.org/uploads/default/original/2X/0/071f62b9f109fc61a136860b8d13c6523b71aeae.png)

and there it is:  
 ![image](https://forum.xwiki.org/uploads/default/original/2X/e/e6a966c3d0fee98ed665cfea3c589ced817b0c99.png)

---

<div class="post-metadata">

**Author:** ![rogerpenna](https://forum.xwiki.org/user_avatar/forum.xwiki.org/rogerpenna/32/5264_2.png) [@rogerpenna](https://forum.xwiki.org/u/rogerpenna)\
**Post date:** [September 5, 2024, 11:50am UTC](https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460/11 "2024-09-05T11:50:27Z")

</div>

based on the code in that part, I don´t really understand what it does. If the document is without title, it should should CALL that function and show the title there.

but the document HAS a title, it’s even being shown in the header.

Since it’s showing the text there, what if I delete the text?

Seems to work. But what will be the downsides?  
 ![image](https://forum.xwiki.org/uploads/default/original/2X/5/566120ddf40217dcef3e1b7276dcd631d6dff91e.png)

---

<div class="post-metadata">

**Author:** ![mflorea](https://forum.xwiki.org/user_avatar/forum.xwiki.org/mflorea/32/49_2.png) [@mflorea](https://forum.xwiki.org/u/mflorea)\
**Post date:** [September 5, 2024, 12:14pm UTC](https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460/12 "2024-09-05T12:14:40Z")

</div>

> [@rogerpenna](#):
>
> Only a SINGLE ocurrence appears to me… weird…

Then you’re missing some code. I don’t understand how. See [xwiki-platform/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Sheet.xml at xwiki-platform-16.7.0 · xwiki/xwiki-platform · GitHub](https://github.com/xwiki/xwiki-platform/blob/xwiki-platform-16.7.0/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Sheet.xml#L167-L175) . This is the code from v16.7.0 (latest). If you upgraded to 16.7.0 then should normally have this code. You’re missing precisely the macro definition… I suggest you go to Administration \> Extensions and looks for the PDF Export Application. From there you can compute the local changes compared to the standard code (and you can revert them). See [https://extensions.xwiki.org/xwiki/bin/view/Extension/Extension+Manager+Application#HComputeChanges](https://extensions.xwiki.org/xwiki/bin/view/Extension/Extension+Manager+Application#HComputeChanges) .

---

<div class="post-metadata">

**Author:** ![rogerpenna](https://forum.xwiki.org/user_avatar/forum.xwiki.org/rogerpenna/32/5264_2.png) [@rogerpenna](https://forum.xwiki.org/u/rogerpenna)\
**Post date:** [September 5, 2024, 12:22pm UTC](https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460/13 "2024-09-05T12:22:56Z")

</div>

weird, the extension appears twice to me. I don´t see why the 14.xx should appear

 ![image](https://forum.xwiki.org/uploads/default/original/2X/e/ef99e265fffbdea8f668a7f54ba4b182305fb750.png)

anyway, I computed the changes. I suppose I should “restart”? (I suppose the button should be called RESTAURAR or even the adapted loanword RESETAR

Reiniciar (Restart) seems to be a bad translation

 ![image](https://forum.xwiki.org/uploads/default/original/2X/3/3f0e43cdeaf784339277e78fb4350aaf76e294f1.png)

---

<div class="post-metadata">

**Author:** ![rogerpenna](https://forum.xwiki.org/user_avatar/forum.xwiki.org/rogerpenna/32/5264_2.png) [@rogerpenna](https://forum.xwiki.org/u/rogerpenna)\
**Post date:** [September 5, 2024, 12:30pm UTC](https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460/14 "2024-09-05T12:30:47Z")

</div>

the help text on " [https://extensions.xwiki.org/xwiki/bin/view/Extension/Extension+Manager+Application#HComputeChanges](https://extensions.xwiki.org/xwiki/bin/view/Extension/Extension+Manager+Application#HComputeChanges) " to compute changes is very bad. Where do I post suggestions to improve it? The help should show an image that you must click on the arrow next to uninstall to see the “Computer Changes” option. And then click the tab Changes. The image in the help doesn´t show the changes tab NEITHER the Compute Changes option

---

<div class="post-metadata">

**Author:** ![rogerpenna](https://forum.xwiki.org/user_avatar/forum.xwiki.org/rogerpenna/32/5264_2.png) [@rogerpenna](https://forum.xwiki.org/u/rogerpenna)\
**Post date:** [September 5, 2024, 12:55pm UTC](https://forum.xwiki.org/t/error-outputmetadata-from-target-document-when-trying-to-export-as-pdf/15460/15 "2024-09-05T12:55:04Z")

</div>

Reseted the changes, now it shows no changes

 ![image](https://forum.xwiki.org/uploads/default/original/2X/4/4176a414742e0febf513d9c931bfdca2f39e7b2e.png)

Sheet now shows the macro code

 ![image](https://forum.xwiki.org/uploads/default/original/2X/5/584b747be024a586b7f62b0aa61f130858040325.png)

and export worked fine! Thank you MFlorea!  
 ![image](https://forum.xwiki.org/uploads/default/original/2X/3/3a18f7a94dea39037fd38051b0ef95985b035053.png)
