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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[馃悰 Bug]: print_page method does not adhere to page_height and page_width declared in PrintOptions #12066

Closed
MrChadMWood opened this issue May 18, 2023 · 5 comments
Labels
G-geckodriver Requires fixes in GeckoDriver I-defect needs-triaging

Comments

@MrChadMWood
Copy link

MrChadMWood commented May 18, 2023

What happened?

Hello,

Method: driver.print_page
Issue: does not ahere to selenium.webdriver.common.print_page_options.PrintOptions declared page_height and page_width

Recently attempted to customize the resulting PDF size after using driver.print_page().
Given 72 points per inch, the resulting PDF does not appear to adhere to the preconfigured customization.

I set page height and page width to 10". The resulting yield was a 284x284pt PDF, which by my understand equates to 3.94".
The expected output was a file of size 720x720pt, or 10"x10".

How can we reproduce the issue?

Python 3.11.2
selenium==4.9.1
pdfminer==20191125

from selenium import webdriver
import base64
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfpage import PDFPage


driver = webdriver.Firefox(options=options)
driver.get('https://www.google.com')

print_options = PrintOptions()
print_options.page_height = 10
print_options.page_width = 10

pdf = driver.print_page(print_options=print_options)
driver.close()

# save the output to a file.
with open('example.pdf', 'wb') as file:
    file.write(base64.b64decode(pdf))
    
# verify the page size of the PDF file created
parser = PDFParser(open('example.pdf', 'rb'))
doc = PDFDocument(parser)
pageSizesList = []
for page in PDFPage.create_pages(doc):
    print(page.mediabox)


### Relevant log output

```shell
[0, 0, 284, 284]
[0, 0, 284, 284]

Operating System

Windows 10

Selenium version

4.9.1

What are the browser(s) and version(s) where you see this issue?

Firefox 113.0.1

What are the browser driver(s) and version(s) where you see this issue?

geckodriver 0.31.0

Are you using Selenium Grid?

No

@github-actions
Copy link

@MrChadMWood, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@MrChadMWood MrChadMWood changed the title [馃悰 Bug]: driver.print_page method does not ahere to selenium.webdriver.common.print_page_options.PrintOptions declared page_height and page_width [馃悰 Bug]: print_page method does not ahere to page_height and page_width declared in PrintOptions May 18, 2023
@MrChadMWood
Copy link
Author

MrChadMWood commented May 18, 2023

Current workaround: multiply desired dimension by value of 2.5352112676056335

from selenium import webdriver
import base64
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfpage import PDFPage

# Function to find page size
S = lambda X: driver.execute_script('return document.body.parentNode.scroll'+X)

# Ratio to achieve desired size (for me atleast)
RATIO_MULTIPLIER = 2.5352112676056335

driver = webdriver.Firefox(options=options)
driver.get('https://www.google.com')

print_options = PrintOptions()
print_options.page_height = 10*RATIO_MULTIPLIER
print_options.page_width = 10*RATIO_MULTIPLIER
print_options.shrink_to_fit = True

pdf = driver.print_page(print_options=print_options)
driver.close()

# save the output to a file.
with open('example.pdf', 'wb') as file:
    file.write(base64.b64decode(pdf))
    
# verify the page size of the PDF file created
parser = PDFParser(open('example.pdf', 'rb'))
doc = PDFDocument(parser)
pageSizesList = []
for page in PDFPage.create_pages(doc):
    print(page.mediabox)

OUTPUT

[0, 0, 719, 719]

Expected result was 720x720. Close.

@titusfortner titusfortner added the G-geckodriver Requires fixes in GeckoDriver label May 18, 2023
@github-actions
Copy link

Hi, @MrChadMWood.
This issue has been determined to require fixes in GeckoDriver.

You can see if the feature is passing in the Web Platform Tests.

If it is something new, please create an Issue with the GeckoDriver team.

Feel free to comment the issues that you raise back in this issue. Thank you.

@MrChadMWood
Copy link
Author

Hi, @MrChadMWood. This issue has been determined to require fixes in GeckoDriver.

You can see if the feature is passing in the Web Platform Tests.

If it is something new, please create an Issue with the GeckoDriver team.

Feel free to comment the issues that you raise back in this issue. Thank you.

https://bugzilla.mozilla.org/show_bug.cgi?id=1833964

@MrChadMWood MrChadMWood changed the title [馃悰 Bug]: print_page method does not ahere to page_height and page_width declared in PrintOptions [馃悰 Bug]: print_page method does not adhere to page_height and page_width declared in PrintOptions May 29, 2023
Copy link

github-actions bot commented Dec 9, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
G-geckodriver Requires fixes in GeckoDriver I-defect needs-triaging
Projects
None yet
Development

No branches or pull requests

2 participants