Skip to content
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

how to change the viewport size in ruby #26

Closed
perljuls opened this issue Jul 12, 2019 · 5 comments
Closed

how to change the viewport size in ruby #26

perljuls opened this issue Jul 12, 2019 · 5 comments

Comments

@perljuls
Copy link

perljuls commented Jul 12, 2019

// reports_controller.rb

def pdf
    pdf_html = ActionController::Base.new.render_to_string(template: 'reports/pdf.html.erb', layout: 'pdf' )

    pdf = Grover.new(pdf_html, {
      format: 'A4' //dynamic 
    }).to_pdf
end

//grover.rb

Grover.configure do |config|
  config.options = {
    emulate_media: 'screen',
    cache: false,
    print_background: true,
    prefer_css_page_size: true,
    # timeout: 0 # Timeout in ms. A value of `0` means 'no timeout'
  }
end

I tried pdf.setViewPort() but I think it is for page = ..browser something

@abrom
Copy link
Contributor

abrom commented Jul 12, 2019

Good question @perljuls

Unfortunately I haven't added that in just yet. It's available in the puppeteer API on the page object:
https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagesetviewportviewport

Interestingly, I was hitting up on the need to have that in place no more than 30 minutes ago! I'll likely look to add it in for the next release

@abrom
Copy link
Contributor

abrom commented Jul 12, 2019

FYI this has been added in #28

You can configure it either via the global configuration, in the Grover initialiser or if you're using the middleware, via meta options

I'll roll a release with this soon

@perljuls
Copy link
Author

Thanks :)

@abrom abrom closed this as completed Jul 23, 2019
@willkoehler
Copy link
Contributor

willkoehler commented Feb 14, 2020

Is it possible to set the viewport size with <meta> tags? Ex:

<meta name="grover-viewport-width" content=640>
<meta name="grover-viewport-height" content=480>

This doesn't work because 640 and 480 are converted to strings and puppeteer throws an error "Protocol error (Emulation.setDeviceMetricsOverride): Invalid parameters width: integer value expected; height: integer value expected"

@abrom
Copy link
Contributor

abrom commented Feb 14, 2020

Suggest create a new issue for this @willkoehler, but yes definitely possible. Something I'd already done for the scale attribute:

options['scale'] = options['scale'].to_f

You're welcome to create a PR for it, otherwise I can take a look when I get some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants