mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-08 16:42:15 +01:00
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package api
|
|
|
|
import (
|
|
"github.com/labstack/echo"
|
|
"github.com/thecodingmachine/gotenberg/internal/pkg/printer"
|
|
)
|
|
|
|
func convertHTML(c echo.Context) error {
|
|
r, err := newResource(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer r.removeAll()
|
|
ctx, cancel := newContext(r)
|
|
if cancel != nil {
|
|
defer cancel()
|
|
}
|
|
p := &printer.HTML{Context: ctx}
|
|
indexPath, err := r.filePath("index.html")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
p.WithLocalURL(indexPath)
|
|
headerPath, _ := r.filePath("header.html")
|
|
if err := p.WithHeaderFile(headerPath); err != nil {
|
|
return err
|
|
}
|
|
footerPath, _ := r.filePath("footer.html")
|
|
if err := p.WithFooterFile(footerPath); err != nil {
|
|
return err
|
|
}
|
|
paperSize, err := r.paperSize()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
p.PaperWidth = paperSize[0]
|
|
p.PaperHeight = paperSize[1]
|
|
paperMargins, err := r.paperMargins()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
p.MarginTop = paperMargins[0]
|
|
p.MarginBottom = paperMargins[1]
|
|
p.MarginLeft = paperMargins[2]
|
|
p.MarginRight = paperMargins[3]
|
|
landscape, err := r.landscape()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
p.Landscape = landscape
|
|
return print(c, p, r)
|
|
}
|