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

jdonges
Posts: 4
Joined: Mon Dec 16, 2019 3:01 pm

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

Post by jdonges » Wed Jul 01, 2020 4:04 pm

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

julien_lacour
Posts: 99
Joined: Wed Oct 16, 2019 3:47 pm

Re: Custom transformation parameters for css

Post by julien_lacour » Fri Jul 03, 2020 10:58 am

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

Dan
Posts: 453
Joined: Mon Feb 03, 2003 10:56 am

Re: Custom transformation parameters for css

Post by Dan » Fri Jul 03, 2020 2:42 pm

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.

chrispitude
Posts: 201
Joined: Thu May 02, 2019 2:32 pm

Re: Custom transformation parameters for css

Post by chrispitude » Sat Jul 04, 2020 7:39 pm

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?

julien_lacour
Posts: 99
Joined: Wed Oct 16, 2019 3:47 pm

Re: Custom transformation parameters for css

Post by julien_lacour » Mon Jul 06, 2020 10:05 am

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

jdonges
Posts: 4
Joined: Mon Dec 16, 2019 3:01 pm

Re: Custom transformation parameters for css

Post by jdonges » Mon Jul 06, 2020 11:18 am

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

Post Reply