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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

抓取精选文件过多导致pdfkit生成不了pdf文件 #1

Open
xingstarx opened this issue May 10, 2019 · 1 comment
Open

抓取精选文件过多导致pdfkit生成不了pdf文件 #1

xingstarx opened this issue May 10, 2019 · 1 comment

Comments

@xingstarx
Copy link
Owner

def make_pdf():
    html_files = []
    for index, html in enumerate(range(0, 400)):
        file = str(index) + ".html"
        html_files.append(file)
        

    options = {
        "user-style-sheet": "test.css",
        "page-size": "Letter",
        "margin-top": "0.75in",
        "margin-right": "0.75in",
        "margin-bottom": "0.75in",
        "margin-left": "0.75in",
        "encoding": "UTF-8",
        "custom-header": [("Accept-Encoding", "gzip")],
        "cookie": [
            ("cookie-name1", "cookie-value1"), ("cookie-name2", "cookie-value2")
        ],
        "outline-depth": 10,
    }
    try:
        pdfkit.from_file(html_files, "xxx电子书.pdf", options=options)
    except Exception as e:
        pass

    for file in html_files:
        os.remove(file)

    print("已制作电子书在当前目录!")
@xingstarx
Copy link
Owner Author

可以考虑先获取所有的html文件,然后生成多个pdf文件(xxx-1.pdf, xxx-2.pdf类似这样的),那么我们就可以考虑修改make_pdf的方法了,在内部记得修改为上面的代码(很简单的,for循环), for index, html in enumerate(range(0, 400)): 类似这种,自己控制文件的起始序号到结束序号。然后执行程序即可。

if __name__ == '__main__':
    make_pdf()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant