Rendering PDF using Ferrum sometimes loses landscape #324
-
Hello! I am using Ferrum to generate PDFs from HTML. However, if I pass the new HTML it will not write it as landscape even if the option is given. # Inspired by:
# https://gist.github.com/forsbergplustwo/da777dd47f343408ad9adc29e21ad674
def self.generate(html, footer_text: "", wait_for_status: nil, wait_for_timeout: Platform.pdf_timeout_in_seconds, landscape: false)
browser = Ferrum::Browser.new(
headless: true,
process_timeout: Platform.pdf_timeout_in_seconds,
timeout: Platform.pdf_timeout_in_seconds
)
intercept(browser: browser, html: html)
browser.go_to(FAKE_URL)
wait_for_page(
browser: browser,
wait_for_status: wait_for_status,
wait_for_timeout: wait_for_timeout
)
pdf = nil
Tempfile.create do |tempfile|
browser.pdf(
path: tempfile.path,
format: :A4,
landscape: landscape,
margins: {
top: 15,
right: 12,
bottom: 15,
left: 12
},
preferCSSPageSize: true,
printBackground: true,
displayHeaderFooter: true,
footer_template: footer_html(footer_text),
header_template: "<div></div>"
)
if block_given?
yield(File.new(tempfile.path))
else
return(File.read(tempfile.path))
end
end
nil
ensure
browser&.reset
browser&.quit
end The CSS and HTML-layout is completely different, but I cannot find why it is not landscape with the new layout. Do anyone have any idea how I can debug this? |
Beta Was this translation helpful? Give feedback.
Answered by
route
Jan 11, 2023
Replies: 1 comment 1 reply
-
You could set FERRUM_DEBUG=true env variable before running browser and check that all options you pass at least passed to Chrome in the corresponding CDP call. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
davidwessman
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could set FERRUM_DEBUG=true env variable before running browser and check that all options you pass at least passed to Chrome in the corresponding CDP call.