asciidoctor / asciidoctor-pdf

:page_with_curl: Asciidoctor PDF: A native PDF converter for AsciiDoc based on Asciidoctor and Prawn, written entirely in Ruby.
https://docs.asciidoctor.org/pdf-converter/latest/
MIT License
1.14k stars 500 forks source link

Background image in portrait and landscape mode #1739

Closed cloud-fundis closed 2 years ago

cloud-fundis commented 4 years ago

Hi folks,

First, let me say, what an awesome product. You guys have done exceptionally well and I love asciidoctor-pdf.

I wanted to ask about switching between portrait and landscape modes. I can of course do this as described elsewhere, but I would love to be able to put my background image on the landscape page by specifying a different PNG in the landscape mode instead of the portrait mode.

Illustration: I usually put a border around all pages on my documentation. It's a thing for my company. So I have a PNG/JPG that is A4 in size with this border (and of course my logo on the top-right corner). However when I switch my page from portrait to landscape, the border is still in portrait mode making the page look daft.

I tried: page: portrait: margin: 5mm background-image: image:img/PDFBorderP.png[] landscape: margin: 5mm background-image: image:img/PDFBorderL.png[]

But this does not work.

Any advice or is this a feature that you would have to implement?

Thanks in advance, Hamish

1marc1 commented 4 years ago

+1 - Asciidoctor is an awesome product and a big thank you to everyone involved to make it happen! +1 - I would also really like this functionality!

mojavelinux commented 4 years ago

We did something similar to this for the background image in the running content. (See #1570). Unfortunately, it's a bit more complicated of a change in this case since we resolve the background image up front, and it's not tied to the layout. I'm not sure if I have time to work on that right now.

mojavelinux commented 4 years ago

One open question would be whether to allow the {page-layout} placeholder to be used in the image target, or whether to use a separate key page-background-image-landscape or page-background-image-recto-landscape. (The permutations get out of hand pretty quickly here).

1marc1 commented 4 years ago

@mojavelinux My view is that the user currently has the option to set a page background and they have the option to specify the page orientation. However, practically they cannot combine these two options. I am not sure about the best way to technically implement a solution or what key naming would be most appropriate.

I feel there is a gap in functionality that somehow needs to be closed.

mojavelinux commented 4 years ago

I understand the need. There's no need to justify that aspect.

mojavelinux commented 2 years ago

Note that this is already possible for the background of the running content (header or footer). See #1570. This issue is about the background for the content area.

mojavelinux commented 2 years ago

To be consistent with the approach we took for the running content, I've decided to implement support for the {page-layout} attribute reference in the image path for all background images.

If defined in the document, the attribute reference must be escaped to defer evaluation:

:page-background-image: image:bg-\{page-layout}.svg[]

If defined in the theme, the attribute reference can be used as is (since attribute references are not evaluated until the converter resolves the image)

page:
  background-image: image:bg-{page-layout}.svg[]

This change does require changing the parameters of the internal init_page method to accept the parsed document as the first argument. That argument is needed to pass down to the method that ultimately resolves the background image.