func convertHTMLRoute(chromium API, engine gotenberg.PDFEngine) api.Route {
	return api.Route{
		Method:      http.MethodPost,
		Path:        "/forms/chromium/convert/html",
		IsMultipart: true,
		Handler: func(c echo.Context) error {
			ctx := c.Get("context").(*api.Context)
			form, options := FormDataChromiumPDFOptions(ctx)
			var (
				inputPath string
				PDFformat string
			)
			err := form.
				MandatoryPath("index.html", &inputPath).
				String("pdfFormat", &PDFformat, "").
				Validate()
			if err != nil {
				return fmt.Errorf("validate form data: %w", err)
			}
			URL := fmt.Sprintf("file://%s", inputPath)
			err = convertURL(ctx, chromium, engine, URL, PDFformat, options)
			if err != nil {
				return fmt.Errorf("convert HTML to PDF: %w", err)
			}
			return nil
		},
	}
}
convertHTMLRoute returns an api.Route which can convert an HTML file to PDF.
package chromium
import (
	"bytes"
	"encoding/json"
	"errors"
	"fmt"
	"html/template"
	"io/ioutil"
	"net/http"
	"os"
	"path/filepath"
	"time"
	"github.com/gotenberg/gotenberg/v7/pkg/gotenberg"
	"github.com/gotenberg/gotenberg/v7/pkg/modules/api"
	"github.com/labstack/echo/v4"
	"github.com/microcosm-cc/bluemonday"
	"github.com/russross/blackfriday/v2"
	"go.uber.org/multierr"
)
func FormDataChromiumPDFOptions(ctx *api.Context) (*api.FormData, Options) {
	defaultOptions := DefaultOptions()
	var (
		waitDelay                                        time.Duration
		waitWindowStatus                                 string
		extraHTTPHeaders                                 map[string]string
		landscape, printBackground                       bool
		scale, paperWidth, paperHeight                   float64
		marginTop, marginBottom, marginLeft, marginRight float64
		pageRanges                                       string
		headerTemplate, footerTemplate                   string
		preferCSSPageSize                                bool
	)
	form := ctx.FormData().
		Duration("waitDelay", &waitDelay, defaultOptions.WaitDelay).
		String("waitWindowStatus", &waitWindowStatus, defaultOptions.WaitWindowStatus).
		Custom("extraHttpHeaders", func(value string) error {
			if value == "" {
				extraHTTPHeaders = defaultOptions.ExtraHTTPHeaders
				return nil
			}
			err := json.Unmarshal([]byte(value), &extraHTTPHeaders)
			if err != nil {
				return fmt.Errorf("unmarshal extra HTTP headers: %w", err)
			}
			return nil
		}).
		Bool("landscape", &landscape, defaultOptions.Landscape).
		Bool("printBackground", &printBackground, defaultOptions.PrintBackground).
		Float64("scale", &scale, defaultOptions.Scale).
		Float64("paperWidth", &paperWidth, defaultOptions.PaperWidth).
		Float64("paperHeight", &paperHeight, defaultOptions.PaperHeight).
		Float64("marginTop", &marginTop, defaultOptions.MarginTop).
		Float64("marginBottom", &marginBottom, defaultOptions.MarginBottom).
		Float64("marginLeft", &marginLeft, defaultOptions.MarginLeft).
		Float64("marginRight", &marginRight, defaultOptions.MarginRight).
		String("nativePageRanges", &pageRanges, defaultOptions.PageRanges).
		Content("header.html", &headerTemplate, defaultOptions.HeaderTemplate).
		Content("footer.html", &footerTemplate, defaultOptions.FooterTemplate).
		Bool("preferCssPageSize", &preferCSSPageSize, defaultOptions.PreferCSSPageSize)
	options := Options{
		WaitDelay:         waitDelay,
		WaitWindowStatus:  waitWindowStatus,
		ExtraHTTPHeaders:  extraHTTPHeaders,
		Landscape:         landscape,
		PrintBackground:   printBackground,
		Scale:             scale,
		PaperWidth:        paperWidth,
		PaperHeight:       paperHeight,
		MarginTop:         marginTop,
		MarginBottom:      marginBottom,
		MarginLeft:        marginLeft,
		MarginRight:       marginRight,
		PageRanges:        pageRanges,
		HeaderTemplate:    headerTemplate,
		FooterTemplate:    footerTemplate,
		PreferCSSPageSize: preferCSSPageSize,
	}
	return form, options
}
func convertURLRoute(chromium API, engine gotenberg.PDFEngine) api.Route {
	return api.Route{
		Method:      http.MethodPost,
		Path:        "/forms/chromium/convert/url",
		IsMultipart: true,
		Handler: func(c echo.Context) error {
			ctx := c.Get("context").(*api.Context)
			form, options := FormDataChromiumPDFOptions(ctx)
			var (
				URL       string
				PDFformat string
			)
			err := form.
				MandatoryString("url", &URL).
				String("pdfFormat", &PDFformat, "").
				Validate()
			if err != nil {
				return fmt.Errorf("validate form data: %w", err)
			}
			err = convertURL(ctx, chromium, engine, URL, PDFformat, options)
			if err != nil {
				return fmt.Errorf("convert URL to PDF: %w", err)
			}
			return nil
		},
	}
}