webdriver

webdriver print with desired pageWidth pageHeight


I was searching and trying many things to change page size of generated PDF with webdriver.

I already read and studied those following links

https://w3c.github.io/webdriver/#print-page

https://webdriver.io/docs/api/webdriver/#printpage

https://github.com/jlipps/simple-wd-spec

as so far I was able to succesuflly use {"background": true} but when I try to change page size with using {"pageWidth": 29.70, "pageHeight": 42.00} (desired A3 format) then I have no success, I mean generated PDF is still 8,50x11,00 inches but I wanted A3 format which should be 11,69x16,54 inches.

Size of page in PDF I check using AcrobatReader: enter image description here

So I wanted to ask if I pass {"pageWidth": 29.70, "pageHeight": 42.00} incorectly or there is another issue which I do not understand.


Solution

  • I finally was able find the proper way

    {
        "page":{
                "width": 29.70
                ,"height": 42.00
            }
        ,"margin":{
                "top": 2
                ,"bottom": 2
                ,"left": 2
                ,"right": 2
            }
        ,"scale": 0.5
        ,"orientation":"landscape"
        ,"shrinkToFit": true
        ,"background": true
        ,"pageRanges": ["1", "1-1"]
    }
    

    EDIT 2024-12-16: I forgot to add that I also modified this description:

    https://github.com/jlipps/simple-wd-spec/?tab=readme-ov-file#print-page

    exactly here: https://github.com/jlipps/simple-wd-spec/pull/8