Page 1 of 1

Custom transformation parameters for css (background image for the title page)

Posted: Wed Jul 01, 2020 4:04 pm
by jdonges
Hello, I need some help again.

I use the XSLT and CSS to PDF Transformation Scenario and have specified a background image for the title page

Code: Select all

@page front-page{
    
    background-image: url("../img/title.png");
}
It works fine as long as we need the same title page all the time. But to produce different documents with different titlepages I would like to pass the url to an image as parameter to the transformation.

I tried to make a new parameter "titlepage" in the transformation settings and refer to it with

Code: Select all

@page front-page{
    
    background-image: url(${titlepage});
}
But this does not work.
How can we pass the filename to transformation?
tia
Jörn

Re: Custom transformation parameters for css

Posted: Fri Jul 03, 2020 10:58 am
by julien_lacour
Hello,

The best thing to do is to use a custom parameter:
  1. In the transformation scenario dialog, create a new parameter called for example "args.css.param.cover-page" and set its value to the image path (for example: "../img/title.png")
  2. In your CSS file use the following selector

    Code: Select all

    @page front-page {
        background-image: url(oxy_xpath('/*/@*[local-name()="cover-page"][1]'));
    }
You image should appear in the PDF.

Regards,
Julien

Re: Custom transformation parameters for css

Posted: Fri Jul 03, 2020 2:42 pm
by Dan
Please note that the image path should be given as an absolute URI, like: file:/C:/temp/example.svg. It works also with relative paths, but it will solve them relative to the XML location.

Re: Custom transformation parameters for css

Posted: Sat Jul 04, 2020 7:39 pm
by chrispitude
Useful technique, thank you!

Is there a way to write a CSS selector so that it is only applied when the parameter is set to a particular value?

Re: Custom transformation parameters for css

Posted: Mon Jul 06, 2020 10:05 am
by julien_lacour
Hello,

It is possible to control the first parameter by using a second custom parameter, for example "args.css.param.use-cover" with value "yes".

Then in the CSS, using the following selectors:

Code: Select all

:root[use-cover='yes'] *[class~='front-page/front-page'] {
    page: custom-front-page;
}

@page custom-front-page {
	background-image: url(oxy_xpath('/*/@*[local-name()="cover-page"][1]'));
}
Regards,
Julien

Re: Custom transformation parameters for css

Posted: Mon Jul 06, 2020 11:18 am
by jdonges
This works well, thank you!
Sometimes it is hard to figure out these cryptic notations :)

We have to use the relative paths because the XML data is in a repository and will be downloaded to different locations.

Regards
Joern