- Create PDF file based on the directory that contains HTML along with CSS, JavaScript and Images.
- Create PDF file based on the external web link.
- Define output page dimensions in metric or imperial systems.
- Define output page size based on the [ISO Paper Sizes](https://en.wikipedia.org/wiki/Paper_size#International_paper_sizes) for `A`, `B` series and a `Letter`.
- Define output page orientation.
- Define custom margin sizes for the output document.
- Injection of HTML defined document into existing PDF document.
- CLI that allows to execute HTML -> PDF conversion.
## Preparation
UniHTML is a plugin for the [UniPDF](https://github.com/unidoc/unipdf) Golang library.
It requires valid UniPDF license with the UniHTML plugin. Visit [https://unidoc.io](https://unidoc.io) to get more information.
This plugin works in a pair with the UniHTML server. It is distributed using Docker images and could be downloaded directly from the `unidoccloud/unihtml` DockerHub repository
Following example connects to the UniHTML server, reads the content of the input file and converts it using `github.com/unidoc/unipdf/v3/creator` package.
```go
package main
import (
"fmt"
"os"
"github.com/unidoc/unihtml"
"github.com/unidoc/unipdf/v3/creator"
)
func main() {
// UniHTML requires two arguments:
// - Connection path to the unihtml-server i.e.: https://localhost:8080
// - Input path for the file / directory to convert
if len(os.Args) != 3 {
fmt.Println("Err: provided invalid arguments. No UniHTML server path provided")
os.Exit(1)
}
// Establish connection with the UniHTML Server.
if err := unihtml.Connect(os.Args[1]); err != nil {
fmt.Printf("Err: Connect failed: %v\n", err)
os.Exit(1)
}
// Get new PDF Creator.
c := creator.New()
// Read the content of the simple.html file and load it to the conversion.
doc, err := unihtml.NewDocument(os.Args[2])
if err != nil {
fmt.Printf("Err: NewDocument failed: %v\n", err)
os.Exit(1)
}
// Draw the html document file in the context of the creator.
if err = c.Draw(doc); err != nil {
fmt.Printf("Err: Draw failed: %v\n", err)
os.Exit(1)
}
// Write the result file to PDF.
if err = c.WriteToFile("document.pdf"); err != nil {