Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling printBackground for html to PDF conversion? #33

Closed
ghost opened this issue Aug 27, 2021 · 4 comments
Closed

Enabling printBackground for html to PDF conversion? #33

ghost opened this issue Aug 27, 2021 · 4 comments

Comments

@ghost
Copy link

ghost commented Aug 27, 2021

I would like to enable the printBackground option when creating a PDF with HTML. In Gotenberg's documentation, we can pass a param in the form data to enable this: https://gotenberg.dev/docs/modules/chromium
How can i do the same with gotenberg-js-client?

@ghost
Copy link
Author

ghost commented Aug 27, 2021

This is how to do it:

  const toPDF = pipe(
    gotenberg(url),
    convert,
    html,
    adjust({
      fields: {
        printBackground: true,
      },
    }),
    please
  );

however, the typings are not updated for this yet.

Type '{ printBackground: true; }' is not assignable to type 'RequestFields'.
  Object literal may only specify known properties, and 'printBackground' does not exist in type 'RequestFields'.

@ghost ghost closed this as completed Aug 27, 2021
@yumauri
Copy link
Owner

yumauri commented Aug 27, 2021

Hello!

Gotenberg:7 was released 5 days ago, and this library is not yet compatible with it. There is an issue for that.

It is possible to manually adjust request, as you already figured that out :) This doesn't looks good, though, I know...

const toPDF = pipe(
  gotenberg(''),
  convert, // it is save to remove this line, if you want
  html,
  adjust({
    // manually adjust endpoint, because
    // gotenberg:7 has different conversion endpoints
    url: 'http://localhost:3500/forms/chromium/convert/html',

    // manually adjust for fields
    fields: {
      printBackground: true,
      // `printBackground` is not valid field for gotenberg:6
      // so we have to cast to any, otherwise typescript will complain
    } as any,
  }),
  please
)

I've tested, and this works fine.

@yumauri
Copy link
Owner

yumauri commented Aug 27, 2021

Oh, you don't have to adjust URL if you add /forms/chromium to gotenberg function argument:

pipe(
  //         / gotenberg url:port \
  gotenberg('http://localhost:3500/forms/chromium'),
  convert,
  html,
  adjust({
    fields: {
      printBackground: true,
    } as any,
  }),
  please
)

@ghost
Copy link
Author

ghost commented Aug 27, 2021

Thanks @yumauri! This library is really good - thank you.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant