-
Notifications
You must be signed in to change notification settings - Fork 640
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
Request for help: Setting footer height or margin on page by page basis #572
Comments
The margins are document-global (as if you did page-setup before printing), and this is not supported by wkhtmltopdf (or wicked_pdf). The workaround to this would be to create the cover as a separate PDF document from the rest, and stitch them together with PDFtk or something like that. Here are some other related issues that might help you out: Please let me know how it goes, and how the solution looked for future developers that have this issue, as it seems to be a common issue/request. |
Ok will do thanks for the timely response. |
@unixmonkey I am going down the route you suggested and create a pdf on a page by page basis and stitch them together. I am trying to determine how to know when page 1 ends and page 2 begins. I am using the I know I cant do
Then stitch those three pdf's together. Is there a way to know the max content on page one so a user only has to fill out one form and then somehow that gets parsed into three pdf's. I guess I could do Thanks again. |
Given what you're telling me, I think I might try to do something like this, where you create two versions of the PDF, one with a large footer on every page, and one with a normal footer. Then using PDFtk, split out the first page (and discard the rest) of the first PDF, then do the same with the body PDF, but discard the first page something like this: Warning: this is untested, not very secure, very inefficient, has no error-handling, and may not even work at all. html_content = render_to_string
cover_pdf = WickedPdf.new.pdf_from_string(html_content, { footer: { margin: { bottom: 200 })
body_pdf = WickedPdf.new.pdf_from_string(html_content, { footer: { margin: { bottom: 10 })
cover_src_temp_file = Tempfile.new(['cover_src', '.pdf'])
cover_src_temp_file.binmode
cover_src_temp_file.write(cover_pdf)
cover_src_temp_file.rewind
cover_temp_file = Tempfile.new(cover_pdf)
`pdftk #{cover_src_temp_file} cat 1 output #{cover_temp_file.path.to_s}` # first page only
body_src_temp_file = Tempfile.new(['body_src', '.pdf'])
body_src_temp_file.binmode
body_src_temp_file.write(cover_pdf)
body_src_temp_file.rewind
body_temp_file = Tempfile.new(body_pdf)
`pdftk #{body_src_temp_file.path} cat 2-end output #{body_temp_file.path}` # everything else
output_temp_file = Tempfile.new(['output', '.pdf'])
`pdftk #{cover_temp_file.path} #{body_temp_file.path} cat output #{output_temp_file.path}`
send_file output_temp_file, disposition: 'inline'
[cover_src_temp_file, body_src_temp_file, cover_temp_file, body_temp_file, output_temp_file].each do |tf|
tf.close
tf.unlink
end If you have trouble getting your HTML to break at a good spot, you can use this CSS class to delimit where your first page content ends: page 1 content
<div style="page-break-after: always;"></div>
page 2 content This is kind of a lot of hoop-jumping though, and I might be tempted to give this a shot using prawn for finer-grained control (at the expense of being able to use existing markup and styles and such) for simpler reports. Let me know how it goes. |
Thanks for the code! Ill let you know what I come up with |
@unixmonkey sorry if this is a newbie question but out of curiosity why am I not able to set the margin on a page by page basis using JS. I was able to specify which footer shows up on each page using JS as well as change the background color on the footer. Is it not possible because the size of the header, body and footer content is fixed and cant be overwritten? Also could you recommend any good books or tutorials on |
I need to add margin and padding with respect to header to multiple pages pdf report generated with wicked pdf but I can't find any solutions yet, can anyone help me please! |
I have been using the Wicked Pdf gem and have been loving it, thanks for creating it.
However, I have run into a situation where a need to attach and have visible a large footer to the first page, but not the rest of the pages. To accomplish this I added a margin to the bottom of the body of the pdf as suggested in this post which gives the footer enough room to be visible.
This causes adverse side effects because it adds bottom margin to all of the pages not just this first page. I was hoping to only add margin to the first page and leave the rest of the pages unchanged.
I've tried to accomplish this with the use of javascript and css but have had no luck so far.
Thanks in advance
The text was updated successfully, but these errors were encountered: