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

#outputMetadataFromTargetDocument()

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

Here is the PDF Template CSS

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

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 . 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)?

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

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

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.

and INDEED, the error message did not appear

trying to export ONLY one document (the same one) results in the message again
image

any suggestion on how to proceed?

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

16.4 but I am just now upgrading to 16.7

ok, finished upgrading to 16.7. The problem persists.

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?

Only a SINGLE ocurrence appears to me… weird…

{{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

and there it is:
image

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

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

1 Like

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

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

the help text on " 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

Reseted the changes, now it shows no changes

Sheet now shows the macro code

and export worked fine! Thank you MFlorea!
image

1 Like