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
Initial commit and sketchings of Print Page As PDF
Keyword
#1851
base: master
Are you sure you want to change the base?
Conversation
Some initial ideas and sketches for the `Print Page As PDF` keyword. I wanted to seewhat it may look like and how it may work. So this is just some preliminary ideas. Seeing a need to handle Print Options, need to document options and what are valid values, how to deal with the return encoded base64 string, etc.
|
||
base64code = self.driver.print_page(print_options) | ||
pdfdata = b64decode(base64code) | ||
with open('test.pdf', mode='wb') as pdf: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very preliminary. For example, here I just use a test file. I expect a fair more code and allowing the user to specify the optional filename or filename syntax when printing page as pdf.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the first thing I noticed, thanks for clarifying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to be able to set a default set of PrintOptions? Meaning the user can set the PrintOptions once, and those settings will be used every time the print_page_as_pdf will be called?
Something like with setting the timeouts
${old_value} Set Print to PDF options scale=0.5 password=${pdfpassword}
or something like that
Print Page As PDF Without Print Options | ||
Print Page As PDF | ||
|
||
Provide Print Options From Module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this test I just wanted to do a preliminary exploration of how to set print options. A while back for when one opens a browser there were ways to customize how the browser was started. To do this one had to do something similar, which is go into the python module and make an instance of the python class of options. Then add to that robot variable as class instance with a method on that class to add attributes. It was fairly ugly and the syntax was all python. But doable. Tatu really cleaned that up with just having a string of options. I wanted to see if one could add print options that old school way. Here I left in my failed attempts as a reminder of what failed and what worked so if we do explain it with this then I can say what and what not to do.
@@ -235,3 +237,20 @@ def _embed_to_log_as_file(self, path, width): | |||
f'<a href="{src}"><img src="{src}" width="{width}px"></a>', | |||
html=True, | |||
) | |||
|
|||
@keyword | |||
# def print_page_as_pdf(self, print_options: Optional[PrintOptions]=None,): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to figure out the proper type hints and type conversion signature for this method ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't been able to try this yet, but added some thoughts/comments
|
||
base64code = self.driver.print_page(print_options) | ||
pdfdata = b64decode(base64code) | ||
with open('test.pdf', mode='wb') as pdf: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the first thing I noticed, thanks for clarifying.
|
||
base64code = self.driver.print_page(print_options) | ||
pdfdata = b64decode(base64code) | ||
with open('test.pdf', mode='wb') as pdf: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to be able to set a default set of PrintOptions? Meaning the user can set the PrintOptions once, and those settings will be used every time the print_page_as_pdf will be called?
Something like with setting the timeouts
${old_value} Set Print to PDF options scale=0.5 password=${pdfpassword}
or something like that
@@ -241,16 +241,64 @@ def _embed_to_log_as_file(self, path, width): | |||
@keyword | |||
# def print_page_as_pdf(self, print_options: Optional[PrintOptions]=None,): | |||
# def print_page_as_pdf(self, print_options: Optional[Union[PrintOptions, dict]]=None): | |||
def print_page_as_pdf(self, print_options: Union[PrintOptions, dict, None]=None): | |||
# def print_page_as_pdf(self, print_options: Union[PrintOptions, dict, None]=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments can be removed
Some initial ideas and sketches for the
Print Page As PDF
keyword. I wanted to seewhat it may look like and how it may work. So this is just some preliminary ideas. Seeing a need to handle Print Options, need to document options and what are valid values, how to deal with the return encoded base64 string, etc.