-
Notifications
You must be signed in to change notification settings - Fork 684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repeater should be added before any other content (or allow it) #1135
Comments
Repeaters are ran right before the document gets rendered. That is, after all content has been placed. That is by design. Is there a reason you can not render images before placing the content? |
You mean outside of a repeater? (because as you said, repeaters are called "after all content is placed", so rendering images "before" means not using a repeater, right?) To summarize the problem again: A repeater is like a stamp (it is implemented like it). Now you might want to have a stamp behind some text or above, the later is what's implemented, for the former there's the PR. I'll be glad to make changes if that's required. I did try to follow the code logic as good as I could, but I'm by no means a prawn expert... |
There are a number of solutions.
|
If I understood your code and comment correctly, this would not work:
From your comments the best option would be to call on_page_create for the first page too (and by the way pass some context information, like the page count) |
It's not quite possible to call As for the page number, it's accessible via Here's an example: Prawn::Document.generate "test.pdf" do
# This is a proc that draws background
page_bg = proc do
image 'background.png'
text_box page_number.to_s # Show the page number
end
on_page_create(&page_bg) # Set the proc as callback
# Manually call the background drawing proc on the first page
# callback is called in a `float` to not disturb the flow of the page, here we do it for the same reason
float { page_bg.call }
move_down 20
text 'foo'
start_new_page
move_down 20
text 'bar'
start_new_page
move_down 20
text 'baz'
end |
According to the docs you can also pass the Prawn::Document.generate "test.pdf", skip_page_creation: true do
on_page_create do
# add image based on current page_number
end
start_new_page
# continue creating the document
end |
I have similar problem I have an image that has a header and background for the page
the problem with this is the image will be put out as foreground instead background the workaround are using so you will need to add it manualy so the complete solution are
my current problem is move_cursor_to not working inside on_page_create do |
I don't think placing I agree that this is a confusing behaviour but it's a nature of Prawn. You can think of Prawn as being a streaming library. Document is constructed as the code executes. The fact that you can jump around pages doesn't change this fact. Streaming nature dictates how the document is created and in which order it is being constructed. For historical reasons (mostly) Prawn creates first page on initialization. That is before any One work around might be to pass require 'open-uri'
Prawn::Document.generate("test.pdf", skip_page_creation: true) do
on_page_create do
image URI.open("https://prawnpdf.org/images/prawn.png")
end
1.upto(3) do |n|
start_new_page
text "Page #{n}\n" * 10
end
end This produces a document with 3 pages each having an image in the background and the text in the foreground. |
yeah I have refine my code( I just read it somewhere that the only problem that still exist to me is how to make the text started at certain cursor (below the repeated image ideally)? I could use problem is when the page creation is created by flowing content the cursor is not moved at all in that case |
You can try setting margins to leave enough space for your header image. |
the only way to setup margin is only by giving parameter to so for you guys that kinda have similar problemo
extra notes for u guys that confused about conversion points and measurements the doc said default margin is 0.5 inch what number is 0.5 in the parameter? the number is 36 because 0.5 *72 is 36 as in this |
You can also use |
thank you so much for helping and maintaining prawn |
We use different background images for different pages, adding it with a repeater this way:
We need to do it in Overlay mode, because the text is rendered behind the image. The overlay affects the rendering so we want to get rid of it.
I think what is happening is that the repeat block (or stamp) is called after the page has been rendered, not before.
The text was updated successfully, but these errors were encountered: