-
Notifications
You must be signed in to change notification settings - Fork 9
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
using Buffer is undocumented, and not easy to find how to use #5
Comments
Hi, @thib3113! There is no way to know filename from const pdf = await toPDF('<html>...</html>') (I presume, that converting HTMLs is more frequent task, than converting DOCs) There are few ways to define filename, they are mentioned here in example, but you are right, description is not very, well, specific... In your case you can use any of this: // like tuple, as you already know
const pdf = await toPDF(['myDoc.docx', myBuffer])
// like object, where keys are filenames
const pdf = await toPDF({ 'myDoc.docx': myBuffer })
// using file link, fs.ReadStream will be used internally
// in that case you don't need variable myBuffer
const pdf = await toPDF({ 'myDoc.docx': 'file://myDoc.docx' })
// using file link without specifying filename
// fs.ReadStream will be used internally, and will get filename from file link
// in that case you don't need variable myBuffer also
const pdf = await toPDF('file://myDoc.docx')
// using fs.ReadStream directly
// filename will be retrieved from file stream
const pdf = await toPDF(fs.createReadStream('myDoc.docx')) Library will try to figure out, what kind of format you are using :) |
I will think, maybe, I'll add some heuristic, and if filename is not defined (and cannot be determined), and source doesn't look like HTML — throw an exception, as you suggested |
In my case, the buffer come from an http request ... So, can't use About the index.html, you need to pass a function in the pipe, to set if you want to convert HTML to PDF, or OFFICE to PDF, you can maybe use it ? If function to convert to office is used, and filename can't be retrieve, throw an exception . |
You are right, no need for heuristic, because I already know, what I want to convert :) |
great :) so, thank you for the lib :) . |
Published version 0.4.2 just now, added some sources validations: If you'll try to convert Office document with default filename (
If you will try to convert HTML (or Markdown) without
If you will add two assets with same name, it will throw exception
Also, to native client I've added passing messages from Gotenberg itself, in case of error, for example, if you will pass asset
By the way, you can implement your own client, for example, based on request library, but this is also undocumented, though 😅 |
I think I'll leave this issue opened until I add more lengthy description for sources in documentation |
@thib3113 can you check this out, please? Does this look good enough? |
yes, seems great :) . We can easily understand how to "name" the buffer, or string, or else . Maybe add a link in the readme ;) . |
It's seems this :
Doesn't work, because the file name send to gotenberg is 'index.html' ...
After some debug, I found a solution :
But it's either undocumented, and maybe need to throw an exception if the fileName is not retrievable with the argument (Buffer, stream ...) ...
The text was updated successfully, but these errors were encountered: