[英]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.