小编Ris*_*nto的帖子

如何使用 selenium python 打印 PDF 横向

我已经成功地使用上面的脚本打印和下载了 pdf,但是我在如何在 LANDSCAPE 模式输出中使用 selenium python 打印/下载 pdf 时遇到了问题。

我尝试将 pdfkit 与“fromstring”和硒“driver.getsource”一起使用,但纵向模式效果不佳,最后我选择使用来自 chromedriver 的打印 PDF 并成功制作了我想要的 PDF 文件,但效果很好只停留在纵向模式。即使我需要的是横向模式

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select

import time
import pdfkit
import json
import os

curr_dir = os.getcwd()
download_path = os.path.join(curr_dir, 'dl')
appState = {
    "recentDestinations": [
        {
            "id": "Save as PDF",
            "origin": "local"
        }
    ],
    "selectedDestinationId": "Save as PDF",
    "version": 2,
}

profile = {
    'printing.print_preview_sticky_settings.appState': json.dumps(appState),
    'savefile.default_directory': download_path,
}

chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('prefs', profile)
chrome_options.add_argument('--kiosk-printing') …
Run Code Online (Sandbox Code Playgroud)

python printing selenium landscape

5
推荐指数
1
解决办法
1325
查看次数

标签 统计

landscape ×1

printing ×1

python ×1

selenium ×1