Open soullivaneuh opened 4 years ago
Hello!
Never heard about polka
(this one, right?), I'll check it out, thank you :)
Can you explain what do you mean by "bind this client to a express server"?
There is example in README, how you can send PDF file to client from Express server:
app.get('/pdf', function(req, res) {
//...
pdf.pipe(res)
})
And I don't quite understand, what is "wrap the renderd html on a pdf file"?
Can you explain step-by-step, how do you see it, please?
Thanks for the quick reply!
Oh right, the express example should match as polka is based on express. :+1:
And I don't quite understand, what is "wrap the renderd html on a pdf file"?
I have this link: /posts/1
that renders the html page.
I would like /posts/1.pdf
to render the pdf version of the page.
I also use Sapper middleware and I'm quite confuse about how I should make this working. :thinking:
I've never used Sapper, so I made a quick investigation.
I guess you can add your own middleware, right before sapper.middleware()
, and intercept all requests to *.pdf
.
But I cannot tell, how to return PDF from Sapper middleware... As far as I can tell from its source code — it never calls next()
in case of matching page, so any middleware after sapper.middleware()
will not be executed. I tried to replace res.end
, but without success. It is possible to get page HTML content, but I don't know, how to replace response with PDF :(
Here is what I tried, you can dig in that direction, maybe you will succeed:
https://pastebin.com/NB7HdfHQ (this is file src/server.js
)
Hah! I made it with a little kinda hack — immediately replace res.end
function back, when it is called, so it will not go recursive: https://pastebin.com/ETxkTG4n
To have styles, you should also add them to gotenberg, as sources. Looks like sapper generates them dynamically, so, this is whole another task to get links to styles from HTML content, and add those styles to gotenberg.
And I doubt it should be documented, this is quite specific use case, in my opinion...
Wow, I'm impress by your POC! I'll look at that and try my integration ASAP! Thanks a lot! :+1:
And I doubt it should be documented, this is quite specific use case, in my opinion...
Maybe not directly on the README, but maybe a cookbook section? I would enjoy to add my contribution if I manage to make something right with this method. :wink:
Is your project open source? I think I can add links to projects, which are using this library, somewhere...
Unfortunately, not this one.
Your PasteBin works great, but it's a lot of setup just to convert a page to a4 pdf format.
Don't you think some parts of your script may be provided by your library? :thinking:
The goal would be to simplify the integration, and make the users happier. :+1:
Hm.
There are only 13 rows, related to PDF converting (including import
) in the whole pastebin example.
I can think of something like Gotenberg Express middleware, which will convert responses to PDF on the fly, but this definitely should be external package. Which could use my library :)
I don't think this should be in this client, I like Unix philosophy, when one tool do one thing and do it well :)
But I'll mark this idea with middleware in my list :) And you are welcome to implement this package ahead of me ;)
Subject
It would be useful to have one example of how to bind this client to a polka and/or express server.
A complete example with a url extension matching
.pdf
would be enough for a good demo.Concrete case
I use the Sapper framework which has ssr rendering.
I can create a
.pdf.svelte
route with html rendering.I would like to match this kind of route to wrap the renderd html on a pdf file.