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.13k stars 500 forks source link

Watermark (foreground image) is always left-aligned on landscape pages #2528

Closed nlyubova-psee closed 4 weeks ago

nlyubova-psee commented 1 month ago

Hello, it seems like Watermark (foreground image) is always left-aligned on landscape pages.

mojavelinux commented 1 month ago

The size, fit, and position of the foreground (watermark) image is controlled using the pdfwidth, fit, and position attributes on the image macro in the value of the page-foreground-image attribute. For example:

:page-foreground-image: image:watermark[pdfwidth=1in,fit=none,position=top center]

By default, a foreground image is automatically scaled to fit the bounds of the page (i.e., fit=contain) and centered (i.e., position=center).

You can learn more about how these attributes work on the following page: https://docs.asciidoctor.org/pdf-converter/latest/background-images/

I'll update that page to clarify that the size, fit, and position apply to foreground images as well.

mojavelinux commented 1 month ago

In the future, please direct questions about usage to the project chat first at https://chat.asciidoctor.org.

nlyubova-psee commented 1 month ago

Ok, Sorry for my request here and Thank you for your answer! Indeed, the documentation says it should be centered by default, but it was not. I'll try the attributes.

mojavelinux commented 1 month ago

No worries.

I'm confident the image is centered by default. This is supported by tests. It's possible that the image is not aligned to the center in the image itself. But if you can prove otherwise, please provide a reproducible example and I will study it.

nlyubova-psee commented 1 month ago

maybe I am doing something wrong. It works fine for portrait pages but not for landscape pages.

Here is an example [page-layout=landscape] <<<

== Possible issues

Here is an example of a landscape image.

[page-layout=portrait] <<<

image image

test.zip

mojavelinux commented 1 month ago

The fact that the layout is being changed back and forth in the document is very important context that was missing from your original report. Your terse report could be interpreted that the watermark was not being centered when the whole document was in landscape. It's always helpful be clear how you are using the feature, and that means providing a reproducible example up front.

You're correct that when you switch the layout, the foreground image is not positioned correctly on pages with a layout which is different from the layout on the first page. That's because the foreground image is being added using a single stamp and that stamp is static.

In order to correct this behavior, there needs to be a foreground image stamp per layout. That's not too difficult, so I will implement it.