Automate opening HTML and printing to PDF

6,471

Solution 1

http://code.google.com/p/wkhtmltopdf/

If internet explorer is not a requirement, this is kind of an older project, but I have used it with great success. It will allow you to specify a HTML page (On the internet or on your computer) from the command line and will automatically save it to a specified PDF file or even an image. Usage information is here. http://code.google.com/p/wkhtmltopdf/wiki/Usage

Solution 2

HTML-TO-PDF batch converts HTML documents to PDF. Makes use of Internet Explorer and ABCpdf, so the results should match what you expect to see in IE.

See: http://sourceforge.net/projects/html-to-pdf/

screenshot of HTML to PDF

Share:
6,471

Related videos on Youtube

craigpatik
Author by

craigpatik

Updated on September 18, 2022

Comments

  • craigpatik
    craigpatik over 1 year

    I need a way to automate the following process in Windows 7:

    1. Open an .html file in Internet Explorer
    2. Print to PDF
    3. Save the PDF with a patterned file name (i.e., original_name_YYYY-MM-DD.pdf)

    Ideally, I could drag and drop several files or open a whole folder of files at once and a PDF would be created for each one. A command line solution is also acceptable.

    The files have to be opened in the browser because parts of the page are rendered with JavaScript on page load. In other words, if you simply right-click on the file in Explorer and choose "print", the resulting file is not the same because the JS didn't run.

    If it helps, Internet Explorer can be set as the default browser, and a PDF printer can be set as the default printer.

    • Ƭᴇcʜιᴇ007
      Ƭᴇcʜιᴇ007 almost 12 years
      What have you tried so far? Where are you getting stuck? Right now this is a list of wants, not a question. ;)
    • iglvzx
      iglvzx almost 12 years
      If you're adventurous enough, you can automate this task with AutoHotkey. I'll check back later and work this out if you haven't found a solution yet. :)
    • craigpatik
      craigpatik almost 12 years
      @techie007: I am getting stuck because the converters I've found parse the HTML themselves and I need IE7 to parse it. iglvzx: Thanks, I will try that if affinefesh's suggestion doesn't pan out.
  • iglvzx
    iglvzx almost 12 years
    Does it execute JavaScript in the process before printing? This is the main requirement for @craigpatik ...
  • iglvzx
    iglvzx almost 12 years
    Does it execute JavaScript in the process before printing? This is the main requirement for @craigpatik ...
  • DanielG
    DanielG almost 12 years
    It does. It uses webkit so it is a full featured renderer.
  • AffineMesh
    AffineMesh almost 12 years
    Yes. Note that documents are generated as soon as a page has finished loading and JavaScript animation with an initial blank state won't show up unless the rendering process is delayed.