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

Can I convert a remote docx (on s3) to PDF? #14

Closed
shaharsol opened this issue May 26, 2020 · 5 comments
Closed

Can I convert a remote docx (on s3) to PDF? #14

shaharsol opened this issue May 26, 2020 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@shaharsol
Copy link

Not sure what the syntax would be.

I try

    const signedUrl = await this.getSignedURL(bucket, docxKey);
    console.log('signed url: ', signedUrl);
    const toPDF = pipe(
      gotenberg('http://localhost:8008'),
      convert,
      url,
      office,
      set(filename('result.pdf')),
      please
    )

    const pdfStream = await toPDF(signedUrl);

and I always get 404 from Gotenberg as if it wasn't able to fetch the signed url tough it is accessible from curl or browser.

@yumauri
Copy link
Owner

yumauri commented May 26, 2020

I think, Gotenberg doesn't support this, unfortunately :( You can ask for feature here, but for now, as I see, remote URL is considered HTML.

URL conversions work the same as HTML conversions.

For now, I guess, the only way is to download document and send it to Gotenberg as a file.

@yumauri
Copy link
Owner

yumauri commented May 26, 2020

(You don't have to save document to the filesystem, if you don't want to — you can use Buffer or ReadableStream)

@yumauri
Copy link
Owner

yumauri commented May 26, 2020

BTW to clarify, why you get 404:

Functions like convert, url, office, aside from setting conversion type, appends URL parts to the base Gotenberg URL, so in case of

const toPDF = pipe(
  gotenberg('http://localhost:8008'),
  convert,
  url,
  office,
  set(filename('result.pdf')),
  please
)

you get URL

http://localhost:8008/convert/url/office

and this is not a valid Gotenberg endpoint, of course.

Not sure, should I handle such cases in my client somehow, or not... I'll think on it

@yumauri yumauri added the enhancement New feature or request label May 26, 2020
@yumauri yumauri self-assigned this May 26, 2020
@yumauri
Copy link
Owner

yumauri commented May 30, 2020

I've added few lines to README file, with example of streaming downloaded file to Gotenberg, without saving it to the disk.

// you can create this function as a static class field or module local variable,
// there is no need to create it anew for each conversion
const toPDF = pipe(
  gotenberg('http://localhost:8008'),
  convert,
  office,
  please
)

// --- 8< ---

const signedUrl = await this.getSignedURL(bucket, docxKey)

// I assume s3 uses HTTPS:
// import https from 'https'
https.get(signedUrl, async (document) => {
  const pdfStream = await toPDF({ 'document.docx': document })
  // ...
})

I'll leave this issue open for a while, though, because I want to think about handling issues, when you specify multiple conversion types (which is incorrect and should throw an exception).

yumauri added a commit that referenced this issue May 30, 2020
@yumauri
Copy link
Owner

yumauri commented May 30, 2020

Published new version 0.6.1

It will throw error

Cannot set "Office" conversion, already set to "Url"

For your op code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants