简体   繁体   English

有什么方法可以将chrome无头模式制作的PDF存储在RAM中?

[英]Is there any way to store PDF made by chrome headless mode in RAM?

I'm trying to change an HTML to PDF using chrome headless mode and I'm looking for a way to store the response in RAM instead of storing it on the disk but I couldn't find a way to do that.我正在尝试使用 chrome 无头模式将 HTML 更改为PDF并且我正在寻找一种将响应存储在 RAM 中而不是将其存储在磁盘上的方法,但我找不到这样做的方法。 Is there any possible way to do that?有没有办法做到这一点?

To solve your problem, you can use tmpfs:要解决您的问题,您可以使用 tmpfs:

http://man7.org/linux/man-pages/man5/tmpfs.5.html http://man7.org/linux/man-pages/man5/tmpfs.5.html

tmpfs can mount a disk partition in RAM. tmpfs 可以在 RAM 中挂载磁盘分区。

Based on OP input - the goal is to get the content of the PDF into a program variable.基于 OP 输入 - 目标是将 PDF 的内容放入程序变量中。 There is no explicit problem limitation that will prevent using (temporary) file.没有明确的问题限制会阻止使用(临时)文件。 The process will include the following steps * Generate the pdf file * Read the content of the file into (python) variable * Remove the temp file该过程将包括以下步骤 * 生成 pdf 文件 * 将文件内容读入(python)变量 * 删除临时文件

Coded uses 'page.pdf' as temporary file, but this can be modified to place the temp file in a different location. Coded 使用“page.pdf”作为临时文件,但可以修改它以将临时文件放在不同的位置。

import os ;
url = "http://www.yahoo.com"
# Use chrome, or whatever name needed to launch chrome on your system
os.system("chromium-browser --headless --print-to-pdf=page.pdf " + url) ;
with open("page.pdf", mode='rb') as file:
    data = file.read()
# Remove the file, if needed
os.remove("page.pdf")
# Do something with data, e.g., print the size
print("file size=", len(data))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在无头模式下使用 Selenium Chrome 驱动程序打印 PDF - Printing a PDF with Selenium Chrome Driver in headless mode 带有硒的无头模式下的铬 - chrome in headless mode with selenium Chrome / Firefox在新标签页中打开PDF,并且不会以无头模式保存它(Selenium + Python) - Chrome/Firefox opens PDF in new tab and does not save it in headless mode (Selenium+Python) Selenium Chrome Webdriver 无法在带有配置文件的无头模式下工作 - Selenium Chrome Webdriver not working in headless mode with profile 在Chrome无头模式下使用Python中的Selenium实现Scrapyng AngularJS - Scrapyng AngularJS with Selenium in Python in Chrome headless mode Seleniumwire 未在 Chrome 无头模式下记录所有请求 - Seleniumwire not logging all requests in chrome headless mode 如何配置 Chrome 浏览器以无头模式运行 - How To Configure Chrome Browser To Run In Headless Mode Chrome 在没有无头模式的情况下无法运行(Ubuntu 18.04) - Chrome not running without headless mode (Ubuntu 18.04) 按 ID 查找元素在 Chrome Headless 模式下不起作用 - Find element by id not working in Chrome Headless mode “Chrome 无法访问”在非无头模式下使用 Xvfb - "Chrome not reachable" using Xvfb in non headless mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM