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

[chrome_print] add support for PDF streaming #205

Merged
merged 8 commits into from
Jan 17, 2021
Merged

[chrome_print] add support for PDF streaming #205

merged 8 commits into from
Jan 17, 2021

Conversation

RLesur
Copy link
Collaborator

@RLesur RLesur commented Jan 17, 2021

The aim of this PR is to add support for PDF streaming in chrome_print().

For now, very large PDF lead to a websocket error:

[error] consume error: websocketpp.processor.4 (A message was too large)

The Page.printToPDF method has an experimental feature to return the PDF as a stream: transferMode = "ReturnAsStream".

With this PR, one can print a PDF with the stream transfer mode:

chrome_print(..., options = list(transferMode = "ReturnAsStream"))

TODO

  • write a test
  • implement stream support
  • test the generation of very large PDF files (more than one chunk)
    Edit: tested with a 24 MB PDF file (4 stream chunks)
  • add support for the chunk size parameter (see IO.read)
    Edit: after several tests, I think this is useless, the websocket package works fine
  • update documentation

@RLesur RLesur marked this pull request as ready for review January 17, 2021 21:34
@RLesur RLesur merged commit 7991cbc into master Jan 17, 2021
@RLesur RLesur deleted the pdf_streaming branch January 17, 2021 21:47
@cderv
Copy link
Collaborator

cderv commented Jan 18, 2021

So cool ! Thanks @RLesur !

@RLesur
Copy link
Collaborator Author

RLesur commented Jan 18, 2021

IMO, the next step will be to change the default behavior of chrome_print() and use the stream mode transfer by default (when the Chrome version supports it).

@cderv
Copy link
Collaborator

cderv commented Jan 18, 2021

Would that mean compatibility issues with previous Chrome version and pagedown if we make it the default ?

@RLesur
Copy link
Collaborator Author

RLesur commented Jan 18, 2021

Would that mean compatibility issues with previous Chrome version and pagedown if we make it the default ?

The compatibility issue would only be with older versions of Chrome which do not support PDF streaming.

But, for now, I think that we could take benefit of Chrome PDF streaming capabilities like this:

  1. Check if the available version of Chrome supports PDF streaming: feasible (=> check the remote protocol and test whether the transferMode parameter is available in the Page.printToPDF command)
  2. If Chrome support PDF streaming, change automatically the value of transferMode (and allow users to override this behavior)

IMO, this would lead to a better user experience: chrome_print() would automatically exploit the available Chrome features. If a user is stuck with a large PDF file, he would only have to upgrade Chrome.

@cderv
Copy link
Collaborator

cderv commented Jan 18, 2021

Oh yeah if we have a way to check this is the way to go.

I suggest we open an issue to track the idea of changing this to the default in future versions ?

That way, I'll remember to do it in case you don't find the 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

Successfully merging this pull request may close these issues.

2 participants