Documentation ¶
Index ¶
- Variables
- func Convert(ctx context.Context, w io.Writer, options *ConversionOptions) error
- func ConvertHTML(ctx context.Context, w io.Writer, options *ConversionOptions) error
- func ConvertURL(ctx context.Context, w io.Writer, options *ConversionOptions) error
- func Merge(ctx context.Context, w io.Writer, options *MergeOptions) error
- type ConversionOptions
- type Media
- type MergeOptions
- type ParseError
- type WatermarkConfig
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidJSON is a JSON syntax error. ErrInvalidJSON = errors.New("the json request is malformed") // ErrNoSource states that the options neither have an HTML string nor a URL. ErrNoSource = errors.New("no url or html provided") )
var ( // MediaScreen is the CSS "screen" media. MediaScreen = Media("screen") // MediaPrint is the CSS "print" media. MediaPrint = Media("print") )
var ( // ErrTimeout is returned when the conversion times out. ErrTimeout = errors.New("conversion timed out") // ErrWaitUntilTimeout is returned when the Chrome DevTools times out while waiting for the "load" or "DOMContentLoaded" event. ErrWaitUntilTimeout = errors.New("WaitUntil timed out") // ErrNoBody is returned when the page has no 'body' element. ErrNoBody = errors.New("page has no 'body' element") )
var PaperFormats = map[string]struct { Width float64 Height float64 }{ "letter": { Width: 8.5, Height: 11, }, "legal": { Width: 8.5, Height: 14, }, "tabloid": { Width: 11, Height: 17, }, "ledger": { Width: 17, Height: 11, }, "a0": { Width: 33.1, Height: 46.8, }, "a1": { Width: 23.4, Height: 33.1, }, "a2": { Width: 16.54, Height: 23.4, }, "a3": { Width: 11.7, Height: 16.54, }, "a4": { Width: 8.27, Height: 11.7, }, "a5": { Width: 5.83, Height: 8.27, }, "a6": { Width: 4.13, Height: 5.83, }, }
PaperFormats are the available paper formats.
var UnitToPixels = map[string]float64{
"px": 1,
"in": 96,
"cm": 37.8,
"mm": 3.78,
}
UnitToPixels contains the to-pixel-ratios for the different units.
Functions ¶
func ConvertHTML ¶
ConvertHTML creates a PDF from an HTML string.
func ConvertURL ¶
ConvertURL creates a PDF from a URL.
Types ¶
type ConversionOptions ¶
type ConversionOptions struct { HTML string URL string PDFParams *page.PrintToPDFParams `json:"pdfParams"` ViewportWidth int64 ViewportHeight int64 BlockAds bool Selector string WaitForSelector string WaitForSelectorTimeout time.Duration WaitUntil string WaitUntilTimeout time.Duration Delay time.Duration Timeout time.Duration Headers map[string]interface{} EmulateMedia Media OwnerPassword string UserPassword string Watermark *WatermarkConfig }
ConversionOptions are the conversion options.
func NewConversionOptions ¶
func NewConversionOptions() *ConversionOptions
NewConversionOptions returns new converter options with default values.
func NewConversionOptionsFromJSON ¶
func NewConversionOptionsFromJSON(r io.Reader) (*ConversionOptions, error)
NewConversionOptionsFromJSON returns new converter options from JSON.
func NewConversionOptionsFromJSONString ¶
func NewConversionOptionsFromJSONString(json string) (*ConversionOptions, error)
NewConversionOptionsFromJSONString returns new converter options from JSON.
type MergeOptions ¶
type MergeOptions struct { Documents []*ConversionOptions OwnerPassword string UserPassword string Watermark *WatermarkConfig }
MergeOptions are the merge options.
func NewMergeOptions ¶
func NewMergeOptions() *MergeOptions
NewMergeOptions returns new merge options.
func NewMergeOptionsFromJSON ¶
func NewMergeOptionsFromJSON(r io.Reader) (*MergeOptions, error)
NewMergeOptionsFromJSON returns new merge options from JSON.
func NewMergeOptionsFromJSONString ¶
func NewMergeOptionsFromJSONString(json string) (*MergeOptions, error)
NewMergeOptionsFromJSONString returns new merge options from JSON.
type ParseError ¶
type ParseError struct { Key string Value interface{} }
ParseError is returned when a PDF parameter cannot be parsed from a request body.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type WatermarkConfig ¶ added in v1.1.0
WatermarkConfig is the pdfcpu watermark configuration.