Reputation: 2251
I have a chrome extension running locally. I would like it to "print-to-pdf" active page in a chrome tab programmatically and save to local drive (or upload to Google Drive).
Currently I was able to achieve only this:
saveAsMHTML
using
chrome.pageCapture.saveAsMHTML
API chrome.downloads.download
API to my local drive.How can I convert mHTML into pdf? Is there a javascript library? Or a command line too that I could run on my Mac?
Any solution would work, not planning to publish this extension, just for my own needs, so not concerned about security, etc.
Upvotes: 1
Views: 1344
Reputation: 73506
There are two "print-to-PDF" methods you can use in an extension.
Use window.print()
in the content script to display a dialog where you can print to PDF.
Use chrome.debugger API and emit a remote debugging protocol command Page.printToPDF.
Upvotes: 3