Search code examples
pythonpython-2.7pdfkit

python pdfkit preserve datetimestamp


I am using pdfkit library in python to convert html files to pdf. The code is as follows:

import pdfkit

pdfkit.from_file("test.html", "test.pdf")

Now the date modified/created for "test.pdf" will be the time I ran the Python script.

Is there a way to make the date modified for "test.pdf" the same as "test.html"?


Solution

  • you need something like this:

    import os
    s = os.stat("test.html")
    os.utime("test.pdf", (s.st_atime, s.st_mtime))