PejmanNik/puppeteer-report

puppeteer-report does not take into account the scale attribute

ELOUFIR opened this issue · 4 comments

Hi
First, thank you for this module. I pass the scale attribute to report.pdfPage(page, options) but it always use the original height of my header instead of multiple it by the scale that I provided.

I manage to fix that in my local by editing the pdfPage function to this :

async function pdfPage(page: Page, options?: PDFOptions): Promise<Uint8Array> {
  const { path, ...pdfOptions } = options ?? {};
  const margin = {
    marginTop: pdfOptions?.margin?.top ?? 0,
    marginBottom: pdfOptions?.margin?.bottom ?? 0,
  };

  const [getHeightFunc, getHeightArg] = core.getHeightEvaluator(
    margin.marginTop,
    margin.marginBottom
  );
-* const { headerHeight, footerHeight } = await page.evaluate(
+* let { headerHeight, footerHeight } = await page.evaluate(
    getHeightFunc,
    getHeightArg
  );
  
+*  if (pdfOptions?.scale) {
+*   headerHeight *= pdfOptions.scale;
+*   footerHeight *= pdfOptions.scale;
+*  }

Greetings

Hi, Thank you. Yes, you are right It doesn't support scale.
Thank you for the modification. Can you please send it as a PR?

DONE @PejmanNik .

@PejmanNik Would you mind publishing a release with this fix please?