pdfResource : use MODX placeholders in footer

Hello

I’d place MODX placeholders inside mPDF footer using pdfresource.SetHTMLFooter system setting , eg:

["<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td class='w-50 v-align-top'><a href='https://catalogue.[[+migx.domain]]'>catalogue.[[+migx.domain]]</a>
</td><td class='w-50 v-align-top text-right'>{PAGENO}/{nbpg}</td></tr></table>"]

But placeholders returns [[+placeholdername]], not the output

how and where to you set that placeholder?

No MODx placeholders are replaced in the footer string.
You have to change the code to make it work.

For example if you change the code above to this

if ($value && method_exists($this->pdf, $methodName)) {
	$value[0] = $this->parseChunk("@INLINE",$value[0],$resource->toArray()); //replace placeholders
	call_user_func_array(array($this->pdf, $methodName), $value);
}

then resource placeholders (like [[+pagetitle]]) would be replaced.

  1. in footer via pdfresource.SetHTMLFooter system setting (will be probably resolved with the help of @halftrainedharry )

  2. in the resource content, in non-default context, placeholders doesn’t return anything inside PDF, and settings returns the default context values (for example: ++site_url → default ‘web’ context site_url inside the PDF), the context seems to me ignored inside the PDF output.
    Here is the PDF link :

<p><a class="button btn btn-primary" download="" href="[[*id:pdfresourcelink]]">Downoad</a></p>

Thank you very much ! I’ll try.

Also when I use the “Create PDF” TV (checked), placeholders are empty and system settings are related to the default “web” context, not the resource context

But when I use the “Create PDF on the fly”, placeholders and site settings (ex: ++site_url) are OK, including my MIGX placeholders.

Regarding the wrong context, you could try if if works, when you move this line

further down (between line 29 and 30), so the creation of the PDF (line 28: $this->pdfresource->createPDF) still happens in the context of the resource (line 18: $this->modx->switchContext($resource->context_key);)

But I’m not sure it that works. I haven’t tested it.

Still not working… May it’s because I use xRouting extra with http_host_aliases (?)
My custom placeholders are set via a snippet using the http host alias (not the context domain).

It’s unclear to me what exactly you are trying to do.

But if the content of the PDF depends on the specific way a resource is called, then maybe you can’t use create_pdf.

  • create_pdf creates the PDF once when you click the save-button of the resource in the manager.
  • live_pdf on the other hand creates a new PDF for every request.