Skip to content

Commit

Permalink
feat: Add url to every Printer event
Browse files Browse the repository at this point in the history
Release-As: 0.1.0
  • Loading branch information
nzakas committed Apr 8, 2022
1 parent c628609 commit 4b8240c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/printer.js
Expand Up @@ -123,7 +123,7 @@ export class Printer extends EventEmitter {
*/
async printFileToPdf(filePath) {
const fullFilePath = path.resolve(this.cwd, filePath);
const fileUrl = pathToFileURL(fullFilePath);
const fileUrl = pathToFileURL(fullFilePath).href;

return this.printUrlToPdf(fileUrl);
}
Expand Down Expand Up @@ -161,15 +161,16 @@ export class Printer extends EventEmitter {
* difficult to debug.
*/
await page.exposeFunction("onSize", size => {
this.emit("size", { size });
this.emit("size", { url, size });
});

await page.exposeFunction("onPage", (page) => {
this.emit("page", { page });
this.emit("page", { url, page });
});

await page.exposeFunction("onRendered", (msg, operation) => {
this.emit("renderend", {
url,
message: msg,
operation
});
Expand All @@ -181,7 +182,7 @@ export class Printer extends EventEmitter {
* so in the next step it can be converted to a PDF.
*/

this.emit("renderstart");
this.emit("renderstart", { url });

await page.evaluate(async () => {
let done;
Expand Down Expand Up @@ -243,9 +244,9 @@ export class Printer extends EventEmitter {
await page.waitForSelector(".pagedjs_pages");

// generate the PDF
this.emit("pdfstart");
this.emit("pdfstart", { url });
const blob = await page.pdf(createPdfOptions());
this.emit("pdfend");
this.emit("pdfend", { url });

// cleanup
await page.close();
Expand Down

0 comments on commit 4b8240c

Please sign in to comment.