Is it possible to configure the type of printing?
dan-developer opened this issue · 3 comments
For example, leaf type, orientation, etc ...?
The create
function takes an instance of CreateOptions
:
https://github.com/westy92/html-pdf-chrome/blob/master/src/index.ts#L26
Those have a property called printOptions
:
https://github.com/westy92/html-pdf-chrome/blob/master/src/CreateOptions.ts#L54-L61
printOptions
is an instance of PrintToPDFOptions
, which should have the options you're looking for!
https://github.com/westy92/html-pdf-chrome/blob/master/src/typings/chrome/Page/PrintToPDFOptions.ts
In summary, you should be able to do something like this:
import * as htmlPdf from 'html-pdf-chrome';
const html = '<p>Hello, world!</p>';
const options: htmlPdf.CreateOptions = {
port: 9222, // port Chrome is listening on
printOptions: {
landscape: true,
paperWidth: 4, // inches
paperHeight: 3 // inches
}
};
const pdf = await htmlPdf.create(html, options);
Thank you.
For the record, the full list of properties can be seen here: https://github.com/ChromeDevTools/devtools-protocol/blob/28c241dc86c3847ef346e1481996dafd62446d27/types/protocol.d.ts#L12342 (the line numbers might change, but you can search that file for export interface PrintToPDFRequest
).