feat: reastructure and create commands
Some checks failed
Go / build (push) Has been cancelled

This commit is contained in:
2025-09-16 21:11:14 +02:00
parent 8180b38225
commit 6f069ad97b
14 changed files with 387 additions and 5 deletions

42
internal/pdf/resource.go Normal file
View File

@@ -0,0 +1,42 @@
package pdf
import (
"context"
"io"
"net/http"
"github.com/starwalkn/gotenberg-go-client/v8"
"github.com/starwalkn/gotenberg-go-client/v8/document"
)
type Service struct {
gotenberg *gotenberg.Client
}
func New(hostname string) (service *Service, err error) {
service = &Service{}
service.gotenberg, err = gotenberg.NewClient(hostname, http.DefaultClient)
return
}
func (s *Service) HtmlToPdf(html string) (pdf io.ReadCloser, err error) {
index, err := document.FromString("index.html", html)
if err != nil {
return
}
req := gotenberg.NewHTMLRequest(index)
req.PaperSize(gotenberg.A4)
req.Margins(gotenberg.NoMargins)
// Skips the IDLE events for faster PDF conversion.
req.SkipNetworkIdleEvent(true)
req.EmulatePrintMediaType()
resp, err := s.gotenberg.Send(context.Background(), req)
if err != nil {
return
}
pdf = resp.Body
return
}