yumauri / gotenberg-js-client

A simple JS/TS client for interacting with a Gotenberg API
MIT License
111 stars 9 forks source link

url to pdf conversion bad request #62

Closed ogolan-ig closed 11 months ago

ogolan-ig commented 11 months ago

hi, im using version 0.7.4 and im trying to use the gotenberg demo to a conversion.

itl works with postman :curl --location 'https://demo.gotenberg.dev/forms/libreoffice/convert' \ --form 'files=@"/myFile.docx"'

however i could not make it work using gotenberg-js-client, what am i doing wrong? i keep getting status 404

const { pipe, gotenberg, adjust, add, header, convert, office, url, to, landscape, set, filename, please, } = require('gotenberg-js-client');

async function officeToPdf() { const toPDF = pipe( gotenberg(https://demo.gotenberg.dev/forms/chromium), convert, office, please, )

const res = await toPDF('file://myfile.docx');

return res;

}

yumauri commented 11 months ago

Hello!

For URL conversion you should use it like this:

const pdfFromUrl = pipe(
  gotenberg(`https://demo.gotenberg.dev/forms/chromium`),
  convert,
  url,
  to({ margins: [0, 0, 0, 0] }), // it is better to remove margins with URL conversion
  (request) => {
    request.fields.url = request.fields.remoteURL
    delete request.fields.remoteURL
    return request
  },
  please,
)
return pdfFromUrl(`http://www.google.com`)

For office like this:

pipe(
  gotenberg(''), // any string here, will be overridden
  convert, // it is save to remove this line, if you want
  office,
  adjust({
    // manually adjust endpoint
    url: 'https://demo.gotenberg.dev/forms/libreoffice/convert',
  }),
  please
)

Sorry for inconvenience, I still didn't find a time to update library for latest Gotenberg version ._.

ogolan-ig commented 11 months ago

thank you for the quick respone, now it works