Help us shape the future of Go! Take the 2026 Go Developer Survey

pdfserver

package module
v0.0.0-...-4745b2a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 7 Imported by: 0

README

pdfserver

API

Name Value
Method POST
Path /
Content-Type application/json

Body

Name Type Desc Default Example
content string HTML for render to pdf <h1>PDF Server</h1>
scale number Print scale 1.0 1.0
paper PaperSize Paper size A4
margin Margin or number Margin 0.4
background boolean Print Background true false
pageRanges string Page ranges "1-4,7"
header string Header template <span></span>
footer string Footer template <span></span>
cssPageSize boolean Use CSS page size false
landscape boolean Landscape false
wait number Wait time in milliseconds 1000
PaperSize
Name Type
width number
height number
Margin
Name Type
top number
right number
bottom number
left number

Example

POST / HTTP/1.1
Content-Type: application/json; charset=utf-8

{"content":"<h1>PDF Server</h1>","scale":1}

Usage

As a web server
# run
$ go run ./cmd/pdfserver

# generate pdf
$ http :8080 content="<h1>PDF Server</h1>" scale:=1 > file.pdf

Env

Name Desc Default
PORT HTTP Port 8080
CONCURRENT Max Concurrent 5

Build

$ make build
# or
$ go build -o pdfserver .

Docker

$ docker build -t IMAGE .

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintHTML

func PrintHTML(ctx context.Context, w io.Writer, r HTMLRequest) error

Types

type HTMLRequest

type HTMLRequest struct {
	Content     string     `json:"content"`
	Scale       float64    `json:"scale"`
	Paper       *PaperSize `json:"paper"`
	Margin      *Margin    `json:"margin"`
	Background  *bool      `json:"background"`
	PageRanges  string     `json:"pageRanges"`
	Header      string     `json:"header"`
	Footer      string     `json:"footer"`
	CSSPageSize bool       `json:"cssPageSize"`
	Landscape   bool       `json:"landscape"`
	Wait        *int       `json:"wait"`
}

type Margin

type Margin struct {
	Top    float64 `json:"top"`
	Right  float64 `json:"right"`
	Bottom float64 `json:"bottom"`
	Left   float64 `json:"left"`
}

func (*Margin) UnmarshalJSON

func (m *Margin) UnmarshalJSON(data []byte) error

func (*Margin) UnmarshalJSONFloat64

func (m *Margin) UnmarshalJSONFloat64(data []byte) error

func (*Margin) UnmarshalJSONStruct

func (m *Margin) UnmarshalJSONStruct(data []byte) error

type PaperSize

type PaperSize struct {
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
}

Directories

Path Synopsis
cmd
pdfserver command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL