Sergei Ledvanov
Sergei Ledvanov

Reputation: 2251

How to convert mHTML to pdf in chrome extension?

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:

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

Answers (1)

woxxom
woxxom

Reputation: 73506

There are two "print-to-PDF" methods you can use in an extension.

Interactive

Use window.print() in the content script to display a dialog where you can print to PDF.

Silent

Use chrome.debugger API and emit a remote debugging protocol command Page.printToPDF.

Upvotes: 3

Related Questions