From 18666c5cfd59944530c4bbfaddff6e07c266a63a Mon Sep 17 00:00:00 2001 From: UniDoc Build Date: Sun, 9 May 2021 11:11:57 +0000 Subject: [PATCH 1/9] prepare release --- README.md | 4 +- cli/cmd/cmd.go | 71 +++++++------ cli/main.go | 2 +- client/client.go | 237 +++++++++++++++++++++++++------------------ common/common.go | 6 +- content/content.go | 50 +++++---- selector/selector.go | 18 ++++ sizes/sizes.go | 235 +++++++++++++++++++++--------------------- unihtml.go | 143 ++++++++++++++------------ 9 files changed, 426 insertions(+), 340 deletions(-) create mode 100644 selector/selector.go diff --git a/README.md b/README.md index b640e35..2aeeed8 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,12 @@ [UniDoc](https://unidoc.io) UniHTML is a [UniPDF](https://github.com/unidoc/unipdf) library plugin module with capability of extracting and converting HTML files and inject into PDF document. +For the golang documentation check: [GoDoc](https://apidocs.unidoc.io/unihtml/latest). + It requires a UniHTML Server component to work. Visit [https://unidoc.io](https://unidoc.io). [![License: UniDoc EULA](https://img.shields.io/badge/license-UniDoc%20EULA-blue)](https://unidoc.io/eula/) -[![GoDoc](https://godoc.org/github.com/unidoc/unipdf?status.svg)](https://godoc.org/github.com/unidoc/unihtml) +[![GoDoc](https://godoc.org/github.com/unidoc/unipdf?status.svg)](https://apidocs.unidoc.io/unihtml/latest/) ## Features diff --git a/cli/cmd/cmd.go b/cli/cmd/cmd.go index a0b3064..12dfa06 100644 --- a/cli/cmd/cmd.go +++ b/cli/cmd/cmd.go @@ -9,56 +9,55 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package cmd ;import (_b "context";_ea "fmt";_fg "github.com/mitchellh/go-homedir";_a "github.com/spf13/cobra";_eaf "github.com/spf13/viper";_ad "github.com/unidoc/unihtml/client";_aee "github.com/unidoc/unihtml/content";_d "github.com/unidoc/unihtml/sizes"; -_ae "github.com/unidoc/unipdf/v3/common";_e "os";_ga "path/filepath";_f "time";);type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;}; - -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. -func Execute (){if _gc :=_gaf .Execute ();_gc !=nil {_ea .Println (_gc );_e .Exit (1);};};func _fa (){if _fe !=""{_eaf .SetConfigFile (_fe );}else {_bbg ,_dc :=_fg .Dir ();if _dc !=nil {_ea .Println (_dc );_e .Exit (1);};_eaf .AddConfigPath (_bbg );_eaf .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063"); -};_eaf .AutomaticEnv ();if _bae :=_eaf .ReadInConfig ();_bae ==nil {_ea .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_eaf .ConfigFileUsed ());};};func _bc (cmd *_a .Command ,_da []string ){_gf :=_f .Now (); -if _gfe :=_eaf .BindPFlags (cmd .Flags ());_gfe !=nil {_ea .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gfe );_e .Exit (1);};if _gg :=_eaf .Unmarshal (&_c );_gg !=nil {_ea .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gg ); -_e .Exit (1);};_ff ();_bga :=_f .Now ();_dd ,_ddg :=_e .Stat (_da [0]);if _ddg !=nil {_ea .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ddg );_e .Exit (1);};if !_dd .IsDir (){if _ga .Ext (_dd .Name ())!="\u002e\u0068\u0074m\u006c"{_ea .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_da [0]); -_e .Exit (1);};};_gfb ,_ddg :=_e .OpenFile (_da [1],_e .O_CREATE |_e .O_WRONLY |_e .O_TRUNC ,0700);if _ddg !=nil {_ea .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ddg );_e .Exit (1);};defer _gfb .Close ();_be :=_ad .New (_ad .Options {HTTPS :_c .Https ,Hostname :_c .Host ,Port :_c .Port ,Prefix :_c .Prefix }); -_eeb ,_ab :=_b .WithTimeout (_b .Background (),_f .Second *10);defer _ab ();_bga =_f .Now ();var _bcf _aee .Content ;if _dd .IsDir (){_bcf ,_ddg =_aee .NewZipDirectory (_da [0]);}else {_bcf ,_ddg =_aee .NewHTMLFile (_da [0]);};if _ddg !=nil {_ea .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_ddg ); -_e .Exit (1);};_ba ,_ddg :=_ad .BuildHTMLQuery ().PaperWidth (_eafc .PaperWidth .Length ).PaperHeight (_eafc .PaperHeight .Length ).PageSize (_eafc .PageSize ).MarginTop (_eafc .MarginTop .Length ).MarginBottom (_eafc .MarginBottom .Length ).MarginLeft (_eafc .MarginLeft .Length ).MarginRight (_eafc .MarginRight .Length ).Orientation (_eafc .Orientation ).SetContent (_bcf ).Query (); -if _ddg !=nil {_ea .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ddg );_e .Exit (1);};_gag ,_ddg :=_be .ConvertHTML (_eeb ,_ba );if _ddg !=nil {_ea .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ddg );_e .Exit (1);};_ae .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_f .Since (_bga )); -_bga =_f .Now ();_ ,_ddg =_gfb .Write (_gag .Data );if _ddg !=nil {_ea .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ddg );_e .Exit (1);};_ae .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_f .Since (_bga )); -_ea .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_f .Since (_gf ));};func init (){_gaf .AddCommand (_bb );_bb .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072"); -_bb .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); -_bb .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); -_bb .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); -_bb .Flags ().Var (&_eafc .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_bb .Flags ().Var (&_eafc .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); -_bb .Flags ().Var (&_eafc .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_bb .Flags ().Var (&_eafc .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); -_bb .Flags ().Var (&_eafc .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_bb .Flags ().Var (&_eafc .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); -_bb .Flags ().Var (&_eafc .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_bb .Flags ().Var (&_eafc .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); -};var _gaf =&_a .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; +package cmd ;import (_a "context";_c "fmt";_bf "github.com/mitchellh/go-homedir";_fc "github.com/spf13/cobra";_bb "github.com/spf13/viper";_ad "github.com/unidoc/unihtml/client";_cf "github.com/unidoc/unihtml/content";_fe "github.com/unidoc/unihtml/sizes"; +_fa "github.com/unidoc/unipdf/v3/common";_f "os";_aa "path/filepath";_b "time";);var _bd =&_fc .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_cfa ,Args :_fc .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; +func _ace (){_baf :=_fa .LogLevelInfo ;if _d {_baf =_fa .LogLevelDebug ;};if _fae {_baf =_fa .LogLevelTrace ;};_fa .Log =_fa .NewConsoleLogger (_baf );};var _gaf =&_fc .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; type parametersConfig struct{ // PaperWidth sets the width of the paper. -PaperWidth _d .LengthFlag `mapstructure:"paper-width"`; +PaperWidth _fe .LengthFlag `mapstructure:"paper-width"`; // PaperHeight is the height of the output paper. -PaperHeight _d .LengthFlag `mapstructure:"paper-height"`; +PaperHeight _fe .LengthFlag `mapstructure:"paper-height"`; // PageSize is the page size string. -PageSize _d .PageSize `mapstructure:"page-size"`; +PageSize _fe .PageSize `mapstructure:"page-size"`; // Orientation defines if the output should be in a landscape format. -Orientation _d .Orientation `mapstructure:"orientation"`; +Orientation _fe .Orientation `mapstructure:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _d .LengthFlag `mapstructure:"margin-top"`; +MarginTop _fe .LengthFlag `mapstructure:"margin-top"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _d .LengthFlag `mapstructure:"margin-bottom"`; +MarginBottom _fe .LengthFlag `mapstructure:"margin-bottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _d .LengthFlag `mapstructure:"margin-left"`; +MarginLeft _fe .LengthFlag `mapstructure:"margin-left"`; // MarginRight sets up the Right Margin for the output. -MarginRight _d .LengthFlag `mapstructure:"margin-right"`;};func _ff (){_eaa :=_ae .LogLevelInfo ;if _fd {_eaa =_ae .LogLevelDebug ;};if _ggb {_eaa =_ae .LogLevelTrace ;};_ae .Log =_ae .NewConsoleLogger (_eaa );};var (_fd ,_ggb bool ;);var _bb =&_a .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_bc ,Args :_a .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; -func init (){_a .OnInitialize (_fa );_gaf .PersistentFlags ().BoolVarP (&_fd ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065");_gaf .PersistentFlags ().BoolVarP (&_ggb ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); -_gaf .PersistentFlags ().StringVar (&_fe ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); -_gaf .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};var _fe string ;var (_c =generateConfig {}; -_eafc =parametersConfig {PaperWidth :_d .LengthFlag {Length :_d .Inch (8.5).Millimeters ()},PaperHeight :_d .LengthFlag {Length :_d .Inch (11).Millimeters ()},Orientation :_d .Portrait ,MarginTop :_d .LengthFlag {Length :_d .Millimeter (10)},MarginBottom :_d .LengthFlag {Length :_d .Millimeter (10)},MarginLeft :_d .LengthFlag {Length :_d .Millimeter (10)},MarginRight :_d .LengthFlag {Length :_d .Millimeter (10)}}; -); \ No newline at end of file +MarginRight _fe .LengthFlag `mapstructure:"margin-right"`;};func init (){_gaf .AddCommand (_bd );_bd .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072"); +_bd .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); +_bd .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); +_bd .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); +_bd .Flags ().Var (&_fea .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_bd .Flags ().Var (&_fea .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); +_bd .Flags ().Var (&_fea .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_bd .Flags ().Var (&_fea .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); +_bd .Flags ().Var (&_fea .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_bd .Flags ().Var (&_fea .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); +_bd .Flags ().Var (&_fea .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_bd .Flags ().Var (&_fea .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); +};func _bbd (){if _acb !=""{_bb .SetConfigFile (_acb );}else {_dc ,_ccd :=_bf .Dir ();if _ccd !=nil {_c .Println (_ccd );_f .Exit (1);};_bb .AddConfigPath (_dc );_bb .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063"); +};_bb .AutomaticEnv ();if _gd :=_bb .ReadInConfig ();_gd ==nil {_c .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_bb .ConfigFileUsed ());};};var _acb string ; + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute (){if _gc :=_gaf .Execute ();_gc !=nil {_c .Println (_gc );_f .Exit (1);};};type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`; +};var (_d ,_fae bool ;);func init (){_fc .OnInitialize (_bbd );_gaf .PersistentFlags ().BoolVarP (&_d ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065");_gaf .PersistentFlags ().BoolVarP (&_fae ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); +_gaf .PersistentFlags ().StringVar (&_acb ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); +_gaf .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};var (_ca =generateConfig {};_fea =parametersConfig {PaperWidth :_fe .LengthFlag {Length :_fe .Inch (8.5).Millimeters ()},PaperHeight :_fe .LengthFlag {Length :_fe .Inch (11).Millimeters ()},Orientation :_fe .Portrait ,MarginTop :_fe .LengthFlag {Length :_fe .Millimeter (10)},MarginBottom :_fe .LengthFlag {Length :_fe .Millimeter (10)},MarginLeft :_fe .LengthFlag {Length :_fe .Millimeter (10)},MarginRight :_fe .LengthFlag {Length :_fe .Millimeter (10)}}; +);func _cfa (cmd *_fc .Command ,_cc []string ){_fb :=_b .Now ();if _ff :=_bb .BindPFlags (cmd .Flags ());_ff !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ff );_f .Exit (1);};if _ga :=_bb .Unmarshal (&_ca );_ga !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ga ); +_f .Exit (1);};_ace ();_ab :=_b .Now ();_eg ,_ag :=_f .Stat (_cc [0]);if _ag !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ag );_f .Exit (1);};if !_eg .IsDir (){if _aa .Ext (_eg .Name ())!="\u002e\u0068\u0074m\u006c"{_c .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_cc [0]); +_f .Exit (1);};};_bg ,_ag :=_f .OpenFile (_cc [1],_f .O_CREATE |_f .O_WRONLY |_f .O_TRUNC ,0700);if _ag !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ag );_f .Exit (1);};defer _bg .Close ();_ba :=_ad .New (_ad .Options {HTTPS :_ca .Https ,Hostname :_ca .Host ,Port :_ca .Port ,Prefix :_ca .Prefix }); +_fee ,_gg :=_a .WithTimeout (_a .Background (),_b .Second *10);defer _gg ();_ab =_b .Now ();var _bag _cf .Content ;if _eg .IsDir (){_bag ,_ag =_cf .NewZipDirectory (_cc [0]);}else {_bag ,_ag =_cf .NewHTMLFile (_cc [0]);};if _ag !=nil {_c .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_ag ); +_f .Exit (1);};_abe ,_ag :=_ad .BuildHTMLQuery ().PaperWidth (_fea .PaperWidth .Length ).PaperHeight (_fea .PaperHeight .Length ).PageSize (_fea .PageSize ).MarginTop (_fea .MarginTop .Length ).MarginBottom (_fea .MarginBottom .Length ).MarginLeft (_fea .MarginLeft .Length ).MarginRight (_fea .MarginRight .Length ).Orientation (_fea .Orientation ).SetContent (_bag ).Query (); +if _ag !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ag );_f .Exit (1);};_be ,_ag :=_ba .ConvertHTML (_fee ,_abe );if _ag !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ag );_f .Exit (1);};_fa .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_b .Since (_ab )); +_ab =_b .Now ();_ ,_ag =_bg .Write (_be .Data );if _ag !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ag );_f .Exit (1);};_fa .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_b .Since (_ab )); +_c .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_b .Since (_fb ));}; \ No newline at end of file diff --git a/cli/main.go b/cli/main.go index 9be0d6b..f0b00cc 100644 --- a/cli/main.go +++ b/cli/main.go @@ -9,4 +9,4 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package main ;import _c "github.com/unidoc/unihtml/cli/cmd";func main (){_c .Execute ()}; \ No newline at end of file +package main ;import _g "github.com/unidoc/unihtml/cli/cmd";func main (){_g .Execute ()}; \ No newline at end of file diff --git a/client/client.go b/client/client.go index b9fa623..8ebde68 100644 --- a/client/client.go +++ b/client/client.go @@ -11,163 +11,198 @@ // Package client contains HTML Converter HTTP Client. The Client implements htmlcreator.HTMLConverter interface // for the UniPDF module and can be used as a plugin for the UniPDF creator.Creator. -package client ;import (_daa "bytes";_da "compress/flate";_ba "compress/gzip";_bd "context";_a "errors";_fa "fmt";_aa "github.com/unidoc/unihtml/content";_e "github.com/unidoc/unihtml/sizes";_ff "github.com/unidoc/unipdf/v3/common";_db "golang.org/x/xerrors"; -_d "io/ioutil";_f "net";_g "net/http";_c "net/url";_af "strconv";_deb "strings";_de "time";); +package client ;import (_bb "bytes";_fb "compress/flate";_db "compress/gzip";_d "context";_a "encoding/json";_b "errors";_eg "fmt";_dg "github.com/unidoc/unihtml/content";_bd "github.com/unidoc/unihtml/selector";_dc "github.com/unidoc/unihtml/sizes";_fe "github.com/unidoc/unipdf/v3/common"; +_ea "golang.org/x/xerrors";_f "io/ioutil";_fcf "net";_e "net/http";_fc "net/url";_bg "strconv";_c "strings";_af "time";); -// WithHTTPS sets the TLS option for the client options. -func WithHTTPS (useHTTPS bool )Option {return func (_caf *Options ){_caf .HTTPS =useHTTPS }}; +// WaitReady waits for the selector to get ready - 'loaded'. +func (_eee *QueryBuilder )WaitReady (selector string ,by _bd .ByType )*QueryBuilder {_eee ._cb .RenderParameters .WaitReady =append (_eee ._cb .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _eee ;};var (ErrNotFound =_b .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed"); +ErrBadRequest =_b .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074");ErrNotImplemented =_b .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_b .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072"); +ErrBadGateway =_b .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079");ErrUnauthorized =_b .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_b .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074"); +);type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`;Method string `json:"method"`;ExpiresAt int64 `json:"expiresAt"`;PageParameters ;RenderParameters ;}; -// Err gets the error which could occur in the query. -func (_efg *QueryBuilder )Err ()error {return _efg ._ca }; +// Validate checks validity of the selector. +func (_ee BySelector )Validate ()error {if _ee .Selector ==""{return _b .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _fca :=_ee .By .Validate ();_fca !=nil {return _fca ; +};return nil ;}; -// HealthCheck connects to the server and check the health status of the server. -func (_fe *Client )HealthCheck (ctx _bd .Context )error {_ab :=_fe .Options .Addr ();_ab =_fa .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_ab );_dd ,_ea :=_g .NewRequest ("\u0047\u0045\u0054",_ab ,nil );if _ea !=nil {return _ea ;};_dd =_dd .WithContext (ctx ); -_ed ,_ea :=_fe .Client .Do (_dd );if _ea !=nil {return _ea ;};switch _ed .StatusCode {case _g .StatusOK :return nil ;case _g .StatusNotFound :return ErrNotFound ;case _g .StatusInternalServerError :return ErrInternalError ;case _g .StatusBadGateway :return ErrBadGateway ; -default:return ErrNotImplemented ;};}; +// RenderParameters are the parameters related with the rendering. +type RenderParameters struct{WaitTime _af .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; + +// BySelector is a structure that defines a selector with it's query 'by' type. +type BySelector struct{Selector string `json:"selector"`;By _bd .ByType `json:"by"`;}; + +// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. +type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;};func (_gb *Client )setQueryValues (_ffc *_e .Request ,_ce *Query ){_afb :=_ffc .URL .Query ();_dgb :=_ce .PageParameters ; +if _dgb .PageSize !=nil {_afb .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_dgb .PageSize .String ());};if _dgb .PaperHeight !=nil {_afb .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_dgb .PaperHeight .String ());}; +if _dgb .PaperWidth !=nil {_afb .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_dgb .PaperWidth .String ());};if _dgb .MarginTop !=nil {_afb .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_dgb .MarginTop .String ()); +};if _dgb .MarginBottom !=nil {_afb .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_dgb .MarginBottom .String ());};if _dgb .MarginRight !=nil {_afb .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_dgb .MarginRight .String ()); +};if _dgb .MarginLeft !=nil {_afb .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_dgb .MarginLeft .String ());};if _dgb .Orientation ==_dc .Landscape {_afb .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_dgb .Orientation .String ()); +};if _ce .RenderParameters .WaitTime !=0{_afb .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_bg .FormatInt (int64 (_ce .RenderParameters .WaitTime /_af .Millisecond ),10));};_ffc .URL .RawQuery =_afb .Encode (); +}; // Query gets the Query from provided query builder. If some error occurred during build process // or the input is not valid the function would return an error. -func (_ee *QueryBuilder )Query ()(*Query ,error ){if _bgf :=_ee .Validate ();_bgf !=nil {return nil ,_bgf ;};return &_ee ._gfe ,nil ;}; +func (_cf *QueryBuilder )Query ()(*Query ,error ){if _da :=_cf .Validate ();_da !=nil {return nil ,_da ;};return &_cf ._cb ,nil ;}; -// ConvertHTML converts provided Query input into PDF file data. -// Implements creator.HTMLConverter interface. -func (_bg *Client )ConvertHTML (ctx _bd .Context ,q *Query )(*PDFResponse ,error ){if _ddc :=q .Validate ();_ddc !=nil {return nil ,_ddc ;};_be ,_eg :=_bg .getRequest (ctx ,q );if _eg !=nil {return nil ,_eg ;};_ff .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_be .Method ,_be .URL .Hostname (),_be .URL .Path ,_be .Header ,_be .URL .Query ()); -_ef ,_eg :=_bg .Client .Do (_be );if _eg !=nil {return nil ,_eg ;};var _bea error ;switch _ef .StatusCode {case _g .StatusNotFound :_bea =ErrNotFound ;case _g .StatusBadRequest :_bea =ErrBadRequest ;case _g .StatusNotImplemented :_bea =ErrNotImplemented ; -case _g .StatusUnauthorized :_bea =ErrUnauthorized ;case _g .StatusCreated :default:_bea =ErrInternalError ;};_dde :=_ef .Body ;switch _ef .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_dde ,_eg =_ba .NewReader (_ef .Body ); -if _eg !=nil {return nil ,_eg ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_dde =_da .NewReader (_ef .Body );case "":default:return nil ,_fa .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_ef .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); -};_aaa ,_eg :=_d .ReadAll (_dde );if _eg !=nil &&_bea ==nil {return nil ,_fa .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_eg );};_ff .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_ef .StatusCode ,_be .Method ,_be .URL .Host ,_be .URL .Path ); -if _bea !=nil {return nil ,_fa .Errorf ("\u0025\u0073\u0020%\u0077",string (_aaa ),_bea );};_afc :=_ef .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_ff .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_afc ); -return &PDFResponse {ID :_afc ,Data :_aaa },nil ;};var (ErrMissingData =_a .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061");ErrContentType =_a .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065"); -ErrContentTypeDeclared =_a .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064");); +// MarginLeft sets up the MarginLeft parameter for the query. +func (_cbf *QueryBuilder )MarginLeft (marginLeft _dc .Length )*QueryBuilder {_cbf ._cb .PageParameters .MarginLeft =marginLeft ;return _cbf ;}; -// PaperWidth sets up the PaperWidth (in cm) parameter for the query. -func (_ede *QueryBuilder )PaperWidth (paperWidth _e .Length )*QueryBuilder {_ede ._gfe .PageParameters .PaperWidth =paperWidth ;return _ede ;}; +// Client is a structure that is a HTTP client for the unihtml server. +type Client struct{Options Options ;Client *_e .Client ;}; + +// QueryBuilder is the query that converts HTMLConverter defined data +type QueryBuilder struct{_cb Query ;_gdg error ;}; // Validate checks if provided Query is valid. -func (_gg *Query )Validate ()error {if len (_gg .Data )==0{return ErrMissingData ;};if _gg .ContentType ==""{return ErrContentType ;};if _dba :=_gg .PageParameters .Validate ();_dba !=nil {return _dba ;};return nil ;}; +func (_fed *Query )Validate ()error {switch _fed .Method {case "\u0077\u0065\u0062":if _fed .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_fed .Content )==0{return ErrMissingData ;};if _fed .ContentType ==""{return ErrContentType ; +};default:return _eg .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_fed .Method );};if _be :=_fed .PageParameters .Validate (); +_be !=nil {return _be ;};if _gg :=_fed .RenderParameters .Validate ();_gg !=nil {return _gg ;};return nil ;}; -// Option is a function that changes client options. -type Option func (_bbf *Options ); +// MarginTop sets up the MarginTop parameter for the query. +func (_ccg *QueryBuilder )MarginTop (marginTop _dc .Length )*QueryBuilder {_ccg ._cb .PageParameters .MarginTop =marginTop ;return _ccg ;}; -// WithPort sets the Port option for the client options. -func WithPort (option int )Option {return func (_gafb *Options ){_gafb .Port =option }}; +// WithDefaultTimeout sets the DefaultTimeout option for the client options. +func WithDefaultTimeout (option _af .Duration )Option {return func (_dca *Options ){_dca .DefaultTimeout =option };}; + +// PaperHeight sets up the PaperHeight (in cm) parameter for the query. +func (_bc *QueryBuilder )PaperHeight (paperHeight _dc .Length )*QueryBuilder {_bc ._cb .PageParameters .PaperHeight =paperHeight ;return _bc ;}; + +// Portrait sets up the portrait page orientation. +func (_cff *QueryBuilder )Portrait ()*QueryBuilder {_cff ._cb .PageParameters .Orientation =_dc .Portrait ;return _cff ;}; // New creates new client with provided options. -func New (o Options )*Client {o .DefaultTimeout =_de .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _dac =&_g .Transport {DialContext :(&_f .Dialer {Timeout :5*_de .Second }).DialContext ,TLSHandshakeTimeout :5*_de .Second }; -_ff .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_g .Client {Transport :_dac ,Timeout :o .DefaultTimeout }};}; +func New (o Options )*Client {o .DefaultTimeout =_af .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _cde =&_e .Transport {DialContext :(&_fcf .Dialer {Timeout :5*_af .Second }).DialContext ,TLSHandshakeTimeout :5*_af .Second }; +_fe .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_e .Client {Transport :_cde ,Timeout :o .DefaultTimeout }};}; -// MarginLeft sets up the MarginLeft parameter for the query. -func (_efa *QueryBuilder )MarginLeft (marginLeft _e .Length )*QueryBuilder {_efa ._gfe .PageParameters .MarginLeft =marginLeft ;return _efa ;};var (ErrNotFound =_a .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_a .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); -ErrNotImplemented =_a .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_a .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_a .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079"); -ErrUnauthorized =_a .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");); +// PaperWidth sets up the PaperWidth (in cm) parameter for the query. +func (_cbee *QueryBuilder )PaperWidth (paperWidth _dc .Length )*QueryBuilder {_cbee ._cb .PageParameters .PaperWidth =paperWidth ;return _cbee ;}; -// Landscape sets up the landscape portrait orientation. -func (_bc *QueryBuilder )Landscape ()*QueryBuilder {_bc ._gfe .PageParameters .Orientation =_e .Landscape ;return _bc ;}; +// Addr gets the HTTP address URI used by the http.Client. +func (_dfd *Options )Addr ()string {_eab :=_c .Builder {};_eab .WriteString ("\u0068\u0074\u0074\u0070");if _dfd .HTTPS {_eab .WriteRune ('s');};_eab .WriteString ("\u003a\u002f\u002f");_eab .WriteString (_dfd .Hostname );_eab .WriteRune (':');_eab .WriteString (_bg .Itoa (_dfd .Port )); +if _dfd .Prefix !=""{_eab .WriteString (_dfd .Prefix );};return _eab .String ();}; -// Orientation sets the page orientation for the Query. -func (_ga *QueryBuilder )Orientation (orientation _e .Orientation )*QueryBuilder {_ga ._gfe .PageParameters .Orientation =orientation ;return _ga ;}; +// Option is a function that changes client options. +type Option func (_faf *Options );func (_ed *Client )getGenerateRequest (_bf _d .Context ,_ec *Query )(*_e .Request ,error ){_fg :=generatePDFRequestV1 {Method :_ec .Method ,PageParameters :_ec .PageParameters ,RenderParameters :_ec .RenderParameters }; +switch _ec .Method {case "\u0077\u0065\u0062":_fg .ContentURL =_ec .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_fg .ContentType =_ec .ContentType ;_fg .Content =_ec .Content ;};_dff :=new (_bb .Buffer );if _eda :=_a .NewEncoder (_dff ).Encode (&_fg ); +_eda !=nil {return nil ,_ea .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_eda );};_fa :=_ed .Options .Addr ();_fa =_eg .Sprintf ("%\u0073\u002f\u0062\u0065\u0074\u0061\u002f\u0070\u0064\u0066",_fa ); +_fea ,_cdca :=_e .NewRequest ("\u0050\u004f\u0053\u0054",_fa ,_dff );if _cdca !=nil {return nil ,_cdca ;};_fea .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); +_fea .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); +_fea =_fea .WithContext (_bf );return _fea ,nil ;}; -// Portrait sets up the portrait page orientation. -func (_fg *QueryBuilder )Portrait ()*QueryBuilder {_fg ._gfe .PageParameters .Orientation =_e .Portrait ;return _fg ;}; +// ConvertHTML converts provided Query input into PDF file data. +// Implements creator.HTMLConverter interface. +func (_gc *Client )ConvertHTML (ctx _d .Context ,q *Query )(*PDFResponse ,error ){if _bbe :=q .Validate ();_bbe !=nil {return nil ,_bbe ;};_gf ,_bbc :=_gc .getGenerateRequest (ctx ,q );if _bbc !=nil {return nil ,_bbc ;};_fe .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_gf .Method ,_gf .URL .Hostname (),_gf .URL .Path ,_gf .Header ,_gf .URL .Query ()); +_fd ,_bbc :=_gc .Client .Do (_gf );if _bbc !=nil {return nil ,_bbc ;};var _gfe error ;switch _fd .StatusCode {case _e .StatusNotFound :_gfe =ErrNotFound ;case _e .StatusBadRequest :_gfe =ErrBadRequest ;case _e .StatusNotImplemented :_gfe =ErrNotImplemented ; +case _e .StatusUnauthorized :_gfe =ErrUnauthorized ;case _e .StatusRequestTimeout :_gfe =ErrTimedOut ;case _e .StatusCreated :default:_gfe =ErrInternalError ;};_fbg :=_fd .Body ;switch _fd .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_fbg ,_bbc =_db .NewReader (_fd .Body ); +if _bbc !=nil {return nil ,_bbc ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_fbg =_fb .NewReader (_fd .Body );case "":default:return nil ,_eg .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_fd .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); +};_eae ,_bbc :=_f .ReadAll (_fbg );if _bbc !=nil &&_gfe ==nil {return nil ,_eg .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_bbc );};_fe .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_fd .StatusCode ,_gf .Method ,_gf .URL .Host ,_gf .URL .Path ); +if _gfe !=nil {return nil ,_eg .Errorf ("\u0025\u0073\u0020%\u0077",string (_eae ),_gfe );};_ff :=_fd .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_fe .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_ff ); +return &PDFResponse {ID :_ff ,Data :_eae },nil ;}; + +// Landscape sets up the landscape portrait orientation. +func (_ef *QueryBuilder )Landscape ()*QueryBuilder {_ef ._cb .PageParameters .Orientation =_dc .Landscape ;return _ef ;}; // WithPrefix sets the client prefix. -func WithPrefix (prefix string )Option {return func (_aeb *Options ){_aeb .Prefix =prefix }}; +func WithPrefix (prefix string )Option {return func (_ecf *Options ){_ecf .Prefix =prefix }}; -// QueryBuilder is the query that converts HTMLConverter defined data -type QueryBuilder struct{_gfe Query ;_ca error ;}; +// WithHTTPS sets the TLS option for the client options. +func WithHTTPS (useHTTPS bool )Option {return func (_ffe *Options ){_ffe .HTTPS =useHTTPS }}; -// SetContent sets custom data with it's content type. -func (_dc *QueryBuilder )SetContent (content _aa .Content )*QueryBuilder {if _dc ._ca !=nil {return _dc ;};if _dc ._gfe .ContentType !=""{_dc ._ca =ErrContentTypeDeclared ;return _dc ;};if content .ContentType ()==""{_dc ._ca =_db .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType ); -return _dc ;};_dc ._gfe .Data =content .Data ();_dc ._gfe .ContentType =content .ContentType ();return _dc ;}; +// MarginRight sets up the MarginRight parameter for the query. +func (_cee *QueryBuilder )MarginRight (marginRight _dc .Length )*QueryBuilder {_cee ._cb .PageParameters .MarginRight =marginRight ;return _cee ;}; -// WithDefaultTimeout sets the DefaultTimeout option for the client options. -func WithDefaultTimeout (option _de .Duration )Option {return func (_fbf *Options ){_fbf .DefaultTimeout =option };}; +// WaitVisible waits for the selector to get visible. +func (_edf *QueryBuilder )WaitVisible (selector string ,by _bd .ByType )*QueryBuilder {_edf ._cb .RenderParameters .WaitVisible =append (_edf ._cb .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _edf ;}; // Options are the client options used by the HTTP client. -type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _de .Duration ;Prefix string ;}; +type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _af .Duration ;Prefix string ;}; -// ParseOptions parses options for the Client. -func ParseOptions (connectPath string )(Options ,error ){if !_deb .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_ce ,_df :=_c .Parse (connectPath );if _df !=nil {return Options {},_db .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); -};var _gf int ;if _ce .Port ()!=""{_gf ,_df =_af .Atoi (_ce .Port ());if _df !=nil {return Options {},_db .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_df ); -};};return Options {Hostname :_ce .Hostname (),Port :_gf ,HTTPS :_ce .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_ce .Path },nil ;}; +// WithHostname sets the Hostname option for the client options. +func WithHostname (option string )Option {return func (_dce *Options ){_dce .Hostname =option }}; -// BuildHTMLQuery creates a Query builder that is supposed to create valid -func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; +// PageSize sets up the PageSize parameter for the query. +func (_fba *QueryBuilder )PageSize (pageSize _dc .PageSize )*QueryBuilder {if pageSize !=_dc .Undefined {_fba ._cb .PageParameters .PageSize =&pageSize ;};return _fba ;}; // PDFResponse is the response used by the HTMLConverter. type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; -// MarginBottom sets up the MarginBottom parameter for the query. -func (_bgb *QueryBuilder )MarginBottom (marginBottom _e .Length )*QueryBuilder {_bgb ._gfe .PageParameters .MarginBottom =marginBottom ;return _bgb ;}; - -// MarginRight sets up the MarginRight parameter for the query. -func (_baac *QueryBuilder )MarginRight (marginRight _e .Length )*QueryBuilder {_baac ._gfe .PageParameters .MarginRight =marginRight ;return _baac ;}; - -// WithHostname sets the Hostname option for the client options. -func WithHostname (option string )Option {return func (_gaf *Options ){_gaf .Hostname =option }}; - -// PageSize sets up the PageSize parameter for the query. -func (_aec *QueryBuilder )PageSize (pageSize _e .PageSize )*QueryBuilder {if pageSize !=_e .Undefined {_aec ._gfe .PageParameters .PageSize =&pageSize ;};return _aec ;}; +// Validate checks if the parameters are valid. +func (_eca *PageParameters )Validate ()error {if _eca .PaperWidth !=nil {if _eca .PaperWidth .Millimeters ()< 0{return _b .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); +};};if _eca .PaperHeight !=nil {if _eca .PaperHeight .Millimeters ()< 0{return _b .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); +};};if _eca .MarginTop !=nil {if _eca .MarginTop .Millimeters ()< 0{return _b .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _eca .MarginBottom !=nil {if _eca .MarginBottom .Millimeters ()< 0{return _b .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); +};};if _eca .MarginLeft !=nil {if _eca .MarginLeft .Millimeters ()< 0{return _b .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};}; +if _eca .MarginRight !=nil {if _eca .MarginRight .Millimeters ()< 0{return _b .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); +};};if _eca .PageSize !=nil &&!_eca .PageSize .IsAPageSize (){return _b .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; // PageParameters are the query parameters used in the PDF generation. type PageParameters struct{ // PaperWidth sets the width of the paper. -PaperWidth _e .Length `schema:"paper-width" json:"paperWidth"`; +PaperWidth _dc .Length `schema:"paper-width" json:"paperWidth"`; // PaperHeight is the height of the output paper. -PaperHeight _e .Length `schema:"paper-height" json:"paperHeight"`; +PaperHeight _dc .Length `schema:"paper-height" json:"paperHeight"`; // PageSize is the page size string. -PageSize *_e .PageSize `schema:"page-size" json:"pageSize"`; +PageSize *_dc .PageSize `schema:"page-size" json:"pageSize"`; // Orientation defines if the output should be in a landscape format. -Orientation _e .Orientation `schema:"orientation" json:"orientation"`; +Orientation _dc .Orientation `schema:"orientation" json:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _e .Length `schema:"margin-top" json:"marginTop"`; +MarginTop _dc .Length `schema:"margin-top" json:"marginTop"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _e .Length `schema:"margin-bottom" json:"marginBottom"`; +MarginBottom _dc .Length `schema:"margin-bottom" json:"marginBottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _e .Length `schema:"margin-left" json:"marginLeft"`; +MarginLeft _dc .Length `schema:"margin-left" json:"marginLeft"`; // MarginRight sets up the Right Margin for the output. -MarginRight _e .Length `schema:"margin-right" json:"marginRight"`;}; +MarginRight _dc .Length `schema:"margin-right" json:"marginRight"`;}; // Validate checks if the QueryBuilder had no errors during composition and creation. -func (_dg *QueryBuilder )Validate ()error {if _dg ._ca !=nil {return _dg ._ca ;};return _dg ._gfe .Validate ();}; +func (_cdcg *QueryBuilder )Validate ()error {if _cdcg ._gdg !=nil {return _cdcg ._gdg ;};return _cdcg ._cb .Validate ();}; -// Client is a structure that is a HTTP client for the unihtml server. -type Client struct{Options Options ;Client *_g .Client ;}; +// Err gets the error which could occur in the query. +func (_cbe *QueryBuilder )Err ()error {return _cbe ._gdg }; -// PaperHeight sets up the PaperHeight (in cm) parameter for the query. -func (_dfc *QueryBuilder )PaperHeight (paperHeight _e .Length )*QueryBuilder {_dfc ._gfe .PageParameters .PaperHeight =paperHeight ;return _dfc ;}; +// HealthCheck connects to the server and check the health status of the server. +func (_df *Client )HealthCheck (ctx _d .Context )error {_cdc :=_df .Options .Addr ();_cdc =_eg .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_cdc );_ege ,_bga :=_e .NewRequest ("\u0047\u0045\u0054",_cdc ,nil );if _bga !=nil {return _bga ;};_ege =_ege .WithContext (ctx ); +_ga ,_bga :=_df .Client .Do (_ege );if _bga !=nil {return _bga ;};switch _ga .StatusCode {case _e .StatusOK :return nil ;case _e .StatusNotFound :return ErrNotFound ;case _e .StatusInternalServerError :return ErrInternalError ;case _e .StatusBadGateway :return ErrBadGateway ; +default:return ErrNotImplemented ;};}; -// MarginTop sets up the MarginTop parameter for the query. -func (_ead *QueryBuilder )MarginTop (marginTop _e .Length )*QueryBuilder {_ead ._gfe .PageParameters .MarginTop =marginTop ;return _ead ;};func (_gc *Client )getRequest (_bb _bd .Context ,_fb *Query )(*_g .Request ,error ){_fd :=_gc .Options .Addr ();_fd =_fa .Sprintf ("\u0025\u0073\u002f\u0070\u0064\u0066",_fd ); -_ae ,_baa :=_g .NewRequest ("\u0050\u004f\u0053\u0054",_fd ,_daa .NewReader (_fb .Data ));if _baa !=nil {return nil ,_baa ;};_ae .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065",_fb .ContentType );_ae .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); -_ae =_ae .WithContext (_bb );_eb :=_ae .URL .Query ();_cf :=_fb .PageParameters ;if _cf .PageSize !=nil {_eb .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_cf .PageSize .String ());};if _cf .PaperHeight !=nil {_eb .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_cf .PaperHeight .String ()); -};if _cf .PaperWidth !=nil {_eb .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_cf .PaperWidth .String ());};if _cf .MarginTop !=nil {_eb .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_cf .MarginTop .String ()); -};if _cf .MarginBottom !=nil {_eb .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_cf .MarginBottom .String ());};if _cf .MarginRight !=nil {_eb .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_cf .MarginRight .String ()); -};if _cf .MarginLeft !=nil {_eb .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_cf .MarginLeft .String ());};if _cf .Orientation ==_e .Landscape {_eb .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_cf .Orientation .String ()); -};_ae .URL .RawQuery =_eb .Encode ();return _ae ,nil ;}; +// WaitTime sets the minimum load time parameter for the page rendering. +func (_afe *QueryBuilder )WaitTime (d _af .Duration )*QueryBuilder {_afe ._cb .RenderParameters .WaitTime =d ;return _afe ;}; -// Validate checks if the parameters are valid. -func (_fge *PageParameters )Validate ()error {if _fge .PaperWidth !=nil {if _fge .PaperWidth .Millimeters ()< 0{return _a .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); -};};if _fge .PaperHeight !=nil {if _fge .PaperHeight .Millimeters ()< 0{return _a .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); -};};if _fge .MarginTop !=nil {if _fge .MarginTop .Millimeters ()< 0{return _a .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _fge .MarginBottom !=nil {if _fge .MarginBottom .Millimeters ()< 0{return _a .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); -};};if _fge .MarginLeft !=nil {if _fge .MarginLeft .Millimeters ()< 0{return _a .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};}; -if _fge .MarginRight !=nil {if _fge .MarginRight .Millimeters ()< 0{return _a .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); -};};if _fge .PageSize !=nil &&!_fge .PageSize .IsAPageSize (){return _a .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; +// DefaultPageParameters creates default parameters. +func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_dc .Portrait }}; -// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. -type Query struct{Data []byte ;ContentType string ;PageParameters PageParameters ;}; +// SetContent sets custom data with it's content type. +func (_feaa *QueryBuilder )SetContent (content _dg .Content )*QueryBuilder {if _feaa ._gdg !=nil {return _feaa ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _feaa ._cb .ContentType !=""{_feaa ._gdg =ErrContentTypeDeclared ; +return _feaa ;};if content .ContentType ()==""{_feaa ._gdg =_ea .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _feaa ; +};_feaa ._cb .Content =content .Data ();_feaa ._cb .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _feaa ._cb .ContentType !=""{_feaa ._gdg =ErrContentTypeDeclared ;return _feaa ;};_feaa ._cb .URL =string (content .Data ());_feaa ._cb .ContentType =content .ContentType (); +default:_feaa ._gdg =_ea .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ());return _feaa ;};_feaa ._cb .Method =content .Method (); +return _feaa ;}; -// Addr gets the HTTP address URI used by the http.Client. -func (_afb *Options )Addr ()string {_fc :=_deb .Builder {};_fc .WriteString ("\u0068\u0074\u0074\u0070");if _afb .HTTPS {_fc .WriteRune ('s');};_fc .WriteString ("\u003a\u002f\u002f");_fc .WriteString (_afb .Hostname );_fc .WriteRune (':');_fc .WriteString (_af .Itoa (_afb .Port )); -if _afb .Prefix !=""{_fc .WriteString (_afb .Prefix );};return _fc .String ();}; +// BuildHTMLQuery creates a Query builder that is supposed to create valid +func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; -// DefaultPageParameters creates default parameters. -func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_e .Portrait }}; \ No newline at end of file +// Orientation sets the page orientation for the Query. +func (_gge *QueryBuilder )Orientation (orientation _dc .Orientation )*QueryBuilder {_gge ._cb .PageParameters .Orientation =orientation ;return _gge ;}; + +// MarginBottom sets up the MarginBottom parameter for the query. +func (_fbc *QueryBuilder )MarginBottom (marginBottom _dc .Length )*QueryBuilder {_fbc ._cb .PageParameters .MarginBottom =marginBottom ;return _fbc ;}; + +// WithPort sets the Port option for the client options. +func WithPort (option int )Option {return func (_dga *Options ){_dga .Port =option }}; + +// ParseOptions parses options for the Client. +func ParseOptions (connectPath string )(Options ,error ){if !_c .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_cc ,_cd :=_fc .Parse (connectPath );if _cd !=nil {return Options {},_ea .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); +};var _ad int ;if _cc .Port ()!=""{_ad ,_cd =_bg .Atoi (_cc .Port ());if _cd !=nil {return Options {},_ea .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_cd ); +};};return Options {Hostname :_cc .Hostname (),Port :_ad ,HTTPS :_cc .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_cc .Path },nil ;}; + +// Validate checks the validity of the RenderParameters. +func (_cdb *RenderParameters )Validate ()error {if _cdb .WaitTime > _af .Minute *3{return _b .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); +};for _ ,_dd :=range _cdb .WaitReady {if _gd :=_dd .Validate ();_gd !=nil {return _eg .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_gd ); +};};return nil ;};var (ErrMissingData =_b .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061");ErrContentType =_b .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065"); +ErrContentTypeDeclared =_b .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064");); \ No newline at end of file diff --git a/common/common.go b/common/common.go index 3669cfd..c3d32f3 100644 --- a/common/common.go +++ b/common/common.go @@ -10,8 +10,8 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package common contains common properties used by the subpackages. -package common ;import _g "time";const _ee =20;const _gb =3;var ReleasedAt =_g .Date (_a ,_gb ,_c ,_af ,_ee ,0,0,_g .UTC ); +package common ;import _b "time";const Version ="\u0030\u002e\u0035.\u0030"; // UtcTimeFormat returns a formatted string describing a UTC timestamp. -func UtcTimeFormat (t _g .Time )string {return t .Format (_e )+"\u0020\u0055\u0054\u0043"};const _e ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";const _c =27;const Version ="\u0030\u002e\u0034.\u0030"; -const _a =2021;const _af =12; \ No newline at end of file +func UtcTimeFormat (t _b .Time )string {return t .Format (_d )+"\u0020\u0055\u0054\u0043"};const _f =2021;const _fe =12;const _g =20;const _bb =8;const _d ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034"; +var ReleasedAt =_b .Date (_f ,_c ,_bb ,_fe ,_g ,0,0,_b .UTC );const _c =5; \ No newline at end of file diff --git a/content/content.go b/content/content.go index 1ae41a5..e7075e8 100644 --- a/content/content.go +++ b/content/content.go @@ -9,41 +9,49 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package content ;import (_b "archive/zip";_g "bytes";_ce "encoding/json";_cgc "golang.org/x/xerrors";_e "io/ioutil";_cg "net/url";_dc "os";_d "strings";);func (_bgd *zipDirectory )zipPath (_ef ,_db string )error {_bc ,_ae :=_e .ReadDir (_ef );if _ae !=nil {return _cgc .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_ef ,_ae ); -};_bcf :=&_d .Builder {};for _ ,_gb :=range _bc {_bb ,_cgd :=_bgd .zipBasePaths (_gb ,_ef ,_db ,_gb .IsDir (),_bcf );if _gb .IsDir (){if _cbc :=_bgd .zipPath (_bb ,_cgd );_cbc !=nil {return _cbc ;};continue ;};_dg ,_ee :=_e .ReadFile (_bb );if _ee !=nil {return _ee ; -};_bce ,_ee :=_bgd ._cgae .Create (_cgd );if _ee !=nil {return _ee ;};if _ ,_ee =_bce .Write (_dg );_ee !=nil {return _ee ;};};return nil ;}; +package content ;import (_c "archive/zip";_g "bytes";_cb "golang.org/x/xerrors";_ee "io/ioutil";_b "net/url";_f "os";_e "strings";);type webURL struct{_dc string }; // NewHTMLFile creates new Content htmFile for provided input path. -func NewHTMLFile (path string )(Content ,error ){_f ,_ed :=_dc .Open (path );if _ed !=nil {return nil ,_ed ;};_gc :=&htmFile {_cb :_g .Buffer {}};if _ ,_ed =_gc ._cb .ReadFrom (_f );_ed !=nil {return nil ,_ed ;};return _gc ,nil ;}; +func NewHTMLFile (path string )(Content ,error ){_a ,_ed :=_f .Open (path );if _ed !=nil {return nil ,_ed ;};_df :=&htmlFile {_cba :_g .Buffer {}};if _ ,_ed =_df ._cba .ReadFrom (_a );_ed !=nil {return nil ,_ed ;};return _df ,nil ;}; // ContentType implements Content interface. -func (_bg *htmFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; +func (_fe *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; + +// ContentType implements Content interface. +func (_ff *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";};type zipDirectory struct{_dcc _g .Buffer ;_ae *_c .Writer ;}; // Data implements Content interface. -func (_cbb *htmFile )Data ()[]byte {return _cbb ._cb .Bytes ()}; +func (_fc *htmlFile )Data ()[]byte {return _fc ._cba .Bytes ()}; // Data implements Content interface. -func (_ba *webURL )Data ()[]byte {return _ba ._gd };type webURL struct{_a string ;_gd []byte ;};func (_dgf *zipDirectory )zipBasePaths (_ga _dc .FileInfo ,_fac ,_gbg string ,_fag bool ,_cbf *_d .Builder )(string ,string ){_cbf .WriteString (_fac );if !_d .HasSuffix (_fac ,"\u002f"){_cbf .WriteRune ('/'); -};_cbf .WriteString (_ga .Name ());if _fag {_cbf .WriteRune ('/');};_de :=_cbf .String ();_cbf .Reset ();_cbf .WriteString (_gbg );_cbf .WriteString (_ga .Name ());if _fag {_cbf .WriteRune ('/');};_eg :=_cbf .String ();_cbf .Reset ();return _de ,_eg ;}; +func (_bg *webURL )Data ()[]byte {return []byte (_bg ._dc )};func (_fa *zipDirectory )zipBasePaths (_cg _f .FileInfo ,_cbad ,_ab string ,_bf bool ,_gff *_e .Builder )(string ,string ){_gff .WriteString (_cbad );if !_e .HasSuffix (_cbad ,"\u002f"){_gff .WriteRune ('/'); +};_gff .WriteString (_cg .Name ());if _bf {_gff .WriteRune ('/');};_deb :=_gff .String ();_gff .Reset ();_gff .WriteString (_ab );_gff .WriteString (_cg .Name ());if _bf {_gff .WriteRune ('/');};_ba :=_gff .String ();_gff .Reset ();return _deb ,_ba ;}; -// NewWebURL creates new Content webURL for provided input URL path. -func NewWebURL (path string )(Content ,error ){if _ ,_bf :=_cg .Parse (path );_bf !=nil {return nil ,_bf ;};type urlOutput struct{URL string `json:"url"`;};_da :=urlOutput {URL :path };_be ,_bd :=_ce .Marshal (_da );if _bd !=nil {return nil ,_bd ;};return &webURL {_a :path ,_gd :_be },nil ; -}; +// Method gets the zip directory method. +func (_ef *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; -// NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' -// and stores in it's in-memory buffer. -func NewZipDirectory (dirPath string )(Content ,error ){_eb :=&zipDirectory {_cga :_g .Buffer {}};_eb ._cgae =_b .NewWriter (&_eb ._cga );if _fed :=_eb .zipPath (dirPath ,"");_fed !=nil {return nil ,_fed ;};if _dd :=_eb ._cgae .Close ();_dd !=nil {return nil ,_dd ; -};return _eb ,nil ;}; +// Method gets the query method. +func (_gg *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"}; -// Content is an interface used for putting the content into Client Query. -type Content interface{ContentType ()string ;Data ()[]byte ;}; +// Method gets the web url query method. +func (_cbb *webURL )Method ()string {return "\u0077\u0065\u0062"}; // ContentType implements Content interface. -func (_df *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";};type zipDirectory struct{_cga _g .Buffer ;_cgae *_b .Writer ;};type htmFile struct{_cb _g .Buffer }; +func (_de *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; + +// Content is an interface used for putting the content into Client Query. +type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;}; // Data implements Content interface. -func (_fa *zipDirectory )Data ()[]byte {return _fa ._cga .Bytes ()}; +func (_ad *zipDirectory )Data ()[]byte {return _ad ._dcc .Bytes ()};type htmlFile struct{_cba _g .Buffer };func (_ec *zipDirectory )zipPath (_adb ,_ca string )error {_bd ,_bc :=_ee .ReadDir (_adb );if _bc !=nil {return _cb .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_adb ,_bc ); +};_afb :=&_e .Builder {};for _ ,_dg :=range _bd {_fgg ,_ggb :=_ec .zipBasePaths (_dg ,_adb ,_ca ,_dg .IsDir (),_afb );if _dg .IsDir (){if _ecg :=_ec .zipPath (_fgg ,_ggb );_ecg !=nil {return _ecg ;};continue ;};_afa ,_aa :=_ee .ReadFile (_fgg );if _aa !=nil {return _aa ; +};_da ,_aa :=_ec ._ae .Create (_ggb );if _aa !=nil {return _aa ;};if _ ,_aa =_da .Write (_afa );_aa !=nil {return _aa ;};};return nil ;}; -// ContentType implements Content interface. -func (_bgc *webURL )ContentType ()string {return "\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e";}; \ No newline at end of file +// NewWebURL creates new Content webURL for provided input URL path. +func NewWebURL (path string )(Content ,error ){if _ ,_af :=_b .Parse (path );_af !=nil {return nil ,_af ;};return &webURL {_dc :path },nil ;}; + +// NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' +// and stores in it's in-memory buffer. +func NewZipDirectory (dirPath string )(Content ,error ){_cd :=&zipDirectory {_dcc :_g .Buffer {}};_cd ._ae =_c .NewWriter (&_cd ._dcc );if _fg :=_cd .zipPath (dirPath ,"");_fg !=nil {return nil ,_fg ;};if _gf :=_cd ._ae .Close ();_gf !=nil {return nil ,_gf ; +};return _cd ,nil ;}; \ No newline at end of file diff --git a/selector/selector.go b/selector/selector.go new file mode 100644 index 0000000..d7c77a2 --- /dev/null +++ b/selector/selector.go @@ -0,0 +1,18 @@ +// +// Copyright 2020 FoxyUtils ehf. All rights reserved. +// +// This is a commercial product and requires a license to operate. +// A trial license can be obtained at https://unidoc.io +// +// DO NOT EDIT: generated by unitwist Go source code obfuscator. +// +// Use of this source code is governed by the UniDoc End User License Agreement +// terms that can be accessed at https://unidoc.io/eula/ + +package selector ;import _a "errors";const (ByUndefined ByType =iota ;ByID ;ByQueryAll ;ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); + +// ByType is a 'By' selector type enumerator. +type ByType uint ; + +// Validate checks validity of the ByType. +func (_e ByType )Validate ()error {if _e >=ByID &&_e <=BySearch {return nil ;};return _a .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");}; \ No newline at end of file diff --git a/sizes/sizes.go b/sizes/sizes.go index c1f4580..c86c91c 100644 --- a/sizes/sizes.go +++ b/sizes/sizes.go @@ -12,180 +12,189 @@ // Package sizes defines basic types that determines the size units i.e. lengths. // // -package sizes ;import (_f "encoding/json";_c "flag";_a "fmt";_e "strconv";_g "strings";);func _fb (_eea string )(Inch ,error ){_eea =_g .TrimSpace (_g .Trim (_eea ,"\u0069\u006e"));_egd ,_df :=_e .ParseFloat (_eea ,64);if _df !=nil {return 0,_a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_df ); -};return Inch (_egd ),nil ;}; +package sizes ;import (_a "encoding/json";_g "flag";_ccg "fmt";_cc "strconv";_b "strings";); -// Points implements Length interface. -func (_gad Point )Points ()Point {return _gad }; +// String implements fmt.Stringer interface. +func (_ea Millimeter )String ()string {_dd :=_b .Builder {};_dd .WriteString (_cc .FormatFloat (float64 (_ea ),'f',1,64));_dd .WriteString ("\u006d\u006d");return _dd .String ();}; -// MarshalJSON implements the json.Marshaler interface for PageSize -func (_ac PageSize )MarshalJSON ()([]byte ,error ){return _f .Marshal (_ac .String ())}; +// LengthFlag is a pflag wrapper for the Length value. +type LengthFlag struct{Length Length ;};func _fgg (_fdf string )(Millimeter ,error ){_fdf =_b .TrimSpace (_b .TrimSuffix (_fdf ,"\u006d\u006d"));_aef ,_bde :=_cc .ParseFloat (_fdf ,64);if _bde !=nil {return 0,_ccg .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_bde ); +};return Millimeter (_aef ),nil ;}; // Millimeters gets the float64 millimeter value. -func (_bf Millimeter )Millimeters ()Millimeter {return _bf };var _ffe =map[string ]PageSize {_da [0:9]:0,_da [9:11]:1,_da [11:13]:2,_da [13:15]:3,_da [15:17]:4,_da [17:19]:5,_da [19:21]:6,_da [21:23]:7,_da [23:25]:8,_da [25:27]:9,_da [27:29]:10,_da [29:32]:11,_da [32:34]:12,_da [34:36]:13,_da [36:38]:14,_da [38:40]:15,_da [40:42]:16,_da [42:44]:17,_da [44:46]:18,_da [46:48]:19,_da [48:50]:20,_da [50:52]:21,_da [52:55]:22,_da [55:61]:23}; +func (_ab Millimeter )Millimeters ()Millimeter {return _ab };var _ _g .Value =(*Orientation )(nil ); +// Type implements pflag.Value interface. +func (_ed Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; -// Set implements flag.Value interface. -func (_fe *Point )Set (s string )error {_cd ,_ba :=_e .ParseFloat (s ,64);if _ba !=nil {return _a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ba );};*_fe =Point (_cd ); +// PageSizeValues returns all values of the enum +func PageSizeValues ()[]PageSize {return _deg }; + +// Name implements viper.FlagValue interface. +func (_ccbc Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; + +// Set implements pflag.Value interface. +func (_fb *Inch )Set (s string )error {_dg ,_ee :=_cc .ParseFloat (s ,64);if _ee !=nil {return _ccg .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ee );};*_fb =Inch (_dg ); return nil ;}; -// ValueString implements pflag.Value interface. -func (_eeg Inch )ValueString ()string {return _eeg .String ()}; +// Orientation is the page orientation type wrapper. +type Orientation bool ; -// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise -func (_cbae PageSize )IsAPageSize ()bool {for _ ,_gcg :=range _dgc {if _cbae ==_gcg {return true ;};};return false ;};var _ Length =Inch (0); +// ValueString implements pflag.Value interface. +func (_fcb Inch )ValueString ()string {return _fcb .String ()}; -// Type implements pflag.Value interface. -func (_ae Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; +// HasChanged implements pflag.Value interface. +func (_fbe *Inch )HasChanged ()bool {return _fbe !=nil }; // Inch is a unit that type Inch float64 ; // MarshalUnit marshals the unit into the string. -func MarshalUnit (unit Length )(string ,error ){switch _ag :=unit .(type ){case Millimeter :return _a .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_ag ),nil ;case Inch :return _a .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_ag ),nil ;case Point :return _a .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_ag ),nil ; -default:return "",_a .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; - -// UnmarshalPageSize unmarshals the page size from the string. -func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _cbb PageSize ;if _eff :=(&_cbb ).UnmarshalText ([]byte (pageSize ));_eff !=nil {return 0,_a .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_eff ); -};return _cbb ,nil ;}; +func MarshalUnit (unit Length )(string ,error ){switch _ffb :=unit .(type ){case Millimeter :return _ccg .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_ffb ),nil ;case Inch :return _ccg .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_ffb ),nil ;case Point :return _ccg .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_ffb ),nil ; +default:return "",_ccg .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};};func _baa (_eea string )(Inch ,error ){_eea =_b .TrimSpace (_b .Trim (_eea ,"\u0069\u006e"));_ccc ,_ga :=_cc .ParseFloat (_eea ,64); +if _ga !=nil {return 0,_ccg .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ga );};return Inch (_ccc ),nil ;};var _ _g .Value =(*Point )(nil ); // Type implements pflag.Value interface. -func (_fa Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; +func (_gc *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; -// Millimeters converts the inches value to the millimeters. -func (_gb Point )Millimeters ()Millimeter {return Millimeter (float64 (_gb )*_d )}; +// MarshalJSON implements json.Marshaler interface +func (_fc Millimeter )MarshalJSON ()([]byte ,error ){return _eaf (_fc )}; -// UnmarshalInch unmarshalls provided string into unit. -func UnmarshalInch (unit string )(Inch ,error ){if _g .HasSuffix (unit ,"\u006d\u006d"){_aec ,_bde :=_cg (unit );if _bde !=nil {return 0,_bde ;};return _aec .Inches (),nil ;};if _g .HasSuffix (unit ,"\u0069\u006e"){return _fb (unit );};return 0,_a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); -}; +// ValueType implements pflag.Value interface. +func (_ae Inch )ValueType ()string {return _ae .Type ()}; -// ValueString implements viper.FlagValue interface. -func (_ebe Point )ValueString ()string {return _ebe .String ()}; +// Points implements Length interface. +func (_ba Inch )Points ()Point {return Point (float64 (_ba )*_e )};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;);func (_dgg PageSize )String ()string {if _dgg < 0||_dgg >=PageSize (len (_cga )-1){return _ccg .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_dgg ); +};return _aed [_cga [_dgg ]:_cga [_dgg +1]];}; -// Millimeter is the dimension unit that defines a millimeter. -type Millimeter float64 ; +// String implements fmt.Stringer interface. +func (_ddg Orientation )String ()string {if _ddg ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; -// MarshalPageSize marshals the page size into string. -func MarshalPageSize (p PageSize )(string ,error ){_gda ,_fbb :=p .MarshalText ();if _fbb !=nil {return "",_fbb ;};return string (_gda ),nil ;}; +// HasChanged implements viper.FlagValue interface. +func (_bga *Point )HasChanged ()bool {return _bga !=nil }; -// PageSize is the enum used for defining the page size. -type PageSize int ; +// Set sets the unit value. +// Implements pflag.Value interface. +func (_bb *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_bb .Length =nil ;return nil ;};_cd ,_ff :=UnmarshalLength (s );if _ff !=nil {return _ff ;};_bb .Length =_cd ;return nil ;}; -// ValueType implements viper.FlagValue interface. -func (_baf Point )ValueType ()string {return _baf .Type ()}; +// Inches gets the inch value. Implements Length interface. +func (_bd Inch )Inches ()Inch {return _bd }; -// HasChanged implements viper.FlagValue interface. -func (_dcf *Point )HasChanged ()bool {return _dcf !=nil }; +// Type implements pflag.Value interface. +func (_bg Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; -// PageSizeValues returns all values of the enum -func PageSizeValues ()[]PageSize {return _dgc }; +// Type implements pflag.Value interface. +func (_bba Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; -// Name implements viper.FlagValue interface. -func (_ega Point )Name ()string {return "\u0070\u006f\u0069n\u0074"};func _cg (_edc string )(Millimeter ,error ){_edc =_g .TrimSpace (_g .TrimSuffix (_edc ,"\u006d\u006d"));_fed ,_dbf :=_e .ParseFloat (_edc ,64);if _dbf !=nil {return 0,_a .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_dbf ); -};return Millimeter (_fed ),nil ;};var _dgc =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; +// Millimeter is the dimension unit that defines a millimeter. +type Millimeter float64 ;var (_ Length =Millimeter (0);); -// Point is a unit of Length commonly used to measure the height of fonts. -type Point float64 ;const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;); +// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize +func (_ad *PageSize )UnmarshalText (text []byte )error {var _ge error ;*_ad ,_ge =PageSizeString (string (text ));return _ge ;}; -// Set sets the unit value. -// Implements pflag.Value interface. -func (_ee *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_ee .Length =nil ;return nil ;};_ca ,_ed :=UnmarshalLength (s );if _ed !=nil {return _ed ;};_ee .Length =_ca ;return nil ;}; +// Set implements flag.Value interface. +func (_ac *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_ac =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_ac =Landscape ;default:return _ccg .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); +};return nil ;}; -// Inches gets the inches equivalent from provided millimeter value. -func (_bff Millimeter )Inches ()Inch {return Inch (float64 (_bff )*_bd )};var _ _c .Value =(*Orientation )(nil ); +// ValueString implements viper.FlagValue interface. +func (_cf Point )ValueString ()string {return _cf .String ()}; -// Type implements pflag.Value interface. -func (_gdc Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; +// Inches gets the inch value. Implements Length interface. +func (_fbea Point )Inches ()Inch {return Inch (float64 (_fbea )*_f )}; // String implements fmt.Stringer interface. -func (_gd Inch )String ()string {_ab :=_g .Builder {};_ab .WriteString (_e .FormatFloat (float64 (_gd ),'f',1,64));_ab .WriteString ("\u0069\u006e");return _ab .String ();}; +func (_db Inch )String ()string {_ec :=_b .Builder {};_ec .WriteString (_cc .FormatFloat (float64 (_db ),'f',1,64));_ec .WriteString ("\u0069\u006e");return _ec .String ();}; -// Set implements pflag.Value interface. -func (_bfa *PageSize )Set (s string )error {_fg ,_aa :=UnmarshalPageSize (s );if _aa !=nil {return _aa ;};*_bfa =_fg ;return nil ;}; +// String gets the string value for given flag. +func (_gfg *LengthFlag )String ()string {if _gfg .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _gfg .Length .String ();};var _deg =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; -// Set implements flag.Value interface. -func (_dbc *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_dbc =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_dbc =Landscape ;default:return _a .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); -};return nil ;}; +// ValueType implements viper.FlagValue interface. +func (_dga Point )ValueType ()string {return _dga .Type ()}; -// Length is it the default dimension unit. -type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; +// Point is a unit of Length commonly used to measure the height of fonts. +type Point float64 ; + +// Inches gets the inches equivalent from provided millimeter value. +func (_fd Millimeter )Inches ()Inch {return Inch (float64 (_fd )*_gf )}; + +// Set implements flag.Value interface. +func (_bf *Point )Set (s string )error {_gd ,_df :=_cc .ParseFloat (s ,64);if _df !=nil {return _ccg .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_df );};*_bf =Point (_gd ); +return nil ;}; // Points implements Length interface. -func (_bdf Inch )Points ()Point {return Point (float64 (_bdf )*_eg )}; +func (_abf Millimeter )Points ()Point {return Point (_abf *_aa )}; -// Type implements pflag.Value interface. -func (_af *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; +// Millimeters converts the inches value to the millimeters. +func (_ag Point )Millimeters ()Millimeter {return Millimeter (float64 (_ag )*_d )}; -// HasChanged implements pflag.Value interface. -func (_cba *Inch )HasChanged ()bool {return _cba !=nil };var (_ Length =Millimeter (0);); +// MarshalJSON implements json.Marshaler interface +func (_ccd Inch )MarshalJSON ()([]byte ,error ){return _eaf (_ccd )};func _da (_eac string )(Point ,error ){_eac =_b .TrimSpace (_b .Trim (_eac ,"\u0070\u0074"));_gg ,_egg :=_cc .ParseFloat (_eac ,64);if _egg !=nil {return 0,_egg ;};return Point (_gg ),nil ; +}; -// UnmarshalJSON implements the json.Unmarshaler interface for PageSize -func (_ded *PageSize )UnmarshalJSON (data []byte )error {var _aab string ;if _abb :=_f .Unmarshal (data ,&_aab );_abb !=nil {return _a .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); -};var _afd error ;*_ded ,_afd =PageSizeString (_aab );return _afd ;}; +// Millimeters converts the inches value to the millimeters. +func (_dc Inch )Millimeters ()Millimeter {return Millimeter (float64 (_dc )*_ccb )}; // PageSizeString retrieves an enum value from the enum constants string name. // Throws an error if the param is not part of the enum. -func PageSizeString (s string )(PageSize ,error ){if _bc ,_cac :=_ffe [s ];_cac {return _bc ,nil ;};return 0,_a .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); +func PageSizeString (s string )(PageSize ,error ){if _ccdf ,_aag :=_aab [s ];_aag {return _ccdf ,nil ;};return 0,_ccg .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); }; -// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize -func (_afdd *PageSize )UnmarshalText (text []byte )error {var _cdb error ;*_afdd ,_cdb =PageSizeString (string (text ));return _cdb ;}; - -// Millimeters converts the inches value to the millimeters. -func (_gc Inch )Millimeters ()Millimeter {return Millimeter (float64 (_gc )*_eb )}; - -// UnmarshalLength unmarshalls string value into Length. -func UnmarshalLength (length string )(Length ,error ){if _g .HasSuffix (length ,"\u006d\u006d"){return _cg (length );};if _g .HasSuffix (length ,"\u0069\u006e"){return _fb (length );};if _g .HasSuffix (length ,"\u0070\u0074"){return _feb (length );};return nil ,_a .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length ); -};const (_bd =float64 (1)/float64 (25.4);_eb =25.4;_ga =0.0139;_d =0.3528;_eg =1/64;_de =1/_d ;); +// UnmarshalInch unmarshalls provided string into unit. +func UnmarshalInch (unit string )(Inch ,error ){if _b .HasSuffix (unit ,"\u006d\u006d"){_bbb ,_dda :=_fgg (unit );if _dda !=nil {return 0,_dda ;};return _bbb .Inches (),nil ;};if _b .HasSuffix (unit ,"\u0069\u006e"){return _baa (unit );};return 0,_ccg .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); +}; -// Set implements pflag.Value interface. -func (_bfe *Inch )Set (s string )error {_gge ,_db :=_e .ParseFloat (s ,64);if _db !=nil {return _a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_db );};*_bfe =Inch (_gge ); -return nil ;}; +// PageSize is the enum used for defining the page size. +type PageSize int ; // MarshalText implements the encoding.TextMarshaler interface for PageSize -func (_cf PageSize )MarshalText ()([]byte ,error ){return []byte (_cf .String ()),nil }; +func (_bec PageSize )MarshalText ()([]byte ,error ){return []byte (_bec .String ()),nil }; // String implements fmt.Stringer interface. -func (_cb Millimeter )String ()string {_dc :=_g .Builder {};_dc .WriteString (_e .FormatFloat (float64 (_cb ),'f',1,64));_dc .WriteString ("\u006d\u006d");return _dc .String ();}; +func (_abe Point )String ()string {_eg :=_b .Builder {};_eg .WriteString (_cc .FormatFloat (float64 (_abe ),'f',1,64));_eg .WriteString ("\u0070\u0074");return _eg .String ();}; -// Dimensions gets the dimensions of the given page size. -// If provided page size is not valid than the function returns 0 values. -func (_dg PageSize )Dimensions ()(_abg ,_edg Millimeter ){switch _dg {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; -case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; -case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _abg ,_edg ;};var _gag =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; +// UnmarshalPageSize unmarshals the page size from the string. +func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _gfa PageSize ;if _dcc :=(&_gfa ).UnmarshalText ([]byte (pageSize ));_dcc !=nil {return 0,_ccg .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_dcc ); +};return _gfa ,nil ;};func _eaf (_ddf Length )([]byte ,error ){if _ddf ==nil {return nil ,nil ;};_gab ,_bdd :=MarshalUnit (_ddf );if _bdd !=nil {return nil ,_bdd ;};return []byte ("\u0022"+_gab +"\u0022"),nil ;}; -// Type implements pflag.Value interface. -func (_fdc PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"};var _ _c .Value =(*Point )(nil ); +// MarshalPageSize marshals the page size into string. +func MarshalPageSize (p PageSize )(string ,error ){_aaa ,_de :=p .MarshalText ();if _de !=nil {return "",_de ;};return string (_aaa ),nil ;}; -// Inches gets the inch value. Implements Length interface. -func (_fef Point )Inches ()Inch {return Inch (float64 (_fef )*_ga )}; +// Name implements pflag.Value interface. +func (_ca Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; -// Points implements Length interface. -func (_ge Millimeter )Points ()Point {return Point (_ge *_de )};func _feb (_geb string )(Point ,error ){_geb =_g .TrimSpace (_g .Trim (_geb ,"\u0070\u0074"));_bg ,_bda :=_e .ParseFloat (_geb ,64);if _bda !=nil {return 0,_bda ;};return Point (_bg ),nil ; -}; +// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise +func (_ce PageSize )IsAPageSize ()bool {for _ ,_cfe :=range _deg {if _ce ==_cfe {return true ;};};return false ;}; -// String gets the string value for given flag. -func (_ff *LengthFlag )String ()string {if _ff .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _ff .Length .String ();};const (Portrait =Orientation (false );Landscape =Orientation (true );); +// UnmarshalJSON implements the json.Unmarshaler interface for PageSize +func (_gfbe *PageSize )UnmarshalJSON (data []byte )error {var _bcb string ;if _agd :=_a .Unmarshal (data ,&_bcb );_agd !=nil {return _ccg .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); +};var _bed error ;*_gfbe ,_bed =PageSizeString (_bcb );return _bed ;}; -// ValueType implements pflag.Value interface. -func (_be Inch )ValueType ()string {return _be .Type ()}; +// Set implements pflag.Value interface. +func (_gfb *PageSize )Set (s string )error {_eaa ,_fa :=UnmarshalPageSize (s );if _fa !=nil {return _fa ;};*_gfb =_eaa ;return nil ;};var _ Length =Inch (0);const (_gf =float64 (1)/float64 (25.4);_ccb =25.4;_f =0.0139;_d =0.3528;_e =1/64;_aa =1/_d ;); -// LengthFlag is a pflag wrapper for the Length value. -type LengthFlag struct{Length Length ;}; +// Length is it the default dimension unit. +type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; -// Inches gets the inch value. Implements Length interface. -func (_fd Inch )Inches ()Inch {return _fd }; +// MarshalJSON implements the json.Marshaler interface for PageSize +func (_fffg PageSize )MarshalJSON ()([]byte ,error ){return _a .Marshal (_fffg .String ())}; -// Orientation is the page orientation type wrapper. -type Orientation bool ; +// Points implements Length interface. +func (_fdc Point )Points ()Point {return _fdc };var _cga =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; -// String implements fmt.Stringer interface. -func (_ef Orientation )String ()string {if _ef ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";};const _da ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; +// Type implements pflag.Value interface. +func (_ace PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"};var _aab =map[string ]PageSize {_aed [0:9]:0,_aed [9:11]:1,_aed [11:13]:2,_aed [13:15]:3,_aed [15:17]:4,_aed [17:19]:5,_aed [19:21]:6,_aed [21:23]:7,_aed [23:25]:8,_aed [25:27]:9,_aed [27:29]:10,_aed [29:32]:11,_aed [32:34]:12,_aed [34:36]:13,_aed [36:38]:14,_aed [38:40]:15,_aed [40:42]:16,_aed [42:44]:17,_aed [44:46]:18,_aed [46:48]:19,_aed [48:50]:20,_aed [50:52]:21,_aed [52:55]:22,_aed [55:61]:23}; -// Name implements pflag.Value interface. -func (_cabb Inch )Name ()string {return "\u0069\u006e\u0063\u0068"};func (_ce PageSize )String ()string {if _ce < 0||_ce >=PageSize (len (_gag )-1){return _a .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_ce );};return _da [_gag [_ce ]:_gag [_ce +1]]; -}; +// MarshalJSON implements json.Marshaler interface. +func (_fff Point )MarshalJSON ()([]byte ,error ){return _eaf (_fff )}; -// String implements fmt.Stringer interface. -func (_dcb Point )String ()string {_ege :=_g .Builder {};_ege .WriteString (_e .FormatFloat (float64 (_dcb ),'f',1,64));_ege .WriteString ("\u0070\u0074");return _ege .String ();}; \ No newline at end of file +// Dimensions gets the dimensions of the given page size. +// If provided page size is not valid than the function returns 0 values. +func (_cab PageSize )Dimensions ()(_ega ,_eed Millimeter ){switch _cab {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; +case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; +case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _ega ,_eed ;};const (Portrait =Orientation (false );Landscape =Orientation (true ););const _aed ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; + + +// UnmarshalLength unmarshalls string value into Length. +func UnmarshalLength (length string )(Length ,error ){if _b .HasSuffix (length ,"\u006d\u006d"){return _fgg (length );};if _b .HasSuffix (length ,"\u0069\u006e"){return _baa (length );};if _b .HasSuffix (length ,"\u0070\u0074"){return _da (length );};return nil ,_ccg .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length ); +}; \ No newline at end of file diff --git a/unihtml.go b/unihtml.go index a143faf..59a9980 100644 --- a/unihtml.go +++ b/unihtml.go @@ -10,43 +10,88 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package unihtml contains a plugin for the UniDoc. -package unihtml ;import (_gf "bytes";_g "context";_dg "errors";_ba "fmt";_ea "github.com/unidoc/unihtml/client";_c "github.com/unidoc/unihtml/content";_gc "github.com/unidoc/unihtml/sizes";_ec "github.com/unidoc/unipdf/v3/common";_eab "github.com/unidoc/unipdf/v3/common/license"; -_eac "github.com/unidoc/unipdf/v3/creator";_fb "github.com/unidoc/unipdf/v3/model";_be "github.com/unidoc/unipdf/v3/render";_bf "image";_a "image/color";_f "math";_d "net/url";_e "os";_fe "time";); +package unihtml ;import (_eb "bytes";_f "context";_af "errors";_fc "fmt";_ee "github.com/unidoc/unihtml/client";_fd "github.com/unidoc/unihtml/content";_eee "github.com/unidoc/unihtml/selector";_ab "github.com/unidoc/unihtml/sizes";_ad "github.com/unidoc/unipdf/v3/common"; +_ae "github.com/unidoc/unipdf/v3/common/license";_da "github.com/unidoc/unipdf/v3/creator";_fb "github.com/unidoc/unipdf/v3/model";_cga "github.com/unidoc/unipdf/v3/render";_gg "image";_g "image/color";_c "math";_a "net/url";_e "os";_cg "time";); -// ChapterDraw implements creator.containerElement interface. -func (_ega *Document )ContainerComponent (container _eac .Drawable )(_eac .Drawable ,error ){switch container .(type ){case *_eac .Chapter :default:return nil ,_ba .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); -};return _ega ,nil ;}; +// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. +func ConnectOptions (o Options )error {_ge =_ee .New (_ee .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_ggg ,_be :=_f .WithTimeout (_f .Background (),_cg .Second *5);defer _be ();if _cd :=_ge .HealthCheck (_ggg );_cd !=nil {return _cd ; +};return nil ;};func (_cacd *Document )validate ()error {if _ge ==nil {return ErrNoClient ;};if _cacd ._db ==nil {return ErrContentNotDefined ;};return nil ;};func (_ege *Document )getMargins ()margins {_dfd :=_ege ._fca ;if _ege ._fef .IsRelative (){_dfd .Top =_ab .Millimeter (1); +_dfd .Left =_ab .Millimeter (1);_dfd .Bottom =_ab .Millimeter (1);_dfd .Right =_ab .Millimeter (1);return _dfd ;};if _dfd .Top ==nil {_dfd .Top =_ab .Millimeter (10);};if _dfd .Bottom ==nil {_dfd .Bottom =_ab .Millimeter (10);};if _dfd .Left ==nil {_dfd .Left =_ab .Millimeter (10); +};if _dfd .Right ==nil {_dfd .Right =_ab .Millimeter (10);};return _dfd ;}; -// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. -func (_gfe *Document )TrimLastPageContent (){_gfe ._ca =true };var ErrNoClient =_dg .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");func (_faa *Document )validate ()error {if _ae ==nil {return ErrNoClient ; -};if _faa ._gfa ==nil {return ErrContentNotDefined ;};return nil ;}; +// SetMarginLeft sets the left margin. +func (_egb *Document )SetMarginLeft (margin _ab .Length ){_egb ._fca .Left =margin }; -// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. -func ConnectOptions (o Options )error {_ae =_ea .New (_ea .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_gcb ,_cg :=_g .WithTimeout (_g .Background (),_fe .Second *5);defer _cg ();if _baf :=_ae .HealthCheck (_gcb );_baf !=nil {return _baf ; -};return nil ;};var _ae *_ea .Client ; +// WriteToFile writes the document to a file defined by the output path. +func (_cge *Document )WriteToFile (outputPath string )error {if _ga :=_cge .validate ();_ga !=nil {return _ga ;};_aef :=_cg .Second *20+_cge ._ce ;_faa ,_cf :=_f .WithTimeout (_f .Background (),_aef );defer _cf ();_bea ,_cff :=_cge .extract (_faa ,_cge ._gc ,_cge ._fde ,_cge .getMargins ()); +if _cff !=nil {return _cff ;};_bf :=_da .New ();for _ ,_ede :=range _bea {if _cff =_bf .AddPage (_ede );_cff !=nil {return _cff ;};};return _bf .WriteToFile (outputPath );}; + +// SetLandscapeOrientation sets document landscape page orientation. +func (_bff *Document )SetLandscapeOrientation (){_bff ._gcg =_ab .Landscape }; + +// GetPdfPages is a function that converts provided input content and +func (_abc *Document )GetPdfPages (ctx _f .Context )([]*_fb .PdfPage ,error ){if _adfg :=_abc .validate ();_adfg !=nil {return nil ,_adfg ;};return _abc .extract (ctx ,_abc ._gc ,_abc ._fde ,_abc .getMargins ());}; + +// SetPos sets the absolute position. Changes object positioning to absolute. +func (_bda *Document )SetPos (x ,y float64 ){_bda ._fef =_da .PositionAbsolute ;_bda ._fa =x ;_bda ._ged =y ;};func _ba ()error {_fe :=_ae .GetLicenseKey ();if _fe ==nil {return _af .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); +};if !_fe .IsLicensed (){return _af .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};return nil ;};func _ffe (_geg _gg .Image )float64 {_eg :=_geg .Bounds (); +var (_fed int ;_abg _g .Color ;_eda ,_fdf ,_fg uint32 ;);_aeg ,_cbb :=_eg .Min .X ,_eg .Max .Y -1;_cac :=_geg .At (_aeg ,_cbb );_aec ,_fdb ,_bdg ,_ :=_cac .RGBA ();_ccaa :=_aec ==_c .MaxUint16 &&_fdb ==_c .MaxUint16 &&_bdg ==_c .MaxUint16 ;for _cbb =_eg .Max .Y -1; +_cbb >=_eg .Min .Y ;_cbb --{var _fdff bool ;for _aeg =_eg .Min .X ;_aeg < _eg .Max .X ;_aeg ++{_abg =_geg .At (_aeg ,_cbb );_eda ,_fdf ,_fg ,_ =_abg .RGBA ();if (_ccaa &&!(_eda ==_aec &&_fdf ==_fdb &&_bdg ==_fg ))||(!_ccaa &&(_c .Abs (float64 (_eda )-float64 (_aec ))/float64 (_c .MaxUint16 )> 0.03||_c .Abs (float64 (_fdf )-float64 (_fdb ))/float64 (_c .MaxUint16 )> 0.03||_c .Abs (float64 (_fg )-float64 (_bdg ))/float64 (_c .MaxUint16 )> 0.03)){_fdff =true ; +break ;};};if _fdff {break ;};_fed =_cbb ;};return float64 (_eg .Max .Y -_fed )/float64 (_eg .Max .Y );}; // SetPageSize sets the page default size. -func (_eca *Document )SetPageSize (pageSize _gc .PageSize )error {if !pageSize .IsAPageSize (){return _dg .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); -};_eca ._dga =pageSize ;_eca ._ac =_eac .PositionAbsolute ;return nil ;}; +func (_gaa *Document )SetPageSize (pageSize _ab .PageSize )error {if !pageSize .IsAPageSize (){return _af .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); +};_gaa ._bc =pageSize ;_gaa ._fef =_da .PositionAbsolute ;return nil ;}; + +// Connect creates UniHTML HTTP Client and tries to establish connection with the server. +func Connect (path string )error {if _b :=_ba ();_b !=nil {return _b ;};_fbb ,_fcb :=_ee .ParseOptions (path );if _fcb !=nil {return _fcb ;};_ge =_ee .New (_fbb );_ca ,_adf :=_f .WithTimeout (_f .Background (),_cg .Second *5);defer _adf ();if _bd :=_ge .HealthCheck (_ca ); +_bd !=nil {return _bd ;};return nil ;}; + +// SetMarginTop sets the left margin. +func (_eeg *Document )SetMarginTop (margin _ab .Length ){_eeg ._fca .Top =margin }; // SetMargins sets the Document Margins. -func (_daa *Document )SetMargins (left ,right ,top ,bottom float64 ){_daa ._ab .Left =_gc .Point (left );_daa ._ab .Right =_gc .Point (right );_daa ._ab .Top =_gc .Point (top );_daa ._ab .Bottom =_gc .Point (bottom );_daa ._ac =_eac .PositionAbsolute ; +func (_caf *Document )SetMargins (left ,right ,top ,bottom float64 ){_caf ._fca .Left =_ab .Point (left );_caf ._fca .Right =_ab .Point (right );_caf ._fca .Top =_ab .Point (top );_caf ._fca .Bottom =_ab .Point (bottom );_caf ._fef =_da .PositionAbsolute ; }; +// WaitReady waits for the provided selector to be ready. +// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. +func (_dg *Document )WaitReady (sel string ,by ..._eee .ByType ){_cfg :=_eee .BySearch ;if len (by )> 0{_cfg =by [0];};_dg ._ed =append (_dg ._ed ,_ee .BySelector {Selector :sel ,By :_cfg });}; + +// SetPageHeight sets the page height for given document. +func (_aff *Document )SetPageHeight (pageHeight _ab .Length )error {_aff ._fde =pageHeight ;_aff ._fef =_da .PositionAbsolute ;return nil ;}; + // SetPageWidth sets the page width for given document. -func (_ede *Document )SetPageWidth (pageWidth _gc .Length )error {_ede ._ead =pageWidth ;_ede ._ac =_eac .PositionAbsolute ;return nil ;}; +func (_ggd *Document )SetPageWidth (pageWidth _ab .Length )error {_ggd ._gc =pageWidth ;_ggd ._fef =_da .PositionAbsolute ;return nil ;};var _ge *_ee .Client ; -// SetMarginRight sets the left margin. -func (_ga *Document )SetMarginRight (margin _gc .Length ){_ga ._ab .Right =margin };func (_egc *Document )getMargins ()margins {_aec :=_egc ._ab ;if _egc ._ac .IsRelative (){_aec .Top =_gc .Millimeter (1);_aec .Left =_gc .Millimeter (1);_aec .Bottom =_gc .Millimeter (1); -_aec .Right =_gc .Millimeter (1);return _aec ;};if _aec .Top ==nil {_aec .Top =_gc .Millimeter (10);};if _aec .Bottom ==nil {_aec .Bottom =_gc .Millimeter (10);};if _aec .Left ==nil {_aec .Left =_gc .Millimeter (10);};if _aec .Right ==nil {_aec .Right =_gc .Millimeter (10); -};return _aec ;}; +// WaitVisible waits for the provided selector to be ready. +// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. +func (_afb *Document )WaitVisible (sel string ,by ..._eee .ByType ){_bbb :=_eee .BySearch ;if len (by )> 0{_bbb =by [0];};_afb ._gd =append (_afb ._gd ,_ee .BySelector {Selector :sel ,By :_bbb });};var ErrContentNotDefined =_af .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); + + +// ContainerComponent implements creator.containerElement interface. +func (_gcb *Document )ContainerComponent (container _da .Drawable )(_da .Drawable ,error ){switch container .(type ){case *_da .Chapter :default:return nil ,_fc .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); +};return _gcb ,nil ;}; + +// NewDocument creates new HTML Document used as an input for the creator.Drawable. +func NewDocument (path string )(*Document ,error ){_cb :=&Document {};_fcf ,_gee :=_a .Parse (path );if _gee !=nil {return nil ,_gee ;};switch _fcf .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_cb ._db ,_gee =_fd .NewWebURL (path ); +if _gee !=nil {return nil ,_gee ;};return _cb ,nil ;};_gea ,_gee :=_e .Stat (path );if _gee !=nil {return nil ,_gee ;};if !_gea .IsDir (){_cb ._db ,_gee =_fd .NewHTMLFile (path );}else {_cb ._db ,_gee =_fd .NewZipDirectory (path );};if _gee !=nil {return nil ,_gee ; +};return _cb ,nil ;}; // Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. -type Document struct{_gfa _c .Content ;_ab margins ;_ac _eac .Positioning ;_ebc ,_fa float64 ;_dga _gc .PageSize ;_ead ,_ggg _gc .Length ;_bba _gc .Orientation ;_ca bool ;};func _bb ()error {_dd :=_eab .GetLicenseKey ();if _dd ==nil {return _dg .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); -};if !_dd .IsLicensed (){return _dg .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};return nil ;}; +type Document struct{_db _fd .Content ;_fca margins ;_fef _da .Positioning ;_fa ,_ged float64 ;_bc _ab .PageSize ;_gc ,_fde _ab .Length ;_gcg _ab .Orientation ;_adg bool ;_ce _cg .Duration ;_ed []_ee .BySelector ;_gd []_ee .BySelector ;}; -// GetPdfPages is a function that converts provided input content and -func (_ff *Document )GetPdfPages (ctx _g .Context )([]*_fb .PdfPage ,error ){if _bd :=_ff .validate ();_bd !=nil {return nil ,_bd ;};return _ff .extract (ctx ,_ff ._ead ,_ff ._ggg ,_ff .getMargins ());}; +// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. +func (_cbe *Document )TrimLastPageContent (){_cbe ._adg =true }; + +// SetMarginBottom sets the left margin. +func (_faac *Document )SetMarginBottom (margin _ab .Length ){_faac ._fca .Bottom =margin }; + +// WaitTime sets the waiting time before the webpage is rendered to PDF. +func (_bde *Document )WaitTime (duration _cg .Duration ){_bde ._ce =duration }; + +// SetMarginRight sets the left margin. +func (_bcf *Document )SetMarginRight (margin _ab .Length ){_bcf ._fca .Right =margin }; // Options are the HTML Client options used for establishing the connection. type Options struct{ @@ -61,46 +106,16 @@ Port int ; Secure bool ; // Prefix is an option setting used when the server is working with the URI prefix. Default Value: ''. -Prefix string ;}; - -// SetLandscapeOrientation sets document landscape page orientation. -func (_abg *Document )SetLandscapeOrientation (){_abg ._bba =_gc .Landscape };type margins struct{Left ,Right ,Bottom ,Top _gc .Length ;};var ErrContentNotDefined =_dg .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); - - -// SetMarginTop sets the left margin. -func (_fbg *Document )SetMarginTop (margin _gc .Length ){_fbg ._ab .Top =margin };func _ge (_eg _bf .Image )float64 {_fae :=_eg .Bounds ();var (_gce int ;_fac _a .Color ;_edb ,_fcd ,_eacb uint32 ;);_af ,_dff :=_fae .Min .X ,_fae .Max .Y -1;_dfb :=_eg .At (_af ,_dff ); -_bbd ,_egd ,_fbca ,_ :=_dfb .RGBA ();_ad :=_bbd ==_f .MaxUint16 &&_egd ==_f .MaxUint16 &&_fbca ==_f .MaxUint16 ;for _dff =_fae .Max .Y -1;_dff >=_fae .Min .Y ;_dff --{var _fca bool ;for _af =_fae .Min .X ;_af < _fae .Max .X ;_af ++{_fac =_eg .At (_af ,_dff ); -_edb ,_fcd ,_eacb ,_ =_fac .RGBA ();if (_ad &&!(_edb ==_bbd &&_fcd ==_egd &&_fbca ==_eacb ))||(!_ad &&(_f .Abs (float64 (_edb )-float64 (_bbd ))/float64 (_f .MaxUint16 )> 0.03||_f .Abs (float64 (_fcd )-float64 (_egd ))/float64 (_f .MaxUint16 )> 0.03||_f .Abs (float64 (_eacb )-float64 (_fbca ))/float64 (_f .MaxUint16 )> 0.03)){_fca =true ; -break ;};};if _fca {break ;};_gce =_dff ;};return float64 (_fae .Max .Y -_gce )/float64 (_fae .Max .Y );};var _ _eac .Drawable =(*Document )(nil ); +Prefix string ;};var _ _da .Drawable =(*Document )(nil );func (_df *Document )extract (_ebe _f .Context ,_gdd ,_bad _ab .Length ,_ac margins )([]*_fb .PdfPage ,error ){_ega :=_ee .BuildHTMLQuery ().SetContent (_df ._db ).PageSize (_df ._bc ).PaperWidth (_gdd ).PaperHeight (_bad ).Orientation (_df ._gcg ).MarginLeft (_ac .Left ).MarginRight (_ac .Right ).MarginTop (_ac .Top ).MarginBottom (_ac .Bottom ).WaitTime (_df ._ce ); +for _ ,_edee :=range _df ._ed {_ega .WaitReady (_edee .Selector ,_edee .By );};for _ ,_add :=range _df ._gd {_ega .WaitVisible (_add .Selector ,_add .By );};_bag ,_ccf :=_ega .Query ();if _ccf !=nil {return nil ,_ccf ;};_ebe ,_ffbg :=_f .WithTimeout (_ebe ,_cg .Second *15); +defer _ffbg ();_caac ,_ccf :=_ge .ConvertHTML (_ebe ,_bag );if _ccf !=nil {return nil ,_ccf ;};_gaad :=_eb .NewReader (_caac .Data );_de ,_ccf :=_fb .NewPdfReader (_gaad );if _ccf !=nil {return nil ,_ccf ;};return _de .PageList ,nil ;}; // GeneratePageBlocks implements creator.Drawable interface. -func (_fbc *Document )GeneratePageBlocks (ctx _eac .DrawContext )([]*_eac .Block ,_eac .DrawContext ,error ){if _db :=_fbc .validate ();_db !=nil {return nil ,ctx ,_db ;};var _dad []*_eac .Block ;_aed :=_fbc .getMargins ();_fee ,_cad :=_fbc ._ead ,_fbc ._ggg ; -if _fbc ._ac .IsRelative (){_fee ,_cad =_gc .Point (ctx .Width ),_gc .Point (ctx .Height );ctx .X -=float64 (_aed .Left .Points ());};_ggf ,_bde :=_fbc .extract (_g .Background (),_fee ,_cad ,_aed );if _bde !=nil {return nil ,_eac .DrawContext {},_bde ; -};for _df ,_ebb :=range _ggf {_fba ,_fec :=_eac .NewBlockFromPage (_ebb );if _fec !=nil {return nil ,_eac .DrawContext {},_fec ;};var _fd float64 ;if _fbc ._ca &&_df ==len (_ggf )-1{_caf :=_be .NewImageDevice ();_fab ,_fdb :=_caf .Render (_ebb );if _fdb !=nil {return nil ,_eac .DrawContext {},_fdb ; -};_dc ,_fdb :=_ebb .GetMediaBox ();if _fdb !=nil {return nil ,_eac .DrawContext {},_fdb ;};_dgf :=_fe .Now ();_cgd :=_ge (_fab );_fd =_dc .Height ()*_cgd ;_ec .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_fe .Since (_dgf )); -if _fbc ._ab .Bottom !=nil {_fd -=float64 (_fbc ._ab .Bottom .Points ());};if _fd < 0{_fd =0;};_ec .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_fd ); -};_fbab ,_gfef ,_fec :=_fba .GeneratePageBlocks (ctx );if _fec !=nil {return nil ,_eac .DrawContext {},_fec ;};ctx =_gfef ;ctx .Y -=_fd ;if _df !=len (_ggf )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; -ctx .Page ++;};_dad =append (_dad ,_fbab ...);};return _dad ,ctx ,nil ;}; - -// SetPageHeight sets the page height for given document. -func (_cf *Document )SetPageHeight (pageHeight _gc .Length )error {_cf ._ggg =pageHeight ;_cf ._ac =_eac .PositionAbsolute ;return nil ;}; - -// NewDocument creates new HTML Document used as an input for the creator.Drawable. -func NewDocument (path string )(*Document ,error ){_cc :=&Document {};_ccc ,_eag :=_d .Parse (path );if _eag !=nil {return nil ,_eag ;};switch _ccc .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_cc ._gfa ,_eag =_c .NewWebURL (path ); -if _eag !=nil {return nil ,_eag ;};return _cc ,nil ;};_ed ,_eag :=_e .Stat (path );if _eag !=nil {return nil ,_eag ;};if !_ed .IsDir (){_cc ._gfa ,_eag =_c .NewHTMLFile (path );}else {_cc ._gfa ,_eag =_c .NewZipDirectory (path );};if _eag !=nil {return nil ,_eag ; -};return _cc ,nil ;}; - -// SetMarginLeft sets the left margin. -func (_ggc *Document )SetMarginLeft (margin _gc .Length ){_ggc ._ab .Left =margin }; - -// Connect creates UniHTML HTTP Client and tries to establish connection with the server. -func Connect (path string )error {if _eb :=_bb ();_eb !=nil {return _eb ;};_gg ,_ee :=_ea .ParseOptions (path );if _ee !=nil {return _ee ;};_ae =_ea .New (_gg );_da ,_de :=_g .WithTimeout (_g .Background (),_fe .Second *5);defer _de ();if _fc :=_ae .HealthCheck (_da ); -_fc !=nil {return _fc ;};return nil ;}; - -// SetMarginBottom sets the left margin. -func (_faf *Document )SetMarginBottom (margin _gc .Length ){_faf ._ab .Bottom =margin };func (_dffa *Document )extract (_feg _g .Context ,_dba ,_feb _gc .Length ,_eae margins )([]*_fb .PdfPage ,error ){_cgb :=_ea .BuildHTMLQuery ().SetContent (_dffa ._gfa ).PageSize (_dffa ._dga ).PaperWidth (_dba ).PaperHeight (_feb ).Orientation (_dffa ._bba ).MarginLeft (_eae .Left ).MarginRight (_eae .Right ).MarginTop (_eae .Top ).MarginBottom (_eae .Bottom ); -_ggga ,_bfc :=_cgb .Query ();if _bfc !=nil {return nil ,_bfc ;};_feg ,_ag :=_g .WithTimeout (_feg ,_fe .Second *15);defer _ag ();_gcbf ,_bfc :=_ae .ConvertHTML (_feg ,_ggga );if _bfc !=nil {return nil ,_bfc ;};_ded :=_gf .NewReader (_gcbf .Data );_fg ,_bfc :=_fb .NewPdfReader (_ded ); -if _bfc !=nil {return nil ,_bfc ;};return _fg .PageList ,nil ;}; - -// SetPos sets the absolute position. Changes object positioning to absolute. -func (_beb *Document )SetPos (x ,y float64 ){_beb ._ac =_eac .PositionAbsolute ;_beb ._ebc =x ;_beb ._fa =y ;}; \ No newline at end of file +func (_adgb *Document )GeneratePageBlocks (ctx _da .DrawContext )([]*_da .Block ,_da .DrawContext ,error ){if _ff :=_adgb .validate ();_ff !=nil {return nil ,ctx ,_ff ;};var _ag []*_da .Block ;_faf :=_adgb .getMargins ();_cca ,_cde :=_adgb ._gc ,_adgb ._fde ; +if _adgb ._fef .IsRelative (){_cca ,_cde =_ab .Point (ctx .Width ),_ab .Point (ctx .Height );ctx .X -=float64 (_faf .Left .Points ());};_caa ,_fbbb :=_adgb .extract (_f .Background (),_cca ,_cde ,_faf );if _fbbb !=nil {return nil ,_da .DrawContext {},_fbbb ; +};for _dbb ,_dd :=range _caa {_eea ,_gdg :=_da .NewBlockFromPage (_dd );if _gdg !=nil {return nil ,_da .DrawContext {},_gdg ;};var _fbc float64 ;if _adgb ._adg &&_dbb ==len (_caa )-1{_ea :=_cga .NewImageDevice ();_afd ,_bb :=_ea .Render (_dd );if _bb !=nil {return nil ,_da .DrawContext {},_bb ; +};_cdd ,_bb :=_dd .GetMediaBox ();if _bb !=nil {return nil ,_da .DrawContext {},_bb ;};_ef :=_cg .Now ();_feff :=_ffe (_afd );_fbc =_cdd .Height ()*_feff ;_ad .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_cg .Since (_ef )); +if _adgb ._fca .Bottom !=nil {_fbc -=float64 (_adgb ._fca .Bottom .Points ());};if _fbc < 0{_fbc =0;};_ad .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_fbc ); +};_ffb ,_ddf ,_gdg :=_eea .GeneratePageBlocks (ctx );if _gdg !=nil {return nil ,_da .DrawContext {},_gdg ;};ctx =_ddf ;ctx .Y -=_fbc ;if _dbb !=len (_caa )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; +ctx .Page ++;};_ag =append (_ag ,_ffb ...);};return _ag ,ctx ,nil ;};var ErrNoClient =_af .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");type margins struct{Left ,Right ,Bottom ,Top _ab .Length ; +}; \ No newline at end of file From f9fb6375e0e5402147a254dcb740aea4cb6768c6 Mon Sep 17 00:00:00 2001 From: UniDoc Build Date: Thu, 5 May 2022 21:25:46 +0000 Subject: [PATCH 2/9] prepare release --- cli/cmd/cmd.go | 74 ++++++------ cli/main.go | 2 +- client/client.go | 280 +++++++++++++++++++++---------------------- common/common.go | 6 +- content/content.go | 58 ++++----- go.mod | 13 +- go.sum | 64 +++++++--- selector/selector.go | 11 +- sizes/sizes.go | 249 +++++++++++++++++++------------------- unihtml.go | 157 ++++++++++++------------ 10 files changed, 479 insertions(+), 435 deletions(-) diff --git a/cli/cmd/cmd.go b/cli/cmd/cmd.go index 12dfa06..0f9baa4 100644 --- a/cli/cmd/cmd.go +++ b/cli/cmd/cmd.go @@ -9,55 +9,57 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package cmd ;import (_a "context";_c "fmt";_bf "github.com/mitchellh/go-homedir";_fc "github.com/spf13/cobra";_bb "github.com/spf13/viper";_ad "github.com/unidoc/unihtml/client";_cf "github.com/unidoc/unihtml/content";_fe "github.com/unidoc/unihtml/sizes"; -_fa "github.com/unidoc/unipdf/v3/common";_f "os";_aa "path/filepath";_b "time";);var _bd =&_fc .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_cfa ,Args :_fc .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; -func _ace (){_baf :=_fa .LogLevelInfo ;if _d {_baf =_fa .LogLevelDebug ;};if _fae {_baf =_fa .LogLevelTrace ;};_fa .Log =_fa .NewConsoleLogger (_baf );};var _gaf =&_fc .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; -type parametersConfig struct{ +package cmd ;import (_g "context";_dc "fmt";_ec "github.com/mitchellh/go-homedir";_c "github.com/spf13/cobra";_ab "github.com/spf13/viper";_ee "github.com/unidoc/unihtml/client";_dd "github.com/unidoc/unihtml/content";_a "github.com/unidoc/unihtml/sizes"; +_cc "github.com/unidoc/unipdf/v3/common";_d "os";_b "path/filepath";_f "time";);func _cdc (cmd *_c .Command ,_gg []string ){_fb :=_f .Now ();if _fe :=_ab .BindPFlags (cmd .Flags ());_fe !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_fe ); +_d .Exit (1);};if _ac :=_ab .Unmarshal (&_cd );_ac !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ac );_d .Exit (1);};_def ();_bg :=_f .Now ();_db ,_gb :=_d .Stat (_gg [0]);if _gb !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gb ); +_d .Exit (1);};if !_db .IsDir (){if _b .Ext (_db .Name ())!="\u002e\u0068\u0074m\u006c"{_dc .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_gg [0]); +_d .Exit (1);};};_bc ,_gb :=_d .OpenFile (_gg [1],_d .O_CREATE |_d .O_WRONLY |_d .O_TRUNC ,0700);if _gb !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gb );_d .Exit (1);};defer _bc .Close ();_fc :=_ee .New (_ee .Options {HTTPS :_cd .Https ,Hostname :_cd .Host ,Port :_cd .Port ,Prefix :_cd .Prefix }); +_fae ,_fcb :=_g .WithTimeout (_g .Background (),_f .Second *10);defer _fcb ();_bg =_f .Now ();var _fba _dd .Content ;if _db .IsDir (){_fba ,_gb =_dd .NewZipDirectory (_gg [0]);}else {_fba ,_gb =_dd .NewHTMLFile (_gg [0]);};if _gb !=nil {_dc .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_gb ); +_d .Exit (1);};_df ,_gb :=_ee .BuildHTMLQuery ().PaperWidth (_cg .PaperWidth .Length ).PaperHeight (_cg .PaperHeight .Length ).PageSize (_cg .PageSize ).MarginTop (_cg .MarginTop .Length ).MarginBottom (_cg .MarginBottom .Length ).MarginLeft (_cg .MarginLeft .Length ).MarginRight (_cg .MarginRight .Length ).Orientation (_cg .Orientation ).SetContent (_fba ).Query (); +if _gb !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gb );_d .Exit (1);};_dg ,_gb :=_fc .ConvertHTML (_fae ,_df );if _gb !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gb );_d .Exit (1);};_cc .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_f .Since (_bg )); +_bg =_f .Now ();_ ,_gb =_bc .Write (_dg .Data );if _gb !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gb );_d .Exit (1);};_cc .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_f .Since (_bg )); +_dc .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_f .Since (_fb ));};var (_cd =generateConfig {};_cg =parametersConfig {PaperWidth :_a .LengthFlag {Length :_a .Inch (8.5).Millimeters ()},PaperHeight :_a .LengthFlag {Length :_a .Inch (11).Millimeters ()},Orientation :_a .Portrait ,MarginTop :_a .LengthFlag {Length :_a .Millimeter (10)},MarginBottom :_a .LengthFlag {Length :_a .Millimeter (10)},MarginLeft :_a .LengthFlag {Length :_a .Millimeter (10)},MarginRight :_a .LengthFlag {Length :_a .Millimeter (10)}}; +); + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute (){if _ce :=_de .Execute ();_ce !=nil {_dc .Println (_ce );_d .Exit (1);};};func _def (){_fcg :=_cc .LogLevelInfo ;if _fad {_fcg =_cc .LogLevelDebug ;};if _ca {_fcg =_cc .LogLevelTrace ;};_cc .Log =_cc .NewConsoleLogger (_fcg );};func init (){_de .AddCommand (_fa ); +_fa .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072");_fa .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); +_fa .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); +_fa .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); +_fa .Flags ().Var (&_cg .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_fa .Flags ().Var (&_cg .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); +_fa .Flags ().Var (&_cg .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_fa .Flags ().Var (&_cg .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); +_fa .Flags ().Var (&_cg .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_fa .Flags ().Var (&_cg .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); +_fa .Flags ().Var (&_cg .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_fa .Flags ().Var (&_cg .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); +};var _fa =&_c .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_cdc ,Args :_c .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; +var (_fad ,_ca bool ;);type parametersConfig struct{ // PaperWidth sets the width of the paper. -PaperWidth _fe .LengthFlag `mapstructure:"paper-width"`; +PaperWidth _a .LengthFlag `mapstructure:"paper-width"`; // PaperHeight is the height of the output paper. -PaperHeight _fe .LengthFlag `mapstructure:"paper-height"`; +PaperHeight _a .LengthFlag `mapstructure:"paper-height"`; // PageSize is the page size string. -PageSize _fe .PageSize `mapstructure:"page-size"`; +PageSize _a .PageSize `mapstructure:"page-size"`; // Orientation defines if the output should be in a landscape format. -Orientation _fe .Orientation `mapstructure:"orientation"`; +Orientation _a .Orientation `mapstructure:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _fe .LengthFlag `mapstructure:"margin-top"`; +MarginTop _a .LengthFlag `mapstructure:"margin-top"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _fe .LengthFlag `mapstructure:"margin-bottom"`; +MarginBottom _a .LengthFlag `mapstructure:"margin-bottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _fe .LengthFlag `mapstructure:"margin-left"`; +MarginLeft _a .LengthFlag `mapstructure:"margin-left"`; // MarginRight sets up the Right Margin for the output. -MarginRight _fe .LengthFlag `mapstructure:"margin-right"`;};func init (){_gaf .AddCommand (_bd );_bd .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072"); -_bd .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); -_bd .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); -_bd .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); -_bd .Flags ().Var (&_fea .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_bd .Flags ().Var (&_fea .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); -_bd .Flags ().Var (&_fea .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_bd .Flags ().Var (&_fea .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); -_bd .Flags ().Var (&_fea .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_bd .Flags ().Var (&_fea .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); -_bd .Flags ().Var (&_fea .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_bd .Flags ().Var (&_fea .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); -};func _bbd (){if _acb !=""{_bb .SetConfigFile (_acb );}else {_dc ,_ccd :=_bf .Dir ();if _ccd !=nil {_c .Println (_ccd );_f .Exit (1);};_bb .AddConfigPath (_dc );_bb .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063"); -};_bb .AutomaticEnv ();if _gd :=_bb .ReadInConfig ();_gd ==nil {_c .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_bb .ConfigFileUsed ());};};var _acb string ; - -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. -func Execute (){if _gc :=_gaf .Execute ();_gc !=nil {_c .Println (_gc );_f .Exit (1);};};type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`; -};var (_d ,_fae bool ;);func init (){_fc .OnInitialize (_bbd );_gaf .PersistentFlags ().BoolVarP (&_d ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065");_gaf .PersistentFlags ().BoolVarP (&_fae ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); -_gaf .PersistentFlags ().StringVar (&_acb ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); -_gaf .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};var (_ca =generateConfig {};_fea =parametersConfig {PaperWidth :_fe .LengthFlag {Length :_fe .Inch (8.5).Millimeters ()},PaperHeight :_fe .LengthFlag {Length :_fe .Inch (11).Millimeters ()},Orientation :_fe .Portrait ,MarginTop :_fe .LengthFlag {Length :_fe .Millimeter (10)},MarginBottom :_fe .LengthFlag {Length :_fe .Millimeter (10)},MarginLeft :_fe .LengthFlag {Length :_fe .Millimeter (10)},MarginRight :_fe .LengthFlag {Length :_fe .Millimeter (10)}}; -);func _cfa (cmd *_fc .Command ,_cc []string ){_fb :=_b .Now ();if _ff :=_bb .BindPFlags (cmd .Flags ());_ff !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ff );_f .Exit (1);};if _ga :=_bb .Unmarshal (&_ca );_ga !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ga ); -_f .Exit (1);};_ace ();_ab :=_b .Now ();_eg ,_ag :=_f .Stat (_cc [0]);if _ag !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ag );_f .Exit (1);};if !_eg .IsDir (){if _aa .Ext (_eg .Name ())!="\u002e\u0068\u0074m\u006c"{_c .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_cc [0]); -_f .Exit (1);};};_bg ,_ag :=_f .OpenFile (_cc [1],_f .O_CREATE |_f .O_WRONLY |_f .O_TRUNC ,0700);if _ag !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ag );_f .Exit (1);};defer _bg .Close ();_ba :=_ad .New (_ad .Options {HTTPS :_ca .Https ,Hostname :_ca .Host ,Port :_ca .Port ,Prefix :_ca .Prefix }); -_fee ,_gg :=_a .WithTimeout (_a .Background (),_b .Second *10);defer _gg ();_ab =_b .Now ();var _bag _cf .Content ;if _eg .IsDir (){_bag ,_ag =_cf .NewZipDirectory (_cc [0]);}else {_bag ,_ag =_cf .NewHTMLFile (_cc [0]);};if _ag !=nil {_c .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_ag ); -_f .Exit (1);};_abe ,_ag :=_ad .BuildHTMLQuery ().PaperWidth (_fea .PaperWidth .Length ).PaperHeight (_fea .PaperHeight .Length ).PageSize (_fea .PageSize ).MarginTop (_fea .MarginTop .Length ).MarginBottom (_fea .MarginBottom .Length ).MarginLeft (_fea .MarginLeft .Length ).MarginRight (_fea .MarginRight .Length ).Orientation (_fea .Orientation ).SetContent (_bag ).Query (); -if _ag !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ag );_f .Exit (1);};_be ,_ag :=_ba .ConvertHTML (_fee ,_abe );if _ag !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ag );_f .Exit (1);};_fa .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_b .Since (_ab )); -_ab =_b .Now ();_ ,_ag =_bg .Write (_be .Data );if _ag !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ag );_f .Exit (1);};_fa .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_b .Since (_ab )); -_c .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_b .Since (_fb ));}; \ No newline at end of file +MarginRight _a .LengthFlag `mapstructure:"margin-right"`;};var _de =&_c .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; +var _bb string ;func init (){_c .OnInitialize (_bf );_de .PersistentFlags ().BoolVarP (&_fad ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065");_de .PersistentFlags ().BoolVarP (&_ca ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); +_de .PersistentFlags ().StringVar (&_bb ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); +_de .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};type generateConfig struct{Port int `mapstructure:"port"`; +Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};func _bf (){if _bb !=""{_ab .SetConfigFile (_bb );}else {_cb ,_fcge :=_ec .Dir ();if _fcge !=nil {_dc .Println (_fcge );_d .Exit (1);};_ab .AddConfigPath (_cb ); +_ab .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063");};_ab .AutomaticEnv ();if _cgg :=_ab .ReadInConfig ();_cgg ==nil {_dc .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_ab .ConfigFileUsed ()); +};}; \ No newline at end of file diff --git a/cli/main.go b/cli/main.go index f0b00cc..7ce4592 100644 --- a/cli/main.go +++ b/cli/main.go @@ -9,4 +9,4 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package main ;import _g "github.com/unidoc/unihtml/cli/cmd";func main (){_g .Execute ()}; \ No newline at end of file +package main ;import _ca "github.com/unidoc/unihtml/cli/cmd";func main (){_ca .Execute ()}; \ No newline at end of file diff --git a/client/client.go b/client/client.go index 8ebde68..d98620b 100644 --- a/client/client.go +++ b/client/client.go @@ -11,198 +11,198 @@ // Package client contains HTML Converter HTTP Client. The Client implements htmlcreator.HTMLConverter interface // for the UniPDF module and can be used as a plugin for the UniPDF creator.Creator. -package client ;import (_bb "bytes";_fb "compress/flate";_db "compress/gzip";_d "context";_a "encoding/json";_b "errors";_eg "fmt";_dg "github.com/unidoc/unihtml/content";_bd "github.com/unidoc/unihtml/selector";_dc "github.com/unidoc/unihtml/sizes";_fe "github.com/unidoc/unipdf/v3/common"; -_ea "golang.org/x/xerrors";_f "io/ioutil";_fcf "net";_e "net/http";_fc "net/url";_bg "strconv";_c "strings";_af "time";); +package client ;import (_db "bytes";_b "compress/flate";_cc "compress/gzip";_e "context";_ee "encoding/json";_d "errors";_gcg "fmt";_adf "github.com/unidoc/unihtml/content";_eb "github.com/unidoc/unihtml/selector";_gf "github.com/unidoc/unihtml/sizes"; +_bg "github.com/unidoc/unipdf/v3/common";_c "io/ioutil";_ccf "net";_ea "net/http";_gc "net/url";_ge "strconv";_g "strings";_ad "time";); -// WaitReady waits for the selector to get ready - 'loaded'. -func (_eee *QueryBuilder )WaitReady (selector string ,by _bd .ByType )*QueryBuilder {_eee ._cb .RenderParameters .WaitReady =append (_eee ._cb .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _eee ;};var (ErrNotFound =_b .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed"); -ErrBadRequest =_b .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074");ErrNotImplemented =_b .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_b .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072"); -ErrBadGateway =_b .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079");ErrUnauthorized =_b .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_b .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074"); -);type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`;Method string `json:"method"`;ExpiresAt int64 `json:"expiresAt"`;PageParameters ;RenderParameters ;}; - -// Validate checks validity of the selector. -func (_ee BySelector )Validate ()error {if _ee .Selector ==""{return _b .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _fca :=_ee .By .Validate ();_fca !=nil {return _fca ; -};return nil ;}; - -// RenderParameters are the parameters related with the rendering. -type RenderParameters struct{WaitTime _af .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; - -// BySelector is a structure that defines a selector with it's query 'by' type. -type BySelector struct{Selector string `json:"selector"`;By _bd .ByType `json:"by"`;}; - -// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. -type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;};func (_gb *Client )setQueryValues (_ffc *_e .Request ,_ce *Query ){_afb :=_ffc .URL .Query ();_dgb :=_ce .PageParameters ; -if _dgb .PageSize !=nil {_afb .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_dgb .PageSize .String ());};if _dgb .PaperHeight !=nil {_afb .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_dgb .PaperHeight .String ());}; -if _dgb .PaperWidth !=nil {_afb .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_dgb .PaperWidth .String ());};if _dgb .MarginTop !=nil {_afb .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_dgb .MarginTop .String ()); -};if _dgb .MarginBottom !=nil {_afb .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_dgb .MarginBottom .String ());};if _dgb .MarginRight !=nil {_afb .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_dgb .MarginRight .String ()); -};if _dgb .MarginLeft !=nil {_afb .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_dgb .MarginLeft .String ());};if _dgb .Orientation ==_dc .Landscape {_afb .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_dgb .Orientation .String ()); -};if _ce .RenderParameters .WaitTime !=0{_afb .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_bg .FormatInt (int64 (_ce .RenderParameters .WaitTime /_af .Millisecond ),10));};_ffc .URL .RawQuery =_afb .Encode (); -}; +// New creates new client with provided options. +func New (o Options )*Client {o .DefaultTimeout =_ad .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _fb =&_ea .Transport {DialContext :(&_ccf .Dialer {Timeout :5*_ad .Second }).DialContext ,TLSHandshakeTimeout :5*_ad .Second }; +_bg .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_ea .Client {Transport :_fb ,Timeout :o .DefaultTimeout }};}; // Query gets the Query from provided query builder. If some error occurred during build process // or the input is not valid the function would return an error. -func (_cf *QueryBuilder )Query ()(*Query ,error ){if _da :=_cf .Validate ();_da !=nil {return nil ,_da ;};return &_cf ._cb ,nil ;}; - -// MarginLeft sets up the MarginLeft parameter for the query. -func (_cbf *QueryBuilder )MarginLeft (marginLeft _dc .Length )*QueryBuilder {_cbf ._cb .PageParameters .MarginLeft =marginLeft ;return _cbf ;}; +func (_cd *QueryBuilder )Query ()(*Query ,error ){if _efd :=_cd .Validate ();_efd !=nil {return nil ,_efd ;};return &_cd ._dbc ,nil ;}; -// Client is a structure that is a HTTP client for the unihtml server. -type Client struct{Options Options ;Client *_e .Client ;}; - -// QueryBuilder is the query that converts HTMLConverter defined data -type QueryBuilder struct{_cb Query ;_gdg error ;}; - -// Validate checks if provided Query is valid. -func (_fed *Query )Validate ()error {switch _fed .Method {case "\u0077\u0065\u0062":if _fed .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_fed .Content )==0{return ErrMissingData ;};if _fed .ContentType ==""{return ErrContentType ; -};default:return _eg .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_fed .Method );};if _be :=_fed .PageParameters .Validate (); -_be !=nil {return _be ;};if _gg :=_fed .RenderParameters .Validate ();_gg !=nil {return _gg ;};return nil ;}; - -// MarginTop sets up the MarginTop parameter for the query. -func (_ccg *QueryBuilder )MarginTop (marginTop _dc .Length )*QueryBuilder {_ccg ._cb .PageParameters .MarginTop =marginTop ;return _ccg ;}; +// WithPort sets the Port option for the client options. +func WithPort (option int )Option {return func (_gbg *Options ){_gbg .Port =option }}; -// WithDefaultTimeout sets the DefaultTimeout option for the client options. -func WithDefaultTimeout (option _af .Duration )Option {return func (_dca *Options ){_dca .DefaultTimeout =option };}; +// WaitTime sets the minimum load time parameter for the page rendering. +func (_gg *QueryBuilder )WaitTime (d _ad .Duration )*QueryBuilder {_gg ._dbc .RenderParameters .WaitTime =d ;return _gg ;};var (ErrNotFound =_d .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_d .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); +ErrNotImplemented =_d .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_d .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_d .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079"); +ErrUnauthorized =_d .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_d .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); -// PaperHeight sets up the PaperHeight (in cm) parameter for the query. -func (_bc *QueryBuilder )PaperHeight (paperHeight _dc .Length )*QueryBuilder {_bc ._cb .PageParameters .PaperHeight =paperHeight ;return _bc ;}; +// DefaultPageParameters creates default parameters. +func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_gf .Portrait }}; // Portrait sets up the portrait page orientation. -func (_cff *QueryBuilder )Portrait ()*QueryBuilder {_cff ._cb .PageParameters .Orientation =_dc .Portrait ;return _cff ;}; +func (_ccae *QueryBuilder )Portrait ()*QueryBuilder {_ccae ._dbc .PageParameters .Orientation =_gf .Portrait ;return _ccae ;}; -// New creates new client with provided options. -func New (o Options )*Client {o .DefaultTimeout =_af .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _cde =&_e .Transport {DialContext :(&_fcf .Dialer {Timeout :5*_af .Second }).DialContext ,TLSHandshakeTimeout :5*_af .Second }; -_fe .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_e .Client {Transport :_cde ,Timeout :o .DefaultTimeout }};}; +// Options are the client options used by the HTTP client. +type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _ad .Duration ;Prefix string ;}; -// PaperWidth sets up the PaperWidth (in cm) parameter for the query. -func (_cbee *QueryBuilder )PaperWidth (paperWidth _dc .Length )*QueryBuilder {_cbee ._cb .PageParameters .PaperWidth =paperWidth ;return _cbee ;}; +// Err gets the error which could occur in the query. +func (_ga *QueryBuilder )Err ()error {return _ga ._dc };func (_fbbf *Client )setQueryValues (_eeb *_ea .Request ,_fga *Query ){_bgg :=_eeb .URL .Query ();_gb :=_fga .PageParameters ;if _gb .PageSize !=nil {_bgg .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_gb .PageSize .String ()); +};if _gb .PaperHeight !=nil {_bgg .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_gb .PaperHeight .String ());};if _gb .PaperWidth !=nil {_bgg .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_gb .PaperWidth .String ()); +};if _gb .MarginTop !=nil {_bgg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_gb .MarginTop .String ());};if _gb .MarginBottom !=nil {_bgg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_gb .MarginBottom .String ()); +};if _gb .MarginRight !=nil {_bgg .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_gb .MarginRight .String ());};if _gb .MarginLeft !=nil {_bgg .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_gb .MarginLeft .String ()); +};if _gb .Orientation ==_gf .Landscape {_bgg .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_gb .Orientation .String ());};if _fga .RenderParameters .WaitTime !=0{_bgg .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_ge .FormatInt (int64 (_fga .RenderParameters .WaitTime /_ad .Millisecond ),10)); +};_eeb .URL .RawQuery =_bgg .Encode ();}; -// Addr gets the HTTP address URI used by the http.Client. -func (_dfd *Options )Addr ()string {_eab :=_c .Builder {};_eab .WriteString ("\u0068\u0074\u0074\u0070");if _dfd .HTTPS {_eab .WriteRune ('s');};_eab .WriteString ("\u003a\u002f\u002f");_eab .WriteString (_dfd .Hostname );_eab .WriteRune (':');_eab .WriteString (_bg .Itoa (_dfd .Port )); -if _dfd .Prefix !=""{_eab .WriteString (_dfd .Prefix );};return _eab .String ();}; +// Orientation sets the page orientation for the Query. +func (_geff *QueryBuilder )Orientation (orientation _gf .Orientation )*QueryBuilder {_geff ._dbc .PageParameters .Orientation =orientation ;return _geff ;};var (ErrMissingData =_d .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061"); +ErrContentType =_d .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065");ErrContentTypeDeclared =_d .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064"); +); -// Option is a function that changes client options. -type Option func (_faf *Options );func (_ed *Client )getGenerateRequest (_bf _d .Context ,_ec *Query )(*_e .Request ,error ){_fg :=generatePDFRequestV1 {Method :_ec .Method ,PageParameters :_ec .PageParameters ,RenderParameters :_ec .RenderParameters }; -switch _ec .Method {case "\u0077\u0065\u0062":_fg .ContentURL =_ec .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_fg .ContentType =_ec .ContentType ;_fg .Content =_ec .Content ;};_dff :=new (_bb .Buffer );if _eda :=_a .NewEncoder (_dff ).Encode (&_fg ); -_eda !=nil {return nil ,_ea .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_eda );};_fa :=_ed .Options .Addr ();_fa =_eg .Sprintf ("%\u0073\u002f\u0062\u0065\u0074\u0061\u002f\u0070\u0064\u0066",_fa ); -_fea ,_cdca :=_e .NewRequest ("\u0050\u004f\u0053\u0054",_fa ,_dff );if _cdca !=nil {return nil ,_cdca ;};_fea .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); -_fea .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); -_fea =_fea .WithContext (_bf );return _fea ,nil ;}; +// Validate checks the validity of the RenderParameters. +func (_cge *RenderParameters )Validate ()error {if _cge .WaitTime > _ad .Minute *3{return _d .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); +};for _ ,_bc :=range _cge .WaitReady {if _cgeb :=_bc .Validate ();_cgeb !=nil {return _gcg .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_cgeb ); +};};return nil ;}; + +// Validate checks if provided Query is valid. +func (_caf *Query )Validate ()error {switch _caf .Method {case "\u0077\u0065\u0062":if _caf .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_caf .Content )==0{return ErrMissingData ;};if _caf .ContentType ==""{return ErrContentType ; +};default:return _gcg .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_caf .Method );};if _cca :=_caf .PageParameters .Validate (); +_cca !=nil {return _cca ;};if _ebe :=_caf .RenderParameters .Validate ();_ebe !=nil {return _ebe ;};return nil ;}; // ConvertHTML converts provided Query input into PDF file data. // Implements creator.HTMLConverter interface. -func (_gc *Client )ConvertHTML (ctx _d .Context ,q *Query )(*PDFResponse ,error ){if _bbe :=q .Validate ();_bbe !=nil {return nil ,_bbe ;};_gf ,_bbc :=_gc .getGenerateRequest (ctx ,q );if _bbc !=nil {return nil ,_bbc ;};_fe .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_gf .Method ,_gf .URL .Hostname (),_gf .URL .Path ,_gf .Header ,_gf .URL .Query ()); -_fd ,_bbc :=_gc .Client .Do (_gf );if _bbc !=nil {return nil ,_bbc ;};var _gfe error ;switch _fd .StatusCode {case _e .StatusNotFound :_gfe =ErrNotFound ;case _e .StatusBadRequest :_gfe =ErrBadRequest ;case _e .StatusNotImplemented :_gfe =ErrNotImplemented ; -case _e .StatusUnauthorized :_gfe =ErrUnauthorized ;case _e .StatusRequestTimeout :_gfe =ErrTimedOut ;case _e .StatusCreated :default:_gfe =ErrInternalError ;};_fbg :=_fd .Body ;switch _fd .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_fbg ,_bbc =_db .NewReader (_fd .Body ); -if _bbc !=nil {return nil ,_bbc ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_fbg =_fb .NewReader (_fd .Body );case "":default:return nil ,_eg .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_fd .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); -};_eae ,_bbc :=_f .ReadAll (_fbg );if _bbc !=nil &&_gfe ==nil {return nil ,_eg .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_bbc );};_fe .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_fd .StatusCode ,_gf .Method ,_gf .URL .Host ,_gf .URL .Path ); -if _gfe !=nil {return nil ,_eg .Errorf ("\u0025\u0073\u0020%\u0077",string (_eae ),_gfe );};_ff :=_fd .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_fe .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_ff ); -return &PDFResponse {ID :_ff ,Data :_eae },nil ;}; +func (_ca *Client )ConvertHTML (ctx _e .Context ,q *Query )(*PDFResponse ,error ){if _gfb :=q .Validate ();_gfb !=nil {return nil ,_gfb ;};_bb ,_ef :=_ca .getGenerateRequest (ctx ,q );if _ef !=nil {return nil ,_ef ;};_bg .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_bb .Method ,_bb .URL .Hostname (),_bb .URL .Path ,_bb .Header ,_bb .URL .Query ()); +_af ,_ef :=_ca .Client .Do (_bb );if _ef !=nil {return nil ,_ef ;};var _ec error ;switch _af .StatusCode {case _ea .StatusNotFound :_ec =ErrNotFound ;case _ea .StatusBadRequest :_ec =ErrBadRequest ;case _ea .StatusNotImplemented :_ec =ErrNotImplemented ; +case _ea .StatusUnauthorized :_ec =ErrUnauthorized ;case _ea .StatusRequestTimeout :_ec =ErrTimedOut ;case _ea .StatusCreated :default:_ec =ErrInternalError ;};_bga :=_af .Body ;switch _af .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_bga ,_ef =_cc .NewReader (_af .Body ); +if _ef !=nil {return nil ,_ef ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_bga =_b .NewReader (_af .Body );case "":default:return nil ,_gcg .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_af .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); +};_ba ,_ef :=_c .ReadAll (_bga );if _ef !=nil &&_ec ==nil {return nil ,_gcg .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_ef );};_bg .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_af .StatusCode ,_bb .Method ,_bb .URL .Host ,_bb .URL .Path ); +if _ec !=nil {return nil ,_gcg .Errorf ("\u0025\u0073\u0020%\u0077",string (_ba ),_ec );};_cg :=_af .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_bg .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_cg ); +return &PDFResponse {ID :_cg ,Data :_ba },nil ;}; -// Landscape sets up the landscape portrait orientation. -func (_ef *QueryBuilder )Landscape ()*QueryBuilder {_ef ._cb .PageParameters .Orientation =_dc .Landscape ;return _ef ;}; +// QueryBuilder is the query that converts HTMLConverter defined data +type QueryBuilder struct{_dbc Query ;_dc error ;}; // WithPrefix sets the client prefix. -func WithPrefix (prefix string )Option {return func (_ecf *Options ){_ecf .Prefix =prefix }}; +func WithPrefix (prefix string )Option {return func (_aag *Options ){_aag .Prefix =prefix }}; // WithHTTPS sets the TLS option for the client options. -func WithHTTPS (useHTTPS bool )Option {return func (_ffe *Options ){_ffe .HTTPS =useHTTPS }}; - -// MarginRight sets up the MarginRight parameter for the query. -func (_cee *QueryBuilder )MarginRight (marginRight _dc .Length )*QueryBuilder {_cee ._cb .PageParameters .MarginRight =marginRight ;return _cee ;}; - -// WaitVisible waits for the selector to get visible. -func (_edf *QueryBuilder )WaitVisible (selector string ,by _bd .ByType )*QueryBuilder {_edf ._cb .RenderParameters .WaitVisible =append (_edf ._cb .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _edf ;}; - -// Options are the client options used by the HTTP client. -type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _af .Duration ;Prefix string ;}; - -// WithHostname sets the Hostname option for the client options. -func WithHostname (option string )Option {return func (_dce *Options ){_dce .Hostname =option }}; - -// PageSize sets up the PageSize parameter for the query. -func (_fba *QueryBuilder )PageSize (pageSize _dc .PageSize )*QueryBuilder {if pageSize !=_dc .Undefined {_fba ._cb .PageParameters .PageSize =&pageSize ;};return _fba ;}; - -// PDFResponse is the response used by the HTMLConverter. -type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; - -// Validate checks if the parameters are valid. -func (_eca *PageParameters )Validate ()error {if _eca .PaperWidth !=nil {if _eca .PaperWidth .Millimeters ()< 0{return _b .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); -};};if _eca .PaperHeight !=nil {if _eca .PaperHeight .Millimeters ()< 0{return _b .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); -};};if _eca .MarginTop !=nil {if _eca .MarginTop .Millimeters ()< 0{return _b .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _eca .MarginBottom !=nil {if _eca .MarginBottom .Millimeters ()< 0{return _b .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); -};};if _eca .MarginLeft !=nil {if _eca .MarginLeft .Millimeters ()< 0{return _b .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};}; -if _eca .MarginRight !=nil {if _eca .MarginRight .Millimeters ()< 0{return _b .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); -};};if _eca .PageSize !=nil &&!_eca .PageSize .IsAPageSize (){return _b .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; +func WithHTTPS (useHTTPS bool )Option {return func (_gcf *Options ){_gcf .HTTPS =useHTTPS }}; // PageParameters are the query parameters used in the PDF generation. type PageParameters struct{ // PaperWidth sets the width of the paper. -PaperWidth _dc .Length `schema:"paper-width" json:"paperWidth"`; +PaperWidth _gf .Length `schema:"paper-width" json:"paperWidth"`; // PaperHeight is the height of the output paper. -PaperHeight _dc .Length `schema:"paper-height" json:"paperHeight"`; +PaperHeight _gf .Length `schema:"paper-height" json:"paperHeight"`; // PageSize is the page size string. -PageSize *_dc .PageSize `schema:"page-size" json:"pageSize"`; +PageSize *_gf .PageSize `schema:"page-size" json:"pageSize"`; // Orientation defines if the output should be in a landscape format. -Orientation _dc .Orientation `schema:"orientation" json:"orientation"`; +Orientation _gf .Orientation `schema:"orientation" json:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _dc .Length `schema:"margin-top" json:"marginTop"`; +MarginTop _gf .Length `schema:"margin-top" json:"marginTop"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _dc .Length `schema:"margin-bottom" json:"marginBottom"`; +MarginBottom _gf .Length `schema:"margin-bottom" json:"marginBottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _dc .Length `schema:"margin-left" json:"marginLeft"`; +MarginLeft _gf .Length `schema:"margin-left" json:"marginLeft"`; // MarginRight sets up the Right Margin for the output. -MarginRight _dc .Length `schema:"margin-right" json:"marginRight"`;}; +MarginRight _gf .Length `schema:"margin-right" json:"marginRight"`;};func (_de *Client )getGenerateRequest (_aga _e .Context ,_ce *Query )(*_ea .Request ,error ){_fbb :=generatePDFRequestV1 {Method :_ce .Method ,PageParameters :_ce .PageParameters ,RenderParameters :_ce .RenderParameters }; +switch _ce .Method {case "\u0077\u0065\u0062":_fbb .ContentURL =_ce .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_fbb .ContentType =_ce .ContentType ;_fbb .Content =_ce .Content ;};_eef :=new (_db .Buffer );if _eg :=_ee .NewEncoder (_eef ).Encode (&_fbb ); +_eg !=nil {return nil ,_gcg .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_eg );};_aa :=_de .Options .Addr ();_aa =_gcg .Sprintf ("%\u0073\u002f\u0062\u0065\u0074\u0061\u002f\u0070\u0064\u0066",_aa ); +_fg ,_efg :=_ea .NewRequest ("\u0050\u004f\u0053\u0054",_aa ,_eef );if _efg !=nil {return nil ,_efg ;};_fg .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); +_fg .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); +_fg =_fg .WithContext (_aga );return _fg ,nil ;}; + +// SetContent sets custom data with it's content type. +func (_abg *QueryBuilder )SetContent (content _adf .Content )*QueryBuilder {if _abg ._dc !=nil {return _abg ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _abg ._dbc .ContentType !=""{_abg ._dc =ErrContentTypeDeclared ; +return _abg ;};if content .ContentType ()==""{_abg ._dc =_gcg .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _abg ; +};_abg ._dbc .Content =content .Data ();_abg ._dbc .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _abg ._dbc .ContentType !=""{_abg ._dc =ErrContentTypeDeclared ;return _abg ;};_abg ._dbc .URL =string (content .Data ());_abg ._dbc .ContentType =content .ContentType (); +default:_abg ._dc =_gcg .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ());return _abg ;};_abg ._dbc .Method =content .Method (); +return _abg ;}; + +// BuildHTMLQuery creates a Query builder that is supposed to create valid +func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`;Method string `json:"method"`;ExpiresAt int64 `json:"expiresAt"`; +PageParameters ;RenderParameters ;}; + +// MarginTop sets up the MarginTop parameter for the query. +func (_dfb *QueryBuilder )MarginTop (marginTop _gf .Length )*QueryBuilder {_dfb ._dbc .PageParameters .MarginTop =marginTop ;return _dfb ;}; + +// Option is a function that changes client options. +type Option func (_ae *Options ); + +// WaitReady waits for the selector to get ready - 'loaded'. +func (_bac *QueryBuilder )WaitReady (selector string ,by _eb .ByType )*QueryBuilder {_bac ._dbc .RenderParameters .WaitReady =append (_bac ._dbc .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _bac ;}; // Validate checks if the QueryBuilder had no errors during composition and creation. -func (_cdcg *QueryBuilder )Validate ()error {if _cdcg ._gdg !=nil {return _cdcg ._gdg ;};return _cdcg ._cb .Validate ();}; +func (_gef *QueryBuilder )Validate ()error {if _gef ._dc !=nil {return _gef ._dc ;};return _gef ._dbc .Validate ();}; -// Err gets the error which could occur in the query. -func (_cbe *QueryBuilder )Err ()error {return _cbe ._gdg }; +// MarginBottom sets up the MarginBottom parameter for the query. +func (_ceb *QueryBuilder )MarginBottom (marginBottom _gf .Length )*QueryBuilder {_ceb ._dbc .PageParameters .MarginBottom =marginBottom ;return _ceb ;}; + +// PDFResponse is the response used by the HTMLConverter. +type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; + +// PaperHeight sets up the PaperHeight (in cm) parameter for the query. +func (_bdd *QueryBuilder )PaperHeight (paperHeight _gf .Length )*QueryBuilder {_bdd ._dbc .PageParameters .PaperHeight =paperHeight ;return _bdd ;}; + +// Landscape sets up the landscape portrait orientation. +func (_cgd *QueryBuilder )Landscape ()*QueryBuilder {_cgd ._dbc .PageParameters .Orientation =_gf .Landscape ;return _cgd ;}; + +// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. +type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;}; // HealthCheck connects to the server and check the health status of the server. -func (_df *Client )HealthCheck (ctx _d .Context )error {_cdc :=_df .Options .Addr ();_cdc =_eg .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_cdc );_ege ,_bga :=_e .NewRequest ("\u0047\u0045\u0054",_cdc ,nil );if _bga !=nil {return _bga ;};_ege =_ege .WithContext (ctx ); -_ga ,_bga :=_df .Client .Do (_ege );if _bga !=nil {return _bga ;};switch _ga .StatusCode {case _e .StatusOK :return nil ;case _e .StatusNotFound :return ErrNotFound ;case _e .StatusInternalServerError :return ErrInternalError ;case _e .StatusBadGateway :return ErrBadGateway ; +func (_ada *Client )HealthCheck (ctx _e .Context )error {_da :=_ada .Options .Addr ();_da =_gcg .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_da );_ab ,_be :=_ea .NewRequest ("\u0047\u0045\u0054",_da ,nil );if _be !=nil {return _be ;};_ab =_ab .WithContext (ctx ); +_bd ,_be :=_ada .Client .Do (_ab );if _be !=nil {return _be ;};switch _bd .StatusCode {case _ea .StatusOK :return nil ;case _ea .StatusNotFound :return ErrNotFound ;case _ea .StatusInternalServerError :return ErrInternalError ;case _ea .StatusBadGateway :return ErrBadGateway ; default:return ErrNotImplemented ;};}; -// WaitTime sets the minimum load time parameter for the page rendering. -func (_afe *QueryBuilder )WaitTime (d _af .Duration )*QueryBuilder {_afe ._cb .RenderParameters .WaitTime =d ;return _afe ;}; +// MarginLeft sets up the MarginLeft parameter for the query. +func (_gcd *QueryBuilder )MarginLeft (marginLeft _gf .Length )*QueryBuilder {_gcd ._dbc .PageParameters .MarginLeft =marginLeft ;return _gcd ;}; -// DefaultPageParameters creates default parameters. -func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_dc .Portrait }}; +// Client is a structure that is a HTTP client for the unihtml server. +type Client struct{Options Options ;Client *_ea .Client ;}; -// SetContent sets custom data with it's content type. -func (_feaa *QueryBuilder )SetContent (content _dg .Content )*QueryBuilder {if _feaa ._gdg !=nil {return _feaa ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _feaa ._cb .ContentType !=""{_feaa ._gdg =ErrContentTypeDeclared ; -return _feaa ;};if content .ContentType ()==""{_feaa ._gdg =_ea .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _feaa ; -};_feaa ._cb .Content =content .Data ();_feaa ._cb .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _feaa ._cb .ContentType !=""{_feaa ._gdg =ErrContentTypeDeclared ;return _feaa ;};_feaa ._cb .URL =string (content .Data ());_feaa ._cb .ContentType =content .ContentType (); -default:_feaa ._gdg =_ea .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ());return _feaa ;};_feaa ._cb .Method =content .Method (); -return _feaa ;}; +// Validate checks if the parameters are valid. +func (_fgg *PageParameters )Validate ()error {if _fgg .PaperWidth !=nil {if _fgg .PaperWidth .Millimeters ()< 0{return _d .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); +};};if _fgg .PaperHeight !=nil {if _fgg .PaperHeight .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); +};};if _fgg .MarginTop !=nil {if _fgg .MarginTop .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _fgg .MarginBottom !=nil {if _fgg .MarginBottom .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); +};};if _fgg .MarginLeft !=nil {if _fgg .MarginLeft .Millimeters ()< 0{return _d .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};}; +if _fgg .MarginRight !=nil {if _fgg .MarginRight .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); +};};if _fgg .PageSize !=nil &&!_fgg .PageSize .IsAPageSize (){return _d .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; -// BuildHTMLQuery creates a Query builder that is supposed to create valid -func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; +// PageSize sets up the PageSize parameter for the query. +func (_bde *QueryBuilder )PageSize (pageSize _gf .PageSize )*QueryBuilder {if pageSize !=_gf .Undefined {_bde ._dbc .PageParameters .PageSize =&pageSize ;};return _bde ;}; -// Orientation sets the page orientation for the Query. -func (_gge *QueryBuilder )Orientation (orientation _dc .Orientation )*QueryBuilder {_gge ._cb .PageParameters .Orientation =orientation ;return _gge ;}; +// WaitVisible waits for the selector to get visible. +func (_gab *QueryBuilder )WaitVisible (selector string ,by _eb .ByType )*QueryBuilder {_gab ._dbc .RenderParameters .WaitVisible =append (_gab ._dbc .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _gab ;}; -// MarginBottom sets up the MarginBottom parameter for the query. -func (_fbc *QueryBuilder )MarginBottom (marginBottom _dc .Length )*QueryBuilder {_fbc ._cb .PageParameters .MarginBottom =marginBottom ;return _fbc ;}; +// WithDefaultTimeout sets the DefaultTimeout option for the client options. +func WithDefaultTimeout (option _ad .Duration )Option {return func (_ade *Options ){_ade .DefaultTimeout =option };}; -// WithPort sets the Port option for the client options. -func WithPort (option int )Option {return func (_dga *Options ){_dga .Port =option }}; +// Addr gets the HTTP address URI used by the http.Client. +func (_fc *Options )Addr ()string {_fa :=_g .Builder {};_fa .WriteString ("\u0068\u0074\u0074\u0070");if _fc .HTTPS {_fa .WriteRune ('s');};_fa .WriteString ("\u003a\u002f\u002f");_fa .WriteString (_fc .Hostname );_fa .WriteRune (':');_fa .WriteString (_ge .Itoa (_fc .Port )); +if _fc .Prefix !=""{_fa .WriteString (_fc .Prefix );};return _fa .String ();}; -// ParseOptions parses options for the Client. -func ParseOptions (connectPath string )(Options ,error ){if !_c .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_cc ,_cd :=_fc .Parse (connectPath );if _cd !=nil {return Options {},_ea .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); -};var _ad int ;if _cc .Port ()!=""{_ad ,_cd =_bg .Atoi (_cc .Port ());if _cd !=nil {return Options {},_ea .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_cd ); -};};return Options {Hostname :_cc .Hostname (),Port :_ad ,HTTPS :_cc .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_cc .Path },nil ;}; +// RenderParameters are the parameters related with the rendering. +type RenderParameters struct{WaitTime _ad .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; -// Validate checks the validity of the RenderParameters. -func (_cdb *RenderParameters )Validate ()error {if _cdb .WaitTime > _af .Minute *3{return _b .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); -};for _ ,_dd :=range _cdb .WaitReady {if _gd :=_dd .Validate ();_gd !=nil {return _eg .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_gd ); -};};return nil ;};var (ErrMissingData =_b .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061");ErrContentType =_b .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065"); -ErrContentTypeDeclared =_b .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064");); \ No newline at end of file +// MarginRight sets up the MarginRight parameter for the query. +func (_ed *QueryBuilder )MarginRight (marginRight _gf .Length )*QueryBuilder {_ed ._dbc .PageParameters .MarginRight =marginRight ;return _ed ;}; + +// WithHostname sets the Hostname option for the client options. +func WithHostname (option string )Option {return func (_daf *Options ){_daf .Hostname =option }}; + +// PaperWidth sets up the PaperWidth (in cm) parameter for the query. +func (_gfg *QueryBuilder )PaperWidth (paperWidth _gf .Length )*QueryBuilder {_gfg ._dbc .PageParameters .PaperWidth =paperWidth ;return _gfg ;}; + +// Validate checks validity of the selector. +func (_fbe BySelector )Validate ()error {if _fbe .Selector ==""{return _d .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _ece :=_fbe .By .Validate ();_ece !=nil {return _ece ; +};return nil ;}; + +// BySelector is a structure that defines a selector with it's query 'by' type. +type BySelector struct{Selector string `json:"selector"`;By _eb .ByType `json:"by"`;}; + +// ParseOptions parses options for the Client. +func ParseOptions (connectPath string )(Options ,error ){if !_g .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_ag ,_df :=_gc .Parse (connectPath );if _df !=nil {return Options {},_gcg .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); +};var _f int ;if _ag .Port ()!=""{_f ,_df =_ge .Atoi (_ag .Port ());if _df !=nil {return Options {},_gcg .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_df );}; +};return Options {Hostname :_ag .Hostname (),Port :_f ,HTTPS :_ag .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_ag .Path },nil ;}; \ No newline at end of file diff --git a/common/common.go b/common/common.go index c3d32f3..bab43e1 100644 --- a/common/common.go +++ b/common/common.go @@ -10,8 +10,8 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package common contains common properties used by the subpackages. -package common ;import _b "time";const Version ="\u0030\u002e\u0035.\u0030"; +package common ;import _e "time";var ReleasedAt =_e .Date (_a ,_g ,_ea ,_dg ,_ab ,0,0,_e .UTC );const _dg =12;const Version ="\u0030\u002e\u0036.\u0030"; // UtcTimeFormat returns a formatted string describing a UTC timestamp. -func UtcTimeFormat (t _b .Time )string {return t .Format (_d )+"\u0020\u0055\u0054\u0043"};const _f =2021;const _fe =12;const _g =20;const _bb =8;const _d ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034"; -var ReleasedAt =_b .Date (_f ,_c ,_bb ,_fe ,_g ,0,0,_b .UTC );const _c =5; \ No newline at end of file +func UtcTimeFormat (t _e .Time )string {return t .Format (_f )+"\u0020\u0055\u0054\u0043"};const _ea =5;const _f ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";const _ab =20; +const _a =2022;const _g =5; \ No newline at end of file diff --git a/content/content.go b/content/content.go index e7075e8..2e6ed95 100644 --- a/content/content.go +++ b/content/content.go @@ -9,49 +9,49 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package content ;import (_c "archive/zip";_g "bytes";_cb "golang.org/x/xerrors";_ee "io/ioutil";_b "net/url";_f "os";_e "strings";);type webURL struct{_dc string }; +package content ;import (_a "archive/zip";_gc "bytes";_g "fmt";_de "io/ioutil";_c "net/url";_d "os";_f "strings";); -// NewHTMLFile creates new Content htmFile for provided input path. -func NewHTMLFile (path string )(Content ,error ){_a ,_ed :=_f .Open (path );if _ed !=nil {return nil ,_ed ;};_df :=&htmlFile {_cba :_g .Buffer {}};if _ ,_ed =_df ._cba .ReadFrom (_a );_ed !=nil {return nil ,_ed ;};return _df ,nil ;}; - -// ContentType implements Content interface. -func (_fe *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; +// Method gets the query method. +func (_gb *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"}; -// ContentType implements Content interface. -func (_ff *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";};type zipDirectory struct{_dcc _g .Buffer ;_ae *_c .Writer ;}; +// NewHTMLFile creates new Content htmFile for provided input path. +func NewHTMLFile (path string )(Content ,error ){_fb ,_e :=_d .Open (path );if _e !=nil {return nil ,_e ;};_ee :=&htmlFile {_ff :_gc .Buffer {}};if _ ,_e =_ee ._ff .ReadFrom (_fb );_e !=nil {return nil ,_e ;};return _ee ,nil ;}; // Data implements Content interface. -func (_fc *htmlFile )Data ()[]byte {return _fc ._cba .Bytes ()}; +func (_cd *webURL )Data ()[]byte {return []byte (_cd ._db )};type zipDirectory struct{_dd _gc .Buffer ;_bgg *_a .Writer ;}; // Data implements Content interface. -func (_bg *webURL )Data ()[]byte {return []byte (_bg ._dc )};func (_fa *zipDirectory )zipBasePaths (_cg _f .FileInfo ,_cbad ,_ab string ,_bf bool ,_gff *_e .Builder )(string ,string ){_gff .WriteString (_cbad );if !_e .HasSuffix (_cbad ,"\u002f"){_gff .WriteRune ('/'); -};_gff .WriteString (_cg .Name ());if _bf {_gff .WriteRune ('/');};_deb :=_gff .String ();_gff .Reset ();_gff .WriteString (_ab );_gff .WriteString (_cg .Name ());if _bf {_gff .WriteRune ('/');};_ba :=_gff .String ();_gff .Reset ();return _deb ,_ba ;}; - +func (_bg *htmlFile )Data ()[]byte {return _bg ._ff .Bytes ()}; // Method gets the zip directory method. -func (_ef *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; +func (_bgd *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; -// Method gets the query method. -func (_gg *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"}; +// ContentType implements Content interface. +func (_fd *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; -// Method gets the web url query method. -func (_cbb *webURL )Method ()string {return "\u0077\u0065\u0062"}; +// NewWebURL creates new Content webURL for provided input URL path. +func NewWebURL (path string )(Content ,error ){if _ ,_gg :=_c .Parse (path );_gg !=nil {return nil ,_gg ;};return &webURL {_db :path },nil ;}; // ContentType implements Content interface. -func (_de *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; +func (_fg *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; + +// NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' +// and stores in it's in-memory buffer. +func NewZipDirectory (dirPath string )(Content ,error ){_ga :=&zipDirectory {_dd :_gc .Buffer {}};_ga ._bgg =_a .NewWriter (&_ga ._dd );if _ec :=_ga .zipPath (dirPath ,"");_ec !=nil {return nil ,_ec ;};if _eeb :=_ga ._bgg .Close ();_eeb !=nil {return nil ,_eeb ; +};return _ga ,nil ;};func (_ac *zipDirectory )zipBasePaths (_dbf _d .FileInfo ,_bfe ,_ffc string ,_ece bool ,_gfb *_f .Builder )(string ,string ){_gfb .WriteString (_bfe );if !_f .HasSuffix (_bfe ,"\u002f"){_gfb .WriteRune ('/');};_gfb .WriteString (_dbf .Name ()); +if _ece {_gfb .WriteRune ('/');};_fbd :=_gfb .String ();_gfb .Reset ();_gfb .WriteString (_ffc );_gfb .WriteString (_dbf .Name ());if _ece {_gfb .WriteRune ('/');};_fge :=_gfb .String ();_gfb .Reset ();return _fbd ,_fge ;};type webURL struct{_db string }; + + +// Method gets the web url query method. +func (_df *webURL )Method ()string {return "\u0077\u0065\u0062"};func (_bda *zipDirectory )zipPath (_cg ,_eb string )error {_gad ,_gce :=_de .ReadDir (_cg );if _gce !=nil {return _g .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_cg ,_gce ); +};_bb :=&_f .Builder {};for _ ,_bf :=range _gad {_bbc ,_af :=_bda .zipBasePaths (_bf ,_cg ,_eb ,_bf .IsDir (),_bb );if _bf .IsDir (){if _gaf :=_bda .zipPath (_bbc ,_af );_gaf !=nil {return _gaf ;};continue ;};_dde ,_ffb :=_de .ReadFile (_bbc );if _ffb !=nil {return _ffb ; +};_bad ,_ffb :=_bda ._bgg .Create (_af );if _ffb !=nil {return _ffb ;};if _ ,_ffb =_bad .Write (_dde );_ffb !=nil {return _ffb ;};};return nil ;}; // Content is an interface used for putting the content into Client Query. type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;}; -// Data implements Content interface. -func (_ad *zipDirectory )Data ()[]byte {return _ad ._dcc .Bytes ()};type htmlFile struct{_cba _g .Buffer };func (_ec *zipDirectory )zipPath (_adb ,_ca string )error {_bd ,_bc :=_ee .ReadDir (_adb );if _bc !=nil {return _cb .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_adb ,_bc ); -};_afb :=&_e .Builder {};for _ ,_dg :=range _bd {_fgg ,_ggb :=_ec .zipBasePaths (_dg ,_adb ,_ca ,_dg .IsDir (),_afb );if _dg .IsDir (){if _ecg :=_ec .zipPath (_fgg ,_ggb );_ecg !=nil {return _ecg ;};continue ;};_afa ,_aa :=_ee .ReadFile (_fgg );if _aa !=nil {return _aa ; -};_da ,_aa :=_ec ._ae .Create (_ggb );if _aa !=nil {return _aa ;};if _ ,_aa =_da .Write (_afa );_aa !=nil {return _aa ;};};return nil ;}; - -// NewWebURL creates new Content webURL for provided input URL path. -func NewWebURL (path string )(Content ,error ){if _ ,_af :=_b .Parse (path );_af !=nil {return nil ,_af ;};return &webURL {_dc :path },nil ;}; +// ContentType implements Content interface. +func (_bd *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; -// NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' -// and stores in it's in-memory buffer. -func NewZipDirectory (dirPath string )(Content ,error ){_cd :=&zipDirectory {_dcc :_g .Buffer {}};_cd ._ae =_c .NewWriter (&_cd ._dcc );if _fg :=_cd .zipPath (dirPath ,"");_fg !=nil {return nil ,_fg ;};if _gf :=_cd ._ae .Close ();_gf !=nil {return nil ,_gf ; -};return _cd ,nil ;}; \ No newline at end of file +// Data implements Content interface. +func (_ba *zipDirectory )Data ()[]byte {return _ba ._dd .Bytes ()};type htmlFile struct{_ff _gc .Buffer }; \ No newline at end of file diff --git a/go.mod b/go.mod index 0108857..ebc88b0 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,18 @@ module github.com/unidoc/unihtml go 1.15 require ( + github.com/adrg/strutil v0.3.0 // indirect + github.com/adrg/sysfont v0.1.2 // indirect + github.com/adrg/xdg v0.4.0 // indirect github.com/mitchellh/go-homedir v1.1.0 + github.com/sirupsen/logrus v1.8.1 // indirect github.com/spf13/cobra v1.1.1 github.com/spf13/viper v1.7.1 - github.com/unidoc/unipdf/v3 v3.20.0 - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 + github.com/unidoc/unipdf/v3 v3.34.0 + golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f // indirect + golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 // indirect + golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect + golang.org/x/text v0.3.7 // indirect + golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index 92807d6..dcc67e5 100644 --- a/go.sum +++ b/go.sum @@ -15,12 +15,17 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/adrg/strutil v0.1.0 h1:IOQnSOAjbE17+7l1lw4rXgX6JuSeJGdZa7BucTMV3Qg= github.com/adrg/strutil v0.1.0/go.mod h1:pXRr2+IyX5AEPAF5icj/EeTaiflPSD2hvGjnguilZgE= -github.com/adrg/sysfont v0.1.1 h1:l9WKJNHsIpsfOhYIm1oSj+77837r/vls1MH17SH6gp0= +github.com/adrg/strutil v0.2.2/go.mod h1:EF2fjOFlGTepljfI+FzgTG13oXthR7ZAil9/aginnNQ= +github.com/adrg/strutil v0.3.0 h1:bi/HB2zQbDihC8lxvATDTDzkT4bG7PATtVnDYp5rvq4= +github.com/adrg/strutil v0.3.0/go.mod h1:Jz0wzBVE6Uiy9wxo62YEqEY1Nwto3QlLl1Il5gkLKWU= github.com/adrg/sysfont v0.1.1/go.mod h1:19nTHzfIn/HbngFMet+yNAvwSQYtOJYMI7vWexLWyNw= -github.com/adrg/xdg v0.2.1 h1:VSVdnH7cQ7V+B33qSJHTCRlNgra1607Q8PzEmnvb2Ic= +github.com/adrg/sysfont v0.1.2 h1:MSU3KREM4RhsQ+7QgH7wPEPTgAgBIz0Hw6Nd4u7QgjE= +github.com/adrg/sysfont v0.1.2/go.mod h1:6d3l7/BSjX9VaeXWJt9fcrftFaD/t7l11xgSywCPZGk= github.com/adrg/xdg v0.2.1/go.mod h1:ZuOshBmzV4Ta+s23hdfFZnBsdzmoR3US0d7ErpqSbTQ= +github.com/adrg/xdg v0.3.0/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ= +github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls= +github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= @@ -55,8 +60,6 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= -github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= -github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -65,6 +68,7 @@ github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFU github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -113,7 +117,6 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -139,6 +142,7 @@ github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQz github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= @@ -165,8 +169,9 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q= github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= @@ -192,17 +197,25 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df h1:1RV3lxQ6L6xGFNhngpP9iMjJPSwvH3p17JNbK9u5274= +github.com/trimmer-io/go-xmp v1.0.0/go.mod h1:Aaptr9sp1lLv7UnCAdQ+gSHZyY2miYaKmcNVj7HRBwA= +github.com/unidoc/freetype v0.0.0-20220130190903-3efbeefd0c90 h1:Rk4easgDQslR3DK7vwtl6jYMZTF3JqZ3ceUdyT6a3UM= +github.com/unidoc/freetype v0.0.0-20220130190903-3efbeefd0c90/go.mod h1:mJ/Q7JnqEoWtajJVrV6S1InbRv0K/fJerPB5SQs32KI= github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= +github.com/unidoc/pkcs7 v0.1.0 h1:9bQfbWMYsIfUP8PyhTcBudOsvbLpNH0MBv4U0P/jDTE= +github.com/unidoc/pkcs7 v0.1.0/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a h1:RLtvUhe4DsUDl66m7MJ8OqBjq8jpWBXPK6/RKtqeTkc= github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a/go.mod h1:j+qMWZVpZFTvDey3zxUkSgPJZEX33tDgU/QIA0IzCUw= -github.com/unidoc/unipdf/v3 v3.20.0 h1:efG2Y99K9xTELWmZuKGMgVYIhPsI0QbkNxx97IDMyyU= -github.com/unidoc/unipdf/v3 v3.20.0/go.mod h1:WdRz3hVhi/M0jFGXhsT5/9FDyRfga6KgI2ZQqjiOXaM= +github.com/unidoc/unichart v0.1.0 h1:GoJ/rxSoOYZsqlG3yOJpKkwgfsIQgb9hHX7bILZHcCg= +github.com/unidoc/unichart v0.1.0/go.mod h1:9sJXeqxIIsU2D07tmhpDMoND0mBFRGfKBJnXZMsJnzk= +github.com/unidoc/unipdf/v3 v3.34.0 h1:rTfnDuT1EMDR4QbxLsse/AtnZ7UJEar0vqZ/45SA+eM= +github.com/unidoc/unipdf/v3 v3.34.0/go.mod h1:rU+M1cSW0me6NOqQ471noVeEvQWhNBH3iUWkfFqJIgM= github.com/unidoc/unitype v0.2.1 h1:x0jMn7pB/tNrjEVjy3Ukpxo++HOBQaTCXcTYFA6BH3w= github.com/unidoc/unitype v0.2.1/go.mod h1:mafyug7zYmDOusqa7G0dJV45qp4b6TDAN+pHN7ZUIBU= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= @@ -217,8 +230,9 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 h1:hb9wdF1z5waM+dSIICn1l0DkLVDT3hqhhQsDNUmHPRE= golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f h1:OeJjE6G4dgCY4PIXvIRQbE8+RX+uXZyGhUy/ksMGJoc= +golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -226,8 +240,9 @@ golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm0 golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 h1:QelT11PB4FXiDEXucrfNckHoFxwt8USGY1ajP1ZF5lM= -golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= +golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 h1:LRtI4W37N+KFebI/qV0OFiLUv4GLOWeEW5hn/KEJvxE= +golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -253,6 +268,7 @@ golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -275,13 +291,21 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 h1:opSr2sbRXk5X5/givKrrKj9HXxFpW2sdCiP8MJSKLQY= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -302,8 +326,9 @@ golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f h1:GGU+dLjvlC3qDwqYgL6UgRmHXhOOgns0bZu2Ty5mm6U= +golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= @@ -339,8 +364,9 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/selector/selector.go b/selector/selector.go index d7c77a2..0bf0252 100644 --- a/selector/selector.go +++ b/selector/selector.go @@ -9,10 +9,11 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package selector ;import _a "errors";const (ByUndefined ByType =iota ;ByID ;ByQueryAll ;ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); - -// ByType is a 'By' selector type enumerator. -type ByType uint ; +package selector ;import _f "errors"; // Validate checks validity of the ByType. -func (_e ByType )Validate ()error {if _e >=ByID &&_e <=BySearch {return nil ;};return _a .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");}; \ No newline at end of file +func (_aa ByType )Validate ()error {if _aa >=ByID &&_aa <=BySearch {return nil ;};return _f .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};const (ByUndefined ByType =iota ;ByID ;ByQueryAll ; +ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); + +// ByType is a 'By' selector type enumerator. +type ByType uint ; \ No newline at end of file diff --git a/sizes/sizes.go b/sizes/sizes.go index c86c91c..4aac165 100644 --- a/sizes/sizes.go +++ b/sizes/sizes.go @@ -12,189 +12,190 @@ // Package sizes defines basic types that determines the size units i.e. lengths. // // -package sizes ;import (_a "encoding/json";_g "flag";_ccg "fmt";_cc "strconv";_b "strings";); +package sizes ;import (_d "encoding/json";_g "flag";_e "fmt";_c "strconv";_b "strings";);var _abc =map[string ]PageSize {_efbf [0:9]:0,_efbf [9:11]:1,_efbf [11:13]:2,_efbf [13:15]:3,_efbf [15:17]:4,_efbf [17:19]:5,_efbf [19:21]:6,_efbf [21:23]:7,_efbf [23:25]:8,_efbf [25:27]:9,_efbf [27:29]:10,_efbf [29:32]:11,_efbf [32:34]:12,_efbf [34:36]:13,_efbf [36:38]:14,_efbf [38:40]:15,_efbf [40:42]:16,_efbf [42:44]:17,_efbf [44:46]:18,_efbf [46:48]:19,_efbf [48:50]:20,_efbf [50:52]:21,_efbf [52:55]:22,_efbf [55:61]:23}; +var _ _g .Value =(*Orientation )(nil );var _egg =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; -// String implements fmt.Stringer interface. -func (_ea Millimeter )String ()string {_dd :=_b .Builder {};_dd .WriteString (_cc .FormatFloat (float64 (_ea ),'f',1,64));_dd .WriteString ("\u006d\u006d");return _dd .String ();}; +// Inches gets the inches equivalent from provided millimeter value. +func (_eb Millimeter )Inches ()Inch {return Inch (float64 (_eb )*_cb )}; -// LengthFlag is a pflag wrapper for the Length value. -type LengthFlag struct{Length Length ;};func _fgg (_fdf string )(Millimeter ,error ){_fdf =_b .TrimSpace (_b .TrimSuffix (_fdf ,"\u006d\u006d"));_aef ,_bde :=_cc .ParseFloat (_fdf ,64);if _bde !=nil {return 0,_ccg .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_bde ); -};return Millimeter (_aef ),nil ;}; +// Millimeters converts the inches value to the millimeters. +func (_fda Point )Millimeters ()Millimeter {return Millimeter (float64 (_fda )*_ce )};func _af (_gbb string )(Millimeter ,error ){_gbb =_b .TrimSpace (_b .TrimSuffix (_gbb ,"\u006d\u006d"));_fdg ,_bb :=_c .ParseFloat (_gbb ,64);if _bb !=nil {return 0,_e .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_bb ); +};return Millimeter (_fdg ),nil ;}; -// Millimeters gets the float64 millimeter value. -func (_ab Millimeter )Millimeters ()Millimeter {return _ab };var _ _g .Value =(*Orientation )(nil ); +// Name implements pflag.Value interface. +func (_ed Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; + +// Millimeter is the dimension unit that defines a millimeter. +type Millimeter float64 ; // Type implements pflag.Value interface. -func (_ed Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; +func (_eab Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; -// PageSizeValues returns all values of the enum -func PageSizeValues ()[]PageSize {return _deg }; +// String implements fmt.Stringer interface. +func (_gf Point )String ()string {_fba :=_b .Builder {};_fba .WriteString (_c .FormatFloat (float64 (_gf ),'f',1,64));_fba .WriteString ("\u0070\u0074");return _fba .String ();}; -// Name implements viper.FlagValue interface. -func (_ccbc Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; +// Type implements pflag.Value interface. +func (_ebg PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; -// Set implements pflag.Value interface. -func (_fb *Inch )Set (s string )error {_dg ,_ee :=_cc .ParseFloat (s ,64);if _ee !=nil {return _ccg .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ee );};*_fb =Inch (_dg ); -return nil ;}; +// Inches gets the inch value. Implements Length interface. +func (_eg Inch )Inches ()Inch {return _eg };func (_ceb PageSize )String ()string {if _ceb < 0||_ceb >=PageSize (len (_egg )-1){return _e .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_ceb );};return _efbf [_egg [_ceb ]:_egg [_ceb +1]]; +}; -// Orientation is the page orientation type wrapper. -type Orientation bool ; +// MarshalText implements the encoding.TextMarshaler interface for PageSize +func (_fdef PageSize )MarshalText ()([]byte ,error ){return []byte (_fdef .String ()),nil }; -// ValueString implements pflag.Value interface. -func (_fcb Inch )ValueString ()string {return _fcb .String ()}; +// UnmarshalJSON implements the json.Unmarshaler interface for PageSize +func (_eeg *PageSize )UnmarshalJSON (data []byte )error {var _eega string ;if _gfg :=_d .Unmarshal (data ,&_eega );_gfg !=nil {return _e .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); +};var _bee error ;*_eeg ,_bee =PageSizeString (_eega );return _bee ;}; -// HasChanged implements pflag.Value interface. -func (_fbe *Inch )HasChanged ()bool {return _fbe !=nil }; +// ValueType implements viper.FlagValue interface. +func (_da Point )ValueType ()string {return _da .Type ()}; -// Inch is a unit that -type Inch float64 ; +// Length is it the default dimension unit. +type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; -// MarshalUnit marshals the unit into the string. -func MarshalUnit (unit Length )(string ,error ){switch _ffb :=unit .(type ){case Millimeter :return _ccg .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_ffb ),nil ;case Inch :return _ccg .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_ffb ),nil ;case Point :return _ccg .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_ffb ),nil ; -default:return "",_ccg .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};};func _baa (_eea string )(Inch ,error ){_eea =_b .TrimSpace (_b .Trim (_eea ,"\u0069\u006e"));_ccc ,_ga :=_cc .ParseFloat (_eea ,64); -if _ga !=nil {return 0,_ccg .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ga );};return Inch (_ccc ),nil ;};var _ _g .Value =(*Point )(nil ); +// Point is a unit of Length commonly used to measure the height of fonts. +type Point float64 ; -// Type implements pflag.Value interface. -func (_gc *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; +// MarshalJSON implements json.Marshaler interface. +func (_ggd Point )MarshalJSON ()([]byte ,error ){return _eaab (_ggd )}; -// MarshalJSON implements json.Marshaler interface -func (_fc Millimeter )MarshalJSON ()([]byte ,error ){return _eaf (_fc )}; +// LengthFlag is a pflag wrapper for the Length value. +type LengthFlag struct{Length Length ;};const (Portrait =Orientation (false );Landscape =Orientation (true );); -// ValueType implements pflag.Value interface. -func (_ae Inch )ValueType ()string {return _ae .Type ()}; +// MarshalPageSize marshals the page size into string. +func MarshalPageSize (p PageSize )(string ,error ){_dae ,_ebf :=p .MarshalText ();if _ebf !=nil {return "",_ebf ;};return string (_dae ),nil ;}; -// Points implements Length interface. -func (_ba Inch )Points ()Point {return Point (float64 (_ba )*_e )};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;);func (_dgg PageSize )String ()string {if _dgg < 0||_dgg >=PageSize (len (_cga )-1){return _ccg .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_dgg ); -};return _aed [_cga [_dgg ]:_cga [_dgg +1]];}; +// PageSize is the enum used for defining the page size. +type PageSize int ; -// String implements fmt.Stringer interface. -func (_ddg Orientation )String ()string {if _ddg ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; +// UnmarshalInch unmarshalls provided string into unit. +func UnmarshalInch (unit string )(Inch ,error ){if _b .HasSuffix (unit ,"\u006d\u006d"){_fc ,_cab :=_af (unit );if _cab !=nil {return 0,_cab ;};return _fc .Inches (),nil ;};if _b .HasSuffix (unit ,"\u0069\u006e"){return _eaa (unit );};return 0,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); +}; -// HasChanged implements viper.FlagValue interface. -func (_bga *Point )HasChanged ()bool {return _bga !=nil }; +// Inch is a unit that +type Inch float64 ;var _ _g .Value =(*Point )(nil ); -// Set sets the unit value. -// Implements pflag.Value interface. -func (_bb *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_bb .Length =nil ;return nil ;};_cd ,_ff :=UnmarshalLength (s );if _ff !=nil {return _ff ;};_bb .Length =_cd ;return nil ;}; +// UnmarshalLength unmarshalls string value into Length. +func UnmarshalLength (length string )(Length ,error ){if _b .HasSuffix (length ,"\u006d\u006d"){return _af (length );};if _b .HasSuffix (length ,"\u0069\u006e"){return _eaa (length );};if _b .HasSuffix (length ,"\u0070\u0074"){return _gbd (length );};return nil ,_e .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length ); +};func _gbd (_ebb string )(Point ,error ){_ebb =_b .TrimSpace (_b .Trim (_ebb ,"\u0070\u0074"));_efba ,_gbc :=_c .ParseFloat (_ebb ,64);if _gbc !=nil {return 0,_gbc ;};return Point (_efba ),nil ;}; // Inches gets the inch value. Implements Length interface. -func (_bd Inch )Inches ()Inch {return _bd }; +func (_gbe Point )Inches ()Inch {return Inch (float64 (_gbe )*_ef )};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;); -// Type implements pflag.Value interface. -func (_bg Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; +// Set implements flag.Value interface. +func (_bbg *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_bbg =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_bbg =Landscape ;default:return _e .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); +};return nil ;}; -// Type implements pflag.Value interface. -func (_bba Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; +// Set sets the unit value. +// Implements pflag.Value interface. +func (_fd *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_fd .Length =nil ;return nil ;};_ca ,_fde :=UnmarshalLength (s );if _fde !=nil {return _fde ;};_fd .Length =_ca ;return nil ;}; -// Millimeter is the dimension unit that defines a millimeter. -type Millimeter float64 ;var (_ Length =Millimeter (0);); +// String implements fmt.Stringer interface. +func (_gge Orientation )String ()string {if _gge ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";};var _ba =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; -// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize -func (_ad *PageSize )UnmarshalText (text []byte )error {var _ge error ;*_ad ,_ge =PageSizeString (string (text ));return _ge ;}; -// Set implements flag.Value interface. -func (_ac *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_ac =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_ac =Landscape ;default:return _ccg .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); -};return nil ;}; +// String implements fmt.Stringer interface. +func (_efd Inch )String ()string {_gb :=_b .Builder {};_gb .WriteString (_c .FormatFloat (float64 (_efd ),'f',1,64));_gb .WriteString ("\u0069\u006e");return _gb .String ();}; -// ValueString implements viper.FlagValue interface. -func (_cf Point )ValueString ()string {return _cf .String ()}; +// ValueString implements pflag.Value interface. +func (_ddd Inch )ValueString ()string {return _ddd .String ()}; -// Inches gets the inch value. Implements Length interface. -func (_fbea Point )Inches ()Inch {return Inch (float64 (_fbea )*_f )}; +// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize +func (_cda *PageSize )UnmarshalText (text []byte )error {var _ac error ;*_cda ,_ac =PageSizeString (string (text ));return _ac ;}; -// String implements fmt.Stringer interface. -func (_db Inch )String ()string {_ec :=_b .Builder {};_ec .WriteString (_cc .FormatFloat (float64 (_db ),'f',1,64));_ec .WriteString ("\u0069\u006e");return _ec .String ();}; +// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise +func (_gdd PageSize )IsAPageSize ()bool {for _ ,_ede :=range _ba {if _gdd ==_ede {return true ;};};return false ;}; -// String gets the string value for given flag. -func (_gfg *LengthFlag )String ()string {if _gfg .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _gfg .Length .String ();};var _deg =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; +// Name implements viper.FlagValue interface. +func (_gfe Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; -// ValueType implements viper.FlagValue interface. -func (_dga Point )ValueType ()string {return _dga .Type ()}; +// MarshalJSON implements json.Marshaler interface +func (_cd Millimeter )MarshalJSON ()([]byte ,error ){return _eaab (_cd )}; -// Point is a unit of Length commonly used to measure the height of fonts. -type Point float64 ; +// Orientation is the page orientation type wrapper. +type Orientation bool ; -// Inches gets the inches equivalent from provided millimeter value. -func (_fd Millimeter )Inches ()Inch {return Inch (float64 (_fd )*_gf )}; +// Type implements pflag.Value interface. +func (_efe *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"};func _eaa (_efb string )(Inch ,error ){_efb =_b .TrimSpace (_b .Trim (_efb ,"\u0069\u006e"));_dab ,_ebd :=_c .ParseFloat (_efb ,64);if _ebd !=nil {return 0,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ebd ); +};return Inch (_dab ),nil ;}; // Set implements flag.Value interface. -func (_bf *Point )Set (s string )error {_gd ,_df :=_cc .ParseFloat (s ,64);if _df !=nil {return _ccg .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_df );};*_bf =Point (_gd ); +func (_fbd *Point )Set (s string )error {_cc ,_ea :=_c .ParseFloat (s ,64);if _ea !=nil {return _e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ea );};*_fbd =Point (_cc ); return nil ;}; +// Type implements pflag.Value interface. +func (_fb Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; + // Points implements Length interface. -func (_abf Millimeter )Points ()Point {return Point (_abf *_aa )}; +func (_cde Point )Points ()Point {return _cde }; -// Millimeters converts the inches value to the millimeters. -func (_ag Point )Millimeters ()Millimeter {return Millimeter (float64 (_ag )*_d )}; +// String gets the string value for given flag. +func (_df *LengthFlag )String ()string {if _df .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _df .Length .String ();}; // MarshalJSON implements json.Marshaler interface -func (_ccd Inch )MarshalJSON ()([]byte ,error ){return _eaf (_ccd )};func _da (_eac string )(Point ,error ){_eac =_b .TrimSpace (_b .Trim (_eac ,"\u0070\u0074"));_gg ,_egg :=_cc .ParseFloat (_eac ,64);if _egg !=nil {return 0,_egg ;};return Point (_gg ),nil ; -}; - -// Millimeters converts the inches value to the millimeters. -func (_dc Inch )Millimeters ()Millimeter {return Millimeter (float64 (_dc )*_ccb )}; +func (_egc Inch )MarshalJSON ()([]byte ,error ){return _eaab (_egc )}; -// PageSizeString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func PageSizeString (s string )(PageSize ,error ){if _ccdf ,_aag :=_aab [s ];_aag {return _ccdf ,nil ;};return 0,_ccg .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); -}; +// MarshalUnit marshals the unit into the string. +func MarshalUnit (unit Length )(string ,error ){switch _aa :=unit .(type ){case Millimeter :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_aa ),nil ;case Inch :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_aa ),nil ;case Point :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_aa ),nil ; +default:return "",_e .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};};var (_ Length =Millimeter (0);); -// UnmarshalInch unmarshalls provided string into unit. -func UnmarshalInch (unit string )(Inch ,error ){if _b .HasSuffix (unit ,"\u006d\u006d"){_bbb ,_dda :=_fgg (unit );if _dda !=nil {return 0,_dda ;};return _bbb .Inches (),nil ;};if _b .HasSuffix (unit ,"\u0069\u006e"){return _baa (unit );};return 0,_ccg .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); -}; +// ValueType implements pflag.Value interface. +func (_dfc Inch )ValueType ()string {return _dfc .Type ()}; -// PageSize is the enum used for defining the page size. -type PageSize int ; +// ValueString implements viper.FlagValue interface. +func (_db Point )ValueString ()string {return _db .String ()}; -// MarshalText implements the encoding.TextMarshaler interface for PageSize -func (_bec PageSize )MarshalText ()([]byte ,error ){return []byte (_bec .String ()),nil }; +// Dimensions gets the dimensions of the given page size. +// If provided page size is not valid than the function returns 0 values. +func (_bcc PageSize )Dimensions ()(_bcd ,_ebba Millimeter ){switch _bcc {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; +case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; +case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _bcd ,_ebba ;}; -// String implements fmt.Stringer interface. -func (_abe Point )String ()string {_eg :=_b .Builder {};_eg .WriteString (_cc .FormatFloat (float64 (_abe ),'f',1,64));_eg .WriteString ("\u0070\u0074");return _eg .String ();}; +// Points implements Length interface. +func (_caa Millimeter )Points ()Point {return Point (_caa *_fa )}; -// UnmarshalPageSize unmarshals the page size from the string. -func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _gfa PageSize ;if _dcc :=(&_gfa ).UnmarshalText ([]byte (pageSize ));_dcc !=nil {return 0,_ccg .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_dcc ); -};return _gfa ,nil ;};func _eaf (_ddf Length )([]byte ,error ){if _ddf ==nil {return nil ,nil ;};_gab ,_bdd :=MarshalUnit (_ddf );if _bdd !=nil {return nil ,_bdd ;};return []byte ("\u0022"+_gab +"\u0022"),nil ;}; +// Millimeters gets the float64 millimeter value. +func (_fe Millimeter )Millimeters ()Millimeter {return _fe }; -// MarshalPageSize marshals the page size into string. -func MarshalPageSize (p PageSize )(string ,error ){_aaa ,_de :=p .MarshalText ();if _de !=nil {return "",_de ;};return string (_aaa ),nil ;}; +// Type implements pflag.Value interface. +func (_fg Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; -// Name implements pflag.Value interface. -func (_ca Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; +// UnmarshalPageSize unmarshals the page size from the string. +func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _egce PageSize ;if _cf :=(&_egce ).UnmarshalText ([]byte (pageSize ));_cf !=nil {return 0,_e .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_cf ); +};return _egce ,nil ;}; -// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise -func (_ce PageSize )IsAPageSize ()bool {for _ ,_cfe :=range _deg {if _ce ==_cfe {return true ;};};return false ;}; +// HasChanged implements pflag.Value interface. +func (_ee *Inch )HasChanged ()bool {return _ee !=nil }; -// UnmarshalJSON implements the json.Unmarshaler interface for PageSize -func (_gfbe *PageSize )UnmarshalJSON (data []byte )error {var _bcb string ;if _agd :=_a .Unmarshal (data ,&_bcb );_agd !=nil {return _ccg .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); -};var _bed error ;*_gfbe ,_bed =PageSizeString (_bcb );return _bed ;}; +// PageSizeValues returns all values of the enum +func PageSizeValues ()[]PageSize {return _ba };const (_cb =float64 (1)/float64 (25.4);_f =25.4;_ef =0.0139;_ce =0.3528;_bf =1.0/64;_fa =1.0/_ce ;);var _ Length =Inch (0); // Set implements pflag.Value interface. -func (_gfb *PageSize )Set (s string )error {_eaa ,_fa :=UnmarshalPageSize (s );if _fa !=nil {return _fa ;};*_gfb =_eaa ;return nil ;};var _ Length =Inch (0);const (_gf =float64 (1)/float64 (25.4);_ccb =25.4;_f =0.0139;_d =0.3528;_e =1/64;_aa =1/_d ;); - -// Length is it the default dimension unit. -type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; - -// MarshalJSON implements the json.Marshaler interface for PageSize -func (_fffg PageSize )MarshalJSON ()([]byte ,error ){return _a .Marshal (_fffg .String ())}; +func (_afg *PageSize )Set (s string )error {_dg ,_dga :=UnmarshalPageSize (s );if _dga !=nil {return _dga ;};*_afg =_dg ;return nil ;}; // Points implements Length interface. -func (_fdc Point )Points ()Point {return _fdc };var _cga =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; +func (_edf Inch )Points ()Point {return Point (float64 (_edf )*_bf )}; -// Type implements pflag.Value interface. -func (_ace PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"};var _aab =map[string ]PageSize {_aed [0:9]:0,_aed [9:11]:1,_aed [11:13]:2,_aed [13:15]:3,_aed [15:17]:4,_aed [17:19]:5,_aed [19:21]:6,_aed [21:23]:7,_aed [23:25]:8,_aed [25:27]:9,_aed [27:29]:10,_aed [29:32]:11,_aed [32:34]:12,_aed [34:36]:13,_aed [36:38]:14,_aed [38:40]:15,_aed [40:42]:16,_aed [42:44]:17,_aed [44:46]:18,_aed [46:48]:19,_aed [48:50]:20,_aed [50:52]:21,_aed [52:55]:22,_aed [55:61]:23}; +// String implements fmt.Stringer interface. +func (_cag Millimeter )String ()string {_ab :=_b .Builder {};_ab .WriteString (_c .FormatFloat (float64 (_cag ),'f',1,64));_ab .WriteString ("\u006d\u006d");return _ab .String ();}; +// Set implements pflag.Value interface. +func (_bc *Inch )Set (s string )error {_cg ,_bg :=_c .ParseFloat (s ,64);if _bg !=nil {return _e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_bg );};*_bc =Inch (_cg ); +return nil ;}; -// MarshalJSON implements json.Marshaler interface. -func (_fff Point )MarshalJSON ()([]byte ,error ){return _eaf (_fff )}; +// PageSizeString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func PageSizeString (s string )(PageSize ,error ){if _fab ,_fae :=_abc [s ];_fae {return _fab ,nil ;};return 0,_e .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); +}; -// Dimensions gets the dimensions of the given page size. -// If provided page size is not valid than the function returns 0 values. -func (_cab PageSize )Dimensions ()(_ega ,_eed Millimeter ){switch _cab {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; -case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; -case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _ega ,_eed ;};const (Portrait =Orientation (false );Landscape =Orientation (true ););const _aed ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; +// Millimeters converts the inches value to the millimeters. +func (_eea Inch )Millimeters ()Millimeter {return Millimeter (float64 (_eea )*_f )};const _efbf ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; -// UnmarshalLength unmarshalls string value into Length. -func UnmarshalLength (length string )(Length ,error ){if _b .HasSuffix (length ,"\u006d\u006d"){return _fgg (length );};if _b .HasSuffix (length ,"\u0069\u006e"){return _baa (length );};if _b .HasSuffix (length ,"\u0070\u0074"){return _da (length );};return nil ,_ccg .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length ); -}; \ No newline at end of file +// MarshalJSON implements the json.Marshaler interface for PageSize +func (_ad PageSize )MarshalJSON ()([]byte ,error ){return _d .Marshal (_ad .String ())};func _eaab (_gga Length )([]byte ,error ){if _gga ==nil {return nil ,nil ;};_dfb ,_be :=MarshalUnit (_gga );if _be !=nil {return nil ,_be ;};return []byte ("\u0022"+_dfb +"\u0022"),nil ; +}; + +// HasChanged implements viper.FlagValue interface. +func (_gd *Point )HasChanged ()bool {return _gd !=nil }; \ No newline at end of file diff --git a/unihtml.go b/unihtml.go index 59a9980..28b7810 100644 --- a/unihtml.go +++ b/unihtml.go @@ -10,88 +10,59 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package unihtml contains a plugin for the UniDoc. -package unihtml ;import (_eb "bytes";_f "context";_af "errors";_fc "fmt";_ee "github.com/unidoc/unihtml/client";_fd "github.com/unidoc/unihtml/content";_eee "github.com/unidoc/unihtml/selector";_ab "github.com/unidoc/unihtml/sizes";_ad "github.com/unidoc/unipdf/v3/common"; -_ae "github.com/unidoc/unipdf/v3/common/license";_da "github.com/unidoc/unipdf/v3/creator";_fb "github.com/unidoc/unipdf/v3/model";_cga "github.com/unidoc/unipdf/v3/render";_gg "image";_g "image/color";_c "math";_a "net/url";_e "os";_cg "time";); +package unihtml ;import (_df "bytes";_c "context";_cb "errors";_eg "fmt";_fc "github.com/unidoc/unihtml/client";_ce "github.com/unidoc/unihtml/content";_b "github.com/unidoc/unihtml/selector";_de "github.com/unidoc/unihtml/sizes";_fd "github.com/unidoc/unipdf/v3/common"; +_dd "github.com/unidoc/unipdf/v3/common/license";_dc "github.com/unidoc/unipdf/v3/creator";_be "github.com/unidoc/unipdf/v3/model";_ec "github.com/unidoc/unipdf/v3/render";_d "image";_e "image/color";_f "math";_a "net/url";_gc "os";_fb "time";); -// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. -func ConnectOptions (o Options )error {_ge =_ee .New (_ee .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_ggg ,_be :=_f .WithTimeout (_f .Background (),_cg .Second *5);defer _be ();if _cd :=_ge .HealthCheck (_ggg );_cd !=nil {return _cd ; -};return nil ;};func (_cacd *Document )validate ()error {if _ge ==nil {return ErrNoClient ;};if _cacd ._db ==nil {return ErrContentNotDefined ;};return nil ;};func (_ege *Document )getMargins ()margins {_dfd :=_ege ._fca ;if _ege ._fef .IsRelative (){_dfd .Top =_ab .Millimeter (1); -_dfd .Left =_ab .Millimeter (1);_dfd .Bottom =_ab .Millimeter (1);_dfd .Right =_ab .Millimeter (1);return _dfd ;};if _dfd .Top ==nil {_dfd .Top =_ab .Millimeter (10);};if _dfd .Bottom ==nil {_dfd .Bottom =_ab .Millimeter (10);};if _dfd .Left ==nil {_dfd .Left =_ab .Millimeter (10); -};if _dfd .Right ==nil {_dfd .Right =_ab .Millimeter (10);};return _dfd ;}; - -// SetMarginLeft sets the left margin. -func (_egb *Document )SetMarginLeft (margin _ab .Length ){_egb ._fca .Left =margin }; - -// WriteToFile writes the document to a file defined by the output path. -func (_cge *Document )WriteToFile (outputPath string )error {if _ga :=_cge .validate ();_ga !=nil {return _ga ;};_aef :=_cg .Second *20+_cge ._ce ;_faa ,_cf :=_f .WithTimeout (_f .Background (),_aef );defer _cf ();_bea ,_cff :=_cge .extract (_faa ,_cge ._gc ,_cge ._fde ,_cge .getMargins ()); -if _cff !=nil {return _cff ;};_bf :=_da .New ();for _ ,_ede :=range _bea {if _cff =_bf .AddPage (_ede );_cff !=nil {return _cff ;};};return _bf .WriteToFile (outputPath );}; - -// SetLandscapeOrientation sets document landscape page orientation. -func (_bff *Document )SetLandscapeOrientation (){_bff ._gcg =_ab .Landscape }; +// WaitVisible waits for the provided selector to be ready. +// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. +func (_fdd *Document )WaitVisible (sel string ,by ..._b .ByType ){_gfe :=_b .BySearch ;if len (by )> 0{_gfe =by [0];};_fdd ._dbf =append (_fdd ._dbf ,_fc .BySelector {Selector :sel ,By :_gfe });}; -// GetPdfPages is a function that converts provided input content and -func (_abc *Document )GetPdfPages (ctx _f .Context )([]*_fb .PdfPage ,error ){if _adfg :=_abc .validate ();_adfg !=nil {return nil ,_adfg ;};return _abc .extract (ctx ,_abc ._gc ,_abc ._fde ,_abc .getMargins ());}; +// SetPageHeight sets the page height for given document. +func (_dfg *Document )SetPageHeight (pageHeight _de .Length )error {_dfg ._gd =pageHeight ;_dfg ._ccg =_dc .PositionAbsolute ;return nil ;};var ErrContentNotDefined =_cb .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); -// SetPos sets the absolute position. Changes object positioning to absolute. -func (_bda *Document )SetPos (x ,y float64 ){_bda ._fef =_da .PositionAbsolute ;_bda ._fa =x ;_bda ._ged =y ;};func _ba ()error {_fe :=_ae .GetLicenseKey ();if _fe ==nil {return _af .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); -};if !_fe .IsLicensed (){return _af .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};return nil ;};func _ffe (_geg _gg .Image )float64 {_eg :=_geg .Bounds (); -var (_fed int ;_abg _g .Color ;_eda ,_fdf ,_fg uint32 ;);_aeg ,_cbb :=_eg .Min .X ,_eg .Max .Y -1;_cac :=_geg .At (_aeg ,_cbb );_aec ,_fdb ,_bdg ,_ :=_cac .RGBA ();_ccaa :=_aec ==_c .MaxUint16 &&_fdb ==_c .MaxUint16 &&_bdg ==_c .MaxUint16 ;for _cbb =_eg .Max .Y -1; -_cbb >=_eg .Min .Y ;_cbb --{var _fdff bool ;for _aeg =_eg .Min .X ;_aeg < _eg .Max .X ;_aeg ++{_abg =_geg .At (_aeg ,_cbb );_eda ,_fdf ,_fg ,_ =_abg .RGBA ();if (_ccaa &&!(_eda ==_aec &&_fdf ==_fdb &&_bdg ==_fg ))||(!_ccaa &&(_c .Abs (float64 (_eda )-float64 (_aec ))/float64 (_c .MaxUint16 )> 0.03||_c .Abs (float64 (_fdf )-float64 (_fdb ))/float64 (_c .MaxUint16 )> 0.03||_c .Abs (float64 (_fg )-float64 (_bdg ))/float64 (_c .MaxUint16 )> 0.03)){_fdff =true ; -break ;};};if _fdff {break ;};_fed =_cbb ;};return float64 (_eg .Max .Y -_fed )/float64 (_eg .Max .Y );}; -// SetPageSize sets the page default size. -func (_gaa *Document )SetPageSize (pageSize _ab .PageSize )error {if !pageSize .IsAPageSize (){return _af .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); -};_gaa ._bc =pageSize ;_gaa ._fef =_da .PositionAbsolute ;return nil ;}; +// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. +func ConnectOptions (o Options )error {_fcd =_fc .New (_fc .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_dcc ,_cf :=_c .WithTimeout (_c .Background (),_fb .Second *5);defer _cf ();if _db :=_fcd .HealthCheck (_dcc );_db !=nil {return _db ; +};return nil ;};var ErrNoClient =_cb .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); -// Connect creates UniHTML HTTP Client and tries to establish connection with the server. -func Connect (path string )error {if _b :=_ba ();_b !=nil {return _b ;};_fbb ,_fcb :=_ee .ParseOptions (path );if _fcb !=nil {return _fcb ;};_ge =_ee .New (_fbb );_ca ,_adf :=_f .WithTimeout (_f .Background (),_cg .Second *5);defer _adf ();if _bd :=_ge .HealthCheck (_ca ); -_bd !=nil {return _bd ;};return nil ;}; +// Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. +type Document struct{_fg _ce .Content ;_fe margins ;_ccg _dc .Positioning ;_dbg ,_gf float64 ;_feb _de .PageSize ;_ggd ,_gd _de .Length ;_aa _de .Orientation ;_ea bool ;_ccgd _fb .Duration ;_ccb []_fc .BySelector ;_dbf []_fc .BySelector ;_fa *_fb .Duration ; +}; -// SetMarginTop sets the left margin. -func (_eeg *Document )SetMarginTop (margin _ab .Length ){_eeg ._fca .Top =margin }; +// NewDocument creates new HTML Document used as an input for the creator.Drawable. +func NewDocument (path string )(*Document ,error ){_ddc :=&Document {};_fac ,_cea :=_a .Parse (path );if _cea !=nil {return nil ,_cea ;};switch _fac .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_ddc ._fg ,_cea =_ce .NewWebURL (path ); +if _cea !=nil {return nil ,_cea ;};return _ddc ,nil ;};_gdg ,_cea :=_gc .Stat (path );if _cea !=nil {return nil ,_cea ;};if !_gdg .IsDir (){_ddc ._fg ,_cea =_ce .NewHTMLFile (path );}else {_ddc ._fg ,_cea =_ce .NewZipDirectory (path );};if _cea !=nil {return nil ,_cea ; +};return _ddc ,nil ;}; // SetMargins sets the Document Margins. -func (_caf *Document )SetMargins (left ,right ,top ,bottom float64 ){_caf ._fca .Left =_ab .Point (left );_caf ._fca .Right =_ab .Point (right );_caf ._fca .Top =_ab .Point (top );_caf ._fca .Bottom =_ab .Point (bottom );_caf ._fef =_da .PositionAbsolute ; +func (_dac *Document )SetMargins (left ,right ,top ,bottom float64 ){_dac ._fe .Left =_de .Point (left );_dac ._fe .Right =_de .Point (right );_dac ._fe .Top =_de .Point (top );_dac ._fe .Bottom =_de .Point (bottom );_dac ._ccg =_dc .PositionAbsolute ; }; +// SetPos sets the absolute position. Changes object positioning to absolute. +func (_ede *Document )SetPos (x ,y float64 ){_ede ._ccg =_dc .PositionAbsolute ;_ede ._dbg =x ;_ede ._gf =y ;}; + // WaitReady waits for the provided selector to be ready. // A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_dg *Document )WaitReady (sel string ,by ..._eee .ByType ){_cfg :=_eee .BySearch ;if len (by )> 0{_cfg =by [0];};_dg ._ed =append (_dg ._ed ,_ee .BySelector {Selector :sel ,By :_cfg });}; - -// SetPageHeight sets the page height for given document. -func (_aff *Document )SetPageHeight (pageHeight _ab .Length )error {_aff ._fde =pageHeight ;_aff ._fef =_da .PositionAbsolute ;return nil ;}; +func (_gb *Document )WaitReady (sel string ,by ..._b .ByType ){_eeg :=_b .BySearch ;if len (by )> 0{_eeg =by [0];};_gb ._ccb =append (_gb ._ccb ,_fc .BySelector {Selector :sel ,By :_eeg });}; -// SetPageWidth sets the page width for given document. -func (_ggd *Document )SetPageWidth (pageWidth _ab .Length )error {_ggd ._gc =pageWidth ;_ggd ._fef =_da .PositionAbsolute ;return nil ;};var _ge *_ee .Client ; +// SetMarginTop sets the left margin. +func (_ceaa *Document )SetMarginTop (margin _de .Length ){_ceaa ._fe .Top =margin };func (_acc *Document )getMargins ()margins {_gafg :=_acc ._fe ;if _acc ._ccg .IsRelative (){_gafg .Top =_de .Millimeter (1);_gafg .Left =_de .Millimeter (1);_gafg .Bottom =_de .Millimeter (1); +_gafg .Right =_de .Millimeter (1);return _gafg ;};if _gafg .Top ==nil {_gafg .Top =_de .Millimeter (10);};if _gafg .Bottom ==nil {_gafg .Bottom =_de .Millimeter (10);};if _gafg .Left ==nil {_gafg .Left =_de .Millimeter (10);};if _gafg .Right ==nil {_gafg .Right =_de .Millimeter (10); +};return _gafg ;}; -// WaitVisible waits for the provided selector to be ready. -// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_afb *Document )WaitVisible (sel string ,by ..._eee .ByType ){_bbb :=_eee .BySearch ;if len (by )> 0{_bbb =by [0];};_afb ._gd =append (_afb ._gd ,_ee .BySelector {Selector :sel ,By :_bbb });};var ErrContentNotDefined =_af .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); +// WriteToFile writes the document to a file defined by the output path. +func (_abd *Document )WriteToFile (outputPath string )error {if _daa :=_abd .validate ();_daa !=nil {return _daa ;};_dbbe :=_fb .Second *20+_abd ._ccgd ;_fgf ,_ade :=_c .WithTimeout (_c .Background (),_dbbe );defer _ade ();_aaf ,_ebc :=_abd .extract (_fgf ,_abd ._ggd ,_abd ._gd ,_abd .getMargins ()); +if _ebc !=nil {return _ebc ;};_eaf :=_dc .New ();for _ ,_dec :=range _aaf {if _ebc =_eaf .AddPage (_dec );_ebc !=nil {return _ebc ;};};return _eaf .WriteToFile (outputPath );}; +// SetLandscapeOrientation sets document landscape page orientation. +func (_adf *Document )SetLandscapeOrientation (){_adf ._aa =_de .Landscape };func _cae (_ga _d .Image )float64 {_faa :=_ga .Bounds ();var (_ed int ;_cge _e .Color ;_cgd ,_beg ,_daf uint32 ;);_cgc ,_bga :=_faa .Min .X ,_faa .Max .Y -1;_gaf :=_ga .At (_cgc ,_bga ); +_bdg ,_faf ,_begb ,_ :=_gaf .RGBA ();_decb :=_bdg ==_f .MaxUint16 &&_faf ==_f .MaxUint16 &&_begb ==_f .MaxUint16 ;for _bga =_faa .Max .Y -1;_bga >=_faa .Min .Y ;_bga --{var _bf bool ;for _cgc =_faa .Min .X ;_cgc < _faa .Max .X ;_cgc ++{_cge =_ga .At (_cgc ,_bga ); +_cgd ,_beg ,_daf ,_ =_cge .RGBA ();if (_decb &&!(_cgd ==_bdg &&_beg ==_faf &&_begb ==_daf ))||(!_decb &&(_f .Abs (float64 (_cgd )-float64 (_bdg ))/float64 (_f .MaxUint16 )> 0.03||_f .Abs (float64 (_beg )-float64 (_faf ))/float64 (_f .MaxUint16 )> 0.03||_f .Abs (float64 (_daf )-float64 (_begb ))/float64 (_f .MaxUint16 )> 0.03)){_bf =true ; +break ;};};if _bf {break ;};_ed =_bga ;};return float64 (_faa .Max .Y -_ed )/float64 (_faa .Max .Y );};type margins struct{Left ,Right ,Bottom ,Top _de .Length ;}; // ContainerComponent implements creator.containerElement interface. -func (_gcb *Document )ContainerComponent (container _da .Drawable )(_da .Drawable ,error ){switch container .(type ){case *_da .Chapter :default:return nil ,_fc .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); -};return _gcb ,nil ;}; - -// NewDocument creates new HTML Document used as an input for the creator.Drawable. -func NewDocument (path string )(*Document ,error ){_cb :=&Document {};_fcf ,_gee :=_a .Parse (path );if _gee !=nil {return nil ,_gee ;};switch _fcf .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_cb ._db ,_gee =_fd .NewWebURL (path ); -if _gee !=nil {return nil ,_gee ;};return _cb ,nil ;};_gea ,_gee :=_e .Stat (path );if _gee !=nil {return nil ,_gee ;};if !_gea .IsDir (){_cb ._db ,_gee =_fd .NewHTMLFile (path );}else {_cb ._db ,_gee =_fd .NewZipDirectory (path );};if _gee !=nil {return nil ,_gee ; -};return _cb ,nil ;}; - -// Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. -type Document struct{_db _fd .Content ;_fca margins ;_fef _da .Positioning ;_fa ,_ged float64 ;_bc _ab .PageSize ;_gc ,_fde _ab .Length ;_gcg _ab .Orientation ;_adg bool ;_ce _cg .Duration ;_ed []_ee .BySelector ;_gd []_ee .BySelector ;}; - -// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. -func (_cbe *Document )TrimLastPageContent (){_cbe ._adg =true }; - -// SetMarginBottom sets the left margin. -func (_faac *Document )SetMarginBottom (margin _ab .Length ){_faac ._fca .Bottom =margin }; - -// WaitTime sets the waiting time before the webpage is rendered to PDF. -func (_bde *Document )WaitTime (duration _cg .Duration ){_bde ._ce =duration }; - -// SetMarginRight sets the left margin. -func (_bcf *Document )SetMarginRight (margin _ab .Length ){_bcf ._fca .Right =margin }; +func (_ddg *Document )ContainerComponent (container _dc .Drawable )(_dc .Drawable ,error ){switch container .(type ){case *_dc .Chapter :default:return nil ,_eg .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); +};return _ddg ,nil ;}; // Options are the HTML Client options used for establishing the connection. type Options struct{ @@ -106,16 +77,50 @@ Port int ; Secure bool ; // Prefix is an option setting used when the server is working with the URI prefix. Default Value: ''. -Prefix string ;};var _ _da .Drawable =(*Document )(nil );func (_df *Document )extract (_ebe _f .Context ,_gdd ,_bad _ab .Length ,_ac margins )([]*_fb .PdfPage ,error ){_ega :=_ee .BuildHTMLQuery ().SetContent (_df ._db ).PageSize (_df ._bc ).PaperWidth (_gdd ).PaperHeight (_bad ).Orientation (_df ._gcg ).MarginLeft (_ac .Left ).MarginRight (_ac .Right ).MarginTop (_ac .Top ).MarginBottom (_ac .Bottom ).WaitTime (_df ._ce ); -for _ ,_edee :=range _df ._ed {_ega .WaitReady (_edee .Selector ,_edee .By );};for _ ,_add :=range _df ._gd {_ega .WaitVisible (_add .Selector ,_add .By );};_bag ,_ccf :=_ega .Query ();if _ccf !=nil {return nil ,_ccf ;};_ebe ,_ffbg :=_f .WithTimeout (_ebe ,_cg .Second *15); -defer _ffbg ();_caac ,_ccf :=_ge .ConvertHTML (_ebe ,_bag );if _ccf !=nil {return nil ,_ccf ;};_gaad :=_eb .NewReader (_caac .Data );_de ,_ccf :=_fb .NewPdfReader (_gaad );if _ccf !=nil {return nil ,_ccf ;};return _de .PageList ,nil ;}; +Prefix string ;};var _ _dc .Drawable =(*Document )(nil ); + +// SetMarginBottom sets the left margin. +func (_begbg *Document )SetMarginBottom (margin _de .Length ){_begbg ._fe .Bottom =margin }; + +// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. +func (_cac *Document )TrimLastPageContent (){_cac ._ea =true }; + +// SetMarginRight sets the left margin. +func (_fed *Document )SetMarginRight (margin _de .Length ){_fed ._fe .Right =margin };func (_eac *Document )validate ()error {if _fcd ==nil {return ErrNoClient ;};if _eac ._fg ==nil {return ErrContentNotDefined ;};return nil ;};var _fcd *_fc .Client ; + +// Connect creates UniHTML HTTP Client and tries to establish connection with the server. +func Connect (path string )error {if _ef :=_gg ();_ef !=nil {return _ef ;};_ge ,_dg :=_fc .ParseOptions (path );if _dg !=nil {return _dg ;};_fcd =_fc .New (_ge );_ca ,_ab :=_c .WithTimeout (_c .Background (),_fb .Second *5);defer _ab ();if _eb :=_fcd .HealthCheck (_ca ); +_eb !=nil {return _eb ;};return nil ;}; + +// SetPageSize sets the page default size. +func (_cba *Document )SetPageSize (pageSize _de .PageSize )error {if !pageSize .IsAPageSize (){return _cb .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); +};_cba ._feb =pageSize ;_cba ._ccg =_dc .PositionAbsolute ;return nil ;};func (_cebe *Document )extract (_ccc _c .Context ,_bef ,_dga _de .Length ,_ggg margins )([]*_be .PdfPage ,error ){_daca :=_fc .BuildHTMLQuery ().SetContent (_cebe ._fg ).PageSize (_cebe ._feb ).PaperWidth (_bef ).PaperHeight (_dga ).Orientation (_cebe ._aa ).MarginLeft (_ggg .Left ).MarginRight (_ggg .Right ).MarginTop (_ggg .Top ).MarginBottom (_ggg .Bottom ).WaitTime (_cebe ._ccgd ); +for _ ,_eea :=range _cebe ._ccb {_daca .WaitReady (_eea .Selector ,_eea .By );};for _ ,_cef :=range _cebe ._dbf {_daca .WaitVisible (_cef .Selector ,_cef .By );};_fdc ,_fca :=_daca .Query ();if _fca !=nil {return nil ,_fca ;};var _ae _c .CancelFunc ;if _cebe ._fa !=nil {_ccc ,_ae =_c .WithTimeout (_ccc ,*_cebe ._fa ); +}else {_ccc ,_ae =_c .WithTimeout (_ccc ,_fb .Second *15);};defer _ae ();_ege ,_fca :=_fcd .ConvertHTML (_ccc ,_fdc );if _fca !=nil {return nil ,_fca ;};_bcb :=_df .NewReader (_ege .Data );_geb ,_fca :=_be .NewPdfReader (_bcb );if _fca !=nil {return nil ,_fca ; +};return _geb .PageList ,nil ;}; + +// SetTimeoutDuration sets the timeout duration +// the default timeout is 15 seconds. +func (_gbg *Document )SetTimeoutDuration (duration _fb .Duration ){_gbg ._fa =&duration }; + +// SetPageWidth sets the page width for given document. +func (_ag *Document )SetPageWidth (pageWidth _de .Length )error {_ag ._ggd =pageWidth ;_ag ._ccg =_dc .PositionAbsolute ;return nil ;}; + +// GetPdfPages is a function that converts provided input content and +func (_ee *Document )GetPdfPages (ctx _c .Context )([]*_be .PdfPage ,error ){if _cce :=_ee .validate ();_cce !=nil {return nil ,_cce ;};return _ee .extract (ctx ,_ee ._ggd ,_ee ._gd ,_ee .getMargins ());};func _gg ()error {_cc :=_dd .GetLicenseKey ();if _cc ==nil {return _cb .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); +};if !_cc .IsLicensed (){return _cb .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};return nil ;}; // GeneratePageBlocks implements creator.Drawable interface. -func (_adgb *Document )GeneratePageBlocks (ctx _da .DrawContext )([]*_da .Block ,_da .DrawContext ,error ){if _ff :=_adgb .validate ();_ff !=nil {return nil ,ctx ,_ff ;};var _ag []*_da .Block ;_faf :=_adgb .getMargins ();_cca ,_cde :=_adgb ._gc ,_adgb ._fde ; -if _adgb ._fef .IsRelative (){_cca ,_cde =_ab .Point (ctx .Width ),_ab .Point (ctx .Height );ctx .X -=float64 (_faf .Left .Points ());};_caa ,_fbbb :=_adgb .extract (_f .Background (),_cca ,_cde ,_faf );if _fbbb !=nil {return nil ,_da .DrawContext {},_fbbb ; -};for _dbb ,_dd :=range _caa {_eea ,_gdg :=_da .NewBlockFromPage (_dd );if _gdg !=nil {return nil ,_da .DrawContext {},_gdg ;};var _fbc float64 ;if _adgb ._adg &&_dbb ==len (_caa )-1{_ea :=_cga .NewImageDevice ();_afd ,_bb :=_ea .Render (_dd );if _bb !=nil {return nil ,_da .DrawContext {},_bb ; -};_cdd ,_bb :=_dd .GetMediaBox ();if _bb !=nil {return nil ,_da .DrawContext {},_bb ;};_ef :=_cg .Now ();_feff :=_ffe (_afd );_fbc =_cdd .Height ()*_feff ;_ad .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_cg .Since (_ef )); -if _adgb ._fca .Bottom !=nil {_fbc -=float64 (_adgb ._fca .Bottom .Points ());};if _fbc < 0{_fbc =0;};_ad .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_fbc ); -};_ffb ,_ddf ,_gdg :=_eea .GeneratePageBlocks (ctx );if _gdg !=nil {return nil ,_da .DrawContext {},_gdg ;};ctx =_ddf ;ctx .Y -=_fbc ;if _dbb !=len (_caa )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; -ctx .Page ++;};_ag =append (_ag ,_ffb ...);};return _ag ,ctx ,nil ;};var ErrNoClient =_af .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");type margins struct{Left ,Right ,Bottom ,Top _ab .Length ; -}; \ No newline at end of file +func (_dbb *Document )GeneratePageBlocks (ctx _dc .DrawContext )([]*_dc .Block ,_dc .DrawContext ,error ){if _ceb :=_dbb .validate ();_ceb !=nil {return nil ,ctx ,_ceb ;};var _cg []*_dc .Block ;_bg :=_dbb .getMargins ();_dcb ,_fbd :=_dbb ._ggd ,_dbb ._gd ; +if _dbb ._ccg .IsRelative (){_dcb ,_fbd =_de .Point (ctx .Width ),_de .Point (ctx .Height );ctx .X -=float64 (_bg .Left .Points ());};_fbf ,_fbe :=_dbb .extract (_c .Background (),_dcb ,_fbd ,_bg );if _fbe !=nil {return nil ,_dc .DrawContext {},_fbe ;}; +for _bb ,_bd :=range _fbf {_dde ,_da :=_dc .NewBlockFromPage (_bd );if _da !=nil {return nil ,_dc .DrawContext {},_da ;};var _gdf float64 ;if _dbb ._ea &&_bb ==len (_fbf )-1{_def :=_ec .NewImageDevice ();_ddf ,_ddb :=_def .Render (_bd );if _ddb !=nil {return nil ,_dc .DrawContext {},_ddb ; +};_abg ,_ddb :=_bd .GetMediaBox ();if _ddb !=nil {return nil ,_dc .DrawContext {},_ddb ;};_ad :=_fb .Now ();_cgb :=_cae (_ddf );_gdf =_abg .Height ()*_cgb ;_fd .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_fb .Since (_ad )); +if _dbb ._fe .Bottom !=nil {_gdf -=float64 (_dbb ._fe .Bottom .Points ());};if _gdf < 0{_gdf =0;};_fd .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_gdf ); +};_ba ,_fcc ,_da :=_dde .GeneratePageBlocks (ctx );if _da !=nil {return nil ,_dc .DrawContext {},_da ;};ctx =_fcc ;ctx .Y -=_gdf ;if _bb !=len (_fbf )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; +ctx .Page ++;};_cg =append (_cg ,_ba ...);};return _cg ,ctx ,nil ;}; + +// SetMarginLeft sets the left margin. +func (_fbdd *Document )SetMarginLeft (margin _de .Length ){_fbdd ._fe .Left =margin }; + +// WaitTime sets the waiting time before the webpage is rendered to PDF. +func (_cace *Document )WaitTime (duration _fb .Duration ){_cace ._ccgd =duration }; \ No newline at end of file From bb53e79e671d2e93c9ad3d8e2f858be7fb7c6df3 Mon Sep 17 00:00:00 2001 From: UniDoc Build Date: Fri, 10 Feb 2023 16:57:05 +0000 Subject: [PATCH 3/9] prepare release --- cli/cmd/cmd.go | 73 ++++++----- cli/main.go | 2 +- client/client.go | 282 ++++++++++++++++++++++--------------------- common/common.go | 6 +- content/content.go | 55 ++++----- selector/selector.go | 12 +- sizes/sizes.go | 250 +++++++++++++++++++------------------- unihtml.go | 150 +++++++++++------------ 8 files changed, 417 insertions(+), 413 deletions(-) diff --git a/cli/cmd/cmd.go b/cli/cmd/cmd.go index 0f9baa4..f5eaa9a 100644 --- a/cli/cmd/cmd.go +++ b/cli/cmd/cmd.go @@ -9,57 +9,56 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package cmd ;import (_g "context";_dc "fmt";_ec "github.com/mitchellh/go-homedir";_c "github.com/spf13/cobra";_ab "github.com/spf13/viper";_ee "github.com/unidoc/unihtml/client";_dd "github.com/unidoc/unihtml/content";_a "github.com/unidoc/unihtml/sizes"; -_cc "github.com/unidoc/unipdf/v3/common";_d "os";_b "path/filepath";_f "time";);func _cdc (cmd *_c .Command ,_gg []string ){_fb :=_f .Now ();if _fe :=_ab .BindPFlags (cmd .Flags ());_fe !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_fe ); -_d .Exit (1);};if _ac :=_ab .Unmarshal (&_cd );_ac !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ac );_d .Exit (1);};_def ();_bg :=_f .Now ();_db ,_gb :=_d .Stat (_gg [0]);if _gb !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gb ); -_d .Exit (1);};if !_db .IsDir (){if _b .Ext (_db .Name ())!="\u002e\u0068\u0074m\u006c"{_dc .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_gg [0]); -_d .Exit (1);};};_bc ,_gb :=_d .OpenFile (_gg [1],_d .O_CREATE |_d .O_WRONLY |_d .O_TRUNC ,0700);if _gb !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gb );_d .Exit (1);};defer _bc .Close ();_fc :=_ee .New (_ee .Options {HTTPS :_cd .Https ,Hostname :_cd .Host ,Port :_cd .Port ,Prefix :_cd .Prefix }); -_fae ,_fcb :=_g .WithTimeout (_g .Background (),_f .Second *10);defer _fcb ();_bg =_f .Now ();var _fba _dd .Content ;if _db .IsDir (){_fba ,_gb =_dd .NewZipDirectory (_gg [0]);}else {_fba ,_gb =_dd .NewHTMLFile (_gg [0]);};if _gb !=nil {_dc .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_gb ); -_d .Exit (1);};_df ,_gb :=_ee .BuildHTMLQuery ().PaperWidth (_cg .PaperWidth .Length ).PaperHeight (_cg .PaperHeight .Length ).PageSize (_cg .PageSize ).MarginTop (_cg .MarginTop .Length ).MarginBottom (_cg .MarginBottom .Length ).MarginLeft (_cg .MarginLeft .Length ).MarginRight (_cg .MarginRight .Length ).Orientation (_cg .Orientation ).SetContent (_fba ).Query (); -if _gb !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gb );_d .Exit (1);};_dg ,_gb :=_fc .ConvertHTML (_fae ,_df );if _gb !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gb );_d .Exit (1);};_cc .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_f .Since (_bg )); -_bg =_f .Now ();_ ,_gb =_bc .Write (_dg .Data );if _gb !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gb );_d .Exit (1);};_cc .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_f .Since (_bg )); -_dc .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_f .Since (_fb ));};var (_cd =generateConfig {};_cg =parametersConfig {PaperWidth :_a .LengthFlag {Length :_a .Inch (8.5).Millimeters ()},PaperHeight :_a .LengthFlag {Length :_a .Inch (11).Millimeters ()},Orientation :_a .Portrait ,MarginTop :_a .LengthFlag {Length :_a .Millimeter (10)},MarginBottom :_a .LengthFlag {Length :_a .Millimeter (10)},MarginLeft :_a .LengthFlag {Length :_a .Millimeter (10)},MarginRight :_a .LengthFlag {Length :_a .Millimeter (10)}}; -); - -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. -func Execute (){if _ce :=_de .Execute ();_ce !=nil {_dc .Println (_ce );_d .Exit (1);};};func _def (){_fcg :=_cc .LogLevelInfo ;if _fad {_fcg =_cc .LogLevelDebug ;};if _ca {_fcg =_cc .LogLevelTrace ;};_cc .Log =_cc .NewConsoleLogger (_fcg );};func init (){_de .AddCommand (_fa ); -_fa .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072");_fa .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); -_fa .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); -_fa .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); -_fa .Flags ().Var (&_cg .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_fa .Flags ().Var (&_cg .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); -_fa .Flags ().Var (&_cg .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_fa .Flags ().Var (&_cg .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); -_fa .Flags ().Var (&_cg .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_fa .Flags ().Var (&_cg .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); -_fa .Flags ().Var (&_cg .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_fa .Flags ().Var (&_cg .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); -};var _fa =&_c .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_cdc ,Args :_c .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; -var (_fad ,_ca bool ;);type parametersConfig struct{ +package cmd ;import (_e "context";_bc "fmt";_efg "github.com/mitchellh/go-homedir";_g "github.com/spf13/cobra";_fd "github.com/spf13/viper";_fe "github.com/unidoc/unihtml/client";_ab "github.com/unidoc/unihtml/content";_d "github.com/unidoc/unihtml/sizes"; +_a "github.com/unidoc/unipdf/v3/common";_b "os";_ff "path/filepath";_ef "time";);var _egf =&_g .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; +var (_eb =generateConfig {};_ba =parametersConfig {PaperWidth :_d .LengthFlag {Length :_d .Inch (8.5).Millimeters ()},PaperHeight :_d .LengthFlag {Length :_d .Inch (11).Millimeters ()},Orientation :_d .Portrait ,MarginTop :_d .LengthFlag {Length :_d .Millimeter (10)},MarginBottom :_d .LengthFlag {Length :_d .Millimeter (10)},MarginLeft :_d .LengthFlag {Length :_d .Millimeter (10)},MarginRight :_d .LengthFlag {Length :_d .Millimeter (10)}}; +);func _gg (cmd *_g .Command ,_eg []string ){_gd :=_ef .Now ();if _abc :=_fd .BindPFlags (cmd .Flags ());_abc !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_abc );_b .Exit (1);};if _ebb :=_fd .Unmarshal (&_eb );_ebb !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ebb ); +_b .Exit (1);};_gfg ();_dg ,_c :=_b .Stat (_eg [0]);if _c !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_c );_b .Exit (1);};if !_dg .IsDir (){if _ff .Ext (_dg .Name ())!="\u002e\u0068\u0074m\u006c"{_bc .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_eg [0]); +_b .Exit (1);};};_fg ,_c :=_b .OpenFile (_eg [1],_b .O_CREATE |_b .O_WRONLY |_b .O_TRUNC ,0700);if _c !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_c );_b .Exit (1);};defer _fg .Close ();_fed :=_fe .New (_fe .Options {HTTPS :_eb .Https ,Hostname :_eb .Host ,Port :_eb .Port ,Prefix :_eb .Prefix }); +_ec ,_cd :=_e .WithTimeout (_e .Background (),_ef .Second *10);defer _cd ();_ed :=_ef .Now ();var _fa _ab .Content ;if _dg .IsDir (){_fa ,_c =_ab .NewZipDirectory (_eg [0]);}else {_fa ,_c =_ab .NewHTMLFile (_eg [0]);};if _c !=nil {_bc .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_c ); +_b .Exit (1);};_ea ,_c :=_fe .BuildHTMLQuery ().PaperWidth (_ba .PaperWidth .Length ).PaperHeight (_ba .PaperHeight .Length ).PageSize (_ba .PageSize ).MarginTop (_ba .MarginTop .Length ).MarginBottom (_ba .MarginBottom .Length ).MarginLeft (_ba .MarginLeft .Length ).MarginRight (_ba .MarginRight .Length ).Orientation (_ba .Orientation ).SetContent (_fa ).Query (); +if _c !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_c );_b .Exit (1);};_ece ,_c :=_fed .ConvertHTML (_ec ,_ea );if _c !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_c );_b .Exit (1);};_a .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_ef .Since (_ed )); +_ed =_ef .Now ();_ ,_c =_fg .Write (_ece .Data );if _c !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_c );_b .Exit (1);};_a .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_ef .Since (_ed )); +_bc .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_ef .Since (_gd ));};var _ac =&_g .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_gg ,Args :_g .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; +func init (){_egf .AddCommand (_ac );_ac .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072");_ac .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); +_ac .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); +_ac .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); +_ac .Flags ().Var (&_ba .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_ac .Flags ().Var (&_ba .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); +_ac .Flags ().Var (&_ba .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_ac .Flags ().Var (&_ba .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); +_ac .Flags ().Var (&_ba .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_ac .Flags ().Var (&_ba .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); +_ac .Flags ().Var (&_ba .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_ac .Flags ().Var (&_ba .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); +};func _gfg (){_ca :=_a .LogLevelInfo ;if _fb {_ca =_a .LogLevelDebug ;};if _abf {_ca =_a .LogLevelTrace ;};_a .Log =_a .NewConsoleLogger (_ca );};var (_fb ,_abf bool ;);type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`; +Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};var _gge string ;type parametersConfig struct{ // PaperWidth sets the width of the paper. -PaperWidth _a .LengthFlag `mapstructure:"paper-width"`; +PaperWidth _d .LengthFlag `mapstructure:"paper-width"`; // PaperHeight is the height of the output paper. -PaperHeight _a .LengthFlag `mapstructure:"paper-height"`; +PaperHeight _d .LengthFlag `mapstructure:"paper-height"`; // PageSize is the page size string. -PageSize _a .PageSize `mapstructure:"page-size"`; +PageSize _d .PageSize `mapstructure:"page-size"`; // Orientation defines if the output should be in a landscape format. -Orientation _a .Orientation `mapstructure:"orientation"`; +Orientation _d .Orientation `mapstructure:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _a .LengthFlag `mapstructure:"margin-top"`; +MarginTop _d .LengthFlag `mapstructure:"margin-top"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _a .LengthFlag `mapstructure:"margin-bottom"`; +MarginBottom _d .LengthFlag `mapstructure:"margin-bottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _a .LengthFlag `mapstructure:"margin-left"`; +MarginLeft _d .LengthFlag `mapstructure:"margin-left"`; // MarginRight sets up the Right Margin for the output. -MarginRight _a .LengthFlag `mapstructure:"margin-right"`;};var _de =&_c .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; -var _bb string ;func init (){_c .OnInitialize (_bf );_de .PersistentFlags ().BoolVarP (&_fad ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065");_de .PersistentFlags ().BoolVarP (&_ca ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); -_de .PersistentFlags ().StringVar (&_bb ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); -_de .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};type generateConfig struct{Port int `mapstructure:"port"`; -Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};func _bf (){if _bb !=""{_ab .SetConfigFile (_bb );}else {_cb ,_fcge :=_ec .Dir ();if _fcge !=nil {_dc .Println (_fcge );_d .Exit (1);};_ab .AddConfigPath (_cb ); -_ab .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063");};_ab .AutomaticEnv ();if _cgg :=_ab .ReadInConfig ();_cgg ==nil {_dc .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_ab .ConfigFileUsed ()); +MarginRight _d .LengthFlag `mapstructure:"margin-right"`;};func init (){_g .OnInitialize (_ga );_egf .PersistentFlags ().BoolVarP (&_fb ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065"); +_egf .PersistentFlags ().BoolVarP (&_abf ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); +_egf .PersistentFlags ().StringVar (&_gge ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); +_egf .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");}; + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute (){if _baa :=_egf .Execute ();_baa !=nil {_bc .Println (_baa );_b .Exit (1);};};func _ga (){if _gge !=""{_fd .SetConfigFile (_gge );}else {_fgf ,_bb :=_efg .Dir ();if _bb !=nil {_bc .Println (_bb );_b .Exit (1);};_fd .AddConfigPath (_fgf ); +_fd .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063");};_fd .AutomaticEnv ();if _gae :=_fd .ReadInConfig ();_gae ==nil {_bc .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_fd .ConfigFileUsed ()); };}; \ No newline at end of file diff --git a/cli/main.go b/cli/main.go index 7ce4592..f0b00cc 100644 --- a/cli/main.go +++ b/cli/main.go @@ -9,4 +9,4 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package main ;import _ca "github.com/unidoc/unihtml/cli/cmd";func main (){_ca .Execute ()}; \ No newline at end of file +package main ;import _g "github.com/unidoc/unihtml/cli/cmd";func main (){_g .Execute ()}; \ No newline at end of file diff --git a/client/client.go b/client/client.go index d98620b..65a50d7 100644 --- a/client/client.go +++ b/client/client.go @@ -11,198 +11,200 @@ // Package client contains HTML Converter HTTP Client. The Client implements htmlcreator.HTMLConverter interface // for the UniPDF module and can be used as a plugin for the UniPDF creator.Creator. -package client ;import (_db "bytes";_b "compress/flate";_cc "compress/gzip";_e "context";_ee "encoding/json";_d "errors";_gcg "fmt";_adf "github.com/unidoc/unihtml/content";_eb "github.com/unidoc/unihtml/selector";_gf "github.com/unidoc/unihtml/sizes"; -_bg "github.com/unidoc/unipdf/v3/common";_c "io/ioutil";_ccf "net";_ea "net/http";_gc "net/url";_ge "strconv";_g "strings";_ad "time";); +package client ;import (_cg "bytes";_ge "compress/flate";_af "compress/gzip";_a "context";_g "encoding/json";_f "errors";_eg "fmt";_fcg "github.com/unidoc/unihtml/content";_gedc "github.com/unidoc/unihtml/selector";_ae "github.com/unidoc/unihtml/sizes"; +_gb "github.com/unidoc/unipdf/v3/common";_c "io/ioutil";_e "net";_fc "net/http";_ga "net/url";_ged "strconv";_bg "strings";_d "time";); -// New creates new client with provided options. -func New (o Options )*Client {o .DefaultTimeout =_ad .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _fb =&_ea .Transport {DialContext :(&_ccf .Dialer {Timeout :5*_ad .Second }).DialContext ,TLSHandshakeTimeout :5*_ad .Second }; -_bg .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_ea .Client {Transport :_fb ,Timeout :o .DefaultTimeout }};}; +// WithHTTPS sets the TLS option for the client options. +func WithHTTPS (useHTTPS bool )Option {return func (_dfd *Options ){_dfd .HTTPS =useHTTPS }}; -// Query gets the Query from provided query builder. If some error occurred during build process -// or the input is not valid the function would return an error. -func (_cd *QueryBuilder )Query ()(*Query ,error ){if _efd :=_cd .Validate ();_efd !=nil {return nil ,_efd ;};return &_cd ._dbc ,nil ;}; +// ParseOptions parses options for the Client. +func ParseOptions (connectPath string )(Options ,error ){if !_bg .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_fg ,_gbg :=_ga .Parse (connectPath );if _gbg !=nil {return Options {},_eg .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); +};var _ac int ;if _fg .Port ()!=""{_ac ,_gbg =_ged .Atoi (_fg .Port ());if _gbg !=nil {return Options {},_eg .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_gbg ); +};};return Options {Hostname :_fg .Hostname (),Port :_ac ,HTTPS :_fg .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_fg .Path },nil ;};func (_aeb *Client )getGenerateRequest (_bc _a .Context ,_gc *Query )(*_fc .Request ,error ){_ag :=generatePDFRequestV1 {Method :_gc .Method ,PageParameters :_gc .PageParameters ,RenderParameters :_gc .RenderParameters ,TimeoutDuration :int64 (_gc .TimeoutDuration )}; +switch _gc .Method {case "\u0077\u0065\u0062":_ag .ContentURL =_gc .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_ag .ContentType =_gc .ContentType ;_ag .Content =_gc .Content ;};_fa :=new (_cg .Buffer );if _gda :=_g .NewEncoder (_fa ).Encode (&_ag ); +_gda !=nil {return nil ,_eg .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_gda );};_aa :=_aeb .Options .Addr ();_aa =_eg .Sprintf ("%\u0073\u002f\u0062\u0065\u0074\u0061\u002f\u0070\u0064\u0066",_aa ); +_fgd ,_dfe :=_fc .NewRequest ("\u0050\u004f\u0053\u0054",_aa ,_fa );if _dfe !=nil {return nil ,_dfe ;};_fgd .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); +_fgd .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); +_fgd =_fgd .WithContext (_bc );return _fgd ,nil ;}; -// WithPort sets the Port option for the client options. -func WithPort (option int )Option {return func (_gbg *Options ){_gbg .Port =option }}; +// MarginBottom sets up the MarginBottom parameter for the query. +func (_ece *QueryBuilder )MarginBottom (marginBottom _ae .Length )*QueryBuilder {_ece ._gaa .PageParameters .MarginBottom =marginBottom ;return _ece ;};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`; +ContentURL string `json:"contentURL"`;Method string `json:"method"`;ExpiresAt int64 `json:"expiresAt"`;TimeoutDuration int64 `json:"timeoutDuration,omitempty"`;PageParameters ;RenderParameters ;}; -// WaitTime sets the minimum load time parameter for the page rendering. -func (_gg *QueryBuilder )WaitTime (d _ad .Duration )*QueryBuilder {_gg ._dbc .RenderParameters .WaitTime =d ;return _gg ;};var (ErrNotFound =_d .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_d .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); -ErrNotImplemented =_d .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_d .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_d .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079"); -ErrUnauthorized =_d .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_d .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); +// HealthCheck connects to the server and check the health status of the server. +func (_cf *Client )HealthCheck (ctx _a .Context )error {_df :=_cf .Options .Addr ();_df =_eg .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_df );_cb ,_ec :=_fc .NewRequest ("\u0047\u0045\u0054",_df ,nil );if _ec !=nil {return _ec ;};_cb =_cb .WithContext (ctx ); +_ed ,_ec :=_cf .Client .Do (_cb );if _ec !=nil {return _ec ;};switch _ed .StatusCode {case _fc .StatusOK :return nil ;case _fc .StatusNotFound :return ErrNotFound ;case _fc .StatusInternalServerError :return ErrInternalError ;case _fc .StatusBadGateway :return ErrBadGateway ; +default:return ErrNotImplemented ;};}; -// DefaultPageParameters creates default parameters. -func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_gf .Portrait }}; +// Client is a structure that is a HTTP client for the unihtml server. +type Client struct{Options Options ;Client *_fc .Client ;}; -// Portrait sets up the portrait page orientation. -func (_ccae *QueryBuilder )Portrait ()*QueryBuilder {_ccae ._dbc .PageParameters .Orientation =_gf .Portrait ;return _ccae ;}; +// Landscape sets up the landscape portrait orientation. +func (_dac *QueryBuilder )Landscape ()*QueryBuilder {_dac ._gaa .PageParameters .Orientation =_ae .Landscape ;return _dac ;}; -// Options are the client options used by the HTTP client. -type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _ad .Duration ;Prefix string ;}; +// SetContent sets custom data with it's content type. +func (_bcb *QueryBuilder )SetContent (content _fcg .Content )*QueryBuilder {if _bcb ._gee !=nil {return _bcb ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _bcb ._gaa .ContentType !=""{_bcb ._gee =ErrContentTypeDeclared ; +return _bcb ;};if content .ContentType ()==""{_bcb ._gee =_eg .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _bcb ; +};_bcb ._gaa .Content =content .Data ();_bcb ._gaa .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _bcb ._gaa .ContentType !=""{_bcb ._gee =ErrContentTypeDeclared ;return _bcb ;};_bcb ._gaa .URL =string (content .Data ());_bcb ._gaa .ContentType =content .ContentType (); +default:_bcb ._gee =_eg .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ());return _bcb ;};_bcb ._gaa .Method =content .Method (); +return _bcb ;}; -// Err gets the error which could occur in the query. -func (_ga *QueryBuilder )Err ()error {return _ga ._dc };func (_fbbf *Client )setQueryValues (_eeb *_ea .Request ,_fga *Query ){_bgg :=_eeb .URL .Query ();_gb :=_fga .PageParameters ;if _gb .PageSize !=nil {_bgg .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_gb .PageSize .String ()); -};if _gb .PaperHeight !=nil {_bgg .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_gb .PaperHeight .String ());};if _gb .PaperWidth !=nil {_bgg .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_gb .PaperWidth .String ()); -};if _gb .MarginTop !=nil {_bgg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_gb .MarginTop .String ());};if _gb .MarginBottom !=nil {_bgg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_gb .MarginBottom .String ()); -};if _gb .MarginRight !=nil {_bgg .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_gb .MarginRight .String ());};if _gb .MarginLeft !=nil {_bgg .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_gb .MarginLeft .String ()); -};if _gb .Orientation ==_gf .Landscape {_bgg .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_gb .Orientation .String ());};if _fga .RenderParameters .WaitTime !=0{_bgg .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_ge .FormatInt (int64 (_fga .RenderParameters .WaitTime /_ad .Millisecond ),10)); -};_eeb .URL .RawQuery =_bgg .Encode ();}; +// WaitTime sets the minimum load time parameter for the page rendering. +func (_gfc *QueryBuilder )WaitTime (d _d .Duration )*QueryBuilder {_gfc ._gaa .RenderParameters .WaitTime =d ;return _gfc ;}; -// Orientation sets the page orientation for the Query. -func (_geff *QueryBuilder )Orientation (orientation _gf .Orientation )*QueryBuilder {_geff ._dbc .PageParameters .Orientation =orientation ;return _geff ;};var (ErrMissingData =_d .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061"); -ErrContentType =_d .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065");ErrContentTypeDeclared =_d .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064"); -); +// PaperHeight sets up the PaperHeight (in cm) parameter for the query. +func (_da *QueryBuilder )PaperHeight (paperHeight _ae .Length )*QueryBuilder {_da ._gaa .PageParameters .PaperHeight =paperHeight ;return _da ;}; + +// Addr gets the HTTP address URI used by the http.Client. +func (_ee *Options )Addr ()string {_dc :=_bg .Builder {};_dc .WriteString ("\u0068\u0074\u0074\u0070");if _ee .HTTPS {_dc .WriteRune ('s');};_dc .WriteString ("\u003a\u002f\u002f");_dc .WriteString (_ee .Hostname );_dc .WriteRune (':');_dc .WriteString (_ged .Itoa (_ee .Port )); +if _ee .Prefix !=""{_dc .WriteString (_ee .Prefix );};return _dc .String ();}; + +// MarginRight sets up the MarginRight parameter for the query. +func (_fd *QueryBuilder )MarginRight (marginRight _ae .Length )*QueryBuilder {_fd ._gaa .PageParameters .MarginRight =marginRight ;return _fd ;};var (ErrNotFound =_f .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_f .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); +ErrNotImplemented =_f .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_f .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_f .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079"); +ErrUnauthorized =_f .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_f .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); // Validate checks the validity of the RenderParameters. -func (_cge *RenderParameters )Validate ()error {if _cge .WaitTime > _ad .Minute *3{return _d .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); -};for _ ,_bc :=range _cge .WaitReady {if _cgeb :=_bc .Validate ();_cgeb !=nil {return _gcg .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_cgeb ); +func (_cbc *RenderParameters )Validate ()error {if _cbc .WaitTime > _d .Minute *3{return _f .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); +};for _ ,_bcg :=range _cbc .WaitReady {if _ca :=_bcg .Validate ();_ca !=nil {return _eg .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_ca ); };};return nil ;}; +// MarginTop sets up the MarginTop parameter for the query. +func (_gdag *QueryBuilder )MarginTop (marginTop _ae .Length )*QueryBuilder {_gdag ._gaa .PageParameters .MarginTop =marginTop ;return _gdag ;}; + +// Query gets the Query from provided query builder. If some error occurred during build process +// or the input is not valid the function would return an error. +func (_eda *QueryBuilder )Query ()(*Query ,error ){if _gbe :=_eda .Validate ();_gbe !=nil {return nil ,_gbe ;};return &_eda ._gaa ,nil ;}; + +// PaperWidth sets up the PaperWidth (in cm) parameter for the query. +func (_bb *QueryBuilder )PaperWidth (paperWidth _ae .Length )*QueryBuilder {_bb ._gaa .PageParameters .PaperWidth =paperWidth ;return _bb ;}; + +// Validate checks if the parameters are valid. +func (_be *PageParameters )Validate ()error {if _be .PaperWidth !=nil {if _be .PaperWidth .Millimeters ()< 0{return _f .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); +};};if _be .PaperHeight !=nil {if _be .PaperHeight .Millimeters ()< 0{return _f .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); +};};if _be .MarginTop !=nil {if _be .MarginTop .Millimeters ()< 0{return _f .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _be .MarginBottom !=nil {if _be .MarginBottom .Millimeters ()< 0{return _f .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); +};};if _be .MarginLeft !=nil {if _be .MarginLeft .Millimeters ()< 0{return _f .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};};if _be .MarginRight !=nil {if _be .MarginRight .Millimeters ()< 0{return _f .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); +};};if _be .PageSize !=nil &&!_be .PageSize .IsAPageSize (){return _f .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; + +// MarginLeft sets up the MarginLeft parameter for the query. +func (_fcd *QueryBuilder )MarginLeft (marginLeft _ae .Length )*QueryBuilder {_fcd ._gaa .PageParameters .MarginLeft =marginLeft ;return _fcd ;}; + +// BuildHTMLQuery creates a Query builder that is supposed to create valid +func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; + +// PDFResponse is the response used by the HTMLConverter. +type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; + +// TimeoutDuration sets the server query duration timeout. +// Once the timeout is reached the server will return an error. +func (_gafe *QueryBuilder )TimeoutDuration (d _d .Duration )*QueryBuilder {_gafe ._gaa .TimeoutDuration =d ;return _gafe ;};func (_cbf *Client )setQueryValues (_dfb *_fc .Request ,_edd *Query ){_gdg :=_dfb .URL .Query ();_fe :=_edd .PageParameters ;if _fe .PageSize !=nil {_gdg .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_fe .PageSize .String ()); +};if _fe .PaperHeight !=nil {_gdg .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_fe .PaperHeight .String ());};if _fe .PaperWidth !=nil {_gdg .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_fe .PaperWidth .String ()); +};if _fe .MarginTop !=nil {_gdg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_fe .MarginTop .String ());};if _fe .MarginBottom !=nil {_gdg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_fe .MarginBottom .String ()); +};if _fe .MarginRight !=nil {_gdg .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_fe .MarginRight .String ());};if _fe .MarginLeft !=nil {_gdg .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_fe .MarginLeft .String ()); +};if _fe .Orientation ==_ae .Landscape {_gdg .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_fe .Orientation .String ());};if _edd .RenderParameters .WaitTime !=0{_gdg .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_ged .FormatInt (int64 (_edd .RenderParameters .WaitTime /_d .Millisecond ),10)); +};_dfb .URL .RawQuery =_gdg .Encode ();}; + // Validate checks if provided Query is valid. -func (_caf *Query )Validate ()error {switch _caf .Method {case "\u0077\u0065\u0062":if _caf .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_caf .Content )==0{return ErrMissingData ;};if _caf .ContentType ==""{return ErrContentType ; -};default:return _gcg .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_caf .Method );};if _cca :=_caf .PageParameters .Validate (); -_cca !=nil {return _cca ;};if _ebe :=_caf .RenderParameters .Validate ();_ebe !=nil {return _ebe ;};return nil ;}; +func (_dg *Query )Validate ()error {switch _dg .Method {case "\u0077\u0065\u0062":if _dg .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_dg .Content )==0{return ErrMissingData ;};if _dg .ContentType ==""{return ErrContentType ; +};default:return _eg .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_dg .Method );};if _acg :=_dg .PageParameters .Validate (); +_acg !=nil {return _acg ;};if _bef :=_dg .RenderParameters .Validate ();_bef !=nil {return _bef ;};return nil ;}; -// ConvertHTML converts provided Query input into PDF file data. -// Implements creator.HTMLConverter interface. -func (_ca *Client )ConvertHTML (ctx _e .Context ,q *Query )(*PDFResponse ,error ){if _gfb :=q .Validate ();_gfb !=nil {return nil ,_gfb ;};_bb ,_ef :=_ca .getGenerateRequest (ctx ,q );if _ef !=nil {return nil ,_ef ;};_bg .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_bb .Method ,_bb .URL .Hostname (),_bb .URL .Path ,_bb .Header ,_bb .URL .Query ()); -_af ,_ef :=_ca .Client .Do (_bb );if _ef !=nil {return nil ,_ef ;};var _ec error ;switch _af .StatusCode {case _ea .StatusNotFound :_ec =ErrNotFound ;case _ea .StatusBadRequest :_ec =ErrBadRequest ;case _ea .StatusNotImplemented :_ec =ErrNotImplemented ; -case _ea .StatusUnauthorized :_ec =ErrUnauthorized ;case _ea .StatusRequestTimeout :_ec =ErrTimedOut ;case _ea .StatusCreated :default:_ec =ErrInternalError ;};_bga :=_af .Body ;switch _af .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_bga ,_ef =_cc .NewReader (_af .Body ); -if _ef !=nil {return nil ,_ef ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_bga =_b .NewReader (_af .Body );case "":default:return nil ,_gcg .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_af .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); -};_ba ,_ef :=_c .ReadAll (_bga );if _ef !=nil &&_ec ==nil {return nil ,_gcg .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_ef );};_bg .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_af .StatusCode ,_bb .Method ,_bb .URL .Host ,_bb .URL .Path ); -if _ec !=nil {return nil ,_gcg .Errorf ("\u0025\u0073\u0020%\u0077",string (_ba ),_ec );};_cg :=_af .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_bg .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_cg ); -return &PDFResponse {ID :_cg ,Data :_ba },nil ;}; +// Orientation sets the page orientation for the Query. +func (_efc *QueryBuilder )Orientation (orientation _ae .Orientation )*QueryBuilder {_efc ._gaa .PageParameters .Orientation =orientation ;return _efc ;}; -// QueryBuilder is the query that converts HTMLConverter defined data -type QueryBuilder struct{_dbc Query ;_dc error ;}; +// WithHostname sets the Hostname option for the client options. +func WithHostname (option string )Option {return func (_dff *Options ){_dff .Hostname =option }};var (ErrMissingData =_f .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061");ErrContentType =_f .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065"); +ErrContentTypeDeclared =_f .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064");); -// WithPrefix sets the client prefix. -func WithPrefix (prefix string )Option {return func (_aag *Options ){_aag .Prefix =prefix }}; +// DefaultPageParameters creates default parameters. +func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_ae .Portrait }}; -// WithHTTPS sets the TLS option for the client options. -func WithHTTPS (useHTTPS bool )Option {return func (_gcf *Options ){_gcf .HTTPS =useHTTPS }}; +// BySelector is a structure that defines a selector with it's query 'by' type. +type BySelector struct{Selector string `json:"selector"`;By _gedc .ByType `json:"by"`;}; + +// Err gets the error which could occur in the query. +func (_efg *QueryBuilder )Err ()error {return _efg ._gee }; + +// Option is a function that changes client options. +type Option func (_age *Options ); + +// Validate checks if the QueryBuilder had no errors during composition and creation. +func (_ab *QueryBuilder )Validate ()error {if _ab ._gee !=nil {return _ab ._gee ;};return _ab ._gaa .Validate ();}; // PageParameters are the query parameters used in the PDF generation. type PageParameters struct{ // PaperWidth sets the width of the paper. -PaperWidth _gf .Length `schema:"paper-width" json:"paperWidth"`; +PaperWidth _ae .Length `schema:"paper-width" json:"paperWidth"`; // PaperHeight is the height of the output paper. -PaperHeight _gf .Length `schema:"paper-height" json:"paperHeight"`; +PaperHeight _ae .Length `schema:"paper-height" json:"paperHeight"`; // PageSize is the page size string. -PageSize *_gf .PageSize `schema:"page-size" json:"pageSize"`; +PageSize *_ae .PageSize `schema:"page-size" json:"pageSize"`; // Orientation defines if the output should be in a landscape format. -Orientation _gf .Orientation `schema:"orientation" json:"orientation"`; +Orientation _ae .Orientation `schema:"orientation" json:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _gf .Length `schema:"margin-top" json:"marginTop"`; +MarginTop _ae .Length `schema:"margin-top" json:"marginTop"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _gf .Length `schema:"margin-bottom" json:"marginBottom"`; +MarginBottom _ae .Length `schema:"margin-bottom" json:"marginBottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _gf .Length `schema:"margin-left" json:"marginLeft"`; +MarginLeft _ae .Length `schema:"margin-left" json:"marginLeft"`; // MarginRight sets up the Right Margin for the output. -MarginRight _gf .Length `schema:"margin-right" json:"marginRight"`;};func (_de *Client )getGenerateRequest (_aga _e .Context ,_ce *Query )(*_ea .Request ,error ){_fbb :=generatePDFRequestV1 {Method :_ce .Method ,PageParameters :_ce .PageParameters ,RenderParameters :_ce .RenderParameters }; -switch _ce .Method {case "\u0077\u0065\u0062":_fbb .ContentURL =_ce .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_fbb .ContentType =_ce .ContentType ;_fbb .Content =_ce .Content ;};_eef :=new (_db .Buffer );if _eg :=_ee .NewEncoder (_eef ).Encode (&_fbb ); -_eg !=nil {return nil ,_gcg .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_eg );};_aa :=_de .Options .Addr ();_aa =_gcg .Sprintf ("%\u0073\u002f\u0062\u0065\u0074\u0061\u002f\u0070\u0064\u0066",_aa ); -_fg ,_efg :=_ea .NewRequest ("\u0050\u004f\u0053\u0054",_aa ,_eef );if _efg !=nil {return nil ,_efg ;};_fg .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); -_fg .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); -_fg =_fg .WithContext (_aga );return _fg ,nil ;}; - -// SetContent sets custom data with it's content type. -func (_abg *QueryBuilder )SetContent (content _adf .Content )*QueryBuilder {if _abg ._dc !=nil {return _abg ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _abg ._dbc .ContentType !=""{_abg ._dc =ErrContentTypeDeclared ; -return _abg ;};if content .ContentType ()==""{_abg ._dc =_gcg .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _abg ; -};_abg ._dbc .Content =content .Data ();_abg ._dbc .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _abg ._dbc .ContentType !=""{_abg ._dc =ErrContentTypeDeclared ;return _abg ;};_abg ._dbc .URL =string (content .Data ());_abg ._dbc .ContentType =content .ContentType (); -default:_abg ._dc =_gcg .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ());return _abg ;};_abg ._dbc .Method =content .Method (); -return _abg ;}; - -// BuildHTMLQuery creates a Query builder that is supposed to create valid -func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`;Method string `json:"method"`;ExpiresAt int64 `json:"expiresAt"`; -PageParameters ;RenderParameters ;}; - -// MarginTop sets up the MarginTop parameter for the query. -func (_dfb *QueryBuilder )MarginTop (marginTop _gf .Length )*QueryBuilder {_dfb ._dbc .PageParameters .MarginTop =marginTop ;return _dfb ;}; - -// Option is a function that changes client options. -type Option func (_ae *Options ); - -// WaitReady waits for the selector to get ready - 'loaded'. -func (_bac *QueryBuilder )WaitReady (selector string ,by _eb .ByType )*QueryBuilder {_bac ._dbc .RenderParameters .WaitReady =append (_bac ._dbc .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _bac ;}; +MarginRight _ae .Length `schema:"margin-right" json:"marginRight"`;}; -// Validate checks if the QueryBuilder had no errors during composition and creation. -func (_gef *QueryBuilder )Validate ()error {if _gef ._dc !=nil {return _gef ._dc ;};return _gef ._dbc .Validate ();}; - -// MarginBottom sets up the MarginBottom parameter for the query. -func (_ceb *QueryBuilder )MarginBottom (marginBottom _gf .Length )*QueryBuilder {_ceb ._dbc .PageParameters .MarginBottom =marginBottom ;return _ceb ;}; - -// PDFResponse is the response used by the HTMLConverter. -type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; +// QueryBuilder is the query that converts HTMLConverter defined data +type QueryBuilder struct{_gaa Query ;_gee error ;}; -// PaperHeight sets up the PaperHeight (in cm) parameter for the query. -func (_bdd *QueryBuilder )PaperHeight (paperHeight _gf .Length )*QueryBuilder {_bdd ._dbc .PageParameters .PaperHeight =paperHeight ;return _bdd ;}; +// ConvertHTML converts provided Query input into PDF file data. +// Implements creator.HTMLConverter interface. +func (_gg *Client )ConvertHTML (ctx _a .Context ,q *Query )(*PDFResponse ,error ){if _bf :=q .Validate ();_bf !=nil {return nil ,_bf ;};_eb ,_gaf :=_gg .getGenerateRequest (ctx ,q );if _gaf !=nil {return nil ,_gaf ;};_gb .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_eb .Method ,_eb .URL .Hostname (),_eb .URL .Path ,_eb .Header ,_eb .URL .Query ()); +_cd :=*_gg .Client ;if q .TimeoutDuration !=0{_cd .Timeout =q .TimeoutDuration ;};_gd ,_gaf :=_cd .Do (_eb );if _gaf !=nil {return nil ,_gaf ;};var _gef error ;switch _gd .StatusCode {case _fc .StatusNotFound :_gef =ErrNotFound ;case _fc .StatusBadRequest :_gef =ErrBadRequest ; +case _fc .StatusNotImplemented :_gef =ErrNotImplemented ;case _fc .StatusUnauthorized :_gef =ErrUnauthorized ;case _fc .StatusRequestTimeout :_gef =ErrTimedOut ;case _fc .StatusCreated :default:_gef =ErrInternalError ;};_ba :=_gd .Body ;switch _gd .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_ba ,_gaf =_af .NewReader (_gd .Body ); +if _gaf !=nil {return nil ,_gaf ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_ba =_ge .NewReader (_gd .Body );case "":default:return nil ,_eg .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_gd .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); +};_fge ,_gaf :=_c .ReadAll (_ba );if _gaf !=nil &&_gef ==nil {return nil ,_eg .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_gaf );};_gb .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_gd .StatusCode ,_eb .Method ,_eb .URL .Host ,_eb .URL .Path ); +if _gef !=nil {return nil ,_eg .Errorf ("\u0025\u0073\u0020%\u0077",string (_fge ),_gef );};_acc :=_gd .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_gb .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_acc ); +return &PDFResponse {ID :_acc ,Data :_fge },nil ;}; -// Landscape sets up the landscape portrait orientation. -func (_cgd *QueryBuilder )Landscape ()*QueryBuilder {_cgd ._dbc .PageParameters .Orientation =_gf .Landscape ;return _cgd ;}; +// New creates new client with provided options. +func New (o Options )*Client {o .DefaultTimeout =_d .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _dd =&_fc .Transport {DialContext :(&_e .Dialer {Timeout :5*_d .Second }).DialContext ,TLSHandshakeTimeout :5*_d .Second }; +_gb .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_fc .Client {Transport :_dd ,Timeout :o .DefaultTimeout }};}; // Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. -type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;}; - -// HealthCheck connects to the server and check the health status of the server. -func (_ada *Client )HealthCheck (ctx _e .Context )error {_da :=_ada .Options .Addr ();_da =_gcg .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_da );_ab ,_be :=_ea .NewRequest ("\u0047\u0045\u0054",_da ,nil );if _be !=nil {return _be ;};_ab =_ab .WithContext (ctx ); -_bd ,_be :=_ada .Client .Do (_ab );if _be !=nil {return _be ;};switch _bd .StatusCode {case _ea .StatusOK :return nil ;case _ea .StatusNotFound :return ErrNotFound ;case _ea .StatusInternalServerError :return ErrInternalError ;case _ea .StatusBadGateway :return ErrBadGateway ; -default:return ErrNotImplemented ;};}; - -// MarginLeft sets up the MarginLeft parameter for the query. -func (_gcd *QueryBuilder )MarginLeft (marginLeft _gf .Length )*QueryBuilder {_gcd ._dbc .PageParameters .MarginLeft =marginLeft ;return _gcd ;}; +type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;TimeoutDuration _d .Duration ;}; -// Client is a structure that is a HTTP client for the unihtml server. -type Client struct{Options Options ;Client *_ea .Client ;}; - -// Validate checks if the parameters are valid. -func (_fgg *PageParameters )Validate ()error {if _fgg .PaperWidth !=nil {if _fgg .PaperWidth .Millimeters ()< 0{return _d .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); -};};if _fgg .PaperHeight !=nil {if _fgg .PaperHeight .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); -};};if _fgg .MarginTop !=nil {if _fgg .MarginTop .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _fgg .MarginBottom !=nil {if _fgg .MarginBottom .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); -};};if _fgg .MarginLeft !=nil {if _fgg .MarginLeft .Millimeters ()< 0{return _d .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};}; -if _fgg .MarginRight !=nil {if _fgg .MarginRight .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); -};};if _fgg .PageSize !=nil &&!_fgg .PageSize .IsAPageSize (){return _d .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; - -// PageSize sets up the PageSize parameter for the query. -func (_bde *QueryBuilder )PageSize (pageSize _gf .PageSize )*QueryBuilder {if pageSize !=_gf .Undefined {_bde ._dbc .PageParameters .PageSize =&pageSize ;};return _bde ;}; +// Options are the client options used by the HTTP client. +type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _d .Duration ;Prefix string ;}; -// WaitVisible waits for the selector to get visible. -func (_gab *QueryBuilder )WaitVisible (selector string ,by _eb .ByType )*QueryBuilder {_gab ._dbc .RenderParameters .WaitVisible =append (_gab ._dbc .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _gab ;}; +// Portrait sets up the portrait page orientation. +func (_gf *QueryBuilder )Portrait ()*QueryBuilder {_gf ._gaa .PageParameters .Orientation =_ae .Portrait ;return _gf ;}; // WithDefaultTimeout sets the DefaultTimeout option for the client options. -func WithDefaultTimeout (option _ad .Duration )Option {return func (_ade *Options ){_ade .DefaultTimeout =option };}; - -// Addr gets the HTTP address URI used by the http.Client. -func (_fc *Options )Addr ()string {_fa :=_g .Builder {};_fa .WriteString ("\u0068\u0074\u0074\u0070");if _fc .HTTPS {_fa .WriteRune ('s');};_fa .WriteString ("\u003a\u002f\u002f");_fa .WriteString (_fc .Hostname );_fa .WriteRune (':');_fa .WriteString (_ge .Itoa (_fc .Port )); -if _fc .Prefix !=""{_fa .WriteString (_fc .Prefix );};return _fa .String ();}; +func WithDefaultTimeout (option _d .Duration )Option {return func (_gdc *Options ){_gdc .DefaultTimeout =option };}; // RenderParameters are the parameters related with the rendering. -type RenderParameters struct{WaitTime _ad .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; - -// MarginRight sets up the MarginRight parameter for the query. -func (_ed *QueryBuilder )MarginRight (marginRight _gf .Length )*QueryBuilder {_ed ._dbc .PageParameters .MarginRight =marginRight ;return _ed ;}; +type RenderParameters struct{WaitTime _d .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; -// WithHostname sets the Hostname option for the client options. -func WithHostname (option string )Option {return func (_daf *Options ){_daf .Hostname =option }}; +// WithPrefix sets the client prefix. +func WithPrefix (prefix string )Option {return func (_gae *Options ){_gae .Prefix =prefix }}; -// PaperWidth sets up the PaperWidth (in cm) parameter for the query. -func (_gfg *QueryBuilder )PaperWidth (paperWidth _gf .Length )*QueryBuilder {_gfg ._dbc .PageParameters .PaperWidth =paperWidth ;return _gfg ;}; +// WaitReady waits for the selector to get ready - 'loaded'. +func (_eeg *QueryBuilder )WaitReady (selector string ,by _gedc .ByType )*QueryBuilder {_eeg ._gaa .RenderParameters .WaitReady =append (_eeg ._gaa .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _eeg ;}; // Validate checks validity of the selector. -func (_fbe BySelector )Validate ()error {if _fbe .Selector ==""{return _d .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _ece :=_fbe .By .Validate ();_ece !=nil {return _ece ; +func (_bfb BySelector )Validate ()error {if _bfb .Selector ==""{return _f .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _afd :=_bfb .By .Validate ();_afd !=nil {return _afd ; };return nil ;}; -// BySelector is a structure that defines a selector with it's query 'by' type. -type BySelector struct{Selector string `json:"selector"`;By _eb .ByType `json:"by"`;}; +// WaitVisible waits for the selector to get visible. +func (_cad *QueryBuilder )WaitVisible (selector string ,by _gedc .ByType )*QueryBuilder {_cad ._gaa .RenderParameters .WaitVisible =append (_cad ._gaa .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _cad ;}; -// ParseOptions parses options for the Client. -func ParseOptions (connectPath string )(Options ,error ){if !_g .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_ag ,_df :=_gc .Parse (connectPath );if _df !=nil {return Options {},_gcg .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); -};var _f int ;if _ag .Port ()!=""{_f ,_df =_ge .Atoi (_ag .Port ());if _df !=nil {return Options {},_gcg .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_df );}; -};return Options {Hostname :_ag .Hostname (),Port :_f ,HTTPS :_ag .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_ag .Path },nil ;}; \ No newline at end of file +// WithPort sets the Port option for the client options. +func WithPort (option int )Option {return func (_ef *Options ){_ef .Port =option }}; + +// PageSize sets up the PageSize parameter for the query. +func (_fb *QueryBuilder )PageSize (pageSize _ae .PageSize )*QueryBuilder {if pageSize !=_ae .Undefined {_fb ._gaa .PageParameters .PageSize =&pageSize ;};return _fb ;}; \ No newline at end of file diff --git a/common/common.go b/common/common.go index bab43e1..ae303be 100644 --- a/common/common.go +++ b/common/common.go @@ -10,8 +10,8 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package common contains common properties used by the subpackages. -package common ;import _e "time";var ReleasedAt =_e .Date (_a ,_g ,_ea ,_dg ,_ab ,0,0,_e .UTC );const _dg =12;const Version ="\u0030\u002e\u0036.\u0030"; +package common ;import _b "time";const Version ="\u0030\u002e\u0037.\u0030"; // UtcTimeFormat returns a formatted string describing a UTC timestamp. -func UtcTimeFormat (t _e .Time )string {return t .Format (_f )+"\u0020\u0055\u0054\u0043"};const _ea =5;const _f ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";const _ab =20; -const _a =2022;const _g =5; \ No newline at end of file +func UtcTimeFormat (t _b .Time )string {return t .Format (_ga )+"\u0020\u0055\u0054\u0043"};var ReleasedAt =_b .Date (_gf ,_f ,_be ,_e ,_ba ,0,0,_b .UTC );const _gf =2023;const _e =12;const _f =2;const _ga ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034"; +const _be =10;const _ba =20; \ No newline at end of file diff --git a/content/content.go b/content/content.go index 2e6ed95..9a9fc61 100644 --- a/content/content.go +++ b/content/content.go @@ -9,49 +9,50 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package content ;import (_a "archive/zip";_gc "bytes";_g "fmt";_de "io/ioutil";_c "net/url";_d "os";_f "strings";); +package content ;import (_d "archive/zip";_fa "bytes";_f "fmt";_c "io/ioutil";_a "net/url";_b "os";_g "strings";); -// Method gets the query method. -func (_gb *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"}; - -// NewHTMLFile creates new Content htmFile for provided input path. -func NewHTMLFile (path string )(Content ,error ){_fb ,_e :=_d .Open (path );if _e !=nil {return nil ,_e ;};_ee :=&htmlFile {_ff :_gc .Buffer {}};if _ ,_e =_ee ._ff .ReadFrom (_fb );_e !=nil {return nil ,_e ;};return _ee ,nil ;}; - -// Data implements Content interface. -func (_cd *webURL )Data ()[]byte {return []byte (_cd ._db )};type zipDirectory struct{_dd _gc .Buffer ;_bgg *_a .Writer ;}; +// ContentType implements Content interface. +func (_bac *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; // Data implements Content interface. -func (_bg *htmlFile )Data ()[]byte {return _bg ._ff .Bytes ()}; - -// Method gets the zip directory method. -func (_bgd *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; +func (_ef *webURL )Data ()[]byte {return []byte (_ef ._fb )};type webURL struct{_fb string }; // ContentType implements Content interface. -func (_fd *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; +func (_ge *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; // NewWebURL creates new Content webURL for provided input URL path. -func NewWebURL (path string )(Content ,error ){if _ ,_gg :=_c .Parse (path );_gg !=nil {return nil ,_gg ;};return &webURL {_db :path },nil ;}; - -// ContentType implements Content interface. -func (_fg *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; +func NewWebURL (path string )(Content ,error ){if _ ,_dc :=_a .Parse (path );_dc !=nil {return nil ,_dc ;};return &webURL {_fb :path },nil ;}; // NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' // and stores in it's in-memory buffer. -func NewZipDirectory (dirPath string )(Content ,error ){_ga :=&zipDirectory {_dd :_gc .Buffer {}};_ga ._bgg =_a .NewWriter (&_ga ._dd );if _ec :=_ga .zipPath (dirPath ,"");_ec !=nil {return nil ,_ec ;};if _eeb :=_ga ._bgg .Close ();_eeb !=nil {return nil ,_eeb ; -};return _ga ,nil ;};func (_ac *zipDirectory )zipBasePaths (_dbf _d .FileInfo ,_bfe ,_ffc string ,_ece bool ,_gfb *_f .Builder )(string ,string ){_gfb .WriteString (_bfe );if !_f .HasSuffix (_bfe ,"\u002f"){_gfb .WriteRune ('/');};_gfb .WriteString (_dbf .Name ()); -if _ece {_gfb .WriteRune ('/');};_fbd :=_gfb .String ();_gfb .Reset ();_gfb .WriteString (_ffc );_gfb .WriteString (_dbf .Name ());if _ece {_gfb .WriteRune ('/');};_fge :=_gfb .String ();_gfb .Reset ();return _fbd ,_fge ;};type webURL struct{_db string }; +func NewZipDirectory (dirPath string )(Content ,error ){_fd :=&zipDirectory {_ga :_fa .Buffer {}};_fd ._gb =_d .NewWriter (&_fd ._ga );if _bb :=_fd .zipPath (dirPath ,"");_bb !=nil {return nil ,_bb ;};if _ee :=_fd ._gb .Close ();_ee !=nil {return nil ,_ee ; +};return _fd ,nil ;}; +// Method gets the query method. +func (_aa *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"}; + +// ContentType implements Content interface. +func (_ba *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; + +// Data implements Content interface. +func (_ea *zipDirectory )Data ()[]byte {return _ea ._ga .Bytes ()}; + +// Method gets the zip directory method. +func (_efc *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; // Method gets the web url query method. -func (_df *webURL )Method ()string {return "\u0077\u0065\u0062"};func (_bda *zipDirectory )zipPath (_cg ,_eb string )error {_gad ,_gce :=_de .ReadDir (_cg );if _gce !=nil {return _g .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_cg ,_gce ); -};_bb :=&_f .Builder {};for _ ,_bf :=range _gad {_bbc ,_af :=_bda .zipBasePaths (_bf ,_cg ,_eb ,_bf .IsDir (),_bb );if _bf .IsDir (){if _gaf :=_bda .zipPath (_bbc ,_af );_gaf !=nil {return _gaf ;};continue ;};_dde ,_ffb :=_de .ReadFile (_bbc );if _ffb !=nil {return _ffb ; -};_bad ,_ffb :=_bda ._bgg .Create (_af );if _ffb !=nil {return _ffb ;};if _ ,_ffb =_bad .Write (_dde );_ffb !=nil {return _ffb ;};};return nil ;}; +func (_da *webURL )Method ()string {return "\u0077\u0065\u0062"};func (_cb *zipDirectory )zipBasePaths (_df _b .FileInfo ,_eg ,_dce string ,_fe bool ,_ffa *_g .Builder )(string ,string ){_ffa .WriteString (_eg );if !_g .HasSuffix (_eg ,"\u002f"){_ffa .WriteRune ('/'); +};_ffa .WriteString (_df .Name ());if _fe {_ffa .WriteRune ('/');};_fc :=_ffa .String ();_ffa .Reset ();_ffa .WriteString (_dce );_ffa .WriteString (_df .Name ());if _fe {_ffa .WriteRune ('/');};_fcb :=_ffa .String ();_ffa .Reset ();return _fc ,_fcb ;}; + // Content is an interface used for putting the content into Client Query. type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;}; -// ContentType implements Content interface. -func (_bd *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; +// NewHTMLFile creates new Content htmFile for provided input path. +func NewHTMLFile (path string )(Content ,error ){_gfd ,_ca :=_b .Open (path );if _ca !=nil {return nil ,_ca ;};_bf :=&htmlFile {_gf :_fa .Buffer {}};if _ ,_ca =_bf ._gf .ReadFrom (_gfd );_ca !=nil {return nil ,_ca ;};return _bf ,nil ;};type zipDirectory struct{_ga _fa .Buffer ; +_gb *_d .Writer ;}; // Data implements Content interface. -func (_ba *zipDirectory )Data ()[]byte {return _ba ._dd .Bytes ()};type htmlFile struct{_ff _gc .Buffer }; \ No newline at end of file +func (_ce *htmlFile )Data ()[]byte {return _ce ._gf .Bytes ()};type htmlFile struct{_gf _fa .Buffer };func (_aaa *zipDirectory )zipPath (_af ,_gg string )error {_dg ,_dd :=_c .ReadDir (_af );if _dd !=nil {return _f .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_af ,_dd ); +};_ggd :=&_g .Builder {};for _ ,_eae :=range _dg {_cd ,_eb :=_aaa .zipBasePaths (_eae ,_af ,_gg ,_eae .IsDir (),_ggd );if _eae .IsDir (){if _cg :=_aaa .zipPath (_cd ,_eb );_cg !=nil {return _cg ;};continue ;};_gge ,_ed :=_c .ReadFile (_cd );if _ed !=nil {return _ed ; +};_dab ,_ed :=_aaa ._gb .Create (_eb );if _ed !=nil {return _ed ;};if _ ,_ed =_dab .Write (_gge );_ed !=nil {return _ed ;};};return nil ;}; \ No newline at end of file diff --git a/selector/selector.go b/selector/selector.go index 0bf0252..97f80a6 100644 --- a/selector/selector.go +++ b/selector/selector.go @@ -9,11 +9,11 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package selector ;import _f "errors"; - -// Validate checks validity of the ByType. -func (_aa ByType )Validate ()error {if _aa >=ByID &&_aa <=BySearch {return nil ;};return _f .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};const (ByUndefined ByType =iota ;ByID ;ByQueryAll ; -ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); +package selector ;import _ff "errors"; // ByType is a 'By' selector type enumerator. -type ByType uint ; \ No newline at end of file +type ByType uint ; + +// Validate checks validity of the ByType. +func (_b ByType )Validate ()error {if _b >=ByID &&_b <=BySearch {return nil ;};return _ff .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};const (ByUndefined ByType =iota ;ByID ;ByQueryAll ; +ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); \ No newline at end of file diff --git a/sizes/sizes.go b/sizes/sizes.go index 4aac165..ca1d9dd 100644 --- a/sizes/sizes.go +++ b/sizes/sizes.go @@ -12,190 +12,190 @@ // Package sizes defines basic types that determines the size units i.e. lengths. // // -package sizes ;import (_d "encoding/json";_g "flag";_e "fmt";_c "strconv";_b "strings";);var _abc =map[string ]PageSize {_efbf [0:9]:0,_efbf [9:11]:1,_efbf [11:13]:2,_efbf [13:15]:3,_efbf [15:17]:4,_efbf [17:19]:5,_efbf [19:21]:6,_efbf [21:23]:7,_efbf [23:25]:8,_efbf [25:27]:9,_efbf [27:29]:10,_efbf [29:32]:11,_efbf [32:34]:12,_efbf [34:36]:13,_efbf [36:38]:14,_efbf [38:40]:15,_efbf [40:42]:16,_efbf [42:44]:17,_efbf [44:46]:18,_efbf [46:48]:19,_efbf [48:50]:20,_efbf [50:52]:21,_efbf [52:55]:22,_efbf [55:61]:23}; -var _ _g .Value =(*Orientation )(nil );var _egg =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; +package sizes ;import (_e "encoding/json";_b "flag";_a "fmt";_d "strconv";_bg "strings";);var (_ Length =Millimeter (0);); -// Inches gets the inches equivalent from provided millimeter value. -func (_eb Millimeter )Inches ()Inch {return Inch (float64 (_eb )*_cb )}; - -// Millimeters converts the inches value to the millimeters. -func (_fda Point )Millimeters ()Millimeter {return Millimeter (float64 (_fda )*_ce )};func _af (_gbb string )(Millimeter ,error ){_gbb =_b .TrimSpace (_b .TrimSuffix (_gbb ,"\u006d\u006d"));_fdg ,_bb :=_c .ParseFloat (_gbb ,64);if _bb !=nil {return 0,_e .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_bb ); -};return Millimeter (_fdg ),nil ;}; +// Set implements pflag.Value interface. +func (_eba *PageSize )Set (s string )error {_cca ,_aeb :=UnmarshalPageSize (s );if _aeb !=nil {return _aeb ;};*_eba =_cca ;return nil ;}; -// Name implements pflag.Value interface. -func (_ed Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; +// Type implements pflag.Value interface. +func (_gc Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; -// Millimeter is the dimension unit that defines a millimeter. -type Millimeter float64 ; +// UnmarshalInch unmarshalls provided string into unit. +func UnmarshalInch (unit string )(Inch ,error ){if _bg .HasSuffix (unit ,"\u006d\u006d"){_gg ,_ce :=_cc (unit );if _ce !=nil {return 0,_ce ;};return _gg .Inches (),nil ;};if _bg .HasSuffix (unit ,"\u0069\u006e"){return _bfa (unit );};return 0,_a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); +}; -// Type implements pflag.Value interface. -func (_eab Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; +// MarshalJSON implements the json.Marshaler interface for PageSize +func (_eecb PageSize )MarshalJSON ()([]byte ,error ){return _e .Marshal (_eecb .String ())}; -// String implements fmt.Stringer interface. -func (_gf Point )String ()string {_fba :=_b .Builder {};_fba .WriteString (_c .FormatFloat (float64 (_gf ),'f',1,64));_fba .WriteString ("\u0070\u0074");return _fba .String ();}; +// ValueType implements pflag.Value interface. +func (_bd Inch )ValueType ()string {return _bd .Type ()}; // Type implements pflag.Value interface. -func (_ebg PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; +func (_abc PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; -// Inches gets the inch value. Implements Length interface. -func (_eg Inch )Inches ()Inch {return _eg };func (_ceb PageSize )String ()string {if _ceb < 0||_ceb >=PageSize (len (_egg )-1){return _e .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_ceb );};return _efbf [_egg [_ceb ]:_egg [_ceb +1]]; +// Inches gets the inches equivalent from provided millimeter value. +func (_ca Millimeter )Inches ()Inch {return Inch (float64 (_ca )*_f )};func _eb (_fg Length )([]byte ,error ){if _fg ==nil {return nil ,nil ;};_gde ,_cd :=MarshalUnit (_fg );if _cd !=nil {return nil ,_cd ;};return []byte ("\u0022"+_gde +"\u0022"),nil ; }; -// MarshalText implements the encoding.TextMarshaler interface for PageSize -func (_fdef PageSize )MarshalText ()([]byte ,error ){return []byte (_fdef .String ()),nil }; +// Length is it the default dimension unit. +type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; -// UnmarshalJSON implements the json.Unmarshaler interface for PageSize -func (_eeg *PageSize )UnmarshalJSON (data []byte )error {var _eega string ;if _gfg :=_d .Unmarshal (data ,&_eega );_gfg !=nil {return _e .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); -};var _bee error ;*_eeg ,_bee =PageSizeString (_eega );return _bee ;}; +// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise +func (_faca PageSize )IsAPageSize ()bool {for _ ,_aaa :=range _dcb {if _faca ==_aaa {return true ;};};return false ;}; -// ValueType implements viper.FlagValue interface. -func (_da Point )ValueType ()string {return _da .Type ()}; +// Set sets the unit value. +// Implements pflag.Value interface. +func (_fc *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_fc .Length =nil ;return nil ;};_eaf ,_ag :=UnmarshalLength (s );if _ag !=nil {return _ag ;};_fc .Length =_eaf ;return nil ;}; -// Length is it the default dimension unit. -type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; +// HasChanged implements viper.FlagValue interface. +func (_dca *Point )HasChanged ()bool {return _dca !=nil }; -// Point is a unit of Length commonly used to measure the height of fonts. -type Point float64 ; +// Millimeters gets the float64 millimeter value. +func (_gd Millimeter )Millimeters ()Millimeter {return _gd }; -// MarshalJSON implements json.Marshaler interface. -func (_ggd Point )MarshalJSON ()([]byte ,error ){return _eaab (_ggd )}; +// MarshalJSON implements json.Marshaler interface +func (_fe Millimeter )MarshalJSON ()([]byte ,error ){return _eb (_fe )}; -// LengthFlag is a pflag wrapper for the Length value. -type LengthFlag struct{Length Length ;};const (Portrait =Orientation (false );Landscape =Orientation (true );); +// Type implements pflag.Value interface. +func (_ef Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; -// MarshalPageSize marshals the page size into string. -func MarshalPageSize (p PageSize )(string ,error ){_dae ,_ebf :=p .MarshalText ();if _ebf !=nil {return "",_ebf ;};return string (_dae ),nil ;}; +// PageSizeValues returns all values of the enum +func PageSizeValues ()[]PageSize {return _dcb }; -// PageSize is the enum used for defining the page size. -type PageSize int ; +// Name implements pflag.Value interface. +func (_eef Inch )Name ()string {return "\u0069\u006e\u0063\u0068"};var _ _b .Value =(*Orientation )(nil );func _cc (_fdg string )(Millimeter ,error ){_fdg =_bg .TrimSpace (_bg .TrimSuffix (_fdg ,"\u006d\u006d"));_fdd ,_dff :=_d .ParseFloat (_fdg ,64);if _dff !=nil {return 0,_a .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_dff ); +};return Millimeter (_fdd ),nil ;}; -// UnmarshalInch unmarshalls provided string into unit. -func UnmarshalInch (unit string )(Inch ,error ){if _b .HasSuffix (unit ,"\u006d\u006d"){_fc ,_cab :=_af (unit );if _cab !=nil {return 0,_cab ;};return _fc .Inches (),nil ;};if _b .HasSuffix (unit ,"\u0069\u006e"){return _eaa (unit );};return 0,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); -}; +// Dimensions gets the dimensions of the given page size. +// If provided page size is not valid than the function returns 0 values. +func (_baf PageSize )Dimensions ()(_dde ,_fac Millimeter ){switch _baf {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; +case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; +case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _dde ,_fac ;}; -// Inch is a unit that -type Inch float64 ;var _ _g .Value =(*Point )(nil ); +// ValueString implements pflag.Value interface. +func (_bf Inch )ValueString ()string {return _bf .String ()}; -// UnmarshalLength unmarshalls string value into Length. -func UnmarshalLength (length string )(Length ,error ){if _b .HasSuffix (length ,"\u006d\u006d"){return _af (length );};if _b .HasSuffix (length ,"\u0069\u006e"){return _eaa (length );};if _b .HasSuffix (length ,"\u0070\u0074"){return _gbd (length );};return nil ,_e .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length ); -};func _gbd (_ebb string )(Point ,error ){_ebb =_b .TrimSpace (_b .Trim (_ebb ,"\u0070\u0074"));_efba ,_gbc :=_c .ParseFloat (_ebb ,64);if _gbc !=nil {return 0,_gbc ;};return Point (_efba ),nil ;}; +// Orientation is the page orientation type wrapper. +type Orientation bool ; -// Inches gets the inch value. Implements Length interface. -func (_gbe Point )Inches ()Inch {return Inch (float64 (_gbe )*_ef )};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;); +// PageSize is the enum used for defining the page size. +type PageSize int ; -// Set implements flag.Value interface. -func (_bbg *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_bbg =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_bbg =Landscape ;default:return _e .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); -};return nil ;}; +// Point is a unit of Length commonly used to measure the height of fonts. +type Point float64 ; -// Set sets the unit value. -// Implements pflag.Value interface. -func (_fd *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_fd .Length =nil ;return nil ;};_ca ,_fde :=UnmarshalLength (s );if _fde !=nil {return _fde ;};_fd .Length =_ca ;return nil ;}; +// LengthFlag is a pflag wrapper for the Length value. +type LengthFlag struct{Length Length ;}; + +// Points implements Length interface. +func (_ff Inch )Points ()Point {return Point (float64 (_ff )*_bb )};const (Portrait =Orientation (false );Landscape =Orientation (true );); // String implements fmt.Stringer interface. -func (_gge Orientation )String ()string {if _gge ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";};var _ba =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; +func (_dd Millimeter )String ()string {_ge :=_bg .Builder {};_ge .WriteString (_d .FormatFloat (float64 (_dd ),'f',1,64));_ge .WriteString ("\u006d\u006d");return _ge .String ();}; +// UnmarshalPageSize unmarshals the page size from the string. +func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _gef PageSize ;if _aa :=(&_gef ).UnmarshalText ([]byte (pageSize ));_aa !=nil {return 0,_a .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_aa ); +};return _gef ,nil ;}; // String implements fmt.Stringer interface. -func (_efd Inch )String ()string {_gb :=_b .Builder {};_gb .WriteString (_c .FormatFloat (float64 (_efd ),'f',1,64));_gb .WriteString ("\u0069\u006e");return _gb .String ();}; +func (_bc Inch )String ()string {_eea :=_bg .Builder {};_eea .WriteString (_d .FormatFloat (float64 (_bc ),'f',1,64));_eea .WriteString ("\u0069\u006e");return _eea .String ();};const _bfg ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; +const (_f =float64 (1)/float64 (25.4);_ee =25.4;_c =0.0139;_ae =0.3528;_bb =1.0/64;_ea =1.0/_ae ;); -// ValueString implements pflag.Value interface. -func (_ddd Inch )ValueString ()string {return _ddd .String ()}; +// Points implements Length interface. +func (_eg Millimeter )Points ()Point {return Point (_eg *_ea )}; -// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize -func (_cda *PageSize )UnmarshalText (text []byte )error {var _ac error ;*_cda ,_ac =PageSizeString (string (text ));return _ac ;}; +// Type implements pflag.Value interface. +func (_bbb Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; -// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise -func (_gdd PageSize )IsAPageSize ()bool {for _ ,_ede :=range _ba {if _gdd ==_ede {return true ;};};return false ;}; +// MarshalUnit marshals the unit into the string. +func MarshalUnit (unit Length )(string ,error ){switch _da :=unit .(type ){case Millimeter :return _a .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_da ),nil ;case Inch :return _a .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_da ),nil ;case Point :return _a .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_da ),nil ; +default:return "",_a .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; -// Name implements viper.FlagValue interface. -func (_gfe Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; +// Millimeter is the dimension unit that defines a millimeter. +type Millimeter float64 ; -// MarshalJSON implements json.Marshaler interface -func (_cd Millimeter )MarshalJSON ()([]byte ,error ){return _eaab (_cd )}; +// MarshalJSON implements json.Marshaler interface. +func (_ad Point )MarshalJSON ()([]byte ,error ){return _eb (_ad )}; -// Orientation is the page orientation type wrapper. -type Orientation bool ; +// Name implements viper.FlagValue interface. +func (_fa Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; -// Type implements pflag.Value interface. -func (_efe *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"};func _eaa (_efb string )(Inch ,error ){_efb =_b .TrimSpace (_b .Trim (_efb ,"\u0069\u006e"));_dab ,_ebd :=_c .ParseFloat (_efb ,64);if _ebd !=nil {return 0,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ebd ); -};return Inch (_dab ),nil ;}; +// Millimeters converts the inches value to the millimeters. +func (_ba Inch )Millimeters ()Millimeter {return Millimeter (float64 (_ba )*_ee )}; -// Set implements flag.Value interface. -func (_fbd *Point )Set (s string )error {_cc ,_ea :=_c .ParseFloat (s ,64);if _ea !=nil {return _e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ea );};*_fbd =Point (_cc ); -return nil ;}; +// MarshalJSON implements json.Marshaler interface +func (_dc Inch )MarshalJSON ()([]byte ,error ){return _eb (_dc )};func _bfa (_ed string )(Inch ,error ){_ed =_bg .TrimSpace (_bg .Trim (_ed ,"\u0069\u006e"));_db ,_ac :=_d .ParseFloat (_ed ,64);if _ac !=nil {return 0,_a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ac ); +};return Inch (_db ),nil ;};var _gcc =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; -// Type implements pflag.Value interface. -func (_fb Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; +// Millimeters converts the inches value to the millimeters. +func (_aee Point )Millimeters ()Millimeter {return Millimeter (float64 (_aee )*_ae )}; -// Points implements Length interface. -func (_cde Point )Points ()Point {return _cde }; +// ValueString implements viper.FlagValue interface. +func (_cag Point )ValueString ()string {return _cag .String ()}; // String gets the string value for given flag. -func (_df *LengthFlag )String ()string {if _df .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _df .Length .String ();}; - -// MarshalJSON implements json.Marshaler interface -func (_egc Inch )MarshalJSON ()([]byte ,error ){return _eaab (_egc )}; +func (_bgd *LengthFlag )String ()string {if _bgd .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _bgd .Length .String ();}; -// MarshalUnit marshals the unit into the string. -func MarshalUnit (unit Length )(string ,error ){switch _aa :=unit .(type ){case Millimeter :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_aa ),nil ;case Inch :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_aa ),nil ;case Point :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_aa ),nil ; -default:return "",_e .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};};var (_ Length =Millimeter (0);); +// MarshalText implements the encoding.TextMarshaler interface for PageSize +func (_ada PageSize )MarshalText ()([]byte ,error ){return []byte (_ada .String ()),nil }; -// ValueType implements pflag.Value interface. -func (_dfc Inch )ValueType ()string {return _dfc .Type ()}; +// Inches gets the inch value. Implements Length interface. +func (_fb Point )Inches ()Inch {return Inch (float64 (_fb )*_c )};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;);func (_fab PageSize )String ()string {if _fab < 0||_fab >=PageSize (len (_gcc )-1){return _a .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_fab ); +};return _bfg [_gcc [_fab ]:_gcc [_fab +1]];};var _dcb =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; -// ValueString implements viper.FlagValue interface. -func (_db Point )ValueString ()string {return _db .String ()}; +// Inches gets the inch value. Implements Length interface. +func (_ab Inch )Inches ()Inch {return _ab }; -// Dimensions gets the dimensions of the given page size. -// If provided page size is not valid than the function returns 0 values. -func (_bcc PageSize )Dimensions ()(_bcd ,_ebba Millimeter ){switch _bcc {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; -case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; -case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _bcd ,_ebba ;}; +// Set implements flag.Value interface. +func (_egg *Point )Set (s string )error {_aed ,_abaa :=_d .ParseFloat (s ,64);if _abaa !=nil {return _a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_abaa );};*_egg =Point (_aed ); +return nil ;}; // Points implements Length interface. -func (_caa Millimeter )Points ()Point {return Point (_caa *_fa )}; +func (_dfa Point )Points ()Point {return _dfa }; -// Millimeters gets the float64 millimeter value. -func (_fe Millimeter )Millimeters ()Millimeter {return _fe }; - -// Type implements pflag.Value interface. -func (_fg Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; - -// UnmarshalPageSize unmarshals the page size from the string. -func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _egce PageSize ;if _cf :=(&_egce ).UnmarshalText ([]byte (pageSize ));_cf !=nil {return 0,_e .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_cf ); -};return _egce ,nil ;}; +// String implements fmt.Stringer interface. +func (_ddd Point )String ()string {_aba :=_bg .Builder {};_aba .WriteString (_d .FormatFloat (float64 (_ddd ),'f',1,64));_aba .WriteString ("\u0070\u0074");return _aba .String ();}; -// HasChanged implements pflag.Value interface. -func (_ee *Inch )HasChanged ()bool {return _ee !=nil }; +// Set implements flag.Value interface. +func (_ga *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_ga =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_ga =Landscape ;default:return _a .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); +};return nil ;}; -// PageSizeValues returns all values of the enum -func PageSizeValues ()[]PageSize {return _ba };const (_cb =float64 (1)/float64 (25.4);_f =25.4;_ef =0.0139;_ce =0.3528;_bf =1.0/64;_fa =1.0/_ce ;);var _ Length =Inch (0); +// Type implements pflag.Value interface. +func (_cg *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; -// Set implements pflag.Value interface. -func (_afg *PageSize )Set (s string )error {_dg ,_dga :=UnmarshalPageSize (s );if _dga !=nil {return _dga ;};*_afg =_dg ;return nil ;}; +// UnmarshalJSON implements the json.Unmarshaler interface for PageSize +func (_ccf *PageSize )UnmarshalJSON (data []byte )error {var _bafa string ;if _gae :=_e .Unmarshal (data ,&_bafa );_gae !=nil {return _a .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); +};var _dg error ;*_ccf ,_dg =PageSizeString (_bafa );return _dg ;}; -// Points implements Length interface. -func (_edf Inch )Points ()Point {return Point (float64 (_edf )*_bf )}; +// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize +func (_aef *PageSize )UnmarshalText (text []byte )error {var _de error ;*_aef ,_de =PageSizeString (string (text ));return _de ;}; -// String implements fmt.Stringer interface. -func (_cag Millimeter )String ()string {_ab :=_b .Builder {};_ab .WriteString (_c .FormatFloat (float64 (_cag ),'f',1,64));_ab .WriteString ("\u006d\u006d");return _ab .String ();}; +// ValueType implements viper.FlagValue interface. +func (_abf Point )ValueType ()string {return _abf .Type ()};var _eec =map[string ]PageSize {_bfg [0:9]:0,_bfg [9:11]:1,_bfg [11:13]:2,_bfg [13:15]:3,_bfg [15:17]:4,_bfg [17:19]:5,_bfg [19:21]:6,_bfg [21:23]:7,_bfg [23:25]:8,_bfg [25:27]:9,_bfg [27:29]:10,_bfg [29:32]:11,_bfg [32:34]:12,_bfg [34:36]:13,_bfg [36:38]:14,_bfg [38:40]:15,_bfg [40:42]:16,_bfg [42:44]:17,_bfg [44:46]:18,_bfg [46:48]:19,_bfg [48:50]:20,_bfg [50:52]:21,_bfg [52:55]:22,_bfg [55:61]:23}; -// Set implements pflag.Value interface. -func (_bc *Inch )Set (s string )error {_cg ,_bg :=_c .ParseFloat (s ,64);if _bg !=nil {return _e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_bg );};*_bc =Inch (_cg ); -return nil ;}; // PageSizeString retrieves an enum value from the enum constants string name. // Throws an error if the param is not part of the enum. -func PageSizeString (s string )(PageSize ,error ){if _fab ,_fae :=_abc [s ];_fae {return _fab ,nil ;};return 0,_e .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); +func PageSizeString (s string )(PageSize ,error ){if _cgf ,_dffb :=_eec [s ];_dffb {return _cgf ,nil ;};return 0,_a .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); }; -// Millimeters converts the inches value to the millimeters. -func (_eea Inch )Millimeters ()Millimeter {return Millimeter (float64 (_eea )*_f )};const _efbf ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; +// String implements fmt.Stringer interface. +func (_egf Orientation )String ()string {if _egf ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; +// UnmarshalLength unmarshalls string value into Length. +func UnmarshalLength (length string )(Length ,error ){if _bg .HasSuffix (length ,"\u006d\u006d"){return _cc (length );};if _bg .HasSuffix (length ,"\u0069\u006e"){return _bfa (length );};if _bg .HasSuffix (length ,"\u0070\u0074"){return _cee (length ); +};return nil ,_a .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length );}; -// MarshalJSON implements the json.Marshaler interface for PageSize -func (_ad PageSize )MarshalJSON ()([]byte ,error ){return _d .Marshal (_ad .String ())};func _eaab (_gga Length )([]byte ,error ){if _gga ==nil {return nil ,nil ;};_dfb ,_be :=MarshalUnit (_gga );if _be !=nil {return nil ,_be ;};return []byte ("\u0022"+_dfb +"\u0022"),nil ; -}; +// MarshalPageSize marshals the page size into string. +func MarshalPageSize (p PageSize )(string ,error ){_cbg ,_ebf :=p .MarshalText ();if _ebf !=nil {return "",_ebf ;};return string (_cbg ),nil ;}; -// HasChanged implements viper.FlagValue interface. -func (_gd *Point )HasChanged ()bool {return _gd !=nil }; \ No newline at end of file +// Inch is a unit that +type Inch float64 ; + +// Set implements pflag.Value interface. +func (_fd *Inch )Set (s string )error {_cb ,_feb :=_d .ParseFloat (s ,64);if _feb !=nil {return _a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_feb );};*_fd =Inch (_cb ); +return nil ;}; + +// HasChanged implements pflag.Value interface. +func (_fde *Inch )HasChanged ()bool {return _fde !=nil };func _cee (_ec string )(Point ,error ){_ec =_bg .TrimSpace (_bg .Trim (_ec ,"\u0070\u0074"));_adf ,_dbb :=_d .ParseFloat (_ec ,64);if _dbb !=nil {return 0,_dbb ;};return Point (_adf ),nil ;};var _ _b .Value =(*Point )(nil ); +var _ Length =Inch (0); \ No newline at end of file diff --git a/unihtml.go b/unihtml.go index 28b7810..bcfc514 100644 --- a/unihtml.go +++ b/unihtml.go @@ -10,59 +10,55 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package unihtml contains a plugin for the UniDoc. -package unihtml ;import (_df "bytes";_c "context";_cb "errors";_eg "fmt";_fc "github.com/unidoc/unihtml/client";_ce "github.com/unidoc/unihtml/content";_b "github.com/unidoc/unihtml/selector";_de "github.com/unidoc/unihtml/sizes";_fd "github.com/unidoc/unipdf/v3/common"; -_dd "github.com/unidoc/unipdf/v3/common/license";_dc "github.com/unidoc/unipdf/v3/creator";_be "github.com/unidoc/unipdf/v3/model";_ec "github.com/unidoc/unipdf/v3/render";_d "image";_e "image/color";_f "math";_a "net/url";_gc "os";_fb "time";); - -// WaitVisible waits for the provided selector to be ready. -// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_fdd *Document )WaitVisible (sel string ,by ..._b .ByType ){_gfe :=_b .BySearch ;if len (by )> 0{_gfe =by [0];};_fdd ._dbf =append (_fdd ._dbf ,_fc .BySelector {Selector :sel ,By :_gfe });}; - -// SetPageHeight sets the page height for given document. -func (_dfg *Document )SetPageHeight (pageHeight _de .Length )error {_dfg ._gd =pageHeight ;_dfg ._ccg =_dc .PositionAbsolute ;return nil ;};var ErrContentNotDefined =_cb .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); - +package unihtml ;import (_ga "bytes";_e "context";_ea "errors";_f "fmt";_eg "github.com/unidoc/unihtml/client";_b "github.com/unidoc/unihtml/content";_ge "github.com/unidoc/unihtml/selector";_ag "github.com/unidoc/unihtml/sizes";_eab "github.com/unidoc/unipdf/v3/common"; +_c "github.com/unidoc/unipdf/v3/common/license";_bg "github.com/unidoc/unipdf/v3/creator";_egd "github.com/unidoc/unipdf/v3/model";_ce "github.com/unidoc/unipdf/v3/render";_g "image";_ab "image/color";_af "math";_a "net/url";_de "os";_fg "time";);func (_ccf *Document )validate ()error {if _cee ==nil {return ErrNoClient ; +};if _ccf ._egf ==nil {return ErrContentNotDefined ;};return nil ;}; // ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. -func ConnectOptions (o Options )error {_fcd =_fc .New (_fc .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_dcc ,_cf :=_c .WithTimeout (_c .Background (),_fb .Second *5);defer _cf ();if _db :=_fcd .HealthCheck (_dcc );_db !=nil {return _db ; -};return nil ;};var ErrNoClient =_cb .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); - -// Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. -type Document struct{_fg _ce .Content ;_fe margins ;_ccg _dc .Positioning ;_dbg ,_gf float64 ;_feb _de .PageSize ;_ggd ,_gd _de .Length ;_aa _de .Orientation ;_ea bool ;_ccgd _fb .Duration ;_ccb []_fc .BySelector ;_dbf []_fc .BySelector ;_fa *_fb .Duration ; -}; - -// NewDocument creates new HTML Document used as an input for the creator.Drawable. -func NewDocument (path string )(*Document ,error ){_ddc :=&Document {};_fac ,_cea :=_a .Parse (path );if _cea !=nil {return nil ,_cea ;};switch _fac .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_ddc ._fg ,_cea =_ce .NewWebURL (path ); -if _cea !=nil {return nil ,_cea ;};return _ddc ,nil ;};_gdg ,_cea :=_gc .Stat (path );if _cea !=nil {return nil ,_cea ;};if !_gdg .IsDir (){_ddc ._fg ,_cea =_ce .NewHTMLFile (path );}else {_ddc ._fg ,_cea =_ce .NewZipDirectory (path );};if _cea !=nil {return nil ,_cea ; -};return _ddc ,nil ;}; +func ConnectOptions (o Options )error {_cee =_eg .New (_eg .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_cd ,_ed :=_e .WithTimeout (_e .Background (),_fg .Second *5);defer _ed ();if _afb :=_cee .HealthCheck (_cd );_afb !=nil {return _afb ; +};return nil ;};func (_gef *Document )extract (_aca _e .Context ,_dcf ,_eacf _ag .Length ,_eae margins )([]*_egd .PdfPage ,error ){_cbc :=_eg .BuildHTMLQuery ().SetContent (_gef ._egf ).PageSize (_gef ._geb ).PaperWidth (_dcf ).PaperHeight (_eacf ).Orientation (_gef ._gg ).MarginLeft (_eae .Left ).MarginRight (_eae .Right ).MarginTop (_eae .Top ).MarginBottom (_eae .Bottom ).TimeoutDuration (_gef .getTimeoutDuration ()).WaitTime (_gef ._egfb ); +for _ ,_cf :=range _gef ._ebc {_cbc .WaitReady (_cf .Selector ,_cf .By );};for _ ,_bbc :=range _gef ._dc {_cbc .WaitVisible (_bbc .Selector ,_bbc .By );};_gab ,_ee :=_cbc .Query ();if _ee !=nil {return nil ,_ee ;};var _dfaf _e .CancelFunc ;if _gef ._fae !=nil {_aca ,_dfaf =_e .WithTimeout (_aca ,*_gef ._fae ); +}else {_aca ,_dfaf =_e .WithTimeout (_aca ,_fg .Second *15);};defer _dfaf ();_ddg ,_ee :=_cee .ConvertHTML (_aca ,_gab );if _ee !=nil {return nil ,_ee ;};_egb :=_ga .NewReader (_ddg .Data );_dcb ,_ee :=_egd .NewPdfReader (_egb );if _ee !=nil {return nil ,_ee ; +};return _dcb .PageList ,nil ;}; // SetMargins sets the Document Margins. -func (_dac *Document )SetMargins (left ,right ,top ,bottom float64 ){_dac ._fe .Left =_de .Point (left );_dac ._fe .Right =_de .Point (right );_dac ._fe .Top =_de .Point (top );_dac ._fe .Bottom =_de .Point (bottom );_dac ._ccg =_dc .PositionAbsolute ; -}; - -// SetPos sets the absolute position. Changes object positioning to absolute. -func (_ede *Document )SetPos (x ,y float64 ){_ede ._ccg =_dc .PositionAbsolute ;_ede ._dbg =x ;_ede ._gf =y ;}; +func (_afd *Document )SetMargins (left ,right ,top ,bottom float64 ){_afd ._gc .Left =_ag .Point (left );_afd ._gc .Right =_ag .Point (right );_afd ._gc .Top =_ag .Point (top );_afd ._gc .Bottom =_ag .Point (bottom );_afd ._daf =_bg .PositionAbsolute ; +};func _aad ()error {_cb :=_c .GetLicenseKey ();if _cb ==nil {return _ea .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};if !_cb .IsLicensed (){return _ea .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); +};return nil ;}; -// WaitReady waits for the provided selector to be ready. +// WaitVisible waits for the provided selector to be ready. // A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_gb *Document )WaitReady (sel string ,by ..._b .ByType ){_eeg :=_b .BySearch ;if len (by )> 0{_eeg =by [0];};_gb ._ccb =append (_gb ._ccb ,_fc .BySelector {Selector :sel ,By :_eeg });}; +func (_abfb *Document )WaitVisible (sel string ,by ..._ge .ByType ){_egff :=_ge .BySearch ;if len (by )> 0{_egff =by [0];};_abfb ._dc =append (_abfb ._dc ,_eg .BySelector {Selector :sel ,By :_egff });}; + +// WaitTime sets the waiting time before the webpage is rendered to PDF. +func (_dd *Document )WaitTime (duration _fg .Duration ){_dd ._egfb =duration }; + +// ContainerComponent implements creator.containerElement interface. +func (_fbd *Document )ContainerComponent (container _bg .Drawable )(_bg .Drawable ,error ){switch container .(type ){case *_bg .Chapter :default:return nil ,_f .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); +};return _fbd ,nil ;}; // SetMarginTop sets the left margin. -func (_ceaa *Document )SetMarginTop (margin _de .Length ){_ceaa ._fe .Top =margin };func (_acc *Document )getMargins ()margins {_gafg :=_acc ._fe ;if _acc ._ccg .IsRelative (){_gafg .Top =_de .Millimeter (1);_gafg .Left =_de .Millimeter (1);_gafg .Bottom =_de .Millimeter (1); -_gafg .Right =_de .Millimeter (1);return _gafg ;};if _gafg .Top ==nil {_gafg .Top =_de .Millimeter (10);};if _gafg .Bottom ==nil {_gafg .Bottom =_de .Millimeter (10);};if _gafg .Left ==nil {_gafg .Left =_de .Millimeter (10);};if _gafg .Right ==nil {_gafg .Right =_de .Millimeter (10); -};return _gafg ;}; +func (_dae *Document )SetMarginTop (margin _ag .Length ){_dae ._gc .Top =margin };func _aaa (_ac _g .Image )float64 {_eacc :=_ac .Bounds ();var (_dfa int ;_gcg _ab .Color ;_dbbc ,_adb ,_afg uint32 ;);_cea ,_aae :=_eacc .Min .X ,_eacc .Max .Y -1;_bcc :=_ac .At (_cea ,_aae ); +_aff ,_aadb ,_egee ,_ :=_bcc .RGBA ();_gcaa :=_aff ==_af .MaxUint16 &&_aadb ==_af .MaxUint16 &&_egee ==_af .MaxUint16 ;for _aae =_eacc .Max .Y -1;_aae >=_eacc .Min .Y ;_aae --{var _age bool ;for _cea =_eacc .Min .X ;_cea < _eacc .Max .X ;_cea ++{_gcg =_ac .At (_cea ,_aae ); +_dbbc ,_adb ,_afg ,_ =_gcg .RGBA ();if (_gcaa &&!(_dbbc ==_aff &&_adb ==_aadb &&_egee ==_afg ))||(!_gcaa &&(_af .Abs (float64 (_dbbc )-float64 (_aff ))/float64 (_af .MaxUint16 )> 0.03||_af .Abs (float64 (_adb )-float64 (_aadb ))/float64 (_af .MaxUint16 )> 0.03||_af .Abs (float64 (_afg )-float64 (_egee ))/float64 (_af .MaxUint16 )> 0.03)){_age =true ; +break ;};};if _age {break ;};_dfa =_aae ;};return float64 (_eacc .Max .Y -_dfa )/float64 (_eacc .Max .Y );};func (_eaeb *Document )getTimeoutDuration ()_fg .Duration {if _eaeb ._fae !=nil {return *_eaeb ._fae ;};return 0;}; -// WriteToFile writes the document to a file defined by the output path. -func (_abd *Document )WriteToFile (outputPath string )error {if _daa :=_abd .validate ();_daa !=nil {return _daa ;};_dbbe :=_fb .Second *20+_abd ._ccgd ;_fgf ,_ade :=_c .WithTimeout (_c .Background (),_dbbe );defer _ade ();_aaf ,_ebc :=_abd .extract (_fgf ,_abd ._ggd ,_abd ._gd ,_abd .getMargins ()); -if _ebc !=nil {return _ebc ;};_eaf :=_dc .New ();for _ ,_dec :=range _aaf {if _ebc =_eaf .AddPage (_dec );_ebc !=nil {return _ebc ;};};return _eaf .WriteToFile (outputPath );}; +// GeneratePageBlocks implements creator.Drawable interface. +func (_df *Document )GeneratePageBlocks (ctx _bg .DrawContext )([]*_bg .Block ,_bg .DrawContext ,error ){if _ecg :=_df .validate ();_ecg !=nil {return nil ,ctx ,_ecg ;};var _bc []*_bg .Block ;_cef :=_df .getMargins ();_eca ,_dbb :=_df ._db ,_df ._gca ; +if _df ._daf .IsRelative (){_eca ,_dbb =_ag .Point (ctx .Width ),_ag .Point (ctx .Height );ctx .X -=float64 (_cef .Left .Points ());};_gb ,_bae :=_df .extract (_e .Background (),_eca ,_dbb ,_cef );if _bae !=nil {return nil ,_bg .DrawContext {},_bae ;}; +for _geg ,_be :=range _gb {_ebe ,_bca :=_bg .NewBlockFromPage (_be );if _bca !=nil {return nil ,_bg .DrawContext {},_bca ;};var _fe float64 ;if _df ._bd &&_geg ==len (_gb )-1{_ca :=_ce .NewImageDevice ();_agc ,_bf :=_ca .Render (_be );if _bf !=nil {return nil ,_bg .DrawContext {},_bf ; +};_aed ,_bf :=_be .GetMediaBox ();if _bf !=nil {return nil ,_bg .DrawContext {},_bf ;};_abf :=_fg .Now ();_bee :=_aaa (_agc );_fe =_aed .Height ()*_bee ;_eab .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_fg .Since (_abf )); +if _df ._gc .Bottom !=nil {_fe -=float64 (_df ._gc .Bottom .Points ());};if _fe < 0{_fe =0;};_eab .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_fe ); +};_aec ,_cc ,_bca :=_ebe .GeneratePageBlocks (ctx );if _bca !=nil {return nil ,_bg .DrawContext {},_bca ;};ctx =_cc ;ctx .Y -=_fe ;if _geg !=len (_gb )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; +ctx .Page ++;};_bc =append (_bc ,_aec ...);};return _bc ,ctx ,nil ;}; -// SetLandscapeOrientation sets document landscape page orientation. -func (_adf *Document )SetLandscapeOrientation (){_adf ._aa =_de .Landscape };func _cae (_ga _d .Image )float64 {_faa :=_ga .Bounds ();var (_ed int ;_cge _e .Color ;_cgd ,_beg ,_daf uint32 ;);_cgc ,_bga :=_faa .Min .X ,_faa .Max .Y -1;_gaf :=_ga .At (_cgc ,_bga ); -_bdg ,_faf ,_begb ,_ :=_gaf .RGBA ();_decb :=_bdg ==_f .MaxUint16 &&_faf ==_f .MaxUint16 &&_begb ==_f .MaxUint16 ;for _bga =_faa .Max .Y -1;_bga >=_faa .Min .Y ;_bga --{var _bf bool ;for _cgc =_faa .Min .X ;_cgc < _faa .Max .X ;_cgc ++{_cge =_ga .At (_cgc ,_bga ); -_cgd ,_beg ,_daf ,_ =_cge .RGBA ();if (_decb &&!(_cgd ==_bdg &&_beg ==_faf &&_begb ==_daf ))||(!_decb &&(_f .Abs (float64 (_cgd )-float64 (_bdg ))/float64 (_f .MaxUint16 )> 0.03||_f .Abs (float64 (_beg )-float64 (_faf ))/float64 (_f .MaxUint16 )> 0.03||_f .Abs (float64 (_daf )-float64 (_begb ))/float64 (_f .MaxUint16 )> 0.03)){_bf =true ; -break ;};};if _bf {break ;};_ed =_bga ;};return float64 (_faa .Max .Y -_ed )/float64 (_faa .Max .Y );};type margins struct{Left ,Right ,Bottom ,Top _de .Length ;}; +// SetPos sets the absolute position. Changes object positioning to absolute. +func (_aeb *Document )SetPos (x ,y float64 ){_aeb ._daf =_bg .PositionAbsolute ;_aeb ._fa =x ;_aeb ._eb =y ;}; -// ContainerComponent implements creator.containerElement interface. -func (_ddg *Document )ContainerComponent (container _dc .Drawable )(_dc .Drawable ,error ){switch container .(type ){case *_dc .Chapter :default:return nil ,_eg .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); -};return _ddg ,nil ;}; +// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. +func (_cg *Document )TrimLastPageContent (){_cg ._bd =true };type margins struct{Left ,Right ,Bottom ,Top _ag .Length ;};func (_ede *Document )getMargins ()margins {_ef :=_ede ._gc ;if _ede ._daf .IsRelative (){_ef .Top =_ag .Millimeter (1);_ef .Left =_ag .Millimeter (1); +_ef .Bottom =_ag .Millimeter (1);_ef .Right =_ag .Millimeter (1);return _ef ;};if _ef .Top ==nil {_ef .Top =_ag .Millimeter (10);};if _ef .Bottom ==nil {_ef .Bottom =_ag .Millimeter (10);};if _ef .Left ==nil {_ef .Left =_ag .Millimeter (10);};if _ef .Right ==nil {_ef .Right =_ag .Millimeter (10); +};return _ef ;}; // Options are the HTML Client options used for establishing the connection. type Options struct{ @@ -77,50 +73,56 @@ Port int ; Secure bool ; // Prefix is an option setting used when the server is working with the URI prefix. Default Value: ''. -Prefix string ;};var _ _dc .Drawable =(*Document )(nil ); +Prefix string ;}; -// SetMarginBottom sets the left margin. -func (_begbg *Document )SetMarginBottom (margin _de .Length ){_begbg ._fe .Bottom =margin }; +// SetTimeoutDuration sets the timeout duration +// the default timeout is 15 seconds. +func (_gcc *Document )SetTimeoutDuration (duration _fg .Duration ){_gcc ._fae =&duration };var ErrContentNotDefined =_ea .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); -// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. -func (_cac *Document )TrimLastPageContent (){_cac ._ea =true }; -// SetMarginRight sets the left margin. -func (_fed *Document )SetMarginRight (margin _de .Length ){_fed ._fe .Right =margin };func (_eac *Document )validate ()error {if _fcd ==nil {return ErrNoClient ;};if _eac ._fg ==nil {return ErrContentNotDefined ;};return nil ;};var _fcd *_fc .Client ; +// WaitReady waits for the provided selector to be ready. +// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. +func (_bdd *Document )WaitReady (sel string ,by ..._ge .ByType ){_faef :=_ge .BySearch ;if len (by )> 0{_faef =by [0];};_bdd ._ebc =append (_bdd ._ebc ,_eg .BySelector {Selector :sel ,By :_faef });}; + +// NewDocument creates new HTML Document used as an input for the creator.Drawable. +func NewDocument (path string )(*Document ,error ){_bb :=&Document {};_bgc ,_eabf :=_a .Parse (path );if _eabf !=nil {return nil ,_eabf ;};switch _bgc .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_bb ._egf ,_eabf =_b .NewWebURL (path ); +if _eabf !=nil {return nil ,_eabf ;};return _bb ,nil ;};_ae ,_eabf :=_de .Stat (path );if _eabf !=nil {return nil ,_eabf ;};if !_ae .IsDir (){_bb ._egf ,_eabf =_b .NewHTMLFile (path );}else {_bb ._egf ,_eabf =_b .NewZipDirectory (path );};if _eabf !=nil {return nil ,_eabf ; +};return _bb ,nil ;}; + +// SetLandscapeOrientation sets document landscape page orientation. +func (_eaf *Document )SetLandscapeOrientation (){_eaf ._gg =_ag .Landscape }; // Connect creates UniHTML HTTP Client and tries to establish connection with the server. -func Connect (path string )error {if _ef :=_gg ();_ef !=nil {return _ef ;};_ge ,_dg :=_fc .ParseOptions (path );if _dg !=nil {return _dg ;};_fcd =_fc .New (_ge );_ca ,_ab :=_c .WithTimeout (_c .Background (),_fb .Second *5);defer _ab ();if _eb :=_fcd .HealthCheck (_ca ); -_eb !=nil {return _eb ;};return nil ;}; +func Connect (path string )error {if _da :=_aad ();_da !=nil {return _da ;};_ad ,_aa :=_eg .ParseOptions (path );if _aa !=nil {return _aa ;};_cee =_eg .New (_ad );_ceg ,_fc :=_e .WithTimeout (_e .Background (),_fg .Second *5);defer _fc ();if _ba :=_cee .HealthCheck (_ceg ); +_ba !=nil {return _ba ;};return nil ;}; -// SetPageSize sets the page default size. -func (_cba *Document )SetPageSize (pageSize _de .PageSize )error {if !pageSize .IsAPageSize (){return _cb .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); -};_cba ._feb =pageSize ;_cba ._ccg =_dc .PositionAbsolute ;return nil ;};func (_cebe *Document )extract (_ccc _c .Context ,_bef ,_dga _de .Length ,_ggg margins )([]*_be .PdfPage ,error ){_daca :=_fc .BuildHTMLQuery ().SetContent (_cebe ._fg ).PageSize (_cebe ._feb ).PaperWidth (_bef ).PaperHeight (_dga ).Orientation (_cebe ._aa ).MarginLeft (_ggg .Left ).MarginRight (_ggg .Right ).MarginTop (_ggg .Top ).MarginBottom (_ggg .Bottom ).WaitTime (_cebe ._ccgd ); -for _ ,_eea :=range _cebe ._ccb {_daca .WaitReady (_eea .Selector ,_eea .By );};for _ ,_cef :=range _cebe ._dbf {_daca .WaitVisible (_cef .Selector ,_cef .By );};_fdc ,_fca :=_daca .Query ();if _fca !=nil {return nil ,_fca ;};var _ae _c .CancelFunc ;if _cebe ._fa !=nil {_ccc ,_ae =_c .WithTimeout (_ccc ,*_cebe ._fa ); -}else {_ccc ,_ae =_c .WithTimeout (_ccc ,_fb .Second *15);};defer _ae ();_ege ,_fca :=_fcd .ConvertHTML (_ccc ,_fdc );if _fca !=nil {return nil ,_fca ;};_bcb :=_df .NewReader (_ege .Data );_geb ,_fca :=_be .NewPdfReader (_bcb );if _fca !=nil {return nil ,_fca ; -};return _geb .PageList ,nil ;}; +// WriteToFile writes the document to a file defined by the output path. +func (_dbd *Document )WriteToFile (outputPath string )error {if _adf :=_dbd .validate ();_adf !=nil {return _adf ;};_fcf :=_fg .Second *20+_dbd ._egfb ;_ecd ,_fcfd :=_e .WithTimeout (_e .Background (),_fcf );defer _fcfd ();_fb ,_faa :=_dbd .extract (_ecd ,_dbd ._db ,_dbd ._gca ,_dbd .getMargins ()); +if _faa !=nil {return _faa ;};_ege :=_bg .New ();for _ ,_dbg :=range _fb {if _faa =_ege .AddPage (_dbg );_faa !=nil {return _faa ;};};return _ege .WriteToFile (outputPath );};var ErrNoClient =_ea .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); -// SetTimeoutDuration sets the timeout duration -// the default timeout is 15 seconds. -func (_gbg *Document )SetTimeoutDuration (duration _fb .Duration ){_gbg ._fa =&duration }; + +// Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. +type Document struct{_egf _b .Content ;_gc margins ;_daf _bg .Positioning ;_fa ,_eb float64 ;_geb _ag .PageSize ;_db ,_gca _ag .Length ;_gg _ag .Orientation ;_bd bool ;_egfb _fg .Duration ;_ebc []_eg .BySelector ;_dc []_eg .BySelector ;_fae *_fg .Duration ; +}; // SetPageWidth sets the page width for given document. -func (_ag *Document )SetPageWidth (pageWidth _de .Length )error {_ag ._ggd =pageWidth ;_ag ._ccg =_dc .PositionAbsolute ;return nil ;}; +func (_cbf *Document )SetPageWidth (pageWidth _ag .Length )error {_cbf ._db =pageWidth ;_cbf ._daf =_bg .PositionAbsolute ;return nil ;}; + +// SetMarginRight sets the left margin. +func (_fcb *Document )SetMarginRight (margin _ag .Length ){_fcb ._gc .Right =margin }; + +// SetPageSize sets the page default size. +func (_gcgg *Document )SetPageSize (pageSize _ag .PageSize )error {if !pageSize .IsAPageSize (){return _ea .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); +};_gcgg ._geb =pageSize ;_gcgg ._daf =_bg .PositionAbsolute ;return nil ;}; // GetPdfPages is a function that converts provided input content and -func (_ee *Document )GetPdfPages (ctx _c .Context )([]*_be .PdfPage ,error ){if _cce :=_ee .validate ();_cce !=nil {return nil ,_cce ;};return _ee .extract (ctx ,_ee ._ggd ,_ee ._gd ,_ee .getMargins ());};func _gg ()error {_cc :=_dd .GetLicenseKey ();if _cc ==nil {return _cb .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); -};if !_cc .IsLicensed (){return _cb .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};return nil ;}; +func (_fgb *Document )GetPdfPages (ctx _e .Context )([]*_egd .PdfPage ,error ){if _eac :=_fgb .validate ();_eac !=nil {return nil ,_eac ;};return _fgb .extract (ctx ,_fgb ._db ,_fgb ._gca ,_fgb .getMargins ());}; -// GeneratePageBlocks implements creator.Drawable interface. -func (_dbb *Document )GeneratePageBlocks (ctx _dc .DrawContext )([]*_dc .Block ,_dc .DrawContext ,error ){if _ceb :=_dbb .validate ();_ceb !=nil {return nil ,ctx ,_ceb ;};var _cg []*_dc .Block ;_bg :=_dbb .getMargins ();_dcb ,_fbd :=_dbb ._ggd ,_dbb ._gd ; -if _dbb ._ccg .IsRelative (){_dcb ,_fbd =_de .Point (ctx .Width ),_de .Point (ctx .Height );ctx .X -=float64 (_bg .Left .Points ());};_fbf ,_fbe :=_dbb .extract (_c .Background (),_dcb ,_fbd ,_bg );if _fbe !=nil {return nil ,_dc .DrawContext {},_fbe ;}; -for _bb ,_bd :=range _fbf {_dde ,_da :=_dc .NewBlockFromPage (_bd );if _da !=nil {return nil ,_dc .DrawContext {},_da ;};var _gdf float64 ;if _dbb ._ea &&_bb ==len (_fbf )-1{_def :=_ec .NewImageDevice ();_ddf ,_ddb :=_def .Render (_bd );if _ddb !=nil {return nil ,_dc .DrawContext {},_ddb ; -};_abg ,_ddb :=_bd .GetMediaBox ();if _ddb !=nil {return nil ,_dc .DrawContext {},_ddb ;};_ad :=_fb .Now ();_cgb :=_cae (_ddf );_gdf =_abg .Height ()*_cgb ;_fd .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_fb .Since (_ad )); -if _dbb ._fe .Bottom !=nil {_gdf -=float64 (_dbb ._fe .Bottom .Points ());};if _gdf < 0{_gdf =0;};_fd .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_gdf ); -};_ba ,_fcc ,_da :=_dde .GeneratePageBlocks (ctx );if _da !=nil {return nil ,_dc .DrawContext {},_da ;};ctx =_fcc ;ctx .Y -=_gdf ;if _bb !=len (_fbf )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; -ctx .Page ++;};_cg =append (_cg ,_ba ...);};return _cg ,ctx ,nil ;}; +// SetPageHeight sets the page height for given document. +func (_eda *Document )SetPageHeight (pageHeight _ag .Length )error {_eda ._gca =pageHeight ;_eda ._daf =_bg .PositionAbsolute ;return nil ;};var _ _bg .Drawable =(*Document )(nil );var _cee *_eg .Client ; // SetMarginLeft sets the left margin. -func (_fbdd *Document )SetMarginLeft (margin _de .Length ){_fbdd ._fe .Left =margin }; +func (_gga *Document )SetMarginLeft (margin _ag .Length ){_gga ._gc .Left =margin }; -// WaitTime sets the waiting time before the webpage is rendered to PDF. -func (_cace *Document )WaitTime (duration _fb .Duration ){_cace ._ccgd =duration }; \ No newline at end of file +// SetMarginBottom sets the left margin. +func (_gcb *Document )SetMarginBottom (margin _ag .Length ){_gcb ._gc .Bottom =margin }; \ No newline at end of file From 59788a6cdca081a8aa14159e108f220baba0def2 Mon Sep 17 00:00:00 2001 From: UniDoc Build Date: Thu, 25 Jan 2024 21:52:36 +0000 Subject: [PATCH 4/9] prepare release --- cli/cmd/cmd.go | 73 ++++---- client/client.go | 290 +++++++++++++++--------------- common/common.go | 6 +- content/content.go | 75 ++++---- go.mod | 52 ++++-- go.sum | 408 ++++++++----------------------------------- selector/selector.go | 4 +- sizes/sizes.go | 251 +++++++++++++------------- unihtml.go | 167 +++++++++--------- 9 files changed, 556 insertions(+), 770 deletions(-) diff --git a/cli/cmd/cmd.go b/cli/cmd/cmd.go index f5eaa9a..638e114 100644 --- a/cli/cmd/cmd.go +++ b/cli/cmd/cmd.go @@ -9,56 +9,55 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package cmd ;import (_e "context";_bc "fmt";_efg "github.com/mitchellh/go-homedir";_g "github.com/spf13/cobra";_fd "github.com/spf13/viper";_fe "github.com/unidoc/unihtml/client";_ab "github.com/unidoc/unihtml/content";_d "github.com/unidoc/unihtml/sizes"; -_a "github.com/unidoc/unipdf/v3/common";_b "os";_ff "path/filepath";_ef "time";);var _egf =&_g .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; -var (_eb =generateConfig {};_ba =parametersConfig {PaperWidth :_d .LengthFlag {Length :_d .Inch (8.5).Millimeters ()},PaperHeight :_d .LengthFlag {Length :_d .Inch (11).Millimeters ()},Orientation :_d .Portrait ,MarginTop :_d .LengthFlag {Length :_d .Millimeter (10)},MarginBottom :_d .LengthFlag {Length :_d .Millimeter (10)},MarginLeft :_d .LengthFlag {Length :_d .Millimeter (10)},MarginRight :_d .LengthFlag {Length :_d .Millimeter (10)}}; -);func _gg (cmd *_g .Command ,_eg []string ){_gd :=_ef .Now ();if _abc :=_fd .BindPFlags (cmd .Flags ());_abc !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_abc );_b .Exit (1);};if _ebb :=_fd .Unmarshal (&_eb );_ebb !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ebb ); -_b .Exit (1);};_gfg ();_dg ,_c :=_b .Stat (_eg [0]);if _c !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_c );_b .Exit (1);};if !_dg .IsDir (){if _ff .Ext (_dg .Name ())!="\u002e\u0068\u0074m\u006c"{_bc .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_eg [0]); -_b .Exit (1);};};_fg ,_c :=_b .OpenFile (_eg [1],_b .O_CREATE |_b .O_WRONLY |_b .O_TRUNC ,0700);if _c !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_c );_b .Exit (1);};defer _fg .Close ();_fed :=_fe .New (_fe .Options {HTTPS :_eb .Https ,Hostname :_eb .Host ,Port :_eb .Port ,Prefix :_eb .Prefix }); -_ec ,_cd :=_e .WithTimeout (_e .Background (),_ef .Second *10);defer _cd ();_ed :=_ef .Now ();var _fa _ab .Content ;if _dg .IsDir (){_fa ,_c =_ab .NewZipDirectory (_eg [0]);}else {_fa ,_c =_ab .NewHTMLFile (_eg [0]);};if _c !=nil {_bc .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_c ); -_b .Exit (1);};_ea ,_c :=_fe .BuildHTMLQuery ().PaperWidth (_ba .PaperWidth .Length ).PaperHeight (_ba .PaperHeight .Length ).PageSize (_ba .PageSize ).MarginTop (_ba .MarginTop .Length ).MarginBottom (_ba .MarginBottom .Length ).MarginLeft (_ba .MarginLeft .Length ).MarginRight (_ba .MarginRight .Length ).Orientation (_ba .Orientation ).SetContent (_fa ).Query (); -if _c !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_c );_b .Exit (1);};_ece ,_c :=_fed .ConvertHTML (_ec ,_ea );if _c !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_c );_b .Exit (1);};_a .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_ef .Since (_ed )); -_ed =_ef .Now ();_ ,_c =_fg .Write (_ece .Data );if _c !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_c );_b .Exit (1);};_a .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_ef .Since (_ed )); -_bc .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_ef .Since (_gd ));};var _ac =&_g .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_gg ,Args :_g .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; -func init (){_egf .AddCommand (_ac );_ac .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072");_ac .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); -_ac .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); -_ac .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); -_ac .Flags ().Var (&_ba .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_ac .Flags ().Var (&_ba .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); -_ac .Flags ().Var (&_ba .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_ac .Flags ().Var (&_ba .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); -_ac .Flags ().Var (&_ba .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_ac .Flags ().Var (&_ba .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); -_ac .Flags ().Var (&_ba .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_ac .Flags ().Var (&_ba .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); -};func _gfg (){_ca :=_a .LogLevelInfo ;if _fb {_ca =_a .LogLevelDebug ;};if _abf {_ca =_a .LogLevelTrace ;};_a .Log =_a .NewConsoleLogger (_ca );};var (_fb ,_abf bool ;);type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`; -Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};var _gge string ;type parametersConfig struct{ +package cmd ;import (_a "context";_c "fmt";_f "github.com/mitchellh/go-homedir";_ca "github.com/spf13/cobra";_cg "github.com/spf13/viper";_e "github.com/unidoc/unihtml/client";_cd "github.com/unidoc/unihtml/content";_bb "github.com/unidoc/unihtml/sizes"; +_bc "github.com/unidoc/unipdf/v3/common";_db "os";_g "path/filepath";_b "time";);func _ae (){_ba :=_bc .LogLevelInfo ;if _dfc {_ba =_bc .LogLevelDebug ;};if _dgd {_ba =_bc .LogLevelTrace ;};_bc .Log =_bc .NewConsoleLogger (_ba );};var _ebf =&_ca .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; +var _da =&_ca .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_gf ,Args :_ca .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; +func _gf (cmd *_ca .Command ,_ff []string ){_ec :=_b .Now ();if _bbg :=_cg .BindPFlags (cmd .Flags ());_bbg !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_bbg );_db .Exit (1);};if _ed :=_cg .Unmarshal (&_df );_ed !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ed ); +_db .Exit (1);};_ae ();_ga ,_dg :=_db .Stat (_ff [0]);if _dg !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dg );_db .Exit (1);};if !_ga .IsDir (){if _g .Ext (_ga .Name ())!="\u002e\u0068\u0074m\u006c"{_c .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_ff [0]); +_db .Exit (1);};};_fb ,_dg :=_db .OpenFile (_ff [1],_db .O_CREATE |_db .O_WRONLY |_db .O_TRUNC ,0700);if _dg !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dg );_db .Exit (1);};defer _fb .Close ();_bg :=_e .New (_e .Options {HTTPS :_df .Https ,Hostname :_df .Host ,Port :_df .Port ,Prefix :_df .Prefix }); +_cde ,_eeb :=_a .WithTimeout (_a .Background (),_b .Second *10);defer _eeb ();_dgc :=_b .Now ();var _eb _cd .Content ;if _ga .IsDir (){_eb ,_dg =_cd .NewZipDirectory (_ff [0]);}else {_eb ,_dg =_cd .NewHTMLFile (_ff [0]);};if _dg !=nil {_c .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_dg ); +_db .Exit (1);};_ad ,_dg :=_e .BuildHTMLQuery ().PaperWidth (_ag .PaperWidth .Length ).PaperHeight (_ag .PaperHeight .Length ).PageSize (_ag .PageSize ).MarginTop (_ag .MarginTop .Length ).MarginBottom (_ag .MarginBottom .Length ).MarginLeft (_ag .MarginLeft .Length ).MarginRight (_ag .MarginRight .Length ).Orientation (_ag .Orientation ).SetContent (_eb ).Query (); +if _dg !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dg );_db .Exit (1);};_dc ,_dg :=_bg .ConvertHTML (_cde ,_ad );if _dg !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dg );_db .Exit (1);};_bc .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_b .Since (_dgc )); +_dgc =_b .Now ();_ ,_dg =_fb .Write (_dc .Data );if _dg !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dg );_db .Exit (1);};_bc .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_b .Since (_dgc )); +_c .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_b .Since (_ec ));};func init (){_ebf .AddCommand (_da );_da .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072"); +_da .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); +_da .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); +_da .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); +_da .Flags ().Var (&_ag .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_da .Flags ().Var (&_ag .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); +_da .Flags ().Var (&_ag .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_da .Flags ().Var (&_ag .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); +_da .Flags ().Var (&_ag .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_da .Flags ().Var (&_ag .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); +_da .Flags ().Var (&_ag .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_da .Flags ().Var (&_ag .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); +};func _fbf (){if _bcc !=""{_cg .SetConfigFile (_bcc );}else {_cdac ,_aa :=_f .Dir ();if _aa !=nil {_c .Println (_aa );_db .Exit (1);};_cg .AddConfigPath (_cdac );_cg .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063"); +};_cg .AutomaticEnv ();if _af :=_cg .ReadInConfig ();_af ==nil {_c .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_cg .ConfigFileUsed ());};};var (_dfc ,_dgd bool ;);type generateConfig struct{Port int `mapstructure:"port"`; +Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;}; + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute (){if _ebg :=_ebf .Execute ();_ebg !=nil {_c .Println (_ebg );_db .Exit (1);};};var (_df =generateConfig {};_ag =parametersConfig {PaperWidth :_bb .LengthFlag {Length :_bb .Inch (8.5).Millimeters ()},PaperHeight :_bb .LengthFlag {Length :_bb .Inch (11).Millimeters ()},Orientation :_bb .Portrait ,MarginTop :_bb .LengthFlag {Length :_bb .Millimeter (10)},MarginBottom :_bb .LengthFlag {Length :_bb .Millimeter (10)},MarginLeft :_bb .LengthFlag {Length :_bb .Millimeter (10)},MarginRight :_bb .LengthFlag {Length :_bb .Millimeter (10)}}; +);func init (){_ca .OnInitialize (_fbf );_ebf .PersistentFlags ().BoolVarP (&_dfc ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065");_ebf .PersistentFlags ().BoolVarP (&_dgd ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); +_ebf .PersistentFlags ().StringVar (&_bcc ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); +_ebf .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};type parametersConfig struct{ // PaperWidth sets the width of the paper. -PaperWidth _d .LengthFlag `mapstructure:"paper-width"`; +PaperWidth _bb .LengthFlag `mapstructure:"paper-width"`; // PaperHeight is the height of the output paper. -PaperHeight _d .LengthFlag `mapstructure:"paper-height"`; +PaperHeight _bb .LengthFlag `mapstructure:"paper-height"`; // PageSize is the page size string. -PageSize _d .PageSize `mapstructure:"page-size"`; +PageSize _bb .PageSize `mapstructure:"page-size"`; // Orientation defines if the output should be in a landscape format. -Orientation _d .Orientation `mapstructure:"orientation"`; +Orientation _bb .Orientation `mapstructure:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _d .LengthFlag `mapstructure:"margin-top"`; +MarginTop _bb .LengthFlag `mapstructure:"margin-top"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _d .LengthFlag `mapstructure:"margin-bottom"`; +MarginBottom _bb .LengthFlag `mapstructure:"margin-bottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _d .LengthFlag `mapstructure:"margin-left"`; +MarginLeft _bb .LengthFlag `mapstructure:"margin-left"`; // MarginRight sets up the Right Margin for the output. -MarginRight _d .LengthFlag `mapstructure:"margin-right"`;};func init (){_g .OnInitialize (_ga );_egf .PersistentFlags ().BoolVarP (&_fb ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065"); -_egf .PersistentFlags ().BoolVarP (&_abf ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); -_egf .PersistentFlags ().StringVar (&_gge ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); -_egf .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");}; - -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. -func Execute (){if _baa :=_egf .Execute ();_baa !=nil {_bc .Println (_baa );_b .Exit (1);};};func _ga (){if _gge !=""{_fd .SetConfigFile (_gge );}else {_fgf ,_bb :=_efg .Dir ();if _bb !=nil {_bc .Println (_bb );_b .Exit (1);};_fd .AddConfigPath (_fgf ); -_fd .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063");};_fd .AutomaticEnv ();if _gae :=_fd .ReadInConfig ();_gae ==nil {_bc .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_fd .ConfigFileUsed ()); -};}; \ No newline at end of file +MarginRight _bb .LengthFlag `mapstructure:"margin-right"`;};var _bcc string ; \ No newline at end of file diff --git a/client/client.go b/client/client.go index 65a50d7..03eee18 100644 --- a/client/client.go +++ b/client/client.go @@ -11,200 +11,202 @@ // Package client contains HTML Converter HTTP Client. The Client implements htmlcreator.HTMLConverter interface // for the UniPDF module and can be used as a plugin for the UniPDF creator.Creator. -package client ;import (_cg "bytes";_ge "compress/flate";_af "compress/gzip";_a "context";_g "encoding/json";_f "errors";_eg "fmt";_fcg "github.com/unidoc/unihtml/content";_gedc "github.com/unidoc/unihtml/selector";_ae "github.com/unidoc/unihtml/sizes"; -_gb "github.com/unidoc/unipdf/v3/common";_c "io/ioutil";_e "net";_fc "net/http";_ga "net/url";_ged "strconv";_bg "strings";_d "time";); +package client ;import (_aa "bytes";_de "compress/flate";_a "compress/gzip";_df "context";_c "encoding/json";_g "errors";_ac "fmt";_fa "github.com/unidoc/unihtml/content";_dbe "github.com/unidoc/unihtml/selector";_b "github.com/unidoc/unihtml/sizes";_da "github.com/unidoc/unipdf/v3/common"; +_e "io/ioutil";_af "net";_dee "net/http";_db "net/url";_eb "strconv";_ca "strings";_f "time";);type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`;Method string `json:"method"`; +ExpiresAt int64 `json:"expiresAt"`;TimeoutDuration int64 `json:"timeoutDuration,omitempty"`;PageParameters ;RenderParameters ;}; -// WithHTTPS sets the TLS option for the client options. -func WithHTTPS (useHTTPS bool )Option {return func (_dfd *Options ){_dfd .HTTPS =useHTTPS }}; +// WithPrefix sets the client prefix. +func WithPrefix (prefix string )Option {return func (_fae *Options ){_fae .Prefix =prefix }}; -// ParseOptions parses options for the Client. -func ParseOptions (connectPath string )(Options ,error ){if !_bg .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_fg ,_gbg :=_ga .Parse (connectPath );if _gbg !=nil {return Options {},_eg .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); -};var _ac int ;if _fg .Port ()!=""{_ac ,_gbg =_ged .Atoi (_fg .Port ());if _gbg !=nil {return Options {},_eg .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_gbg ); -};};return Options {Hostname :_fg .Hostname (),Port :_ac ,HTTPS :_fg .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_fg .Path },nil ;};func (_aeb *Client )getGenerateRequest (_bc _a .Context ,_gc *Query )(*_fc .Request ,error ){_ag :=generatePDFRequestV1 {Method :_gc .Method ,PageParameters :_gc .PageParameters ,RenderParameters :_gc .RenderParameters ,TimeoutDuration :int64 (_gc .TimeoutDuration )}; -switch _gc .Method {case "\u0077\u0065\u0062":_ag .ContentURL =_gc .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_ag .ContentType =_gc .ContentType ;_ag .Content =_gc .Content ;};_fa :=new (_cg .Buffer );if _gda :=_g .NewEncoder (_fa ).Encode (&_ag ); -_gda !=nil {return nil ,_eg .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_gda );};_aa :=_aeb .Options .Addr ();_aa =_eg .Sprintf ("%\u0073\u002f\u0062\u0065\u0074\u0061\u002f\u0070\u0064\u0066",_aa ); -_fgd ,_dfe :=_fc .NewRequest ("\u0050\u004f\u0053\u0054",_aa ,_fa );if _dfe !=nil {return nil ,_dfe ;};_fgd .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); -_fgd .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); -_fgd =_fgd .WithContext (_bc );return _fgd ,nil ;}; +// PaperWidth sets up the PaperWidth (in cm) parameter for the query. +func (_gce *QueryBuilder )PaperWidth (paperWidth _b .Length )*QueryBuilder {_gce ._agg .PageParameters .PaperWidth =paperWidth ;return _gce ;}; -// MarginBottom sets up the MarginBottom parameter for the query. -func (_ece *QueryBuilder )MarginBottom (marginBottom _ae .Length )*QueryBuilder {_ece ._gaa .PageParameters .MarginBottom =marginBottom ;return _ece ;};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`; -ContentURL string `json:"contentURL"`;Method string `json:"method"`;ExpiresAt int64 `json:"expiresAt"`;TimeoutDuration int64 `json:"timeoutDuration,omitempty"`;PageParameters ;RenderParameters ;}; +// ConvertHTML converts provided Query input into PDF file data. +// Implements creator.HTMLConverter interface. +func (_ag *Client )ConvertHTML (ctx _df .Context ,q *Query )(*PDFResponse ,error ){if _gg :=q .Validate ();_gg !=nil {return nil ,_gg ;};_gde ,_eg :=_ag .getGenerateRequest (ctx ,q );if _eg !=nil {return nil ,_eg ;};_da .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_gde .Method ,_gde .URL .Hostname (),_gde .URL .Path ,_gde .Header ,_gde .URL .Query ()); +_cd :=*_ag .Client ;if q .TimeoutDuration !=0{_cd .Timeout =q .TimeoutDuration ;};_cf ,_eg :=_cd .Do (_gde );if _eg !=nil {return nil ,_eg ;};var _gc error ;switch _cf .StatusCode {case _dee .StatusNotFound :_gc =ErrNotFound ;case _dee .StatusBadRequest :_gc =ErrBadRequest ; +case _dee .StatusNotImplemented :_gc =ErrNotImplemented ;case _dee .StatusUnauthorized :_gc =ErrUnauthorized ;case _dee .StatusRequestTimeout :_gc =ErrTimedOut ;case _dee .StatusCreated :default:_gc =ErrInternalError ;};_ee :=_cf .Body ;switch _cf .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_ee ,_eg =_a .NewReader (_cf .Body ); +if _eg !=nil {return nil ,_eg ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_ee =_de .NewReader (_cf .Body );case "":default:return nil ,_ac .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_cf .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); +};_bc ,_eg :=_e .ReadAll (_ee );if _eg !=nil &&_gc ==nil {return nil ,_ac .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_eg );};_da .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_cf .StatusCode ,_gde .Method ,_gde .URL .Host ,_gde .URL .Path ); +if _gc !=nil {return nil ,_ac .Errorf ("\u0025\u0073\u0020%\u0077",string (_bc ),_gc );};_dfd :=_cf .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_da .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_dfd ); +return &PDFResponse {ID :_dfd ,Data :_bc },nil ;}; -// HealthCheck connects to the server and check the health status of the server. -func (_cf *Client )HealthCheck (ctx _a .Context )error {_df :=_cf .Options .Addr ();_df =_eg .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_df );_cb ,_ec :=_fc .NewRequest ("\u0047\u0045\u0054",_df ,nil );if _ec !=nil {return _ec ;};_cb =_cb .WithContext (ctx ); -_ed ,_ec :=_cf .Client .Do (_cb );if _ec !=nil {return _ec ;};switch _ed .StatusCode {case _fc .StatusOK :return nil ;case _fc .StatusNotFound :return ErrNotFound ;case _fc .StatusInternalServerError :return ErrInternalError ;case _fc .StatusBadGateway :return ErrBadGateway ; -default:return ErrNotImplemented ;};}; +// Portrait sets up the portrait page orientation. +func (_gcd *QueryBuilder )Portrait ()*QueryBuilder {_gcd ._agg .PageParameters .Orientation =_b .Portrait ;return _gcd ;}; -// Client is a structure that is a HTTP client for the unihtml server. -type Client struct{Options Options ;Client *_fc .Client ;}; +// WithHostname sets the Hostname option for the client options. +func WithHostname (option string )Option {return func (_ec *Options ){_ec .Hostname =option }}; -// Landscape sets up the landscape portrait orientation. -func (_dac *QueryBuilder )Landscape ()*QueryBuilder {_dac ._gaa .PageParameters .Orientation =_ae .Landscape ;return _dac ;}; +// Validate checks if provided Query is valid. +func (_ddd *Query )Validate ()error {switch _ddd .Method {case "\u0077\u0065\u0062":if _ddd .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_ddd .Content )==0{return ErrMissingData ;};if _ddd .ContentType ==""{return ErrContentType ; +};default:return _ac .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_ddd .Method );};if _bg :=_ddd .PageParameters .Validate (); +_bg !=nil {return _bg ;};if _gba :=_ddd .RenderParameters .Validate ();_gba !=nil {return _gba ;};return nil ;}; -// SetContent sets custom data with it's content type. -func (_bcb *QueryBuilder )SetContent (content _fcg .Content )*QueryBuilder {if _bcb ._gee !=nil {return _bcb ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _bcb ._gaa .ContentType !=""{_bcb ._gee =ErrContentTypeDeclared ; -return _bcb ;};if content .ContentType ()==""{_bcb ._gee =_eg .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _bcb ; -};_bcb ._gaa .Content =content .Data ();_bcb ._gaa .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _bcb ._gaa .ContentType !=""{_bcb ._gee =ErrContentTypeDeclared ;return _bcb ;};_bcb ._gaa .URL =string (content .Data ());_bcb ._gaa .ContentType =content .ContentType (); -default:_bcb ._gee =_eg .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ());return _bcb ;};_bcb ._gaa .Method =content .Method (); -return _bcb ;}; +// Option is a function that changes client options. +type Option func (_dd *Options ); -// WaitTime sets the minimum load time parameter for the page rendering. -func (_gfc *QueryBuilder )WaitTime (d _d .Duration )*QueryBuilder {_gfc ._gaa .RenderParameters .WaitTime =d ;return _gfc ;}; +// Validate checks the validity of the RenderParameters. +func (_acg *RenderParameters )Validate ()error {if _acg .WaitTime > _f .Minute *3{return _g .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); +};for _ ,_gb :=range _acg .WaitReady {if _fbb :=_gb .Validate ();_fbb !=nil {return _ac .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_fbb ); +};};return nil ;};func (_cfc *Client )setQueryValues (_ffe *_dee .Request ,_ce *Query ){_caf :=_ffe .URL .Query ();_cc :=_ce .PageParameters ;if _cc .PageSize !=nil {_caf .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_cc .PageSize .String ());}; +if _cc .PaperHeight !=nil {_caf .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_cc .PaperHeight .String ());};if _cc .PaperWidth !=nil {_caf .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_cc .PaperWidth .String ()); +};if _cc .MarginTop !=nil {_caf .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_cc .MarginTop .String ());};if _cc .MarginBottom !=nil {_caf .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_cc .MarginBottom .String ()); +};if _cc .MarginRight !=nil {_caf .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_cc .MarginRight .String ());};if _cc .MarginLeft !=nil {_caf .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_cc .MarginLeft .String ()); +};if _cc .Orientation ==_b .Landscape {_caf .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_cc .Orientation .String ());};if _ce .RenderParameters .WaitTime !=0{_caf .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_eb .FormatInt (int64 (_ce .RenderParameters .WaitTime /_f .Millisecond ),10)); +};_ffe .URL .RawQuery =_caf .Encode ();}; -// PaperHeight sets up the PaperHeight (in cm) parameter for the query. -func (_da *QueryBuilder )PaperHeight (paperHeight _ae .Length )*QueryBuilder {_da ._gaa .PageParameters .PaperHeight =paperHeight ;return _da ;}; +// HealthCheck connects to the server and check the health status of the server. +func (_fg *Client )HealthCheck (ctx _df .Context )error {_ad :=_fg .Options .Addr ();_ad =_ac .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_ad );_fe ,_fb :=_dee .NewRequest ("\u0047\u0045\u0054",_ad ,nil );if _fb !=nil {return _fb ;};_fe =_fe .WithContext (ctx ); +_feb ,_fb :=_fg .Client .Do (_fe );if _fb !=nil {return _fb ;};switch _feb .StatusCode {case _dee .StatusOK :return nil ;case _dee .StatusNotFound :return ErrNotFound ;case _dee .StatusInternalServerError :return ErrInternalError ;case _dee .StatusBadGateway :return ErrBadGateway ; +default:return ErrNotImplemented ;};}; -// Addr gets the HTTP address URI used by the http.Client. -func (_ee *Options )Addr ()string {_dc :=_bg .Builder {};_dc .WriteString ("\u0068\u0074\u0074\u0070");if _ee .HTTPS {_dc .WriteRune ('s');};_dc .WriteString ("\u003a\u002f\u002f");_dc .WriteString (_ee .Hostname );_dc .WriteRune (':');_dc .WriteString (_ged .Itoa (_ee .Port )); -if _ee .Prefix !=""{_dc .WriteString (_ee .Prefix );};return _dc .String ();}; +// ParseOptions parses options for the Client. +func ParseOptions (connectPath string )(Options ,error ){if !_ca .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_gd ,_ebd :=_db .Parse (connectPath );if _ebd !=nil {return Options {},_ac .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); +};var _bb int ;if _gd .Port ()!=""{_bb ,_ebd =_eb .Atoi (_gd .Port ());if _ebd !=nil {return Options {},_ac .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_ebd ); +};};return Options {Hostname :_gd .Hostname (),Port :_bb ,HTTPS :_gd .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_gd .Path },nil ;}; -// MarginRight sets up the MarginRight parameter for the query. -func (_fd *QueryBuilder )MarginRight (marginRight _ae .Length )*QueryBuilder {_fd ._gaa .PageParameters .MarginRight =marginRight ;return _fd ;};var (ErrNotFound =_f .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_f .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); -ErrNotImplemented =_f .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_f .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_f .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079"); -ErrUnauthorized =_f .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_f .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); +// RenderParameters are the parameters related with the rendering. +type RenderParameters struct{WaitTime _f .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; -// Validate checks the validity of the RenderParameters. -func (_cbc *RenderParameters )Validate ()error {if _cbc .WaitTime > _d .Minute *3{return _f .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); -};for _ ,_bcg :=range _cbc .WaitReady {if _ca :=_bcg .Validate ();_ca !=nil {return _eg .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_ca ); -};};return nil ;}; +// SetContent sets custom data with it's content type. +func (_febbf *QueryBuilder )SetContent (content _fa .Content )*QueryBuilder {if _febbf ._fgb !=nil {return _febbf ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _febbf ._agg .ContentType !=""{_febbf ._fgb =ErrContentTypeDeclared ; +return _febbf ;};if content .ContentType ()==""{_febbf ._fgb =_ac .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _febbf ; +};_febbf ._agg .Content =content .Data ();_febbf ._agg .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _febbf ._agg .ContentType !=""{_febbf ._fgb =ErrContentTypeDeclared ;return _febbf ;};_febbf ._agg .URL =string (content .Data ()); +_febbf ._agg .ContentType =content .ContentType ();default:_febbf ._fgb =_ac .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ()); +return _febbf ;};_febbf ._agg .Method =content .Method ();return _febbf ;}; // MarginTop sets up the MarginTop parameter for the query. -func (_gdag *QueryBuilder )MarginTop (marginTop _ae .Length )*QueryBuilder {_gdag ._gaa .PageParameters .MarginTop =marginTop ;return _gdag ;}; +func (_ea *QueryBuilder )MarginTop (marginTop _b .Length )*QueryBuilder {_ea ._agg .PageParameters .MarginTop =marginTop ;return _ea ;}; -// Query gets the Query from provided query builder. If some error occurred during build process -// or the input is not valid the function would return an error. -func (_eda *QueryBuilder )Query ()(*Query ,error ){if _gbe :=_eda .Validate ();_gbe !=nil {return nil ,_gbe ;};return &_eda ._gaa ,nil ;}; +// BySelector is a structure that defines a selector with it's query 'by' type. +type BySelector struct{Selector string `json:"selector"`;By _dbe .ByType `json:"by"`;}; -// PaperWidth sets up the PaperWidth (in cm) parameter for the query. -func (_bb *QueryBuilder )PaperWidth (paperWidth _ae .Length )*QueryBuilder {_bb ._gaa .PageParameters .PaperWidth =paperWidth ;return _bb ;}; +// QueryBuilder is the query that converts HTMLConverter defined data +type QueryBuilder struct{_agg Query ;_fgb error ;}; -// Validate checks if the parameters are valid. -func (_be *PageParameters )Validate ()error {if _be .PaperWidth !=nil {if _be .PaperWidth .Millimeters ()< 0{return _f .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); -};};if _be .PaperHeight !=nil {if _be .PaperHeight .Millimeters ()< 0{return _f .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); -};};if _be .MarginTop !=nil {if _be .MarginTop .Millimeters ()< 0{return _f .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _be .MarginBottom !=nil {if _be .MarginBottom .Millimeters ()< 0{return _f .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); -};};if _be .MarginLeft !=nil {if _be .MarginLeft .Millimeters ()< 0{return _f .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};};if _be .MarginRight !=nil {if _be .MarginRight .Millimeters ()< 0{return _f .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); -};};if _be .PageSize !=nil &&!_be .PageSize .IsAPageSize (){return _f .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; +// PageParameters are the query parameters used in the PDF generation. +type PageParameters struct{ -// MarginLeft sets up the MarginLeft parameter for the query. -func (_fcd *QueryBuilder )MarginLeft (marginLeft _ae .Length )*QueryBuilder {_fcd ._gaa .PageParameters .MarginLeft =marginLeft ;return _fcd ;}; +// PaperWidth sets the width of the paper. +PaperWidth _b .Length `schema:"paper-width" json:"paperWidth"`; -// BuildHTMLQuery creates a Query builder that is supposed to create valid -func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; +// PaperHeight is the height of the output paper. +PaperHeight _b .Length `schema:"paper-height" json:"paperHeight"`; -// PDFResponse is the response used by the HTMLConverter. -type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; +// PageSize is the page size string. +PageSize *_b .PageSize `schema:"page-size" json:"pageSize"`; -// TimeoutDuration sets the server query duration timeout. -// Once the timeout is reached the server will return an error. -func (_gafe *QueryBuilder )TimeoutDuration (d _d .Duration )*QueryBuilder {_gafe ._gaa .TimeoutDuration =d ;return _gafe ;};func (_cbf *Client )setQueryValues (_dfb *_fc .Request ,_edd *Query ){_gdg :=_dfb .URL .Query ();_fe :=_edd .PageParameters ;if _fe .PageSize !=nil {_gdg .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_fe .PageSize .String ()); -};if _fe .PaperHeight !=nil {_gdg .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_fe .PaperHeight .String ());};if _fe .PaperWidth !=nil {_gdg .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_fe .PaperWidth .String ()); -};if _fe .MarginTop !=nil {_gdg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_fe .MarginTop .String ());};if _fe .MarginBottom !=nil {_gdg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_fe .MarginBottom .String ()); -};if _fe .MarginRight !=nil {_gdg .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_fe .MarginRight .String ());};if _fe .MarginLeft !=nil {_gdg .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_fe .MarginLeft .String ()); -};if _fe .Orientation ==_ae .Landscape {_gdg .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_fe .Orientation .String ());};if _edd .RenderParameters .WaitTime !=0{_gdg .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_ged .FormatInt (int64 (_edd .RenderParameters .WaitTime /_d .Millisecond ),10)); -};_dfb .URL .RawQuery =_gdg .Encode ();}; +// Orientation defines if the output should be in a landscape format. +Orientation _b .Orientation `schema:"orientation" json:"orientation"`; -// Validate checks if provided Query is valid. -func (_dg *Query )Validate ()error {switch _dg .Method {case "\u0077\u0065\u0062":if _dg .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_dg .Content )==0{return ErrMissingData ;};if _dg .ContentType ==""{return ErrContentType ; -};default:return _eg .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_dg .Method );};if _acg :=_dg .PageParameters .Validate (); -_acg !=nil {return _acg ;};if _bef :=_dg .RenderParameters .Validate ();_bef !=nil {return _bef ;};return nil ;}; +// MarginTop sets up the Top Margin for the output. +MarginTop _b .Length `schema:"margin-top" json:"marginTop"`; -// Orientation sets the page orientation for the Query. -func (_efc *QueryBuilder )Orientation (orientation _ae .Orientation )*QueryBuilder {_efc ._gaa .PageParameters .Orientation =orientation ;return _efc ;}; +// MarginBottom sets up the Bottom Margin for the output. +MarginBottom _b .Length `schema:"margin-bottom" json:"marginBottom"`; -// WithHostname sets the Hostname option for the client options. -func WithHostname (option string )Option {return func (_dff *Options ){_dff .Hostname =option }};var (ErrMissingData =_f .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061");ErrContentType =_f .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065"); -ErrContentTypeDeclared =_f .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064");); +// MarginLeft sets up the Left Margin for the output. +MarginLeft _b .Length `schema:"margin-left" json:"marginLeft"`; -// DefaultPageParameters creates default parameters. -func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_ae .Portrait }}; +// MarginRight sets up the Right Margin for the output. +MarginRight _b .Length `schema:"margin-right" json:"marginRight"`;}; -// BySelector is a structure that defines a selector with it's query 'by' type. -type BySelector struct{Selector string `json:"selector"`;By _gedc .ByType `json:"by"`;}; +// Validate checks validity of the selector. +func (_ecg BySelector )Validate ()error {if _ecg .Selector ==""{return _g .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _ega :=_ecg .By .Validate ();_ega !=nil {return _ega ; +};return nil ;}; -// Err gets the error which could occur in the query. -func (_efg *QueryBuilder )Err ()error {return _efg ._gee }; +// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. +type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;TimeoutDuration _f .Duration ;}; -// Option is a function that changes client options. -type Option func (_age *Options ); +// WaitReady waits for the selector to get ready - 'loaded'. +func (_aae *QueryBuilder )WaitReady (selector string ,by _dbe .ByType )*QueryBuilder {_aae ._agg .RenderParameters .WaitReady =append (_aae ._agg .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _aae ;}; -// Validate checks if the QueryBuilder had no errors during composition and creation. -func (_ab *QueryBuilder )Validate ()error {if _ab ._gee !=nil {return _ab ._gee ;};return _ab ._gaa .Validate ();}; +// TimeoutDuration sets the server query duration timeout. +// Once the timeout is reached the server will return an error. +func (_eedb *QueryBuilder )TimeoutDuration (d _f .Duration )*QueryBuilder {_eedb ._agg .TimeoutDuration =d ;return _eedb ;}; -// PageParameters are the query parameters used in the PDF generation. -type PageParameters struct{ +// PaperHeight sets up the PaperHeight (in cm) parameter for the query. +func (_aac *QueryBuilder )PaperHeight (paperHeight _b .Length )*QueryBuilder {_aac ._agg .PageParameters .PaperHeight =paperHeight ;return _aac ;}; -// PaperWidth sets the width of the paper. -PaperWidth _ae .Length `schema:"paper-width" json:"paperWidth"`; +// MarginLeft sets up the MarginLeft parameter for the query. +func (_agf *QueryBuilder )MarginLeft (marginLeft _b .Length )*QueryBuilder {_agf ._agg .PageParameters .MarginLeft =marginLeft ;return _agf ;}; -// PaperHeight is the height of the output paper. -PaperHeight _ae .Length `schema:"paper-height" json:"paperHeight"`; +// Options are the client options used by the HTTP client. +type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _f .Duration ;Prefix string ;}; -// PageSize is the page size string. -PageSize *_ae .PageSize `schema:"page-size" json:"pageSize"`; +// Client is a structure that is a HTTP client for the unihtml server. +type Client struct{Options Options ;Client *_dee .Client ;}; -// Orientation defines if the output should be in a landscape format. -Orientation _ae .Orientation `schema:"orientation" json:"orientation"`; +// WithHTTPS sets the TLS option for the client options. +func WithHTTPS (useHTTPS bool )Option {return func (_cee *Options ){_cee .HTTPS =useHTTPS }}; -// MarginTop sets up the Top Margin for the output. -MarginTop _ae .Length `schema:"margin-top" json:"marginTop"`; +// WithPort sets the Port option for the client options. +func WithPort (option int )Option {return func (_cce *Options ){_cce .Port =option }}; -// MarginBottom sets up the Bottom Margin for the output. -MarginBottom _ae .Length `schema:"margin-bottom" json:"marginBottom"`; +// DefaultPageParameters creates default parameters. +func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_b .Portrait }}; -// MarginLeft sets up the Left Margin for the output. -MarginLeft _ae .Length `schema:"margin-left" json:"marginLeft"`; +// Validate checks if the parameters are valid. +func (_eed *PageParameters )Validate ()error {if _eed .PaperWidth !=nil {if _eed .PaperWidth .Millimeters ()< 0{return _g .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); +};};if _eed .PaperHeight !=nil {if _eed .PaperHeight .Millimeters ()< 0{return _g .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); +};};if _eed .MarginTop !=nil {if _eed .MarginTop .Millimeters ()< 0{return _g .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _eed .MarginBottom !=nil {if _eed .MarginBottom .Millimeters ()< 0{return _g .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); +};};if _eed .MarginLeft !=nil {if _eed .MarginLeft .Millimeters ()< 0{return _g .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};}; +if _eed .MarginRight !=nil {if _eed .MarginRight .Millimeters ()< 0{return _g .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); +};};if _eed .PageSize !=nil &&!_eed .PageSize .IsAPageSize (){return _g .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; -// MarginRight sets up the Right Margin for the output. -MarginRight _ae .Length `schema:"margin-right" json:"marginRight"`;}; +// Addr gets the HTTP address URI used by the http.Client. +func (_eeg *Options )Addr ()string {_afc :=_ca .Builder {};_afc .WriteString ("\u0068\u0074\u0074\u0070");if _eeg .HTTPS {_afc .WriteRune ('s');};_afc .WriteString ("\u003a\u002f\u002f");_afc .WriteString (_eeg .Hostname );_afc .WriteRune (':');_afc .WriteString (_eb .Itoa (_eeg .Port )); +if _eeg .Prefix !=""{_afc .WriteString (_eeg .Prefix );};return _afc .String ();}; -// QueryBuilder is the query that converts HTMLConverter defined data -type QueryBuilder struct{_gaa Query ;_gee error ;}; +// PageSize sets up the PageSize parameter for the query. +func (_bfcb *QueryBuilder )PageSize (pageSize _b .PageSize )*QueryBuilder {if pageSize !=_b .Undefined {_bfcb ._agg .PageParameters .PageSize =&pageSize ;};return _bfcb ;}; -// ConvertHTML converts provided Query input into PDF file data. -// Implements creator.HTMLConverter interface. -func (_gg *Client )ConvertHTML (ctx _a .Context ,q *Query )(*PDFResponse ,error ){if _bf :=q .Validate ();_bf !=nil {return nil ,_bf ;};_eb ,_gaf :=_gg .getGenerateRequest (ctx ,q );if _gaf !=nil {return nil ,_gaf ;};_gb .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_eb .Method ,_eb .URL .Hostname (),_eb .URL .Path ,_eb .Header ,_eb .URL .Query ()); -_cd :=*_gg .Client ;if q .TimeoutDuration !=0{_cd .Timeout =q .TimeoutDuration ;};_gd ,_gaf :=_cd .Do (_eb );if _gaf !=nil {return nil ,_gaf ;};var _gef error ;switch _gd .StatusCode {case _fc .StatusNotFound :_gef =ErrNotFound ;case _fc .StatusBadRequest :_gef =ErrBadRequest ; -case _fc .StatusNotImplemented :_gef =ErrNotImplemented ;case _fc .StatusUnauthorized :_gef =ErrUnauthorized ;case _fc .StatusRequestTimeout :_gef =ErrTimedOut ;case _fc .StatusCreated :default:_gef =ErrInternalError ;};_ba :=_gd .Body ;switch _gd .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_ba ,_gaf =_af .NewReader (_gd .Body ); -if _gaf !=nil {return nil ,_gaf ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_ba =_ge .NewReader (_gd .Body );case "":default:return nil ,_eg .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_gd .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); -};_fge ,_gaf :=_c .ReadAll (_ba );if _gaf !=nil &&_gef ==nil {return nil ,_eg .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_gaf );};_gb .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_gd .StatusCode ,_eb .Method ,_eb .URL .Host ,_eb .URL .Path ); -if _gef !=nil {return nil ,_eg .Errorf ("\u0025\u0073\u0020%\u0077",string (_fge ),_gef );};_acc :=_gd .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_gb .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_acc ); -return &PDFResponse {ID :_acc ,Data :_fge },nil ;}; +// BuildHTMLQuery creates a Query builder that is supposed to create valid +func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; + +// WithDefaultTimeout sets the DefaultTimeout option for the client options. +func WithDefaultTimeout (option _f .Duration )Option {return func (_be *Options ){_be .DefaultTimeout =option };};var (ErrNotFound =_g .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_g .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); +ErrNotImplemented =_g .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_g .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_g .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079"); +ErrUnauthorized =_g .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_g .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); // New creates new client with provided options. -func New (o Options )*Client {o .DefaultTimeout =_d .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _dd =&_fc .Transport {DialContext :(&_e .Dialer {Timeout :5*_d .Second }).DialContext ,TLSHandshakeTimeout :5*_d .Second }; -_gb .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_fc .Client {Transport :_dd ,Timeout :o .DefaultTimeout }};}; +func New (o Options )*Client {o .DefaultTimeout =_f .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _acb =&_dee .Transport {DialContext :(&_af .Dialer {Timeout :5*_f .Second }).DialContext ,TLSHandshakeTimeout :5*_f .Second }; +_da .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_dee .Client {Transport :_acb ,Timeout :o .DefaultTimeout }};}; -// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. -type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;TimeoutDuration _d .Duration ;}; +// MarginRight sets up the MarginRight parameter for the query. +func (_aaa *QueryBuilder )MarginRight (marginRight _b .Length )*QueryBuilder {_aaa ._agg .PageParameters .MarginRight =marginRight ;return _aaa ;}; -// Options are the client options used by the HTTP client. -type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _d .Duration ;Prefix string ;}; +// WaitTime sets the minimum load time parameter for the page rendering. +func (_bcc *QueryBuilder )WaitTime (d _f .Duration )*QueryBuilder {_bcc ._agg .RenderParameters .WaitTime =d ;return _bcc ;}; -// Portrait sets up the portrait page orientation. -func (_gf *QueryBuilder )Portrait ()*QueryBuilder {_gf ._gaa .PageParameters .Orientation =_ae .Portrait ;return _gf ;}; +// Err gets the error which could occur in the query. +func (_fbg *QueryBuilder )Err ()error {return _fbg ._fgb };func (_dc *Client )getGenerateRequest (_dfb _df .Context ,_gded *Query )(*_dee .Request ,error ){_bf :=generatePDFRequestV1 {Method :_gded .Method ,PageParameters :_gded .PageParameters ,RenderParameters :_gded .RenderParameters ,TimeoutDuration :int64 (_gded .TimeoutDuration )}; +switch _gded .Method {case "\u0077\u0065\u0062":_bf .ContentURL =_gded .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_bf .ContentType =_gded .ContentType ;_bf .Content =_gded .Content ;};_ff :=new (_aa .Buffer );if _acbd :=_c .NewEncoder (_ff ).Encode (&_bf ); +_acbd !=nil {return nil ,_ac .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_acbd );};_ffd :=_dc .Options .Addr ();_ffd =_ac .Sprintf ("%\u0073\u002f\u0062\u0065\u0074\u0061\u002f\u0070\u0064\u0066",_ffd ); +_bd ,_fed :=_dee .NewRequest ("\u0050\u004f\u0053\u0054",_ffd ,_ff );if _fed !=nil {return nil ,_fed ;};_bd .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); +_bd .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); +_bd =_bd .WithContext (_dfb );return _bd ,nil ;}; -// WithDefaultTimeout sets the DefaultTimeout option for the client options. -func WithDefaultTimeout (option _d .Duration )Option {return func (_gdc *Options ){_gdc .DefaultTimeout =option };}; +// PDFResponse is the response used by the HTMLConverter. +type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; -// RenderParameters are the parameters related with the rendering. -type RenderParameters struct{WaitTime _d .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; +// Landscape sets up the landscape portrait orientation. +func (_dcd *QueryBuilder )Landscape ()*QueryBuilder {_dcd ._agg .PageParameters .Orientation =_b .Landscape ;return _dcd ;}; -// WithPrefix sets the client prefix. -func WithPrefix (prefix string )Option {return func (_gae *Options ){_gae .Prefix =prefix }}; +// MarginBottom sets up the MarginBottom parameter for the query. +func (_febb *QueryBuilder )MarginBottom (marginBottom _b .Length )*QueryBuilder {_febb ._agg .PageParameters .MarginBottom =marginBottom ;return _febb ;}; -// WaitReady waits for the selector to get ready - 'loaded'. -func (_eeg *QueryBuilder )WaitReady (selector string ,by _gedc .ByType )*QueryBuilder {_eeg ._gaa .RenderParameters .WaitReady =append (_eeg ._gaa .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _eeg ;}; +// Query gets the Query from provided query builder. If some error occurred during build process +// or the input is not valid the function would return an error. +func (_gbf *QueryBuilder )Query ()(*Query ,error ){if _bfc :=_gbf .Validate ();_bfc !=nil {return nil ,_bfc ;};return &_gbf ._agg ,nil ;};var (ErrMissingData =_g .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061"); +ErrContentType =_g .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065");ErrContentTypeDeclared =_g .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064"); +); -// Validate checks validity of the selector. -func (_bfb BySelector )Validate ()error {if _bfb .Selector ==""{return _f .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _afd :=_bfb .By .Validate ();_afd !=nil {return _afd ; -};return nil ;}; +// Validate checks if the QueryBuilder had no errors during composition and creation. +func (_gbd *QueryBuilder )Validate ()error {if _gbd ._fgb !=nil {return _gbd ._fgb ;};return _gbd ._agg .Validate ();}; // WaitVisible waits for the selector to get visible. -func (_cad *QueryBuilder )WaitVisible (selector string ,by _gedc .ByType )*QueryBuilder {_cad ._gaa .RenderParameters .WaitVisible =append (_cad ._gaa .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _cad ;}; +func (_ceea *QueryBuilder )WaitVisible (selector string ,by _dbe .ByType )*QueryBuilder {_ceea ._agg .RenderParameters .WaitVisible =append (_ceea ._agg .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _ceea ;}; -// WithPort sets the Port option for the client options. -func WithPort (option int )Option {return func (_ef *Options ){_ef .Port =option }}; - -// PageSize sets up the PageSize parameter for the query. -func (_fb *QueryBuilder )PageSize (pageSize _ae .PageSize )*QueryBuilder {if pageSize !=_ae .Undefined {_fb ._gaa .PageParameters .PageSize =&pageSize ;};return _fb ;}; \ No newline at end of file +// Orientation sets the page orientation for the Query. +func (_dbb *QueryBuilder )Orientation (orientation _b .Orientation )*QueryBuilder {_dbb ._agg .PageParameters .Orientation =orientation ;return _dbb ;}; \ No newline at end of file diff --git a/common/common.go b/common/common.go index ae303be..2255714 100644 --- a/common/common.go +++ b/common/common.go @@ -10,8 +10,8 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package common contains common properties used by the subpackages. -package common ;import _b "time";const Version ="\u0030\u002e\u0037.\u0030"; +package common ;import _bb "time"; // UtcTimeFormat returns a formatted string describing a UTC timestamp. -func UtcTimeFormat (t _b .Time )string {return t .Format (_ga )+"\u0020\u0055\u0054\u0043"};var ReleasedAt =_b .Date (_gf ,_f ,_be ,_e ,_ba ,0,0,_b .UTC );const _gf =2023;const _e =12;const _f =2;const _ga ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034"; -const _be =10;const _ba =20; \ No newline at end of file +func UtcTimeFormat (t _bb .Time )string {return t .Format (_a )+"\u0020\u0055\u0054\u0043"};const _e =26;const _a ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";const _c =2024; +const _g =1;const _ea =12;var ReleasedAt =_bb .Date (_c ,_g ,_e ,_ea ,_d ,0,0,_bb .UTC );const _d =20;const Version ="\u0030\u002e\u0038.\u0030"; \ No newline at end of file diff --git a/content/content.go b/content/content.go index 9a9fc61..7ebf199 100644 --- a/content/content.go +++ b/content/content.go @@ -9,50 +9,65 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package content ;import (_d "archive/zip";_fa "bytes";_f "fmt";_c "io/ioutil";_a "net/url";_b "os";_g "strings";); +package content ;import (_ff "archive/zip";_d "bytes";_e "fmt";_g "io/ioutil";_c "net/url";_be "os";_b "strings";); // ContentType implements Content interface. -func (_bac *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; +func (_cff *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; -// Data implements Content interface. -func (_ef *webURL )Data ()[]byte {return []byte (_ef ._fb )};type webURL struct{_fb string }; +// StringContent implements Content interface for an HTML string. +type StringContent struct{_aag string };type htmlFile struct{_fe _d .Buffer }; -// ContentType implements Content interface. -func (_ge *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; +// NewHTMLFile creates new Content htmFile for provided input path. +func NewHTMLFile (path string )(Content ,error ){_ge ,_fb :=_be .Open (path );if _fb !=nil {return nil ,_fb ;};_a :=&htmlFile {_fe :_d .Buffer {}};if _ ,_fb =_a ._fe .ReadFrom (_ge );_fb !=nil {return nil ,_fb ;};return _a ,nil ;};type webURL struct{_bf string }; +type zipDirectory struct{_bc _d .Buffer ;_ad *_ff .Writer ;}; -// NewWebURL creates new Content webURL for provided input URL path. -func NewWebURL (path string )(Content ,error ){if _ ,_dc :=_a .Parse (path );_dc !=nil {return nil ,_dc ;};return &webURL {_fb :path },nil ;}; +// Method gets the web url query method. +func (_aa *webURL )Method ()string {return "\u0077\u0065\u0062"}; -// NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' -// and stores in it's in-memory buffer. -func NewZipDirectory (dirPath string )(Content ,error ){_fd :=&zipDirectory {_ga :_fa .Buffer {}};_fd ._gb =_d .NewWriter (&_fd ._ga );if _bb :=_fd .zipPath (dirPath ,"");_bb !=nil {return nil ,_bb ;};if _ee :=_fd ._gb .Close ();_ee !=nil {return nil ,_ee ; -};return _fd ,nil ;}; +// Content is an interface used for putting the content into Client Query. +type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;};func (_adg *zipDirectory )zipPath (_aaa ,_aaf string )error {_ac ,_fa :=_g .ReadDir (_aaa );if _fa !=nil {return _e .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_aaa ,_fa ); +};_df :=&_b .Builder {};for _ ,_ag :=range _ac {_bgb ,_dc :=_adg .zipBasePaths (_ag ,_aaa ,_aaf ,_ag .IsDir (),_df );if _ag .IsDir (){if _dg :=_adg .zipPath (_bgb ,_dc );_dg !=nil {return _dg ;};continue ;};_gg ,_fc :=_g .ReadFile (_bgb );if _fc !=nil {return _fc ; +};_def ,_fc :=_adg ._ad .Create (_dc );if _fc !=nil {return _fc ;};if _ ,_fc =_def .Write (_gg );_fc !=nil {return _fc ;};};return nil ;}; -// Method gets the query method. -func (_aa *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"}; +// Method implements Content interface. +func (_faa *StringContent )Method ()string {return "\u0068\u0074\u006d\u006c"}; -// ContentType implements Content interface. -func (_ba *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; +// Data implements Content interface. +func (_cd *StringContent )Data ()[]byte {return []byte (_cd ._aag )}; // Data implements Content interface. -func (_ea *zipDirectory )Data ()[]byte {return _ea ._ga .Bytes ()}; +func (_de *htmlFile )Data ()[]byte {return _de ._fe .Bytes ()}; -// Method gets the zip directory method. -func (_efc *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; +// Data implements Content interface. +func (_gef *zipDirectory )Data ()[]byte {return _gef ._bc .Bytes ()}; -// Method gets the web url query method. -func (_da *webURL )Method ()string {return "\u0077\u0065\u0062"};func (_cb *zipDirectory )zipBasePaths (_df _b .FileInfo ,_eg ,_dce string ,_fe bool ,_ffa *_g .Builder )(string ,string ){_ffa .WriteString (_eg );if !_g .HasSuffix (_eg ,"\u002f"){_ffa .WriteRune ('/'); -};_ffa .WriteString (_df .Name ());if _fe {_ffa .WriteRune ('/');};_fc :=_ffa .String ();_ffa .Reset ();_ffa .WriteString (_dce );_ffa .WriteString (_df .Name ());if _fe {_ffa .WriteRune ('/');};_fcb :=_ffa .String ();_ffa .Reset ();return _fc ,_fcb ;}; +// ContentType implements Content interface. +func (_bce *StringContent )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl";}; +// NewStringContent creates a new StringContent. +func NewStringContent (html string )(*StringContent ,error ){return &StringContent {_aag :html },nil }; -// Content is an interface used for putting the content into Client Query. -type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;}; +// ContentType implements Content interface. +func (_ab *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; -// NewHTMLFile creates new Content htmFile for provided input path. -func NewHTMLFile (path string )(Content ,error ){_gfd ,_ca :=_b .Open (path );if _ca !=nil {return nil ,_ca ;};_bf :=&htmlFile {_gf :_fa .Buffer {}};if _ ,_ca =_bf ._gf .ReadFrom (_gfd );_ca !=nil {return nil ,_ca ;};return _bf ,nil ;};type zipDirectory struct{_ga _fa .Buffer ; -_gb *_d .Writer ;}; +// NewWebURL creates new Content webURL for provided input URL path. +func NewWebURL (path string )(Content ,error ){if _ ,_ec :=_c .Parse (path );_ec !=nil {return nil ,_ec ;};return &webURL {_bf :path },nil ;}; + +// ContentType implements Content interface. +func (_cg *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; + +// Method gets the query method. +func (_ee *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"}; // Data implements Content interface. -func (_ce *htmlFile )Data ()[]byte {return _ce ._gf .Bytes ()};type htmlFile struct{_gf _fa .Buffer };func (_aaa *zipDirectory )zipPath (_af ,_gg string )error {_dg ,_dd :=_c .ReadDir (_af );if _dd !=nil {return _f .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_af ,_dd ); -};_ggd :=&_g .Builder {};for _ ,_eae :=range _dg {_cd ,_eb :=_aaa .zipBasePaths (_eae ,_af ,_gg ,_eae .IsDir (),_ggd );if _eae .IsDir (){if _cg :=_aaa .zipPath (_cd ,_eb );_cg !=nil {return _cg ;};continue ;};_gge ,_ed :=_c .ReadFile (_cd );if _ed !=nil {return _ed ; -};_dab ,_ed :=_aaa ._gb .Create (_eb );if _ed !=nil {return _ed ;};if _ ,_ed =_dab .Write (_gge );_ed !=nil {return _ed ;};};return nil ;}; \ No newline at end of file +func (_cf *webURL )Data ()[]byte {return []byte (_cf ._bf )};func (_gda *zipDirectory )zipBasePaths (_bd _be .FileInfo ,_fd ,_ea string ,_eaa bool ,_ggf *_b .Builder )(string ,string ){_ggf .WriteString (_fd );if !_b .HasSuffix (_fd ,"\u002f"){_ggf .WriteRune ('/'); +};_ggf .WriteString (_bd .Name ());if _eaa {_ggf .WriteRune ('/');};_fef :=_ggf .String ();_ggf .Reset ();_ggf .WriteString (_ea );_ggf .WriteString (_bd .Name ());if _eaa {_ggf .WriteRune ('/');};_bb :=_ggf .String ();_ggf .Reset ();return _fef ,_bb ; +}; + +// Method gets the zip directory method. +func (_ecf *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; + +// NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' +// and stores in it's in-memory buffer. +func NewZipDirectory (dirPath string )(Content ,error ){_ae :=&zipDirectory {_bc :_d .Buffer {}};_ae ._ad =_ff .NewWriter (&_ae ._bc );if _gd :=_ae .zipPath (dirPath ,"");_gd !=nil {return nil ,_gd ;};if _eg :=_ae ._ad .Close ();_eg !=nil {return nil ,_eg ; +};return _ae ,nil ;}; \ No newline at end of file diff --git a/go.mod b/go.mod index ebc88b0..24cb196 100644 --- a/go.mod +++ b/go.mod @@ -1,20 +1,46 @@ module github.com/unidoc/unihtml -go 1.15 +go 1.17 require ( - github.com/adrg/strutil v0.3.0 // indirect + github.com/mitchellh/go-homedir v1.1.0 + github.com/spf13/cobra v1.8.0 + github.com/spf13/viper v1.16.0 + github.com/stretchr/testify v1.8.4 + github.com/unidoc/unipdf/v3 v3.53.0 +) + +require ( + github.com/adrg/strutil v0.3.1 // indirect github.com/adrg/sysfont v0.1.2 // indirect github.com/adrg/xdg v0.4.0 // indirect - github.com/mitchellh/go-homedir v1.1.0 - github.com/sirupsen/logrus v1.8.1 // indirect - github.com/spf13/cobra v1.1.1 - github.com/spf13/viper v1.7.1 - github.com/unidoc/unipdf/v3 v3.34.0 - golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f // indirect - golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 // indirect - golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect - golang.org/x/text v0.3.7 // indirect - golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/magiconair/properties v1.8.7 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/pelletier/go-toml/v2 v2.1.1 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect + github.com/sirupsen/logrus v1.9.3 // indirect + github.com/spf13/afero v1.11.0 // indirect + github.com/spf13/cast v1.6.0 // indirect + github.com/spf13/jwalterweatherman v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/subosito/gotenv v1.6.0 // indirect + github.com/unidoc/freetype v0.2.3 // indirect + github.com/unidoc/pkcs7 v0.2.0 // indirect + github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a // indirect + github.com/unidoc/unichart v0.3.0 // indirect + github.com/unidoc/unitype v0.4.0 // indirect + golang.org/x/crypto v0.18.0 // indirect + golang.org/x/image v0.15.0 // indirect + golang.org/x/net v0.20.0 // indirect + golang.org/x/sys v0.16.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index dcc67e5..5935136 100644 --- a/go.sum +++ b/go.sum @@ -1,374 +1,114 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= -cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= -cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= -cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= -cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= -cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= -cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= -cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= -cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= -cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= -dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/adrg/strutil v0.1.0/go.mod h1:pXRr2+IyX5AEPAF5icj/EeTaiflPSD2hvGjnguilZgE= github.com/adrg/strutil v0.2.2/go.mod h1:EF2fjOFlGTepljfI+FzgTG13oXthR7ZAil9/aginnNQ= -github.com/adrg/strutil v0.3.0 h1:bi/HB2zQbDihC8lxvATDTDzkT4bG7PATtVnDYp5rvq4= -github.com/adrg/strutil v0.3.0/go.mod h1:Jz0wzBVE6Uiy9wxo62YEqEY1Nwto3QlLl1Il5gkLKWU= -github.com/adrg/sysfont v0.1.1/go.mod h1:19nTHzfIn/HbngFMet+yNAvwSQYtOJYMI7vWexLWyNw= +github.com/adrg/strutil v0.3.1 h1:OLvSS7CSJO8lBii4YmBt8jiK9QOtB9CzCzwl4Ic/Fz4= +github.com/adrg/strutil v0.3.1/go.mod h1:8h90y18QLrs11IBffcGX3NW/GFBXCMcNg4M7H6MspPA= github.com/adrg/sysfont v0.1.2 h1:MSU3KREM4RhsQ+7QgH7wPEPTgAgBIz0Hw6Nd4u7QgjE= github.com/adrg/sysfont v0.1.2/go.mod h1:6d3l7/BSjX9VaeXWJt9fcrftFaD/t7l11xgSywCPZGk= -github.com/adrg/xdg v0.2.1/go.mod h1:ZuOshBmzV4Ta+s23hdfFZnBsdzmoR3US0d7ErpqSbTQ= github.com/adrg/xdg v0.3.0/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ= github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls= github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= -github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= -github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= -github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= -github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= -github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= -github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= -github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= -github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= -github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= -github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= -github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= -github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= -github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= -github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46 h1:N+R2A3fGIr5GucoRMu2xpqyQWQlfY31orbofBCdjMz8= +github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46/go.mod h1:2Yoiy15Cf7Q3NFwfaJquh7Mk1uGI09ytcD7CUhn8j7s= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= -github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= -github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= -github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= -github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= -github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= -github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= -github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= -github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= -github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= -github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= -github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= -github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= -github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= -github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= -github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= -github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= +github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= -github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= -github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo= -github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= -github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= -github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= -github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= -github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= -github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4= -github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= -github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= -github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= +github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= +github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= +github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= -github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk= -github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= +github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc= +github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= -github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/trimmer-io/go-xmp v1.0.0/go.mod h1:Aaptr9sp1lLv7UnCAdQ+gSHZyY2miYaKmcNVj7HRBwA= -github.com/unidoc/freetype v0.0.0-20220130190903-3efbeefd0c90 h1:Rk4easgDQslR3DK7vwtl6jYMZTF3JqZ3ceUdyT6a3UM= -github.com/unidoc/freetype v0.0.0-20220130190903-3efbeefd0c90/go.mod h1:mJ/Q7JnqEoWtajJVrV6S1InbRv0K/fJerPB5SQs32KI= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +github.com/unidoc/freetype v0.2.3 h1:uPqW+AY0vXN6K2tvtg8dMAtHTEvvHTN52b72XpZU+3I= +github.com/unidoc/freetype v0.2.3/go.mod h1:mJ/Q7JnqEoWtajJVrV6S1InbRv0K/fJerPB5SQs32KI= github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= -github.com/unidoc/pkcs7 v0.1.0 h1:9bQfbWMYsIfUP8PyhTcBudOsvbLpNH0MBv4U0P/jDTE= -github.com/unidoc/pkcs7 v0.1.0/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= +github.com/unidoc/pkcs7 v0.2.0 h1:0Y0RJR5Zu7OuD+/l7bODXARn6b8Ev2G4A8lI4rzy9kg= +github.com/unidoc/pkcs7 v0.2.0/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a h1:RLtvUhe4DsUDl66m7MJ8OqBjq8jpWBXPK6/RKtqeTkc= github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a/go.mod h1:j+qMWZVpZFTvDey3zxUkSgPJZEX33tDgU/QIA0IzCUw= -github.com/unidoc/unichart v0.1.0 h1:GoJ/rxSoOYZsqlG3yOJpKkwgfsIQgb9hHX7bILZHcCg= -github.com/unidoc/unichart v0.1.0/go.mod h1:9sJXeqxIIsU2D07tmhpDMoND0mBFRGfKBJnXZMsJnzk= -github.com/unidoc/unipdf/v3 v3.34.0 h1:rTfnDuT1EMDR4QbxLsse/AtnZ7UJEar0vqZ/45SA+eM= -github.com/unidoc/unipdf/v3 v3.34.0/go.mod h1:rU+M1cSW0me6NOqQ471noVeEvQWhNBH3iUWkfFqJIgM= -github.com/unidoc/unitype v0.2.1 h1:x0jMn7pB/tNrjEVjy3Ukpxo++HOBQaTCXcTYFA6BH3w= -github.com/unidoc/unitype v0.2.1/go.mod h1:mafyug7zYmDOusqa7G0dJV45qp4b6TDAN+pHN7ZUIBU= -github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= -go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f h1:OeJjE6G4dgCY4PIXvIRQbE8+RX+uXZyGhUy/ksMGJoc= -golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= -golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= -golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= -golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +github.com/unidoc/unichart v0.3.0 h1:VX1j5yzhjrR3f2flC03Yat6/WF3h7Z+DLEvJLoTGhoc= +github.com/unidoc/unichart v0.3.0/go.mod h1:8JnLNKSOl8yQt1jXewNgYFHhFm5M6/ZiaydncFDpakA= +github.com/unidoc/unipdf/v3 v3.53.0 h1:xUgG/MH2iUHaar554w6OrL0qTKNy4AWzb19z0RyIExs= +github.com/unidoc/unipdf/v3 v3.53.0/go.mod h1:sEXO/chguUL1RAtyPnGos2BbCBGjL9dusmdT5b13eBg= +github.com/unidoc/unitype v0.4.0 h1:/TMZ3wgwfWWX64mU5x2O9no9UmoBqYCB089LYYqHyQQ= +github.com/unidoc/unitype v0.4.0/go.mod h1:HV5zuUeqMKA4QgYQq3KDlJY/P96XF90BQB+6czK6LVA= +golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= +golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= -golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 h1:LRtI4W37N+KFebI/qV0OFiLUv4GLOWeEW5hn/KEJvxE= -golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= -golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8= +golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= +golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= +golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60= -golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f h1:GGU+dLjvlC3qDwqYgL6UgRmHXhOOgns0bZu2Ty5mm6U= -golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= -google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= -google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= +golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= -gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/selector/selector.go b/selector/selector.go index 97f80a6..3b66faf 100644 --- a/selector/selector.go +++ b/selector/selector.go @@ -9,11 +9,11 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package selector ;import _ff "errors"; +package selector ;import _g "errors"; // ByType is a 'By' selector type enumerator. type ByType uint ; // Validate checks validity of the ByType. -func (_b ByType )Validate ()error {if _b >=ByID &&_b <=BySearch {return nil ;};return _ff .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};const (ByUndefined ByType =iota ;ByID ;ByQueryAll ; +func (_cg ByType )Validate ()error {if _cg >=ByID &&_cg <=BySearch {return nil ;};return _g .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};const (ByUndefined ByType =iota ;ByID ;ByQueryAll ; ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); \ No newline at end of file diff --git a/sizes/sizes.go b/sizes/sizes.go index ca1d9dd..407708d 100644 --- a/sizes/sizes.go +++ b/sizes/sizes.go @@ -12,190 +12,191 @@ // Package sizes defines basic types that determines the size units i.e. lengths. // // -package sizes ;import (_e "encoding/json";_b "flag";_a "fmt";_d "strconv";_bg "strings";);var (_ Length =Millimeter (0);); +package sizes ;import (_b "encoding/json";_g "flag";_ea "fmt";_c "strconv";_be "strings";); -// Set implements pflag.Value interface. -func (_eba *PageSize )Set (s string )error {_cca ,_aeb :=UnmarshalPageSize (s );if _aeb !=nil {return _aeb ;};*_eba =_cca ;return nil ;}; +// String gets the string value for given flag. +func (_ga *LengthFlag )String ()string {if _ga .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _ga .Length .String ();}; + +// Points implements Length interface. +func (_dc Inch )Points ()Point {return Point (float64 (_dc )*_af )}; + +// UnmarshalPageSize unmarshals the page size from the string. +func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _deea PageSize ;if _cca :=(&_deea ).UnmarshalText ([]byte (pageSize ));_cca !=nil {return 0,_ea .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_cca ); +};return _deea ,nil ;};var _ _g .Value =(*Orientation )(nil ); // Type implements pflag.Value interface. -func (_gc Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; +func (_fcc Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; -// UnmarshalInch unmarshalls provided string into unit. -func UnmarshalInch (unit string )(Inch ,error ){if _bg .HasSuffix (unit ,"\u006d\u006d"){_gg ,_ce :=_cc (unit );if _ce !=nil {return 0,_ce ;};return _gg .Inches (),nil ;};if _bg .HasSuffix (unit ,"\u0069\u006e"){return _bfa (unit );};return 0,_a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); -}; +// String implements fmt.Stringer interface. +func (_ef Orientation )String ()string {if _ef ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; -// MarshalJSON implements the json.Marshaler interface for PageSize -func (_eecb PageSize )MarshalJSON ()([]byte ,error ){return _e .Marshal (_eecb .String ())}; +// PageSize is the enum used for defining the page size. +type PageSize int ; -// ValueType implements pflag.Value interface. -func (_bd Inch )ValueType ()string {return _bd .Type ()}; +// Type implements pflag.Value interface. +func (_ag *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; // Type implements pflag.Value interface. -func (_abc PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; +func (_ega Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; -// Inches gets the inches equivalent from provided millimeter value. -func (_ca Millimeter )Inches ()Inch {return Inch (float64 (_ca )*_f )};func _eb (_fg Length )([]byte ,error ){if _fg ==nil {return nil ,nil ;};_gde ,_cd :=MarshalUnit (_fg );if _cd !=nil {return nil ,_cd ;};return []byte ("\u0022"+_gde +"\u0022"),nil ; -}; +// ValueType implements pflag.Value interface. +func (_dg Inch )ValueType ()string {return _dg .Type ()}; -// Length is it the default dimension unit. -type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; +// MarshalJSON implements json.Marshaler interface. +func (_ggb Point )MarshalJSON ()([]byte ,error ){return _bee (_ggb )};func _bc (_fed string )(Inch ,error ){_fed =_be .TrimSpace (_be .Trim (_fed ,"\u0069\u006e"));_bcc ,_gaf :=_c .ParseFloat (_fed ,64);if _gaf !=nil {return 0,_ea .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_gaf ); +};return Inch (_bcc ),nil ;}; -// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise -func (_faca PageSize )IsAPageSize ()bool {for _ ,_aaa :=range _dcb {if _faca ==_aaa {return true ;};};return false ;}; +// String implements fmt.Stringer interface. +func (_ffe Point )String ()string {_fcb :=_be .Builder {};_fcb .WriteString (_c .FormatFloat (float64 (_ffe ),'f',1,64));_fcb .WriteString ("\u0070\u0074");return _fcb .String ();}; -// Set sets the unit value. -// Implements pflag.Value interface. -func (_fc *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_fc .Length =nil ;return nil ;};_eaf ,_ag :=UnmarshalLength (s );if _ag !=nil {return _ag ;};_fc .Length =_eaf ;return nil ;}; +// Millimeters converts the inches value to the millimeters. +func (_ba Inch )Millimeters ()Millimeter {return Millimeter (float64 (_ba )*_ee )}; -// HasChanged implements viper.FlagValue interface. -func (_dca *Point )HasChanged ()bool {return _dca !=nil }; +// UnmarshalJSON implements the json.Unmarshaler interface for PageSize +func (_bcf *PageSize )UnmarshalJSON (data []byte )error {var _bge string ;if _ae :=_b .Unmarshal (data ,&_bge );_ae !=nil {return _ea .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); +};var _baed error ;*_bcf ,_baed =PageSizeString (_bge );return _baed ;}; -// Millimeters gets the float64 millimeter value. -func (_gd Millimeter )Millimeters ()Millimeter {return _gd }; +// Length is it the default dimension unit. +type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;};const (_f =float64 (1)/float64 (25.4);_ee =25.4;_a =0.0139;_gd =0.3528;_af =1.0/64;_ff =1.0/_gd ;);const _fbe ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; -// MarshalJSON implements json.Marshaler interface -func (_fe Millimeter )MarshalJSON ()([]byte ,error ){return _eb (_fe )}; // Type implements pflag.Value interface. -func (_ef Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; +func (_bbg PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; -// PageSizeValues returns all values of the enum -func PageSizeValues ()[]PageSize {return _dcb }; +// LengthFlag is a pflag wrapper for the Length value. +type LengthFlag struct{Length Length ;};var _dbf =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};var _cg =map[string ]PageSize {_fbe [0:9]:0,_fbe [9:11]:1,_fbe [11:13]:2,_fbe [13:15]:3,_fbe [15:17]:4,_fbe [17:19]:5,_fbe [19:21]:6,_fbe [21:23]:7,_fbe [23:25]:8,_fbe [25:27]:9,_fbe [27:29]:10,_fbe [29:32]:11,_fbe [32:34]:12,_fbe [34:36]:13,_fbe [36:38]:14,_fbe [38:40]:15,_fbe [40:42]:16,_fbe [42:44]:17,_fbe [44:46]:18,_fbe [46:48]:19,_fbe [48:50]:20,_fbe [50:52]:21,_fbe [52:55]:22,_fbe [55:61]:23}; -// Name implements pflag.Value interface. -func (_eef Inch )Name ()string {return "\u0069\u006e\u0063\u0068"};var _ _b .Value =(*Orientation )(nil );func _cc (_fdg string )(Millimeter ,error ){_fdg =_bg .TrimSpace (_bg .TrimSuffix (_fdg ,"\u006d\u006d"));_fdd ,_dff :=_d .ParseFloat (_fdg ,64);if _dff !=nil {return 0,_a .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_dff ); -};return Millimeter (_fdd ),nil ;}; + +// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise +func (_bg PageSize )IsAPageSize ()bool {for _ ,_ca :=range _dbf {if _bg ==_ca {return true ;};};return false ;}; + +// Set sets the unit value. +// Implements pflag.Value interface. +func (_fg *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_fg .Length =nil ;return nil ;};_d ,_fc :=UnmarshalLength (s );if _fc !=nil {return _fc ;};_fg .Length =_d ;return nil ;}; // Dimensions gets the dimensions of the given page size. // If provided page size is not valid than the function returns 0 values. -func (_baf PageSize )Dimensions ()(_dde ,_fac Millimeter ){switch _baf {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; +func (_dbg PageSize )Dimensions ()(_gdef ,_cc Millimeter ){switch _dbg {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; -case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _dde ,_fac ;}; - -// ValueString implements pflag.Value interface. -func (_bf Inch )ValueString ()string {return _bf .String ()}; +case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _gdef ,_cc ;}; -// Orientation is the page orientation type wrapper. -type Orientation bool ; - -// PageSize is the enum used for defining the page size. -type PageSize int ; - -// Point is a unit of Length commonly used to measure the height of fonts. -type Point float64 ; +// ValueType implements viper.FlagValue interface. +func (_cd Point )ValueType ()string {return _cd .Type ()}; -// LengthFlag is a pflag wrapper for the Length value. -type LengthFlag struct{Length Length ;}; +// ValueString implements viper.FlagValue interface. +func (_cb Point )ValueString ()string {return _cb .String ()}; // Points implements Length interface. -func (_ff Inch )Points ()Point {return Point (float64 (_ff )*_bb )};const (Portrait =Orientation (false );Landscape =Orientation (true );); +func (_bae Point )Points ()Point {return _bae };func (_gee PageSize )String ()string {if _gee < 0||_gee >=PageSize (len (_eba )-1){return _ea .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_gee );};return _fbe [_eba [_gee ]:_eba [_gee +1]]; +}; -// String implements fmt.Stringer interface. -func (_dd Millimeter )String ()string {_ge :=_bg .Builder {};_ge .WriteString (_d .FormatFloat (float64 (_dd ),'f',1,64));_ge .WriteString ("\u006d\u006d");return _ge .String ();}; +// UnmarshalInch unmarshalls provided string into unit. +func UnmarshalInch (unit string )(Inch ,error ){if _be .HasSuffix (unit ,"\u006d\u006d"){_gc ,_gde :=_fca (unit );if _gde !=nil {return 0,_gde ;};return _gc .Inches (),nil ;};if _be .HasSuffix (unit ,"\u0069\u006e"){return _bc (unit );};return 0,_ea .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); +};var _eba =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; -// UnmarshalPageSize unmarshals the page size from the string. -func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _gef PageSize ;if _aa :=(&_gef ).UnmarshalText ([]byte (pageSize ));_aa !=nil {return 0,_a .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_aa ); -};return _gef ,nil ;}; +// Orientation is the page orientation type wrapper. +type Orientation bool ; -// String implements fmt.Stringer interface. -func (_bc Inch )String ()string {_eea :=_bg .Builder {};_eea .WriteString (_d .FormatFloat (float64 (_bc ),'f',1,64));_eea .WriteString ("\u0069\u006e");return _eea .String ();};const _bfg ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; -const (_f =float64 (1)/float64 (25.4);_ee =25.4;_c =0.0139;_ae =0.3528;_bb =1.0/64;_ea =1.0/_ae ;); +// Type implements pflag.Value interface. +func (_bb Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; -// Points implements Length interface. -func (_eg Millimeter )Points ()Point {return Point (_eg *_ea )}; +// Name implements viper.FlagValue interface. +func (_dgg Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; -// Type implements pflag.Value interface. -func (_bbb Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; +// Set implements flag.Value interface. +func (_eeg *Point )Set (s string )error {_baf ,_fbg :=_c .ParseFloat (s ,64);if _fbg !=nil {return _ea .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_fbg );};*_eeg =Point (_baf ); +return nil ;}; -// MarshalUnit marshals the unit into the string. -func MarshalUnit (unit Length )(string ,error ){switch _da :=unit .(type ){case Millimeter :return _a .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_da ),nil ;case Inch :return _a .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_da ),nil ;case Point :return _a .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_da ),nil ; -default:return "",_a .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; +// Set implements flag.Value interface. +func (_bf *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_bf =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_bf =Landscape ;default:return _ea .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); +};return nil ;}; // Millimeter is the dimension unit that defines a millimeter. -type Millimeter float64 ; +type Millimeter float64 ;const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;);func _fca (_deg string )(Millimeter ,error ){_deg =_be .TrimSpace (_be .TrimSuffix (_deg ,"\u006d\u006d")); +_ebf ,_fd :=_c .ParseFloat (_deg ,64);if _fd !=nil {return 0,_ea .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_fd );};return Millimeter (_ebf ),nil ; +}; -// MarshalJSON implements json.Marshaler interface. -func (_ad Point )MarshalJSON ()([]byte ,error ){return _eb (_ad )}; +// Inch is a unit that +type Inch float64 ; -// Name implements viper.FlagValue interface. -func (_fa Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; +// HasChanged implements viper.FlagValue interface. +func (_aad *Point )HasChanged ()bool {return _aad !=nil }; -// Millimeters converts the inches value to the millimeters. -func (_ba Inch )Millimeters ()Millimeter {return Millimeter (float64 (_ba )*_ee )}; +// MarshalUnit marshals the unit into the string. +func MarshalUnit (unit Length )(string ,error ){switch _gfd :=unit .(type ){case Millimeter :return _ea .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_gfd ),nil ;case Inch :return _ea .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_gfd ),nil ;case Point :return _ea .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_gfd ),nil ; +default:return "",_ea .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; -// MarshalJSON implements json.Marshaler interface -func (_dc Inch )MarshalJSON ()([]byte ,error ){return _eb (_dc )};func _bfa (_ed string )(Inch ,error ){_ed =_bg .TrimSpace (_bg .Trim (_ed ,"\u0069\u006e"));_db ,_ac :=_d .ParseFloat (_ed ,64);if _ac !=nil {return 0,_a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ac ); -};return Inch (_db ),nil ;};var _gcc =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; +// String implements fmt.Stringer interface. +func (_ec Millimeter )String ()string {_gff :=_be .Builder {};_gff .WriteString (_c .FormatFloat (float64 (_ec ),'f',1,64));_gff .WriteString ("\u006d\u006d");return _gff .String ();}; -// Millimeters converts the inches value to the millimeters. -func (_aee Point )Millimeters ()Millimeter {return Millimeter (float64 (_aee )*_ae )}; +// MarshalJSON implements the json.Marshaler interface for PageSize +func (_dde PageSize )MarshalJSON ()([]byte ,error ){return _b .Marshal (_dde .String ())};var (_ Length =Millimeter (0););var _ _g .Value =(*Point )(nil ); -// ValueString implements viper.FlagValue interface. -func (_cag Point )ValueString ()string {return _cag .String ()}; +// MarshalText implements the encoding.TextMarshaler interface for PageSize +func (_fbgb PageSize )MarshalText ()([]byte ,error ){return []byte (_fbgb .String ()),nil }; -// String gets the string value for given flag. -func (_bgd *LengthFlag )String ()string {if _bgd .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _bgd .Length .String ();}; +// Set implements pflag.Value interface. +func (_eg *Inch )Set (s string )error {_de ,_fb :=_c .ParseFloat (s ,64);if _fb !=nil {return _ea .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_fb );};*_eg =Inch (_de ); +return nil ;}; -// MarshalText implements the encoding.TextMarshaler interface for PageSize -func (_ada PageSize )MarshalText ()([]byte ,error ){return []byte (_ada .String ()),nil }; +// Millimeters gets the float64 millimeter value. +func (_agg Millimeter )Millimeters ()Millimeter {return _agg }; -// Inches gets the inch value. Implements Length interface. -func (_fb Point )Inches ()Inch {return Inch (float64 (_fb )*_c )};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;);func (_fab PageSize )String ()string {if _fab < 0||_fab >=PageSize (len (_gcc )-1){return _a .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_fab ); -};return _bfg [_gcc [_fab ]:_gcc [_fab +1]];};var _dcb =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; +// Name implements pflag.Value interface. +func (_ge Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; -// Inches gets the inch value. Implements Length interface. -func (_ab Inch )Inches ()Inch {return _ab }; +// PageSizeString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func PageSizeString (s string )(PageSize ,error ){if _dgbf ,_eff :=_cg [s ];_eff {return _dgbf ,nil ;};return 0,_ea .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); +};var _ Length =Inch (0); -// Set implements flag.Value interface. -func (_egg *Point )Set (s string )error {_aed ,_abaa :=_d .ParseFloat (s ,64);if _abaa !=nil {return _a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_abaa );};*_egg =Point (_aed ); -return nil ;}; +// Inches gets the inches equivalent from provided millimeter value. +func (_bef Millimeter )Inches ()Inch {return Inch (float64 (_bef )*_f )}; -// Points implements Length interface. -func (_dfa Point )Points ()Point {return _dfa }; +// PageSizeValues returns all values of the enum +func PageSizeValues ()[]PageSize {return _dbf }; -// String implements fmt.Stringer interface. -func (_ddd Point )String ()string {_aba :=_bg .Builder {};_aba .WriteString (_d .FormatFloat (float64 (_ddd ),'f',1,64));_aba .WriteString ("\u0070\u0074");return _aba .String ();}; +// MarshalPageSize marshals the page size into string. +func MarshalPageSize (p PageSize )(string ,error ){_ad ,_egg :=p .MarshalText ();if _egg !=nil {return "",_egg ;};return string (_ad ),nil ;}; -// Set implements flag.Value interface. -func (_ga *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_ga =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_ga =Landscape ;default:return _a .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); -};return nil ;}; +// Points implements Length interface. +func (_aga Millimeter )Points ()Point {return Point (_aga *_ff )}; -// Type implements pflag.Value interface. -func (_cg *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; +// String implements fmt.Stringer interface. +func (_aa Inch )String ()string {_gg :=_be .Builder {};_gg .WriteString (_c .FormatFloat (float64 (_aa ),'f',1,64));_gg .WriteString ("\u0069\u006e");return _gg .String ();}; -// UnmarshalJSON implements the json.Unmarshaler interface for PageSize -func (_ccf *PageSize )UnmarshalJSON (data []byte )error {var _bafa string ;if _gae :=_e .Unmarshal (data ,&_bafa );_gae !=nil {return _a .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); -};var _dg error ;*_ccf ,_dg =PageSizeString (_bafa );return _dg ;}; +// Inches gets the inch value. Implements Length interface. +func (_eb Point )Inches ()Inch {return Inch (float64 (_eb )*_a )};func _gbe (_gffe string )(Point ,error ){_gffe =_be .TrimSpace (_be .Trim (_gffe ,"\u0070\u0074"));_agd ,_bd :=_c .ParseFloat (_gffe ,64);if _bd !=nil {return 0,_bd ;};return Point (_agd ),nil ; +};func _bee (_cde Length )([]byte ,error ){if _cde ==nil {return nil ,nil ;};_db ,_abd :=MarshalUnit (_cde );if _abd !=nil {return nil ,_abd ;};return []byte ("\u0022"+_db +"\u0022"),nil ;};const (Portrait =Orientation (false );Landscape =Orientation (true ); +); // UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize -func (_aef *PageSize )UnmarshalText (text []byte )error {var _de error ;*_aef ,_de =PageSizeString (string (text ));return _de ;}; +func (_ac *PageSize )UnmarshalText (text []byte )error {var _dgd error ;*_ac ,_dgd =PageSizeString (string (text ));return _dgd ;}; -// ValueType implements viper.FlagValue interface. -func (_abf Point )ValueType ()string {return _abf .Type ()};var _eec =map[string ]PageSize {_bfg [0:9]:0,_bfg [9:11]:1,_bfg [11:13]:2,_bfg [13:15]:3,_bfg [15:17]:4,_bfg [17:19]:5,_bfg [19:21]:6,_bfg [21:23]:7,_bfg [23:25]:8,_bfg [25:27]:9,_bfg [27:29]:10,_bfg [29:32]:11,_bfg [32:34]:12,_bfg [34:36]:13,_bfg [36:38]:14,_bfg [38:40]:15,_bfg [40:42]:16,_bfg [42:44]:17,_bfg [44:46]:18,_bfg [46:48]:19,_bfg [48:50]:20,_bfg [50:52]:21,_bfg [52:55]:22,_bfg [55:61]:23}; +// Set implements pflag.Value interface. +func (_dd *PageSize )Set (s string )error {_afc ,_fcaf :=UnmarshalPageSize (s );if _fcaf !=nil {return _fcaf ;};*_dd =_afc ;return nil ;}; +// Inches gets the inch value. Implements Length interface. +func (_fbb Inch )Inches ()Inch {return _fbb }; -// PageSizeString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func PageSizeString (s string )(PageSize ,error ){if _cgf ,_dffb :=_eec [s ];_dffb {return _cgf ,nil ;};return 0,_a .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); -}; +// HasChanged implements pflag.Value interface. +func (_fcf *Inch )HasChanged ()bool {return _fcf !=nil }; -// String implements fmt.Stringer interface. -func (_egf Orientation )String ()string {if _egf ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; +// ValueString implements pflag.Value interface. +func (_fe Inch )ValueString ()string {return _fe .String ()}; -// UnmarshalLength unmarshalls string value into Length. -func UnmarshalLength (length string )(Length ,error ){if _bg .HasSuffix (length ,"\u006d\u006d"){return _cc (length );};if _bg .HasSuffix (length ,"\u0069\u006e"){return _bfa (length );};if _bg .HasSuffix (length ,"\u0070\u0074"){return _cee (length ); -};return nil ,_a .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length );}; +// MarshalJSON implements json.Marshaler interface +func (_ed Inch )MarshalJSON ()([]byte ,error ){return _bee (_ed )}; -// MarshalPageSize marshals the page size into string. -func MarshalPageSize (p PageSize )(string ,error ){_cbg ,_ebf :=p .MarshalText ();if _ebf !=nil {return "",_ebf ;};return string (_cbg ),nil ;}; +// Point is a unit of Length commonly used to measure the height of fonts. +type Point float64 ; -// Inch is a unit that -type Inch float64 ; +// Millimeters converts the inches value to the millimeters. +func (_dee Point )Millimeters ()Millimeter {return Millimeter (float64 (_dee )*_gd )}; -// Set implements pflag.Value interface. -func (_fd *Inch )Set (s string )error {_cb ,_feb :=_d .ParseFloat (s ,64);if _feb !=nil {return _a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_feb );};*_fd =Inch (_cb ); -return nil ;}; +// UnmarshalLength unmarshalls string value into Length. +func UnmarshalLength (length string )(Length ,error ){if _be .HasSuffix (length ,"\u006d\u006d"){return _fca (length );};if _be .HasSuffix (length ,"\u0069\u006e"){return _bc (length );};if _be .HasSuffix (length ,"\u0070\u0074"){return _gbe (length ); +};return nil ,_ea .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length );}; -// HasChanged implements pflag.Value interface. -func (_fde *Inch )HasChanged ()bool {return _fde !=nil };func _cee (_ec string )(Point ,error ){_ec =_bg .TrimSpace (_bg .Trim (_ec ,"\u0070\u0074"));_adf ,_dbb :=_d .ParseFloat (_ec ,64);if _dbb !=nil {return 0,_dbb ;};return Point (_adf ),nil ;};var _ _b .Value =(*Point )(nil ); -var _ Length =Inch (0); \ No newline at end of file +// MarshalJSON implements json.Marshaler interface +func (_ab Millimeter )MarshalJSON ()([]byte ,error ){return _bee (_ab )}; \ No newline at end of file diff --git a/unihtml.go b/unihtml.go index bcfc514..1e34e4e 100644 --- a/unihtml.go +++ b/unihtml.go @@ -10,55 +10,95 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package unihtml contains a plugin for the UniDoc. -package unihtml ;import (_ga "bytes";_e "context";_ea "errors";_f "fmt";_eg "github.com/unidoc/unihtml/client";_b "github.com/unidoc/unihtml/content";_ge "github.com/unidoc/unihtml/selector";_ag "github.com/unidoc/unihtml/sizes";_eab "github.com/unidoc/unipdf/v3/common"; -_c "github.com/unidoc/unipdf/v3/common/license";_bg "github.com/unidoc/unipdf/v3/creator";_egd "github.com/unidoc/unipdf/v3/model";_ce "github.com/unidoc/unipdf/v3/render";_g "image";_ab "image/color";_af "math";_a "net/url";_de "os";_fg "time";);func (_ccf *Document )validate ()error {if _cee ==nil {return ErrNoClient ; -};if _ccf ._egf ==nil {return ErrContentNotDefined ;};return nil ;}; +package unihtml ;import (_gg "bytes";_g "context";_bg "errors";_af "fmt";_cc "github.com/unidoc/unihtml/client";_bad "github.com/unidoc/unihtml/content";_ac "github.com/unidoc/unihtml/selector";_ag "github.com/unidoc/unihtml/sizes";_d "github.com/unidoc/unipdf/v3/common"; +_ee "github.com/unidoc/unipdf/v3/common/license";_gc "github.com/unidoc/unipdf/v3/creator";_ga "github.com/unidoc/unipdf/v3/model";_ad "github.com/unidoc/unipdf/v3/render";_ba "image";_e "image/color";_a "math";_f "net/url";_b "os";_ce "time";); -// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. -func ConnectOptions (o Options )error {_cee =_eg .New (_eg .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_cd ,_ed :=_e .WithTimeout (_e .Background (),_fg .Second *5);defer _ed ();if _afb :=_cee .HealthCheck (_cd );_afb !=nil {return _afb ; -};return nil ;};func (_gef *Document )extract (_aca _e .Context ,_dcf ,_eacf _ag .Length ,_eae margins )([]*_egd .PdfPage ,error ){_cbc :=_eg .BuildHTMLQuery ().SetContent (_gef ._egf ).PageSize (_gef ._geb ).PaperWidth (_dcf ).PaperHeight (_eacf ).Orientation (_gef ._gg ).MarginLeft (_eae .Left ).MarginRight (_eae .Right ).MarginTop (_eae .Top ).MarginBottom (_eae .Bottom ).TimeoutDuration (_gef .getTimeoutDuration ()).WaitTime (_gef ._egfb ); -for _ ,_cf :=range _gef ._ebc {_cbc .WaitReady (_cf .Selector ,_cf .By );};for _ ,_bbc :=range _gef ._dc {_cbc .WaitVisible (_bbc .Selector ,_bbc .By );};_gab ,_ee :=_cbc .Query ();if _ee !=nil {return nil ,_ee ;};var _dfaf _e .CancelFunc ;if _gef ._fae !=nil {_aca ,_dfaf =_e .WithTimeout (_aca ,*_gef ._fae ); -}else {_aca ,_dfaf =_e .WithTimeout (_aca ,_fg .Second *15);};defer _dfaf ();_ddg ,_ee :=_cee .ConvertHTML (_aca ,_gab );if _ee !=nil {return nil ,_ee ;};_egb :=_ga .NewReader (_ddg .Data );_dcb ,_ee :=_egd .NewPdfReader (_egb );if _ee !=nil {return nil ,_ee ; -};return _dcb .PageList ,nil ;}; +// WriteToFile writes the document to a file defined by the output path. +func (_ccd *Document )WriteToFile (outputPath string )error {if _ccdb :=_ccd .validate ();_ccdb !=nil {return _ccdb ;};_fge :=_ce .Second *20+_ccd ._ae ;_fb ,_abf :=_g .WithTimeout (_g .Background (),_fge );defer _abf ();_gce ,_badc :=_ccd .extract (_fb ,_ccd ._dda ,_ccd ._dcb ,_ccd .getMargins ()); +if _badc !=nil {return _badc ;};_fa :=_gc .New ();for _ ,_acd :=range _gce {if _badc =_fa .AddPage (_acd );_badc !=nil {return _badc ;};};return _fa .WriteToFile (outputPath );}; -// SetMargins sets the Document Margins. -func (_afd *Document )SetMargins (left ,right ,top ,bottom float64 ){_afd ._gc .Left =_ag .Point (left );_afd ._gc .Right =_ag .Point (right );_afd ._gc .Top =_ag .Point (top );_afd ._gc .Bottom =_ag .Point (bottom );_afd ._daf =_bg .PositionAbsolute ; -};func _aad ()error {_cb :=_c .GetLicenseKey ();if _cb ==nil {return _ea .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};if !_cb .IsLicensed (){return _ea .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); -};return nil ;}; +// SetMarginBottom sets the left margin. +func (_fe *Document )SetMarginBottom (margin _ag .Length ){_fe ._gaa .Bottom =margin }; // WaitVisible waits for the provided selector to be ready. // A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_abfb *Document )WaitVisible (sel string ,by ..._ge .ByType ){_egff :=_ge .BySearch ;if len (by )> 0{_egff =by [0];};_abfb ._dc =append (_abfb ._dc ,_eg .BySelector {Selector :sel ,By :_egff });}; +func (_fgf *Document )WaitVisible (sel string ,by ..._ac .ByType ){_cdg :=_ac .BySearch ;if len (by )> 0{_cdg =by [0];};_fgf ._bag =append (_fgf ._bag ,_cc .BySelector {Selector :sel ,By :_cdg });}; -// WaitTime sets the waiting time before the webpage is rendered to PDF. -func (_dd *Document )WaitTime (duration _fg .Duration ){_dd ._egfb =duration }; +// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. +func (_eef *Document )TrimLastPageContent (){_eef ._cd =true };type margins struct{Left ,Right ,Bottom ,Top _ag .Length ;}; + +// SetPageSize sets the page default size. +func (_add *Document )SetPageSize (pageSize _ag .PageSize )error {if !pageSize .IsAPageSize (){return _bg .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); +};_add ._ace =pageSize ;_add ._ebf =_gc .PositionAbsolute ;return nil ;}; + +// SetMarginLeft sets the left margin. +func (_ff *Document )SetMarginLeft (margin _ag .Length ){_ff ._gaa .Left =margin }; // ContainerComponent implements creator.containerElement interface. -func (_fbd *Document )ContainerComponent (container _bg .Drawable )(_bg .Drawable ,error ){switch container .(type ){case *_bg .Chapter :default:return nil ,_f .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); -};return _fbd ,nil ;}; +func (_dag *Document )ContainerComponent (container _gc .Drawable )(_gc .Drawable ,error ){switch container .(type ){case *_gc .Chapter :default:return nil ,_af .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); +};return _dag ,nil ;}; -// SetMarginTop sets the left margin. -func (_dae *Document )SetMarginTop (margin _ag .Length ){_dae ._gc .Top =margin };func _aaa (_ac _g .Image )float64 {_eacc :=_ac .Bounds ();var (_dfa int ;_gcg _ab .Color ;_dbbc ,_adb ,_afg uint32 ;);_cea ,_aae :=_eacc .Min .X ,_eacc .Max .Y -1;_bcc :=_ac .At (_cea ,_aae ); -_aff ,_aadb ,_egee ,_ :=_bcc .RGBA ();_gcaa :=_aff ==_af .MaxUint16 &&_aadb ==_af .MaxUint16 &&_egee ==_af .MaxUint16 ;for _aae =_eacc .Max .Y -1;_aae >=_eacc .Min .Y ;_aae --{var _age bool ;for _cea =_eacc .Min .X ;_cea < _eacc .Max .X ;_cea ++{_gcg =_ac .At (_cea ,_aae ); -_dbbc ,_adb ,_afg ,_ =_gcg .RGBA ();if (_gcaa &&!(_dbbc ==_aff &&_adb ==_aadb &&_egee ==_afg ))||(!_gcaa &&(_af .Abs (float64 (_dbbc )-float64 (_aff ))/float64 (_af .MaxUint16 )> 0.03||_af .Abs (float64 (_adb )-float64 (_aadb ))/float64 (_af .MaxUint16 )> 0.03||_af .Abs (float64 (_afg )-float64 (_egee ))/float64 (_af .MaxUint16 )> 0.03)){_age =true ; -break ;};};if _age {break ;};_dfa =_aae ;};return float64 (_eacc .Max .Y -_dfa )/float64 (_eacc .Max .Y );};func (_eaeb *Document )getTimeoutDuration ()_fg .Duration {if _eaeb ._fae !=nil {return *_eaeb ._fae ;};return 0;}; +// WaitReady waits for the provided selector to be ready. +// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. +func (_ccb *Document )WaitReady (sel string ,by ..._ac .ByType ){_fd :=_ac .BySearch ;if len (by )> 0{_fd =by [0];};_ccb ._gf =append (_ccb ._gf ,_cc .BySelector {Selector :sel ,By :_fd });}; -// GeneratePageBlocks implements creator.Drawable interface. -func (_df *Document )GeneratePageBlocks (ctx _bg .DrawContext )([]*_bg .Block ,_bg .DrawContext ,error ){if _ecg :=_df .validate ();_ecg !=nil {return nil ,ctx ,_ecg ;};var _bc []*_bg .Block ;_cef :=_df .getMargins ();_eca ,_dbb :=_df ._db ,_df ._gca ; -if _df ._daf .IsRelative (){_eca ,_dbb =_ag .Point (ctx .Width ),_ag .Point (ctx .Height );ctx .X -=float64 (_cef .Left .Points ());};_gb ,_bae :=_df .extract (_e .Background (),_eca ,_dbb ,_cef );if _bae !=nil {return nil ,_bg .DrawContext {},_bae ;}; -for _geg ,_be :=range _gb {_ebe ,_bca :=_bg .NewBlockFromPage (_be );if _bca !=nil {return nil ,_bg .DrawContext {},_bca ;};var _fe float64 ;if _df ._bd &&_geg ==len (_gb )-1{_ca :=_ce .NewImageDevice ();_agc ,_bf :=_ca .Render (_be );if _bf !=nil {return nil ,_bg .DrawContext {},_bf ; -};_aed ,_bf :=_be .GetMediaBox ();if _bf !=nil {return nil ,_bg .DrawContext {},_bf ;};_abf :=_fg .Now ();_bee :=_aaa (_agc );_fe =_aed .Height ()*_bee ;_eab .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_fg .Since (_abf )); -if _df ._gc .Bottom !=nil {_fe -=float64 (_df ._gc .Bottom .Points ());};if _fe < 0{_fe =0;};_eab .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_fe ); -};_aec ,_cc ,_bca :=_ebe .GeneratePageBlocks (ctx );if _bca !=nil {return nil ,_bg .DrawContext {},_bca ;};ctx =_cc ;ctx .Y -=_fe ;if _geg !=len (_gb )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; -ctx .Page ++;};_bc =append (_bc ,_aec ...);};return _bc ,ctx ,nil ;}; +// SetMarginRight sets the left margin. +func (_cccb *Document )SetMarginRight (margin _ag .Length ){_cccb ._gaa .Right =margin }; + +// SetTimeoutDuration sets the timeout duration +// the default timeout is 15 seconds. +func (_edg *Document )SetTimeoutDuration (duration _ce .Duration ){_edg ._bf =&duration };var ErrContentNotDefined =_bg .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); +func _de (_badd _ba .Image )float64 {_ceg :=_badd .Bounds ();var (_db int ;_adc _e .Color ;_beef ,_ca ,_gab uint32 ;);_aa ,_ebb :=_ceg .Min .X ,_ceg .Max .Y -1;_fad :=_badd .At (_aa ,_ebb );_bd ,_cga ,_abfg ,_ :=_fad .RGBA ();_ddc :=_bd ==_a .MaxUint16 &&_cga ==_a .MaxUint16 &&_abfg ==_a .MaxUint16 ; +for _ebb =_ceg .Max .Y -1;_ebb >=_ceg .Min .Y ;_ebb --{var _cgae bool ;for _aa =_ceg .Min .X ;_aa < _ceg .Max .X ;_aa ++{_adc =_badd .At (_aa ,_ebb );_beef ,_ca ,_gab ,_ =_adc .RGBA ();if (_ddc &&!(_beef ==_bd &&_ca ==_cga &&_abfg ==_gab ))||(!_ddc &&(_a .Abs (float64 (_beef )-float64 (_bd ))/float64 (_a .MaxUint16 )> 0.03||_a .Abs (float64 (_ca )-float64 (_cga ))/float64 (_a .MaxUint16 )> 0.03||_a .Abs (float64 (_gab )-float64 (_abfg ))/float64 (_a .MaxUint16 )> 0.03)){_cgae =true ; +break ;};};if _cgae {break ;};_db =_ebb ;};return float64 (_ceg .Max .Y -_db )/float64 (_ceg .Max .Y );};func _fg ()error {_cg :=_ee .GetLicenseKey ();if _cg ==nil {return _bg .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); +};if !_cg .IsLicensed (){return _bg .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};return nil ;};func (_cfb *Document )validate ()error {if _bgd ==nil {return ErrNoClient ; +};if _cfb ._dde ==nil {return ErrContentNotDefined ;};return nil ;};func (_dcc *Document )getTimeoutDuration ()_ce .Duration {if _dcc ._bf !=nil {return *_dcc ._bf ;};return 0;}; + +// Connect creates UniHTML HTTP Client and tries to establish connection with the server. +func Connect (path string )error {if _cb :=_fg ();_cb !=nil {return _cb ;};_eb ,_dc :=_cc .ParseOptions (path );if _dc !=nil {return _dc ;};_bgd =_cc .New (_eb );_ge ,_fc :=_g .WithTimeout (_g .Background (),_ce .Second *5);defer _fc ();if _dg :=_bgd .HealthCheck (_ge ); +_dg !=nil {return _dg ;};return nil ;}; + +// SetLandscapeOrientation sets document landscape page orientation. +func (_dgc *Document )SetLandscapeOrientation (){_dgc ._bed =_ag .Landscape };var ErrNoClient =_bg .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); + +// SetPageHeight sets the page height for given document. +func (_dcg *Document )SetPageHeight (pageHeight _ag .Length )error {_dcg ._dcb =pageHeight ;_dcg ._ebf =_gc .PositionAbsolute ;return nil ;};var _ _gc .Drawable =(*Document )(nil ); + +// SetMargins sets the Document Margins. +func (_ed *Document )SetMargins (left ,right ,top ,bottom float64 ){_ed ._gaa .Left =_ag .Point (left );_ed ._gaa .Right =_ag .Point (right );_ed ._gaa .Top =_ag .Point (top );_ed ._gaa .Bottom =_ag .Point (bottom );_ed ._ebf =_gc .PositionAbsolute ;}; +func (_cgg *Document )extract (_dge _g .Context ,_cde ,_dgea _ag .Length ,_cec margins )([]*_ga .PdfPage ,error ){_ebc :=_cc .BuildHTMLQuery ().SetContent (_cgg ._dde ).PageSize (_cgg ._ace ).PaperWidth (_cde ).PaperHeight (_dgea ).Orientation (_cgg ._bed ).MarginLeft (_cec .Left ).MarginRight (_cec .Right ).MarginTop (_cec .Top ).MarginBottom (_cec .Bottom ).TimeoutDuration (_cgg .getTimeoutDuration ()).WaitTime (_cgg ._ae ); +for _ ,_gee :=range _cgg ._gf {_ebc .WaitReady (_gee .Selector ,_gee .By );};for _ ,_bbb :=range _cgg ._bag {_ebc .WaitVisible (_bbb .Selector ,_bbb .By );};_fgec ,_efc :=_ebc .Query ();if _efc !=nil {return nil ,_efc ;};var _df _g .CancelFunc ;if _cgg ._bf !=nil {_dge ,_df =_g .WithTimeout (_dge ,*_cgg ._bf ); +}else {_dge ,_df =_g .WithTimeout (_dge ,_ce .Second *15);};defer _df ();_cdgg ,_efc :=_bgd .ConvertHTML (_dge ,_fgec );if _efc !=nil {return nil ,_efc ;};_gbd :=_gg .NewReader (_cdgg .Data );_abc ,_efc :=_ga .NewPdfReader (_gbd );if _efc !=nil {return nil ,_efc ; +};return _abc .PageList ,nil ;}; + +// Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. +type Document struct{_dde _bad .Content ;_gaa margins ;_ebf _gc .Positioning ;_be ,_bee float64 ;_ace _ag .PageSize ;_dda ,_dcb _ag .Length ;_bed _ag .Orientation ;_cd bool ;_ae _ce .Duration ;_gf []_cc .BySelector ;_bag []_cc .BySelector ;_bf *_ce .Duration ; +}; + +// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. +func ConnectOptions (o Options )error {_bgd =_cc .New (_cc .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_da ,_ef :=_g .WithTimeout (_g .Background (),_ce .Second *5);defer _ef ();if _dd :=_bgd .HealthCheck (_da );_dd !=nil {return _dd ; +};return nil ;}; + +// NewDocumentFromString creates a new Document from the provided HTML string. +func NewDocumentFromString (html string )(*Document ,error ){_acf ,_ea :=_bad .NewStringContent (html );if _ea !=nil {return nil ,_ea ;};_bb :=&Document {};_bb ._dde =_acf ;return _bb ,nil ;}; // SetPos sets the absolute position. Changes object positioning to absolute. -func (_aeb *Document )SetPos (x ,y float64 ){_aeb ._daf =_bg .PositionAbsolute ;_aeb ._fa =x ;_aeb ._eb =y ;}; +func (_gced *Document )SetPos (x ,y float64 ){_gced ._ebf =_gc .PositionAbsolute ;_gced ._be =x ;_gced ._bee =y ;}; -// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. -func (_cg *Document )TrimLastPageContent (){_cg ._bd =true };type margins struct{Left ,Right ,Bottom ,Top _ag .Length ;};func (_ede *Document )getMargins ()margins {_ef :=_ede ._gc ;if _ede ._daf .IsRelative (){_ef .Top =_ag .Millimeter (1);_ef .Left =_ag .Millimeter (1); -_ef .Bottom =_ag .Millimeter (1);_ef .Right =_ag .Millimeter (1);return _ef ;};if _ef .Top ==nil {_ef .Top =_ag .Millimeter (10);};if _ef .Bottom ==nil {_ef .Bottom =_ag .Millimeter (10);};if _ef .Left ==nil {_ef .Left =_ag .Millimeter (10);};if _ef .Right ==nil {_ef .Right =_ag .Millimeter (10); -};return _ef ;}; +// WaitTime sets the waiting time before the webpage is rendered to PDF. +func (_fadd *Document )WaitTime (duration _ce .Duration ){_fadd ._ae =duration }; + +// GeneratePageBlocks implements creator.Drawable interface. +func (_afb *Document )GeneratePageBlocks (ctx _gc .DrawContext )([]*_gc .Block ,_gc .DrawContext ,error ){if _badg :=_afb .validate ();_badg !=nil {return nil ,ctx ,_badg ;};var _gb []*_gc .Block ;_ec :=_afb .getMargins ();_fgc ,_ade :=_afb ._dda ,_afb ._dcb ; +if _afb ._ebf .IsRelative (){_fgc ,_ade =_ag .Point (ctx .Width ),_ag .Point (ctx .Height );ctx .X -=float64 (_ec .Left .Points ());}else {ctx .X =_afb ._be ;ctx .Y =_afb ._bee ;};_cdf ,_ebfe :=_afb .extract (_g .Background (),_fgc ,_ade ,_ec );if _ebfe !=nil {return nil ,_gc .DrawContext {},_ebfe ; +};for _bff ,_cbc :=range _cdf {_ggg ,_ab :=_gc .NewBlockFromPage (_cbc );if _ab !=nil {return nil ,_gc .DrawContext {},_ab ;};var _agg float64 ;if _afb ._cd &&_bff ==len (_cdf )-1{_beg :=_ad .NewImageDevice ();_fca ,_acec :=_beg .Render (_cbc );if _acec !=nil {return nil ,_gc .DrawContext {},_acec ; +};_cdd ,_acec :=_cbc .GetMediaBox ();if _acec !=nil {return nil ,_gc .DrawContext {},_acec ;};_gd :=_ce .Now ();_ccc :=_de (_fca );_agg =_cdd .Height ()*_ccc ;_d .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_ce .Since (_gd )); +if _afb ._gaa .Bottom !=nil {_agg -=float64 (_afb ._gaa .Bottom .Points ());};if _agg < 0{_agg =0;};_d .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_agg ); +};_cfc ,_gggc ,_ab :=_ggg .GeneratePageBlocks (ctx );if _ab !=nil {return nil ,_gc .DrawContext {},_ab ;};ctx =_gggc ;ctx .Y -=_agg ;if _bff !=len (_cdf )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; +ctx .Page ++;};_gb =append (_gb ,_cfc ...);};return _gb ,ctx ,nil ;}; + +// GetContent returns the content of the document. +func (_afg *Document )GetContent ()_bad .Content {return _afg ._dde };var _bgd *_cc .Client ; // Options are the HTML Client options used for establishing the connection. type Options struct{ @@ -73,56 +113,19 @@ Port int ; Secure bool ; // Prefix is an option setting used when the server is working with the URI prefix. Default Value: ''. -Prefix string ;}; - -// SetTimeoutDuration sets the timeout duration -// the default timeout is 15 seconds. -func (_gcc *Document )SetTimeoutDuration (duration _fg .Duration ){_gcc ._fae =&duration };var ErrContentNotDefined =_ea .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); - - -// WaitReady waits for the provided selector to be ready. -// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_bdd *Document )WaitReady (sel string ,by ..._ge .ByType ){_faef :=_ge .BySearch ;if len (by )> 0{_faef =by [0];};_bdd ._ebc =append (_bdd ._ebc ,_eg .BySelector {Selector :sel ,By :_faef });}; +Prefix string ;};func (_deg *Document )getMargins ()margins {_gea :=_deg ._gaa ;if _deg ._ebf .IsRelative (){_gea .Top =_ag .Millimeter (1);_gea .Left =_ag .Millimeter (1);_gea .Bottom =_ag .Millimeter (1);_gea .Right =_ag .Millimeter (1);return _gea ; +};if _gea .Top ==nil {_gea .Top =_ag .Millimeter (10);};if _gea .Bottom ==nil {_gea .Bottom =_ag .Millimeter (10);};if _gea .Left ==nil {_gea .Left =_ag .Millimeter (10);};if _gea .Right ==nil {_gea .Right =_ag .Millimeter (10);};return _gea ;}; // NewDocument creates new HTML Document used as an input for the creator.Drawable. -func NewDocument (path string )(*Document ,error ){_bb :=&Document {};_bgc ,_eabf :=_a .Parse (path );if _eabf !=nil {return nil ,_eabf ;};switch _bgc .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_bb ._egf ,_eabf =_b .NewWebURL (path ); -if _eabf !=nil {return nil ,_eabf ;};return _bb ,nil ;};_ae ,_eabf :=_de .Stat (path );if _eabf !=nil {return nil ,_eabf ;};if !_ae .IsDir (){_bb ._egf ,_eabf =_b .NewHTMLFile (path );}else {_bb ._egf ,_eabf =_b .NewZipDirectory (path );};if _eabf !=nil {return nil ,_eabf ; -};return _bb ,nil ;}; - -// SetLandscapeOrientation sets document landscape page orientation. -func (_eaf *Document )SetLandscapeOrientation (){_eaf ._gg =_ag .Landscape }; - -// Connect creates UniHTML HTTP Client and tries to establish connection with the server. -func Connect (path string )error {if _da :=_aad ();_da !=nil {return _da ;};_ad ,_aa :=_eg .ParseOptions (path );if _aa !=nil {return _aa ;};_cee =_eg .New (_ad );_ceg ,_fc :=_e .WithTimeout (_e .Background (),_fg .Second *5);defer _fc ();if _ba :=_cee .HealthCheck (_ceg ); -_ba !=nil {return _ba ;};return nil ;}; - -// WriteToFile writes the document to a file defined by the output path. -func (_dbd *Document )WriteToFile (outputPath string )error {if _adf :=_dbd .validate ();_adf !=nil {return _adf ;};_fcf :=_fg .Second *20+_dbd ._egfb ;_ecd ,_fcfd :=_e .WithTimeout (_e .Background (),_fcf );defer _fcfd ();_fb ,_faa :=_dbd .extract (_ecd ,_dbd ._db ,_dbd ._gca ,_dbd .getMargins ()); -if _faa !=nil {return _faa ;};_ege :=_bg .New ();for _ ,_dbg :=range _fb {if _faa =_ege .AddPage (_dbg );_faa !=nil {return _faa ;};};return _ege .WriteToFile (outputPath );};var ErrNoClient =_ea .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); - - -// Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. -type Document struct{_egf _b .Content ;_gc margins ;_daf _bg .Positioning ;_fa ,_eb float64 ;_geb _ag .PageSize ;_db ,_gca _ag .Length ;_gg _ag .Orientation ;_bd bool ;_egfb _fg .Duration ;_ebc []_eg .BySelector ;_dc []_eg .BySelector ;_fae *_fg .Duration ; -}; +func NewDocument (path string )(*Document ,error ){_efe :=&Document {};_bfg ,_acb :=_f .Parse (path );if _acb !=nil {return nil ,_acb ;};switch _bfg .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_efe ._dde ,_acb =_bad .NewWebURL (path ); +if _acb !=nil {return nil ,_acb ;};return _efe ,nil ;};_ebd ,_acb :=_b .Stat (path );if _acb !=nil {return nil ,_acb ;};if !_ebd .IsDir (){_efe ._dde ,_acb =_bad .NewHTMLFile (path );}else {_efe ._dde ,_acb =_bad .NewZipDirectory (path );};if _acb !=nil {return nil ,_acb ; +};return _efe ,nil ;}; // SetPageWidth sets the page width for given document. -func (_cbf *Document )SetPageWidth (pageWidth _ag .Length )error {_cbf ._db =pageWidth ;_cbf ._daf =_bg .PositionAbsolute ;return nil ;}; - -// SetMarginRight sets the left margin. -func (_fcb *Document )SetMarginRight (margin _ag .Length ){_fcb ._gc .Right =margin }; +func (_ege *Document )SetPageWidth (pageWidth _ag .Length )error {_ege ._dda =pageWidth ;_ege ._ebf =_gc .PositionAbsolute ;return nil ;}; -// SetPageSize sets the page default size. -func (_gcgg *Document )SetPageSize (pageSize _ag .PageSize )error {if !pageSize .IsAPageSize (){return _ea .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); -};_gcgg ._geb =pageSize ;_gcgg ._daf =_bg .PositionAbsolute ;return nil ;}; +// SetMarginTop sets the left margin. +func (_cef *Document )SetMarginTop (margin _ag .Length ){_cef ._gaa .Top =margin }; // GetPdfPages is a function that converts provided input content and -func (_fgb *Document )GetPdfPages (ctx _e .Context )([]*_egd .PdfPage ,error ){if _eac :=_fgb .validate ();_eac !=nil {return nil ,_eac ;};return _fgb .extract (ctx ,_fgb ._db ,_fgb ._gca ,_fgb .getMargins ());}; - -// SetPageHeight sets the page height for given document. -func (_eda *Document )SetPageHeight (pageHeight _ag .Length )error {_eda ._gca =pageHeight ;_eda ._daf =_bg .PositionAbsolute ;return nil ;};var _ _bg .Drawable =(*Document )(nil );var _cee *_eg .Client ; - -// SetMarginLeft sets the left margin. -func (_gga *Document )SetMarginLeft (margin _ag .Length ){_gga ._gc .Left =margin }; - -// SetMarginBottom sets the left margin. -func (_gcb *Document )SetMarginBottom (margin _ag .Length ){_gcb ._gc .Bottom =margin }; \ No newline at end of file +func (_ddd *Document )GetPdfPages (ctx _g .Context )([]*_ga .PdfPage ,error ){if _cf :=_ddd .validate ();_cf !=nil {return nil ,_cf ;};return _ddd .extract (ctx ,_ddd ._dda ,_ddd ._dcb ,_ddd .getMargins ());}; \ No newline at end of file From 3757adb7e844809ee3d187263b5140d793e5719c Mon Sep 17 00:00:00 2001 From: UniDoc Build Date: Sun, 22 Dec 2024 09:15:36 +0000 Subject: [PATCH 5/9] prepare release --- cli/cmd/cmd.go | 71 ++++++----- cli/main.go | 2 +- client/client.go | 272 +++++++++++++++++++++---------------------- common/common.go | 6 +- content/content.go | 79 +++++++------ go.mod | 21 ++-- go.sum | 39 ++++--- selector/selector.go | 7 +- sizes/sizes.go | 253 ++++++++++++++++++++-------------------- unihtml.go | 178 ++++++++++++++-------------- 10 files changed, 467 insertions(+), 461 deletions(-) diff --git a/cli/cmd/cmd.go b/cli/cmd/cmd.go index 638e114..69a2e56 100644 --- a/cli/cmd/cmd.go +++ b/cli/cmd/cmd.go @@ -9,55 +9,54 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package cmd ;import (_a "context";_c "fmt";_f "github.com/mitchellh/go-homedir";_ca "github.com/spf13/cobra";_cg "github.com/spf13/viper";_e "github.com/unidoc/unihtml/client";_cd "github.com/unidoc/unihtml/content";_bb "github.com/unidoc/unihtml/sizes"; -_bc "github.com/unidoc/unipdf/v3/common";_db "os";_g "path/filepath";_b "time";);func _ae (){_ba :=_bc .LogLevelInfo ;if _dfc {_ba =_bc .LogLevelDebug ;};if _dgd {_ba =_bc .LogLevelTrace ;};_bc .Log =_bc .NewConsoleLogger (_ba );};var _ebf =&_ca .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; -var _da =&_ca .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_gf ,Args :_ca .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; -func _gf (cmd *_ca .Command ,_ff []string ){_ec :=_b .Now ();if _bbg :=_cg .BindPFlags (cmd .Flags ());_bbg !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_bbg );_db .Exit (1);};if _ed :=_cg .Unmarshal (&_df );_ed !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ed ); -_db .Exit (1);};_ae ();_ga ,_dg :=_db .Stat (_ff [0]);if _dg !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dg );_db .Exit (1);};if !_ga .IsDir (){if _g .Ext (_ga .Name ())!="\u002e\u0068\u0074m\u006c"{_c .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_ff [0]); -_db .Exit (1);};};_fb ,_dg :=_db .OpenFile (_ff [1],_db .O_CREATE |_db .O_WRONLY |_db .O_TRUNC ,0700);if _dg !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dg );_db .Exit (1);};defer _fb .Close ();_bg :=_e .New (_e .Options {HTTPS :_df .Https ,Hostname :_df .Host ,Port :_df .Port ,Prefix :_df .Prefix }); -_cde ,_eeb :=_a .WithTimeout (_a .Background (),_b .Second *10);defer _eeb ();_dgc :=_b .Now ();var _eb _cd .Content ;if _ga .IsDir (){_eb ,_dg =_cd .NewZipDirectory (_ff [0]);}else {_eb ,_dg =_cd .NewHTMLFile (_ff [0]);};if _dg !=nil {_c .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_dg ); -_db .Exit (1);};_ad ,_dg :=_e .BuildHTMLQuery ().PaperWidth (_ag .PaperWidth .Length ).PaperHeight (_ag .PaperHeight .Length ).PageSize (_ag .PageSize ).MarginTop (_ag .MarginTop .Length ).MarginBottom (_ag .MarginBottom .Length ).MarginLeft (_ag .MarginLeft .Length ).MarginRight (_ag .MarginRight .Length ).Orientation (_ag .Orientation ).SetContent (_eb ).Query (); -if _dg !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dg );_db .Exit (1);};_dc ,_dg :=_bg .ConvertHTML (_cde ,_ad );if _dg !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dg );_db .Exit (1);};_bc .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_b .Since (_dgc )); -_dgc =_b .Now ();_ ,_dg =_fb .Write (_dc .Data );if _dg !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dg );_db .Exit (1);};_bc .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_b .Since (_dgc )); -_c .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_b .Since (_ec ));};func init (){_ebf .AddCommand (_da );_da .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072"); -_da .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); -_da .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); -_da .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); -_da .Flags ().Var (&_ag .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_da .Flags ().Var (&_ag .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); -_da .Flags ().Var (&_ag .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_da .Flags ().Var (&_ag .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); -_da .Flags ().Var (&_ag .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_da .Flags ().Var (&_ag .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); -_da .Flags ().Var (&_ag .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_da .Flags ().Var (&_ag .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); -};func _fbf (){if _bcc !=""{_cg .SetConfigFile (_bcc );}else {_cdac ,_aa :=_f .Dir ();if _aa !=nil {_c .Println (_aa );_db .Exit (1);};_cg .AddConfigPath (_cdac );_cg .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063"); -};_cg .AutomaticEnv ();if _af :=_cg .ReadInConfig ();_af ==nil {_c .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_cg .ConfigFileUsed ());};};var (_dfc ,_dgd bool ;);type generateConfig struct{Port int `mapstructure:"port"`; -Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;}; - -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. -func Execute (){if _ebg :=_ebf .Execute ();_ebg !=nil {_c .Println (_ebg );_db .Exit (1);};};var (_df =generateConfig {};_ag =parametersConfig {PaperWidth :_bb .LengthFlag {Length :_bb .Inch (8.5).Millimeters ()},PaperHeight :_bb .LengthFlag {Length :_bb .Inch (11).Millimeters ()},Orientation :_bb .Portrait ,MarginTop :_bb .LengthFlag {Length :_bb .Millimeter (10)},MarginBottom :_bb .LengthFlag {Length :_bb .Millimeter (10)},MarginLeft :_bb .LengthFlag {Length :_bb .Millimeter (10)},MarginRight :_bb .LengthFlag {Length :_bb .Millimeter (10)}}; -);func init (){_ca .OnInitialize (_fbf );_ebf .PersistentFlags ().BoolVarP (&_dfc ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065");_ebf .PersistentFlags ().BoolVarP (&_dgd ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); -_ebf .PersistentFlags ().StringVar (&_bcc ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); -_ebf .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};type parametersConfig struct{ +package cmd ;import (_b "context";_d "fmt";_ge "github.com/mitchellh/go-homedir";_ff "github.com/spf13/cobra";_da "github.com/spf13/viper";_eg "github.com/unidoc/unihtml/client";_ec "github.com/unidoc/unihtml/content";_egf "github.com/unidoc/unihtml/sizes"; +_a "github.com/unidoc/unipdf/v3/common";_c "os";_g "path/filepath";_f "time";);type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};type parametersConfig struct{ // PaperWidth sets the width of the paper. -PaperWidth _bb .LengthFlag `mapstructure:"paper-width"`; +PaperWidth _egf .LengthFlag `mapstructure:"paper-width"`; // PaperHeight is the height of the output paper. -PaperHeight _bb .LengthFlag `mapstructure:"paper-height"`; +PaperHeight _egf .LengthFlag `mapstructure:"paper-height"`; // PageSize is the page size string. -PageSize _bb .PageSize `mapstructure:"page-size"`; +PageSize _egf .PageSize `mapstructure:"page-size"`; // Orientation defines if the output should be in a landscape format. -Orientation _bb .Orientation `mapstructure:"orientation"`; +Orientation _egf .Orientation `mapstructure:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _bb .LengthFlag `mapstructure:"margin-top"`; +MarginTop _egf .LengthFlag `mapstructure:"margin-top"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _bb .LengthFlag `mapstructure:"margin-bottom"`; +MarginBottom _egf .LengthFlag `mapstructure:"margin-bottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _bb .LengthFlag `mapstructure:"margin-left"`; +MarginLeft _egf .LengthFlag `mapstructure:"margin-left"`; // MarginRight sets up the Right Margin for the output. -MarginRight _bb .LengthFlag `mapstructure:"margin-right"`;};var _bcc string ; \ No newline at end of file +MarginRight _egf .LengthFlag `mapstructure:"margin-right"`;};func _ae (){_ac :=_a .LogLevelInfo ;if _ab {_ac =_a .LogLevelDebug ;};if _bc {_ac =_a .LogLevelTrace ;};_a .Log =_a .NewConsoleLogger (_ac );};var _dg =&_ff .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_cd ,Args :_ff .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; +func init (){_ba .AddCommand (_dg );_dg .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072");_dg .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); +_dg .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); +_dg .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); +_dg .Flags ().Var (&_gd .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_dg .Flags ().Var (&_gd .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); +_dg .Flags ().Var (&_gd .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_dg .Flags ().Var (&_gd .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); +_dg .Flags ().Var (&_gd .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_dg .Flags ().Var (&_gd .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); +_dg .Flags ().Var (&_gd .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_dg .Flags ().Var (&_gd .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); +};func _cd (cmd *_ff .Command ,_ce []string ){_bd :=_f .Now ();if _fb :=_da .BindPFlags (cmd .Flags ());_fb !=nil {_d .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_fb );_c .Exit (1);};if _dc :=_da .Unmarshal (&_gf );_dc !=nil {_d .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dc ); +_c .Exit (1);};_ae ();_ca ,_cdg :=_c .Stat (_ce [0]);if _cdg !=nil {_d .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_cdg );_c .Exit (1);};if !_ca .IsDir (){if _g .Ext (_ca .Name ())!="\u002e\u0068\u0074m\u006c"{_d .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_ce [0]); +_c .Exit (1);};};_cad ,_cdg :=_c .OpenFile (_ce [1],_c .O_CREATE |_c .O_WRONLY |_c .O_TRUNC ,0700);if _cdg !=nil {_d .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_cdg );_c .Exit (1);};defer _cad .Close ();_ea :=_eg .New (_eg .Options {HTTPS :_gf .Https ,Hostname :_gf .Host ,Port :_gf .Port ,Prefix :_gf .Prefix }); +_bb ,_af :=_b .WithTimeout (_b .Background (),_f .Second *10);defer _af ();_gb :=_f .Now ();var _gbd _ec .Content ;if _ca .IsDir (){_gbd ,_cdg =_ec .NewZipDirectory (_ce [0]);}else {_gbd ,_cdg =_ec .NewHTMLFile (_ce [0]);};if _cdg !=nil {_d .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_cdg ); +_c .Exit (1);};_db ,_cdg :=_eg .BuildHTMLQuery ().PaperWidth (_gd .PaperWidth .Length ).PaperHeight (_gd .PaperHeight .Length ).PageSize (_gd .PageSize ).MarginTop (_gd .MarginTop .Length ).MarginBottom (_gd .MarginBottom .Length ).MarginLeft (_gd .MarginLeft .Length ).MarginRight (_gd .MarginRight .Length ).Orientation (_gd .Orientation ).SetContent (_gbd ).Query (); +if _cdg !=nil {_d .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_cdg );_c .Exit (1);};_be ,_cdg :=_ea .ConvertHTML (_bb ,_db );if _cdg !=nil {_d .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_cdg );_c .Exit (1);};_a .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_f .Since (_gb )); +_gb =_f .Now ();_ ,_cdg =_cad .Write (_be .Data );if _cdg !=nil {_d .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_cdg );_c .Exit (1);};_a .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_f .Since (_gb )); +_d .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_f .Since (_bd ));};var (_gf =generateConfig {};_gd =parametersConfig {PaperWidth :_egf .LengthFlag {Length :_egf .Inch (8.5).Millimeters ()},PaperHeight :_egf .LengthFlag {Length :_egf .Inch (11).Millimeters ()},Orientation :_egf .Portrait ,MarginTop :_egf .LengthFlag {Length :_egf .Millimeter (10)},MarginBottom :_egf .LengthFlag {Length :_egf .Millimeter (10)},MarginLeft :_egf .LengthFlag {Length :_egf .Millimeter (10)},MarginRight :_egf .LengthFlag {Length :_egf .Millimeter (10)}}; +);var (_ab ,_bc bool ;); + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute (){if _bde :=_ba .Execute ();_bde !=nil {_d .Println (_bde );_c .Exit (1);};};var _cb string ;func init (){_ff .OnInitialize (_gg );_ba .PersistentFlags ().BoolVarP (&_ab ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065"); +_ba .PersistentFlags ().BoolVarP (&_bc ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); +_ba .PersistentFlags ().StringVar (&_cb ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); +_ba .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};func _gg (){if _cb !=""{_da .SetConfigFile (_cb ); +}else {_aa ,_ad :=_ge .Dir ();if _ad !=nil {_d .Println (_ad );_c .Exit (1);};_da .AddConfigPath (_aa );_da .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063");};_da .AutomaticEnv ();if _eb :=_da .ReadInConfig ();_eb ==nil {_d .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_da .ConfigFileUsed ()); +};};var _ba =&_ff .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; diff --git a/cli/main.go b/cli/main.go index f0b00cc..c33ee30 100644 --- a/cli/main.go +++ b/cli/main.go @@ -9,4 +9,4 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package main ;import _g "github.com/unidoc/unihtml/cli/cmd";func main (){_g .Execute ()}; \ No newline at end of file +package main ;import _e "github.com/unidoc/unihtml/cli/cmd";func main (){_e .Execute ()}; \ No newline at end of file diff --git a/client/client.go b/client/client.go index 03eee18..4223495 100644 --- a/client/client.go +++ b/client/client.go @@ -11,202 +11,202 @@ // Package client contains HTML Converter HTTP Client. The Client implements htmlcreator.HTMLConverter interface // for the UniPDF module and can be used as a plugin for the UniPDF creator.Creator. -package client ;import (_aa "bytes";_de "compress/flate";_a "compress/gzip";_df "context";_c "encoding/json";_g "errors";_ac "fmt";_fa "github.com/unidoc/unihtml/content";_dbe "github.com/unidoc/unihtml/selector";_b "github.com/unidoc/unihtml/sizes";_da "github.com/unidoc/unipdf/v3/common"; -_e "io/ioutil";_af "net";_dee "net/http";_db "net/url";_eb "strconv";_ca "strings";_f "time";);type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`;Method string `json:"method"`; -ExpiresAt int64 `json:"expiresAt"`;TimeoutDuration int64 `json:"timeoutDuration,omitempty"`;PageParameters ;RenderParameters ;}; +package client ;import (_db "bytes";_dac "compress/flate";_de "compress/gzip";_f "context";_da "encoding/json";_fe "errors";_dbc "fmt";_cd "github.com/unidoc/unihtml/content";_ga "github.com/unidoc/unihtml/selector";_gg "github.com/unidoc/unihtml/sizes"; +_aa "github.com/unidoc/unipdf/v3/common";_d "io";_df "net";_ab "net/http";_af "net/url";_g "strconv";_a "strings";_c "time";); -// WithPrefix sets the client prefix. -func WithPrefix (prefix string )Option {return func (_fae *Options ){_fae .Prefix =prefix }}; - -// PaperWidth sets up the PaperWidth (in cm) parameter for the query. -func (_gce *QueryBuilder )PaperWidth (paperWidth _b .Length )*QueryBuilder {_gce ._agg .PageParameters .PaperWidth =paperWidth ;return _gce ;}; +// ParseOptions parses options for the Client. +func ParseOptions (connectPath string )(Options ,error ){if !_a .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_aag ,_b :=_af .Parse (connectPath );if _b !=nil {return Options {},_dbc .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); +};var _fc int ;if _aag .Port ()!=""{_fc ,_b =_g .Atoi (_aag .Port ());if _b !=nil {return Options {},_dbc .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_b );}; +};return Options {Hostname :_aag .Hostname (),Port :_fc ,HTTPS :_aag .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_aag .Path },nil ;}; -// ConvertHTML converts provided Query input into PDF file data. -// Implements creator.HTMLConverter interface. -func (_ag *Client )ConvertHTML (ctx _df .Context ,q *Query )(*PDFResponse ,error ){if _gg :=q .Validate ();_gg !=nil {return nil ,_gg ;};_gde ,_eg :=_ag .getGenerateRequest (ctx ,q );if _eg !=nil {return nil ,_eg ;};_da .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_gde .Method ,_gde .URL .Hostname (),_gde .URL .Path ,_gde .Header ,_gde .URL .Query ()); -_cd :=*_ag .Client ;if q .TimeoutDuration !=0{_cd .Timeout =q .TimeoutDuration ;};_cf ,_eg :=_cd .Do (_gde );if _eg !=nil {return nil ,_eg ;};var _gc error ;switch _cf .StatusCode {case _dee .StatusNotFound :_gc =ErrNotFound ;case _dee .StatusBadRequest :_gc =ErrBadRequest ; -case _dee .StatusNotImplemented :_gc =ErrNotImplemented ;case _dee .StatusUnauthorized :_gc =ErrUnauthorized ;case _dee .StatusRequestTimeout :_gc =ErrTimedOut ;case _dee .StatusCreated :default:_gc =ErrInternalError ;};_ee :=_cf .Body ;switch _cf .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_ee ,_eg =_a .NewReader (_cf .Body ); -if _eg !=nil {return nil ,_eg ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_ee =_de .NewReader (_cf .Body );case "":default:return nil ,_ac .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_cf .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); -};_bc ,_eg :=_e .ReadAll (_ee );if _eg !=nil &&_gc ==nil {return nil ,_ac .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_eg );};_da .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_cf .StatusCode ,_gde .Method ,_gde .URL .Host ,_gde .URL .Path ); -if _gc !=nil {return nil ,_ac .Errorf ("\u0025\u0073\u0020%\u0077",string (_bc ),_gc );};_dfd :=_cf .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_da .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_dfd ); -return &PDFResponse {ID :_dfd ,Data :_bc },nil ;}; +// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. +type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;TimeoutDuration _c .Duration ;}; -// Portrait sets up the portrait page orientation. -func (_gcd *QueryBuilder )Portrait ()*QueryBuilder {_gcd ._agg .PageParameters .Orientation =_b .Portrait ;return _gcd ;}; +// Addr gets the HTTP address URI used by the http.Client. +func (_dacf *Options )Addr ()string {_cbc :=_a .Builder {};_cbc .WriteString ("\u0068\u0074\u0074\u0070");if _dacf .HTTPS {_cbc .WriteRune ('s');};_cbc .WriteString ("\u003a\u002f\u002f");_cbc .WriteString (_dacf .Hostname );_cbc .WriteRune (':');_cbc .WriteString (_g .Itoa (_dacf .Port )); +if _dacf .Prefix !=""{_cbc .WriteString (_dacf .Prefix );};return _cbc .String ();}; -// WithHostname sets the Hostname option for the client options. -func WithHostname (option string )Option {return func (_ec *Options ){_ec .Hostname =option }}; +// BuildHTMLQuery creates a Query builder that is supposed to create valid +func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; -// Validate checks if provided Query is valid. -func (_ddd *Query )Validate ()error {switch _ddd .Method {case "\u0077\u0065\u0062":if _ddd .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_ddd .Content )==0{return ErrMissingData ;};if _ddd .ContentType ==""{return ErrContentType ; -};default:return _ac .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_ddd .Method );};if _bg :=_ddd .PageParameters .Validate (); -_bg !=nil {return _bg ;};if _gba :=_ddd .RenderParameters .Validate ();_gba !=nil {return _gba ;};return nil ;}; +// MarginLeft sets up the MarginLeft parameter for the query. +func (_cdd *QueryBuilder )MarginLeft (marginLeft _gg .Length )*QueryBuilder {_cdd ._bade .PageParameters .MarginLeft =marginLeft ;return _cdd ;}; -// Option is a function that changes client options. -type Option func (_dd *Options ); +// BySelector is a structure that defines a selector with it's query 'by' type. +type BySelector struct{Selector string `json:"selector"`;By _ga .ByType `json:"by"`;}; -// Validate checks the validity of the RenderParameters. -func (_acg *RenderParameters )Validate ()error {if _acg .WaitTime > _f .Minute *3{return _g .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); -};for _ ,_gb :=range _acg .WaitReady {if _fbb :=_gb .Validate ();_fbb !=nil {return _ac .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_fbb ); -};};return nil ;};func (_cfc *Client )setQueryValues (_ffe *_dee .Request ,_ce *Query ){_caf :=_ffe .URL .Query ();_cc :=_ce .PageParameters ;if _cc .PageSize !=nil {_caf .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_cc .PageSize .String ());}; -if _cc .PaperHeight !=nil {_caf .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_cc .PaperHeight .String ());};if _cc .PaperWidth !=nil {_caf .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_cc .PaperWidth .String ()); -};if _cc .MarginTop !=nil {_caf .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_cc .MarginTop .String ());};if _cc .MarginBottom !=nil {_caf .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_cc .MarginBottom .String ()); -};if _cc .MarginRight !=nil {_caf .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_cc .MarginRight .String ());};if _cc .MarginLeft !=nil {_caf .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_cc .MarginLeft .String ()); -};if _cc .Orientation ==_b .Landscape {_caf .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_cc .Orientation .String ());};if _ce .RenderParameters .WaitTime !=0{_caf .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_eb .FormatInt (int64 (_ce .RenderParameters .WaitTime /_f .Millisecond ),10)); -};_ffe .URL .RawQuery =_caf .Encode ();}; +// WithDefaultTimeout sets the DefaultTimeout option for the client options. +func WithDefaultTimeout (option _c .Duration )Option {return func (_cbb *Options ){_cbb .DefaultTimeout =option };}; -// HealthCheck connects to the server and check the health status of the server. -func (_fg *Client )HealthCheck (ctx _df .Context )error {_ad :=_fg .Options .Addr ();_ad =_ac .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_ad );_fe ,_fb :=_dee .NewRequest ("\u0047\u0045\u0054",_ad ,nil );if _fb !=nil {return _fb ;};_fe =_fe .WithContext (ctx ); -_feb ,_fb :=_fg .Client .Do (_fe );if _fb !=nil {return _fb ;};switch _feb .StatusCode {case _dee .StatusOK :return nil ;case _dee .StatusNotFound :return ErrNotFound ;case _dee .StatusInternalServerError :return ErrInternalError ;case _dee .StatusBadGateway :return ErrBadGateway ; -default:return ErrNotImplemented ;};}; +// Option is a function that changes client options. +type Option func (_aad *Options );var (ErrNotFound =_fe .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_fe .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074");ErrNotImplemented =_fe .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064"); +ErrInternalError =_fe .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_fe .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079");ErrUnauthorized =_fe .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064"); +ErrTimedOut =_fe .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); -// ParseOptions parses options for the Client. -func ParseOptions (connectPath string )(Options ,error ){if !_ca .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_gd ,_ebd :=_db .Parse (connectPath );if _ebd !=nil {return Options {},_ac .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); -};var _bb int ;if _gd .Port ()!=""{_bb ,_ebd =_eb .Atoi (_gd .Port ());if _ebd !=nil {return Options {},_ac .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_ebd ); -};};return Options {Hostname :_gd .Hostname (),Port :_bb ,HTTPS :_gd .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_gd .Path },nil ;}; +// MarginBottom sets up the MarginBottom parameter for the query. +func (_ae *QueryBuilder )MarginBottom (marginBottom _gg .Length )*QueryBuilder {_ae ._bade .PageParameters .MarginBottom =marginBottom ;return _ae ;}; -// RenderParameters are the parameters related with the rendering. -type RenderParameters struct{WaitTime _f .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; +// WaitTime sets the minimum load time parameter for the page rendering. +func (_ggd *QueryBuilder )WaitTime (d _c .Duration )*QueryBuilder {_ggd ._bade .RenderParameters .WaitTime =d ;return _ggd ;}; -// SetContent sets custom data with it's content type. -func (_febbf *QueryBuilder )SetContent (content _fa .Content )*QueryBuilder {if _febbf ._fgb !=nil {return _febbf ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _febbf ._agg .ContentType !=""{_febbf ._fgb =ErrContentTypeDeclared ; -return _febbf ;};if content .ContentType ()==""{_febbf ._fgb =_ac .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _febbf ; -};_febbf ._agg .Content =content .Data ();_febbf ._agg .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _febbf ._agg .ContentType !=""{_febbf ._fgb =ErrContentTypeDeclared ;return _febbf ;};_febbf ._agg .URL =string (content .Data ()); -_febbf ._agg .ContentType =content .ContentType ();default:_febbf ._fgb =_ac .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ()); -return _febbf ;};_febbf ._agg .Method =content .Method ();return _febbf ;}; +// Portrait sets up the portrait page orientation. +func (_cbg *QueryBuilder )Portrait ()*QueryBuilder {_cbg ._bade .PageParameters .Orientation =_gg .Portrait ;return _cbg ;};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`; +Method string `json:"method"`;ExpiresAt int64 `json:"expiresAt"`;TimeoutDuration int64 `json:"timeoutDuration,omitempty"`;PageParameters ;RenderParameters ;}; -// MarginTop sets up the MarginTop parameter for the query. -func (_ea *QueryBuilder )MarginTop (marginTop _b .Length )*QueryBuilder {_ea ._agg .PageParameters .MarginTop =marginTop ;return _ea ;}; +// WithPrefix sets the client prefix. +func WithPrefix (prefix string )Option {return func (_ce *Options ){_ce .Prefix =prefix }}; -// BySelector is a structure that defines a selector with it's query 'by' type. -type BySelector struct{Selector string `json:"selector"`;By _dbe .ByType `json:"by"`;}; +// PDFResponse is the response used by the HTMLConverter. +type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; // QueryBuilder is the query that converts HTMLConverter defined data -type QueryBuilder struct{_agg Query ;_fgb error ;}; +type QueryBuilder struct{_bade Query ;_afb error ;}; // PageParameters are the query parameters used in the PDF generation. type PageParameters struct{ // PaperWidth sets the width of the paper. -PaperWidth _b .Length `schema:"paper-width" json:"paperWidth"`; +PaperWidth _gg .Length `schema:"paper-width" json:"paperWidth"`; // PaperHeight is the height of the output paper. -PaperHeight _b .Length `schema:"paper-height" json:"paperHeight"`; +PaperHeight _gg .Length `schema:"paper-height" json:"paperHeight"`; // PageSize is the page size string. -PageSize *_b .PageSize `schema:"page-size" json:"pageSize"`; +PageSize *_gg .PageSize `schema:"page-size" json:"pageSize"`; // Orientation defines if the output should be in a landscape format. -Orientation _b .Orientation `schema:"orientation" json:"orientation"`; +Orientation _gg .Orientation `schema:"orientation" json:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _b .Length `schema:"margin-top" json:"marginTop"`; +MarginTop _gg .Length `schema:"margin-top" json:"marginTop"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _b .Length `schema:"margin-bottom" json:"marginBottom"`; +MarginBottom _gg .Length `schema:"margin-bottom" json:"marginBottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _b .Length `schema:"margin-left" json:"marginLeft"`; +MarginLeft _gg .Length `schema:"margin-left" json:"marginLeft"`; // MarginRight sets up the Right Margin for the output. -MarginRight _b .Length `schema:"margin-right" json:"marginRight"`;}; +MarginRight _gg .Length `schema:"margin-right" json:"marginRight"`;}; -// Validate checks validity of the selector. -func (_ecg BySelector )Validate ()error {if _ecg .Selector ==""{return _g .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _ega :=_ecg .By .Validate ();_ega !=nil {return _ega ; -};return nil ;}; +// Client is a structure that is a HTTP client for the unihtml server. +type Client struct{Options Options ;Client *_ab .Client ;};func (_ffgf *Client )setQueryValues (_fae *_ab .Request ,_dbe *Query ){_ffb :=_fae .URL .Query ();_ggcf :=_dbe .PageParameters ;if _ggcf .PageSize !=nil {_ffb .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_ggcf .PageSize .String ()); +};if _ggcf .PaperHeight !=nil {_ffb .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_ggcf .PaperHeight .String ());};if _ggcf .PaperWidth !=nil {_ffb .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_ggcf .PaperWidth .String ()); +};if _ggcf .MarginTop !=nil {_ffb .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_ggcf .MarginTop .String ());};if _ggcf .MarginBottom !=nil {_ffb .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_ggcf .MarginBottom .String ()); +};if _ggcf .MarginRight !=nil {_ffb .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_ggcf .MarginRight .String ());};if _ggcf .MarginLeft !=nil {_ffb .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_ggcf .MarginLeft .String ()); +};if _ggcf .Orientation ==_gg .Landscape {_ffb .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_ggcf .Orientation .String ());};if _dbe .RenderParameters .WaitTime !=0{_ffb .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_g .FormatInt (int64 (_dbe .RenderParameters .WaitTime /_c .Millisecond ),10)); +};_fae .URL .RawQuery =_ffb .Encode ();}; -// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. -type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;TimeoutDuration _f .Duration ;}; +// SetContent sets custom data with it's content type. +func (_fg *QueryBuilder )SetContent (content _cd .Content )*QueryBuilder {if _fg ._afb !=nil {return _fg ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _fg ._bade .ContentType !=""{_fg ._afb =ErrContentTypeDeclared ; +return _fg ;};if content .ContentType ()==""{_fg ._afb =_dbc .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _fg ;}; +_fg ._bade .Content =content .Data ();_fg ._bade .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _fg ._bade .ContentType !=""{_fg ._afb =ErrContentTypeDeclared ;return _fg ;};_fg ._bade .URL =string (content .Data ());_fg ._bade .ContentType =content .ContentType (); +default:_fg ._afb =_dbc .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ());return _fg ;};_fg ._bade .Method =content .Method (); +return _fg ;}; -// WaitReady waits for the selector to get ready - 'loaded'. -func (_aae *QueryBuilder )WaitReady (selector string ,by _dbe .ByType )*QueryBuilder {_aae ._agg .RenderParameters .WaitReady =append (_aae ._agg .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _aae ;}; +// New creates new client with provided options. +func New (o Options )*Client {o .DefaultTimeout =_c .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _bc =&_ab .Transport {DialContext :(&_df .Dialer {Timeout :5*_c .Second }).DialContext ,TLSHandshakeTimeout :5*_c .Second }; +_aa .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_ab .Client {Transport :_bc ,Timeout :o .DefaultTimeout }};}; -// TimeoutDuration sets the server query duration timeout. -// Once the timeout is reached the server will return an error. -func (_eedb *QueryBuilder )TimeoutDuration (d _f .Duration )*QueryBuilder {_eedb ._agg .TimeoutDuration =d ;return _eedb ;}; +// WaitReady waits for the selector to get ready - 'loaded'. +func (_bf *QueryBuilder )WaitReady (selector string ,by _ga .ByType )*QueryBuilder {_bf ._bade .RenderParameters .WaitReady =append (_bf ._bade .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _bf ;}; -// PaperHeight sets up the PaperHeight (in cm) parameter for the query. -func (_aac *QueryBuilder )PaperHeight (paperHeight _b .Length )*QueryBuilder {_aac ._agg .PageParameters .PaperHeight =paperHeight ;return _aac ;}; +// DefaultPageParameters creates default parameters. +func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_gg .Portrait }}; -// MarginLeft sets up the MarginLeft parameter for the query. -func (_agf *QueryBuilder )MarginLeft (marginLeft _b .Length )*QueryBuilder {_agf ._agg .PageParameters .MarginLeft =marginLeft ;return _agf ;}; +// Validate checks if the parameters are valid. +func (_bab *PageParameters )Validate ()error {if _bab .PaperWidth !=nil {if _bab .PaperWidth .Millimeters ()< 0{return _fe .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); +};};if _bab .PaperHeight !=nil {if _bab .PaperHeight .Millimeters ()< 0{return _fe .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); +};};if _bab .MarginTop !=nil {if _bab .MarginTop .Millimeters ()< 0{return _fe .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _bab .MarginBottom !=nil {if _bab .MarginBottom .Millimeters ()< 0{return _fe .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); +};};if _bab .MarginLeft !=nil {if _bab .MarginLeft .Millimeters ()< 0{return _fe .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");}; +};if _bab .MarginRight !=nil {if _bab .MarginRight .Millimeters ()< 0{return _fe .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); +};};if _bab .PageSize !=nil &&!_bab .PageSize .IsAPageSize (){return _fe .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;};var (ErrMissingData =_fe .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061"); +ErrContentType =_fe .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065");ErrContentTypeDeclared =_fe .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064"); +); -// Options are the client options used by the HTTP client. -type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _f .Duration ;Prefix string ;}; +// PageSize sets up the PageSize parameter for the query. +func (_cga *QueryBuilder )PageSize (pageSize _gg .PageSize )*QueryBuilder {if pageSize !=_gg .Undefined {_cga ._bade .PageParameters .PageSize =&pageSize ;};return _cga ;}; -// Client is a structure that is a HTTP client for the unihtml server. -type Client struct{Options Options ;Client *_dee .Client ;}; +// PaperWidth sets up the PaperWidth (in cm) parameter for the query. +func (_aagg *QueryBuilder )PaperWidth (paperWidth _gg .Length )*QueryBuilder {_aagg ._bade .PageParameters .PaperWidth =paperWidth ;return _aagg ;}; -// WithHTTPS sets the TLS option for the client options. -func WithHTTPS (useHTTPS bool )Option {return func (_cee *Options ){_cee .HTTPS =useHTTPS }}; +// Validate checks if the QueryBuilder had no errors during composition and creation. +func (_eg *QueryBuilder )Validate ()error {if _eg ._afb !=nil {return _eg ._afb ;};return _eg ._bade .Validate ();}; -// WithPort sets the Port option for the client options. -func WithPort (option int )Option {return func (_cce *Options ){_cce .Port =option }}; +// Validate checks validity of the selector. +func (_dgd BySelector )Validate ()error {if _dgd .Selector ==""{return _fe .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _geb :=_dgd .By .Validate ();_geb !=nil {return _geb ; +};return nil ;}; -// DefaultPageParameters creates default parameters. -func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_b .Portrait }}; +// Err gets the error which could occur in the query. +func (_edb *QueryBuilder )Err ()error {return _edb ._afb }; -// Validate checks if the parameters are valid. -func (_eed *PageParameters )Validate ()error {if _eed .PaperWidth !=nil {if _eed .PaperWidth .Millimeters ()< 0{return _g .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); -};};if _eed .PaperHeight !=nil {if _eed .PaperHeight .Millimeters ()< 0{return _g .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); -};};if _eed .MarginTop !=nil {if _eed .MarginTop .Millimeters ()< 0{return _g .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _eed .MarginBottom !=nil {if _eed .MarginBottom .Millimeters ()< 0{return _g .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); -};};if _eed .MarginLeft !=nil {if _eed .MarginLeft .Millimeters ()< 0{return _g .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};}; -if _eed .MarginRight !=nil {if _eed .MarginRight .Millimeters ()< 0{return _g .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); -};};if _eed .PageSize !=nil &&!_eed .PageSize .IsAPageSize (){return _g .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; +// Validate checks the validity of the RenderParameters. +func (_ad *RenderParameters )Validate ()error {if _ad .WaitTime > _c .Minute *3{return _fe .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); +};for _ ,_cc :=range _ad .WaitReady {if _cec :=_cc .Validate ();_cec !=nil {return _dbc .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_cec ); +};};return nil ;}; -// Addr gets the HTTP address URI used by the http.Client. -func (_eeg *Options )Addr ()string {_afc :=_ca .Builder {};_afc .WriteString ("\u0068\u0074\u0074\u0070");if _eeg .HTTPS {_afc .WriteRune ('s');};_afc .WriteString ("\u003a\u002f\u002f");_afc .WriteString (_eeg .Hostname );_afc .WriteRune (':');_afc .WriteString (_eb .Itoa (_eeg .Port )); -if _eeg .Prefix !=""{_afc .WriteString (_eeg .Prefix );};return _afc .String ();}; +// HealthCheck connects to the server and check the health status of the server. +func (_bb *Client )HealthCheck (ctx _f .Context )error {_cf :=_bb .Options .Addr ();_cf =_dbc .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_cf );_ed ,_ea :=_ab .NewRequest ("\u0047\u0045\u0054",_cf ,nil );if _ea !=nil {return _ea ;};_ed =_ed .WithContext (ctx ); +_deb ,_ea :=_bb .Client .Do (_ed );if _ea !=nil {return _ea ;};switch _deb .StatusCode {case _ab .StatusOK :return nil ;case _ab .StatusNotFound :return ErrNotFound ;case _ab .StatusInternalServerError :return ErrInternalError ;case _ab .StatusBadGateway :return ErrBadGateway ; +default:return ErrNotImplemented ;};}; -// PageSize sets up the PageSize parameter for the query. -func (_bfcb *QueryBuilder )PageSize (pageSize _b .PageSize )*QueryBuilder {if pageSize !=_b .Undefined {_bfcb ._agg .PageParameters .PageSize =&pageSize ;};return _bfcb ;}; +// ConvertHTML converts provided Query input into PDF file data. +// Implements creator.HTMLConverter interface. +func (_cdg *Client )ConvertHTML (ctx _f .Context ,q *Query )(*PDFResponse ,error ){if _fca :=q .Validate ();_fca !=nil {return nil ,_fca ;};_ff ,_dg :=_cdg .getGenerateRequest (ctx ,q );if _dg !=nil {return nil ,_dg ;};_aa .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_ff .Method ,_ff .URL .Hostname (),_ff .URL .Path ,_ff .Header ,_ff .URL .Query ()); +_ede :=*_cdg .Client ;if q .TimeoutDuration !=0{_ede .Timeout =q .TimeoutDuration ;};_ffg ,_dg :=_ede .Do (_ff );if _dg !=nil {return nil ,_dg ;};var _dc error ;switch _ffg .StatusCode {case _ab .StatusNotFound :_dc =ErrNotFound ;case _ab .StatusBadRequest :_dc =ErrBadRequest ; +case _ab .StatusNotImplemented :_dc =ErrNotImplemented ;case _ab .StatusUnauthorized :_dc =ErrUnauthorized ;case _ab .StatusRequestTimeout :_dc =ErrTimedOut ;case _ab .StatusCreated :default:_dc =ErrInternalError ;};_gc :=_ffg .Body ;switch _ffg .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_gc ,_dg =_de .NewReader (_ffg .Body ); +if _dg !=nil {return nil ,_dg ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_gc =_dac .NewReader (_ffg .Body );case "":default:return nil ,_dbc .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_ffg .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); +};_ggc ,_dg :=_d .ReadAll (_gc );if _dg !=nil &&_dc ==nil {return nil ,_dbc .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_dg );};_aa .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_ffg .StatusCode ,_ff .Method ,_ff .URL .Host ,_ff .URL .Path ); +if _dc !=nil {return nil ,_dbc .Errorf ("\u0025\u0073\u0020%\u0077",string (_ggc ),_dc );};_cb :=_ffg .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_aa .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_cb ); +return &PDFResponse {ID :_cb ,Data :_ggc },nil ;}; -// BuildHTMLQuery creates a Query builder that is supposed to create valid -func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; +// Orientation sets the page orientation for the Query. +func (_ecd *QueryBuilder )Orientation (orientation _gg .Orientation )*QueryBuilder {_ecd ._bade .PageParameters .Orientation =orientation ;return _ecd ;}; -// WithDefaultTimeout sets the DefaultTimeout option for the client options. -func WithDefaultTimeout (option _f .Duration )Option {return func (_be *Options ){_be .DefaultTimeout =option };};var (ErrNotFound =_g .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_g .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); -ErrNotImplemented =_g .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_g .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_g .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079"); -ErrUnauthorized =_g .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_g .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); +// WithPort sets the Port option for the client options. +func WithPort (option int )Option {return func (_fb *Options ){_fb .Port =option }}; -// New creates new client with provided options. -func New (o Options )*Client {o .DefaultTimeout =_f .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _acb =&_dee .Transport {DialContext :(&_af .Dialer {Timeout :5*_f .Second }).DialContext ,TLSHandshakeTimeout :5*_f .Second }; -_da .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_dee .Client {Transport :_acb ,Timeout :o .DefaultTimeout }};}; +// Landscape sets up the landscape portrait orientation. +func (_ggb *QueryBuilder )Landscape ()*QueryBuilder {_ggb ._bade .PageParameters .Orientation =_gg .Landscape ;return _ggb ;}; -// MarginRight sets up the MarginRight parameter for the query. -func (_aaa *QueryBuilder )MarginRight (marginRight _b .Length )*QueryBuilder {_aaa ._agg .PageParameters .MarginRight =marginRight ;return _aaa ;}; +// WithHTTPS sets the TLS option for the client options. +func WithHTTPS (useHTTPS bool )Option {return func (_bad *Options ){_bad .HTTPS =useHTTPS }}; -// WaitTime sets the minimum load time parameter for the page rendering. -func (_bcc *QueryBuilder )WaitTime (d _f .Duration )*QueryBuilder {_bcc ._agg .RenderParameters .WaitTime =d ;return _bcc ;}; +// PaperHeight sets up the PaperHeight (in cm) parameter for the query. +func (_aadb *QueryBuilder )PaperHeight (paperHeight _gg .Length )*QueryBuilder {_aadb ._bade .PageParameters .PaperHeight =paperHeight ;return _aadb ;}; -// Err gets the error which could occur in the query. -func (_fbg *QueryBuilder )Err ()error {return _fbg ._fgb };func (_dc *Client )getGenerateRequest (_dfb _df .Context ,_gded *Query )(*_dee .Request ,error ){_bf :=generatePDFRequestV1 {Method :_gded .Method ,PageParameters :_gded .PageParameters ,RenderParameters :_gded .RenderParameters ,TimeoutDuration :int64 (_gded .TimeoutDuration )}; -switch _gded .Method {case "\u0077\u0065\u0062":_bf .ContentURL =_gded .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_bf .ContentType =_gded .ContentType ;_bf .Content =_gded .Content ;};_ff :=new (_aa .Buffer );if _acbd :=_c .NewEncoder (_ff ).Encode (&_bf ); -_acbd !=nil {return nil ,_ac .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_acbd );};_ffd :=_dc .Options .Addr ();_ffd =_ac .Sprintf ("%\u0073\u002f\u0062\u0065\u0074\u0061\u002f\u0070\u0064\u0066",_ffd ); -_bd ,_fed :=_dee .NewRequest ("\u0050\u004f\u0053\u0054",_ffd ,_ff );if _fed !=nil {return nil ,_fed ;};_bd .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); -_bd .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); -_bd =_bd .WithContext (_dfb );return _bd ,nil ;}; +// MarginTop sets up the MarginTop parameter for the query. +func (_ee *QueryBuilder )MarginTop (marginTop _gg .Length )*QueryBuilder {_ee ._bade .PageParameters .MarginTop =marginTop ;return _ee ;}; -// PDFResponse is the response used by the HTMLConverter. -type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; +// MarginRight sets up the MarginRight parameter for the query. +func (_cge *QueryBuilder )MarginRight (marginRight _gg .Length )*QueryBuilder {_cge ._bade .PageParameters .MarginRight =marginRight ;return _cge ;}; -// Landscape sets up the landscape portrait orientation. -func (_dcd *QueryBuilder )Landscape ()*QueryBuilder {_dcd ._agg .PageParameters .Orientation =_b .Landscape ;return _dcd ;}; +// WaitVisible waits for the selector to get visible. +func (_ef *QueryBuilder )WaitVisible (selector string ,by _ga .ByType )*QueryBuilder {_ef ._bade .RenderParameters .WaitVisible =append (_ef ._bade .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _ef ;}; -// MarginBottom sets up the MarginBottom parameter for the query. -func (_febb *QueryBuilder )MarginBottom (marginBottom _b .Length )*QueryBuilder {_febb ._agg .PageParameters .MarginBottom =marginBottom ;return _febb ;}; +// WithHostname sets the Hostname option for the client options. +func WithHostname (option string )Option {return func (_dcb *Options ){_dcb .Hostname =option }}; // Query gets the Query from provided query builder. If some error occurred during build process // or the input is not valid the function would return an error. -func (_gbf *QueryBuilder )Query ()(*Query ,error ){if _bfc :=_gbf .Validate ();_bfc !=nil {return nil ,_bfc ;};return &_gbf ._agg ,nil ;};var (ErrMissingData =_g .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061"); -ErrContentType =_g .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065");ErrContentTypeDeclared =_g .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064"); -); +func (_cg *QueryBuilder )Query ()(*Query ,error ){if _bd :=_cg .Validate ();_bd !=nil {return nil ,_bd ;};return &_cg ._bade ,nil ;}; -// Validate checks if the QueryBuilder had no errors during composition and creation. -func (_gbd *QueryBuilder )Validate ()error {if _gbd ._fgb !=nil {return _gbd ._fgb ;};return _gbd ._agg .Validate ();}; +// Validate checks if provided Query is valid. +func (_gb *Query )Validate ()error {switch _gb .Method {case "\u0077\u0065\u0062":if _gb .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_gb .Content )==0{return ErrMissingData ;};if _gb .ContentType ==""{return ErrContentType ; +};default:return _dbc .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_gb .Method );};if _dd :=_gb .PageParameters .Validate (); +_dd !=nil {return _dd ;};if _gcc :=_gb .RenderParameters .Validate ();_gcc !=nil {return _gcc ;};return nil ;}; -// WaitVisible waits for the selector to get visible. -func (_ceea *QueryBuilder )WaitVisible (selector string ,by _dbe .ByType )*QueryBuilder {_ceea ._agg .RenderParameters .WaitVisible =append (_ceea ._agg .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _ceea ;}; +// RenderParameters are the parameters related with the rendering. +type RenderParameters struct{WaitTime _c .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; -// Orientation sets the page orientation for the Query. -func (_dbb *QueryBuilder )Orientation (orientation _b .Orientation )*QueryBuilder {_dbb ._agg .PageParameters .Orientation =orientation ;return _dbb ;}; \ No newline at end of file +// TimeoutDuration sets the server query duration timeout. +// Once the timeout is reached the server will return an error. +func (_eea *QueryBuilder )TimeoutDuration (d _c .Duration )*QueryBuilder {_eea ._bade .TimeoutDuration =d ;return _eea ;}; + +// Options are the client options used by the HTTP client. +type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _c .Duration ;Prefix string ;};func (_ge *Client )getGenerateRequest (_ba _f .Context ,_ec *Query )(*_ab .Request ,error ){_ggce :=generatePDFRequestV1 {Method :_ec .Method ,PageParameters :_ec .PageParameters ,RenderParameters :_ec .RenderParameters ,TimeoutDuration :int64 (_ec .TimeoutDuration )}; +switch _ec .Method {case "\u0077\u0065\u0062":_ggce .ContentURL =_ec .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_ggce .ContentType =_ec .ContentType ;_ggce .Content =_ec .Content ;};_gec :=new (_db .Buffer );if _fa :=_da .NewEncoder (_gec ).Encode (&_ggce ); +_fa !=nil {return nil ,_dbc .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_fa );};_bbe :=_ge .Options .Addr ();_bbe =_dbc .Sprintf ("\u0025s\u002f\u0076\u0031\u002f\u0070\u0064f",_bbe ); +_eb ,_bbc :=_ab .NewRequest ("\u0050\u004f\u0053\u0054",_bbe ,_gec );if _bbc !=nil {return nil ,_bbc ;};_eb .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); +_eb .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); +_eb =_eb .WithContext (_ba );return _eb ,nil ;}; \ No newline at end of file diff --git a/common/common.go b/common/common.go index 2255714..a52f214 100644 --- a/common/common.go +++ b/common/common.go @@ -10,8 +10,8 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package common contains common properties used by the subpackages. -package common ;import _bb "time"; +package common ;import _e "time";const _f =2024;const Version ="\u0030\u002e\u0039.\u0030"; // UtcTimeFormat returns a formatted string describing a UTC timestamp. -func UtcTimeFormat (t _bb .Time )string {return t .Format (_a )+"\u0020\u0055\u0054\u0043"};const _e =26;const _a ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";const _c =2024; -const _g =1;const _ea =12;var ReleasedAt =_bb .Date (_c ,_g ,_e ,_ea ,_d ,0,0,_bb .UTC );const _d =20;const Version ="\u0030\u002e\u0038.\u0030"; \ No newline at end of file +func UtcTimeFormat (t _e .Time )string {return t .Format (_ca )+"\u0020\u0055\u0054\u0043"};const _ef =20;const _ca ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";const _cd =12; +var ReleasedAt =_e .Date (_f ,_cd ,_d ,_fc ,_ef ,0,0,_e .UTC );const _d =22;const _fc =12; \ No newline at end of file diff --git a/content/content.go b/content/content.go index 7ebf199..3740d9b 100644 --- a/content/content.go +++ b/content/content.go @@ -9,65 +9,64 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package content ;import (_ff "archive/zip";_d "bytes";_e "fmt";_g "io/ioutil";_c "net/url";_be "os";_b "strings";); +package content ;import (_b "archive/zip";_ab "bytes";_bd "fmt";_a "net/url";_d "os";_bc "strings";); -// ContentType implements Content interface. -func (_cff *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; - -// StringContent implements Content interface for an HTML string. -type StringContent struct{_aag string };type htmlFile struct{_fe _d .Buffer }; - -// NewHTMLFile creates new Content htmFile for provided input path. -func NewHTMLFile (path string )(Content ,error ){_ge ,_fb :=_be .Open (path );if _fb !=nil {return nil ,_fb ;};_a :=&htmlFile {_fe :_d .Buffer {}};if _ ,_fb =_a ._fe .ReadFrom (_ge );_fb !=nil {return nil ,_fb ;};return _a ,nil ;};type webURL struct{_bf string }; -type zipDirectory struct{_bc _d .Buffer ;_ad *_ff .Writer ;}; - -// Method gets the web url query method. -func (_aa *webURL )Method ()string {return "\u0077\u0065\u0062"}; +// Method gets the query method. +func (_bg *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"};type htmlFile struct{_c _ab .Buffer }; // Content is an interface used for putting the content into Client Query. -type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;};func (_adg *zipDirectory )zipPath (_aaa ,_aaf string )error {_ac ,_fa :=_g .ReadDir (_aaa );if _fa !=nil {return _e .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_aaa ,_fa ); -};_df :=&_b .Builder {};for _ ,_ag :=range _ac {_bgb ,_dc :=_adg .zipBasePaths (_ag ,_aaa ,_aaf ,_ag .IsDir (),_df );if _ag .IsDir (){if _dg :=_adg .zipPath (_bgb ,_dc );_dg !=nil {return _dg ;};continue ;};_gg ,_fc :=_g .ReadFile (_bgb );if _fc !=nil {return _fc ; -};_def ,_fc :=_adg ._ad .Create (_dc );if _fc !=nil {return _fc ;};if _ ,_fc =_def .Write (_gg );_fc !=nil {return _fc ;};};return nil ;}; - -// Method implements Content interface. -func (_faa *StringContent )Method ()string {return "\u0068\u0074\u006d\u006c"}; +type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;};type webURL struct{_cd string }; // Data implements Content interface. -func (_cd *StringContent )Data ()[]byte {return []byte (_cd ._aag )}; +func (_bee *StringContent )Data ()[]byte {return []byte (_bee ._aca )}; -// Data implements Content interface. -func (_de *htmlFile )Data ()[]byte {return _de ._fe .Bytes ()}; +// ContentType implements Content interface. +func (_bad *StringContent )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl";}; // Data implements Content interface. -func (_gef *zipDirectory )Data ()[]byte {return _gef ._bc .Bytes ()}; +func (_bgb *webURL )Data ()[]byte {return []byte (_bgb ._cd )};func (_af *zipDirectory )zipPath (_dcd ,_fa string )error {_abc ,_agf :=_d .ReadDir (_dcd );if _agf !=nil {return _bd .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_dcd ,_agf ); +};_de :=&_bc .Builder {};for _ ,_bae :=range _abc {_cc ,_faf :=_bae .Info ();if _faf !=nil {return _faf ;};_ee ,_eg :=_af .zipBasePaths (_cc ,_dcd ,_fa ,_bae .IsDir (),_de );if _bae .IsDir (){if _aag :=_af .zipPath (_ee ,_eg );_aag !=nil {return _aag ; +};continue ;};_gf ,_faf :=_d .ReadFile (_ee );if _faf !=nil {return _faf ;};_be ,_faf :=_af ._g .Create (_eg );if _faf !=nil {return _faf ;};if _ ,_faf =_be .Write (_gf );_faf !=nil {return _faf ;};};return nil ;}; -// ContentType implements Content interface. -func (_bce *StringContent )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl";}; +// Method gets the zip directory method. +func (_ba *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; -// NewStringContent creates a new StringContent. -func NewStringContent (html string )(*StringContent ,error ){return &StringContent {_aag :html },nil }; +// NewWebURL creates new Content webURL for provided input URL path. +func NewWebURL (path string )(Content ,error ){if _ ,_cg :=_a .Parse (path );_cg !=nil {return nil ,_cg ;};return &webURL {_cd :path },nil ;};func (_dfe *zipDirectory )zipBasePaths (_gfa _d .FileInfo ,_gg ,_ffe string ,_ffed bool ,_gd *_bc .Builder )(string ,string ){_gd .WriteString (_gg ); +if !_bc .HasSuffix (_gg ,"\u002f"){_gd .WriteRune ('/');};_gd .WriteString (_gfa .Name ());if _ffed {_gd .WriteRune ('/');};_ca :=_gd .String ();_gd .Reset ();_gd .WriteString (_ffe );_gd .WriteString (_gfa .Name ());if _ffed {_gd .WriteRune ('/');};_gbd :=_gd .String (); +_gd .Reset ();return _ca ,_gbd ;}; + +// Method gets the web url query method. +func (_ag *webURL )Method ()string {return "\u0077\u0065\u0062"}; + +// NewHTMLFile creates new Content htmFile for provided input path. +func NewHTMLFile (path string )(Content ,error ){_f ,_ff :=_d .Open (path );if _ff !=nil {return nil ,_ff ;};_bce :=&htmlFile {_c :_ab .Buffer {}};if _ ,_ff =_bce ._c .ReadFrom (_f );_ff !=nil {return nil ,_ff ;};return _bce ,nil ;}; // ContentType implements Content interface. -func (_ab *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; +func (_aa *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; -// NewWebURL creates new Content webURL for provided input URL path. -func NewWebURL (path string )(Content ,error ){if _ ,_ec :=_c .Parse (path );_ec !=nil {return nil ,_ec ;};return &webURL {_bf :path },nil ;}; +// StringContent implements Content interface for an HTML string. +type StringContent struct{_aca string }; // ContentType implements Content interface. -func (_cg *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; +func (_fg *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; -// Method gets the query method. -func (_ee *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"}; +// NewStringContent creates a new StringContent. +func NewStringContent (html string )(*StringContent ,error ){return &StringContent {_aca :html },nil }; // Data implements Content interface. -func (_cf *webURL )Data ()[]byte {return []byte (_cf ._bf )};func (_gda *zipDirectory )zipBasePaths (_bd _be .FileInfo ,_fd ,_ea string ,_eaa bool ,_ggf *_b .Builder )(string ,string ){_ggf .WriteString (_fd );if !_b .HasSuffix (_fd ,"\u002f"){_ggf .WriteRune ('/'); -};_ggf .WriteString (_bd .Name ());if _eaa {_ggf .WriteRune ('/');};_fef :=_ggf .String ();_ggf .Reset ();_ggf .WriteString (_ea );_ggf .WriteString (_bd .Name ());if _eaa {_ggf .WriteRune ('/');};_bb :=_ggf .String ();_ggf .Reset ();return _fef ,_bb ; -}; +func (_ac *zipDirectory )Data ()[]byte {return _ac ._cbb .Bytes ()}; -// Method gets the zip directory method. -func (_ecf *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; +// ContentType implements Content interface. +func (_dc *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; // NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' // and stores in it's in-memory buffer. -func NewZipDirectory (dirPath string )(Content ,error ){_ae :=&zipDirectory {_bc :_d .Buffer {}};_ae ._ad =_ff .NewWriter (&_ae ._bc );if _gd :=_ae .zipPath (dirPath ,"");_gd !=nil {return nil ,_gd ;};if _eg :=_ae ._ad .Close ();_eg !=nil {return nil ,_eg ; -};return _ae ,nil ;}; \ No newline at end of file +func NewZipDirectory (dirPath string )(Content ,error ){_df :=&zipDirectory {_cbb :_ab .Buffer {}};_df ._g =_b .NewWriter (&_df ._cbb );if _dca :=_df .zipPath (dirPath ,"");_dca !=nil {return nil ,_dca ;};if _cgd :=_df ._g .Close ();_cgd !=nil {return nil ,_cgd ; +};return _df ,nil ;}; + +// Data implements Content interface. +func (_cb *htmlFile )Data ()[]byte {return _cb ._c .Bytes ()}; + +// Method implements Content interface. +func (_ga *StringContent )Method ()string {return "\u0068\u0074\u006d\u006c"};type zipDirectory struct{_cbb _ab .Buffer ;_g *_b .Writer ;}; \ No newline at end of file diff --git a/go.mod b/go.mod index 24cb196..8c52edc 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,13 @@ module github.com/unidoc/unihtml -go 1.17 +go 1.18 require ( github.com/mitchellh/go-homedir v1.1.0 github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.16.0 - github.com/stretchr/testify v1.8.4 - github.com/unidoc/unipdf/v3 v3.53.0 + github.com/stretchr/testify v1.9.0 + github.com/unidoc/unipdf/v3 v3.64.0 ) require ( @@ -16,12 +16,13 @@ require ( github.com/adrg/xdg v0.4.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/pelletier/go-toml/v2 v2.1.1 // indirect + github.com/pelletier/go-toml/v2 v2.2.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/spf13/afero v1.11.0 // indirect @@ -34,13 +35,13 @@ require ( github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a // indirect github.com/unidoc/unichart v0.3.0 // indirect github.com/unidoc/unitype v0.4.0 // indirect - golang.org/x/crypto v0.18.0 // indirect - golang.org/x/image v0.15.0 // indirect - golang.org/x/net v0.20.0 // indirect - golang.org/x/sys v0.16.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/crypto v0.31.0 // indirect + golang.org/x/image v0.18.0 // indirect + golang.org/x/net v0.33.0 // indirect + golang.org/x/sys v0.28.0 // indirect + golang.org/x/text v0.21.0 // indirect golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect - gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 5935136..76ea277 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8Yc github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46 h1:N+R2A3fGIr5GucoRMu2xpqyQWQlfY31orbofBCdjMz8= github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46/go.mod h1:2Yoiy15Cf7Q3NFwfaJquh7Mk1uGI09ytcD7CUhn8j7s= @@ -24,6 +26,7 @@ github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLf github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -34,8 +37,8 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= -github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg= +github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -59,14 +62,16 @@ github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1Fof github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/unidoc/freetype v0.2.3 h1:uPqW+AY0vXN6K2tvtg8dMAtHTEvvHTN52b72XpZU+3I= @@ -78,34 +83,34 @@ github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a h1:RLtvUhe4DsUDl6 github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a/go.mod h1:j+qMWZVpZFTvDey3zxUkSgPJZEX33tDgU/QIA0IzCUw= github.com/unidoc/unichart v0.3.0 h1:VX1j5yzhjrR3f2flC03Yat6/WF3h7Z+DLEvJLoTGhoc= github.com/unidoc/unichart v0.3.0/go.mod h1:8JnLNKSOl8yQt1jXewNgYFHhFm5M6/ZiaydncFDpakA= -github.com/unidoc/unipdf/v3 v3.53.0 h1:xUgG/MH2iUHaar554w6OrL0qTKNy4AWzb19z0RyIExs= -github.com/unidoc/unipdf/v3 v3.53.0/go.mod h1:sEXO/chguUL1RAtyPnGos2BbCBGjL9dusmdT5b13eBg= +github.com/unidoc/unipdf/v3 v3.64.0 h1:6qP8Q7lprY+LIgEz43Ni8mM+q7dCydRp3uwnf9LxzTU= +github.com/unidoc/unipdf/v3 v3.64.0/go.mod h1:0OIzSHHno23Y8WzaK+852abK8d3AxUZ1GQkMqpyCzu8= github.com/unidoc/unitype v0.4.0 h1:/TMZ3wgwfWWX64mU5x2O9no9UmoBqYCB089LYYqHyQQ= github.com/unidoc/unitype v0.4.0/go.mod h1:HV5zuUeqMKA4QgYQq3KDlJY/P96XF90BQB+6czK6LVA= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= +golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= -golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8= -golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= +golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= +golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= +golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= +golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/selector/selector.go b/selector/selector.go index 3b66faf..c2986e7 100644 --- a/selector/selector.go +++ b/selector/selector.go @@ -9,11 +9,10 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package selector ;import _g "errors"; +package selector ;import _b "errors"; // ByType is a 'By' selector type enumerator. -type ByType uint ; +type ByType uint ;const (ByUndefined ByType =iota ;ByID ;ByQueryAll ;ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); // Validate checks validity of the ByType. -func (_cg ByType )Validate ()error {if _cg >=ByID &&_cg <=BySearch {return nil ;};return _g .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};const (ByUndefined ByType =iota ;ByID ;ByQueryAll ; -ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); \ No newline at end of file +func (_dd ByType )Validate ()error {if _dd >=ByID &&_dd <=BySearch {return nil ;};return _b .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");}; \ No newline at end of file diff --git a/sizes/sizes.go b/sizes/sizes.go index 407708d..bbac2a7 100644 --- a/sizes/sizes.go +++ b/sizes/sizes.go @@ -12,191 +12,190 @@ // Package sizes defines basic types that determines the size units i.e. lengths. // // -package sizes ;import (_b "encoding/json";_g "flag";_ea "fmt";_c "strconv";_be "strings";); +package sizes ;import (_d "encoding/json";_a "flag";_bd "fmt";_c "strconv";_b "strings";);const _ece ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; -// String gets the string value for given flag. -func (_ga *LengthFlag )String ()string {if _ga .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _ga .Length .String ();}; -// Points implements Length interface. -func (_dc Inch )Points ()Point {return Point (float64 (_dc )*_af )}; +// Inches gets the inches equivalent from provided millimeter value. +func (_ebb Millimeter )Inches ()Inch {return Inch (float64 (_ebb )*_cb )}; -// UnmarshalPageSize unmarshals the page size from the string. -func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _deea PageSize ;if _cca :=(&_deea ).UnmarshalText ([]byte (pageSize ));_cca !=nil {return 0,_ea .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_cca ); -};return _deea ,nil ;};var _ _g .Value =(*Orientation )(nil ); +// ValueString implements viper.FlagValue interface. +func (_fgc Point )ValueString ()string {return _fgc .String ()};var _ Length =Inch (0); -// Type implements pflag.Value interface. -func (_fcc Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; +// String gets the string value for given flag. +func (_db *LengthFlag )String ()string {if _db .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _db .Length .String ();}; -// String implements fmt.Stringer interface. -func (_ef Orientation )String ()string {if _ef ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; +// ValueType implements pflag.Value interface. +func (_aa Inch )ValueType ()string {return _aa .Type ()}; -// PageSize is the enum used for defining the page size. -type PageSize int ; +// ValueType implements viper.FlagValue interface. +func (_dbb Point )ValueType ()string {return _dbb .Type ()}; -// Type implements pflag.Value interface. -func (_ag *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; +// Set sets the unit value. +// Implements pflag.Value interface. +func (_ga *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_ga .Length =nil ;return nil ;};_ae ,_bc :=UnmarshalLength (s );if _bc !=nil {return _bc ;};_ga .Length =_ae ;return nil ;}; -// Type implements pflag.Value interface. -func (_ega Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; +// Inches gets the inch value. Implements Length interface. +func (_ccf Inch )Inches ()Inch {return _ccf }; -// ValueType implements pflag.Value interface. -func (_dg Inch )ValueType ()string {return _dg .Type ()}; +// MarshalJSON implements the json.Marshaler interface for PageSize +func (_gd PageSize )MarshalJSON ()([]byte ,error ){return _d .Marshal (_gd .String ())}; -// MarshalJSON implements json.Marshaler interface. -func (_ggb Point )MarshalJSON ()([]byte ,error ){return _bee (_ggb )};func _bc (_fed string )(Inch ,error ){_fed =_be .TrimSpace (_be .Trim (_fed ,"\u0069\u006e"));_bcc ,_gaf :=_c .ParseFloat (_fed ,64);if _gaf !=nil {return 0,_ea .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_gaf ); -};return Inch (_bcc ),nil ;}; +// UnmarshalLength unmarshalls string value into Length. +func UnmarshalLength (length string )(Length ,error ){if _b .HasSuffix (length ,"\u006d\u006d"){return _dcg (length );};if _b .HasSuffix (length ,"\u0069\u006e"){return _cbfe (length );};if _b .HasSuffix (length ,"\u0070\u0074"){return _ccb (length );}; +return nil ,_bd .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length );};var _eca =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; +func _ccb (_gf string )(Point ,error ){_gf =_b .TrimSpace (_b .Trim (_gf ,"\u0070\u0074"));_dgb ,_abe :=_c .ParseFloat (_gf ,64);if _abe !=nil {return 0,_abe ;};return Point (_dgb ),nil ;}; + +// Set implements flag.Value interface. +func (_fce *Point )Set (s string )error {_fg ,_bef :=_c .ParseFloat (s ,64);if _bef !=nil {return _bd .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_bef );};*_fce =Point (_fg ); +return nil ;}; + +// ValueString implements pflag.Value interface. +func (_de Inch )ValueString ()string {return _de .String ()}; // String implements fmt.Stringer interface. -func (_ffe Point )String ()string {_fcb :=_be .Builder {};_fcb .WriteString (_c .FormatFloat (float64 (_ffe ),'f',1,64));_fcb .WriteString ("\u0070\u0074");return _fcb .String ();}; +func (_dbe Inch )String ()string {_bg :=_b .Builder {};_bg .WriteString (_c .FormatFloat (float64 (_dbe ),'f',1,64));_bg .WriteString ("\u0069\u006e");return _bg .String ();}; -// Millimeters converts the inches value to the millimeters. -func (_ba Inch )Millimeters ()Millimeter {return Millimeter (float64 (_ba )*_ee )}; +// Inch is a unit that +type Inch float64 ;const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;);var _add =map[string ]PageSize {_ece [0:9]:0,_ece [9:11]:1,_ece [11:13]:2,_ece [13:15]:3,_ece [15:17]:4,_ece [17:19]:5,_ece [19:21]:6,_ece [21:23]:7,_ece [23:25]:8,_ece [25:27]:9,_ece [27:29]:10,_ece [29:32]:11,_ece [32:34]:12,_ece [34:36]:13,_ece [36:38]:14,_ece [38:40]:15,_ece [40:42]:16,_ece [42:44]:17,_ece [44:46]:18,_ece [46:48]:19,_ece [48:50]:20,_ece [50:52]:21,_ece [52:55]:22,_ece [55:61]:23}; -// UnmarshalJSON implements the json.Unmarshaler interface for PageSize -func (_bcf *PageSize )UnmarshalJSON (data []byte )error {var _bge string ;if _ae :=_b .Unmarshal (data ,&_bge );_ae !=nil {return _ea .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); -};var _baed error ;*_bcf ,_baed =PageSizeString (_bge );return _baed ;}; -// Length is it the default dimension unit. -type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;};const (_f =float64 (1)/float64 (25.4);_ee =25.4;_a =0.0139;_gd =0.3528;_af =1.0/64;_ff =1.0/_gd ;);const _fbe ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; +// HasChanged implements pflag.Value interface. +func (_df *Inch )HasChanged ()bool {return _df !=nil }; + +// Name implements viper.FlagValue interface. +func (_cce Point )Name ()string {return "\u0070\u006f\u0069n\u0074"};var _ _a .Value =(*Point )(nil ); +// MarshalText implements the encoding.TextMarshaler interface for PageSize +func (_bae PageSize )MarshalText ()([]byte ,error ){return []byte (_bae .String ()),nil }; // Type implements pflag.Value interface. -func (_bbg PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; +func (_cda Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; -// LengthFlag is a pflag wrapper for the Length value. -type LengthFlag struct{Length Length ;};var _dbf =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};var _cg =map[string ]PageSize {_fbe [0:9]:0,_fbe [9:11]:1,_fbe [11:13]:2,_fbe [13:15]:3,_fbe [15:17]:4,_fbe [17:19]:5,_fbe [19:21]:6,_fbe [21:23]:7,_fbe [23:25]:8,_fbe [25:27]:9,_fbe [27:29]:10,_fbe [29:32]:11,_fbe [32:34]:12,_fbe [34:36]:13,_fbe [36:38]:14,_fbe [38:40]:15,_fbe [40:42]:16,_fbe [42:44]:17,_fbe [44:46]:18,_fbe [46:48]:19,_fbe [48:50]:20,_fbe [50:52]:21,_fbe [52:55]:22,_fbe [55:61]:23}; +// MarshalUnit marshals the unit into the string. +func MarshalUnit (unit Length )(string ,error ){switch _fe :=unit .(type ){case Millimeter :return _bd .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_fe ),nil ;case Inch :return _bd .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_fe ),nil ;case Point :return _bd .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_fe ),nil ; +default:return "",_bd .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; +// String implements fmt.Stringer interface. +func (_aab Orientation )String ()string {if _aab ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; -// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise -func (_bg PageSize )IsAPageSize ()bool {for _ ,_ca :=range _dbf {if _bg ==_ca {return true ;};};return false ;}; +// Point is a unit of Length commonly used to measure the height of fonts. +type Point float64 ; -// Set sets the unit value. -// Implements pflag.Value interface. -func (_fg *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_fg .Length =nil ;return nil ;};_d ,_fc :=UnmarshalLength (s );if _fc !=nil {return _fc ;};_fg .Length =_d ;return nil ;}; +// Type implements pflag.Value interface. +func (_fc Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; -// Dimensions gets the dimensions of the given page size. -// If provided page size is not valid than the function returns 0 values. -func (_dbg PageSize )Dimensions ()(_gdef ,_cc Millimeter ){switch _dbg {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; -case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; -case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _gdef ,_cc ;}; +// Set implements pflag.Value interface. +func (_aaa *PageSize )Set (s string )error {_fed ,_acf :=UnmarshalPageSize (s );if _acf !=nil {return _acf ;};*_aaa =_fed ;return nil ;}; -// ValueType implements viper.FlagValue interface. -func (_cd Point )ValueType ()string {return _cd .Type ()}; +// Set implements flag.Value interface. +func (_cde *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_cde =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_cde =Landscape ;default:return _bd .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); +};return nil ;}; -// ValueString implements viper.FlagValue interface. -func (_cb Point )ValueString ()string {return _cb .String ()}; +// PageSize is the enum used for defining the page size. +type PageSize int ;func _dcg (_dbg string )(Millimeter ,error ){_dbg =_b .TrimSpace (_b .TrimSuffix (_dbg ,"\u006d\u006d"));_fd ,_egag :=_c .ParseFloat (_dbg ,64);if _egag !=nil {return 0,_bd .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_egag ); +};return Millimeter (_fd ),nil ;}; -// Points implements Length interface. -func (_bae Point )Points ()Point {return _bae };func (_gee PageSize )String ()string {if _gee < 0||_gee >=PageSize (len (_eba )-1){return _ea .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_gee );};return _fbe [_eba [_gee ]:_eba [_gee +1]]; -}; +// Millimeters converts the inches value to the millimeters. +func (_gab Point )Millimeters ()Millimeter {return Millimeter (float64 (_gab )*_g )}; -// UnmarshalInch unmarshalls provided string into unit. -func UnmarshalInch (unit string )(Inch ,error ){if _be .HasSuffix (unit ,"\u006d\u006d"){_gc ,_gde :=_fca (unit );if _gde !=nil {return 0,_gde ;};return _gc .Inches (),nil ;};if _be .HasSuffix (unit ,"\u0069\u006e"){return _bc (unit );};return 0,_ea .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); -};var _eba =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; +// String implements fmt.Stringer interface. +func (_gac Point )String ()string {_ebe :=_b .Builder {};_ebe .WriteString (_c .FormatFloat (float64 (_gac ),'f',1,64));_ebe .WriteString ("\u0070\u0074");return _ebe .String ();};func (_cad PageSize )String ()string {if _cad < 0||_cad >=PageSize (len (_eca )-1){return _bd .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_cad ); +};return _ece [_eca [_cad ]:_eca [_cad +1]];}; -// Orientation is the page orientation type wrapper. -type Orientation bool ; +// UnmarshalJSON implements the json.Unmarshaler interface for PageSize +func (_acg *PageSize )UnmarshalJSON (data []byte )error {var _bgg string ;if _bag :=_d .Unmarshal (data ,&_bgg );_bag !=nil {return _bd .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); +};var _ege error ;*_acg ,_ege =PageSizeString (_bgg );return _ege ;}; -// Type implements pflag.Value interface. -func (_bb Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; +// PageSizeValues returns all values of the enum +func PageSizeValues ()[]PageSize {return _fef };var _fef =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; -// Name implements viper.FlagValue interface. -func (_dgg Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; +// String implements fmt.Stringer interface. +func (_ff Millimeter )String ()string {_gag :=_b .Builder {};_gag .WriteString (_c .FormatFloat (float64 (_ff ),'f',1,64));_gag .WriteString ("\u006d\u006d");return _gag .String ();};var _ _a .Value =(*Orientation )(nil ); -// Set implements flag.Value interface. -func (_eeg *Point )Set (s string )error {_baf ,_fbg :=_c .ParseFloat (s ,64);if _fbg !=nil {return _ea .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_fbg );};*_eeg =Point (_baf ); -return nil ;}; +// Name implements pflag.Value interface. +func (_gae Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; -// Set implements flag.Value interface. -func (_bf *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_bf =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_bf =Landscape ;default:return _ea .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); -};return nil ;}; +// Millimeters converts the inches value to the millimeters. +func (_dfa Inch )Millimeters ()Millimeter {return Millimeter (float64 (_dfa )*_ba )}; // Millimeter is the dimension unit that defines a millimeter. -type Millimeter float64 ;const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;);func _fca (_deg string )(Millimeter ,error ){_deg =_be .TrimSpace (_be .TrimSuffix (_deg ,"\u006d\u006d")); -_ebf ,_fd :=_c .ParseFloat (_deg ,64);if _fd !=nil {return 0,_ea .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_fd );};return Millimeter (_ebf ),nil ; -}; +type Millimeter float64 ; -// Inch is a unit that -type Inch float64 ; - -// HasChanged implements viper.FlagValue interface. -func (_aad *Point )HasChanged ()bool {return _aad !=nil }; - -// MarshalUnit marshals the unit into the string. -func MarshalUnit (unit Length )(string ,error ){switch _gfd :=unit .(type ){case Millimeter :return _ea .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_gfd ),nil ;case Inch :return _ea .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_gfd ),nil ;case Point :return _ea .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_gfd ),nil ; -default:return "",_ea .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; +// Orientation is the page orientation type wrapper. +type Orientation bool ; -// String implements fmt.Stringer interface. -func (_ec Millimeter )String ()string {_gff :=_be .Builder {};_gff .WriteString (_c .FormatFloat (float64 (_ec ),'f',1,64));_gff .WriteString ("\u006d\u006d");return _gff .String ();}; +// MarshalJSON implements json.Marshaler interface +func (_ab Millimeter )MarshalJSON ()([]byte ,error ){return _bff (_ab )}; -// MarshalJSON implements the json.Marshaler interface for PageSize -func (_dde PageSize )MarshalJSON ()([]byte ,error ){return _b .Marshal (_dde .String ())};var (_ Length =Millimeter (0););var _ _g .Value =(*Point )(nil ); +// UnmarshalInch unmarshalls provided string into unit. +func UnmarshalInch (unit string )(Inch ,error ){if _b .HasSuffix (unit ,"\u006d\u006d"){_dg ,_af :=_dcg (unit );if _af !=nil {return 0,_af ;};return _dg .Inches (),nil ;};if _b .HasSuffix (unit ,"\u0069\u006e"){return _cbfe (unit );};return 0,_bd .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); +}; -// MarshalText implements the encoding.TextMarshaler interface for PageSize -func (_fbgb PageSize )MarshalText ()([]byte ,error ){return []byte (_fbgb .String ()),nil }; +// MarshalJSON implements json.Marshaler interface +func (_ac Inch )MarshalJSON ()([]byte ,error ){return _bff (_ac )};const (Portrait =Orientation (false );Landscape =Orientation (true ););func _bff (_aba Length )([]byte ,error ){if _aba ==nil {return nil ,nil ;};_ad ,_fdd :=MarshalUnit (_aba );if _fdd !=nil {return nil ,_fdd ; +};return []byte ("\u0022"+_ad +"\u0022"),nil ;}; // Set implements pflag.Value interface. -func (_eg *Inch )Set (s string )error {_de ,_fb :=_c .ParseFloat (s ,64);if _fb !=nil {return _ea .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_fb );};*_eg =Inch (_de ); +func (_ega *Inch )Set (s string )error {_dc ,_cc :=_c .ParseFloat (s ,64);if _cc !=nil {return _bd .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_cc );};*_ega =Inch (_dc ); return nil ;}; -// Millimeters gets the float64 millimeter value. -func (_agg Millimeter )Millimeters ()Millimeter {return _agg }; - -// Name implements pflag.Value interface. -func (_ge Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; +// Type implements pflag.Value interface. +func (_fa Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; // PageSizeString retrieves an enum value from the enum constants string name. // Throws an error if the param is not part of the enum. -func PageSizeString (s string )(PageSize ,error ){if _dgbf ,_eff :=_cg [s ];_eff {return _dgbf ,nil ;};return 0,_ea .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); -};var _ Length =Inch (0); +func PageSizeString (s string )(PageSize ,error ){if _ccfc ,_bec :=_add [s ];_bec {return _ccfc ,nil ;};return 0,_bd .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); +}; -// Inches gets the inches equivalent from provided millimeter value. -func (_bef Millimeter )Inches ()Inch {return Inch (float64 (_bef )*_f )}; +// Points implements Length interface. +func (_ec Inch )Points ()Point {return Point (float64 (_ec )*_f )}; -// PageSizeValues returns all values of the enum -func PageSizeValues ()[]PageSize {return _dbf }; +// HasChanged implements viper.FlagValue interface. +func (_ag *Point )HasChanged ()bool {return _ag !=nil };func _cbfe (_dbbc string )(Inch ,error ){_dbbc =_b .TrimSpace (_b .Trim (_dbbc ,"\u0069\u006e"));_dee ,_aca :=_c .ParseFloat (_dbbc ,64);if _aca !=nil {return 0,_bd .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_aca ); +};return Inch (_dee ),nil ;};const (_cb =float64 (1)/float64 (25.4);_ba =25.4;_be =0.0139;_g =0.3528;_f =1.0/64;_cg =1.0/_g ;); -// MarshalPageSize marshals the page size into string. -func MarshalPageSize (p PageSize )(string ,error ){_ad ,_egg :=p .MarshalText ();if _egg !=nil {return "",_egg ;};return string (_ad ),nil ;}; +// Type implements pflag.Value interface. +func (_bab *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; -// Points implements Length interface. -func (_aga Millimeter )Points ()Point {return Point (_aga *_ff )}; +// UnmarshalPageSize unmarshals the page size from the string. +func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _dcb PageSize ;if _bb :=(&_dcb ).UnmarshalText ([]byte (pageSize ));_bb !=nil {return 0,_bd .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_bb ); +};return _dcb ,nil ;}; -// String implements fmt.Stringer interface. -func (_aa Inch )String ()string {_gg :=_be .Builder {};_gg .WriteString (_c .FormatFloat (float64 (_aa ),'f',1,64));_gg .WriteString ("\u0069\u006e");return _gg .String ();}; +// MarshalJSON implements json.Marshaler interface. +func (_cd Point )MarshalJSON ()([]byte ,error ){return _bff (_cd )}; -// Inches gets the inch value. Implements Length interface. -func (_eb Point )Inches ()Inch {return Inch (float64 (_eb )*_a )};func _gbe (_gffe string )(Point ,error ){_gffe =_be .TrimSpace (_be .Trim (_gffe ,"\u0070\u0074"));_agd ,_bd :=_c .ParseFloat (_gffe ,64);if _bd !=nil {return 0,_bd ;};return Point (_agd ),nil ; -};func _bee (_cde Length )([]byte ,error ){if _cde ==nil {return nil ,nil ;};_db ,_abd :=MarshalUnit (_cde );if _abd !=nil {return nil ,_abd ;};return []byte ("\u0022"+_db +"\u0022"),nil ;};const (Portrait =Orientation (false );Landscape =Orientation (true ); -); +// Points implements Length interface. +func (_cbf Point )Points ()Point {return _cbf }; -// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize -func (_ac *PageSize )UnmarshalText (text []byte )error {var _dgd error ;*_ac ,_dgd =PageSizeString (string (text ));return _dgd ;}; +// Inches gets the inch value. Implements Length interface. +func (_dbc Point )Inches ()Inch {return Inch (float64 (_dbc )*_be )};var (_ Length =Millimeter (0);); -// Set implements pflag.Value interface. -func (_dd *PageSize )Set (s string )error {_afc ,_fcaf :=UnmarshalPageSize (s );if _fcaf !=nil {return _fcaf ;};*_dd =_afc ;return nil ;}; +// LengthFlag is a pflag wrapper for the Length value. +type LengthFlag struct{Length Length ;}; -// Inches gets the inch value. Implements Length interface. -func (_fbb Inch )Inches ()Inch {return _fbb }; +// Millimeters gets the float64 millimeter value. +func (_eb Millimeter )Millimeters ()Millimeter {return _eb }; -// HasChanged implements pflag.Value interface. -func (_fcf *Inch )HasChanged ()bool {return _fcf !=nil }; +// Dimensions gets the dimensions of the given page size. +// If provided page size is not valid than the function returns 0 values. +func (_ge PageSize )Dimensions ()(_ca ,_dca Millimeter ){switch _ge {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; +case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; +case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _ca ,_dca ;}; -// ValueString implements pflag.Value interface. -func (_fe Inch )ValueString ()string {return _fe .String ()}; +// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize +func (_gdd *PageSize )UnmarshalText (text []byte )error {var _gb error ;*_gdd ,_gb =PageSizeString (string (text ));return _gb ;}; -// MarshalJSON implements json.Marshaler interface -func (_ed Inch )MarshalJSON ()([]byte ,error ){return _bee (_ed )}; +// Type implements pflag.Value interface. +func (_ed PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; -// Point is a unit of Length commonly used to measure the height of fonts. -type Point float64 ; +// Points implements Length interface. +func (_gc Millimeter )Points ()Point {return Point (_gc *_cg )}; -// Millimeters converts the inches value to the millimeters. -func (_dee Point )Millimeters ()Millimeter {return Millimeter (float64 (_dee )*_gd )}; +// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise +func (_bcc PageSize )IsAPageSize ()bool {for _ ,_ee :=range _fef {if _bcc ==_ee {return true ;};};return false ;}; -// UnmarshalLength unmarshalls string value into Length. -func UnmarshalLength (length string )(Length ,error ){if _be .HasSuffix (length ,"\u006d\u006d"){return _fca (length );};if _be .HasSuffix (length ,"\u0069\u006e"){return _bc (length );};if _be .HasSuffix (length ,"\u0070\u0074"){return _gbe (length ); -};return nil ,_ea .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length );}; +// Length is it the default dimension unit. +type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; -// MarshalJSON implements json.Marshaler interface -func (_ab Millimeter )MarshalJSON ()([]byte ,error ){return _bee (_ab )}; \ No newline at end of file +// MarshalPageSize marshals the page size into string. +func MarshalPageSize (p PageSize )(string ,error ){_acb ,_aabg :=p .MarshalText ();if _aabg !=nil {return "",_aabg ;};return string (_acb ),nil ;}; \ No newline at end of file diff --git a/unihtml.go b/unihtml.go index 1e34e4e..a112f8d 100644 --- a/unihtml.go +++ b/unihtml.go @@ -10,122 +10,126 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package unihtml contains a plugin for the UniDoc. -package unihtml ;import (_gg "bytes";_g "context";_bg "errors";_af "fmt";_cc "github.com/unidoc/unihtml/client";_bad "github.com/unidoc/unihtml/content";_ac "github.com/unidoc/unihtml/selector";_ag "github.com/unidoc/unihtml/sizes";_d "github.com/unidoc/unipdf/v3/common"; -_ee "github.com/unidoc/unipdf/v3/common/license";_gc "github.com/unidoc/unipdf/v3/creator";_ga "github.com/unidoc/unipdf/v3/model";_ad "github.com/unidoc/unipdf/v3/render";_ba "image";_e "image/color";_a "math";_f "net/url";_b "os";_ce "time";); +package unihtml ;import (_ee "bytes";_f "context";_a "errors";_ea "fmt";_fde "github.com/unidoc/unihtml/client";_fb "github.com/unidoc/unihtml/content";_eea "github.com/unidoc/unihtml/selector";_g "github.com/unidoc/unihtml/sizes";_eac "github.com/unidoc/unipdf/v3/common"; +_fdd "github.com/unidoc/unipdf/v3/common/license";_cb "github.com/unidoc/unipdf/v3/creator";_ed "github.com/unidoc/unipdf/v3/model";_ab "github.com/unidoc/unipdf/v3/render";_b "image";_eg "image/color";_d "math";_e "net/url";_ff "os";_fd "time";); -// WriteToFile writes the document to a file defined by the output path. -func (_ccd *Document )WriteToFile (outputPath string )error {if _ccdb :=_ccd .validate ();_ccdb !=nil {return _ccdb ;};_fge :=_ce .Second *20+_ccd ._ae ;_fb ,_abf :=_g .WithTimeout (_g .Background (),_fge );defer _abf ();_gce ,_badc :=_ccd .extract (_fb ,_ccd ._dda ,_ccd ._dcb ,_ccd .getMargins ()); -if _badc !=nil {return _badc ;};_fa :=_gc .New ();for _ ,_acd :=range _gce {if _badc =_fa .AddPage (_acd );_badc !=nil {return _badc ;};};return _fa .WriteToFile (outputPath );}; +// Options are the HTML Client options used for establishing the connection. +type Options struct{ -// SetMarginBottom sets the left margin. -func (_fe *Document )SetMarginBottom (margin _ag .Length ){_fe ._gaa .Bottom =margin }; +// Hostname defines the hostname for the client. Default value: 'localhost'. +Hostname string ; -// WaitVisible waits for the provided selector to be ready. -// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_fgf *Document )WaitVisible (sel string ,by ..._ac .ByType ){_cdg :=_ac .BySearch ;if len (by )> 0{_cdg =by [0];};_fgf ._bag =append (_fgf ._bag ,_cc .BySelector {Selector :sel ,By :_cdg });}; +// Port defines the port at which the server works. Default value: '8080' +Port int ; -// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. -func (_eef *Document )TrimLastPageContent (){_eef ._cd =true };type margins struct{Left ,Right ,Bottom ,Top _ag .Length ;}; +// Secure is the flag that states if the connection uses HTTPS protocol. Default Value: 'false'. +Secure bool ; -// SetPageSize sets the page default size. -func (_add *Document )SetPageSize (pageSize _ag .PageSize )error {if !pageSize .IsAPageSize (){return _bg .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); -};_add ._ace =pageSize ;_add ._ebf =_gc .PositionAbsolute ;return nil ;}; +// Prefix is an option setting used when the server is working with the URI prefix. Default Value: ''. +Prefix string ;}; -// SetMarginLeft sets the left margin. -func (_ff *Document )SetMarginLeft (margin _ag .Length ){_ff ._gaa .Left =margin }; +// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. +func ConnectOptions (o Options )error {_dd =_fde .New (_fde .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_ad ,_fe :=_f .WithTimeout (_f .Background (),_fd .Second *5);defer _fe ();if _gb :=_dd .HealthCheck (_ad );_gb !=nil {return _gb ; +};return nil ;}; -// ContainerComponent implements creator.containerElement interface. -func (_dag *Document )ContainerComponent (container _gc .Drawable )(_gc .Drawable ,error ){switch container .(type ){case *_gc .Chapter :default:return nil ,_af .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); -};return _dag ,nil ;}; +// SetMarkedContentID sets the marked content id for the document. +func (_dcc *Document )SetMarkedContentID (id int64 )*_ed .KDict {return nil }; -// WaitReady waits for the provided selector to be ready. -// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_ccb *Document )WaitReady (sel string ,by ..._ac .ByType ){_fd :=_ac .BySearch ;if len (by )> 0{_fd =by [0];};_ccb ._gf =append (_ccb ._gf ,_cc .BySelector {Selector :sel ,By :_fd });}; +// SetPageSize sets the page default size. +func (_egg *Document )SetPageSize (pageSize _g .PageSize )error {if !pageSize .IsAPageSize (){return _a .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); +};_egg ._ffa =pageSize ;_egg ._bg =_cb .PositionAbsolute ;return nil ;}; -// SetMarginRight sets the left margin. -func (_cccb *Document )SetMarginRight (margin _ag .Length ){_cccb ._gaa .Right =margin }; +// SetLandscapeOrientation sets document landscape page orientation. +func (_bffb *Document )SetLandscapeOrientation (){_bffb ._ced =_g .Landscape }; -// SetTimeoutDuration sets the timeout duration -// the default timeout is 15 seconds. -func (_edg *Document )SetTimeoutDuration (duration _ce .Duration ){_edg ._bf =&duration };var ErrContentNotDefined =_bg .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); -func _de (_badd _ba .Image )float64 {_ceg :=_badd .Bounds ();var (_db int ;_adc _e .Color ;_beef ,_ca ,_gab uint32 ;);_aa ,_ebb :=_ceg .Min .X ,_ceg .Max .Y -1;_fad :=_badd .At (_aa ,_ebb );_bd ,_cga ,_abfg ,_ :=_fad .RGBA ();_ddc :=_bd ==_a .MaxUint16 &&_cga ==_a .MaxUint16 &&_abfg ==_a .MaxUint16 ; -for _ebb =_ceg .Max .Y -1;_ebb >=_ceg .Min .Y ;_ebb --{var _cgae bool ;for _aa =_ceg .Min .X ;_aa < _ceg .Max .X ;_aa ++{_adc =_badd .At (_aa ,_ebb );_beef ,_ca ,_gab ,_ =_adc .RGBA ();if (_ddc &&!(_beef ==_bd &&_ca ==_cga &&_abfg ==_gab ))||(!_ddc &&(_a .Abs (float64 (_beef )-float64 (_bd ))/float64 (_a .MaxUint16 )> 0.03||_a .Abs (float64 (_ca )-float64 (_cga ))/float64 (_a .MaxUint16 )> 0.03||_a .Abs (float64 (_gab )-float64 (_abfg ))/float64 (_a .MaxUint16 )> 0.03)){_cgae =true ; -break ;};};if _cgae {break ;};_db =_ebb ;};return float64 (_ceg .Max .Y -_db )/float64 (_ceg .Max .Y );};func _fg ()error {_cg :=_ee .GetLicenseKey ();if _cg ==nil {return _bg .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); -};if !_cg .IsLicensed (){return _bg .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};return nil ;};func (_cfb *Document )validate ()error {if _bgd ==nil {return ErrNoClient ; -};if _cfb ._dde ==nil {return ErrContentNotDefined ;};return nil ;};func (_dcc *Document )getTimeoutDuration ()_ce .Duration {if _dcc ._bf !=nil {return *_dcc ._bf ;};return 0;}; +// NewDocumentFromString creates a new Document from the provided HTML string. +func NewDocumentFromString (html string )(*Document ,error ){_adc ,_cd :=_fb .NewStringContent (html );if _cd !=nil {return nil ,_cd ;};_ef :=&Document {};_ef ._bf =_adc ;return _ef ,nil ;}; -// Connect creates UniHTML HTTP Client and tries to establish connection with the server. -func Connect (path string )error {if _cb :=_fg ();_cb !=nil {return _cb ;};_eb ,_dc :=_cc .ParseOptions (path );if _dc !=nil {return _dc ;};_bgd =_cc .New (_eb );_ge ,_fc :=_g .WithTimeout (_g .Background (),_ce .Second *5);defer _fc ();if _dg :=_bgd .HealthCheck (_ge ); -_dg !=nil {return _dg ;};return nil ;}; +// SetPos sets the absolute position. Changes object positioning to absolute. +func (_fgb *Document )SetPos (x ,y float64 ){_fgb ._bg =_cb .PositionAbsolute ;_fgb ._fbd =x ;_fgb ._fba =y ;}; -// SetLandscapeOrientation sets document landscape page orientation. -func (_dgc *Document )SetLandscapeOrientation (){_dgc ._bed =_ag .Landscape };var ErrNoClient =_bg .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); +// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. +func (_acd *Document )TrimLastPageContent (){_acd ._fdg =true }; -// SetPageHeight sets the page height for given document. -func (_dcg *Document )SetPageHeight (pageHeight _ag .Length )error {_dcg ._dcb =pageHeight ;_dcg ._ebf =_gc .PositionAbsolute ;return nil ;};var _ _gc .Drawable =(*Document )(nil ); +// GetPdfPages is a function that converts provided input content and +func (_fac *Document )GetPdfPages (ctx _f .Context )([]*_ed .PdfPage ,error ){if _gf :=_fac .validate ();_gf !=nil {return nil ,_gf ;};return _fac .extract (ctx ,_fac ._db ,_fac ._eb ,_fac .getMargins ());}; -// SetMargins sets the Document Margins. -func (_ed *Document )SetMargins (left ,right ,top ,bottom float64 ){_ed ._gaa .Left =_ag .Point (left );_ed ._gaa .Right =_ag .Point (right );_ed ._gaa .Top =_ag .Point (top );_ed ._gaa .Bottom =_ag .Point (bottom );_ed ._ebf =_gc .PositionAbsolute ;}; -func (_cgg *Document )extract (_dge _g .Context ,_cde ,_dgea _ag .Length ,_cec margins )([]*_ga .PdfPage ,error ){_ebc :=_cc .BuildHTMLQuery ().SetContent (_cgg ._dde ).PageSize (_cgg ._ace ).PaperWidth (_cde ).PaperHeight (_dgea ).Orientation (_cgg ._bed ).MarginLeft (_cec .Left ).MarginRight (_cec .Right ).MarginTop (_cec .Top ).MarginBottom (_cec .Bottom ).TimeoutDuration (_cgg .getTimeoutDuration ()).WaitTime (_cgg ._ae ); -for _ ,_gee :=range _cgg ._gf {_ebc .WaitReady (_gee .Selector ,_gee .By );};for _ ,_bbb :=range _cgg ._bag {_ebc .WaitVisible (_bbb .Selector ,_bbb .By );};_fgec ,_efc :=_ebc .Query ();if _efc !=nil {return nil ,_efc ;};var _df _g .CancelFunc ;if _cgg ._bf !=nil {_dge ,_df =_g .WithTimeout (_dge ,*_cgg ._bf ); -}else {_dge ,_df =_g .WithTimeout (_dge ,_ce .Second *15);};defer _df ();_cdgg ,_efc :=_bgd .ConvertHTML (_dge ,_fgec );if _efc !=nil {return nil ,_efc ;};_gbd :=_gg .NewReader (_cdgg .Data );_abc ,_efc :=_ga .NewPdfReader (_gbd );if _efc !=nil {return nil ,_efc ; -};return _abc .PageList ,nil ;}; +// SetPageWidth sets the page width for given document. +func (_abg *Document )SetPageWidth (pageWidth _g .Length )error {_abg ._db =pageWidth ;_abg ._bg =_cb .PositionAbsolute ;return nil ;};var _ _cb .Drawable =(*Document )(nil ); -// Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. -type Document struct{_dde _bad .Content ;_gaa margins ;_ebf _gc .Positioning ;_be ,_bee float64 ;_ace _ag .PageSize ;_dda ,_dcb _ag .Length ;_bed _ag .Orientation ;_cd bool ;_ae _ce .Duration ;_gf []_cc .BySelector ;_bag []_cc .BySelector ;_bf *_ce .Duration ; -}; +// SetMarginLeft sets the left margin. +func (_fgf *Document )SetMarginLeft (margin _g .Length ){_fgf ._fdb .Left =margin }; -// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. -func ConnectOptions (o Options )error {_bgd =_cc .New (_cc .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_da ,_ef :=_g .WithTimeout (_g .Background (),_ce .Second *5);defer _ef ();if _dd :=_bgd .HealthCheck (_da );_dd !=nil {return _dd ; -};return nil ;}; +// SetMarginRight sets the left margin. +func (_ddbf *Document )SetMarginRight (margin _g .Length ){_ddbf ._fdb .Right =margin }; -// NewDocumentFromString creates a new Document from the provided HTML string. -func NewDocumentFromString (html string )(*Document ,error ){_acf ,_ea :=_bad .NewStringContent (html );if _ea !=nil {return nil ,_ea ;};_bb :=&Document {};_bb ._dde =_acf ;return _bb ,nil ;}; +// WriteToFile writes the document to a file defined by the output path. +func (_ga *Document )WriteToFile (outputPath string )error {if _bc :=_ga .validate ();_bc !=nil {return _bc ;};_abd :=_fd .Second *20+_ga ._age ;_cf ,_fdbf :=_f .WithTimeout (_f .Background (),_abd );defer _fdbf ();_gc ,_agea :=_ga .extract (_cf ,_ga ._db ,_ga ._eb ,_ga .getMargins ()); +if _agea !=nil {return _agea ;};_ece :=_cb .New ();for _ ,_ebf :=range _gc {if _agea =_ece .AddPage (_ebf );_agea !=nil {return _agea ;};};return _ece .WriteToFile (outputPath );};func _cg (_fda _b .Image )float64 {_cde :=_fda .Bounds ();var (_gef int ; +_abc _eg .Color ;_fbc ,_aeb ,_gdc uint32 ;);_af ,_dad :=_cde .Min .X ,_cde .Max .Y -1;_gfc :=_fda .At (_af ,_dad );_def ,_bca ,_ebg ,_ :=_gfc .RGBA ();_dbg :=_def ==_d .MaxUint16 &&_bca ==_d .MaxUint16 &&_ebg ==_d .MaxUint16 ;for _dad =_cde .Max .Y -1; +_dad >=_cde .Min .Y ;_dad --{var _fae bool ;for _af =_cde .Min .X ;_af < _cde .Max .X ;_af ++{_abc =_fda .At (_af ,_dad );_fbc ,_aeb ,_gdc ,_ =_abc .RGBA ();if (_dbg &&!(_fbc ==_def &&_aeb ==_bca &&_ebg ==_gdc ))||(!_dbg &&(_d .Abs (float64 (_fbc )-float64 (_def ))/float64 (_d .MaxUint16 )> 0.03||_d .Abs (float64 (_aeb )-float64 (_bca ))/float64 (_d .MaxUint16 )> 0.03||_d .Abs (float64 (_gdc )-float64 (_ebg ))/float64 (_d .MaxUint16 )> 0.03)){_fae =true ; +break ;};};if _fae {break ;};_gef =_dad ;};return float64 (_cde .Max .Y -_gef )/float64 (_cde .Max .Y );};type margins struct{Left ,Right ,Bottom ,Top _g .Length ;};var ErrNoClient =_a .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); -// SetPos sets the absolute position. Changes object positioning to absolute. -func (_gced *Document )SetPos (x ,y float64 ){_gced ._ebf =_gc .PositionAbsolute ;_gced ._be =x ;_gced ._bee =y ;}; // WaitTime sets the waiting time before the webpage is rendered to PDF. -func (_fadd *Document )WaitTime (duration _ce .Duration ){_fadd ._ae =duration }; +func (_bce *Document )WaitTime (duration _fd .Duration ){_bce ._age =duration };func (_baa *Document )validate ()error {if _dd ==nil {return ErrNoClient ;};if _baa ._bf ==nil {return ErrContentNotDefined ;};return nil ;}; -// GeneratePageBlocks implements creator.Drawable interface. -func (_afb *Document )GeneratePageBlocks (ctx _gc .DrawContext )([]*_gc .Block ,_gc .DrawContext ,error ){if _badg :=_afb .validate ();_badg !=nil {return nil ,ctx ,_badg ;};var _gb []*_gc .Block ;_ec :=_afb .getMargins ();_fgc ,_ade :=_afb ._dda ,_afb ._dcb ; -if _afb ._ebf .IsRelative (){_fgc ,_ade =_ag .Point (ctx .Width ),_ag .Point (ctx .Height );ctx .X -=float64 (_ec .Left .Points ());}else {ctx .X =_afb ._be ;ctx .Y =_afb ._bee ;};_cdf ,_ebfe :=_afb .extract (_g .Background (),_fgc ,_ade ,_ec );if _ebfe !=nil {return nil ,_gc .DrawContext {},_ebfe ; -};for _bff ,_cbc :=range _cdf {_ggg ,_ab :=_gc .NewBlockFromPage (_cbc );if _ab !=nil {return nil ,_gc .DrawContext {},_ab ;};var _agg float64 ;if _afb ._cd &&_bff ==len (_cdf )-1{_beg :=_ad .NewImageDevice ();_fca ,_acec :=_beg .Render (_cbc );if _acec !=nil {return nil ,_gc .DrawContext {},_acec ; -};_cdd ,_acec :=_cbc .GetMediaBox ();if _acec !=nil {return nil ,_gc .DrawContext {},_acec ;};_gd :=_ce .Now ();_ccc :=_de (_fca );_agg =_cdd .Height ()*_ccc ;_d .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_ce .Since (_gd )); -if _afb ._gaa .Bottom !=nil {_agg -=float64 (_afb ._gaa .Bottom .Points ());};if _agg < 0{_agg =0;};_d .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_agg ); -};_cfc ,_gggc ,_ab :=_ggg .GeneratePageBlocks (ctx );if _ab !=nil {return nil ,_gc .DrawContext {},_ab ;};ctx =_gggc ;ctx .Y -=_agg ;if _bff !=len (_cdf )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; -ctx .Page ++;};_gb =append (_gb ,_cfc ...);};return _gb ,ctx ,nil ;}; +// WaitVisible waits for the provided selector to be ready. +// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. +func (_gcg *Document )WaitVisible (sel string ,by ..._eea .ByType ){_gaf :=_eea .BySearch ;if len (by )> 0{_gaf =by [0];};_gcg ._da =append (_gcg ._da ,_fde .BySelector {Selector :sel ,By :_gaf });}; -// GetContent returns the content of the document. -func (_afg *Document )GetContent ()_bad .Content {return _afg ._dde };var _bgd *_cc .Client ; +// Connect creates UniHTML HTTP Client and tries to establish connection with the server. +func Connect (path string )error {if _ddg :=_aa ();_ddg !=nil {return _ddg ;};_eda ,_ae :=_fde .ParseOptions (path );if _ae !=nil {return _ae ;};_dd =_fde .New (_eda );_ag ,_ce :=_f .WithTimeout (_f .Background (),_fd .Second *5);defer _ce ();if _ge :=_dd .HealthCheck (_ag ); +_ge !=nil {return _ge ;};return nil ;}; -// Options are the HTML Client options used for establishing the connection. -type Options struct{ +// WaitReady waits for the provided selector to be ready. +// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. +func (_dfb *Document )WaitReady (sel string ,by ..._eea .ByType ){_dc :=_eea .BySearch ;if len (by )> 0{_dc =by [0];};_dfb ._ac =append (_dfb ._ac ,_fde .BySelector {Selector :sel ,By :_dc });}; -// Hostname defines the hostname for the client. Default value: 'localhost'. -Hostname string ; +// NewDocument creates new HTML Document used as an input for the creator.Drawable. +func NewDocument (path string )(*Document ,error ){_gd :=&Document {};_fa ,_eebf :=_e .Parse (path );if _eebf !=nil {return nil ,_eebf ;};switch _fa .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_gd ._bf ,_eebf =_fb .NewWebURL (path ); +if _eebf !=nil {return nil ,_eebf ;};return _gd ,nil ;};_cac ,_eebf :=_ff .Stat (path );if _eebf !=nil {return nil ,_eebf ;};if !_cac .IsDir (){_gd ._bf ,_eebf =_fb .NewHTMLFile (path );}else {_gd ._bf ,_eebf =_fb .NewZipDirectory (path );};if _eebf !=nil {return nil ,_eebf ; +};return _gd ,nil ;};var _dd *_fde .Client ; -// Port defines the port at which the server works. Default value: '8080' -Port int ; +// GeneratePageBlocks implements creator.Drawable interface. +func (_fcc *Document )GeneratePageBlocks (ctx _cb .DrawContext )([]*_cb .Block ,_cb .DrawContext ,error ){if _cec :=_fcc .validate ();_cec !=nil {return nil ,ctx ,_cec ;};var _eab []*_cb .Block ;_aae :=_fcc .getMargins ();_de ,_ec :=_fcc ._db ,_fcc ._eb ; +if _fcc ._bg .IsRelative (){_de ,_ec =_g .Point (ctx .Width ),_g .Point (ctx .Height );ctx .X -=float64 (_aae .Left .Points ());}else {ctx .X =_fcc ._fbd ;ctx .Y =_fcc ._fba ;};_ffd ,_faf :=_fcc .extract (_f .Background (),_de ,_ec ,_aae );if _faf !=nil {return nil ,_cb .DrawContext {},_faf ; +};for _df ,_ceg :=range _ffd {_efd ,_cab :=_cb .NewBlockFromPage (_ceg );if _cab !=nil {return nil ,_cb .DrawContext {},_cab ;};var _fed float64 ;if _fcc ._fdg &&_df ==len (_ffd )-1{_ba :=_ab .NewImageDevice ();_cbe ,_aac :=_ba .Render (_ceg );if _aac !=nil {return nil ,_cb .DrawContext {},_aac ; +};_cdg ,_aac :=_ceg .GetMediaBox ();if _aac !=nil {return nil ,_cb .DrawContext {},_aac ;};_ffda :=_fd .Now ();_bff :=_cg (_cbe );_fed =_cdg .Height ()*_bff ;_eac .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_fd .Since (_ffda )); +if _fcc ._fdb .Bottom !=nil {_fed -=float64 (_fcc ._fdb .Bottom .Points ());};if _fed < 0{_fed =0;};_eac .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_fed ); +};_fg ,_be ,_cab :=_efd .GeneratePageBlocks (ctx );if _cab !=nil {return nil ,_cb .DrawContext {},_cab ;};ctx =_be ;ctx .Y -=_fed ;if _df !=len (_ffd )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; +ctx .Page ++;};_eab =append (_eab ,_fg ...);};return _eab ,ctx ,nil ;};func (_gfb *Document )getMargins ()margins {_daf :=_gfb ._fdb ;if _gfb ._bg .IsRelative (){_daf .Top =_g .Millimeter (1);_daf .Left =_g .Millimeter (1);_daf .Bottom =_g .Millimeter (1); +_daf .Right =_g .Millimeter (1);return _daf ;};if _daf .Top ==nil {_daf .Top =_g .Millimeter (10);};if _daf .Bottom ==nil {_daf .Bottom =_g .Millimeter (10);};if _daf .Left ==nil {_daf .Left =_g .Millimeter (10);};if _daf .Right ==nil {_daf .Right =_g .Millimeter (10); +};return _daf ;};func (_aed *Document )getTimeoutDuration ()_fd .Duration {if _aed ._fc !=nil {return *_aed ._fc ;};return 0;}; -// Secure is the flag that states if the connection uses HTTPS protocol. Default Value: 'false'. -Secure bool ; +// GetContent returns the content of the document. +func (_eaf *Document )GetContent ()_fb .Content {return _eaf ._bf }; -// Prefix is an option setting used when the server is working with the URI prefix. Default Value: ''. -Prefix string ;};func (_deg *Document )getMargins ()margins {_gea :=_deg ._gaa ;if _deg ._ebf .IsRelative (){_gea .Top =_ag .Millimeter (1);_gea .Left =_ag .Millimeter (1);_gea .Bottom =_ag .Millimeter (1);_gea .Right =_ag .Millimeter (1);return _gea ; -};if _gea .Top ==nil {_gea .Top =_ag .Millimeter (10);};if _gea .Bottom ==nil {_gea .Bottom =_ag .Millimeter (10);};if _gea .Left ==nil {_gea .Left =_ag .Millimeter (10);};if _gea .Right ==nil {_gea .Right =_ag .Millimeter (10);};return _gea ;}; +// SetTimeoutDuration sets the timeout duration +// the default timeout is 15 seconds. +func (_ggb *Document )SetTimeoutDuration (duration _fd .Duration ){_ggb ._fc =&duration }; -// NewDocument creates new HTML Document used as an input for the creator.Drawable. -func NewDocument (path string )(*Document ,error ){_efe :=&Document {};_bfg ,_acb :=_f .Parse (path );if _acb !=nil {return nil ,_acb ;};switch _bfg .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_efe ._dde ,_acb =_bad .NewWebURL (path ); -if _acb !=nil {return nil ,_acb ;};return _efe ,nil ;};_ebd ,_acb :=_b .Stat (path );if _acb !=nil {return nil ,_acb ;};if !_ebd .IsDir (){_efe ._dde ,_acb =_bad .NewHTMLFile (path );}else {_efe ._dde ,_acb =_bad .NewZipDirectory (path );};if _acb !=nil {return nil ,_acb ; -};return _efe ,nil ;}; +// SetPageHeight sets the page height for given document. +func (_bgc *Document )SetPageHeight (pageHeight _g .Length )error {_bgc ._eb =pageHeight ;_bgc ._bg =_cb .PositionAbsolute ;return nil ;}; -// SetPageWidth sets the page width for given document. -func (_ege *Document )SetPageWidth (pageWidth _ag .Length )error {_ege ._dda =pageWidth ;_ege ._ebf =_gc .PositionAbsolute ;return nil ;}; +// Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. +type Document struct{_bf _fb .Content ;_fdb margins ;_bg _cb .Positioning ;_fbd ,_fba float64 ;_ffa _g .PageSize ;_db ,_eb _g .Length ;_ced _g .Orientation ;_fdg bool ;_age _fd .Duration ;_ac []_fde .BySelector ;_da []_fde .BySelector ;_fc *_fd .Duration ; +};func (_edf *Document )extract (_gff _f .Context ,_fag ,_gaa _g .Length ,_feg margins )([]*_ed .PdfPage ,error ){_dbb :=_fde .BuildHTMLQuery ().SetContent (_edf ._bf ).PageSize (_edf ._ffa ).PaperWidth (_fag ).PaperHeight (_gaa ).Orientation (_edf ._ced ).MarginLeft (_feg .Left ).MarginRight (_feg .Right ).MarginTop (_feg .Top ).MarginBottom (_feg .Bottom ).TimeoutDuration (_edf .getTimeoutDuration ()).WaitTime (_edf ._age ); +for _ ,_ade :=range _edf ._ac {_dbb .WaitReady (_ade .Selector ,_ade .By );};for _ ,_edb :=range _edf ._da {_dbb .WaitVisible (_edb .Selector ,_edb .By );};_fad ,_aag :=_dbb .Query ();if _aag !=nil {return nil ,_aag ;};var _ace _f .CancelFunc ;if _edf ._fc !=nil {_gff ,_ace =_f .WithTimeout (_gff ,*_edf ._fc ); +}else {_gff ,_ace =_f .WithTimeout (_gff ,_fd .Second *15);};defer _ace ();_eff ,_aag :=_dd .ConvertHTML (_gff ,_fad );if _aag !=nil {return nil ,_aag ;};_fbf :=_ee .NewReader (_eff .Data );_dba ,_aag :=_ed .NewPdfReader (_fbf );if _aag !=nil {return nil ,_aag ; +};return _dba .PageList ,nil ;}; + +// ContainerComponent implements creator.containerElement interface. +func (_bd *Document )ContainerComponent (container _cb .Drawable )(_cb .Drawable ,error ){switch container .(type ){case *_cb .Chapter :default:return nil ,_ea .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); +};return _bd ,nil ;};func _aa ()error {_ca :=_fdd .GetLicenseKey ();if _ca ==nil {return _a .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};if !_ca .IsLicensed (){return _a .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); +};return nil ;}; // SetMarginTop sets the left margin. -func (_cef *Document )SetMarginTop (margin _ag .Length ){_cef ._gaa .Top =margin }; +func (_gbe *Document )SetMarginTop (margin _g .Length ){_gbe ._fdb .Top =margin }; -// GetPdfPages is a function that converts provided input content and -func (_ddd *Document )GetPdfPages (ctx _g .Context )([]*_ga .PdfPage ,error ){if _cf :=_ddd .validate ();_cf !=nil {return nil ,_cf ;};return _ddd .extract (ctx ,_ddd ._dda ,_ddd ._dcb ,_ddd .getMargins ());}; \ No newline at end of file +// SetMargins sets the Document Margins. +func (_aca *Document )SetMargins (left ,right ,top ,bottom float64 ){_aca ._fdb .Left =_g .Point (left );_aca ._fdb .Right =_g .Point (right );_aca ._fdb .Top =_g .Point (top );_aca ._fdb .Bottom =_g .Point (bottom );_aca ._bg =_cb .PositionAbsolute ;}; + + +// SetMarginBottom sets the left margin. +func (_gg *Document )SetMarginBottom (margin _g .Length ){_gg ._fdb .Bottom =margin };var ErrContentNotDefined =_a .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); From c9692539f1d9a751793439bc6e1c363b55cc1e62 Mon Sep 17 00:00:00 2001 From: UniDoc Build Date: Mon, 24 Mar 2025 21:04:13 +0000 Subject: [PATCH 6/9] prepare release --- cli/cmd/cmd.go | 72 ++++++------ cli/main.go | 2 +- client/client.go | 263 ++++++++++++++++++++++--------------------- common/common.go | 5 +- content/content.go | 78 ++++++------- go.mod | 24 ++-- go.sum | 58 ++++------ selector/selector.go | 10 +- sizes/sizes.go | 254 ++++++++++++++++++++--------------------- unihtml.go | 176 ++++++++++++++--------------- 10 files changed, 467 insertions(+), 475 deletions(-) diff --git a/cli/cmd/cmd.go b/cli/cmd/cmd.go index 69a2e56..ebfca2f 100644 --- a/cli/cmd/cmd.go +++ b/cli/cmd/cmd.go @@ -9,54 +9,56 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package cmd ;import (_b "context";_d "fmt";_ge "github.com/mitchellh/go-homedir";_ff "github.com/spf13/cobra";_da "github.com/spf13/viper";_eg "github.com/unidoc/unihtml/client";_ec "github.com/unidoc/unihtml/content";_egf "github.com/unidoc/unihtml/sizes"; -_a "github.com/unidoc/unipdf/v3/common";_c "os";_g "path/filepath";_f "time";);type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};type parametersConfig struct{ +package cmd ;import (_cg "context";_e "fmt";_da "github.com/mitchellh/go-homedir";_b "github.com/spf13/cobra";_db "github.com/spf13/viper";_eb "github.com/unidoc/unihtml/client";_ce "github.com/unidoc/unihtml/content";_dg "github.com/unidoc/unihtml/sizes"; +_ee "github.com/unidoc/unipdf/v3/common";_de "os";_a "path/filepath";_d "time";); + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute (){if _dae :=_fea .Execute ();_dae !=nil {_e .Println (_dae );_de .Exit (1);};};var _fea =&_b .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; +func _df (){_eef :=_ee .LogLevelInfo ;if _ad {_eef =_ee .LogLevelDebug ;};if _cd {_eef =_ee .LogLevelTrace ;};_ee .Log =_ee .NewConsoleLogger (_eef );};var _ba string ;func init (){_fea .AddCommand (_g );_g .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072"); +_g .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); +_g .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); +_g .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); +_g .Flags ().Var (&_dc .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_g .Flags ().Var (&_dc .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); +_g .Flags ().Var (&_dc .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_g .Flags ().Var (&_dc .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); +_g .Flags ().Var (&_dc .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_g .Flags ().Var (&_dc .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); +_g .Flags ().Var (&_dc .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_g .Flags ().Var (&_dc .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); +};type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};var _g =&_b .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_gc ,Args :_b .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; +type parametersConfig struct{ // PaperWidth sets the width of the paper. -PaperWidth _egf .LengthFlag `mapstructure:"paper-width"`; +PaperWidth _dg .LengthFlag `mapstructure:"paper-width"`; // PaperHeight is the height of the output paper. -PaperHeight _egf .LengthFlag `mapstructure:"paper-height"`; +PaperHeight _dg .LengthFlag `mapstructure:"paper-height"`; // PageSize is the page size string. -PageSize _egf .PageSize `mapstructure:"page-size"`; +PageSize _dg .PageSize `mapstructure:"page-size"`; // Orientation defines if the output should be in a landscape format. -Orientation _egf .Orientation `mapstructure:"orientation"`; +Orientation _dg .Orientation `mapstructure:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _egf .LengthFlag `mapstructure:"margin-top"`; +MarginTop _dg .LengthFlag `mapstructure:"margin-top"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _egf .LengthFlag `mapstructure:"margin-bottom"`; +MarginBottom _dg .LengthFlag `mapstructure:"margin-bottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _egf .LengthFlag `mapstructure:"margin-left"`; +MarginLeft _dg .LengthFlag `mapstructure:"margin-left"`; // MarginRight sets up the Right Margin for the output. -MarginRight _egf .LengthFlag `mapstructure:"margin-right"`;};func _ae (){_ac :=_a .LogLevelInfo ;if _ab {_ac =_a .LogLevelDebug ;};if _bc {_ac =_a .LogLevelTrace ;};_a .Log =_a .NewConsoleLogger (_ac );};var _dg =&_ff .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_cd ,Args :_ff .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; -func init (){_ba .AddCommand (_dg );_dg .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072");_dg .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); -_dg .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); -_dg .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); -_dg .Flags ().Var (&_gd .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_dg .Flags ().Var (&_gd .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); -_dg .Flags ().Var (&_gd .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_dg .Flags ().Var (&_gd .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); -_dg .Flags ().Var (&_gd .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_dg .Flags ().Var (&_gd .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); -_dg .Flags ().Var (&_gd .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_dg .Flags ().Var (&_gd .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); -};func _cd (cmd *_ff .Command ,_ce []string ){_bd :=_f .Now ();if _fb :=_da .BindPFlags (cmd .Flags ());_fb !=nil {_d .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_fb );_c .Exit (1);};if _dc :=_da .Unmarshal (&_gf );_dc !=nil {_d .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dc ); -_c .Exit (1);};_ae ();_ca ,_cdg :=_c .Stat (_ce [0]);if _cdg !=nil {_d .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_cdg );_c .Exit (1);};if !_ca .IsDir (){if _g .Ext (_ca .Name ())!="\u002e\u0068\u0074m\u006c"{_d .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_ce [0]); -_c .Exit (1);};};_cad ,_cdg :=_c .OpenFile (_ce [1],_c .O_CREATE |_c .O_WRONLY |_c .O_TRUNC ,0700);if _cdg !=nil {_d .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_cdg );_c .Exit (1);};defer _cad .Close ();_ea :=_eg .New (_eg .Options {HTTPS :_gf .Https ,Hostname :_gf .Host ,Port :_gf .Port ,Prefix :_gf .Prefix }); -_bb ,_af :=_b .WithTimeout (_b .Background (),_f .Second *10);defer _af ();_gb :=_f .Now ();var _gbd _ec .Content ;if _ca .IsDir (){_gbd ,_cdg =_ec .NewZipDirectory (_ce [0]);}else {_gbd ,_cdg =_ec .NewHTMLFile (_ce [0]);};if _cdg !=nil {_d .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_cdg ); -_c .Exit (1);};_db ,_cdg :=_eg .BuildHTMLQuery ().PaperWidth (_gd .PaperWidth .Length ).PaperHeight (_gd .PaperHeight .Length ).PageSize (_gd .PageSize ).MarginTop (_gd .MarginTop .Length ).MarginBottom (_gd .MarginBottom .Length ).MarginLeft (_gd .MarginLeft .Length ).MarginRight (_gd .MarginRight .Length ).Orientation (_gd .Orientation ).SetContent (_gbd ).Query (); -if _cdg !=nil {_d .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_cdg );_c .Exit (1);};_be ,_cdg :=_ea .ConvertHTML (_bb ,_db );if _cdg !=nil {_d .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_cdg );_c .Exit (1);};_a .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_f .Since (_gb )); -_gb =_f .Now ();_ ,_cdg =_cad .Write (_be .Data );if _cdg !=nil {_d .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_cdg );_c .Exit (1);};_a .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_f .Since (_gb )); -_d .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_f .Since (_bd ));};var (_gf =generateConfig {};_gd =parametersConfig {PaperWidth :_egf .LengthFlag {Length :_egf .Inch (8.5).Millimeters ()},PaperHeight :_egf .LengthFlag {Length :_egf .Inch (11).Millimeters ()},Orientation :_egf .Portrait ,MarginTop :_egf .LengthFlag {Length :_egf .Millimeter (10)},MarginBottom :_egf .LengthFlag {Length :_egf .Millimeter (10)},MarginLeft :_egf .LengthFlag {Length :_egf .Millimeter (10)},MarginRight :_egf .LengthFlag {Length :_egf .Millimeter (10)}}; -);var (_ab ,_bc bool ;); - -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. -func Execute (){if _bde :=_ba .Execute ();_bde !=nil {_d .Println (_bde );_c .Exit (1);};};var _cb string ;func init (){_ff .OnInitialize (_gg );_ba .PersistentFlags ().BoolVarP (&_ab ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065"); -_ba .PersistentFlags ().BoolVarP (&_bc ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); -_ba .PersistentFlags ().StringVar (&_cb ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); -_ba .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};func _gg (){if _cb !=""{_da .SetConfigFile (_cb ); -}else {_aa ,_ad :=_ge .Dir ();if _ad !=nil {_d .Println (_ad );_c .Exit (1);};_da .AddConfigPath (_aa );_da .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063");};_da .AutomaticEnv ();if _eb :=_da .ReadInConfig ();_eb ==nil {_d .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_da .ConfigFileUsed ()); -};};var _ba =&_ff .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; +MarginRight _dg .LengthFlag `mapstructure:"margin-right"`;};var (_ad ,_cd bool ;);var (_f =generateConfig {};_dc =parametersConfig {PaperWidth :_dg .LengthFlag {Length :_dg .Inch (8.5).Millimeters ()},PaperHeight :_dg .LengthFlag {Length :_dg .Inch (11).Millimeters ()},Orientation :_dg .Portrait ,MarginTop :_dg .LengthFlag {Length :_dg .Millimeter (10)},MarginBottom :_dg .LengthFlag {Length :_dg .Millimeter (10)},MarginLeft :_dg .LengthFlag {Length :_dg .Millimeter (10)},MarginRight :_dg .LengthFlag {Length :_dg .Millimeter (10)}}; +);func init (){_b .OnInitialize (_fa );_fea .PersistentFlags ().BoolVarP (&_ad ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065");_fea .PersistentFlags ().BoolVarP (&_cd ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); +_fea .PersistentFlags ().StringVar (&_ba ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); +_fea .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};func _fa (){if _ba !=""{_db .SetConfigFile (_ba ); +}else {_baf ,_dd :=_da .Dir ();if _dd !=nil {_e .Println (_dd );_de .Exit (1);};_db .AddConfigPath (_baf );_db .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063");};_db .AutomaticEnv ();if _bgc :=_db .ReadInConfig (); +_bgc ==nil {_e .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_db .ConfigFileUsed ());};};func _gc (cmd *_b .Command ,_be []string ){_bc :=_d .Now ();if _ag :=_db .BindPFlags (cmd .Flags ());_ag !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ag ); +_de .Exit (1);};if _fe :=_db .Unmarshal (&_f );_fe !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_fe );_de .Exit (1);};_df ();_agb ,_bg :=_de .Stat (_be [0]);if _bg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_bg ); +_de .Exit (1);};if !_agb .IsDir (){if _a .Ext (_agb .Name ())!="\u002e\u0068\u0074m\u006c"{_e .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_be [0]); +_de .Exit (1);};};_fec ,_bg :=_de .OpenFile (_be [1],_de .O_CREATE |_de .O_WRONLY |_de .O_TRUNC ,0700);if _bg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_bg );_de .Exit (1);};defer _fec .Close ();_gb :=_eb .New (_eb .Options {HTTPS :_f .Https ,Hostname :_f .Host ,Port :_f .Port ,Prefix :_f .Prefix }); +_bd ,_dcg :=_cg .WithTimeout (_cg .Background (),_d .Second *10);defer _dcg ();_bf :=_d .Now ();var _cb _ce .Content ;if _agb .IsDir (){_cb ,_bg =_ce .NewZipDirectory (_be [0]);}else {_cb ,_bg =_ce .NewHTMLFile (_be [0]);};if _bg !=nil {_e .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_bg ); +_de .Exit (1);};_dbb ,_bg :=_eb .BuildHTMLQuery ().PaperWidth (_dc .PaperWidth .Length ).PaperHeight (_dc .PaperHeight .Length ).PageSize (_dc .PageSize ).MarginTop (_dc .MarginTop .Length ).MarginBottom (_dc .MarginBottom .Length ).MarginLeft (_dc .MarginLeft .Length ).MarginRight (_dc .MarginRight .Length ).Orientation (_dc .Orientation ).SetContent (_cb ).Query (); +if _bg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_bg );_de .Exit (1);};_eec ,_bg :=_gb .ConvertHTML (_bd ,_dbb );if _bg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_bg );_de .Exit (1);};_ee .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_d .Since (_bf )); +_bf =_d .Now ();_ ,_bg =_fec .Write (_eec .Data );if _bg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_bg );_de .Exit (1);};_ee .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_d .Since (_bf )); +_e .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_d .Since (_bc ));}; \ No newline at end of file diff --git a/cli/main.go b/cli/main.go index c33ee30..48b52ba 100644 --- a/cli/main.go +++ b/cli/main.go @@ -9,4 +9,4 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package main ;import _e "github.com/unidoc/unihtml/cli/cmd";func main (){_e .Execute ()}; \ No newline at end of file +package main ;import _a "github.com/unidoc/unihtml/cli/cmd";func main (){_a .Execute ()}; \ No newline at end of file diff --git a/client/client.go b/client/client.go index 4223495..ddcf12e 100644 --- a/client/client.go +++ b/client/client.go @@ -11,202 +11,203 @@ // Package client contains HTML Converter HTTP Client. The Client implements htmlcreator.HTMLConverter interface // for the UniPDF module and can be used as a plugin for the UniPDF creator.Creator. -package client ;import (_db "bytes";_dac "compress/flate";_de "compress/gzip";_f "context";_da "encoding/json";_fe "errors";_dbc "fmt";_cd "github.com/unidoc/unihtml/content";_ga "github.com/unidoc/unihtml/selector";_gg "github.com/unidoc/unihtml/sizes"; -_aa "github.com/unidoc/unipdf/v3/common";_d "io";_df "net";_ab "net/http";_af "net/url";_g "strconv";_a "strings";_c "time";); +package client ;import (_a "bytes";_dd "compress/flate";_gb "compress/gzip";_g "context";_b "encoding/json";_d "errors";_ba "fmt";_bb "github.com/unidoc/unihtml/content";_be "github.com/unidoc/unihtml/selector";_f "github.com/unidoc/unihtml/sizes";_ag "github.com/unidoc/unipdf/v3/common"; +_ge "io";_gd "net";_eb "net/http";_bg "net/url";_e "strconv";_ac "strings";_bd "time";); -// ParseOptions parses options for the Client. -func ParseOptions (connectPath string )(Options ,error ){if !_a .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_aag ,_b :=_af .Parse (connectPath );if _b !=nil {return Options {},_dbc .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); -};var _fc int ;if _aag .Port ()!=""{_fc ,_b =_g .Atoi (_aag .Port ());if _b !=nil {return Options {},_dbc .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_b );}; -};return Options {Hostname :_aag .Hostname (),Port :_fc ,HTTPS :_aag .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_aag .Path },nil ;}; +// WaitVisible waits for the selector to get visible. +func (_bfg *QueryBuilder )WaitVisible (selector string ,by _be .ByType )*QueryBuilder {_bfg ._fd .RenderParameters .WaitVisible =append (_bfg ._fd .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _bfg ;};var (ErrNotFound =_d .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed"); +ErrBadRequest =_d .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074");ErrNotImplemented =_d .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_d .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072"); +ErrBadGateway =_d .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079");ErrUnauthorized =_d .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_d .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074"); +); // Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. -type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;TimeoutDuration _c .Duration ;}; +type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;TimeoutDuration _bd .Duration ;};func (_ec *Client )setQueryValues (_gbb *_eb .Request ,_eg *Query ){_cdg :=_gbb .URL .Query (); +_egc :=_eg .PageParameters ;if _egc .PageSize !=nil {_cdg .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_egc .PageSize .String ());};if _egc .PaperHeight !=nil {_cdg .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_egc .PaperHeight .String ()); +};if _egc .PaperWidth !=nil {_cdg .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_egc .PaperWidth .String ());};if _egc .MarginTop !=nil {_cdg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_egc .MarginTop .String ()); +};if _egc .MarginBottom !=nil {_cdg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_egc .MarginBottom .String ());};if _egc .MarginRight !=nil {_cdg .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_egc .MarginRight .String ()); +};if _egc .MarginLeft !=nil {_cdg .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_egc .MarginLeft .String ());};if _egc .Orientation ==_f .Landscape {_cdg .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_egc .Orientation .String ()); +};if _eg .RenderParameters .WaitTime !=0{_cdg .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_e .FormatInt (int64 (_eg .RenderParameters .WaitTime /_bd .Millisecond ),10));};_gbb .URL .RawQuery =_cdg .Encode (); +}; -// Addr gets the HTTP address URI used by the http.Client. -func (_dacf *Options )Addr ()string {_cbc :=_a .Builder {};_cbc .WriteString ("\u0068\u0074\u0074\u0070");if _dacf .HTTPS {_cbc .WriteRune ('s');};_cbc .WriteString ("\u003a\u002f\u002f");_cbc .WriteString (_dacf .Hostname );_cbc .WriteRune (':');_cbc .WriteString (_g .Itoa (_dacf .Port )); -if _dacf .Prefix !=""{_cbc .WriteString (_dacf .Prefix );};return _cbc .String ();}; +// WithDefaultTimeout sets the DefaultTimeout option for the client options. +func WithDefaultTimeout (option _bd .Duration )Option {return func (_ed *Options ){_ed .DefaultTimeout =option };}; -// BuildHTMLQuery creates a Query builder that is supposed to create valid -func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; +// SetContent sets custom data with it's content type. +func (_aebg *QueryBuilder )SetContent (content _bb .Content )*QueryBuilder {if _aebg ._ece !=nil {return _aebg ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _aebg ._fd .ContentType !=""{_aebg ._ece =ErrContentTypeDeclared ; +return _aebg ;};if content .ContentType ()==""{_aebg ._ece =_ba .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _aebg ; +};_aebg ._fd .Content =content .Data ();_aebg ._fd .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _aebg ._fd .ContentType !=""{_aebg ._ece =ErrContentTypeDeclared ;return _aebg ;};_aebg ._fd .URL =string (content .Data ());_aebg ._fd .ContentType =content .ContentType (); +default:_aebg ._ece =_ba .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ());return _aebg ;};_aebg ._fd .Method =content .Method (); +return _aebg ;}; -// MarginLeft sets up the MarginLeft parameter for the query. -func (_cdd *QueryBuilder )MarginLeft (marginLeft _gg .Length )*QueryBuilder {_cdd ._bade .PageParameters .MarginLeft =marginLeft ;return _cdd ;}; +// Options are the client options used by the HTTP client. +type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _bd .Duration ;Prefix string ;}; -// BySelector is a structure that defines a selector with it's query 'by' type. -type BySelector struct{Selector string `json:"selector"`;By _ga .ByType `json:"by"`;}; +// Validate checks if the parameters are valid. +func (_ege *PageParameters )Validate ()error {if _ege .PaperWidth !=nil {if _ege .PaperWidth .Millimeters ()< 0{return _d .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); +};};if _ege .PaperHeight !=nil {if _ege .PaperHeight .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); +};};if _ege .MarginTop !=nil {if _ege .MarginTop .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _ege .MarginBottom !=nil {if _ege .MarginBottom .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); +};};if _ege .MarginLeft !=nil {if _ege .MarginLeft .Millimeters ()< 0{return _d .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};}; +if _ege .MarginRight !=nil {if _ege .MarginRight .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); +};};if _ege .PageSize !=nil &&!_ege .PageSize .IsAPageSize (){return _d .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; -// WithDefaultTimeout sets the DefaultTimeout option for the client options. -func WithDefaultTimeout (option _c .Duration )Option {return func (_cbb *Options ){_cbb .DefaultTimeout =option };}; +// Portrait sets up the portrait page orientation. +func (_cdd *QueryBuilder )Portrait ()*QueryBuilder {_cdd ._fd .PageParameters .Orientation =_f .Portrait ;return _cdd ;}; -// Option is a function that changes client options. -type Option func (_aad *Options );var (ErrNotFound =_fe .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_fe .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074");ErrNotImplemented =_fe .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064"); -ErrInternalError =_fe .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_fe .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079");ErrUnauthorized =_fe .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064"); -ErrTimedOut =_fe .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); +// PageSize sets up the PageSize parameter for the query. +func (_ccd *QueryBuilder )PageSize (pageSize _f .PageSize )*QueryBuilder {if pageSize !=_f .Undefined {_ccd ._fd .PageParameters .PageSize =&pageSize ;};return _ccd ;}; // MarginBottom sets up the MarginBottom parameter for the query. -func (_ae *QueryBuilder )MarginBottom (marginBottom _gg .Length )*QueryBuilder {_ae ._bade .PageParameters .MarginBottom =marginBottom ;return _ae ;}; +func (_aa *QueryBuilder )MarginBottom (marginBottom _f .Length )*QueryBuilder {_aa ._fd .PageParameters .MarginBottom =marginBottom ;return _aa ;}; // WaitTime sets the minimum load time parameter for the page rendering. -func (_ggd *QueryBuilder )WaitTime (d _c .Duration )*QueryBuilder {_ggd ._bade .RenderParameters .WaitTime =d ;return _ggd ;}; +func (_deg *QueryBuilder )WaitTime (d _bd .Duration )*QueryBuilder {_deg ._fd .RenderParameters .WaitTime =d ;return _deg ;}; -// Portrait sets up the portrait page orientation. -func (_cbg *QueryBuilder )Portrait ()*QueryBuilder {_cbg ._bade .PageParameters .Orientation =_gg .Portrait ;return _cbg ;};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`; -Method string `json:"method"`;ExpiresAt int64 `json:"expiresAt"`;TimeoutDuration int64 `json:"timeoutDuration,omitempty"`;PageParameters ;RenderParameters ;}; +// RenderParameters are the parameters related with the rendering. +type RenderParameters struct{WaitTime _bd .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; -// WithPrefix sets the client prefix. -func WithPrefix (prefix string )Option {return func (_ce *Options ){_ce .Prefix =prefix }}; +// ConvertHTML converts provided Query input into PDF file data. +// Implements creator.HTMLConverter interface. +func (_cc *Client )ConvertHTML (ctx _g .Context ,q *Query )(*PDFResponse ,error ){if _fc :=q .Validate ();_fc !=nil {return nil ,_fc ;};_gec ,_ccg :=_cc .getGenerateRequest (ctx ,q );if _ccg !=nil {return nil ,_ccg ;};_ag .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_gec .Method ,_gec .URL .Hostname (),_gec .URL .Path ,_gec .Header ,_gec .URL .Query ()); +_df :=*_cc .Client ;if q .TimeoutDuration !=0{_df .Timeout =q .TimeoutDuration ;};_bf ,_ccg :=_df .Do (_gec );if _ccg !=nil {return nil ,_ccg ;};var _ebc error ;switch _bf .StatusCode {case _eb .StatusNotFound :_ebc =ErrNotFound ;case _eb .StatusBadRequest :_ebc =ErrBadRequest ; +case _eb .StatusNotImplemented :_ebc =ErrNotImplemented ;case _eb .StatusUnauthorized :_ebc =ErrUnauthorized ;case _eb .StatusRequestTimeout :_ebc =ErrTimedOut ;case _eb .StatusCreated :default:_ebc =ErrInternalError ;};_dc :=_bf .Body ;switch _bf .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_dc ,_ccg =_gb .NewReader (_bf .Body ); +if _ccg !=nil {return nil ,_ccg ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_dc =_dd .NewReader (_bf .Body );case "":default:return nil ,_ba .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_bf .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); +};_af ,_ccg :=_ge .ReadAll (_dc );if _ccg !=nil &&_ebc ==nil {return nil ,_ba .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_ccg );};_ag .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_bf .StatusCode ,_gec .Method ,_gec .URL .Host ,_gec .URL .Path ); +if _ebc !=nil {return nil ,_ba .Errorf ("\u0025\u0073\u0020%\u0077",string (_af ),_ebc );};_aea :=_bf .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_ag .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_aea ); +return &PDFResponse {ID :_aea ,Data :_af },nil ;}; -// PDFResponse is the response used by the HTMLConverter. -type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; +// Validate checks if provided Query is valid. +func (_agb *Query )Validate ()error {switch _agb .Method {case "\u0077\u0065\u0062":if _agb .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_agb .Content )==0{return ErrMissingData ;};if _agb .ContentType ==""{return ErrContentType ; +};default:return _ba .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_agb .Method );};if _afa :=_agb .PageParameters .Validate (); +_afa !=nil {return _afa ;};if _geg :=_agb .RenderParameters .Validate ();_geg !=nil {return _geg ;};return nil ;};var (ErrMissingData =_d .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061");ErrContentType =_d .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065"); +ErrContentTypeDeclared =_d .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064");); -// QueryBuilder is the query that converts HTMLConverter defined data -type QueryBuilder struct{_bade Query ;_afb error ;}; +// PaperWidth sets up the PaperWidth (in cm) parameter for the query. +func (_dbc *QueryBuilder )PaperWidth (paperWidth _f .Length )*QueryBuilder {_dbc ._fd .PageParameters .PaperWidth =paperWidth ;return _dbc ;}; // PageParameters are the query parameters used in the PDF generation. type PageParameters struct{ // PaperWidth sets the width of the paper. -PaperWidth _gg .Length `schema:"paper-width" json:"paperWidth"`; +PaperWidth _f .Length `schema:"paper-width" json:"paperWidth"`; // PaperHeight is the height of the output paper. -PaperHeight _gg .Length `schema:"paper-height" json:"paperHeight"`; +PaperHeight _f .Length `schema:"paper-height" json:"paperHeight"`; // PageSize is the page size string. -PageSize *_gg .PageSize `schema:"page-size" json:"pageSize"`; +PageSize *_f .PageSize `schema:"page-size" json:"pageSize"`; // Orientation defines if the output should be in a landscape format. -Orientation _gg .Orientation `schema:"orientation" json:"orientation"`; +Orientation _f .Orientation `schema:"orientation" json:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _gg .Length `schema:"margin-top" json:"marginTop"`; +MarginTop _f .Length `schema:"margin-top" json:"marginTop"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _gg .Length `schema:"margin-bottom" json:"marginBottom"`; +MarginBottom _f .Length `schema:"margin-bottom" json:"marginBottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _gg .Length `schema:"margin-left" json:"marginLeft"`; +MarginLeft _f .Length `schema:"margin-left" json:"marginLeft"`; // MarginRight sets up the Right Margin for the output. -MarginRight _gg .Length `schema:"margin-right" json:"marginRight"`;}; +MarginRight _f .Length `schema:"margin-right" json:"marginRight"`;}; -// Client is a structure that is a HTTP client for the unihtml server. -type Client struct{Options Options ;Client *_ab .Client ;};func (_ffgf *Client )setQueryValues (_fae *_ab .Request ,_dbe *Query ){_ffb :=_fae .URL .Query ();_ggcf :=_dbe .PageParameters ;if _ggcf .PageSize !=nil {_ffb .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_ggcf .PageSize .String ()); -};if _ggcf .PaperHeight !=nil {_ffb .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_ggcf .PaperHeight .String ());};if _ggcf .PaperWidth !=nil {_ffb .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_ggcf .PaperWidth .String ()); -};if _ggcf .MarginTop !=nil {_ffb .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_ggcf .MarginTop .String ());};if _ggcf .MarginBottom !=nil {_ffb .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_ggcf .MarginBottom .String ()); -};if _ggcf .MarginRight !=nil {_ffb .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_ggcf .MarginRight .String ());};if _ggcf .MarginLeft !=nil {_ffb .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_ggcf .MarginLeft .String ()); -};if _ggcf .Orientation ==_gg .Landscape {_ffb .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_ggcf .Orientation .String ());};if _dbe .RenderParameters .WaitTime !=0{_ffb .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_g .FormatInt (int64 (_dbe .RenderParameters .WaitTime /_c .Millisecond ),10)); -};_fae .URL .RawQuery =_ffb .Encode ();}; - -// SetContent sets custom data with it's content type. -func (_fg *QueryBuilder )SetContent (content _cd .Content )*QueryBuilder {if _fg ._afb !=nil {return _fg ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _fg ._bade .ContentType !=""{_fg ._afb =ErrContentTypeDeclared ; -return _fg ;};if content .ContentType ()==""{_fg ._afb =_dbc .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _fg ;}; -_fg ._bade .Content =content .Data ();_fg ._bade .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _fg ._bade .ContentType !=""{_fg ._afb =ErrContentTypeDeclared ;return _fg ;};_fg ._bade .URL =string (content .Data ());_fg ._bade .ContentType =content .ContentType (); -default:_fg ._afb =_dbc .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ());return _fg ;};_fg ._bade .Method =content .Method (); -return _fg ;}; +// ParseOptions parses options for the Client. +func ParseOptions (connectPath string )(Options ,error ){if !_ac .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_fa ,_ad :=_bg .Parse (connectPath );if _ad !=nil {return Options {},_ba .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); +};var _ga int ;if _fa .Port ()!=""{_ga ,_ad =_e .Atoi (_fa .Port ());if _ad !=nil {return Options {},_ba .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_ad );}; +};return Options {Hostname :_fa .Hostname (),Port :_ga ,HTTPS :_fa .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_fa .Path },nil ;}; // New creates new client with provided options. -func New (o Options )*Client {o .DefaultTimeout =_c .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _bc =&_ab .Transport {DialContext :(&_df .Dialer {Timeout :5*_c .Second }).DialContext ,TLSHandshakeTimeout :5*_c .Second }; -_aa .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_ab .Client {Transport :_bc ,Timeout :o .DefaultTimeout }};}; +func New (o Options )*Client {o .DefaultTimeout =_bd .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _ddg =&_eb .Transport {DialContext :(&_gd .Dialer {Timeout :5*_bd .Second }).DialContext ,TLSHandshakeTimeout :5*_bd .Second }; +_ag .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_eb .Client {Transport :_ddg ,Timeout :o .DefaultTimeout }};}; -// WaitReady waits for the selector to get ready - 'loaded'. -func (_bf *QueryBuilder )WaitReady (selector string ,by _ga .ByType )*QueryBuilder {_bf ._bade .RenderParameters .WaitReady =append (_bf ._bade .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _bf ;}; +// Orientation sets the page orientation for the Query. +func (_gff *QueryBuilder )Orientation (orientation _f .Orientation )*QueryBuilder {_gff ._fd .PageParameters .Orientation =orientation ;return _gff ;}; -// DefaultPageParameters creates default parameters. -func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_gg .Portrait }}; +// Validate checks the validity of the RenderParameters. +func (_bga *RenderParameters )Validate ()error {if _bga .WaitTime > _bd .Minute *3{return _d .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); +};for _ ,_aee :=range _bga .WaitReady {if _ebe :=_aee .Validate ();_ebe !=nil {return _ba .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_ebe ); +};};return nil ;}; -// Validate checks if the parameters are valid. -func (_bab *PageParameters )Validate ()error {if _bab .PaperWidth !=nil {if _bab .PaperWidth .Millimeters ()< 0{return _fe .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); -};};if _bab .PaperHeight !=nil {if _bab .PaperHeight .Millimeters ()< 0{return _fe .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); -};};if _bab .MarginTop !=nil {if _bab .MarginTop .Millimeters ()< 0{return _fe .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _bab .MarginBottom !=nil {if _bab .MarginBottom .Millimeters ()< 0{return _fe .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); -};};if _bab .MarginLeft !=nil {if _bab .MarginLeft .Millimeters ()< 0{return _fe .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");}; -};if _bab .MarginRight !=nil {if _bab .MarginRight .Millimeters ()< 0{return _fe .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); -};};if _bab .PageSize !=nil &&!_bab .PageSize .IsAPageSize (){return _fe .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;};var (ErrMissingData =_fe .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061"); -ErrContentType =_fe .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065");ErrContentTypeDeclared =_fe .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064"); -); +// WithPort sets the Port option for the client options. +func WithPort (option int )Option {return func (_cdf *Options ){_cdf .Port =option }};func (_bag *Client )getGenerateRequest (_beg _g .Context ,_ab *Query )(*_eb .Request ,error ){_ddf :=generatePDFRequestV1 {Method :_ab .Method ,PageParameters :_ab .PageParameters ,RenderParameters :_ab .RenderParameters ,TimeoutDuration :int64 (_ab .TimeoutDuration )}; +switch _ab .Method {case "\u0077\u0065\u0062":_ddf .ContentURL =_ab .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_ddf .ContentType =_ab .ContentType ;_ddf .Content =_ab .Content ;};_cb :=new (_a .Buffer );if _gf :=_b .NewEncoder (_cb ).Encode (&_ddf ); +_gf !=nil {return nil ,_ba .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_gf );};_bgf :=_bag .Options .Addr ();_bgf =_ba .Sprintf ("\u0025s\u002f\u0076\u0031\u002f\u0070\u0064f",_bgf ); +_cd ,_bfe :=_eb .NewRequest ("\u0050\u004f\u0053\u0054",_bgf ,_cb );if _bfe !=nil {return nil ,_bfe ;};_cd .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); +_cd .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); +_cd =_cd .WithContext (_beg );return _cd ,nil ;}; -// PageSize sets up the PageSize parameter for the query. -func (_cga *QueryBuilder )PageSize (pageSize _gg .PageSize )*QueryBuilder {if pageSize !=_gg .Undefined {_cga ._bade .PageParameters .PageSize =&pageSize ;};return _cga ;}; +// Addr gets the HTTP address URI used by the http.Client. +func (_ddd *Options )Addr ()string {_aeb :=_ac .Builder {};_aeb .WriteString ("\u0068\u0074\u0074\u0070");if _ddd .HTTPS {_aeb .WriteRune ('s');};_aeb .WriteString ("\u003a\u002f\u002f");_aeb .WriteString (_ddd .Hostname );_aeb .WriteRune (':');_aeb .WriteString (_e .Itoa (_ddd .Port )); +if _ddd .Prefix !=""{_aeb .WriteString (_ddd .Prefix );};return _aeb .String ();}; -// PaperWidth sets up the PaperWidth (in cm) parameter for the query. -func (_aagg *QueryBuilder )PaperWidth (paperWidth _gg .Length )*QueryBuilder {_aagg ._bade .PageParameters .PaperWidth =paperWidth ;return _aagg ;}; +// MarginTop sets up the MarginTop parameter for the query. +func (_ce *QueryBuilder )MarginTop (marginTop _f .Length )*QueryBuilder {_ce ._fd .PageParameters .MarginTop =marginTop ;return _ce ;}; -// Validate checks if the QueryBuilder had no errors during composition and creation. -func (_eg *QueryBuilder )Validate ()error {if _eg ._afb !=nil {return _eg ._afb ;};return _eg ._bade .Validate ();}; +// Landscape sets up the landscape portrait orientation. +func (_gdg *QueryBuilder )Landscape ()*QueryBuilder {_gdg ._fd .PageParameters .Orientation =_f .Landscape ;return _gdg ;}; + +// WithPrefix sets the client prefix. +func WithPrefix (prefix string )Option {return func (_ada *Options ){_ada .Prefix =prefix }}; + +// PaperHeight sets up the PaperHeight (in cm) parameter for the query. +func (_aga *QueryBuilder )PaperHeight (paperHeight _f .Length )*QueryBuilder {_aga ._fd .PageParameters .PaperHeight =paperHeight ;return _aga ;}; // Validate checks validity of the selector. -func (_dgd BySelector )Validate ()error {if _dgd .Selector ==""{return _fe .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _geb :=_dgd .By .Validate ();_geb !=nil {return _geb ; +func (_cdfg BySelector )Validate ()error {if _cdfg .Selector ==""{return _d .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _ebd :=_cdfg .By .Validate ();_ebd !=nil {return _ebd ; };return nil ;}; -// Err gets the error which could occur in the query. -func (_edb *QueryBuilder )Err ()error {return _edb ._afb }; +// Option is a function that changes client options. +type Option func (_bfb *Options ); -// Validate checks the validity of the RenderParameters. -func (_ad *RenderParameters )Validate ()error {if _ad .WaitTime > _c .Minute *3{return _fe .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); -};for _ ,_cc :=range _ad .WaitReady {if _cec :=_cc .Validate ();_cec !=nil {return _dbc .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_cec ); -};};return nil ;}; +// QueryBuilder is the query that converts HTMLConverter defined data +type QueryBuilder struct{_fd Query ;_ece error ;}; -// HealthCheck connects to the server and check the health status of the server. -func (_bb *Client )HealthCheck (ctx _f .Context )error {_cf :=_bb .Options .Addr ();_cf =_dbc .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_cf );_ed ,_ea :=_ab .NewRequest ("\u0047\u0045\u0054",_cf ,nil );if _ea !=nil {return _ea ;};_ed =_ed .WithContext (ctx ); -_deb ,_ea :=_bb .Client .Do (_ed );if _ea !=nil {return _ea ;};switch _deb .StatusCode {case _ab .StatusOK :return nil ;case _ab .StatusNotFound :return ErrNotFound ;case _ab .StatusInternalServerError :return ErrInternalError ;case _ab .StatusBadGateway :return ErrBadGateway ; -default:return ErrNotImplemented ;};}; +// WithHTTPS sets the TLS option for the client options. +func WithHTTPS (useHTTPS bool )Option {return func (_acd *Options ){_acd .HTTPS =useHTTPS }}; -// ConvertHTML converts provided Query input into PDF file data. -// Implements creator.HTMLConverter interface. -func (_cdg *Client )ConvertHTML (ctx _f .Context ,q *Query )(*PDFResponse ,error ){if _fca :=q .Validate ();_fca !=nil {return nil ,_fca ;};_ff ,_dg :=_cdg .getGenerateRequest (ctx ,q );if _dg !=nil {return nil ,_dg ;};_aa .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_ff .Method ,_ff .URL .Hostname (),_ff .URL .Path ,_ff .Header ,_ff .URL .Query ()); -_ede :=*_cdg .Client ;if q .TimeoutDuration !=0{_ede .Timeout =q .TimeoutDuration ;};_ffg ,_dg :=_ede .Do (_ff );if _dg !=nil {return nil ,_dg ;};var _dc error ;switch _ffg .StatusCode {case _ab .StatusNotFound :_dc =ErrNotFound ;case _ab .StatusBadRequest :_dc =ErrBadRequest ; -case _ab .StatusNotImplemented :_dc =ErrNotImplemented ;case _ab .StatusUnauthorized :_dc =ErrUnauthorized ;case _ab .StatusRequestTimeout :_dc =ErrTimedOut ;case _ab .StatusCreated :default:_dc =ErrInternalError ;};_gc :=_ffg .Body ;switch _ffg .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_gc ,_dg =_de .NewReader (_ffg .Body ); -if _dg !=nil {return nil ,_dg ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_gc =_dac .NewReader (_ffg .Body );case "":default:return nil ,_dbc .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_ffg .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); -};_ggc ,_dg :=_d .ReadAll (_gc );if _dg !=nil &&_dc ==nil {return nil ,_dbc .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_dg );};_aa .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_ffg .StatusCode ,_ff .Method ,_ff .URL .Host ,_ff .URL .Path ); -if _dc !=nil {return nil ,_dbc .Errorf ("\u0025\u0073\u0020%\u0077",string (_ggc ),_dc );};_cb :=_ffg .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_aa .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_cb ); -return &PDFResponse {ID :_cb ,Data :_ggc },nil ;}; +// TimeoutDuration sets the server query duration timeout. +// Once the timeout is reached the server will return an error. +func (_adaf *QueryBuilder )TimeoutDuration (d _bd .Duration )*QueryBuilder {_adaf ._fd .TimeoutDuration =d ;return _adaf ;}; -// Orientation sets the page orientation for the Query. -func (_ecd *QueryBuilder )Orientation (orientation _gg .Orientation )*QueryBuilder {_ecd ._bade .PageParameters .Orientation =orientation ;return _ecd ;}; +// WaitReady waits for the selector to get ready - 'loaded'. +func (_ea *QueryBuilder )WaitReady (selector string ,by _be .ByType )*QueryBuilder {_ea ._fd .RenderParameters .WaitReady =append (_ea ._fd .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _ea ;}; -// WithPort sets the Port option for the client options. -func WithPort (option int )Option {return func (_fb *Options ){_fb .Port =option }}; +// Client is a structure that is a HTTP client for the unihtml server. +type Client struct{Options Options ;Client *_eb .Client ;}; -// Landscape sets up the landscape portrait orientation. -func (_ggb *QueryBuilder )Landscape ()*QueryBuilder {_ggb ._bade .PageParameters .Orientation =_gg .Landscape ;return _ggb ;}; +// WithHostname sets the Hostname option for the client options. +func WithHostname (option string )Option {return func (_baa *Options ){_baa .Hostname =option }}; -// WithHTTPS sets the TLS option for the client options. -func WithHTTPS (useHTTPS bool )Option {return func (_bad *Options ){_bad .HTTPS =useHTTPS }}; +// BySelector is a structure that defines a selector with it's query 'by' type. +type BySelector struct{Selector string `json:"selector"`;By _be .ByType `json:"by"`;};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`;Method string `json:"method"`; +ExpiresAt int64 `json:"expiresAt"`;TimeoutDuration int64 `json:"timeoutDuration,omitempty"`;PageParameters ;RenderParameters ;}; -// PaperHeight sets up the PaperHeight (in cm) parameter for the query. -func (_aadb *QueryBuilder )PaperHeight (paperHeight _gg .Length )*QueryBuilder {_aadb ._bade .PageParameters .PaperHeight =paperHeight ;return _aadb ;}; +// DefaultPageParameters creates default parameters. +func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_f .Portrait }}; -// MarginTop sets up the MarginTop parameter for the query. -func (_ee *QueryBuilder )MarginTop (marginTop _gg .Length )*QueryBuilder {_ee ._bade .PageParameters .MarginTop =marginTop ;return _ee ;}; +// Err gets the error which could occur in the query. +func (_db *QueryBuilder )Err ()error {return _db ._ece }; // MarginRight sets up the MarginRight parameter for the query. -func (_cge *QueryBuilder )MarginRight (marginRight _gg .Length )*QueryBuilder {_cge ._bade .PageParameters .MarginRight =marginRight ;return _cge ;}; +func (_fgb *QueryBuilder )MarginRight (marginRight _f .Length )*QueryBuilder {_fgb ._fd .PageParameters .MarginRight =marginRight ;return _fgb ;}; -// WaitVisible waits for the selector to get visible. -func (_ef *QueryBuilder )WaitVisible (selector string ,by _ga .ByType )*QueryBuilder {_ef ._bade .RenderParameters .WaitVisible =append (_ef ._bade .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _ef ;}; - -// WithHostname sets the Hostname option for the client options. -func WithHostname (option string )Option {return func (_dcb *Options ){_dcb .Hostname =option }}; +// MarginLeft sets up the MarginLeft parameter for the query. +func (_de *QueryBuilder )MarginLeft (marginLeft _f .Length )*QueryBuilder {_de ._fd .PageParameters .MarginLeft =marginLeft ;return _de ;}; // Query gets the Query from provided query builder. If some error occurred during build process // or the input is not valid the function would return an error. -func (_cg *QueryBuilder )Query ()(*Query ,error ){if _bd :=_cg .Validate ();_bd !=nil {return nil ,_bd ;};return &_cg ._bade ,nil ;}; +func (_ca *QueryBuilder )Query ()(*Query ,error ){if _bbc :=_ca .Validate ();_bbc !=nil {return nil ,_bbc ;};return &_ca ._fd ,nil ;}; -// Validate checks if provided Query is valid. -func (_gb *Query )Validate ()error {switch _gb .Method {case "\u0077\u0065\u0062":if _gb .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_gb .Content )==0{return ErrMissingData ;};if _gb .ContentType ==""{return ErrContentType ; -};default:return _dbc .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_gb .Method );};if _dd :=_gb .PageParameters .Validate (); -_dd !=nil {return _dd ;};if _gcc :=_gb .RenderParameters .Validate ();_gcc !=nil {return _gcc ;};return nil ;}; +// HealthCheck connects to the server and check the health status of the server. +func (_ae *Client )HealthCheck (ctx _g .Context )error {_fg :=_ae .Options .Addr ();_fg =_ba .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_fg );_cf ,_da :=_eb .NewRequest ("\u0047\u0045\u0054",_fg ,nil );if _da !=nil {return _da ;};_cf =_cf .WithContext (ctx ); +_ebg ,_da :=_ae .Client .Do (_cf );if _da !=nil {return _da ;};switch _ebg .StatusCode {case _eb .StatusOK :return nil ;case _eb .StatusNotFound :return ErrNotFound ;case _eb .StatusInternalServerError :return ErrInternalError ;case _eb .StatusBadGateway :return ErrBadGateway ; +default:return ErrNotImplemented ;};}; -// RenderParameters are the parameters related with the rendering. -type RenderParameters struct{WaitTime _c .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; +// Validate checks if the QueryBuilder had no errors during composition and creation. +func (_fdb *QueryBuilder )Validate ()error {if _fdb ._ece !=nil {return _fdb ._ece ;};return _fdb ._fd .Validate ();}; -// TimeoutDuration sets the server query duration timeout. -// Once the timeout is reached the server will return an error. -func (_eea *QueryBuilder )TimeoutDuration (d _c .Duration )*QueryBuilder {_eea ._bade .TimeoutDuration =d ;return _eea ;}; +// BuildHTMLQuery creates a Query builder that is supposed to create valid +func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; -// Options are the client options used by the HTTP client. -type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _c .Duration ;Prefix string ;};func (_ge *Client )getGenerateRequest (_ba _f .Context ,_ec *Query )(*_ab .Request ,error ){_ggce :=generatePDFRequestV1 {Method :_ec .Method ,PageParameters :_ec .PageParameters ,RenderParameters :_ec .RenderParameters ,TimeoutDuration :int64 (_ec .TimeoutDuration )}; -switch _ec .Method {case "\u0077\u0065\u0062":_ggce .ContentURL =_ec .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_ggce .ContentType =_ec .ContentType ;_ggce .Content =_ec .Content ;};_gec :=new (_db .Buffer );if _fa :=_da .NewEncoder (_gec ).Encode (&_ggce ); -_fa !=nil {return nil ,_dbc .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_fa );};_bbe :=_ge .Options .Addr ();_bbe =_dbc .Sprintf ("\u0025s\u002f\u0076\u0031\u002f\u0070\u0064f",_bbe ); -_eb ,_bbc :=_ab .NewRequest ("\u0050\u004f\u0053\u0054",_bbe ,_gec );if _bbc !=nil {return nil ,_bbc ;};_eb .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); -_eb .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); -_eb =_eb .WithContext (_ba );return _eb ,nil ;}; \ No newline at end of file +// PDFResponse is the response used by the HTMLConverter. +type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; \ No newline at end of file diff --git a/common/common.go b/common/common.go index a52f214..e8fbe84 100644 --- a/common/common.go +++ b/common/common.go @@ -10,8 +10,7 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package common contains common properties used by the subpackages. -package common ;import _e "time";const _f =2024;const Version ="\u0030\u002e\u0039.\u0030"; +package common ;import _gc "time";const Version ="\u0030\u002e\u0031\u0030\u002e\u0030";const _d ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";const _e =20; // UtcTimeFormat returns a formatted string describing a UTC timestamp. -func UtcTimeFormat (t _e .Time )string {return t .Format (_ca )+"\u0020\u0055\u0054\u0043"};const _ef =20;const _ca ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";const _cd =12; -var ReleasedAt =_e .Date (_f ,_cd ,_d ,_fc ,_ef ,0,0,_e .UTC );const _d =22;const _fc =12; \ No newline at end of file +func UtcTimeFormat (t _gc .Time )string {return t .Format (_d )+"\u0020\u0055\u0054\u0043"};const _b =2025;var ReleasedAt =_gc .Date (_b ,_c ,_gb ,_gf ,_e ,0,0,_gc .UTC );const _gb =25;const _gf =12;const _c =3; \ No newline at end of file diff --git a/content/content.go b/content/content.go index 3740d9b..e15806f 100644 --- a/content/content.go +++ b/content/content.go @@ -9,64 +9,64 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package content ;import (_b "archive/zip";_ab "bytes";_bd "fmt";_a "net/url";_d "os";_bc "strings";); +package content ;import (_e "archive/zip";_fd "bytes";_b "fmt";_f "net/url";_df "os";_a "strings";);type webURL struct{_gd string }; -// Method gets the query method. -func (_bg *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"};type htmlFile struct{_c _ab .Buffer }; +// Data implements Content interface. +func (_fc *webURL )Data ()[]byte {return []byte (_fc ._gd )}; -// Content is an interface used for putting the content into Client Query. -type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;};type webURL struct{_cd string }; +// ContentType implements Content interface. +func (_db *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; // Data implements Content interface. -func (_bee *StringContent )Data ()[]byte {return []byte (_bee ._aca )}; +func (_ef *zipDirectory )Data ()[]byte {return _ef ._dff .Bytes ()}; + +// NewWebURL creates new Content webURL for provided input URL path. +func NewWebURL (path string )(Content ,error ){if _ ,_faa :=_f .Parse (path );_faa !=nil {return nil ,_faa ;};return &webURL {_gd :path },nil ;}; // ContentType implements Content interface. -func (_bad *StringContent )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl";}; +func (_bea *StringContent )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl";}; // Data implements Content interface. -func (_bgb *webURL )Data ()[]byte {return []byte (_bgb ._cd )};func (_af *zipDirectory )zipPath (_dcd ,_fa string )error {_abc ,_agf :=_d .ReadDir (_dcd );if _agf !=nil {return _bd .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_dcd ,_agf ); -};_de :=&_bc .Builder {};for _ ,_bae :=range _abc {_cc ,_faf :=_bae .Info ();if _faf !=nil {return _faf ;};_ee ,_eg :=_af .zipBasePaths (_cc ,_dcd ,_fa ,_bae .IsDir (),_de );if _bae .IsDir (){if _aag :=_af .zipPath (_ee ,_eg );_aag !=nil {return _aag ; -};continue ;};_gf ,_faf :=_d .ReadFile (_ee );if _faf !=nil {return _faf ;};_be ,_faf :=_af ._g .Create (_eg );if _faf !=nil {return _faf ;};if _ ,_faf =_be .Write (_gf );_faf !=nil {return _faf ;};};return nil ;}; - -// Method gets the zip directory method. -func (_ba *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; +func (_dbe *StringContent )Data ()[]byte {return []byte (_dbe ._fe )}; -// NewWebURL creates new Content webURL for provided input URL path. -func NewWebURL (path string )(Content ,error ){if _ ,_cg :=_a .Parse (path );_cg !=nil {return nil ,_cg ;};return &webURL {_cd :path },nil ;};func (_dfe *zipDirectory )zipBasePaths (_gfa _d .FileInfo ,_gg ,_ffe string ,_ffed bool ,_gd *_bc .Builder )(string ,string ){_gd .WriteString (_gg ); -if !_bc .HasSuffix (_gg ,"\u002f"){_gd .WriteRune ('/');};_gd .WriteString (_gfa .Name ());if _ffed {_gd .WriteRune ('/');};_ca :=_gd .String ();_gd .Reset ();_gd .WriteString (_ffe );_gd .WriteString (_gfa .Name ());if _ffed {_gd .WriteRune ('/');};_gbd :=_gd .String (); -_gd .Reset ();return _ca ,_gbd ;}; +// StringContent implements Content interface for an HTML string. +type StringContent struct{_fe string };func (_aaa *zipDirectory )zipBasePaths (_ab _df .FileInfo ,_gc ,_de string ,_da bool ,_fdf *_a .Builder )(string ,string ){_fdf .WriteString (_gc );if !_a .HasSuffix (_gc ,"\u002f"){_fdf .WriteRune ('/');};_fdf .WriteString (_ab .Name ()); +if _da {_fdf .WriteRune ('/');};_bfe :=_fdf .String ();_fdf .Reset ();_fdf .WriteString (_de );_fdf .WriteString (_ab .Name ());if _da {_fdf .WriteRune ('/');};_gf :=_fdf .String ();_fdf .Reset ();return _bfe ,_gf ;};type zipDirectory struct{_dff _fd .Buffer ; +_ce *_e .Writer ;}; -// Method gets the web url query method. -func (_ag *webURL )Method ()string {return "\u0077\u0065\u0062"}; +// NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' +// and stores in it's in-memory buffer. +func NewZipDirectory (dirPath string )(Content ,error ){_dfc :=&zipDirectory {_dff :_fd .Buffer {}};_dfc ._ce =_e .NewWriter (&_dfc ._dff );if _cea :=_dfc .zipPath (dirPath ,"");_cea !=nil {return nil ,_cea ;};if _ec :=_dfc ._ce .Close ();_ec !=nil {return nil ,_ec ; +};return _dfc ,nil ;};func (_ga *zipDirectory )zipPath (_gb ,_ge string )error {_fac ,_ac :=_df .ReadDir (_gb );if _ac !=nil {return _b .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_gb ,_ac ); +};_cg :=&_a .Builder {};for _ ,_fca :=range _fac {_bd ,_acb :=_fca .Info ();if _acb !=nil {return _acb ;};_dd ,_ee :=_ga .zipBasePaths (_bd ,_gb ,_ge ,_fca .IsDir (),_cg );if _fca .IsDir (){if _ae :=_ga .zipPath (_dd ,_ee );_ae !=nil {return _ae ;};continue ; +};_dc ,_acb :=_df .ReadFile (_dd );if _acb !=nil {return _acb ;};_cb ,_acb :=_ga ._ce .Create (_ee );if _acb !=nil {return _acb ;};if _ ,_acb =_cb .Write (_dc );_acb !=nil {return _acb ;};};return nil ;}; -// NewHTMLFile creates new Content htmFile for provided input path. -func NewHTMLFile (path string )(Content ,error ){_f ,_ff :=_d .Open (path );if _ff !=nil {return nil ,_ff ;};_bce :=&htmlFile {_c :_ab .Buffer {}};if _ ,_ff =_bce ._c .ReadFrom (_f );_ff !=nil {return nil ,_ff ;};return _bce ,nil ;}; +// Data implements Content interface. +func (_fg *htmlFile )Data ()[]byte {return _fg ._c .Bytes ()}; -// ContentType implements Content interface. -func (_aa *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; +// NewStringContent creates a new StringContent. +func NewStringContent (html string )(*StringContent ,error ){return &StringContent {_fe :html },nil }; -// StringContent implements Content interface for an HTML string. -type StringContent struct{_aca string }; +// Method implements Content interface. +func (_adg *StringContent )Method ()string {return "\u0068\u0074\u006d\u006c"}; // ContentType implements Content interface. -func (_fg *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; +func (_bg *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; -// NewStringContent creates a new StringContent. -func NewStringContent (html string )(*StringContent ,error ){return &StringContent {_aca :html },nil }; +// Method gets the query method. +func (_be *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"}; -// Data implements Content interface. -func (_ac *zipDirectory )Data ()[]byte {return _ac ._cbb .Bytes ()}; +// Content is an interface used for putting the content into Client Query. +type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;}; // ContentType implements Content interface. -func (_dc *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; +func (_fag *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"};type htmlFile struct{_c _fd .Buffer }; -// NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' -// and stores in it's in-memory buffer. -func NewZipDirectory (dirPath string )(Content ,error ){_df :=&zipDirectory {_cbb :_ab .Buffer {}};_df ._g =_b .NewWriter (&_df ._cbb );if _dca :=_df .zipPath (dirPath ,"");_dca !=nil {return nil ,_dca ;};if _cgd :=_df ._g .Close ();_cgd !=nil {return nil ,_cgd ; -};return _df ,nil ;}; +// Method gets the zip directory method. +func (_aa *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; -// Data implements Content interface. -func (_cb *htmlFile )Data ()[]byte {return _cb ._c .Bytes ()}; +// NewHTMLFile creates new Content htmFile for provided input path. +func NewHTMLFile (path string )(Content ,error ){_fa ,_cc :=_df .Open (path );if _cc !=nil {return nil ,_cc ;};_g :=&htmlFile {_c :_fd .Buffer {}};if _ ,_cc =_g ._c .ReadFrom (_fa );_cc !=nil {return nil ,_cc ;};return _g ,nil ;}; -// Method implements Content interface. -func (_ga *StringContent )Method ()string {return "\u0068\u0074\u006d\u006c"};type zipDirectory struct{_cbb _ab .Buffer ;_g *_b .Writer ;}; \ No newline at end of file +// Method gets the web url query method. +func (_ca *webURL )Method ()string {return "\u0077\u0065\u0062"}; \ No newline at end of file diff --git a/go.mod b/go.mod index 8c52edc..d125340 100644 --- a/go.mod +++ b/go.mod @@ -6,17 +6,17 @@ require ( github.com/mitchellh/go-homedir v1.1.0 github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.16.0 - github.com/stretchr/testify v1.9.0 - github.com/unidoc/unipdf/v3 v3.64.0 + github.com/stretchr/testify v1.10.0 + github.com/unidoc/unipdf/v3 v3.68.0 ) require ( github.com/adrg/strutil v0.3.1 // indirect github.com/adrg/sysfont v0.1.2 // indirect - github.com/adrg/xdg v0.4.0 // indirect + github.com/adrg/xdg v0.5.3 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect - github.com/gabriel-vasile/mimetype v1.4.3 // indirect + github.com/gabriel-vasile/mimetype v1.4.8 // indirect github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect @@ -33,14 +33,14 @@ require ( github.com/unidoc/freetype v0.2.3 // indirect github.com/unidoc/pkcs7 v0.2.0 // indirect github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a // indirect - github.com/unidoc/unichart v0.3.0 // indirect - github.com/unidoc/unitype v0.4.0 // indirect - golang.org/x/crypto v0.31.0 // indirect - golang.org/x/image v0.18.0 // indirect - golang.org/x/net v0.33.0 // indirect - golang.org/x/sys v0.28.0 // indirect - golang.org/x/text v0.21.0 // indirect - golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect + github.com/unidoc/unichart v0.4.0 // indirect + github.com/unidoc/unitype v0.5.1 // indirect + golang.org/x/crypto v0.33.0 // indirect + golang.org/x/image v0.24.0 // indirect + golang.org/x/net v0.35.0 // indirect + golang.org/x/sys v0.30.0 // indirect + golang.org/x/text v0.22.0 // indirect + golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 76ea277..0938820 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/adrg/strutil v0.3.1/go.mod h1:8h90y18QLrs11IBffcGX3NW/GFBXCMcNg4M7H6M github.com/adrg/sysfont v0.1.2 h1:MSU3KREM4RhsQ+7QgH7wPEPTgAgBIz0Hw6Nd4u7QgjE= github.com/adrg/sysfont v0.1.2/go.mod h1:6d3l7/BSjX9VaeXWJt9fcrftFaD/t7l11xgSywCPZGk= github.com/adrg/xdg v0.3.0/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ= -github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls= -github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E= +github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78= +github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -14,8 +14,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8Yc github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= -github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= -github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= +github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46 h1:N+R2A3fGIr5GucoRMu2xpqyQWQlfY31orbofBCdjMz8= github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46/go.mod h1:2Yoiy15Cf7Q3NFwfaJquh7Mk1uGI09ytcD7CUhn8j7s= @@ -23,9 +23,6 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -44,7 +41,6 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= @@ -64,14 +60,14 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/unidoc/freetype v0.2.3 h1:uPqW+AY0vXN6K2tvtg8dMAtHTEvvHTN52b72XpZU+3I= @@ -81,39 +77,33 @@ github.com/unidoc/pkcs7 v0.2.0 h1:0Y0RJR5Zu7OuD+/l7bODXARn6b8Ev2G4A8lI4rzy9kg= github.com/unidoc/pkcs7 v0.2.0/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a h1:RLtvUhe4DsUDl66m7MJ8OqBjq8jpWBXPK6/RKtqeTkc= github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a/go.mod h1:j+qMWZVpZFTvDey3zxUkSgPJZEX33tDgU/QIA0IzCUw= -github.com/unidoc/unichart v0.3.0 h1:VX1j5yzhjrR3f2flC03Yat6/WF3h7Z+DLEvJLoTGhoc= -github.com/unidoc/unichart v0.3.0/go.mod h1:8JnLNKSOl8yQt1jXewNgYFHhFm5M6/ZiaydncFDpakA= -github.com/unidoc/unipdf/v3 v3.64.0 h1:6qP8Q7lprY+LIgEz43Ni8mM+q7dCydRp3uwnf9LxzTU= -github.com/unidoc/unipdf/v3 v3.64.0/go.mod h1:0OIzSHHno23Y8WzaK+852abK8d3AxUZ1GQkMqpyCzu8= -github.com/unidoc/unitype v0.4.0 h1:/TMZ3wgwfWWX64mU5x2O9no9UmoBqYCB089LYYqHyQQ= -github.com/unidoc/unitype v0.4.0/go.mod h1:HV5zuUeqMKA4QgYQq3KDlJY/P96XF90BQB+6czK6LVA= -golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= -golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= +github.com/unidoc/unichart v0.4.0 h1:uXk9ZjbqzKb8Lt2Qv2oM9D2ftNRXvezPevgxQhsTQys= +github.com/unidoc/unichart v0.4.0/go.mod h1:9QsE8RbS0fE7ndHNroeCEFkRPqqk47Qsoj6QSAtcwN0= +github.com/unidoc/unipdf/v3 v3.68.0 h1:AM1wKukv75hvCtTbiPb3HSIdHS5RbmR6aYTCE0jiO+A= +github.com/unidoc/unipdf/v3 v3.68.0/go.mod h1:4mQ4E8niuY+30TGxT1e/8aVoSk/nn0yCKfi+kYw98+I= +github.com/unidoc/unitype v0.5.1 h1:UwTX15K6bktwKocWVvLoijIeu4JAVEAIeFqMOjvxqQs= +github.com/unidoc/unitype v0.5.1/go.mod h1:3dxbRL+f1otNqFQIRHho8fxdg3CcUKrqS8w1SXTsqcI= +golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= +golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= -golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= -golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= -golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= -golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/image v0.24.0 h1:AN7zRgVsbvmTfNyqIbbOraYL8mSwcKncEj8ofjgzcMQ= +golang.org/x/image v0.24.0/go.mod h1:4b/ITuLfqYq1hqZcjofwctIhi7sZh2WaCjvsBNjjya8= +golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= +golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= -golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= +golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da h1:noIWHXmPHxILtqtCOPIhSt0ABwskkZKjD3bXGnZGpNY= +golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/selector/selector.go b/selector/selector.go index c2986e7..4d5b7c7 100644 --- a/selector/selector.go +++ b/selector/selector.go @@ -9,10 +9,10 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package selector ;import _b "errors"; - -// ByType is a 'By' selector type enumerator. -type ByType uint ;const (ByUndefined ByType =iota ;ByID ;ByQueryAll ;ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); +package selector ;import _f "errors"; // Validate checks validity of the ByType. -func (_dd ByType )Validate ()error {if _dd >=ByID &&_dd <=BySearch {return nil ;};return _b .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");}; \ No newline at end of file +func (_e ByType )Validate ()error {if _e >=ByID &&_e <=BySearch {return nil ;};return _f .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");}; + +// ByType is a 'By' selector type enumerator. +type ByType uint ;const (ByUndefined ByType =iota ;ByID ;ByQueryAll ;ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); \ No newline at end of file diff --git a/sizes/sizes.go b/sizes/sizes.go index bbac2a7..fe84dcc 100644 --- a/sizes/sizes.go +++ b/sizes/sizes.go @@ -12,190 +12,190 @@ // Package sizes defines basic types that determines the size units i.e. lengths. // // -package sizes ;import (_d "encoding/json";_a "flag";_bd "fmt";_c "strconv";_b "strings";);const _ece ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; +package sizes ;import (_g "encoding/json";_ae "flag";_e "fmt";_ce "strconv";_c "strings";);const (_cd =float64 (1)/float64 (25.4);_b =25.4;_d =0.0139;_ac =0.3528;_cb =1.0/64;_bc =1.0/_ac ;); +// MarshalPageSize marshals the page size into string. +func MarshalPageSize (p PageSize )(string ,error ){_cgg ,_ab :=p .MarshalText ();if _ab !=nil {return "",_ab ;};return string (_cgg ),nil ;}; -// Inches gets the inches equivalent from provided millimeter value. -func (_ebb Millimeter )Inches ()Inch {return Inch (float64 (_ebb )*_cb )}; +// Name implements viper.FlagValue interface. +func (_bab Point )Name ()string {return "\u0070\u006f\u0069n\u0074"};var _ Length =Inch (0);var _ccc =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ; +B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;); -// ValueString implements viper.FlagValue interface. -func (_fgc Point )ValueString ()string {return _fgc .String ()};var _ Length =Inch (0); +// String implements fmt.Stringer interface. +func (_fc Inch )String ()string {_aa :=_c .Builder {};_aa .WriteString (_ce .FormatFloat (float64 (_fc ),'f',1,64));_aa .WriteString ("\u0069\u006e");return _aa .String ();};func _eaa (_fbb string )(Point ,error ){_fbb =_c .TrimSpace (_c .Trim (_fbb ,"\u0070\u0074")); +_bbe ,_gdf :=_ce .ParseFloat (_fbb ,64);if _gdf !=nil {return 0,_gdf ;};return Point (_bbe ),nil ;}; -// String gets the string value for given flag. -func (_db *LengthFlag )String ()string {if _db .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _db .Length .String ();}; +// Orientation is the page orientation type wrapper. +type Orientation bool ; -// ValueType implements pflag.Value interface. -func (_aa Inch )ValueType ()string {return _aa .Type ()}; +// Points implements Length interface. +func (_dcc Inch )Points ()Point {return Point (float64 (_dcc )*_cb )}; -// ValueType implements viper.FlagValue interface. -func (_dbb Point )ValueType ()string {return _dbb .Type ()}; +// Set implements pflag.Value interface. +func (_ecd *PageSize )Set (s string )error {_bdf ,_fgb :=UnmarshalPageSize (s );if _fgb !=nil {return _fgb ;};*_ecd =_bdf ;return nil ;}; -// Set sets the unit value. -// Implements pflag.Value interface. -func (_ga *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_ga .Length =nil ;return nil ;};_ae ,_bc :=UnmarshalLength (s );if _bc !=nil {return _bc ;};_ga .Length =_ae ;return nil ;}; +// PageSizeValues returns all values of the enum +func PageSizeValues ()[]PageSize {return _ccc };const (Portrait =Orientation (false );Landscape =Orientation (true );); -// Inches gets the inch value. Implements Length interface. -func (_ccf Inch )Inches ()Inch {return _ccf }; +// Points implements Length interface. +func (_aef Millimeter )Points ()Point {return Point (_aef *_bc )}; -// MarshalJSON implements the json.Marshaler interface for PageSize -func (_gd PageSize )MarshalJSON ()([]byte ,error ){return _d .Marshal (_gd .String ())}; +// PageSizeString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func PageSizeString (s string )(PageSize ,error ){if _afb ,_bbfe :=_gde [s ];_bbfe {return _afb ,nil ;};return 0,_e .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); +}; -// UnmarshalLength unmarshalls string value into Length. -func UnmarshalLength (length string )(Length ,error ){if _b .HasSuffix (length ,"\u006d\u006d"){return _dcg (length );};if _b .HasSuffix (length ,"\u0069\u006e"){return _cbfe (length );};if _b .HasSuffix (length ,"\u0070\u0074"){return _ccb (length );}; -return nil ,_bd .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length );};var _eca =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; -func _ccb (_gf string )(Point ,error ){_gf =_b .TrimSpace (_b .Trim (_gf ,"\u0070\u0074"));_dgb ,_abe :=_c .ParseFloat (_gf ,64);if _abe !=nil {return 0,_abe ;};return Point (_dgb ),nil ;}; +// Dimensions gets the dimensions of the given page size. +// If provided page size is not valid than the function returns 0 values. +func (_bae PageSize )Dimensions ()(_ga ,_bdfc Millimeter ){switch _bae {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; +case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; +case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _ga ,_bdfc ;};var _fdg =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; -// Set implements flag.Value interface. -func (_fce *Point )Set (s string )error {_fg ,_bef :=_c .ParseFloat (s ,64);if _bef !=nil {return _bd .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_bef );};*_fce =Point (_fg ); -return nil ;}; +// HasChanged implements pflag.Value interface. +func (_fcd *Inch )HasChanged ()bool {return _fcd !=nil }; -// ValueString implements pflag.Value interface. -func (_de Inch )ValueString ()string {return _de .String ()}; +// Type implements pflag.Value interface. +func (_bd *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; // String implements fmt.Stringer interface. -func (_dbe Inch )String ()string {_bg :=_b .Builder {};_bg .WriteString (_c .FormatFloat (float64 (_dbe ),'f',1,64));_bg .WriteString ("\u0069\u006e");return _bg .String ();}; - -// Inch is a unit that -type Inch float64 ;const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;);var _add =map[string ]PageSize {_ece [0:9]:0,_ece [9:11]:1,_ece [11:13]:2,_ece [13:15]:3,_ece [15:17]:4,_ece [17:19]:5,_ece [19:21]:6,_ece [21:23]:7,_ece [23:25]:8,_ece [25:27]:9,_ece [27:29]:10,_ece [29:32]:11,_ece [32:34]:12,_ece [34:36]:13,_ece [36:38]:14,_ece [38:40]:15,_ece [40:42]:16,_ece [42:44]:17,_ece [44:46]:18,_ece [46:48]:19,_ece [48:50]:20,_ece [50:52]:21,_ece [52:55]:22,_ece [55:61]:23}; +func (_cg Point )String ()string {_da :=_c .Builder {};_da .WriteString (_ce .FormatFloat (float64 (_cg ),'f',1,64));_da .WriteString ("\u0070\u0074");return _da .String ();}; +// UnmarshalLength unmarshalls string value into Length. +func UnmarshalLength (length string )(Length ,error ){if _c .HasSuffix (length ,"\u006d\u006d"){return _dbf (length );};if _c .HasSuffix (length ,"\u0069\u006e"){return _fg (length );};if _c .HasSuffix (length ,"\u0070\u0074"){return _eaa (length );};return nil ,_e .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length ); +}; -// HasChanged implements pflag.Value interface. -func (_df *Inch )HasChanged ()bool {return _df !=nil }; - -// Name implements viper.FlagValue interface. -func (_cce Point )Name ()string {return "\u0070\u006f\u0069n\u0074"};var _ _a .Value =(*Point )(nil ); - -// MarshalText implements the encoding.TextMarshaler interface for PageSize -func (_bae PageSize )MarshalText ()([]byte ,error ){return []byte (_bae .String ()),nil }; +// MarshalJSON implements json.Marshaler interface +func (_cda Millimeter )MarshalJSON ()([]byte ,error ){return _cff (_cda )}; // Type implements pflag.Value interface. -func (_cda Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; +func (_aaf Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; -// MarshalUnit marshals the unit into the string. -func MarshalUnit (unit Length )(string ,error ){switch _fe :=unit .(type ){case Millimeter :return _bd .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_fe ),nil ;case Inch :return _bd .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_fe ),nil ;case Point :return _bd .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_fe ),nil ; -default:return "",_bd .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; - -// String implements fmt.Stringer interface. -func (_aab Orientation )String ()string {if _aab ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; +// MarshalJSON implements json.Marshaler interface +func (_dce Inch )MarshalJSON ()([]byte ,error ){return _cff (_dce )}; -// Point is a unit of Length commonly used to measure the height of fonts. -type Point float64 ; +// MarshalJSON implements the json.Marshaler interface for PageSize +func (_gdff PageSize )MarshalJSON ()([]byte ,error ){return _g .Marshal (_gdff .String ())}; -// Type implements pflag.Value interface. -func (_fc Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; +// Millimeter is the dimension unit that defines a millimeter. +type Millimeter float64 ; -// Set implements pflag.Value interface. -func (_aaa *PageSize )Set (s string )error {_fed ,_acf :=UnmarshalPageSize (s );if _acf !=nil {return _acf ;};*_aaa =_fed ;return nil ;}; +// UnmarshalPageSize unmarshals the page size from the string. +func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _fd PageSize ;if _gce :=(&_fd ).UnmarshalText ([]byte (pageSize ));_gce !=nil {return 0,_e .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_gce ); +};return _fd ,nil ;};func _dbf (_beaf string )(Millimeter ,error ){_beaf =_c .TrimSpace (_c .TrimSuffix (_beaf ,"\u006d\u006d"));_agg ,_fa :=_ce .ParseFloat (_beaf ,64);if _fa !=nil {return 0,_e .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_fa ); +};return Millimeter (_agg ),nil ;}; -// Set implements flag.Value interface. -func (_cde *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_cde =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_cde =Landscape ;default:return _bd .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); -};return nil ;}; +// MarshalText implements the encoding.TextMarshaler interface for PageSize +func (_ggb PageSize )MarshalText ()([]byte ,error ){return []byte (_ggb .String ()),nil }; -// PageSize is the enum used for defining the page size. -type PageSize int ;func _dcg (_dbg string )(Millimeter ,error ){_dbg =_b .TrimSpace (_b .TrimSuffix (_dbg ,"\u006d\u006d"));_fd ,_egag :=_c .ParseFloat (_dbg ,64);if _egag !=nil {return 0,_bd .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_egag ); -};return Millimeter (_fd ),nil ;}; +// Type implements pflag.Value interface. +func (_ee Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";};const _fdf ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; -// Millimeters converts the inches value to the millimeters. -func (_gab Point )Millimeters ()Millimeter {return Millimeter (float64 (_gab )*_g )}; -// String implements fmt.Stringer interface. -func (_gac Point )String ()string {_ebe :=_b .Builder {};_ebe .WriteString (_c .FormatFloat (float64 (_gac ),'f',1,64));_ebe .WriteString ("\u0070\u0074");return _ebe .String ();};func (_cad PageSize )String ()string {if _cad < 0||_cad >=PageSize (len (_eca )-1){return _bd .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_cad ); -};return _ece [_eca [_cad ]:_eca [_cad +1]];}; +// Inch is a unit that +type Inch float64 ; -// UnmarshalJSON implements the json.Unmarshaler interface for PageSize -func (_acg *PageSize )UnmarshalJSON (data []byte )error {var _bgg string ;if _bag :=_d .Unmarshal (data ,&_bgg );_bag !=nil {return _bd .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); -};var _ege error ;*_acg ,_ege =PageSizeString (_bgg );return _ege ;}; +// Set sets the unit value. +// Implements pflag.Value interface. +func (_cf *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_cf .Length =nil ;return nil ;};_bg ,_f :=UnmarshalLength (s );if _f !=nil {return _f ;};_cf .Length =_bg ;return nil ;}; -// PageSizeValues returns all values of the enum -func PageSizeValues ()[]PageSize {return _fef };var _fef =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; +// Points implements Length interface. +func (_bea Point )Points ()Point {return _bea }; // String implements fmt.Stringer interface. -func (_ff Millimeter )String ()string {_gag :=_b .Builder {};_gag .WriteString (_c .FormatFloat (float64 (_ff ),'f',1,64));_gag .WriteString ("\u006d\u006d");return _gag .String ();};var _ _a .Value =(*Orientation )(nil ); - -// Name implements pflag.Value interface. -func (_gae Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; - -// Millimeters converts the inches value to the millimeters. -func (_dfa Inch )Millimeters ()Millimeter {return Millimeter (float64 (_dfa )*_ba )}; +func (_df Millimeter )String ()string {_cea :=_c .Builder {};_cea .WriteString (_ce .FormatFloat (float64 (_df ),'f',1,64));_cea .WriteString ("\u006d\u006d");return _cea .String ();}; -// Millimeter is the dimension unit that defines a millimeter. -type Millimeter float64 ; +// Type implements pflag.Value interface. +func (_ea Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; -// Orientation is the page orientation type wrapper. -type Orientation bool ; +// ValueString implements pflag.Value interface. +func (_ba Inch )ValueString ()string {return _ba .String ()}; -// MarshalJSON implements json.Marshaler interface -func (_ab Millimeter )MarshalJSON ()([]byte ,error ){return _bff (_ab )}; +// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize +func (_gdfa *PageSize )UnmarshalText (text []byte )error {var _gad error ;*_gdfa ,_gad =PageSizeString (string (text ));return _gad ;};func _cff (_cgd Length )([]byte ,error ){if _cgd ==nil {return nil ,nil ;};_ccd ,_cfb :=MarshalUnit (_cgd );if _cfb !=nil {return nil ,_cfb ; +};return []byte ("\u0022"+_ccd +"\u0022"),nil ;}; -// UnmarshalInch unmarshalls provided string into unit. -func UnmarshalInch (unit string )(Inch ,error ){if _b .HasSuffix (unit ,"\u006d\u006d"){_dg ,_af :=_dcg (unit );if _af !=nil {return 0,_af ;};return _dg .Inches (),nil ;};if _b .HasSuffix (unit ,"\u0069\u006e"){return _cbfe (unit );};return 0,_bd .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); -}; +// Point is a unit of Length commonly used to measure the height of fonts. +type Point float64 ; -// MarshalJSON implements json.Marshaler interface -func (_ac Inch )MarshalJSON ()([]byte ,error ){return _bff (_ac )};const (Portrait =Orientation (false );Landscape =Orientation (true ););func _bff (_aba Length )([]byte ,error ){if _aba ==nil {return nil ,nil ;};_ad ,_fdd :=MarshalUnit (_aba );if _fdd !=nil {return nil ,_fdd ; -};return []byte ("\u0022"+_ad +"\u0022"),nil ;}; +// ValueType implements viper.FlagValue interface. +func (_ag Point )ValueType ()string {return _ag .Type ()}; // Set implements pflag.Value interface. -func (_ega *Inch )Set (s string )error {_dc ,_cc :=_c .ParseFloat (s ,64);if _cc !=nil {return _bd .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_cc );};*_ega =Inch (_dc ); -return nil ;}; +func (_dg *Inch )Set (s string )error {_dgc ,_db :=_ce .ParseFloat (s ,64);if _db !=nil {return _e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_db );};*_dg =Inch (_dgc ); +return nil ;};func (_af PageSize )String ()string {if _af < 0||_af >=PageSize (len (_fdg )-1){return _e .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_af );};return _fdf [_fdg [_af ]:_fdg [_af +1]];}; // Type implements pflag.Value interface. -func (_fa Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; +func (_ddf PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; -// PageSizeString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func PageSizeString (s string )(PageSize ,error ){if _ccfc ,_bec :=_add [s ];_bec {return _ccfc ,nil ;};return 0,_bd .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); -}; +// ValueType implements pflag.Value interface. +func (_gg Inch )ValueType ()string {return _gg .Type ()}; -// Points implements Length interface. -func (_ec Inch )Points ()Point {return Point (float64 (_ec )*_f )}; +// String implements fmt.Stringer interface. +func (_gbc Orientation )String ()string {if _gbc ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; + +// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise +func (_gaa PageSize )IsAPageSize ()bool {for _ ,_gf :=range _ccc {if _gaa ==_gf {return true ;};};return false ;}; + +// MarshalJSON implements json.Marshaler interface. +func (_eb Point )MarshalJSON ()([]byte ,error ){return _cff (_eb )}; // HasChanged implements viper.FlagValue interface. -func (_ag *Point )HasChanged ()bool {return _ag !=nil };func _cbfe (_dbbc string )(Inch ,error ){_dbbc =_b .TrimSpace (_b .Trim (_dbbc ,"\u0069\u006e"));_dee ,_aca :=_c .ParseFloat (_dbbc ,64);if _aca !=nil {return 0,_bd .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_aca ); -};return Inch (_dee ),nil ;};const (_cb =float64 (1)/float64 (25.4);_ba =25.4;_be =0.0139;_g =0.3528;_f =1.0/64;_cg =1.0/_g ;); +func (_cga *Point )HasChanged ()bool {return _cga !=nil }; -// Type implements pflag.Value interface. -func (_bab *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; +// PageSize is the enum used for defining the page size. +type PageSize int ; -// UnmarshalPageSize unmarshals the page size from the string. -func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _dcb PageSize ;if _bb :=(&_dcb ).UnmarshalText ([]byte (pageSize ));_bb !=nil {return 0,_bd .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_bb ); -};return _dcb ,nil ;}; +// Millimeters gets the float64 millimeter value. +func (_eg Millimeter )Millimeters ()Millimeter {return _eg }; -// MarshalJSON implements json.Marshaler interface. -func (_cd Point )MarshalJSON ()([]byte ,error ){return _bff (_cd )}; +// Millimeters converts the inches value to the millimeters. +func (_dgd Inch )Millimeters ()Millimeter {return Millimeter (float64 (_dgd )*_b )}; -// Points implements Length interface. -func (_cbf Point )Points ()Point {return _cbf }; +// MarshalUnit marshals the unit into the string. +func MarshalUnit (unit Length )(string ,error ){switch _bbf :=unit .(type ){case Millimeter :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_bbf ),nil ;case Inch :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_bbf ),nil ;case Point :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_bbf ),nil ; +default:return "",_e .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; // Inches gets the inch value. Implements Length interface. -func (_dbc Point )Inches ()Inch {return Inch (float64 (_dbc )*_be )};var (_ Length =Millimeter (0);); +func (_gb Point )Inches ()Inch {return Inch (float64 (_gb )*_d )}; -// LengthFlag is a pflag wrapper for the Length value. -type LengthFlag struct{Length Length ;}; +// Name implements pflag.Value interface. +func (_dc Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; -// Millimeters gets the float64 millimeter value. -func (_eb Millimeter )Millimeters ()Millimeter {return _eb }; +// Set implements flag.Value interface. +func (_dcg *Point )Set (s string )error {_cc ,_bad :=_ce .ParseFloat (s ,64);if _bad !=nil {return _e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_bad );};*_dcg =Point (_cc ); +return nil ;}; -// Dimensions gets the dimensions of the given page size. -// If provided page size is not valid than the function returns 0 values. -func (_ge PageSize )Dimensions ()(_ca ,_dca Millimeter ){switch _ge {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; -case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; -case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _ca ,_dca ;}; +// Millimeters converts the inches value to the millimeters. +func (_fb Point )Millimeters ()Millimeter {return Millimeter (float64 (_fb )*_ac )}; -// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize -func (_gdd *PageSize )UnmarshalText (text []byte )error {var _gb error ;*_gdd ,_gb =PageSizeString (string (text ));return _gb ;}; +// String gets the string value for given flag. +func (_bb *LengthFlag )String ()string {if _bb .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _bb .Length .String ();}; -// Type implements pflag.Value interface. -func (_ed PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; +// LengthFlag is a pflag wrapper for the Length value. +type LengthFlag struct{Length Length ;};var _gde =map[string ]PageSize {_fdf [0:9]:0,_fdf [9:11]:1,_fdf [11:13]:2,_fdf [13:15]:3,_fdf [15:17]:4,_fdf [17:19]:5,_fdf [19:21]:6,_fdf [21:23]:7,_fdf [23:25]:8,_fdf [25:27]:9,_fdf [27:29]:10,_fdf [29:32]:11,_fdf [32:34]:12,_fdf [34:36]:13,_fdf [36:38]:14,_fdf [38:40]:15,_fdf [40:42]:16,_fdf [42:44]:17,_fdf [44:46]:18,_fdf [46:48]:19,_fdf [48:50]:20,_fdf [50:52]:21,_fdf [52:55]:22,_fdf [55:61]:23}; +var (_ Length =Millimeter (0);); -// Points implements Length interface. -func (_gc Millimeter )Points ()Point {return Point (_gc *_cg )}; +// UnmarshalInch unmarshalls provided string into unit. +func UnmarshalInch (unit string )(Inch ,error ){if _c .HasSuffix (unit ,"\u006d\u006d"){_bf ,_fcf :=_dbf (unit );if _fcf !=nil {return 0,_fcf ;};return _bf .Inches (),nil ;};if _c .HasSuffix (unit ,"\u0069\u006e"){return _fg (unit );};return 0,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); +};func _fg (_ec string )(Inch ,error ){_ec =_c .TrimSpace (_c .Trim (_ec ,"\u0069\u006e"));_dbe ,_dag :=_ce .ParseFloat (_ec ,64);if _dag !=nil {return 0,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_dag ); +};return Inch (_dbe ),nil ;};var _ _ae .Value =(*Point )(nil ); -// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise -func (_bcc PageSize )IsAPageSize ()bool {for _ ,_ee :=range _fef {if _bcc ==_ee {return true ;};};return false ;}; +// UnmarshalJSON implements the json.Unmarshaler interface for PageSize +func (_ggg *PageSize )UnmarshalJSON (data []byte )error {var _dad string ;if _afc :=_g .Unmarshal (data ,&_dad );_afc !=nil {return _e .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); +};var _beae error ;*_ggg ,_beae =PageSizeString (_dad );return _beae ;}; // Length is it the default dimension unit. type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; -// MarshalPageSize marshals the page size into string. -func MarshalPageSize (p PageSize )(string ,error ){_acb ,_aabg :=p .MarshalText ();if _aabg !=nil {return "",_aabg ;};return string (_acb ),nil ;}; \ No newline at end of file +// Set implements flag.Value interface. +func (_acf *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_acf =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_acf =Landscape ;default:return _e .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); +};return nil ;};var _ _ae .Value =(*Orientation )(nil ); + +// Inches gets the inch value. Implements Length interface. +func (_gd Inch )Inches ()Inch {return _gd }; + +// ValueString implements viper.FlagValue interface. +func (_be Point )ValueString ()string {return _be .String ()}; + +// Inches gets the inches equivalent from provided millimeter value. +func (_gc Millimeter )Inches ()Inch {return Inch (float64 (_gc )*_cd )}; \ No newline at end of file diff --git a/unihtml.go b/unihtml.go index a112f8d..d840751 100644 --- a/unihtml.go +++ b/unihtml.go @@ -10,126 +10,126 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package unihtml contains a plugin for the UniDoc. -package unihtml ;import (_ee "bytes";_f "context";_a "errors";_ea "fmt";_fde "github.com/unidoc/unihtml/client";_fb "github.com/unidoc/unihtml/content";_eea "github.com/unidoc/unihtml/selector";_g "github.com/unidoc/unihtml/sizes";_eac "github.com/unidoc/unipdf/v3/common"; -_fdd "github.com/unidoc/unipdf/v3/common/license";_cb "github.com/unidoc/unipdf/v3/creator";_ed "github.com/unidoc/unipdf/v3/model";_ab "github.com/unidoc/unipdf/v3/render";_b "image";_eg "image/color";_d "math";_e "net/url";_ff "os";_fd "time";); +package unihtml ;import (_gc "bytes";_d "context";_cg "errors";_e "fmt";_f "github.com/unidoc/unihtml/client";_ef "github.com/unidoc/unihtml/content";_ea "github.com/unidoc/unihtml/selector";_gf "github.com/unidoc/unihtml/sizes";_fa "github.com/unidoc/unipdf/v3/common"; +_a "github.com/unidoc/unipdf/v3/common/license";_ac "github.com/unidoc/unipdf/v3/creator";_cd "github.com/unidoc/unipdf/v3/model";_dff "github.com/unidoc/unipdf/v3/render";_dd "image";_g "image/color";_cb "math";_c "net/url";_de "os";_df "time";); -// Options are the HTML Client options used for establishing the connection. -type Options struct{ +// SetMarginTop sets the left margin. +func (_eaag *Document )SetMarginTop (margin _gf .Length ){_eaag ._daf .Top =margin }; -// Hostname defines the hostname for the client. Default value: 'localhost'. -Hostname string ; +// SetMarginLeft sets the left margin. +func (_fgd *Document )SetMarginLeft (margin _gf .Length ){_fgd ._daf .Left =margin }; -// Port defines the port at which the server works. Default value: '8080' -Port int ; +// GeneratePageBlocks implements creator.Drawable interface. +func (_dbe *Document )GeneratePageBlocks (ctx _ac .DrawContext )([]*_ac .Block ,_ac .DrawContext ,error ){if _fc :=_dbe .validate ();_fc !=nil {return nil ,ctx ,_fc ;};var _ecg []*_ac .Block ;_ca :=_dbe .getMargins ();_fcb ,_cac :=_dbe ._db ,_dbe ._dbf ; +if _dbe ._dgg .IsRelative (){_fcb ,_cac =_gf .Point (ctx .Width ),_gf .Point (ctx .Height );ctx .X -=float64 (_ca .Left .Points ());}else {ctx .X =_dbe ._ag ;ctx .Y =_dbe ._ddb ;};_geg ,_bb :=_dbe .extract (_d .Background (),_fcb ,_cac ,_ca );if _bb !=nil {return nil ,_ac .DrawContext {},_bb ; +};for _ecd ,_dea :=range _geg {_ce ,_ff :=_ac .NewBlockFromPage (_dea );if _ff !=nil {return nil ,_ac .DrawContext {},_ff ;};var _bc float64 ;if _dbe ._ace &&_ecd ==len (_geg )-1{_gd :=_dff .NewImageDevice ();_af ,_fg :=_gd .Render (_dea );if _fg !=nil {return nil ,_ac .DrawContext {},_fg ; +};_aff ,_fg :=_dea .GetMediaBox ();if _fg !=nil {return nil ,_ac .DrawContext {},_fg ;};_bbd :=_df .Now ();_fab :=_fcg (_af );_bc =_aff .Height ()*_fab ;_fa .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_df .Since (_bbd )); +if _dbe ._daf .Bottom !=nil {_bc -=float64 (_dbe ._daf .Bottom .Points ());};if _bc < 0{_bc =0;};_fa .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_bc ); +};_ccd ,_def ,_ff :=_ce .GeneratePageBlocks (ctx );if _ff !=nil {return nil ,_ac .DrawContext {},_ff ;};ctx =_def ;ctx .Y -=_bc ;if _ecd !=len (_geg )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; +ctx .Page ++;};_ecg =append (_ecg ,_ccd ...);};return _ecg ,ctx ,nil ;}; -// Secure is the flag that states if the connection uses HTTPS protocol. Default Value: 'false'. -Secure bool ; +// WriteToFile writes the document to a file defined by the output path. +func (_cfe *Document )WriteToFile (outputPath string )error {if _dee :=_cfe .validate ();_dee !=nil {return _dee ;};_eac :=_df .Second *20+_cfe ._gg ;_ffg ,_eaab :=_d .WithTimeout (_d .Background (),_eac );defer _eaab ();_bf ,_bd :=_cfe .extract (_ffg ,_cfe ._db ,_cfe ._dbf ,_cfe .getMargins ()); +if _bd !=nil {return _bd ;};_cfb :=_ac .New ();for _ ,_feg :=range _bf {if _bd =_cfb .AddPage (_feg );_bd !=nil {return _bd ;};};return _cfb .WriteToFile (outputPath );}; -// Prefix is an option setting used when the server is working with the URI prefix. Default Value: ''. -Prefix string ;}; +// ContainerComponent implements creator.containerElement interface. +func (_cdg *Document )ContainerComponent (container _ac .Drawable )(_ac .Drawable ,error ){switch container .(type ){case *_ac .Chapter :default:return nil ,_e .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); +};return _cdg ,nil ;}; -// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. -func ConnectOptions (o Options )error {_dd =_fde .New (_fde .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_ad ,_fe :=_f .WithTimeout (_f .Background (),_fd .Second *5);defer _fe ();if _gb :=_dd .HealthCheck (_ad );_gb !=nil {return _gb ; -};return nil ;}; +// Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. +type Document struct{_dg _ef .Content ;_daf margins ;_dgg _ac .Positioning ;_ag ,_ddb float64 ;_eaa _gf .PageSize ;_db ,_dbf _gf .Length ;_ed _gf .Orientation ;_ace bool ;_gg _df .Duration ;_dab []_f .BySelector ;_faf []_f .BySelector ;_dde *_df .Duration ; +}; -// SetMarkedContentID sets the marked content id for the document. -func (_dcc *Document )SetMarkedContentID (id int64 )*_ed .KDict {return nil }; +// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. +func (_agg *Document )TrimLastPageContent (){_agg ._ace =true };func (_gb *Document )extract (_gde _d .Context ,_aad ,_ccb _gf .Length ,_be margins )([]*_cd .PdfPage ,error ){_deg :=_f .BuildHTMLQuery ().SetContent (_gb ._dg ).PageSize (_gb ._eaa ).PaperWidth (_aad ).PaperHeight (_ccb ).Orientation (_gb ._ed ).MarginLeft (_be .Left ).MarginRight (_be .Right ).MarginTop (_be .Top ).MarginBottom (_be .Bottom ).TimeoutDuration (_gb .getTimeoutDuration ()).WaitTime (_gb ._gg ); +for _ ,_fec :=range _gb ._dab {_deg .WaitReady (_fec .Selector ,_fec .By );};for _ ,_dgd :=range _gb ._faf {_deg .WaitVisible (_dgd .Selector ,_dgd .By );};_gda ,_ddg :=_deg .Query ();if _ddg !=nil {return nil ,_ddg ;};var _aee _d .CancelFunc ;if _gb ._dde !=nil {_gde ,_aee =_d .WithTimeout (_gde ,*_gb ._dde ); +}else {_gde ,_aee =_d .WithTimeout (_gde ,_df .Second *15);};defer _aee ();_ade ,_ddg :=_ge .ConvertHTML (_gde ,_gda );if _ddg !=nil {return nil ,_ddg ;};_bad :=_gc .NewReader (_ade .Data );_cad ,_ddg :=_cd .NewPdfReader (_bad );if _ddg !=nil {return nil ,_ddg ; +};return _cad .PageList ,nil ;}; -// SetPageSize sets the page default size. -func (_egg *Document )SetPageSize (pageSize _g .PageSize )error {if !pageSize .IsAPageSize (){return _a .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); -};_egg ._ffa =pageSize ;_egg ._bg =_cb .PositionAbsolute ;return nil ;}; +// NewDocument creates new HTML Document used as an input for the creator.Drawable. +func NewDocument (path string )(*Document ,error ){_ad :=&Document {};_cgg ,_fb :=_c .Parse (path );if _fb !=nil {return nil ,_fb ;};switch _cgg .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_ad ._dg ,_fb =_ef .NewWebURL (path ); +if _fb !=nil {return nil ,_fb ;};return _ad ,nil ;};_gcd ,_fb :=_de .Stat (path );if _fb !=nil {return nil ,_fb ;};if !_gcd .IsDir (){_ad ._dg ,_fb =_ef .NewHTMLFile (path );}else {_ad ._dg ,_fb =_ef .NewZipDirectory (path );};if _fb !=nil {return nil ,_fb ; +};return _ad ,nil ;}; // SetLandscapeOrientation sets document landscape page orientation. -func (_bffb *Document )SetLandscapeOrientation (){_bffb ._ced =_g .Landscape }; +func (_fbf *Document )SetLandscapeOrientation (){_fbf ._ed =_gf .Landscape };func (_gac *Document )validate ()error {if _ge ==nil {return ErrNoClient ;};if _gac ._dg ==nil {return ErrContentNotDefined ;};return nil ;}; -// NewDocumentFromString creates a new Document from the provided HTML string. -func NewDocumentFromString (html string )(*Document ,error ){_adc ,_cd :=_fb .NewStringContent (html );if _cd !=nil {return nil ,_cd ;};_ef :=&Document {};_ef ._bf =_adc ;return _ef ,nil ;}; +// SetTimeoutDuration sets the timeout duration +// the default timeout is 15 seconds. +func (_gfce *Document )SetTimeoutDuration (duration _df .Duration ){_gfce ._dde =&duration }; -// SetPos sets the absolute position. Changes object positioning to absolute. -func (_fgb *Document )SetPos (x ,y float64 ){_fgb ._bg =_cb .PositionAbsolute ;_fgb ._fbd =x ;_fgb ._fba =y ;}; +// SetMarkedContentID sets the marked content id for the document. +func (_dbec *Document )SetMarkedContentID (id int64 )*_cd .KDict {return nil }; -// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. -func (_acd *Document )TrimLastPageContent (){_acd ._fdg =true }; +// SetPageHeight sets the page height for given document. +func (_aef *Document )SetPageHeight (pageHeight _gf .Length )error {_aef ._dbf =pageHeight ;_aef ._dgg =_ac .PositionAbsolute ;return nil ;}; -// GetPdfPages is a function that converts provided input content and -func (_fac *Document )GetPdfPages (ctx _f .Context )([]*_ed .PdfPage ,error ){if _gf :=_fac .validate ();_gf !=nil {return nil ,_gf ;};return _fac .extract (ctx ,_fac ._db ,_fac ._eb ,_fac .getMargins ());}; +// Options are the HTML Client options used for establishing the connection. +type Options struct{ -// SetPageWidth sets the page width for given document. -func (_abg *Document )SetPageWidth (pageWidth _g .Length )error {_abg ._db =pageWidth ;_abg ._bg =_cb .PositionAbsolute ;return nil ;};var _ _cb .Drawable =(*Document )(nil ); +// Hostname defines the hostname for the client. Default value: 'localhost'. +Hostname string ; -// SetMarginLeft sets the left margin. -func (_fgf *Document )SetMarginLeft (margin _g .Length ){_fgf ._fdb .Left =margin }; +// Port defines the port at which the server works. Default value: '8080' +Port int ; + +// Secure is the flag that states if the connection uses HTTPS protocol. Default Value: 'false'. +Secure bool ; + +// Prefix is an option setting used when the server is working with the URI prefix. Default Value: ''. +Prefix string ;};func (_cbed *Document )getMargins ()margins {_gcf :=_cbed ._daf ;if _cbed ._dgg .IsRelative (){_gcf .Top =_gf .Millimeter (1);_gcf .Left =_gf .Millimeter (1);_gcf .Bottom =_gf .Millimeter (1);_gcf .Right =_gf .Millimeter (1);return _gcf ; +};if _gcf .Top ==nil {_gcf .Top =_gf .Millimeter (10);};if _gcf .Bottom ==nil {_gcf .Bottom =_gf .Millimeter (10);};if _gcf .Left ==nil {_gcf .Left =_gf .Millimeter (10);};if _gcf .Right ==nil {_gcf .Right =_gf .Millimeter (10);};return _gcf ;}; // SetMarginRight sets the left margin. -func (_ddbf *Document )SetMarginRight (margin _g .Length ){_ddbf ._fdb .Right =margin }; +func (_gfc *Document )SetMarginRight (margin _gf .Length ){_gfc ._daf .Right =margin }; -// WriteToFile writes the document to a file defined by the output path. -func (_ga *Document )WriteToFile (outputPath string )error {if _bc :=_ga .validate ();_bc !=nil {return _bc ;};_abd :=_fd .Second *20+_ga ._age ;_cf ,_fdbf :=_f .WithTimeout (_f .Background (),_abd );defer _fdbf ();_gc ,_agea :=_ga .extract (_cf ,_ga ._db ,_ga ._eb ,_ga .getMargins ()); -if _agea !=nil {return _agea ;};_ece :=_cb .New ();for _ ,_ebf :=range _gc {if _agea =_ece .AddPage (_ebf );_agea !=nil {return _agea ;};};return _ece .WriteToFile (outputPath );};func _cg (_fda _b .Image )float64 {_cde :=_fda .Bounds ();var (_gef int ; -_abc _eg .Color ;_fbc ,_aeb ,_gdc uint32 ;);_af ,_dad :=_cde .Min .X ,_cde .Max .Y -1;_gfc :=_fda .At (_af ,_dad );_def ,_bca ,_ebg ,_ :=_gfc .RGBA ();_dbg :=_def ==_d .MaxUint16 &&_bca ==_d .MaxUint16 &&_ebg ==_d .MaxUint16 ;for _dad =_cde .Max .Y -1; -_dad >=_cde .Min .Y ;_dad --{var _fae bool ;for _af =_cde .Min .X ;_af < _cde .Max .X ;_af ++{_abc =_fda .At (_af ,_dad );_fbc ,_aeb ,_gdc ,_ =_abc .RGBA ();if (_dbg &&!(_fbc ==_def &&_aeb ==_bca &&_ebg ==_gdc ))||(!_dbg &&(_d .Abs (float64 (_fbc )-float64 (_def ))/float64 (_d .MaxUint16 )> 0.03||_d .Abs (float64 (_aeb )-float64 (_bca ))/float64 (_d .MaxUint16 )> 0.03||_d .Abs (float64 (_gdc )-float64 (_ebg ))/float64 (_d .MaxUint16 )> 0.03)){_fae =true ; -break ;};};if _fae {break ;};_gef =_dad ;};return float64 (_cde .Max .Y -_gef )/float64 (_cde .Max .Y );};type margins struct{Left ,Right ,Bottom ,Top _g .Length ;};var ErrNoClient =_a .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); +// SetMargins sets the Document Margins. +func (_efd *Document )SetMargins (left ,right ,top ,bottom float64 ){_efd ._daf .Left =_gf .Point (left );_efd ._daf .Right =_gf .Point (right );_efd ._daf .Top =_gf .Point (top );_efd ._daf .Bottom =_gf .Point (bottom );_efd ._dgg =_ac .PositionAbsolute ; +};func _fcg (_bcb _dd .Image )float64 {_gfd :=_bcb .Bounds ();var (_eg int ;_aa _g .Color ;_aceg ,_egb ,_dc uint32 ;);_ffe ,_fea :=_gfd .Min .X ,_gfd .Max .Y -1;_fcd :=_bcb .At (_ffe ,_fea );_cbe ,_fbd ,_afa ,_ :=_fcd .RGBA ();_dga :=_cbe ==_cb .MaxUint16 &&_fbd ==_cb .MaxUint16 &&_afa ==_cb .MaxUint16 ; +for _fea =_gfd .Max .Y -1;_fea >=_gfd .Min .Y ;_fea --{var _ggg bool ;for _ffe =_gfd .Min .X ;_ffe < _gfd .Max .X ;_ffe ++{_aa =_bcb .At (_ffe ,_fea );_aceg ,_egb ,_dc ,_ =_aa .RGBA ();if (_dga &&!(_aceg ==_cbe &&_egb ==_fbd &&_afa ==_dc ))||(!_dga &&(_cb .Abs (float64 (_aceg )-float64 (_cbe ))/float64 (_cb .MaxUint16 )> 0.03||_cb .Abs (float64 (_egb )-float64 (_fbd ))/float64 (_cb .MaxUint16 )> 0.03||_cb .Abs (float64 (_dc )-float64 (_afa ))/float64 (_cb .MaxUint16 )> 0.03)){_ggg =true ; +break ;};};if _ggg {break ;};_eg =_fea ;};return float64 (_gfd .Max .Y -_eg )/float64 (_gfd .Max .Y );}; +// SetPos sets the absolute position. Changes object positioning to absolute. +func (_baf *Document )SetPos (x ,y float64 ){_baf ._dgg =_ac .PositionAbsolute ;_baf ._ag =x ;_baf ._ddb =y ;};func _cc ()error {_ae :=_a .GetLicenseKey ();if _ae ==nil {return _cg .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); +};if !_ae .IsLicensed (){return _cg .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};return nil ;}; // WaitTime sets the waiting time before the webpage is rendered to PDF. -func (_bce *Document )WaitTime (duration _fd .Duration ){_bce ._age =duration };func (_baa *Document )validate ()error {if _dd ==nil {return ErrNoClient ;};if _baa ._bf ==nil {return ErrContentNotDefined ;};return nil ;}; +func (_eae *Document )WaitTime (duration _df .Duration ){_eae ._gg =duration }; -// WaitVisible waits for the provided selector to be ready. -// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_gcg *Document )WaitVisible (sel string ,by ..._eea .ByType ){_gaf :=_eea .BySearch ;if len (by )> 0{_gaf =by [0];};_gcg ._da =append (_gcg ._da ,_fde .BySelector {Selector :sel ,By :_gaf });}; +// NewDocumentFromString creates a new Document from the provided HTML string. +func NewDocumentFromString (html string )(*Document ,error ){_cba ,_ec :=_ef .NewStringContent (html );if _ec !=nil {return nil ,_ec ;};_dfc :=&Document {};_dfc ._dg =_cba ;return _dfc ,nil ;};func (_feaa *Document )getTimeoutDuration ()_df .Duration {if _feaa ._dde !=nil {return *_feaa ._dde ; +};return 0;};var _ge *_f .Client ;type margins struct{Left ,Right ,Bottom ,Top _gf .Length ;}; -// Connect creates UniHTML HTTP Client and tries to establish connection with the server. -func Connect (path string )error {if _ddg :=_aa ();_ddg !=nil {return _ddg ;};_eda ,_ae :=_fde .ParseOptions (path );if _ae !=nil {return _ae ;};_dd =_fde .New (_eda );_ag ,_ce :=_f .WithTimeout (_f .Background (),_fd .Second *5);defer _ce ();if _ge :=_dd .HealthCheck (_ag ); -_ge !=nil {return _ge ;};return nil ;}; +// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. +func ConnectOptions (o Options )error {_ge =_f .New (_f .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_bgg ,_cf :=_d .WithTimeout (_d .Background (),_df .Second *5);defer _cf ();if _ab :=_ge .HealthCheck (_bgg );_ab !=nil {return _ab ; +};return nil ;}; -// WaitReady waits for the provided selector to be ready. -// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_dfb *Document )WaitReady (sel string ,by ..._eea .ByType ){_dc :=_eea .BySearch ;if len (by )> 0{_dc =by [0];};_dfb ._ac =append (_dfb ._ac ,_fde .BySelector {Selector :sel ,By :_dc });}; +// GetPdfPages is a function that converts provided input content and +func (_aca *Document )GetPdfPages (ctx _d .Context )([]*_cd .PdfPage ,error ){if _eda :=_aca .validate ();_eda !=nil {return nil ,_eda ;};return _aca .extract (ctx ,_aca ._db ,_aca ._dbf ,_aca .getMargins ());};var ErrNoClient =_cg .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); -// NewDocument creates new HTML Document used as an input for the creator.Drawable. -func NewDocument (path string )(*Document ,error ){_gd :=&Document {};_fa ,_eebf :=_e .Parse (path );if _eebf !=nil {return nil ,_eebf ;};switch _fa .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_gd ._bf ,_eebf =_fb .NewWebURL (path ); -if _eebf !=nil {return nil ,_eebf ;};return _gd ,nil ;};_cac ,_eebf :=_ff .Stat (path );if _eebf !=nil {return nil ,_eebf ;};if !_cac .IsDir (){_gd ._bf ,_eebf =_fb .NewHTMLFile (path );}else {_gd ._bf ,_eebf =_fb .NewZipDirectory (path );};if _eebf !=nil {return nil ,_eebf ; -};return _gd ,nil ;};var _dd *_fde .Client ; -// GeneratePageBlocks implements creator.Drawable interface. -func (_fcc *Document )GeneratePageBlocks (ctx _cb .DrawContext )([]*_cb .Block ,_cb .DrawContext ,error ){if _cec :=_fcc .validate ();_cec !=nil {return nil ,ctx ,_cec ;};var _eab []*_cb .Block ;_aae :=_fcc .getMargins ();_de ,_ec :=_fcc ._db ,_fcc ._eb ; -if _fcc ._bg .IsRelative (){_de ,_ec =_g .Point (ctx .Width ),_g .Point (ctx .Height );ctx .X -=float64 (_aae .Left .Points ());}else {ctx .X =_fcc ._fbd ;ctx .Y =_fcc ._fba ;};_ffd ,_faf :=_fcc .extract (_f .Background (),_de ,_ec ,_aae );if _faf !=nil {return nil ,_cb .DrawContext {},_faf ; -};for _df ,_ceg :=range _ffd {_efd ,_cab :=_cb .NewBlockFromPage (_ceg );if _cab !=nil {return nil ,_cb .DrawContext {},_cab ;};var _fed float64 ;if _fcc ._fdg &&_df ==len (_ffd )-1{_ba :=_ab .NewImageDevice ();_cbe ,_aac :=_ba .Render (_ceg );if _aac !=nil {return nil ,_cb .DrawContext {},_aac ; -};_cdg ,_aac :=_ceg .GetMediaBox ();if _aac !=nil {return nil ,_cb .DrawContext {},_aac ;};_ffda :=_fd .Now ();_bff :=_cg (_cbe );_fed =_cdg .Height ()*_bff ;_eac .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_fd .Since (_ffda )); -if _fcc ._fdb .Bottom !=nil {_fed -=float64 (_fcc ._fdb .Bottom .Points ());};if _fed < 0{_fed =0;};_eac .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_fed ); -};_fg ,_be ,_cab :=_efd .GeneratePageBlocks (ctx );if _cab !=nil {return nil ,_cb .DrawContext {},_cab ;};ctx =_be ;ctx .Y -=_fed ;if _df !=len (_ffd )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; -ctx .Page ++;};_eab =append (_eab ,_fg ...);};return _eab ,ctx ,nil ;};func (_gfb *Document )getMargins ()margins {_daf :=_gfb ._fdb ;if _gfb ._bg .IsRelative (){_daf .Top =_g .Millimeter (1);_daf .Left =_g .Millimeter (1);_daf .Bottom =_g .Millimeter (1); -_daf .Right =_g .Millimeter (1);return _daf ;};if _daf .Top ==nil {_daf .Top =_g .Millimeter (10);};if _daf .Bottom ==nil {_daf .Bottom =_g .Millimeter (10);};if _daf .Left ==nil {_daf .Left =_g .Millimeter (10);};if _daf .Right ==nil {_daf .Right =_g .Millimeter (10); -};return _daf ;};func (_aed *Document )getTimeoutDuration ()_fd .Duration {if _aed ._fc !=nil {return *_aed ._fc ;};return 0;}; +// Connect creates UniHTML HTTP Client and tries to establish connection with the server. +func Connect (path string )error {if _ga :=_cc ();_ga !=nil {return _ga ;};_dfe ,_fe :=_f .ParseOptions (path );if _fe !=nil {return _fe ;};_ge =_f .New (_dfe );_da ,_ba :=_d .WithTimeout (_d .Background (),_df .Second *5);defer _ba ();if _bg :=_ge .HealthCheck (_da ); +_bg !=nil {return _bg ;};return nil ;}; // GetContent returns the content of the document. -func (_eaf *Document )GetContent ()_fb .Content {return _eaf ._bf }; +func (_dec *Document )GetContent ()_ef .Content {return _dec ._dg };var _ _ac .Drawable =(*Document )(nil ); -// SetTimeoutDuration sets the timeout duration -// the default timeout is 15 seconds. -func (_ggb *Document )SetTimeoutDuration (duration _fd .Duration ){_ggb ._fc =&duration }; - -// SetPageHeight sets the page height for given document. -func (_bgc *Document )SetPageHeight (pageHeight _g .Length )error {_bgc ._eb =pageHeight ;_bgc ._bg =_cb .PositionAbsolute ;return nil ;}; - -// Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. -type Document struct{_bf _fb .Content ;_fdb margins ;_bg _cb .Positioning ;_fbd ,_fba float64 ;_ffa _g .PageSize ;_db ,_eb _g .Length ;_ced _g .Orientation ;_fdg bool ;_age _fd .Duration ;_ac []_fde .BySelector ;_da []_fde .BySelector ;_fc *_fd .Duration ; -};func (_edf *Document )extract (_gff _f .Context ,_fag ,_gaa _g .Length ,_feg margins )([]*_ed .PdfPage ,error ){_dbb :=_fde .BuildHTMLQuery ().SetContent (_edf ._bf ).PageSize (_edf ._ffa ).PaperWidth (_fag ).PaperHeight (_gaa ).Orientation (_edf ._ced ).MarginLeft (_feg .Left ).MarginRight (_feg .Right ).MarginTop (_feg .Top ).MarginBottom (_feg .Bottom ).TimeoutDuration (_edf .getTimeoutDuration ()).WaitTime (_edf ._age ); -for _ ,_ade :=range _edf ._ac {_dbb .WaitReady (_ade .Selector ,_ade .By );};for _ ,_edb :=range _edf ._da {_dbb .WaitVisible (_edb .Selector ,_edb .By );};_fad ,_aag :=_dbb .Query ();if _aag !=nil {return nil ,_aag ;};var _ace _f .CancelFunc ;if _edf ._fc !=nil {_gff ,_ace =_f .WithTimeout (_gff ,*_edf ._fc ); -}else {_gff ,_ace =_f .WithTimeout (_gff ,_fd .Second *15);};defer _ace ();_eff ,_aag :=_dd .ConvertHTML (_gff ,_fad );if _aag !=nil {return nil ,_aag ;};_fbf :=_ee .NewReader (_eff .Data );_dba ,_aag :=_ed .NewPdfReader (_fbf );if _aag !=nil {return nil ,_aag ; -};return _dba .PageList ,nil ;}; +// SetPageWidth sets the page width for given document. +func (_caa *Document )SetPageWidth (pageWidth _gf .Length )error {_caa ._db =pageWidth ;_caa ._dgg =_ac .PositionAbsolute ;return nil ;}; -// ContainerComponent implements creator.containerElement interface. -func (_bd *Document )ContainerComponent (container _cb .Drawable )(_cb .Drawable ,error ){switch container .(type ){case *_cb .Chapter :default:return nil ,_ea .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); -};return _bd ,nil ;};func _aa ()error {_ca :=_fdd .GetLicenseKey ();if _ca ==nil {return _a .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};if !_ca .IsLicensed (){return _a .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); -};return nil ;}; +// SetPageSize sets the page default size. +func (_dfd *Document )SetPageSize (pageSize _gf .PageSize )error {if !pageSize .IsAPageSize (){return _cg .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); +};_dfd ._eaa =pageSize ;_dfd ._dgg =_ac .PositionAbsolute ;return nil ;}; -// SetMarginTop sets the left margin. -func (_gbe *Document )SetMarginTop (margin _g .Length ){_gbe ._fdb .Top =margin }; +// SetMarginBottom sets the left margin. +func (_ffc *Document )SetMarginBottom (margin _gf .Length ){_ffc ._daf .Bottom =margin }; -// SetMargins sets the Document Margins. -func (_aca *Document )SetMargins (left ,right ,top ,bottom float64 ){_aca ._fdb .Left =_g .Point (left );_aca ._fdb .Right =_g .Point (right );_aca ._fdb .Top =_g .Point (top );_aca ._fdb .Bottom =_g .Point (bottom );_aca ._bg =_cb .PositionAbsolute ;}; +// WaitReady waits for the provided selector to be ready. +// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. +func (_efc *Document )WaitReady (sel string ,by ..._ea .ByType ){_abc :=_ea .BySearch ;if len (by )> 0{_abc =by [0];};_efc ._dab =append (_efc ._dab ,_f .BySelector {Selector :sel ,By :_abc });};var ErrContentNotDefined =_cg .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); -// SetMarginBottom sets the left margin. -func (_gg *Document )SetMarginBottom (margin _g .Length ){_gg ._fdb .Bottom =margin };var ErrContentNotDefined =_a .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); +// WaitVisible waits for the provided selector to be ready. +// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. +func (_gdf *Document )WaitVisible (sel string ,by ..._ea .ByType ){_gcda :=_ea .BySearch ;if len (by )> 0{_gcda =by [0];};_gdf ._faf =append (_gdf ._faf ,_f .BySelector {Selector :sel ,By :_gcda });}; \ No newline at end of file From e55a4f57a8d341f32c5e165dd06de752a1225447 Mon Sep 17 00:00:00 2001 From: UniDoc Build Date: Sun, 27 Apr 2025 14:57:20 +0000 Subject: [PATCH 7/9] prepare release --- cli/cmd/cmd.go | 74 +++++------ cli/main.go | 2 +- client/client.go | 284 +++++++++++++++++++++---------------------- common/common.go | 4 +- content/content.go | 71 ++++++----- go.mod | 4 +- go.sum | 6 + selector/selector.go | 10 +- sizes/sizes.go | 245 +++++++++++++++++++------------------ unihtml.go | 179 +++++++++++++-------------- 10 files changed, 442 insertions(+), 437 deletions(-) diff --git a/cli/cmd/cmd.go b/cli/cmd/cmd.go index ebfca2f..a68483b 100644 --- a/cli/cmd/cmd.go +++ b/cli/cmd/cmd.go @@ -9,56 +9,56 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package cmd ;import (_cg "context";_e "fmt";_da "github.com/mitchellh/go-homedir";_b "github.com/spf13/cobra";_db "github.com/spf13/viper";_eb "github.com/unidoc/unihtml/client";_ce "github.com/unidoc/unihtml/content";_dg "github.com/unidoc/unihtml/sizes"; -_ee "github.com/unidoc/unipdf/v3/common";_de "os";_a "path/filepath";_d "time";); - -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. -func Execute (){if _dae :=_fea .Execute ();_dae !=nil {_e .Println (_dae );_de .Exit (1);};};var _fea =&_b .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; -func _df (){_eef :=_ee .LogLevelInfo ;if _ad {_eef =_ee .LogLevelDebug ;};if _cd {_eef =_ee .LogLevelTrace ;};_ee .Log =_ee .NewConsoleLogger (_eef );};var _ba string ;func init (){_fea .AddCommand (_g );_g .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072"); -_g .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); -_g .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); -_g .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); -_g .Flags ().Var (&_dc .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_g .Flags ().Var (&_dc .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); -_g .Flags ().Var (&_dc .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_g .Flags ().Var (&_dc .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); -_g .Flags ().Var (&_dc .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_g .Flags ().Var (&_dc .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); -_g .Flags ().Var (&_dc .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_g .Flags ().Var (&_dc .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); -};type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};var _g =&_b .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_gc ,Args :_b .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; -type parametersConfig struct{ +package cmd ;import (_c "context";_cb "fmt";_cbc "github.com/mitchellh/go-homedir";_bg "github.com/spf13/cobra";_de "github.com/spf13/viper";_d "github.com/unidoc/unihtml/client";_bd "github.com/unidoc/unihtml/content";_f "github.com/unidoc/unihtml/sizes"; +_cf "github.com/unidoc/unipdf/v3/common";_b "os";_g "path/filepath";_a "time";);func _bbd (){if _ae !=""{_de .SetConfigFile (_ae );}else {_ec ,_gcg :=_cbc .Dir ();if _gcg !=nil {_cb .Println (_gcg );_b .Exit (1);};_de .AddConfigPath (_ec );_de .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063"); +};_de .AutomaticEnv ();if _adc :=_de .ReadInConfig ();_adc ==nil {_cb .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_de .ConfigFileUsed ());};};type parametersConfig struct{ // PaperWidth sets the width of the paper. -PaperWidth _dg .LengthFlag `mapstructure:"paper-width"`; +PaperWidth _f .LengthFlag `mapstructure:"paper-width"`; // PaperHeight is the height of the output paper. -PaperHeight _dg .LengthFlag `mapstructure:"paper-height"`; +PaperHeight _f .LengthFlag `mapstructure:"paper-height"`; // PageSize is the page size string. -PageSize _dg .PageSize `mapstructure:"page-size"`; +PageSize _f .PageSize `mapstructure:"page-size"`; // Orientation defines if the output should be in a landscape format. -Orientation _dg .Orientation `mapstructure:"orientation"`; +Orientation _f .Orientation `mapstructure:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _dg .LengthFlag `mapstructure:"margin-top"`; +MarginTop _f .LengthFlag `mapstructure:"margin-top"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _dg .LengthFlag `mapstructure:"margin-bottom"`; +MarginBottom _f .LengthFlag `mapstructure:"margin-bottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _dg .LengthFlag `mapstructure:"margin-left"`; +MarginLeft _f .LengthFlag `mapstructure:"margin-left"`; // MarginRight sets up the Right Margin for the output. -MarginRight _dg .LengthFlag `mapstructure:"margin-right"`;};var (_ad ,_cd bool ;);var (_f =generateConfig {};_dc =parametersConfig {PaperWidth :_dg .LengthFlag {Length :_dg .Inch (8.5).Millimeters ()},PaperHeight :_dg .LengthFlag {Length :_dg .Inch (11).Millimeters ()},Orientation :_dg .Portrait ,MarginTop :_dg .LengthFlag {Length :_dg .Millimeter (10)},MarginBottom :_dg .LengthFlag {Length :_dg .Millimeter (10)},MarginLeft :_dg .LengthFlag {Length :_dg .Millimeter (10)},MarginRight :_dg .LengthFlag {Length :_dg .Millimeter (10)}}; -);func init (){_b .OnInitialize (_fa );_fea .PersistentFlags ().BoolVarP (&_ad ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065");_fea .PersistentFlags ().BoolVarP (&_cd ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); -_fea .PersistentFlags ().StringVar (&_ba ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); -_fea .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};func _fa (){if _ba !=""{_db .SetConfigFile (_ba ); -}else {_baf ,_dd :=_da .Dir ();if _dd !=nil {_e .Println (_dd );_de .Exit (1);};_db .AddConfigPath (_baf );_db .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063");};_db .AutomaticEnv ();if _bgc :=_db .ReadInConfig (); -_bgc ==nil {_e .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_db .ConfigFileUsed ());};};func _gc (cmd *_b .Command ,_be []string ){_bc :=_d .Now ();if _ag :=_db .BindPFlags (cmd .Flags ());_ag !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ag ); -_de .Exit (1);};if _fe :=_db .Unmarshal (&_f );_fe !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_fe );_de .Exit (1);};_df ();_agb ,_bg :=_de .Stat (_be [0]);if _bg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_bg ); -_de .Exit (1);};if !_agb .IsDir (){if _a .Ext (_agb .Name ())!="\u002e\u0068\u0074m\u006c"{_e .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_be [0]); -_de .Exit (1);};};_fec ,_bg :=_de .OpenFile (_be [1],_de .O_CREATE |_de .O_WRONLY |_de .O_TRUNC ,0700);if _bg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_bg );_de .Exit (1);};defer _fec .Close ();_gb :=_eb .New (_eb .Options {HTTPS :_f .Https ,Hostname :_f .Host ,Port :_f .Port ,Prefix :_f .Prefix }); -_bd ,_dcg :=_cg .WithTimeout (_cg .Background (),_d .Second *10);defer _dcg ();_bf :=_d .Now ();var _cb _ce .Content ;if _agb .IsDir (){_cb ,_bg =_ce .NewZipDirectory (_be [0]);}else {_cb ,_bg =_ce .NewHTMLFile (_be [0]);};if _bg !=nil {_e .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_bg ); -_de .Exit (1);};_dbb ,_bg :=_eb .BuildHTMLQuery ().PaperWidth (_dc .PaperWidth .Length ).PaperHeight (_dc .PaperHeight .Length ).PageSize (_dc .PageSize ).MarginTop (_dc .MarginTop .Length ).MarginBottom (_dc .MarginBottom .Length ).MarginLeft (_dc .MarginLeft .Length ).MarginRight (_dc .MarginRight .Length ).Orientation (_dc .Orientation ).SetContent (_cb ).Query (); -if _bg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_bg );_de .Exit (1);};_eec ,_bg :=_gb .ConvertHTML (_bd ,_dbb );if _bg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_bg );_de .Exit (1);};_ee .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_d .Since (_bf )); -_bf =_d .Now ();_ ,_bg =_fec .Write (_eec .Data );if _bg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_bg );_de .Exit (1);};_ee .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_d .Since (_bf )); -_e .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_d .Since (_bc ));}; \ No newline at end of file +MarginRight _f .LengthFlag `mapstructure:"margin-right"`;}; + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute (){if _cc :=_ceg .Execute ();_cc !=nil {_cb .Println (_cc );_b .Exit (1);};};var _dee =&_bg .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_dd ,Args :_bg .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; +func init (){_ceg .AddCommand (_dee );_dee .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072");_dee .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); +_dee .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); +_dee .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); +_dee .Flags ().Var (&_ce .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_dee .Flags ().Var (&_ce .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); +_dee .Flags ().Var (&_ce .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_dee .Flags ().Var (&_ce .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); +_dee .Flags ().Var (&_ce .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_dee .Flags ().Var (&_ce .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); +_dee .Flags ().Var (&_ce .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_dee .Flags ().Var (&_ce .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); +};var (_ee =generateConfig {};_ce =parametersConfig {PaperWidth :_f .LengthFlag {Length :_f .Inch (8.5).Millimeters ()},PaperHeight :_f .LengthFlag {Length :_f .Inch (11).Millimeters ()},Orientation :_f .Portrait ,MarginTop :_f .LengthFlag {Length :_f .Millimeter (10)},MarginBottom :_f .LengthFlag {Length :_f .Millimeter (10)},MarginLeft :_f .LengthFlag {Length :_f .Millimeter (10)},MarginRight :_f .LengthFlag {Length :_f .Millimeter (10)}}; +);var _ceg =&_bg .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; +func _dd (cmd *_bg .Command ,_eea []string ){_gc :=_a .Now ();if _dc :=_de .BindPFlags (cmd .Flags ());_dc !=nil {_cb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dc );_b .Exit (1);};if _cfe :=_de .Unmarshal (&_ee );_cfe !=nil {_cb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_cfe ); +_b .Exit (1);};_cee ();_aa ,_ab :=_b .Stat (_eea [0]);if _ab !=nil {_cb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ab );_b .Exit (1);};if !_aa .IsDir (){if _g .Ext (_aa .Name ())!="\u002e\u0068\u0074m\u006c"{_cb .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_eea [0]); +_b .Exit (1);};};_fg ,_ab :=_b .OpenFile (_eea [1],_b .O_CREATE |_b .O_WRONLY |_b .O_TRUNC ,0700);if _ab !=nil {_cb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ab );_b .Exit (1);};defer _fg .Close ();_dce :=_d .New (_d .Options {HTTPS :_ee .Https ,Hostname :_ee .Host ,Port :_ee .Port ,Prefix :_ee .Prefix }); +_eb ,_fe :=_c .WithTimeout (_c .Background (),_a .Second *10);defer _fe ();_cg :=_a .Now ();var _af _bd .Content ;if _aa .IsDir (){_af ,_ab =_bd .NewZipDirectory (_eea [0]);}else {_af ,_ab =_bd .NewHTMLFile (_eea [0]);};if _ab !=nil {_cb .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_ab ); +_b .Exit (1);};_fb ,_ab :=_d .BuildHTMLQuery ().PaperWidth (_ce .PaperWidth .Length ).PaperHeight (_ce .PaperHeight .Length ).PageSize (_ce .PageSize ).MarginTop (_ce .MarginTop .Length ).MarginBottom (_ce .MarginBottom .Length ).MarginLeft (_ce .MarginLeft .Length ).MarginRight (_ce .MarginRight .Length ).Orientation (_ce .Orientation ).SetContent (_af ).Query (); +if _ab !=nil {_cb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ab );_b .Exit (1);};_bb ,_ab :=_dce .ConvertHTML (_eb ,_fb );if _ab !=nil {_cb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ab );_b .Exit (1);};_cf .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_a .Since (_cg )); +_cg =_a .Now ();_ ,_ab =_fg .Write (_bb .Data );if _ab !=nil {_cb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ab );_b .Exit (1);};_cf .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_a .Since (_cg )); +_cb .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_a .Since (_gc ));};var _ae string ;type generateConfig struct{Port int `mapstructure:"port"`; +Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};func init (){_bg .OnInitialize (_bbd );_ceg .PersistentFlags ().BoolVarP (&_gg ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065"); +_ceg .PersistentFlags ().BoolVarP (&_gf ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); +_ceg .PersistentFlags ().StringVar (&_ae ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); +_ceg .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};var (_gg ,_gf bool ;);func _cee (){_fee :=_cf .LogLevelInfo ; +if _gg {_fee =_cf .LogLevelDebug ;};if _gf {_fee =_cf .LogLevelTrace ;};_cf .Log =_cf .NewConsoleLogger (_fee );}; \ No newline at end of file diff --git a/cli/main.go b/cli/main.go index 48b52ba..73486a2 100644 --- a/cli/main.go +++ b/cli/main.go @@ -9,4 +9,4 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package main ;import _a "github.com/unidoc/unihtml/cli/cmd";func main (){_a .Execute ()}; \ No newline at end of file +package main ;import _f "github.com/unidoc/unihtml/cli/cmd";func main (){_f .Execute ()}; \ No newline at end of file diff --git a/client/client.go b/client/client.go index ddcf12e..04c5166 100644 --- a/client/client.go +++ b/client/client.go @@ -11,203 +11,201 @@ // Package client contains HTML Converter HTTP Client. The Client implements htmlcreator.HTMLConverter interface // for the UniPDF module and can be used as a plugin for the UniPDF creator.Creator. -package client ;import (_a "bytes";_dd "compress/flate";_gb "compress/gzip";_g "context";_b "encoding/json";_d "errors";_ba "fmt";_bb "github.com/unidoc/unihtml/content";_be "github.com/unidoc/unihtml/selector";_f "github.com/unidoc/unihtml/sizes";_ag "github.com/unidoc/unipdf/v3/common"; -_ge "io";_gd "net";_eb "net/http";_bg "net/url";_e "strconv";_ac "strings";_bd "time";); +package client ;import (_bg "bytes";_da "compress/flate";_c "compress/gzip";_e "context";_d "encoding/json";_ga "errors";_fa "fmt";_cd "github.com/unidoc/unihtml/content";_be "github.com/unidoc/unihtml/selector";_bae "github.com/unidoc/unihtml/sizes";_ge "github.com/unidoc/unipdf/v3/common"; +_g "io";_ebb "net";_ba "net/http";_f "net/url";_eb "strconv";_cf "strings";_gac "time";); -// WaitVisible waits for the selector to get visible. -func (_bfg *QueryBuilder )WaitVisible (selector string ,by _be .ByType )*QueryBuilder {_bfg ._fd .RenderParameters .WaitVisible =append (_bfg ._fd .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _bfg ;};var (ErrNotFound =_d .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed"); -ErrBadRequest =_d .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074");ErrNotImplemented =_d .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_d .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072"); -ErrBadGateway =_d .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079");ErrUnauthorized =_d .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_d .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074"); -); - -// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. -type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;TimeoutDuration _bd .Duration ;};func (_ec *Client )setQueryValues (_gbb *_eb .Request ,_eg *Query ){_cdg :=_gbb .URL .Query (); -_egc :=_eg .PageParameters ;if _egc .PageSize !=nil {_cdg .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_egc .PageSize .String ());};if _egc .PaperHeight !=nil {_cdg .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_egc .PaperHeight .String ()); -};if _egc .PaperWidth !=nil {_cdg .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_egc .PaperWidth .String ());};if _egc .MarginTop !=nil {_cdg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_egc .MarginTop .String ()); -};if _egc .MarginBottom !=nil {_cdg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_egc .MarginBottom .String ());};if _egc .MarginRight !=nil {_cdg .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_egc .MarginRight .String ()); -};if _egc .MarginLeft !=nil {_cdg .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_egc .MarginLeft .String ());};if _egc .Orientation ==_f .Landscape {_cdg .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_egc .Orientation .String ()); -};if _eg .RenderParameters .WaitTime !=0{_cdg .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_e .FormatInt (int64 (_eg .RenderParameters .WaitTime /_bd .Millisecond ),10));};_gbb .URL .RawQuery =_cdg .Encode (); -}; - -// WithDefaultTimeout sets the DefaultTimeout option for the client options. -func WithDefaultTimeout (option _bd .Duration )Option {return func (_ed *Options ){_ed .DefaultTimeout =option };}; - -// SetContent sets custom data with it's content type. -func (_aebg *QueryBuilder )SetContent (content _bb .Content )*QueryBuilder {if _aebg ._ece !=nil {return _aebg ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _aebg ._fd .ContentType !=""{_aebg ._ece =ErrContentTypeDeclared ; -return _aebg ;};if content .ContentType ()==""{_aebg ._ece =_ba .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _aebg ; -};_aebg ._fd .Content =content .Data ();_aebg ._fd .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _aebg ._fd .ContentType !=""{_aebg ._ece =ErrContentTypeDeclared ;return _aebg ;};_aebg ._fd .URL =string (content .Data ());_aebg ._fd .ContentType =content .ContentType (); -default:_aebg ._ece =_ba .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ());return _aebg ;};_aebg ._fd .Method =content .Method (); -return _aebg ;}; - -// Options are the client options used by the HTTP client. -type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _bd .Duration ;Prefix string ;}; - -// Validate checks if the parameters are valid. -func (_ege *PageParameters )Validate ()error {if _ege .PaperWidth !=nil {if _ege .PaperWidth .Millimeters ()< 0{return _d .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); -};};if _ege .PaperHeight !=nil {if _ege .PaperHeight .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); -};};if _ege .MarginTop !=nil {if _ege .MarginTop .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _ege .MarginBottom !=nil {if _ege .MarginBottom .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); -};};if _ege .MarginLeft !=nil {if _ege .MarginLeft .Millimeters ()< 0{return _d .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};}; -if _ege .MarginRight !=nil {if _ege .MarginRight .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); -};};if _ege .PageSize !=nil &&!_ege .PageSize .IsAPageSize (){return _d .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; - -// Portrait sets up the portrait page orientation. -func (_cdd *QueryBuilder )Portrait ()*QueryBuilder {_cdd ._fd .PageParameters .Orientation =_f .Portrait ;return _cdd ;}; - -// PageSize sets up the PageSize parameter for the query. -func (_ccd *QueryBuilder )PageSize (pageSize _f .PageSize )*QueryBuilder {if pageSize !=_f .Undefined {_ccd ._fd .PageParameters .PageSize =&pageSize ;};return _ccd ;}; - -// MarginBottom sets up the MarginBottom parameter for the query. -func (_aa *QueryBuilder )MarginBottom (marginBottom _f .Length )*QueryBuilder {_aa ._fd .PageParameters .MarginBottom =marginBottom ;return _aa ;}; - -// WaitTime sets the minimum load time parameter for the page rendering. -func (_deg *QueryBuilder )WaitTime (d _bd .Duration )*QueryBuilder {_deg ._fd .RenderParameters .WaitTime =d ;return _deg ;}; +// TimeoutDuration sets the server query duration timeout. +// Once the timeout is reached the server will return an error. +func (_cg *QueryBuilder )TimeoutDuration (d _gac .Duration )*QueryBuilder {_cg ._dd .TimeoutDuration =d ;return _cg ;};var (ErrMissingData =_ga .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061");ErrContentType =_ga .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065"); +ErrContentTypeDeclared =_ga .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064");); -// RenderParameters are the parameters related with the rendering. -type RenderParameters struct{WaitTime _bd .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; +// QueryBuilder is the query that converts HTMLConverter defined data +type QueryBuilder struct{_dd Query ;_bgb error ;}; -// ConvertHTML converts provided Query input into PDF file data. -// Implements creator.HTMLConverter interface. -func (_cc *Client )ConvertHTML (ctx _g .Context ,q *Query )(*PDFResponse ,error ){if _fc :=q .Validate ();_fc !=nil {return nil ,_fc ;};_gec ,_ccg :=_cc .getGenerateRequest (ctx ,q );if _ccg !=nil {return nil ,_ccg ;};_ag .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_gec .Method ,_gec .URL .Hostname (),_gec .URL .Path ,_gec .Header ,_gec .URL .Query ()); -_df :=*_cc .Client ;if q .TimeoutDuration !=0{_df .Timeout =q .TimeoutDuration ;};_bf ,_ccg :=_df .Do (_gec );if _ccg !=nil {return nil ,_ccg ;};var _ebc error ;switch _bf .StatusCode {case _eb .StatusNotFound :_ebc =ErrNotFound ;case _eb .StatusBadRequest :_ebc =ErrBadRequest ; -case _eb .StatusNotImplemented :_ebc =ErrNotImplemented ;case _eb .StatusUnauthorized :_ebc =ErrUnauthorized ;case _eb .StatusRequestTimeout :_ebc =ErrTimedOut ;case _eb .StatusCreated :default:_ebc =ErrInternalError ;};_dc :=_bf .Body ;switch _bf .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_dc ,_ccg =_gb .NewReader (_bf .Body ); -if _ccg !=nil {return nil ,_ccg ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_dc =_dd .NewReader (_bf .Body );case "":default:return nil ,_ba .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_bf .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); -};_af ,_ccg :=_ge .ReadAll (_dc );if _ccg !=nil &&_ebc ==nil {return nil ,_ba .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_ccg );};_ag .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_bf .StatusCode ,_gec .Method ,_gec .URL .Host ,_gec .URL .Path ); -if _ebc !=nil {return nil ,_ba .Errorf ("\u0025\u0073\u0020%\u0077",string (_af ),_ebc );};_aea :=_bf .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_ag .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_aea ); -return &PDFResponse {ID :_aea ,Data :_af },nil ;}; +// PaperWidth sets up the PaperWidth (in cm) parameter for the query. +func (_ffd *QueryBuilder )PaperWidth (paperWidth _bae .Length )*QueryBuilder {_ffd ._dd .PageParameters .PaperWidth =paperWidth ;return _ffd ;}; // Validate checks if provided Query is valid. -func (_agb *Query )Validate ()error {switch _agb .Method {case "\u0077\u0065\u0062":if _agb .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_agb .Content )==0{return ErrMissingData ;};if _agb .ContentType ==""{return ErrContentType ; -};default:return _ba .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_agb .Method );};if _afa :=_agb .PageParameters .Validate (); -_afa !=nil {return _afa ;};if _geg :=_agb .RenderParameters .Validate ();_geg !=nil {return _geg ;};return nil ;};var (ErrMissingData =_d .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061");ErrContentType =_d .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065"); -ErrContentTypeDeclared =_d .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064");); +func (_eeb *Query )Validate ()error {switch _eeb .Method {case "\u0077\u0065\u0062":if _eeb .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_eeb .Content )==0{return ErrMissingData ;};if _eeb .ContentType ==""{return ErrContentType ; +};default:return _fa .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_eeb .Method );};if _cdeg :=_eeb .PageParameters .Validate (); +_cdeg !=nil {return _cdeg ;};if _bdg :=_eeb .RenderParameters .Validate ();_bdg !=nil {return _bdg ;};return nil ;}; -// PaperWidth sets up the PaperWidth (in cm) parameter for the query. -func (_dbc *QueryBuilder )PaperWidth (paperWidth _f .Length )*QueryBuilder {_dbc ._fd .PageParameters .PaperWidth =paperWidth ;return _dbc ;}; +// BySelector is a structure that defines a selector with it's query 'by' type. +type BySelector struct{Selector string `json:"selector"`;By _be .ByType `json:"by"`;}; + +// PDFResponse is the response used by the HTMLConverter. +type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; // PageParameters are the query parameters used in the PDF generation. type PageParameters struct{ // PaperWidth sets the width of the paper. -PaperWidth _f .Length `schema:"paper-width" json:"paperWidth"`; +PaperWidth _bae .Length `schema:"paper-width" json:"paperWidth"`; // PaperHeight is the height of the output paper. -PaperHeight _f .Length `schema:"paper-height" json:"paperHeight"`; +PaperHeight _bae .Length `schema:"paper-height" json:"paperHeight"`; // PageSize is the page size string. -PageSize *_f .PageSize `schema:"page-size" json:"pageSize"`; +PageSize *_bae .PageSize `schema:"page-size" json:"pageSize"`; // Orientation defines if the output should be in a landscape format. -Orientation _f .Orientation `schema:"orientation" json:"orientation"`; +Orientation _bae .Orientation `schema:"orientation" json:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _f .Length `schema:"margin-top" json:"marginTop"`; +MarginTop _bae .Length `schema:"margin-top" json:"marginTop"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _f .Length `schema:"margin-bottom" json:"marginBottom"`; +MarginBottom _bae .Length `schema:"margin-bottom" json:"marginBottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _f .Length `schema:"margin-left" json:"marginLeft"`; +MarginLeft _bae .Length `schema:"margin-left" json:"marginLeft"`; // MarginRight sets up the Right Margin for the output. -MarginRight _f .Length `schema:"margin-right" json:"marginRight"`;}; +MarginRight _bae .Length `schema:"margin-right" json:"marginRight"`;}; + +// WaitReady waits for the selector to get ready - 'loaded'. +func (_dac *QueryBuilder )WaitReady (selector string ,by _be .ByType )*QueryBuilder {_dac ._dd .RenderParameters .WaitReady =append (_dac ._dd .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _dac ;}; // ParseOptions parses options for the Client. -func ParseOptions (connectPath string )(Options ,error ){if !_ac .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_fa ,_ad :=_bg .Parse (connectPath );if _ad !=nil {return Options {},_ba .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); -};var _ga int ;if _fa .Port ()!=""{_ga ,_ad =_e .Atoi (_fa .Port ());if _ad !=nil {return Options {},_ba .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_ad );}; -};return Options {Hostname :_fa .Hostname (),Port :_ga ,HTTPS :_fa .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_fa .Path },nil ;}; +func ParseOptions (connectPath string )(Options ,error ){if !_cf .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_df ,_db :=_f .Parse (connectPath );if _db !=nil {return Options {},_fa .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); +};var _baea int ;if _df .Port ()!=""{_baea ,_db =_eb .Atoi (_df .Port ());if _db !=nil {return Options {},_fa .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_db ); +};};return Options {Hostname :_df .Hostname (),Port :_baea ,HTTPS :_df .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_df .Path },nil ;}; -// New creates new client with provided options. -func New (o Options )*Client {o .DefaultTimeout =_bd .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _ddg =&_eb .Transport {DialContext :(&_gd .Dialer {Timeout :5*_bd .Second }).DialContext ,TLSHandshakeTimeout :5*_bd .Second }; -_ag .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_eb .Client {Transport :_ddg ,Timeout :o .DefaultTimeout }};}; +// WithPort sets the Port option for the client options. +func WithPort (option int )Option {return func (_ebd *Options ){_ebd .Port =option }};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`;Method string `json:"method"`; +ExpiresAt int64 `json:"expiresAt"`;TimeoutDuration int64 `json:"timeoutDuration,omitempty"`;PageParameters ;RenderParameters ;}; -// Orientation sets the page orientation for the Query. -func (_gff *QueryBuilder )Orientation (orientation _f .Orientation )*QueryBuilder {_gff ._fd .PageParameters .Orientation =orientation ;return _gff ;}; +// WithHostname sets the Hostname option for the client options. +func WithHostname (option string )Option {return func (_ee *Options ){_ee .Hostname =option }}; -// Validate checks the validity of the RenderParameters. -func (_bga *RenderParameters )Validate ()error {if _bga .WaitTime > _bd .Minute *3{return _d .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); -};for _ ,_aee :=range _bga .WaitReady {if _ebe :=_aee .Validate ();_ebe !=nil {return _ba .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_ebe ); -};};return nil ;}; +// DefaultPageParameters creates default parameters. +func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_bae .Portrait }}; -// WithPort sets the Port option for the client options. -func WithPort (option int )Option {return func (_cdf *Options ){_cdf .Port =option }};func (_bag *Client )getGenerateRequest (_beg _g .Context ,_ab *Query )(*_eb .Request ,error ){_ddf :=generatePDFRequestV1 {Method :_ab .Method ,PageParameters :_ab .PageParameters ,RenderParameters :_ab .RenderParameters ,TimeoutDuration :int64 (_ab .TimeoutDuration )}; -switch _ab .Method {case "\u0077\u0065\u0062":_ddf .ContentURL =_ab .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_ddf .ContentType =_ab .ContentType ;_ddf .Content =_ab .Content ;};_cb :=new (_a .Buffer );if _gf :=_b .NewEncoder (_cb ).Encode (&_ddf ); -_gf !=nil {return nil ,_ba .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_gf );};_bgf :=_bag .Options .Addr ();_bgf =_ba .Sprintf ("\u0025s\u002f\u0076\u0031\u002f\u0070\u0064f",_bgf ); -_cd ,_bfe :=_eb .NewRequest ("\u0050\u004f\u0053\u0054",_bgf ,_cb );if _bfe !=nil {return nil ,_bfe ;};_cd .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); -_cd .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); -_cd =_cd .WithContext (_beg );return _cd ,nil ;}; +// ConvertHTML converts provided Query input into PDF file data. +// Implements creator.HTMLConverter interface. +func (_dg *Client )ConvertHTML (ctx _e .Context ,q *Query )(*PDFResponse ,error ){if _cfg :=q .Validate ();_cfg !=nil {return nil ,_cfg ;};_ag ,_dbb :=_dg .getGenerateRequest (ctx ,q );if _dbb !=nil {return nil ,_dbb ;};_ge .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_ag .Method ,_ag .URL .Hostname (),_ag .URL .Path ,_ag .Header ,_ag .URL .Query ()); +_gg :=*_dg .Client ;if q .TimeoutDuration !=0{_gg .Timeout =q .TimeoutDuration ;};_aee ,_dbb :=_gg .Do (_ag );if _dbb !=nil {return nil ,_dbb ;};var _fb error ;switch _aee .StatusCode {case _ba .StatusNotFound :_fb =ErrNotFound ;case _ba .StatusBadRequest :_fb =ErrBadRequest ; +case _ba .StatusNotImplemented :_fb =ErrNotImplemented ;case _ba .StatusUnauthorized :_fb =ErrUnauthorized ;case _ba .StatusRequestTimeout :_fb =ErrTimedOut ;case _ba .StatusCreated :default:_fb =ErrInternalError ;};_fe :=_aee .Body ;switch _aee .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_fe ,_dbb =_c .NewReader (_aee .Body ); +if _dbb !=nil {return nil ,_dbb ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_fe =_da .NewReader (_aee .Body );case "":default:return nil ,_fa .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_aee .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); +};_cfb ,_dbb :=_g .ReadAll (_fe );if _dbb !=nil &&_fb ==nil {return nil ,_fa .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_dbb );};_ge .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_aee .StatusCode ,_ag .Method ,_ag .URL .Host ,_ag .URL .Path ); +if _fb !=nil {return nil ,_fa .Errorf ("\u0025\u0073\u0020%\u0077",string (_cfb ),_fb );};_ef :=_aee .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_ge .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_ef ); +return &PDFResponse {ID :_ef ,Data :_cfb },nil ;}; -// Addr gets the HTTP address URI used by the http.Client. -func (_ddd *Options )Addr ()string {_aeb :=_ac .Builder {};_aeb .WriteString ("\u0068\u0074\u0074\u0070");if _ddd .HTTPS {_aeb .WriteRune ('s');};_aeb .WriteString ("\u003a\u002f\u002f");_aeb .WriteString (_ddd .Hostname );_aeb .WriteRune (':');_aeb .WriteString (_e .Itoa (_ddd .Port )); -if _ddd .Prefix !=""{_aeb .WriteString (_ddd .Prefix );};return _aeb .String ();}; +// RenderParameters are the parameters related with the rendering. +type RenderParameters struct{WaitTime _gac .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; -// MarginTop sets up the MarginTop parameter for the query. -func (_ce *QueryBuilder )MarginTop (marginTop _f .Length )*QueryBuilder {_ce ._fd .PageParameters .MarginTop =marginTop ;return _ce ;}; +// WaitVisible waits for the selector to get visible. +func (_dceb *QueryBuilder )WaitVisible (selector string ,by _be .ByType )*QueryBuilder {_dceb ._dd .RenderParameters .WaitVisible =append (_dceb ._dd .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _dceb ;}; // Landscape sets up the landscape portrait orientation. -func (_gdg *QueryBuilder )Landscape ()*QueryBuilder {_gdg ._fd .PageParameters .Orientation =_f .Landscape ;return _gdg ;}; - -// WithPrefix sets the client prefix. -func WithPrefix (prefix string )Option {return func (_ada *Options ){_ada .Prefix =prefix }}; +func (_eg *QueryBuilder )Landscape ()*QueryBuilder {_eg ._dd .PageParameters .Orientation =_bae .Landscape ;return _eg ;}; // PaperHeight sets up the PaperHeight (in cm) parameter for the query. -func (_aga *QueryBuilder )PaperHeight (paperHeight _f .Length )*QueryBuilder {_aga ._fd .PageParameters .PaperHeight =paperHeight ;return _aga ;}; +func (_aea *QueryBuilder )PaperHeight (paperHeight _bae .Length )*QueryBuilder {_aea ._dd .PageParameters .PaperHeight =paperHeight ;return _aea ;}; -// Validate checks validity of the selector. -func (_cdfg BySelector )Validate ()error {if _cdfg .Selector ==""{return _d .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _ebd :=_cdfg .By .Validate ();_ebd !=nil {return _ebd ; -};return nil ;}; +// Validate checks if the parameters are valid. +func (_bff *PageParameters )Validate ()error {if _bff .PaperWidth !=nil {if _bff .PaperWidth .Millimeters ()< 0{return _ga .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); +};};if _bff .PaperHeight !=nil {if _bff .PaperHeight .Millimeters ()< 0{return _ga .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); +};};if _bff .MarginTop !=nil {if _bff .MarginTop .Millimeters ()< 0{return _ga .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _bff .MarginBottom !=nil {if _bff .MarginBottom .Millimeters ()< 0{return _ga .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); +};};if _bff .MarginLeft !=nil {if _bff .MarginLeft .Millimeters ()< 0{return _ga .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");}; +};if _bff .MarginRight !=nil {if _bff .MarginRight .Millimeters ()< 0{return _ga .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); +};};if _bff .PageSize !=nil &&!_bff .PageSize .IsAPageSize (){return _ga .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; // Option is a function that changes client options. -type Option func (_bfb *Options ); +type Option func (_dce *Options ); -// QueryBuilder is the query that converts HTMLConverter defined data -type QueryBuilder struct{_fd Query ;_ece error ;}; +// Addr gets the HTTP address URI used by the http.Client. +func (_dc *Options )Addr ()string {_cde :=_cf .Builder {};_cde .WriteString ("\u0068\u0074\u0074\u0070");if _dc .HTTPS {_cde .WriteRune ('s');};_cde .WriteString ("\u003a\u002f\u002f");_cde .WriteString (_dc .Hostname );_cde .WriteRune (':');_cde .WriteString (_eb .Itoa (_dc .Port )); +if _dc .Prefix !=""{_cde .WriteString (_dc .Prefix );};return _cde .String ();}; -// WithHTTPS sets the TLS option for the client options. -func WithHTTPS (useHTTPS bool )Option {return func (_acd *Options ){_acd .HTTPS =useHTTPS }}; +// MarginBottom sets up the MarginBottom parameter for the query. +func (_ddd *QueryBuilder )MarginBottom (marginBottom _bae .Length )*QueryBuilder {_ddd ._dd .PageParameters .MarginBottom =marginBottom ;return _ddd ;}; -// TimeoutDuration sets the server query duration timeout. -// Once the timeout is reached the server will return an error. -func (_adaf *QueryBuilder )TimeoutDuration (d _bd .Duration )*QueryBuilder {_adaf ._fd .TimeoutDuration =d ;return _adaf ;}; +// Query gets the Query from provided query builder. If some error occurred during build process +// or the input is not valid the function would return an error. +func (_ff *QueryBuilder )Query ()(*Query ,error ){if _afb :=_ff .Validate ();_afb !=nil {return nil ,_afb ;};return &_ff ._dd ,nil ;};func (_fee *Client )setQueryValues (_bdd *_ba .Request ,_bf *Query ){_beg :=_bdd .URL .Query ();_dff :=_bf .PageParameters ; +if _dff .PageSize !=nil {_beg .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_dff .PageSize .String ());};if _dff .PaperHeight !=nil {_beg .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_dff .PaperHeight .String ());}; +if _dff .PaperWidth !=nil {_beg .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_dff .PaperWidth .String ());};if _dff .MarginTop !=nil {_beg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_dff .MarginTop .String ()); +};if _dff .MarginBottom !=nil {_beg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_dff .MarginBottom .String ());};if _dff .MarginRight !=nil {_beg .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_dff .MarginRight .String ()); +};if _dff .MarginLeft !=nil {_beg .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_dff .MarginLeft .String ());};if _dff .Orientation ==_bae .Landscape {_beg .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_dff .Orientation .String ()); +};if _bf .RenderParameters .WaitTime !=0{_beg .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_eb .FormatInt (int64 (_bf .RenderParameters .WaitTime /_gac .Millisecond ),10));};_bdd .URL .RawQuery =_beg .Encode (); +}; -// WaitReady waits for the selector to get ready - 'loaded'. -func (_ea *QueryBuilder )WaitReady (selector string ,by _be .ByType )*QueryBuilder {_ea ._fd .RenderParameters .WaitReady =append (_ea ._fd .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _ea ;}; +// BuildHTMLQuery creates a Query builder that is supposed to create valid +func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; -// Client is a structure that is a HTTP client for the unihtml server. -type Client struct{Options Options ;Client *_eb .Client ;}; +// WaitTime sets the minimum load time parameter for the page rendering. +func (_acef *QueryBuilder )WaitTime (d _gac .Duration )*QueryBuilder {_acef ._dd .RenderParameters .WaitTime =d ;return _acef ;}; -// WithHostname sets the Hostname option for the client options. -func WithHostname (option string )Option {return func (_baa *Options ){_baa .Hostname =option }}; +// New creates new client with provided options. +func New (o Options )*Client {o .DefaultTimeout =_gac .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _gb =&_ba .Transport {DialContext :(&_ebb .Dialer {Timeout :5*_gac .Second }).DialContext ,TLSHandshakeTimeout :5*_gac .Second }; +_ge .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_ba .Client {Transport :_gb ,Timeout :o .DefaultTimeout }};}; -// BySelector is a structure that defines a selector with it's query 'by' type. -type BySelector struct{Selector string `json:"selector"`;By _be .ByType `json:"by"`;};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`;Method string `json:"method"`; -ExpiresAt int64 `json:"expiresAt"`;TimeoutDuration int64 `json:"timeoutDuration,omitempty"`;PageParameters ;RenderParameters ;}; +// Validate checks if the QueryBuilder had no errors during composition and creation. +func (_fd *QueryBuilder )Validate ()error {if _fd ._bgb !=nil {return _fd ._bgb ;};return _fd ._dd .Validate ();}; -// DefaultPageParameters creates default parameters. -func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_f .Portrait }}; +// Validate checks validity of the selector. +func (_cb BySelector )Validate ()error {if _cb .Selector ==""{return _ga .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _gc :=_cb .By .Validate ();_gc !=nil {return _gc ; +};return nil ;};func (_ace *Client )getGenerateRequest (_fbd _e .Context ,_ab *Query )(*_ba .Request ,error ){_ea :=generatePDFRequestV1 {Method :_ab .Method ,PageParameters :_ab .PageParameters ,RenderParameters :_ab .RenderParameters ,TimeoutDuration :int64 (_ab .TimeoutDuration )}; +switch _ab .Method {case "\u0077\u0065\u0062":_ea .ContentURL =_ab .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_ea .ContentType =_ab .ContentType ;_ea .Content =_ab .Content ;};_bag :=new (_bg .Buffer );if _ce :=_d .NewEncoder (_bag ).Encode (&_ea ); +_ce !=nil {return nil ,_fa .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_ce );};_bef :=_ace .Options .Addr ();_bef =_fa .Sprintf ("\u0025s\u002f\u0076\u0031\u002f\u0070\u0064f",_bef ); +_af ,_bd :=_ba .NewRequest ("\u0050\u004f\u0053\u0054",_bef ,_bag );if _bd !=nil {return nil ,_bd ;};_af .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); +_af .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); +_af =_af .WithContext (_fbd );return _af ,nil ;}; -// Err gets the error which could occur in the query. -func (_db *QueryBuilder )Err ()error {return _db ._ece }; +// Options are the client options used by the HTTP client. +type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _gac .Duration ;Prefix string ;}; + +// HealthCheck connects to the server and check the health status of the server. +func (_dae *Client )HealthCheck (ctx _e .Context )error {_a :=_dae .Options .Addr ();_a =_fa .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_a );_ae ,_ac :=_ba .NewRequest ("\u0047\u0045\u0054",_a ,nil );if _ac !=nil {return _ac ;};_ae =_ae .WithContext (ctx ); +_fc ,_ac :=_dae .Client .Do (_ae );if _ac !=nil {return _ac ;};switch _fc .StatusCode {case _ba .StatusOK :return nil ;case _ba .StatusNotFound :return ErrNotFound ;case _ba .StatusInternalServerError :return ErrInternalError ;case _ba .StatusBadGateway :return ErrBadGateway ; +default:return ErrNotImplemented ;};}; + +// Orientation sets the page orientation for the Query. +func (_gde *QueryBuilder )Orientation (orientation _bae .Orientation )*QueryBuilder {_gde ._dd .PageParameters .Orientation =orientation ;return _gde ;}; + +// MarginTop sets up the MarginTop parameter for the query. +func (_daf *QueryBuilder )MarginTop (marginTop _bae .Length )*QueryBuilder {_daf ._dd .PageParameters .MarginTop =marginTop ;return _daf ;}; + +// WithDefaultTimeout sets the DefaultTimeout option for the client options. +func WithDefaultTimeout (option _gac .Duration )Option {return func (_bgf *Options ){_bgf .DefaultTimeout =option };};var (ErrNotFound =_ga .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_ga .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); +ErrNotImplemented =_ga .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_ga .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_ga .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079"); +ErrUnauthorized =_ga .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_ga .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); + +// Validate checks the validity of the RenderParameters. +func (_dgf *RenderParameters )Validate ()error {if _dgf .WaitTime > _gac .Minute *3{return _ga .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); +};for _ ,_dbd :=range _dgf .WaitReady {if _cbb :=_dbd .Validate ();_cbb !=nil {return _fa .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_cbb ); +};};return nil ;}; + +// WithPrefix sets the client prefix. +func WithPrefix (prefix string )Option {return func (_ca *Options ){_ca .Prefix =prefix }}; // MarginRight sets up the MarginRight parameter for the query. -func (_fgb *QueryBuilder )MarginRight (marginRight _f .Length )*QueryBuilder {_fgb ._fd .PageParameters .MarginRight =marginRight ;return _fgb ;}; +func (_cab *QueryBuilder )MarginRight (marginRight _bae .Length )*QueryBuilder {_cab ._dd .PageParameters .MarginRight =marginRight ;return _cab ;}; -// MarginLeft sets up the MarginLeft parameter for the query. -func (_de *QueryBuilder )MarginLeft (marginLeft _f .Length )*QueryBuilder {_de ._fd .PageParameters .MarginLeft =marginLeft ;return _de ;}; +// Err gets the error which could occur in the query. +func (_ec *QueryBuilder )Err ()error {return _ec ._bgb }; -// Query gets the Query from provided query builder. If some error occurred during build process -// or the input is not valid the function would return an error. -func (_ca *QueryBuilder )Query ()(*Query ,error ){if _bbc :=_ca .Validate ();_bbc !=nil {return nil ,_bbc ;};return &_ca ._fd ,nil ;}; +// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. +type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;TimeoutDuration _gac .Duration ;}; -// HealthCheck connects to the server and check the health status of the server. -func (_ae *Client )HealthCheck (ctx _g .Context )error {_fg :=_ae .Options .Addr ();_fg =_ba .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_fg );_cf ,_da :=_eb .NewRequest ("\u0047\u0045\u0054",_fg ,nil );if _da !=nil {return _da ;};_cf =_cf .WithContext (ctx ); -_ebg ,_da :=_ae .Client .Do (_cf );if _da !=nil {return _da ;};switch _ebg .StatusCode {case _eb .StatusOK :return nil ;case _eb .StatusNotFound :return ErrNotFound ;case _eb .StatusInternalServerError :return ErrInternalError ;case _eb .StatusBadGateway :return ErrBadGateway ; -default:return ErrNotImplemented ;};}; +// PageSize sets up the PageSize parameter for the query. +func (_gd *QueryBuilder )PageSize (pageSize _bae .PageSize )*QueryBuilder {if pageSize !=_bae .Undefined {_gd ._dd .PageParameters .PageSize =&pageSize ;};return _gd ;}; -// Validate checks if the QueryBuilder had no errors during composition and creation. -func (_fdb *QueryBuilder )Validate ()error {if _fdb ._ece !=nil {return _fdb ._ece ;};return _fdb ._fd .Validate ();}; +// Portrait sets up the portrait page orientation. +func (_cbe *QueryBuilder )Portrait ()*QueryBuilder {_cbe ._dd .PageParameters .Orientation =_bae .Portrait ;return _cbe ;}; -// BuildHTMLQuery creates a Query builder that is supposed to create valid -func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; +// SetContent sets custom data with it's content type. +func (_fg *QueryBuilder )SetContent (content _cd .Content )*QueryBuilder {if _fg ._bgb !=nil {return _fg ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _fg ._dd .ContentType !=""{_fg ._bgb =ErrContentTypeDeclared ; +return _fg ;};if content .ContentType ()==""{_fg ._bgb =_fa .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _fg ;};_fg ._dd .Content =content .Data (); +_fg ._dd .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _fg ._dd .ContentType !=""{_fg ._bgb =ErrContentTypeDeclared ;return _fg ;};_fg ._dd .URL =string (content .Data ());_fg ._dd .ContentType =content .ContentType ();default:_fg ._bgb =_fa .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ()); +return _fg ;};_fg ._dd .Method =content .Method ();return _fg ;}; -// PDFResponse is the response used by the HTMLConverter. -type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; \ No newline at end of file +// WithHTTPS sets the TLS option for the client options. +func WithHTTPS (useHTTPS bool )Option {return func (_eaf *Options ){_eaf .HTTPS =useHTTPS }}; + +// Client is a structure that is a HTTP client for the unihtml server. +type Client struct{Options Options ;Client *_ba .Client ;}; + +// MarginLeft sets up the MarginLeft parameter for the query. +func (_gdf *QueryBuilder )MarginLeft (marginLeft _bae .Length )*QueryBuilder {_gdf ._dd .PageParameters .MarginLeft =marginLeft ;return _gdf ;}; \ No newline at end of file diff --git a/common/common.go b/common/common.go index e8fbe84..2ba66b0 100644 --- a/common/common.go +++ b/common/common.go @@ -10,7 +10,7 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package common contains common properties used by the subpackages. -package common ;import _gc "time";const Version ="\u0030\u002e\u0031\u0030\u002e\u0030";const _d ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";const _e =20; +package common ;import _g "time";const _gc =2025;var ReleasedAt =_g .Date (_gc ,_e ,_gg ,_ag ,_ge ,0,0,_g .UTC );const _gg =26;const _ag =12;const _e =4; // UtcTimeFormat returns a formatted string describing a UTC timestamp. -func UtcTimeFormat (t _gc .Time )string {return t .Format (_d )+"\u0020\u0055\u0054\u0043"};const _b =2025;var ReleasedAt =_gc .Date (_b ,_c ,_gb ,_gf ,_e ,0,0,_gc .UTC );const _gb =25;const _gf =12;const _c =3; \ No newline at end of file +func UtcTimeFormat (t _g .Time )string {return t .Format (_a )+"\u0020\u0055\u0054\u0043"};const Version ="\u0030\u002e\u0031\u0031\u002e\u0030";const _ge =20;const _a ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034"; diff --git a/content/content.go b/content/content.go index e15806f..547d5b4 100644 --- a/content/content.go +++ b/content/content.go @@ -9,64 +9,63 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package content ;import (_e "archive/zip";_fd "bytes";_b "fmt";_f "net/url";_df "os";_a "strings";);type webURL struct{_gd string }; +package content ;import (_g "archive/zip";_cg "bytes";_gf "fmt";_f "net/url";_c "os";_d "strings";); -// Data implements Content interface. -func (_fc *webURL )Data ()[]byte {return []byte (_fc ._gd )}; +// NewStringContent creates a new StringContent. +func NewStringContent (html string )(*StringContent ,error ){return &StringContent {_fdb :html },nil }; -// ContentType implements Content interface. -func (_db *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; +// Method gets the web url query method. +func (_fd *webURL )Method ()string {return "\u0077\u0065\u0062"}; // Data implements Content interface. -func (_ef *zipDirectory )Data ()[]byte {return _ef ._dff .Bytes ()}; +func (_ad *StringContent )Data ()[]byte {return []byte (_ad ._fdb )}; -// NewWebURL creates new Content webURL for provided input URL path. -func NewWebURL (path string )(Content ,error ){if _ ,_faa :=_f .Parse (path );_faa !=nil {return nil ,_faa ;};return &webURL {_gd :path },nil ;}; +// ContentType implements Content interface. +func (_bcc *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; // ContentType implements Content interface. -func (_bea *StringContent )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl";}; +func (_gfc *StringContent )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl";}; // Data implements Content interface. -func (_dbe *StringContent )Data ()[]byte {return []byte (_dbe ._fe )}; +func (_dag *zipDirectory )Data ()[]byte {return _dag ._eg .Bytes ()}; -// StringContent implements Content interface for an HTML string. -type StringContent struct{_fe string };func (_aaa *zipDirectory )zipBasePaths (_ab _df .FileInfo ,_gc ,_de string ,_da bool ,_fdf *_a .Builder )(string ,string ){_fdf .WriteString (_gc );if !_a .HasSuffix (_gc ,"\u002f"){_fdf .WriteRune ('/');};_fdf .WriteString (_ab .Name ()); -if _da {_fdf .WriteRune ('/');};_bfe :=_fdf .String ();_fdf .Reset ();_fdf .WriteString (_de );_fdf .WriteString (_ab .Name ());if _da {_fdf .WriteRune ('/');};_gf :=_fdf .String ();_fdf .Reset ();return _bfe ,_gf ;};type zipDirectory struct{_dff _fd .Buffer ; -_ce *_e .Writer ;}; +// Content is an interface used for putting the content into Client Query. +type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;};type webURL struct{_fc string }; // NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' // and stores in it's in-memory buffer. -func NewZipDirectory (dirPath string )(Content ,error ){_dfc :=&zipDirectory {_dff :_fd .Buffer {}};_dfc ._ce =_e .NewWriter (&_dfc ._dff );if _cea :=_dfc .zipPath (dirPath ,"");_cea !=nil {return nil ,_cea ;};if _ec :=_dfc ._ce .Close ();_ec !=nil {return nil ,_ec ; -};return _dfc ,nil ;};func (_ga *zipDirectory )zipPath (_gb ,_ge string )error {_fac ,_ac :=_df .ReadDir (_gb );if _ac !=nil {return _b .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_gb ,_ac ); -};_cg :=&_a .Builder {};for _ ,_fca :=range _fac {_bd ,_acb :=_fca .Info ();if _acb !=nil {return _acb ;};_dd ,_ee :=_ga .zipBasePaths (_bd ,_gb ,_ge ,_fca .IsDir (),_cg );if _fca .IsDir (){if _ae :=_ga .zipPath (_dd ,_ee );_ae !=nil {return _ae ;};continue ; -};_dc ,_acb :=_df .ReadFile (_dd );if _acb !=nil {return _acb ;};_cb ,_acb :=_ga ._ce .Create (_ee );if _acb !=nil {return _acb ;};if _ ,_acb =_cb .Write (_dc );_acb !=nil {return _acb ;};};return nil ;}; - -// Data implements Content interface. -func (_fg *htmlFile )Data ()[]byte {return _fg ._c .Bytes ()}; - -// NewStringContent creates a new StringContent. -func NewStringContent (html string )(*StringContent ,error ){return &StringContent {_fe :html },nil }; +func NewZipDirectory (dirPath string )(Content ,error ){_gg :=&zipDirectory {_eg :_cg .Buffer {}};_gg ._cd =_g .NewWriter (&_gg ._eg );if _gda :=_gg .zipPath (dirPath ,"");_gda !=nil {return nil ,_gda ;};if _af :=_gg ._cd .Close ();_af !=nil {return nil ,_af ; +};return _gg ,nil ;};type zipDirectory struct{_eg _cg .Buffer ;_cd *_g .Writer ;}; // Method implements Content interface. -func (_adg *StringContent )Method ()string {return "\u0068\u0074\u006d\u006c"}; - -// ContentType implements Content interface. -func (_bg *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; +func (_bgb *StringContent )Method ()string {return "\u0068\u0074\u006d\u006c"};func (_ggb *zipDirectory )zipPath (_cgd ,_db string )error {_ef ,_df :=_c .ReadDir (_cgd );if _df !=nil {return _gf .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_cgd ,_df ); +};_gb :=&_d .Builder {};for _ ,_dbe :=range _ef {_afc ,_aba :=_dbe .Info ();if _aba !=nil {return _aba ;};_fe ,_gff :=_ggb .zipBasePaths (_afc ,_cgd ,_db ,_dbe .IsDir (),_gb );if _dbe .IsDir (){if _de :=_ggb .zipPath (_fe ,_gff );_de !=nil {return _de ; +};continue ;};_fa ,_aba :=_c .ReadFile (_fe );if _aba !=nil {return _aba ;};_dfa ,_aba :=_ggb ._cd .Create (_gff );if _aba !=nil {return _aba ;};if _ ,_aba =_dfa .Write (_fa );_aba !=nil {return _aba ;};};return nil ;}; // Method gets the query method. -func (_be *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"}; +func (_da *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"};type htmlFile struct{_a _cg .Buffer }; -// Content is an interface used for putting the content into Client Query. -type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;}; +// ContentType implements Content interface. +func (_bg *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; + +// StringContent implements Content interface for an HTML string. +type StringContent struct{_fdb string };func (_egf *zipDirectory )zipBasePaths (_ac _c .FileInfo ,_afe ,_ca string ,_cee bool ,_faf *_d .Builder )(string ,string ){_faf .WriteString (_afe );if !_d .HasSuffix (_afe ,"\u002f"){_faf .WriteRune ('/');};_faf .WriteString (_ac .Name ()); +if _cee {_faf .WriteRune ('/');};_efd :=_faf .String ();_faf .Reset ();_faf .WriteString (_ca );_faf .WriteString (_ac .Name ());if _cee {_faf .WriteRune ('/');};_dbef :=_faf .String ();_faf .Reset ();return _efd ,_dbef ;}; // ContentType implements Content interface. -func (_fag *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"};type htmlFile struct{_c _fd .Buffer }; +func (_ab *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; + +// NewWebURL creates new Content webURL for provided input URL path. +func NewWebURL (path string )(Content ,error ){if _ ,_bfg :=_f .Parse (path );_bfg !=nil {return nil ,_bfg ;};return &webURL {_fc :path },nil ;}; // Method gets the zip directory method. -func (_aa *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; +func (_ff *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; + +// Data implements Content interface. +func (_e *webURL )Data ()[]byte {return []byte (_e ._fc )}; // NewHTMLFile creates new Content htmFile for provided input path. -func NewHTMLFile (path string )(Content ,error ){_fa ,_cc :=_df .Open (path );if _cc !=nil {return nil ,_cc ;};_g :=&htmlFile {_c :_fd .Buffer {}};if _ ,_cc =_g ._c .ReadFrom (_fa );_cc !=nil {return nil ,_cc ;};return _g ,nil ;}; +func NewHTMLFile (path string )(Content ,error ){_bc ,_gd :=_c .Open (path );if _gd !=nil {return nil ,_gd ;};_dc :=&htmlFile {_a :_cg .Buffer {}};if _ ,_gd =_dc ._a .ReadFrom (_bc );_gd !=nil {return nil ,_gd ;};return _dc ,nil ;}; -// Method gets the web url query method. -func (_ca *webURL )Method ()string {return "\u0077\u0065\u0062"}; \ No newline at end of file +// Data implements Content interface. +func (_ae *htmlFile )Data ()[]byte {return _ae ._a .Bytes ()}; \ No newline at end of file diff --git a/go.mod b/go.mod index d125340..9d7853e 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.16.0 github.com/stretchr/testify v1.10.0 - github.com/unidoc/unipdf/v3 v3.68.0 + github.com/unidoc/unipdf/v3 v3.69.0 ) require ( @@ -30,7 +30,9 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.6.0 // indirect + github.com/trimmer-io/go-xmp v1.0.0 // indirect github.com/unidoc/freetype v0.2.3 // indirect + github.com/unidoc/garabic v0.0.0-20220702200334-8c7cb25baa11 // indirect github.com/unidoc/pkcs7 v0.2.0 // indirect github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a // indirect github.com/unidoc/unichart v0.4.0 // indirect diff --git a/go.sum b/go.sum index 0938820..5b2be4b 100644 --- a/go.sum +++ b/go.sum @@ -70,8 +70,12 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +github.com/trimmer-io/go-xmp v1.0.0 h1:zY8bolSga5kOjBAaHS6hrdxLgEoYuT875xTy0QDwZWs= +github.com/trimmer-io/go-xmp v1.0.0/go.mod h1:Aaptr9sp1lLv7UnCAdQ+gSHZyY2miYaKmcNVj7HRBwA= github.com/unidoc/freetype v0.2.3 h1:uPqW+AY0vXN6K2tvtg8dMAtHTEvvHTN52b72XpZU+3I= github.com/unidoc/freetype v0.2.3/go.mod h1:mJ/Q7JnqEoWtajJVrV6S1InbRv0K/fJerPB5SQs32KI= +github.com/unidoc/garabic v0.0.0-20220702200334-8c7cb25baa11 h1:kExUKrbi429KdVVuAc85z4P+W/Rk4bjGWB5KzZLl/l8= +github.com/unidoc/garabic v0.0.0-20220702200334-8c7cb25baa11/go.mod h1:SX63w9Ww4+Z7E96B01OuG59SleQUb+m+dmapZ8o1Jac= github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= github.com/unidoc/pkcs7 v0.2.0 h1:0Y0RJR5Zu7OuD+/l7bODXARn6b8Ev2G4A8lI4rzy9kg= github.com/unidoc/pkcs7 v0.2.0/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= @@ -81,6 +85,8 @@ github.com/unidoc/unichart v0.4.0 h1:uXk9ZjbqzKb8Lt2Qv2oM9D2ftNRXvezPevgxQhsTQys github.com/unidoc/unichart v0.4.0/go.mod h1:9QsE8RbS0fE7ndHNroeCEFkRPqqk47Qsoj6QSAtcwN0= github.com/unidoc/unipdf/v3 v3.68.0 h1:AM1wKukv75hvCtTbiPb3HSIdHS5RbmR6aYTCE0jiO+A= github.com/unidoc/unipdf/v3 v3.68.0/go.mod h1:4mQ4E8niuY+30TGxT1e/8aVoSk/nn0yCKfi+kYw98+I= +github.com/unidoc/unipdf/v3 v3.69.0 h1:lW9Ljmc/kHzNRqz7Oo9l2wG6G85mwIgBZuDqsTg1x2I= +github.com/unidoc/unipdf/v3 v3.69.0/go.mod h1:4mQ4E8niuY+30TGxT1e/8aVoSk/nn0yCKfi+kYw98+I= github.com/unidoc/unitype v0.5.1 h1:UwTX15K6bktwKocWVvLoijIeu4JAVEAIeFqMOjvxqQs= github.com/unidoc/unitype v0.5.1/go.mod h1:3dxbRL+f1otNqFQIRHho8fxdg3CcUKrqS8w1SXTsqcI= golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= diff --git a/selector/selector.go b/selector/selector.go index 4d5b7c7..aadf285 100644 --- a/selector/selector.go +++ b/selector/selector.go @@ -9,10 +9,10 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package selector ;import _f "errors"; - -// Validate checks validity of the ByType. -func (_e ByType )Validate ()error {if _e >=ByID &&_e <=BySearch {return nil ;};return _f .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");}; +package selector ;import _g "errors"; // ByType is a 'By' selector type enumerator. -type ByType uint ;const (ByUndefined ByType =iota ;ByID ;ByQueryAll ;ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); \ No newline at end of file +type ByType uint ;const (ByUndefined ByType =iota ;ByID ;ByQueryAll ;ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); + +// Validate checks validity of the ByType. +func (_a ByType )Validate ()error {if _a >=ByID &&_a <=BySearch {return nil ;};return _g .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");}; \ No newline at end of file diff --git a/sizes/sizes.go b/sizes/sizes.go index fe84dcc..3aa1d9c 100644 --- a/sizes/sizes.go +++ b/sizes/sizes.go @@ -12,190 +12,189 @@ // Package sizes defines basic types that determines the size units i.e. lengths. // // -package sizes ;import (_g "encoding/json";_ae "flag";_e "fmt";_ce "strconv";_c "strings";);const (_cd =float64 (1)/float64 (25.4);_b =25.4;_d =0.0139;_ac =0.3528;_cb =1.0/64;_bc =1.0/_ac ;); +package sizes ;import (_ac "encoding/json";_a "flag";_ad "fmt";_e "strconv";_d "strings";); -// MarshalPageSize marshals the page size into string. -func MarshalPageSize (p PageSize )(string ,error ){_cgg ,_ab :=p .MarshalText ();if _ab !=nil {return "",_ab ;};return string (_cgg ),nil ;}; +// ValueType implements viper.FlagValue interface. +func (_bcc Point )ValueType ()string {return _bcc .Type ()}; -// Name implements viper.FlagValue interface. -func (_bab Point )Name ()string {return "\u0070\u006f\u0069n\u0074"};var _ Length =Inch (0);var _ccc =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ; -B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;); +// PageSizeValues returns all values of the enum +func PageSizeValues ()[]PageSize {return _cbb }; -// String implements fmt.Stringer interface. -func (_fc Inch )String ()string {_aa :=_c .Builder {};_aa .WriteString (_ce .FormatFloat (float64 (_fc ),'f',1,64));_aa .WriteString ("\u0069\u006e");return _aa .String ();};func _eaa (_fbb string )(Point ,error ){_fbb =_c .TrimSpace (_c .Trim (_fbb ,"\u0070\u0074")); -_bbe ,_gdf :=_ce .ParseFloat (_fbb ,64);if _gdf !=nil {return 0,_gdf ;};return Point (_bbe ),nil ;}; +// Millimeters gets the float64 millimeter value. +func (_eg Millimeter )Millimeters ()Millimeter {return _eg }; -// Orientation is the page orientation type wrapper. -type Orientation bool ; +// LengthFlag is a pflag wrapper for the Length value. +type LengthFlag struct{Length Length ;}; -// Points implements Length interface. -func (_dcc Inch )Points ()Point {return Point (float64 (_dcc )*_cb )}; +// String implements fmt.Stringer interface. +func (_cg Point )String ()string {_ce :=_d .Builder {};_ce .WriteString (_e .FormatFloat (float64 (_cg ),'f',1,64));_ce .WriteString ("\u0070\u0074");return _ce .String ();}; -// Set implements pflag.Value interface. -func (_ecd *PageSize )Set (s string )error {_bdf ,_fgb :=UnmarshalPageSize (s );if _fgb !=nil {return _fgb ;};*_ecd =_bdf ;return nil ;}; +// Millimeters converts the inches value to the millimeters. +func (_eba Inch )Millimeters ()Millimeter {return Millimeter (float64 (_eba )*_g )}; -// PageSizeValues returns all values of the enum -func PageSizeValues ()[]PageSize {return _ccc };const (Portrait =Orientation (false );Landscape =Orientation (true );); +// ValueType implements pflag.Value interface. +func (_db Inch )ValueType ()string {return _db .Type ()}; // Points implements Length interface. -func (_aef Millimeter )Points ()Point {return Point (_aef *_bc )}; - -// PageSizeString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func PageSizeString (s string )(PageSize ,error ){if _afb ,_bbfe :=_gde [s ];_bbfe {return _afb ,nil ;};return 0,_e .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); +func (_ee Millimeter )Points ()Point {return Point (_ee *_af )};func _aaf (_ggd string )(Point ,error ){_ggd =_d .TrimSpace (_d .Trim (_ggd ,"\u0070\u0074"));_dgc ,_cgaf :=_e .ParseFloat (_ggd ,64);if _cgaf !=nil {return 0,_cgaf ;};return Point (_dgc ),nil ; }; -// Dimensions gets the dimensions of the given page size. -// If provided page size is not valid than the function returns 0 values. -func (_bae PageSize )Dimensions ()(_ga ,_bdfc Millimeter ){switch _bae {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; -case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; -case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _ga ,_bdfc ;};var _fdg =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; +// Type implements pflag.Value interface. +func (_beb Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; -// HasChanged implements pflag.Value interface. -func (_fcd *Inch )HasChanged ()bool {return _fcd !=nil }; +// Inches gets the inches equivalent from provided millimeter value. +func (_ga Millimeter )Inches ()Inch {return Inch (float64 (_ga )*_da )}; -// Type implements pflag.Value interface. -func (_bd *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; +// HasChanged implements viper.FlagValue interface. +func (_cb *Point )HasChanged ()bool {return _cb !=nil }; -// String implements fmt.Stringer interface. -func (_cg Point )String ()string {_da :=_c .Builder {};_da .WriteString (_ce .FormatFloat (float64 (_cg ),'f',1,64));_da .WriteString ("\u0070\u0074");return _da .String ();}; +// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise +func (_fgg PageSize )IsAPageSize ()bool {for _ ,_gfae :=range _cbb {if _fgg ==_gfae {return true ;};};return false ;}; -// UnmarshalLength unmarshalls string value into Length. -func UnmarshalLength (length string )(Length ,error ){if _c .HasSuffix (length ,"\u006d\u006d"){return _dbf (length );};if _c .HasSuffix (length ,"\u0069\u006e"){return _fg (length );};if _c .HasSuffix (length ,"\u0070\u0074"){return _eaa (length );};return nil ,_e .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length ); -}; +// Inch is a unit that +type Inch float64 ; -// MarshalJSON implements json.Marshaler interface -func (_cda Millimeter )MarshalJSON ()([]byte ,error ){return _cff (_cda )}; +// Inches gets the inch value. Implements Length interface. +func (_ba Inch )Inches ()Inch {return _ba }; -// Type implements pflag.Value interface. -func (_aaf Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; +// Set implements flag.Value interface. +func (_dfd *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_dfd =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_dfd =Landscape ;default:return _ad .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); +};return nil ;};func _ec (_fg Length )([]byte ,error ){if _fg ==nil {return nil ,nil ;};_abd ,_fac :=MarshalUnit (_fg );if _fac !=nil {return nil ,_fac ;};return []byte ("\u0022"+_abd +"\u0022"),nil ;}; -// MarshalJSON implements json.Marshaler interface -func (_dce Inch )MarshalJSON ()([]byte ,error ){return _cff (_dce )}; +// Point is a unit of Length commonly used to measure the height of fonts. +type Point float64 ; -// MarshalJSON implements the json.Marshaler interface for PageSize -func (_gdff PageSize )MarshalJSON ()([]byte ,error ){return _g .Marshal (_gdff .String ())}; +// String implements fmt.Stringer interface. +func (_acd Orientation )String ()string {if _acd ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; -// Millimeter is the dimension unit that defines a millimeter. -type Millimeter float64 ; +// PageSize is the enum used for defining the page size. +type PageSize int ; -// UnmarshalPageSize unmarshals the page size from the string. -func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _fd PageSize ;if _gce :=(&_fd ).UnmarshalText ([]byte (pageSize ));_gce !=nil {return 0,_e .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_gce ); -};return _fd ,nil ;};func _dbf (_beaf string )(Millimeter ,error ){_beaf =_c .TrimSpace (_c .TrimSuffix (_beaf ,"\u006d\u006d"));_agg ,_fa :=_ce .ParseFloat (_beaf ,64);if _fa !=nil {return 0,_e .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_fa ); -};return Millimeter (_agg ),nil ;}; +// Orientation is the page orientation type wrapper. +type Orientation bool ; -// MarshalText implements the encoding.TextMarshaler interface for PageSize -func (_ggb PageSize )MarshalText ()([]byte ,error ){return []byte (_ggb .String ()),nil }; +// HasChanged implements pflag.Value interface. +func (_be *Inch )HasChanged ()bool {return _be !=nil };var _ _a .Value =(*Point )(nil ); -// Type implements pflag.Value interface. -func (_ee Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";};const _fdf ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; +// ValueString implements pflag.Value interface. +func (_bc Inch )ValueString ()string {return _bc .String ()}; +// Type implements pflag.Value interface. +func (_bb Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; -// Inch is a unit that -type Inch float64 ; +// Inches gets the inch value. Implements Length interface. +func (_ab Point )Inches ()Inch {return Inch (float64 (_ab )*_eb )}; -// Set sets the unit value. -// Implements pflag.Value interface. -func (_cf *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_cf .Length =nil ;return nil ;};_bg ,_f :=UnmarshalLength (s );if _f !=nil {return _f ;};_cf .Length =_bg ;return nil ;}; +// Name implements pflag.Value interface. +func (_bbg Inch )Name ()string {return "\u0069\u006e\u0063\u0068"};const (_da =float64 (1)/float64 (25.4);_g =25.4;_eb =0.0139;_gg =0.3528;_f =1.0/64;_af =1.0/_gg ;); // Points implements Length interface. -func (_bea Point )Points ()Point {return _bea }; +func (_df Inch )Points ()Point {return Point (float64 (_df )*_f )}; -// String implements fmt.Stringer interface. -func (_df Millimeter )String ()string {_cea :=_c .Builder {};_cea .WriteString (_ce .FormatFloat (float64 (_df ),'f',1,64));_cea .WriteString ("\u006d\u006d");return _cea .String ();}; +// Millimeter is the dimension unit that defines a millimeter. +type Millimeter float64 ;var _cbb =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};func _gaa (_bcb string )(Millimeter ,error ){_bcb =_d .TrimSpace (_d .TrimSuffix (_bcb ,"\u006d\u006d"));_fb ,_gfa :=_e .ParseFloat (_bcb ,64); +if _gfa !=nil {return 0,_ad .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_gfa );};return Millimeter (_fb ),nil ;}; -// Type implements pflag.Value interface. -func (_ea Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; +// UnmarshalPageSize unmarshals the page size from the string. +func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _dge PageSize ;if _aba :=(&_dge ).UnmarshalText ([]byte (pageSize ));_aba !=nil {return 0,_ad .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_aba ); +};return _dge ,nil ;};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;); -// ValueString implements pflag.Value interface. -func (_ba Inch )ValueString ()string {return _ba .String ()}; +// Points implements Length interface. +func (_ef Point )Points ()Point {return _ef };var _ Length =Inch (0); // UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize -func (_gdfa *PageSize )UnmarshalText (text []byte )error {var _gad error ;*_gdfa ,_gad =PageSizeString (string (text ));return _gad ;};func _cff (_cgd Length )([]byte ,error ){if _cgd ==nil {return nil ,nil ;};_ccd ,_cfb :=MarshalUnit (_cgd );if _cfb !=nil {return nil ,_cfb ; -};return []byte ("\u0022"+_ccd +"\u0022"),nil ;}; +func (_abf *PageSize )UnmarshalText (text []byte )error {var _gfg error ;*_abf ,_gfg =PageSizeString (string (text ));return _gfg ;}; -// Point is a unit of Length commonly used to measure the height of fonts. -type Point float64 ; +// Type implements pflag.Value interface. +func (_c *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; -// ValueType implements viper.FlagValue interface. -func (_ag Point )ValueType ()string {return _ag .Type ()}; +// MarshalJSON implements json.Marshaler interface. +func (_fd Point )MarshalJSON ()([]byte ,error ){return _ec (_fd )};func _ff (_aedb string )(Inch ,error ){_aedb =_d .TrimSpace (_d .Trim (_aedb ,"\u0069\u006e"));_ada ,_aea :=_e .ParseFloat (_aedb ,64);if _aea !=nil {return 0,_ad .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_aea ); +};return Inch (_ada ),nil ;}; // Set implements pflag.Value interface. -func (_dg *Inch )Set (s string )error {_dgc ,_db :=_ce .ParseFloat (s ,64);if _db !=nil {return _e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_db );};*_dg =Inch (_dgc ); -return nil ;};func (_af PageSize )String ()string {if _af < 0||_af >=PageSize (len (_fdg )-1){return _e .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_af );};return _fdf [_fdg [_af ]:_fdg [_af +1]];}; +func (_ged *PageSize )Set (s string )error {_bg ,_egc :=UnmarshalPageSize (s );if _egc !=nil {return _egc ;};*_ged =_bg ;return nil ;};func (_cacd PageSize )String ()string {if _cacd < 0||_cacd >=PageSize (len (_caa )-1){return _ad .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_cacd ); +};return _cfa [_caa [_cacd ]:_caa [_cacd +1]];}; -// Type implements pflag.Value interface. -func (_ddf PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; +// MarshalText implements the encoding.TextMarshaler interface for PageSize +func (_eacb PageSize )MarshalText ()([]byte ,error ){return []byte (_eacb .String ()),nil };var _caa =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; -// ValueType implements pflag.Value interface. -func (_gg Inch )ValueType ()string {return _gg .Type ()}; +// Millimeters converts the inches value to the millimeters. +func (_ge Point )Millimeters ()Millimeter {return Millimeter (float64 (_ge )*_gg )}; + +// Type implements pflag.Value interface. +func (_bee PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; // String implements fmt.Stringer interface. -func (_gbc Orientation )String ()string {if _gbc ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; +func (_gf Millimeter )String ()string {_gb :=_d .Builder {};_gb .WriteString (_e .FormatFloat (float64 (_gf ),'f',1,64));_gb .WriteString ("\u006d\u006d");return _gb .String ();}; -// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise -func (_gaa PageSize )IsAPageSize ()bool {for _ ,_gf :=range _ccc {if _gaa ==_gf {return true ;};};return false ;}; +// UnmarshalInch unmarshalls provided string into unit. +func UnmarshalInch (unit string )(Inch ,error ){if _d .HasSuffix (unit ,"\u006d\u006d"){_bd ,_ag :=_gaa (unit );if _ag !=nil {return 0,_ag ;};return _bd .Inches (),nil ;};if _d .HasSuffix (unit ,"\u0069\u006e"){return _ff (unit );};return 0,_ad .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); +};const _cfa ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; +var _ _a .Value =(*Orientation )(nil ); -// MarshalJSON implements json.Marshaler interface. -func (_eb Point )MarshalJSON ()([]byte ,error ){return _cff (_eb )}; +// PageSizeString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func PageSizeString (s string )(PageSize ,error ){if _bga ,_bdf :=_aafe [s ];_bdf {return _bga ,nil ;};return 0,_ad .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); +};var (_ Length =Millimeter (0);); -// HasChanged implements viper.FlagValue interface. -func (_cga *Point )HasChanged ()bool {return _cga !=nil }; +// UnmarshalLength unmarshalls string value into Length. +func UnmarshalLength (length string )(Length ,error ){if _d .HasSuffix (length ,"\u006d\u006d"){return _gaa (length );};if _d .HasSuffix (length ,"\u0069\u006e"){return _ff (length );};if _d .HasSuffix (length ,"\u0070\u0074"){return _aaf (length );};return nil ,_ad .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length ); +}; -// PageSize is the enum used for defining the page size. -type PageSize int ; +// MarshalJSON implements json.Marshaler interface +func (_egg Inch )MarshalJSON ()([]byte ,error ){return _ec (_egg )}; -// Millimeters gets the float64 millimeter value. -func (_eg Millimeter )Millimeters ()Millimeter {return _eg }; +// UnmarshalJSON implements the json.Unmarshaler interface for PageSize +func (_eac *PageSize )UnmarshalJSON (data []byte )error {var _bgaf string ;if _feb :=_ac .Unmarshal (data ,&_bgaf );_feb !=nil {return _ad .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); +};var _eeg error ;*_eac ,_eeg =PageSizeString (_bgaf );return _eeg ;}; -// Millimeters converts the inches value to the millimeters. -func (_dgd Inch )Millimeters ()Millimeter {return Millimeter (float64 (_dgd )*_b )}; +// MarshalPageSize marshals the page size into string. +func MarshalPageSize (p PageSize )(string ,error ){_dfc ,_eea :=p .MarshalText ();if _eea !=nil {return "",_eea ;};return string (_dfc ),nil ;}; + +// ValueString implements viper.FlagValue interface. +func (_cac Point )ValueString ()string {return _cac .String ()};const (Portrait =Orientation (false );Landscape =Orientation (true );); // MarshalUnit marshals the unit into the string. -func MarshalUnit (unit Length )(string ,error ){switch _bbf :=unit .(type ){case Millimeter :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_bbf ),nil ;case Inch :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_bbf ),nil ;case Point :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_bbf ),nil ; -default:return "",_e .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; +func MarshalUnit (unit Length )(string ,error ){switch _fe :=unit .(type ){case Millimeter :return _ad .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_fe ),nil ;case Inch :return _ad .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_fe ),nil ;case Point :return _ad .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_fe ),nil ; +default:return "",_ad .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; -// Inches gets the inch value. Implements Length interface. -func (_gb Point )Inches ()Inch {return Inch (float64 (_gb )*_d )}; +// Name implements viper.FlagValue interface. +func (_aed Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; -// Name implements pflag.Value interface. -func (_dc Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; +// MarshalJSON implements json.Marshaler interface +func (_ae Millimeter )MarshalJSON ()([]byte ,error ){return _ec (_ae )}; + +// Type implements pflag.Value interface. +func (_cf Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; + +// Set sets the unit value. +// Implements pflag.Value interface. +func (_aa *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_aa .Length =nil ;return nil ;};_ggf ,_bf :=UnmarshalLength (s );if _bf !=nil {return _bf ;};_aa .Length =_ggf ;return nil ;}; // Set implements flag.Value interface. -func (_dcg *Point )Set (s string )error {_cc ,_bad :=_ce .ParseFloat (s ,64);if _bad !=nil {return _e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_bad );};*_dcg =Point (_cc ); +func (_dfa *Point )Set (s string )error {_bcd ,_cga :=_e .ParseFloat (s ,64);if _cga !=nil {return _ad .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_cga );};*_dfa =Point (_bcd ); return nil ;}; -// Millimeters converts the inches value to the millimeters. -func (_fb Point )Millimeters ()Millimeter {return Millimeter (float64 (_fb )*_ac )}; - // String gets the string value for given flag. -func (_bb *LengthFlag )String ()string {if _bb .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _bb .Length .String ();}; +func (_gc *LengthFlag )String ()string {if _gc .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _gc .Length .String ();}; -// LengthFlag is a pflag wrapper for the Length value. -type LengthFlag struct{Length Length ;};var _gde =map[string ]PageSize {_fdf [0:9]:0,_fdf [9:11]:1,_fdf [11:13]:2,_fdf [13:15]:3,_fdf [15:17]:4,_fdf [17:19]:5,_fdf [19:21]:6,_fdf [21:23]:7,_fdf [23:25]:8,_fdf [25:27]:9,_fdf [27:29]:10,_fdf [29:32]:11,_fdf [32:34]:12,_fdf [34:36]:13,_fdf [36:38]:14,_fdf [38:40]:15,_fdf [40:42]:16,_fdf [42:44]:17,_fdf [44:46]:18,_fdf [46:48]:19,_fdf [48:50]:20,_fdf [50:52]:21,_fdf [52:55]:22,_fdf [55:61]:23}; -var (_ Length =Millimeter (0);); - -// UnmarshalInch unmarshalls provided string into unit. -func UnmarshalInch (unit string )(Inch ,error ){if _c .HasSuffix (unit ,"\u006d\u006d"){_bf ,_fcf :=_dbf (unit );if _fcf !=nil {return 0,_fcf ;};return _bf .Inches (),nil ;};if _c .HasSuffix (unit ,"\u0069\u006e"){return _fg (unit );};return 0,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); -};func _fg (_ec string )(Inch ,error ){_ec =_c .TrimSpace (_c .Trim (_ec ,"\u0069\u006e"));_dbe ,_dag :=_ce .ParseFloat (_ec ,64);if _dag !=nil {return 0,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_dag ); -};return Inch (_dbe ),nil ;};var _ _ae .Value =(*Point )(nil ); - -// UnmarshalJSON implements the json.Unmarshaler interface for PageSize -func (_ggg *PageSize )UnmarshalJSON (data []byte )error {var _dad string ;if _afc :=_g .Unmarshal (data ,&_dad );_afc !=nil {return _e .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); -};var _beae error ;*_ggg ,_beae =PageSizeString (_dad );return _beae ;}; +// String implements fmt.Stringer interface. +func (_fa Inch )String ()string {_ca :=_d .Builder {};_ca .WriteString (_e .FormatFloat (float64 (_fa ),'f',1,64));_ca .WriteString ("\u0069\u006e");return _ca .String ();}; // Length is it the default dimension unit. type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; -// Set implements flag.Value interface. -func (_acf *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_acf =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_acf =Landscape ;default:return _e .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); -};return nil ;};var _ _ae .Value =(*Orientation )(nil ); +// Dimensions gets the dimensions of the given page size. +// If provided page size is not valid than the function returns 0 values. +func (_gfb PageSize )Dimensions ()(_dc ,_ecc Millimeter ){switch _gfb {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; +case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; +case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _dc ,_ecc ;}; -// Inches gets the inch value. Implements Length interface. -func (_gd Inch )Inches ()Inch {return _gd }; +// Set implements pflag.Value interface. +func (_de *Inch )Set (s string )error {_ebd ,_dg :=_e .ParseFloat (s ,64);if _dg !=nil {return _ad .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_dg );};*_de =Inch (_ebd ); +return nil ;};var _aafe =map[string ]PageSize {_cfa [0:9]:0,_cfa [9:11]:1,_cfa [11:13]:2,_cfa [13:15]:3,_cfa [15:17]:4,_cfa [17:19]:5,_cfa [19:21]:6,_cfa [21:23]:7,_cfa [23:25]:8,_cfa [25:27]:9,_cfa [27:29]:10,_cfa [29:32]:11,_cfa [32:34]:12,_cfa [34:36]:13,_cfa [36:38]:14,_cfa [38:40]:15,_cfa [40:42]:16,_cfa [42:44]:17,_cfa [44:46]:18,_cfa [46:48]:19,_cfa [48:50]:20,_cfa [50:52]:21,_cfa [52:55]:22,_cfa [55:61]:23}; -// ValueString implements viper.FlagValue interface. -func (_be Point )ValueString ()string {return _be .String ()}; -// Inches gets the inches equivalent from provided millimeter value. -func (_gc Millimeter )Inches ()Inch {return Inch (float64 (_gc )*_cd )}; \ No newline at end of file +// MarshalJSON implements the json.Marshaler interface for PageSize +func (_fde PageSize )MarshalJSON ()([]byte ,error ){return _ac .Marshal (_fde .String ())}; \ No newline at end of file diff --git a/unihtml.go b/unihtml.go index d840751..467fa0d 100644 --- a/unihtml.go +++ b/unihtml.go @@ -10,59 +10,8 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package unihtml contains a plugin for the UniDoc. -package unihtml ;import (_gc "bytes";_d "context";_cg "errors";_e "fmt";_f "github.com/unidoc/unihtml/client";_ef "github.com/unidoc/unihtml/content";_ea "github.com/unidoc/unihtml/selector";_gf "github.com/unidoc/unihtml/sizes";_fa "github.com/unidoc/unipdf/v3/common"; -_a "github.com/unidoc/unipdf/v3/common/license";_ac "github.com/unidoc/unipdf/v3/creator";_cd "github.com/unidoc/unipdf/v3/model";_dff "github.com/unidoc/unipdf/v3/render";_dd "image";_g "image/color";_cb "math";_c "net/url";_de "os";_df "time";); - -// SetMarginTop sets the left margin. -func (_eaag *Document )SetMarginTop (margin _gf .Length ){_eaag ._daf .Top =margin }; - -// SetMarginLeft sets the left margin. -func (_fgd *Document )SetMarginLeft (margin _gf .Length ){_fgd ._daf .Left =margin }; - -// GeneratePageBlocks implements creator.Drawable interface. -func (_dbe *Document )GeneratePageBlocks (ctx _ac .DrawContext )([]*_ac .Block ,_ac .DrawContext ,error ){if _fc :=_dbe .validate ();_fc !=nil {return nil ,ctx ,_fc ;};var _ecg []*_ac .Block ;_ca :=_dbe .getMargins ();_fcb ,_cac :=_dbe ._db ,_dbe ._dbf ; -if _dbe ._dgg .IsRelative (){_fcb ,_cac =_gf .Point (ctx .Width ),_gf .Point (ctx .Height );ctx .X -=float64 (_ca .Left .Points ());}else {ctx .X =_dbe ._ag ;ctx .Y =_dbe ._ddb ;};_geg ,_bb :=_dbe .extract (_d .Background (),_fcb ,_cac ,_ca );if _bb !=nil {return nil ,_ac .DrawContext {},_bb ; -};for _ecd ,_dea :=range _geg {_ce ,_ff :=_ac .NewBlockFromPage (_dea );if _ff !=nil {return nil ,_ac .DrawContext {},_ff ;};var _bc float64 ;if _dbe ._ace &&_ecd ==len (_geg )-1{_gd :=_dff .NewImageDevice ();_af ,_fg :=_gd .Render (_dea );if _fg !=nil {return nil ,_ac .DrawContext {},_fg ; -};_aff ,_fg :=_dea .GetMediaBox ();if _fg !=nil {return nil ,_ac .DrawContext {},_fg ;};_bbd :=_df .Now ();_fab :=_fcg (_af );_bc =_aff .Height ()*_fab ;_fa .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_df .Since (_bbd )); -if _dbe ._daf .Bottom !=nil {_bc -=float64 (_dbe ._daf .Bottom .Points ());};if _bc < 0{_bc =0;};_fa .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_bc ); -};_ccd ,_def ,_ff :=_ce .GeneratePageBlocks (ctx );if _ff !=nil {return nil ,_ac .DrawContext {},_ff ;};ctx =_def ;ctx .Y -=_bc ;if _ecd !=len (_geg )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; -ctx .Page ++;};_ecg =append (_ecg ,_ccd ...);};return _ecg ,ctx ,nil ;}; - -// WriteToFile writes the document to a file defined by the output path. -func (_cfe *Document )WriteToFile (outputPath string )error {if _dee :=_cfe .validate ();_dee !=nil {return _dee ;};_eac :=_df .Second *20+_cfe ._gg ;_ffg ,_eaab :=_d .WithTimeout (_d .Background (),_eac );defer _eaab ();_bf ,_bd :=_cfe .extract (_ffg ,_cfe ._db ,_cfe ._dbf ,_cfe .getMargins ()); -if _bd !=nil {return _bd ;};_cfb :=_ac .New ();for _ ,_feg :=range _bf {if _bd =_cfb .AddPage (_feg );_bd !=nil {return _bd ;};};return _cfb .WriteToFile (outputPath );}; - -// ContainerComponent implements creator.containerElement interface. -func (_cdg *Document )ContainerComponent (container _ac .Drawable )(_ac .Drawable ,error ){switch container .(type ){case *_ac .Chapter :default:return nil ,_e .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); -};return _cdg ,nil ;}; - -// Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. -type Document struct{_dg _ef .Content ;_daf margins ;_dgg _ac .Positioning ;_ag ,_ddb float64 ;_eaa _gf .PageSize ;_db ,_dbf _gf .Length ;_ed _gf .Orientation ;_ace bool ;_gg _df .Duration ;_dab []_f .BySelector ;_faf []_f .BySelector ;_dde *_df .Duration ; -}; - -// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. -func (_agg *Document )TrimLastPageContent (){_agg ._ace =true };func (_gb *Document )extract (_gde _d .Context ,_aad ,_ccb _gf .Length ,_be margins )([]*_cd .PdfPage ,error ){_deg :=_f .BuildHTMLQuery ().SetContent (_gb ._dg ).PageSize (_gb ._eaa ).PaperWidth (_aad ).PaperHeight (_ccb ).Orientation (_gb ._ed ).MarginLeft (_be .Left ).MarginRight (_be .Right ).MarginTop (_be .Top ).MarginBottom (_be .Bottom ).TimeoutDuration (_gb .getTimeoutDuration ()).WaitTime (_gb ._gg ); -for _ ,_fec :=range _gb ._dab {_deg .WaitReady (_fec .Selector ,_fec .By );};for _ ,_dgd :=range _gb ._faf {_deg .WaitVisible (_dgd .Selector ,_dgd .By );};_gda ,_ddg :=_deg .Query ();if _ddg !=nil {return nil ,_ddg ;};var _aee _d .CancelFunc ;if _gb ._dde !=nil {_gde ,_aee =_d .WithTimeout (_gde ,*_gb ._dde ); -}else {_gde ,_aee =_d .WithTimeout (_gde ,_df .Second *15);};defer _aee ();_ade ,_ddg :=_ge .ConvertHTML (_gde ,_gda );if _ddg !=nil {return nil ,_ddg ;};_bad :=_gc .NewReader (_ade .Data );_cad ,_ddg :=_cd .NewPdfReader (_bad );if _ddg !=nil {return nil ,_ddg ; -};return _cad .PageList ,nil ;}; - -// NewDocument creates new HTML Document used as an input for the creator.Drawable. -func NewDocument (path string )(*Document ,error ){_ad :=&Document {};_cgg ,_fb :=_c .Parse (path );if _fb !=nil {return nil ,_fb ;};switch _cgg .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_ad ._dg ,_fb =_ef .NewWebURL (path ); -if _fb !=nil {return nil ,_fb ;};return _ad ,nil ;};_gcd ,_fb :=_de .Stat (path );if _fb !=nil {return nil ,_fb ;};if !_gcd .IsDir (){_ad ._dg ,_fb =_ef .NewHTMLFile (path );}else {_ad ._dg ,_fb =_ef .NewZipDirectory (path );};if _fb !=nil {return nil ,_fb ; -};return _ad ,nil ;}; - -// SetLandscapeOrientation sets document landscape page orientation. -func (_fbf *Document )SetLandscapeOrientation (){_fbf ._ed =_gf .Landscape };func (_gac *Document )validate ()error {if _ge ==nil {return ErrNoClient ;};if _gac ._dg ==nil {return ErrContentNotDefined ;};return nil ;}; - -// SetTimeoutDuration sets the timeout duration -// the default timeout is 15 seconds. -func (_gfce *Document )SetTimeoutDuration (duration _df .Duration ){_gfce ._dde =&duration }; - -// SetMarkedContentID sets the marked content id for the document. -func (_dbec *Document )SetMarkedContentID (id int64 )*_cd .KDict {return nil }; - -// SetPageHeight sets the page height for given document. -func (_aef *Document )SetPageHeight (pageHeight _gf .Length )error {_aef ._dbf =pageHeight ;_aef ._dgg =_ac .PositionAbsolute ;return nil ;}; +package unihtml ;import (_g "bytes";_c "context";_db "errors";_a "fmt";_b "github.com/unidoc/unihtml/client";_gc "github.com/unidoc/unihtml/content";_dee "github.com/unidoc/unihtml/selector";_af "github.com/unidoc/unihtml/sizes";_gcg "github.com/unidoc/unipdf/v3/common"; +_da "github.com/unidoc/unipdf/v3/common/license";_cef "github.com/unidoc/unipdf/v3/creator";_ab "github.com/unidoc/unipdf/v3/model";_be "github.com/unidoc/unipdf/v3/render";_dc "image";_de "image/color";_dd "math";_ce "net/url";_d "os";_df "time";); // Options are the HTML Client options used for establishing the connection. type Options struct{ @@ -77,59 +26,111 @@ Port int ; Secure bool ; // Prefix is an option setting used when the server is working with the URI prefix. Default Value: ''. -Prefix string ;};func (_cbed *Document )getMargins ()margins {_gcf :=_cbed ._daf ;if _cbed ._dgg .IsRelative (){_gcf .Top =_gf .Millimeter (1);_gcf .Left =_gf .Millimeter (1);_gcf .Bottom =_gf .Millimeter (1);_gcf .Right =_gf .Millimeter (1);return _gcf ; -};if _gcf .Top ==nil {_gcf .Top =_gf .Millimeter (10);};if _gcf .Bottom ==nil {_gcf .Bottom =_gf .Millimeter (10);};if _gcf .Left ==nil {_gcf .Left =_gf .Millimeter (10);};if _gcf .Right ==nil {_gcf .Right =_gf .Millimeter (10);};return _gcf ;}; +Prefix string ;}; + +// SetMarginTop sets the left margin. +func (_cdb *Document )SetMarginTop (margin _af .Length ){_cdb ._acb .Top =margin }; + +// SetMarginBottom sets the left margin. +func (_cbg *Document )SetMarginBottom (margin _af .Length ){_cbg ._acb .Bottom =margin }; // SetMarginRight sets the left margin. -func (_gfc *Document )SetMarginRight (margin _gf .Length ){_gfc ._daf .Right =margin }; +func (_bg *Document )SetMarginRight (margin _af .Length ){_bg ._acb .Right =margin }; -// SetMargins sets the Document Margins. -func (_efd *Document )SetMargins (left ,right ,top ,bottom float64 ){_efd ._daf .Left =_gf .Point (left );_efd ._daf .Right =_gf .Point (right );_efd ._daf .Top =_gf .Point (top );_efd ._daf .Bottom =_gf .Point (bottom );_efd ._dgg =_ac .PositionAbsolute ; -};func _fcg (_bcb _dd .Image )float64 {_gfd :=_bcb .Bounds ();var (_eg int ;_aa _g .Color ;_aceg ,_egb ,_dc uint32 ;);_ffe ,_fea :=_gfd .Min .X ,_gfd .Max .Y -1;_fcd :=_bcb .At (_ffe ,_fea );_cbe ,_fbd ,_afa ,_ :=_fcd .RGBA ();_dga :=_cbe ==_cb .MaxUint16 &&_fbd ==_cb .MaxUint16 &&_afa ==_cb .MaxUint16 ; -for _fea =_gfd .Max .Y -1;_fea >=_gfd .Min .Y ;_fea --{var _ggg bool ;for _ffe =_gfd .Min .X ;_ffe < _gfd .Max .X ;_ffe ++{_aa =_bcb .At (_ffe ,_fea );_aceg ,_egb ,_dc ,_ =_aa .RGBA ();if (_dga &&!(_aceg ==_cbe &&_egb ==_fbd &&_afa ==_dc ))||(!_dga &&(_cb .Abs (float64 (_aceg )-float64 (_cbe ))/float64 (_cb .MaxUint16 )> 0.03||_cb .Abs (float64 (_egb )-float64 (_fbd ))/float64 (_cb .MaxUint16 )> 0.03||_cb .Abs (float64 (_dc )-float64 (_afa ))/float64 (_cb .MaxUint16 )> 0.03)){_ggg =true ; -break ;};};if _ggg {break ;};_eg =_fea ;};return float64 (_gfd .Max .Y -_eg )/float64 (_gfd .Max .Y );}; +// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. +func (_ge *Document )TrimLastPageContent (){_ge ._eda =true };var ErrContentNotDefined =_db .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); +func (_baa *Document )getMargins ()margins {_abb :=_baa ._acb ;if _baa ._edb .IsRelative (){_abb .Top =_af .Millimeter (1);_abb .Left =_af .Millimeter (1);_abb .Bottom =_af .Millimeter (1);_abb .Right =_af .Millimeter (1);return _abb ;};if _abb .Top ==nil {_abb .Top =_af .Millimeter (10); +};if _abb .Bottom ==nil {_abb .Bottom =_af .Millimeter (10);};if _abb .Left ==nil {_abb .Left =_af .Millimeter (10);};if _abb .Right ==nil {_abb .Right =_af .Millimeter (10);};return _abb ;}; -// SetPos sets the absolute position. Changes object positioning to absolute. -func (_baf *Document )SetPos (x ,y float64 ){_baf ._dgg =_ac .PositionAbsolute ;_baf ._ag =x ;_baf ._ddb =y ;};func _cc ()error {_ae :=_a .GetLicenseKey ();if _ae ==nil {return _cg .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); -};if !_ae .IsLicensed (){return _cg .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};return nil ;}; +// SetMarginLeft sets the left margin. +func (_ead *Document )SetMarginLeft (margin _af .Length ){_ead ._acb .Left =margin }; + +// SetPageWidth sets the page width for given document. +func (_gdc *Document )SetPageWidth (pageWidth _af .Length )error {_gdc ._fb =pageWidth ;_gdc ._edb =_cef .PositionAbsolute ;return nil ;};func _aga (_afa _dc .Image )float64 {_fed :=_afa .Bounds ();var (_bf int ;_ebf _de .Color ;_fgd ,_fdg ,_bfa uint32 ; +);_bc ,_fgf :=_fed .Min .X ,_fed .Max .Y -1;_fae :=_afa .At (_bc ,_fgf );_ee ,_dbf ,_ced ,_ :=_fae .RGBA ();_gf :=_ee ==_dd .MaxUint16 &&_dbf ==_dd .MaxUint16 &&_ced ==_dd .MaxUint16 ;for _fgf =_fed .Max .Y -1;_fgf >=_fed .Min .Y ;_fgf --{var _fcg bool ; +for _bc =_fed .Min .X ;_bc < _fed .Max .X ;_bc ++{_ebf =_afa .At (_bc ,_fgf );_fgd ,_fdg ,_bfa ,_ =_ebf .RGBA ();if (_gf &&!(_fgd ==_ee &&_fdg ==_dbf &&_ced ==_bfa ))||(!_gf &&(_dd .Abs (float64 (_fgd )-float64 (_ee ))/float64 (_dd .MaxUint16 )> 0.03||_dd .Abs (float64 (_fdg )-float64 (_dbf ))/float64 (_dd .MaxUint16 )> 0.03||_dd .Abs (float64 (_bfa )-float64 (_ced ))/float64 (_dd .MaxUint16 )> 0.03)){_fcg =true ; +break ;};};if _fcg {break ;};_bf =_fgf ;};return float64 (_fed .Max .Y -_bf )/float64 (_fed .Max .Y );};func _ed ()error {_acc :=_da .GetLicenseKey ();if _acc ==nil {return _db .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); +};if !_acc .IsLicensed (){return _db .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};return nil ;};var ErrNoClient =_db .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); + + +// Connect creates UniHTML HTTP Client and tries to establish connection with the server. +func Connect (path string )error {if _fc :=_ed ();_fc !=nil {return _fc ;};_fa ,_cg :=_b .ParseOptions (path );if _cg !=nil {return _cg ;};_f =_b .New (_fa );_ba ,_fe :=_c .WithTimeout (_c .Background (),_df .Second *5);defer _fe ();if _cgc :=_f .HealthCheck (_ba ); +_cgc !=nil {return _cgc ;};return nil ;}; // WaitTime sets the waiting time before the webpage is rendered to PDF. -func (_eae *Document )WaitTime (duration _df .Duration ){_eae ._gg =duration }; +func (_eae *Document )WaitTime (duration _df .Duration ){_eae ._dda =duration }; -// NewDocumentFromString creates a new Document from the provided HTML string. -func NewDocumentFromString (html string )(*Document ,error ){_cba ,_ec :=_ef .NewStringContent (html );if _ec !=nil {return nil ,_ec ;};_dfc :=&Document {};_dfc ._dg =_cba ;return _dfc ,nil ;};func (_feaa *Document )getTimeoutDuration ()_df .Duration {if _feaa ._dde !=nil {return *_feaa ._dde ; -};return 0;};var _ge *_f .Client ;type margins struct{Left ,Right ,Bottom ,Top _gf .Length ;}; +// GetContent returns the content of the document. +func (_cgca *Document )GetContent ()_gc .Content {return _cgca ._ca };func (_ffa *Document )getTimeoutDuration ()_df .Duration {if _ffa ._fec !=nil {return *_ffa ._fec ;};return 0;}; -// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. -func ConnectOptions (o Options )error {_ge =_f .New (_f .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_bgg ,_cf :=_d .WithTimeout (_d .Background (),_df .Second *5);defer _cf ();if _ab :=_ge .HealthCheck (_bgg );_ab !=nil {return _ab ; -};return nil ;}; +// Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. +type Document struct{_ca _gc .Content ;_acb margins ;_edb _cef .Positioning ;_cb ,_dg float64 ;_gd _af .PageSize ;_fb ,_edf _af .Length ;_eff _af .Orientation ;_eda bool ;_dda _df .Duration ;_bd []_b .BySelector ;_gcd []_b .BySelector ;_fec *_df .Duration ; +}; + +// WaitReady waits for the provided selector to be ready. +// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. +func (_ceb *Document )WaitReady (sel string ,by ..._dee .ByType ){_agbe :=_dee .BySearch ;if len (by )> 0{_agbe =by [0];};_ceb ._bd =append (_ceb ._bd ,_b .BySelector {Selector :sel ,By :_agbe });};func (_ebd *Document )validate ()error {if _f ==nil {return ErrNoClient ; +};if _ebd ._ca ==nil {return ErrContentNotDefined ;};return nil ;}; + +// GeneratePageBlocks implements creator.Drawable interface. +func (_ag *Document )GeneratePageBlocks (ctx _cef .DrawContext )([]*_cef .Block ,_cef .DrawContext ,error ){if _dde :=_ag .validate ();_dde !=nil {return nil ,ctx ,_dde ;};var _ec []*_cef .Block ;_gdd :=_ag .getMargins ();_fdf ,_gg :=_ag ._fb ,_ag ._edf ; +if _ag ._edb .IsRelative (){_fdf ,_gg =_af .Point (ctx .Width ),_af .Point (ctx .Height );ctx .X -=float64 (_gdd .Left .Points ());}else {ctx .X =_ag ._cb ;ctx .Y =_ag ._dg ;};_ff ,_eg :=_ag .extract (_c .Background (),_fdf ,_gg ,_gdd );if _eg !=nil {return nil ,_cef .DrawContext {},_eg ; +};for _agb ,_efb :=range _ff {_cd ,_fcf :=_cef .NewBlockFromPage (_efb );if _fcf !=nil {return nil ,_cef .DrawContext {},_fcf ;};var _ga float64 ;if _ag ._eda &&_agb ==len (_ff )-1{_gdb :=_be .NewImageDevice ();_fda ,_cc :=_gdb .Render (_efb );if _cc !=nil {return nil ,_cef .DrawContext {},_cc ; +};_dae ,_cc :=_efb .GetMediaBox ();if _cc !=nil {return nil ,_cef .DrawContext {},_cc ;};_fce :=_df .Now ();_aeb :=_aga (_fda );_ga =_dae .Height ()*_aeb ;_gcg .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_df .Since (_fce )); +if _ag ._acb .Bottom !=nil {_ga -=float64 (_ag ._acb .Bottom .Points ());};if _ga < 0{_ga =0;};_gcg .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_ga ); +};_bad ,_gcgc ,_fcf :=_cd .GeneratePageBlocks (ctx );if _fcf !=nil {return nil ,_cef .DrawContext {},_fcf ;};ctx =_gcgc ;ctx .Y -=_ga ;if _agb !=len (_ff )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; +ctx .Page ++;};_ec =append (_ec ,_bad ...);};return _ec ,ctx ,nil ;}; // GetPdfPages is a function that converts provided input content and -func (_aca *Document )GetPdfPages (ctx _d .Context )([]*_cd .PdfPage ,error ){if _eda :=_aca .validate ();_eda !=nil {return nil ,_eda ;};return _aca .extract (ctx ,_aca ._db ,_aca ._dbf ,_aca .getMargins ());};var ErrNoClient =_cg .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); +func (_ae *Document )GetPdfPages (ctx _c .Context )([]*_ab .PdfPage ,error ){if _abdd :=_ae .validate ();_abdd !=nil {return nil ,_abdd ;};return _ae .extract (ctx ,_ae ._fb ,_ae ._edf ,_ae .getMargins ());};var _ _cef .Drawable =(*Document )(nil ); +// SetMarkedContentID sets the marked content id for the document. +func (_fbd *Document )SetMarkedContentID (id int64 )*_ab .KDict {return nil }; -// Connect creates UniHTML HTTP Client and tries to establish connection with the server. -func Connect (path string )error {if _ga :=_cc ();_ga !=nil {return _ga ;};_dfe ,_fe :=_f .ParseOptions (path );if _fe !=nil {return _fe ;};_ge =_f .New (_dfe );_da ,_ba :=_d .WithTimeout (_d .Background (),_df .Second *5);defer _ba ();if _bg :=_ge .HealthCheck (_da ); -_bg !=nil {return _bg ;};return nil ;}; +// WaitVisible waits for the provided selector to be ready. +// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. +func (_gfc *Document )WaitVisible (sel string ,by ..._dee .ByType ){_bada :=_dee .BySearch ;if len (by )> 0{_bada =by [0];};_gfc ._gcd =append (_gfc ._gcd ,_b .BySelector {Selector :sel ,By :_bada });}; -// GetContent returns the content of the document. -func (_dec *Document )GetContent ()_ef .Content {return _dec ._dg };var _ _ac .Drawable =(*Document )(nil ); +// SetLandscapeOrientation sets document landscape page orientation. +func (_fef *Document )SetLandscapeOrientation (){_fef ._eff =_af .Landscape }; -// SetPageWidth sets the page width for given document. -func (_caa *Document )SetPageWidth (pageWidth _gf .Length )error {_caa ._db =pageWidth ;_caa ._dgg =_ac .PositionAbsolute ;return nil ;}; +// SetPageHeight sets the page height for given document. +func (_fgc *Document )SetPageHeight (pageHeight _af .Length )error {_fgc ._edf =pageHeight ;_fgc ._edb =_cef .PositionAbsolute ;return nil ;}; + +// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. +func ConnectOptions (o Options )error {_f =_b .New (_b .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_ac ,_fd :=_c .WithTimeout (_c .Background (),_df .Second *5);defer _fd ();if _ef :=_f .HealthCheck (_ac );_ef !=nil {return _ef ; +};return nil ;}; // SetPageSize sets the page default size. -func (_dfd *Document )SetPageSize (pageSize _gf .PageSize )error {if !pageSize .IsAPageSize (){return _cg .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); -};_dfd ._eaa =pageSize ;_dfd ._dgg =_ac .PositionAbsolute ;return nil ;}; +func (_dge *Document )SetPageSize (pageSize _af .PageSize )error {if !pageSize .IsAPageSize (){return _db .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); +};_dge ._gd =pageSize ;_dge ._edb =_cef .PositionAbsolute ;return nil ;}; -// SetMarginBottom sets the left margin. -func (_ffc *Document )SetMarginBottom (margin _gf .Length ){_ffc ._daf .Bottom =margin }; +// SetTimeoutDuration sets the timeout duration +// the default timeout is 15 seconds. +func (_bfe *Document )SetTimeoutDuration (duration _df .Duration ){_bfe ._fec =&duration };type margins struct{Left ,Right ,Bottom ,Top _af .Length ;}; -// WaitReady waits for the provided selector to be ready. -// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_efc *Document )WaitReady (sel string ,by ..._ea .ByType ){_abc :=_ea .BySearch ;if len (by )> 0{_abc =by [0];};_efc ._dab =append (_efc ._dab ,_f .BySelector {Selector :sel ,By :_abc });};var ErrContentNotDefined =_cg .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); +// WriteToFile writes the document to a file defined by the output path. +func (_ccf *Document )WriteToFile (outputPath string )error {if _gca :=_ccf .validate ();_gca !=nil {return _gca ;};_aa :=_df .Second *20+_ccf ._dda ;_fg ,_eb :=_c .WithTimeout (_c .Background (),_aa );defer _eb ();_fbc ,_dag :=_ccf .extract (_fg ,_ccf ._fb ,_ccf ._edf ,_ccf .getMargins ()); +if _dag !=nil {return _dag ;};_dbe :=_cef .New ();for _ ,_dce :=range _fbc {if _dag =_dbe .AddPage (_dce );_dag !=nil {return _dag ;};};return _dbe .WriteToFile (outputPath );}; +// NewDocument creates new HTML Document used as an input for the creator.Drawable. +func NewDocument (path string )(*Document ,error ){_bec :=&Document {};_cba ,_cee :=_ce .Parse (path );if _cee !=nil {return nil ,_cee ;};switch _cba .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_bec ._ca ,_cee =_gc .NewWebURL (path ); +if _cee !=nil {return nil ,_cee ;};return _bec ,nil ;};_abd ,_cee :=_d .Stat (path );if _cee !=nil {return nil ,_cee ;};if !_abd .IsDir (){_bec ._ca ,_cee =_gc .NewHTMLFile (path );}else {_bec ._ca ,_cee =_gc .NewZipDirectory (path );};if _cee !=nil {return nil ,_cee ; +};return _bec ,nil ;};var _f *_b .Client ; -// WaitVisible waits for the provided selector to be ready. -// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_gdf *Document )WaitVisible (sel string ,by ..._ea .ByType ){_gcda :=_ea .BySearch ;if len (by )> 0{_gcda =by [0];};_gdf ._faf =append (_gdf ._faf ,_f .BySelector {Selector :sel ,By :_gcda });}; \ No newline at end of file +// SetPos sets the absolute position. Changes object positioning to absolute. +func (_beca *Document )SetPos (x ,y float64 ){_beca ._edb =_cef .PositionAbsolute ;_beca ._cb =x ;_beca ._dg =y ;}; + +// ContainerComponent implements creator.containerElement interface. +func (_gde *Document )ContainerComponent (container _cef .Drawable )(_cef .Drawable ,error ){switch container .(type ){case *_cef .Chapter :default:return nil ,_a .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); +};return _gde ,nil ;}; + +// NewDocumentFromString creates a new Document from the provided HTML string. +func NewDocumentFromString (html string )(*Document ,error ){_abe ,_ea :=_gc .NewStringContent (html );if _ea !=nil {return nil ,_ea ;};_fac :=&Document {};_fac ._ca =_abe ;return _fac ,nil ;}; + +// SetMargins sets the Document Margins. +func (_acbg *Document )SetMargins (left ,right ,top ,bottom float64 ){_acbg ._acb .Left =_af .Point (left );_acbg ._acb .Right =_af .Point (right );_acbg ._acb .Top =_af .Point (top );_acbg ._acb .Bottom =_af .Point (bottom );_acbg ._edb =_cef .PositionAbsolute ; +};func (_eaea *Document )extract (_ad _c .Context ,_ddc ,_dfa _af .Length ,_ceef margins )([]*_ab .PdfPage ,error ){_bcb :=_b .BuildHTMLQuery ().SetContent (_eaea ._ca ).PageSize (_eaea ._gd ).PaperWidth (_ddc ).PaperHeight (_dfa ).Orientation (_eaea ._eff ).MarginLeft (_ceef .Left ).MarginRight (_ceef .Right ).MarginTop (_ceef .Top ).MarginBottom (_ceef .Bottom ).TimeoutDuration (_eaea .getTimeoutDuration ()).WaitTime (_eaea ._dda ); +for _ ,_eadb :=range _eaea ._bd {_bcb .WaitReady (_eadb .Selector ,_eadb .By );};for _ ,_gge :=range _eaea ._gcd {_bcb .WaitVisible (_gge .Selector ,_gge .By );};_efc ,_cgb :=_bcb .Query ();if _cgb !=nil {return nil ,_cgb ;};var _baf _c .CancelFunc ;if _eaea ._fec !=nil {_ad ,_baf =_c .WithTimeout (_ad ,*_eaea ._fec ); +}else {_ad ,_baf =_c .WithTimeout (_ad ,_df .Second *15);};defer _baf ();_fbf ,_cgb :=_f .ConvertHTML (_ad ,_efc );if _cgb !=nil {return nil ,_cgb ;};_aad :=_g .NewReader (_fbf .Data );_cad ,_cgb :=_ab .NewPdfReader (_aad );if _cgb !=nil {return nil ,_cgb ; +};return _cad .PageList ,nil ;}; \ No newline at end of file From 11db1ca2fca0c2d39bf4a53e8c3dc746c9e891ae Mon Sep 17 00:00:00 2001 From: UniDoc Build Date: Sun, 11 May 2025 19:42:07 +0000 Subject: [PATCH 8/9] prepare release --- README.md | 4 +- cli/cmd/cmd.go | 74 +++++------ cli/main.go | 2 +- client/client.go | 288 +++++++++++++++++++++---------------------- common/common.go | 5 +- content/content.go | 73 +++++------ go.mod | 4 +- go.sum | 10 +- selector/selector.go | 7 +- sizes/sizes.go | 251 ++++++++++++++++++------------------- unihtml.go | 164 ++++++++++++------------ 11 files changed, 439 insertions(+), 443 deletions(-) diff --git a/README.md b/README.md index 2aeeed8..7de904f 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ This plugin works in a pair with the UniHTML server. It is distributed using Doc ``` 3. Define environment variable: `UNIPDF_LICENSE_PATH` with the path to the UniDoc license. 4. Define environment variable: `UNIPDF_CUSTOMER_NAME` with your customer name matching your license. -5. Get the latest version of the `github.com/unidoc/unipdf/v3` module: `go get github.com/unidoc/unipdf/v3` +5. Get the latest version of the `github.com/unidoc/unipdf/v4` module: `go get github.com/unidoc/unipdf/v4` ## UniHTML Server Licenses @@ -73,7 +73,7 @@ import ( "os" "github.com/unidoc/unihtml" - "github.com/unidoc/unipdf/v3/creator" + "github.com/unidoc/unipdf/v4/creator" ) func main() { diff --git a/cli/cmd/cmd.go b/cli/cmd/cmd.go index a68483b..d3956bb 100644 --- a/cli/cmd/cmd.go +++ b/cli/cmd/cmd.go @@ -9,56 +9,56 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package cmd ;import (_c "context";_cb "fmt";_cbc "github.com/mitchellh/go-homedir";_bg "github.com/spf13/cobra";_de "github.com/spf13/viper";_d "github.com/unidoc/unihtml/client";_bd "github.com/unidoc/unihtml/content";_f "github.com/unidoc/unihtml/sizes"; -_cf "github.com/unidoc/unipdf/v3/common";_b "os";_g "path/filepath";_a "time";);func _bbd (){if _ae !=""{_de .SetConfigFile (_ae );}else {_ec ,_gcg :=_cbc .Dir ();if _gcg !=nil {_cb .Println (_gcg );_b .Exit (1);};_de .AddConfigPath (_ec );_de .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063"); -};_de .AutomaticEnv ();if _adc :=_de .ReadInConfig ();_adc ==nil {_cb .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_de .ConfigFileUsed ());};};type parametersConfig struct{ +package cmd ;import (_b "context";_c "fmt";_g "github.com/mitchellh/go-homedir";_cc "github.com/spf13/cobra";_ef "github.com/spf13/viper";_ab "github.com/unidoc/unihtml/client";_ce "github.com/unidoc/unihtml/content";_d "github.com/unidoc/unihtml/sizes"; +_ea "github.com/unidoc/unipdf/v4/common";_ag "os";_a "path/filepath";_eg "time";);func _afg (){if _bef !=""{_ef .SetConfigFile (_bef );}else {_fa ,_fc :=_g .Dir ();if _fc !=nil {_c .Println (_fc );_ag .Exit (1);};_ef .AddConfigPath (_fa );_ef .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063"); +};_ef .AutomaticEnv ();if _fg :=_ef .ReadInConfig ();_fg ==nil {_c .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_ef .ConfigFileUsed ());};}; + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute (){if _gcg :=_aa .Execute ();_gcg !=nil {_c .Println (_gcg );_ag .Exit (1);};};var _aa =&_cc .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; +type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};func init (){_aa .AddCommand (_f );_f .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072"); +_f .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); +_f .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); +_f .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); +_f .Flags ().Var (&_ed .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_f .Flags ().Var (&_ed .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); +_f .Flags ().Var (&_ed .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_f .Flags ().Var (&_ed .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); +_f .Flags ().Var (&_ed .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_f .Flags ().Var (&_ed .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); +_f .Flags ().Var (&_ed .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_f .Flags ().Var (&_ed .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); +};type parametersConfig struct{ // PaperWidth sets the width of the paper. -PaperWidth _f .LengthFlag `mapstructure:"paper-width"`; +PaperWidth _d .LengthFlag `mapstructure:"paper-width"`; // PaperHeight is the height of the output paper. -PaperHeight _f .LengthFlag `mapstructure:"paper-height"`; +PaperHeight _d .LengthFlag `mapstructure:"paper-height"`; // PageSize is the page size string. -PageSize _f .PageSize `mapstructure:"page-size"`; +PageSize _d .PageSize `mapstructure:"page-size"`; // Orientation defines if the output should be in a landscape format. -Orientation _f .Orientation `mapstructure:"orientation"`; +Orientation _d .Orientation `mapstructure:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _f .LengthFlag `mapstructure:"margin-top"`; +MarginTop _d .LengthFlag `mapstructure:"margin-top"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _f .LengthFlag `mapstructure:"margin-bottom"`; +MarginBottom _d .LengthFlag `mapstructure:"margin-bottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _f .LengthFlag `mapstructure:"margin-left"`; +MarginLeft _d .LengthFlag `mapstructure:"margin-left"`; // MarginRight sets up the Right Margin for the output. -MarginRight _f .LengthFlag `mapstructure:"margin-right"`;}; - -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. -func Execute (){if _cc :=_ceg .Execute ();_cc !=nil {_cb .Println (_cc );_b .Exit (1);};};var _dee =&_bg .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_dd ,Args :_bg .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; -func init (){_ceg .AddCommand (_dee );_dee .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072");_dee .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); -_dee .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); -_dee .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); -_dee .Flags ().Var (&_ce .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_dee .Flags ().Var (&_ce .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); -_dee .Flags ().Var (&_ce .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_dee .Flags ().Var (&_ce .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); -_dee .Flags ().Var (&_ce .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_dee .Flags ().Var (&_ce .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); -_dee .Flags ().Var (&_ce .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_dee .Flags ().Var (&_ce .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); -};var (_ee =generateConfig {};_ce =parametersConfig {PaperWidth :_f .LengthFlag {Length :_f .Inch (8.5).Millimeters ()},PaperHeight :_f .LengthFlag {Length :_f .Inch (11).Millimeters ()},Orientation :_f .Portrait ,MarginTop :_f .LengthFlag {Length :_f .Millimeter (10)},MarginBottom :_f .LengthFlag {Length :_f .Millimeter (10)},MarginLeft :_f .LengthFlag {Length :_f .Millimeter (10)},MarginRight :_f .LengthFlag {Length :_f .Millimeter (10)}}; -);var _ceg =&_bg .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; -func _dd (cmd *_bg .Command ,_eea []string ){_gc :=_a .Now ();if _dc :=_de .BindPFlags (cmd .Flags ());_dc !=nil {_cb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dc );_b .Exit (1);};if _cfe :=_de .Unmarshal (&_ee );_cfe !=nil {_cb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_cfe ); -_b .Exit (1);};_cee ();_aa ,_ab :=_b .Stat (_eea [0]);if _ab !=nil {_cb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ab );_b .Exit (1);};if !_aa .IsDir (){if _g .Ext (_aa .Name ())!="\u002e\u0068\u0074m\u006c"{_cb .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_eea [0]); -_b .Exit (1);};};_fg ,_ab :=_b .OpenFile (_eea [1],_b .O_CREATE |_b .O_WRONLY |_b .O_TRUNC ,0700);if _ab !=nil {_cb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ab );_b .Exit (1);};defer _fg .Close ();_dce :=_d .New (_d .Options {HTTPS :_ee .Https ,Hostname :_ee .Host ,Port :_ee .Port ,Prefix :_ee .Prefix }); -_eb ,_fe :=_c .WithTimeout (_c .Background (),_a .Second *10);defer _fe ();_cg :=_a .Now ();var _af _bd .Content ;if _aa .IsDir (){_af ,_ab =_bd .NewZipDirectory (_eea [0]);}else {_af ,_ab =_bd .NewHTMLFile (_eea [0]);};if _ab !=nil {_cb .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_ab ); -_b .Exit (1);};_fb ,_ab :=_d .BuildHTMLQuery ().PaperWidth (_ce .PaperWidth .Length ).PaperHeight (_ce .PaperHeight .Length ).PageSize (_ce .PageSize ).MarginTop (_ce .MarginTop .Length ).MarginBottom (_ce .MarginBottom .Length ).MarginLeft (_ce .MarginLeft .Length ).MarginRight (_ce .MarginRight .Length ).Orientation (_ce .Orientation ).SetContent (_af ).Query (); -if _ab !=nil {_cb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ab );_b .Exit (1);};_bb ,_ab :=_dce .ConvertHTML (_eb ,_fb );if _ab !=nil {_cb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ab );_b .Exit (1);};_cf .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_a .Since (_cg )); -_cg =_a .Now ();_ ,_ab =_fg .Write (_bb .Data );if _ab !=nil {_cb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ab );_b .Exit (1);};_cf .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_a .Since (_cg )); -_cb .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_a .Since (_gc ));};var _ae string ;type generateConfig struct{Port int `mapstructure:"port"`; -Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};func init (){_bg .OnInitialize (_bbd );_ceg .PersistentFlags ().BoolVarP (&_gg ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065"); -_ceg .PersistentFlags ().BoolVarP (&_gf ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); -_ceg .PersistentFlags ().StringVar (&_ae ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); -_ceg .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};var (_gg ,_gf bool ;);func _cee (){_fee :=_cf .LogLevelInfo ; -if _gg {_fee =_cf .LogLevelDebug ;};if _gf {_fee =_cf .LogLevelTrace ;};_cf .Log =_cf .NewConsoleLogger (_fee );}; \ No newline at end of file +MarginRight _d .LengthFlag `mapstructure:"margin-right"`;};func _ae (cmd *_cc .Command ,_ec []string ){_egc :=_eg .Now ();if _efc :=_ef .BindPFlags (cmd .Flags ());_efc !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_efc );_ag .Exit (1); +};if _gad :=_ef .Unmarshal (&_ga );_gad !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gad );_ag .Exit (1);};_ecg ();_eb ,_ac :=_ag .Stat (_ec [0]);if _ac !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ac ); +_ag .Exit (1);};if !_eb .IsDir (){if _a .Ext (_eb .Name ())!="\u002e\u0068\u0074m\u006c"{_c .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_ec [0]); +_ag .Exit (1);};};_fb ,_ac :=_ag .OpenFile (_ec [1],_ag .O_CREATE |_ag .O_WRONLY |_ag .O_TRUNC ,0700);if _ac !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ac );_ag .Exit (1);};defer _fb .Close ();_ee :=_ab .New (_ab .Options {HTTPS :_ga .Https ,Hostname :_ga .Host ,Port :_ga .Port ,Prefix :_ga .Prefix }); +_be ,_gc :=_b .WithTimeout (_b .Background (),_eg .Second *10);defer _gc ();_cg :=_eg .Now ();var _aeg _ce .Content ;if _eb .IsDir (){_aeg ,_ac =_ce .NewZipDirectory (_ec [0]);}else {_aeg ,_ac =_ce .NewHTMLFile (_ec [0]);};if _ac !=nil {_c .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_ac ); +_ag .Exit (1);};_gada ,_ac :=_ab .BuildHTMLQuery ().PaperWidth (_ed .PaperWidth .Length ).PaperHeight (_ed .PaperHeight .Length ).PageSize (_ed .PageSize ).MarginTop (_ed .MarginTop .Length ).MarginBottom (_ed .MarginBottom .Length ).MarginLeft (_ed .MarginLeft .Length ).MarginRight (_ed .MarginRight .Length ).Orientation (_ed .Orientation ).SetContent (_aeg ).Query (); +if _ac !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ac );_ag .Exit (1);};_agf ,_ac :=_ee .ConvertHTML (_be ,_gada );if _ac !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ac );_ag .Exit (1);};_ea .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_eg .Since (_cg )); +_cg =_eg .Now ();_ ,_ac =_fb .Write (_agf .Data );if _ac !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ac );_ag .Exit (1);};_ea .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_eg .Since (_cg )); +_c .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_eg .Since (_egc ));};var _bef string ;var (_ga =generateConfig {};_ed =parametersConfig {PaperWidth :_d .LengthFlag {Length :_d .Inch (8.5).Millimeters ()},PaperHeight :_d .LengthFlag {Length :_d .Inch (11).Millimeters ()},Orientation :_d .Portrait ,MarginTop :_d .LengthFlag {Length :_d .Millimeter (10)},MarginBottom :_d .LengthFlag {Length :_d .Millimeter (10)},MarginLeft :_d .LengthFlag {Length :_d .Millimeter (10)},MarginRight :_d .LengthFlag {Length :_d .Millimeter (10)}}; +);var _f =&_cc .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_ae ,Args :_cc .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; +func init (){_cc .OnInitialize (_afg );_aa .PersistentFlags ().BoolVarP (&_gd ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065");_aa .PersistentFlags ().BoolVarP (&_gdd ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); +_aa .PersistentFlags ().StringVar (&_bef ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); +_aa .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};func _ecg (){_df :=_ea .LogLevelInfo ;if _gd {_df =_ea .LogLevelDebug ; +};if _gdd {_df =_ea .LogLevelTrace ;};_ea .Log =_ea .NewConsoleLogger (_df );};var (_gd ,_gdd bool ;); \ No newline at end of file diff --git a/cli/main.go b/cli/main.go index 73486a2..9be0d6b 100644 --- a/cli/main.go +++ b/cli/main.go @@ -9,4 +9,4 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package main ;import _f "github.com/unidoc/unihtml/cli/cmd";func main (){_f .Execute ()}; \ No newline at end of file +package main ;import _c "github.com/unidoc/unihtml/cli/cmd";func main (){_c .Execute ()}; \ No newline at end of file diff --git a/client/client.go b/client/client.go index 04c5166..16bf0cd 100644 --- a/client/client.go +++ b/client/client.go @@ -11,201 +11,201 @@ // Package client contains HTML Converter HTTP Client. The Client implements htmlcreator.HTMLConverter interface // for the UniPDF module and can be used as a plugin for the UniPDF creator.Creator. -package client ;import (_bg "bytes";_da "compress/flate";_c "compress/gzip";_e "context";_d "encoding/json";_ga "errors";_fa "fmt";_cd "github.com/unidoc/unihtml/content";_be "github.com/unidoc/unihtml/selector";_bae "github.com/unidoc/unihtml/sizes";_ge "github.com/unidoc/unipdf/v3/common"; -_g "io";_ebb "net";_ba "net/http";_f "net/url";_eb "strconv";_cf "strings";_gac "time";); +package client ;import (_faf "bytes";_f "compress/flate";_fa "compress/gzip";_d "context";_e "encoding/json";_dc "errors";_ed "fmt";_dac "github.com/unidoc/unihtml/content";_bb "github.com/unidoc/unihtml/selector";_gc "github.com/unidoc/unihtml/sizes"; +_aa "github.com/unidoc/unipdf/v4/common";_a "io";_ae "net";_da "net/http";_bd "net/url";_af "strconv";_ff "strings";_b "time";); -// TimeoutDuration sets the server query duration timeout. -// Once the timeout is reached the server will return an error. -func (_cg *QueryBuilder )TimeoutDuration (d _gac .Duration )*QueryBuilder {_cg ._dd .TimeoutDuration =d ;return _cg ;};var (ErrMissingData =_ga .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061");ErrContentType =_ga .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065"); -ErrContentTypeDeclared =_ga .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064");); - -// QueryBuilder is the query that converts HTMLConverter defined data -type QueryBuilder struct{_dd Query ;_bgb error ;}; +// SetContent sets custom data with it's content type. +func (_cf *QueryBuilder )SetContent (content _dac .Content )*QueryBuilder {if _cf ._ddg !=nil {return _cf ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _cf ._bea .ContentType !=""{_cf ._ddg =ErrContentTypeDeclared ; +return _cf ;};if content .ContentType ()==""{_cf ._ddg =_ed .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _cf ;};_cf ._bea .Content =content .Data (); +_cf ._bea .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _cf ._bea .ContentType !=""{_cf ._ddg =ErrContentTypeDeclared ;return _cf ;};_cf ._bea .URL =string (content .Data ());_cf ._bea .ContentType =content .ContentType ();default:_cf ._ddg =_ed .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ()); +return _cf ;};_cf ._bea .Method =content .Method ();return _cf ;}; -// PaperWidth sets up the PaperWidth (in cm) parameter for the query. -func (_ffd *QueryBuilder )PaperWidth (paperWidth _bae .Length )*QueryBuilder {_ffd ._dd .PageParameters .PaperWidth =paperWidth ;return _ffd ;}; +// WithHTTPS sets the TLS option for the client options. +func WithHTTPS (useHTTPS bool )Option {return func (_daf *Options ){_daf .HTTPS =useHTTPS }}; -// Validate checks if provided Query is valid. -func (_eeb *Query )Validate ()error {switch _eeb .Method {case "\u0077\u0065\u0062":if _eeb .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_eeb .Content )==0{return ErrMissingData ;};if _eeb .ContentType ==""{return ErrContentType ; -};default:return _fa .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_eeb .Method );};if _cdeg :=_eeb .PageParameters .Validate (); -_cdeg !=nil {return _cdeg ;};if _bdg :=_eeb .RenderParameters .Validate ();_bdg !=nil {return _bdg ;};return nil ;}; +// Option is a function that changes client options. +type Option func (_ba *Options ); -// BySelector is a structure that defines a selector with it's query 'by' type. -type BySelector struct{Selector string `json:"selector"`;By _be .ByType `json:"by"`;}; +// Validate checks if the QueryBuilder had no errors during composition and creation. +func (_abc *QueryBuilder )Validate ()error {if _abc ._ddg !=nil {return _abc ._ddg ;};return _abc ._bea .Validate ();};var (ErrNotFound =_dc .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_dc .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); +ErrNotImplemented =_dc .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_dc .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_dc .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079"); +ErrUnauthorized =_dc .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_dc .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); -// PDFResponse is the response used by the HTMLConverter. -type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; +// Client is a structure that is a HTTP client for the unihtml server. +type Client struct{Options Options ;Client *_da .Client ;}; -// PageParameters are the query parameters used in the PDF generation. -type PageParameters struct{ +// WaitTime sets the minimum load time parameter for the page rendering. +func (_fc *QueryBuilder )WaitTime (d _b .Duration )*QueryBuilder {_fc ._bea .RenderParameters .WaitTime =d ;return _fc ;}; -// PaperWidth sets the width of the paper. -PaperWidth _bae .Length `schema:"paper-width" json:"paperWidth"`; +// WithPort sets the Port option for the client options. +func WithPort (option int )Option {return func (_aea *Options ){_aea .Port =option }}; -// PaperHeight is the height of the output paper. -PaperHeight _bae .Length `schema:"paper-height" json:"paperHeight"`; +// TimeoutDuration sets the server query duration timeout. +// Once the timeout is reached the server will return an error. +func (_ace *QueryBuilder )TimeoutDuration (d _b .Duration )*QueryBuilder {_ace ._bea .TimeoutDuration =d ;return _ace ;}; -// PageSize is the page size string. -PageSize *_bae .PageSize `schema:"page-size" json:"pageSize"`; +// Orientation sets the page orientation for the Query. +func (_fdb *QueryBuilder )Orientation (orientation _gc .Orientation )*QueryBuilder {_fdb ._bea .PageParameters .Orientation =orientation ;return _fdb ;}; -// Orientation defines if the output should be in a landscape format. -Orientation _bae .Orientation `schema:"orientation" json:"orientation"`; +// PaperWidth sets up the PaperWidth (in cm) parameter for the query. +func (_fdd *QueryBuilder )PaperWidth (paperWidth _gc .Length )*QueryBuilder {_fdd ._bea .PageParameters .PaperWidth =paperWidth ;return _fdd ;}; -// MarginTop sets up the Top Margin for the output. -MarginTop _bae .Length `schema:"margin-top" json:"marginTop"`; +// DefaultPageParameters creates default parameters. +func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_gc .Portrait }}; -// MarginBottom sets up the Bottom Margin for the output. -MarginBottom _bae .Length `schema:"margin-bottom" json:"marginBottom"`; +// WithHostname sets the Hostname option for the client options. +func WithHostname (option string )Option {return func (_cef *Options ){_cef .Hostname =option }}; -// MarginLeft sets up the Left Margin for the output. -MarginLeft _bae .Length `schema:"margin-left" json:"marginLeft"`; +// Validate checks validity of the selector. +func (_cb BySelector )Validate ()error {if _cb .Selector ==""{return _dc .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _ec :=_cb .By .Validate ();_ec !=nil {return _ec ; +};return nil ;}; -// MarginRight sets up the Right Margin for the output. -MarginRight _bae .Length `schema:"margin-right" json:"marginRight"`;}; +// Validate checks the validity of the RenderParameters. +func (_ggf *RenderParameters )Validate ()error {if _ggf .WaitTime > _b .Minute *3{return _dc .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); +};for _ ,_fb :=range _ggf .WaitReady {if _afbb :=_fb .Validate ();_afbb !=nil {return _ed .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_afbb ); +};};return nil ;}; -// WaitReady waits for the selector to get ready - 'loaded'. -func (_dac *QueryBuilder )WaitReady (selector string ,by _be .ByType )*QueryBuilder {_dac ._dd .RenderParameters .WaitReady =append (_dac ._dd .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _dac ;}; +// RenderParameters are the parameters related with the rendering. +type RenderParameters struct{WaitTime _b .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; -// ParseOptions parses options for the Client. -func ParseOptions (connectPath string )(Options ,error ){if !_cf .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_df ,_db :=_f .Parse (connectPath );if _db !=nil {return Options {},_fa .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); -};var _baea int ;if _df .Port ()!=""{_baea ,_db =_eb .Atoi (_df .Port ());if _db !=nil {return Options {},_fa .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_db ); -};};return Options {Hostname :_df .Hostname (),Port :_baea ,HTTPS :_df .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_df .Path },nil ;}; +// WithPrefix sets the client prefix. +func WithPrefix (prefix string )Option {return func (_ede *Options ){_ede .Prefix =prefix }}; -// WithPort sets the Port option for the client options. -func WithPort (option int )Option {return func (_ebd *Options ){_ebd .Port =option }};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`;Method string `json:"method"`; -ExpiresAt int64 `json:"expiresAt"`;TimeoutDuration int64 `json:"timeoutDuration,omitempty"`;PageParameters ;RenderParameters ;}; +// New creates new client with provided options. +func New (o Options )*Client {o .DefaultTimeout =_b .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _fe =&_da .Transport {DialContext :(&_ae .Dialer {Timeout :5*_b .Second }).DialContext ,TLSHandshakeTimeout :5*_b .Second }; +_aa .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_da .Client {Transport :_fe ,Timeout :o .DefaultTimeout }};}; -// WithHostname sets the Hostname option for the client options. -func WithHostname (option string )Option {return func (_ee *Options ){_ee .Hostname =option }}; +// Landscape sets up the landscape portrait orientation. +func (_gbg *QueryBuilder )Landscape ()*QueryBuilder {_gbg ._bea .PageParameters .Orientation =_gc .Landscape ;return _gbg ;}; -// DefaultPageParameters creates default parameters. -func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_bae .Portrait }}; +// Validate checks if the parameters are valid. +func (_bbc *PageParameters )Validate ()error {if _bbc .PaperWidth !=nil {if _bbc .PaperWidth .Millimeters ()< 0{return _dc .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); +};};if _bbc .PaperHeight !=nil {if _bbc .PaperHeight .Millimeters ()< 0{return _dc .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); +};};if _bbc .MarginTop !=nil {if _bbc .MarginTop .Millimeters ()< 0{return _dc .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _bbc .MarginBottom !=nil {if _bbc .MarginBottom .Millimeters ()< 0{return _dc .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); +};};if _bbc .MarginLeft !=nil {if _bbc .MarginLeft .Millimeters ()< 0{return _dc .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");}; +};if _bbc .MarginRight !=nil {if _bbc .MarginRight .Millimeters ()< 0{return _dc .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); +};};if _bbc .PageSize !=nil &&!_bbc .PageSize .IsAPageSize (){return _dc .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; -// ConvertHTML converts provided Query input into PDF file data. -// Implements creator.HTMLConverter interface. -func (_dg *Client )ConvertHTML (ctx _e .Context ,q *Query )(*PDFResponse ,error ){if _cfg :=q .Validate ();_cfg !=nil {return nil ,_cfg ;};_ag ,_dbb :=_dg .getGenerateRequest (ctx ,q );if _dbb !=nil {return nil ,_dbb ;};_ge .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_ag .Method ,_ag .URL .Hostname (),_ag .URL .Path ,_ag .Header ,_ag .URL .Query ()); -_gg :=*_dg .Client ;if q .TimeoutDuration !=0{_gg .Timeout =q .TimeoutDuration ;};_aee ,_dbb :=_gg .Do (_ag );if _dbb !=nil {return nil ,_dbb ;};var _fb error ;switch _aee .StatusCode {case _ba .StatusNotFound :_fb =ErrNotFound ;case _ba .StatusBadRequest :_fb =ErrBadRequest ; -case _ba .StatusNotImplemented :_fb =ErrNotImplemented ;case _ba .StatusUnauthorized :_fb =ErrUnauthorized ;case _ba .StatusRequestTimeout :_fb =ErrTimedOut ;case _ba .StatusCreated :default:_fb =ErrInternalError ;};_fe :=_aee .Body ;switch _aee .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_fe ,_dbb =_c .NewReader (_aee .Body ); -if _dbb !=nil {return nil ,_dbb ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_fe =_da .NewReader (_aee .Body );case "":default:return nil ,_fa .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_aee .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); -};_cfb ,_dbb :=_g .ReadAll (_fe );if _dbb !=nil &&_fb ==nil {return nil ,_fa .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_dbb );};_ge .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_aee .StatusCode ,_ag .Method ,_ag .URL .Host ,_ag .URL .Path ); -if _fb !=nil {return nil ,_fa .Errorf ("\u0025\u0073\u0020%\u0077",string (_cfb ),_fb );};_ef :=_aee .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_ge .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_ef ); -return &PDFResponse {ID :_ef ,Data :_cfb },nil ;}; +// BuildHTMLQuery creates a Query builder that is supposed to create valid +func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; -// RenderParameters are the parameters related with the rendering. -type RenderParameters struct{WaitTime _gac .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; +// PDFResponse is the response used by the HTMLConverter. +type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; // WaitVisible waits for the selector to get visible. -func (_dceb *QueryBuilder )WaitVisible (selector string ,by _be .ByType )*QueryBuilder {_dceb ._dd .RenderParameters .WaitVisible =append (_dceb ._dd .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _dceb ;}; +func (_fcc *QueryBuilder )WaitVisible (selector string ,by _bb .ByType )*QueryBuilder {_fcc ._bea .RenderParameters .WaitVisible =append (_fcc ._bea .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _fcc ;}; -// Landscape sets up the landscape portrait orientation. -func (_eg *QueryBuilder )Landscape ()*QueryBuilder {_eg ._dd .PageParameters .Orientation =_bae .Landscape ;return _eg ;}; +// Addr gets the HTTP address URI used by the http.Client. +func (_bbb *Options )Addr ()string {_egf :=_ff .Builder {};_egf .WriteString ("\u0068\u0074\u0074\u0070");if _bbb .HTTPS {_egf .WriteRune ('s');};_egf .WriteString ("\u003a\u002f\u002f");_egf .WriteString (_bbb .Hostname );_egf .WriteRune (':');_egf .WriteString (_af .Itoa (_bbb .Port )); +if _bbb .Prefix !=""{_egf .WriteString (_bbb .Prefix );};return _egf .String ();}; -// PaperHeight sets up the PaperHeight (in cm) parameter for the query. -func (_aea *QueryBuilder )PaperHeight (paperHeight _bae .Length )*QueryBuilder {_aea ._dd .PageParameters .PaperHeight =paperHeight ;return _aea ;}; +// BySelector is a structure that defines a selector with it's query 'by' type. +type BySelector struct{Selector string `json:"selector"`;By _bb .ByType `json:"by"`;}; -// Validate checks if the parameters are valid. -func (_bff *PageParameters )Validate ()error {if _bff .PaperWidth !=nil {if _bff .PaperWidth .Millimeters ()< 0{return _ga .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); -};};if _bff .PaperHeight !=nil {if _bff .PaperHeight .Millimeters ()< 0{return _ga .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); -};};if _bff .MarginTop !=nil {if _bff .MarginTop .Millimeters ()< 0{return _ga .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _bff .MarginBottom !=nil {if _bff .MarginBottom .Millimeters ()< 0{return _ga .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); -};};if _bff .MarginLeft !=nil {if _bff .MarginLeft .Millimeters ()< 0{return _ga .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");}; -};if _bff .MarginRight !=nil {if _bff .MarginRight .Millimeters ()< 0{return _ga .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); -};};if _bff .PageSize !=nil &&!_bff .PageSize .IsAPageSize (){return _ga .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; +// WithDefaultTimeout sets the DefaultTimeout option for the client options. +func WithDefaultTimeout (option _b .Duration )Option {return func (_egd *Options ){_egd .DefaultTimeout =option };}; -// Option is a function that changes client options. -type Option func (_dce *Options ); +// QueryBuilder is the query that converts HTMLConverter defined data +type QueryBuilder struct{_bea Query ;_ddg error ;};func (_aaa *Client )getGenerateRequest (_gba _d .Context ,_gg *Query )(*_da .Request ,error ){_ce :=generatePDFRequestV1 {Method :_gg .Method ,PageParameters :_gg .PageParameters ,RenderParameters :_gg .RenderParameters ,TimeoutDuration :int64 (_gg .TimeoutDuration )}; +switch _gg .Method {case "\u0077\u0065\u0062":_ce .ContentURL =_gg .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_ce .ContentType =_gg .ContentType ;_ce .Content =_gg .Content ;};_gge :=new (_faf .Buffer );if _bee :=_e .NewEncoder (_gge ).Encode (&_ce ); +_bee !=nil {return nil ,_ed .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_bee );};_beeb :=_aaa .Options .Addr ();_beeb =_ed .Sprintf ("\u0025s\u002f\u0076\u0031\u002f\u0070\u0064f",_beeb ); +_fad ,_ea :=_da .NewRequest ("\u0050\u004f\u0053\u0054",_beeb ,_gge );if _ea !=nil {return nil ,_ea ;};_fad .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); +_fad .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); +_fad =_fad .WithContext (_gba );return _fad ,nil ;}; -// Addr gets the HTTP address URI used by the http.Client. -func (_dc *Options )Addr ()string {_cde :=_cf .Builder {};_cde .WriteString ("\u0068\u0074\u0074\u0070");if _dc .HTTPS {_cde .WriteRune ('s');};_cde .WriteString ("\u003a\u002f\u002f");_cde .WriteString (_dc .Hostname );_cde .WriteRune (':');_cde .WriteString (_eb .Itoa (_dc .Port )); -if _dc .Prefix !=""{_cde .WriteString (_dc .Prefix );};return _cde .String ();}; +// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. +type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;TimeoutDuration _b .Duration ;}; -// MarginBottom sets up the MarginBottom parameter for the query. -func (_ddd *QueryBuilder )MarginBottom (marginBottom _bae .Length )*QueryBuilder {_ddd ._dd .PageParameters .MarginBottom =marginBottom ;return _ddd ;}; +// MarginRight sets up the MarginRight parameter for the query. +func (_aeag *QueryBuilder )MarginRight (marginRight _gc .Length )*QueryBuilder {_aeag ._bea .PageParameters .MarginRight =marginRight ;return _aeag ;}; + +// Err gets the error which could occur in the query. +func (_bbbe *QueryBuilder )Err ()error {return _bbbe ._ddg }; // Query gets the Query from provided query builder. If some error occurred during build process // or the input is not valid the function would return an error. -func (_ff *QueryBuilder )Query ()(*Query ,error ){if _afb :=_ff .Validate ();_afb !=nil {return nil ,_afb ;};return &_ff ._dd ,nil ;};func (_fee *Client )setQueryValues (_bdd *_ba .Request ,_bf *Query ){_beg :=_bdd .URL .Query ();_dff :=_bf .PageParameters ; -if _dff .PageSize !=nil {_beg .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_dff .PageSize .String ());};if _dff .PaperHeight !=nil {_beg .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_dff .PaperHeight .String ());}; -if _dff .PaperWidth !=nil {_beg .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_dff .PaperWidth .String ());};if _dff .MarginTop !=nil {_beg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_dff .MarginTop .String ()); -};if _dff .MarginBottom !=nil {_beg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_dff .MarginBottom .String ());};if _dff .MarginRight !=nil {_beg .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_dff .MarginRight .String ()); -};if _dff .MarginLeft !=nil {_beg .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_dff .MarginLeft .String ());};if _dff .Orientation ==_bae .Landscape {_beg .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_dff .Orientation .String ()); -};if _bf .RenderParameters .WaitTime !=0{_beg .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_eb .FormatInt (int64 (_bf .RenderParameters .WaitTime /_gac .Millisecond ),10));};_bdd .URL .RawQuery =_beg .Encode (); -}; +func (_aba *QueryBuilder )Query ()(*Query ,error ){if _dfc :=_aba .Validate ();_dfc !=nil {return nil ,_dfc ;};return &_aba ._bea ,nil ;};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`; +Method string `json:"method"`;ExpiresAt int64 `json:"expiresAt"`;TimeoutDuration int64 `json:"timeoutDuration,omitempty"`;PageParameters ;RenderParameters ;}; -// BuildHTMLQuery creates a Query builder that is supposed to create valid -func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; +// PageParameters are the query parameters used in the PDF generation. +type PageParameters struct{ -// WaitTime sets the minimum load time parameter for the page rendering. -func (_acef *QueryBuilder )WaitTime (d _gac .Duration )*QueryBuilder {_acef ._dd .RenderParameters .WaitTime =d ;return _acef ;}; +// PaperWidth sets the width of the paper. +PaperWidth _gc .Length `schema:"paper-width" json:"paperWidth"`; -// New creates new client with provided options. -func New (o Options )*Client {o .DefaultTimeout =_gac .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _gb =&_ba .Transport {DialContext :(&_ebb .Dialer {Timeout :5*_gac .Second }).DialContext ,TLSHandshakeTimeout :5*_gac .Second }; -_ge .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_ba .Client {Transport :_gb ,Timeout :o .DefaultTimeout }};}; +// PaperHeight is the height of the output paper. +PaperHeight _gc .Length `schema:"paper-height" json:"paperHeight"`; -// Validate checks if the QueryBuilder had no errors during composition and creation. -func (_fd *QueryBuilder )Validate ()error {if _fd ._bgb !=nil {return _fd ._bgb ;};return _fd ._dd .Validate ();}; +// PageSize is the page size string. +PageSize *_gc .PageSize `schema:"page-size" json:"pageSize"`; -// Validate checks validity of the selector. -func (_cb BySelector )Validate ()error {if _cb .Selector ==""{return _ga .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _gc :=_cb .By .Validate ();_gc !=nil {return _gc ; -};return nil ;};func (_ace *Client )getGenerateRequest (_fbd _e .Context ,_ab *Query )(*_ba .Request ,error ){_ea :=generatePDFRequestV1 {Method :_ab .Method ,PageParameters :_ab .PageParameters ,RenderParameters :_ab .RenderParameters ,TimeoutDuration :int64 (_ab .TimeoutDuration )}; -switch _ab .Method {case "\u0077\u0065\u0062":_ea .ContentURL =_ab .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_ea .ContentType =_ab .ContentType ;_ea .Content =_ab .Content ;};_bag :=new (_bg .Buffer );if _ce :=_d .NewEncoder (_bag ).Encode (&_ea ); -_ce !=nil {return nil ,_fa .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_ce );};_bef :=_ace .Options .Addr ();_bef =_fa .Sprintf ("\u0025s\u002f\u0076\u0031\u002f\u0070\u0064f",_bef ); -_af ,_bd :=_ba .NewRequest ("\u0050\u004f\u0053\u0054",_bef ,_bag );if _bd !=nil {return nil ,_bd ;};_af .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); -_af .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); -_af =_af .WithContext (_fbd );return _af ,nil ;}; +// Orientation defines if the output should be in a landscape format. +Orientation _gc .Orientation `schema:"orientation" json:"orientation"`; -// Options are the client options used by the HTTP client. -type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _gac .Duration ;Prefix string ;}; +// MarginTop sets up the Top Margin for the output. +MarginTop _gc .Length `schema:"margin-top" json:"marginTop"`; -// HealthCheck connects to the server and check the health status of the server. -func (_dae *Client )HealthCheck (ctx _e .Context )error {_a :=_dae .Options .Addr ();_a =_fa .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_a );_ae ,_ac :=_ba .NewRequest ("\u0047\u0045\u0054",_a ,nil );if _ac !=nil {return _ac ;};_ae =_ae .WithContext (ctx ); -_fc ,_ac :=_dae .Client .Do (_ae );if _ac !=nil {return _ac ;};switch _fc .StatusCode {case _ba .StatusOK :return nil ;case _ba .StatusNotFound :return ErrNotFound ;case _ba .StatusInternalServerError :return ErrInternalError ;case _ba .StatusBadGateway :return ErrBadGateway ; -default:return ErrNotImplemented ;};}; +// MarginBottom sets up the Bottom Margin for the output. +MarginBottom _gc .Length `schema:"margin-bottom" json:"marginBottom"`; -// Orientation sets the page orientation for the Query. -func (_gde *QueryBuilder )Orientation (orientation _bae .Orientation )*QueryBuilder {_gde ._dd .PageParameters .Orientation =orientation ;return _gde ;}; +// MarginLeft sets up the Left Margin for the output. +MarginLeft _gc .Length `schema:"margin-left" json:"marginLeft"`; -// MarginTop sets up the MarginTop parameter for the query. -func (_daf *QueryBuilder )MarginTop (marginTop _bae .Length )*QueryBuilder {_daf ._dd .PageParameters .MarginTop =marginTop ;return _daf ;}; +// MarginRight sets up the Right Margin for the output. +MarginRight _gc .Length `schema:"margin-right" json:"marginRight"`;}; -// WithDefaultTimeout sets the DefaultTimeout option for the client options. -func WithDefaultTimeout (option _gac .Duration )Option {return func (_bgf *Options ){_bgf .DefaultTimeout =option };};var (ErrNotFound =_ga .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_ga .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); -ErrNotImplemented =_ga .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_ga .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_ga .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079"); -ErrUnauthorized =_ga .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_ga .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); +// MarginBottom sets up the MarginBottom parameter for the query. +func (_afd *QueryBuilder )MarginBottom (marginBottom _gc .Length )*QueryBuilder {_afd ._bea .PageParameters .MarginBottom =marginBottom ;return _afd ;}; -// Validate checks the validity of the RenderParameters. -func (_dgf *RenderParameters )Validate ()error {if _dgf .WaitTime > _gac .Minute *3{return _ga .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); -};for _ ,_dbd :=range _dgf .WaitReady {if _cbb :=_dbd .Validate ();_cbb !=nil {return _fa .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_cbb ); -};};return nil ;}; +// Validate checks if provided Query is valid. +func (_df *Query )Validate ()error {switch _df .Method {case "\u0077\u0065\u0062":if _df .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_df .Content )==0{return ErrMissingData ;};if _df .ContentType ==""{return ErrContentType ; +};default:return _ed .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_df .Method );};if _beg :=_df .PageParameters .Validate (); +_beg !=nil {return _beg ;};if _cc :=_df .RenderParameters .Validate ();_cc !=nil {return _cc ;};return nil ;};func (_bde *Client )setQueryValues (_cdc *_da .Request ,_bba *Query ){_db :=_cdc .URL .Query ();_eg :=_bba .PageParameters ;if _eg .PageSize !=nil {_db .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_eg .PageSize .String ()); +};if _eg .PaperHeight !=nil {_db .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_eg .PaperHeight .String ());};if _eg .PaperWidth !=nil {_db .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_eg .PaperWidth .String ()); +};if _eg .MarginTop !=nil {_db .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_eg .MarginTop .String ());};if _eg .MarginBottom !=nil {_db .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_eg .MarginBottom .String ()); +};if _eg .MarginRight !=nil {_db .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_eg .MarginRight .String ());};if _eg .MarginLeft !=nil {_db .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_eg .MarginLeft .String ()); +};if _eg .Orientation ==_gc .Landscape {_db .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_eg .Orientation .String ());};if _bba .RenderParameters .WaitTime !=0{_db .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_af .FormatInt (int64 (_bba .RenderParameters .WaitTime /_b .Millisecond ),10)); +};_cdc .URL .RawQuery =_db .Encode ();}; -// WithPrefix sets the client prefix. -func WithPrefix (prefix string )Option {return func (_ca *Options ){_ca .Prefix =prefix }}; +// Options are the client options used by the HTTP client. +type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _b .Duration ;Prefix string ;}; -// MarginRight sets up the MarginRight parameter for the query. -func (_cab *QueryBuilder )MarginRight (marginRight _bae .Length )*QueryBuilder {_cab ._dd .PageParameters .MarginRight =marginRight ;return _cab ;}; +// MarginLeft sets up the MarginLeft parameter for the query. +func (_ac *QueryBuilder )MarginLeft (marginLeft _gc .Length )*QueryBuilder {_ac ._bea .PageParameters .MarginLeft =marginLeft ;return _ac ;};var (ErrMissingData =_dc .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061"); +ErrContentType =_dc .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065");ErrContentTypeDeclared =_dc .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064"); +); -// Err gets the error which could occur in the query. -func (_ec *QueryBuilder )Err ()error {return _ec ._bgb }; +// PaperHeight sets up the PaperHeight (in cm) parameter for the query. +func (_cda *QueryBuilder )PaperHeight (paperHeight _gc .Length )*QueryBuilder {_cda ._bea .PageParameters .PaperHeight =paperHeight ;return _cda ;}; -// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. -type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;TimeoutDuration _gac .Duration ;}; +// ConvertHTML converts provided Query input into PDF file data. +// Implements creator.HTMLConverter interface. +func (_ad *Client )ConvertHTML (ctx _d .Context ,q *Query )(*PDFResponse ,error ){if _be :=q .Validate ();_be !=nil {return nil ,_be ;};_fd ,_de :=_ad .getGenerateRequest (ctx ,q );if _de !=nil {return nil ,_de ;};_aa .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_fd .Method ,_fd .URL .Hostname (),_fd .URL .Path ,_fd .Header ,_fd .URL .Query ()); +_gd :=*_ad .Client ;if q .TimeoutDuration !=0{_gd .Timeout =q .TimeoutDuration ;};_dd ,_de :=_gd .Do (_fd );if _de !=nil {return nil ,_de ;};var _afb error ;switch _dd .StatusCode {case _da .StatusNotFound :_afb =ErrNotFound ;case _da .StatusBadRequest :_afb =ErrBadRequest ; +case _da .StatusNotImplemented :_afb =ErrNotImplemented ;case _da .StatusUnauthorized :_afb =ErrUnauthorized ;case _da .StatusRequestTimeout :_afb =ErrTimedOut ;case _da .StatusCreated :default:_afb =ErrInternalError ;};_ab :=_dd .Body ;switch _dd .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_ab ,_de =_fa .NewReader (_dd .Body ); +if _de !=nil {return nil ,_de ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_ab =_f .NewReader (_dd .Body );case "":default:return nil ,_ed .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_dd .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); +};_feb ,_de :=_a .ReadAll (_ab );if _de !=nil &&_afb ==nil {return nil ,_ed .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_de );};_aa .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_dd .StatusCode ,_fd .Method ,_fd .URL .Host ,_fd .URL .Path ); +if _afb !=nil {return nil ,_ed .Errorf ("\u0025\u0073\u0020%\u0077",string (_feb ),_afb );};_eea :=_dd .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_aa .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_eea ); +return &PDFResponse {ID :_eea ,Data :_feb },nil ;}; -// PageSize sets up the PageSize parameter for the query. -func (_gd *QueryBuilder )PageSize (pageSize _bae .PageSize )*QueryBuilder {if pageSize !=_bae .Undefined {_gd ._dd .PageParameters .PageSize =&pageSize ;};return _gd ;}; +// WaitReady waits for the selector to get ready - 'loaded'. +func (_dacf *QueryBuilder )WaitReady (selector string ,by _bb .ByType )*QueryBuilder {_dacf ._bea .RenderParameters .WaitReady =append (_dacf ._bea .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _dacf ;}; // Portrait sets up the portrait page orientation. -func (_cbe *QueryBuilder )Portrait ()*QueryBuilder {_cbe ._dd .PageParameters .Orientation =_bae .Portrait ;return _cbe ;}; +func (_fff *QueryBuilder )Portrait ()*QueryBuilder {_fff ._bea .PageParameters .Orientation =_gc .Portrait ;return _fff ;}; -// SetContent sets custom data with it's content type. -func (_fg *QueryBuilder )SetContent (content _cd .Content )*QueryBuilder {if _fg ._bgb !=nil {return _fg ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _fg ._dd .ContentType !=""{_fg ._bgb =ErrContentTypeDeclared ; -return _fg ;};if content .ContentType ()==""{_fg ._bgb =_fa .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _fg ;};_fg ._dd .Content =content .Data (); -_fg ._dd .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _fg ._dd .ContentType !=""{_fg ._bgb =ErrContentTypeDeclared ;return _fg ;};_fg ._dd .URL =string (content .Data ());_fg ._dd .ContentType =content .ContentType ();default:_fg ._bgb =_fa .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ()); -return _fg ;};_fg ._dd .Method =content .Method ();return _fg ;}; +// PageSize sets up the PageSize parameter for the query. +func (_ege *QueryBuilder )PageSize (pageSize _gc .PageSize )*QueryBuilder {if pageSize !=_gc .Undefined {_ege ._bea .PageParameters .PageSize =&pageSize ;};return _ege ;}; -// WithHTTPS sets the TLS option for the client options. -func WithHTTPS (useHTTPS bool )Option {return func (_eaf *Options ){_eaf .HTTPS =useHTTPS }}; +// MarginTop sets up the MarginTop parameter for the query. +func (_ddd *QueryBuilder )MarginTop (marginTop _gc .Length )*QueryBuilder {_ddd ._bea .PageParameters .MarginTop =marginTop ;return _ddd ;}; -// Client is a structure that is a HTTP client for the unihtml server. -type Client struct{Options Options ;Client *_ba .Client ;}; +// HealthCheck connects to the server and check the health status of the server. +func (_cde *Client )HealthCheck (ctx _d .Context )error {_ffb :=_cde .Options .Addr ();_ffb =_ed .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_ffb );_dg ,_fg :=_da .NewRequest ("\u0047\u0045\u0054",_ffb ,nil );if _fg !=nil {return _fg ;};_dg =_dg .WithContext (ctx ); +_gb ,_fg :=_cde .Client .Do (_dg );if _fg !=nil {return _fg ;};switch _gb .StatusCode {case _da .StatusOK :return nil ;case _da .StatusNotFound :return ErrNotFound ;case _da .StatusInternalServerError :return ErrInternalError ;case _da .StatusBadGateway :return ErrBadGateway ; +default:return ErrNotImplemented ;};}; -// MarginLeft sets up the MarginLeft parameter for the query. -func (_gdf *QueryBuilder )MarginLeft (marginLeft _bae .Length )*QueryBuilder {_gdf ._dd .PageParameters .MarginLeft =marginLeft ;return _gdf ;}; \ No newline at end of file +// ParseOptions parses options for the Client. +func ParseOptions (connectPath string )(Options ,error ){if !_ff .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_c ,_cd :=_bd .Parse (connectPath );if _cd !=nil {return Options {},_ed .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); +};var _ee int ;if _c .Port ()!=""{_ee ,_cd =_af .Atoi (_c .Port ());if _cd !=nil {return Options {},_ed .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_cd );}; +};return Options {Hostname :_c .Hostname (),Port :_ee ,HTTPS :_c .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_c .Path },nil ;}; \ No newline at end of file diff --git a/common/common.go b/common/common.go index 2ba66b0..824c89f 100644 --- a/common/common.go +++ b/common/common.go @@ -10,7 +10,8 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package common contains common properties used by the subpackages. -package common ;import _g "time";const _gc =2025;var ReleasedAt =_g .Date (_gc ,_e ,_gg ,_ag ,_ge ,0,0,_g .UTC );const _gg =26;const _ag =12;const _e =4; +package common ;import _f "time";const Version ="\u0030\u002e\u0031\u0032\u002e\u0030";const _gd =20;const _b =12;const _c ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034"; +var ReleasedAt =_f .Date (_g ,_e ,_ab ,_b ,_gd ,0,0,_f .UTC ); // UtcTimeFormat returns a formatted string describing a UTC timestamp. -func UtcTimeFormat (t _g .Time )string {return t .Format (_a )+"\u0020\u0055\u0054\u0043"};const Version ="\u0030\u002e\u0031\u0031\u002e\u0030";const _ge =20;const _a ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034"; +func UtcTimeFormat (t _f .Time )string {return t .Format (_c )+"\u0020\u0055\u0054\u0043"};const _g =2025;const _ab =12;const _e =5; \ No newline at end of file diff --git a/content/content.go b/content/content.go index 547d5b4..1c0d70b 100644 --- a/content/content.go +++ b/content/content.go @@ -9,63 +9,64 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package content ;import (_g "archive/zip";_cg "bytes";_gf "fmt";_f "net/url";_c "os";_d "strings";); +package content ;import (_dc "archive/zip";_b "bytes";_e "fmt";_ga "net/url";_df "os";_g "strings";); -// NewStringContent creates a new StringContent. -func NewStringContent (html string )(*StringContent ,error ){return &StringContent {_fdb :html },nil }; +// NewWebURL creates new Content webURL for provided input URL path. +func NewWebURL (path string )(Content ,error ){if _ ,_dcf :=_ga .Parse (path );_dcf !=nil {return nil ,_dcf ;};return &webURL {_cb :path },nil ;}; -// Method gets the web url query method. -func (_fd *webURL )Method ()string {return "\u0077\u0065\u0062"}; +// ContentType implements Content interface. +func (_dea *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; + +// Content is an interface used for putting the content into Client Query. +type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;}; // Data implements Content interface. -func (_ad *StringContent )Data ()[]byte {return []byte (_ad ._fdb )}; +func (_gef *StringContent )Data ()[]byte {return []byte (_gef ._ae )}; // ContentType implements Content interface. -func (_bcc *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; +func (_ac *StringContent )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; -// ContentType implements Content interface. -func (_gfc *StringContent )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl";}; +// Data implements Content interface. +func (_gd *webURL )Data ()[]byte {return []byte (_gd ._cb )}; // Data implements Content interface. -func (_dag *zipDirectory )Data ()[]byte {return _dag ._eg .Bytes ()}; +func (_ca *htmlFile )Data ()[]byte {return _ca ._bc .Bytes ()};type htmlFile struct{_bc _b .Buffer };func (_bg *zipDirectory )zipPath (_gf ,_eg string )error {_bfa ,_bfdb :=_df .ReadDir (_gf );if _bfdb !=nil {return _e .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_gf ,_bfdb ); +};_gfg :=&_g .Builder {};for _ ,_bcb :=range _bfa {_db ,_aa :=_bcb .Info ();if _aa !=nil {return _aa ;};_aaf ,_fge :=_bg .zipBasePaths (_db ,_gf ,_eg ,_bcb .IsDir (),_gfg );if _bcb .IsDir (){if _ge :=_bg .zipPath (_aaf ,_fge );_ge !=nil {return _ge ;}; +continue ;};_fb ,_aa :=_df .ReadFile (_aaf );if _aa !=nil {return _aa ;};_ebe ,_aa :=_bg ._a .Create (_fge );if _aa !=nil {return _aa ;};if _ ,_aa =_ebe .Write (_fb );_aa !=nil {return _aa ;};};return nil ;}; -// Content is an interface used for putting the content into Client Query. -type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;};type webURL struct{_fc string }; +// Data implements Content interface. +func (_ebf *zipDirectory )Data ()[]byte {return _ebf ._gae .Bytes ()}; + +// Method gets the web url query method. +func (_eb *webURL )Method ()string {return "\u0077\u0065\u0062"}; + +// StringContent implements Content interface for an HTML string. +type StringContent struct{_ae string }; // NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' // and stores in it's in-memory buffer. -func NewZipDirectory (dirPath string )(Content ,error ){_gg :=&zipDirectory {_eg :_cg .Buffer {}};_gg ._cd =_g .NewWriter (&_gg ._eg );if _gda :=_gg .zipPath (dirPath ,"");_gda !=nil {return nil ,_gda ;};if _af :=_gg ._cd .Close ();_af !=nil {return nil ,_af ; -};return _gg ,nil ;};type zipDirectory struct{_eg _cg .Buffer ;_cd *_g .Writer ;}; +func NewZipDirectory (dirPath string )(Content ,error ){_bcc :=&zipDirectory {_gae :_b .Buffer {}};_bcc ._a =_dc .NewWriter (&_bcc ._gae );if _gac :=_bcc .zipPath (dirPath ,"");_gac !=nil {return nil ,_gac ;};if _ad :=_bcc ._a .Close ();_ad !=nil {return nil ,_ad ; +};return _bcc ,nil ;}; -// Method implements Content interface. -func (_bgb *StringContent )Method ()string {return "\u0068\u0074\u006d\u006c"};func (_ggb *zipDirectory )zipPath (_cgd ,_db string )error {_ef ,_df :=_c .ReadDir (_cgd );if _df !=nil {return _gf .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_cgd ,_df ); -};_gb :=&_d .Builder {};for _ ,_dbe :=range _ef {_afc ,_aba :=_dbe .Info ();if _aba !=nil {return _aba ;};_fe ,_gff :=_ggb .zipBasePaths (_afc ,_cgd ,_db ,_dbe .IsDir (),_gb );if _dbe .IsDir (){if _de :=_ggb .zipPath (_fe ,_gff );_de !=nil {return _de ; -};continue ;};_fa ,_aba :=_c .ReadFile (_fe );if _aba !=nil {return _aba ;};_dfa ,_aba :=_ggb ._cd .Create (_gff );if _aba !=nil {return _aba ;};if _ ,_aba =_dfa .Write (_fa );_aba !=nil {return _aba ;};};return nil ;}; +// NewHTMLFile creates new Content htmFile for provided input path. +func NewHTMLFile (path string )(Content ,error ){_de ,_ea :=_df .Open (path );if _ea !=nil {return nil ,_ea ;};_bf :=&htmlFile {_bc :_b .Buffer {}};if _ ,_ea =_bf ._bc .ReadFrom (_de );_ea !=nil {return nil ,_ea ;};return _bf ,nil ;}; // Method gets the query method. -func (_da *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"};type htmlFile struct{_a _cg .Buffer }; +func (_f *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"};type zipDirectory struct{_gae _b .Buffer ;_a *_dc .Writer ;}; // ContentType implements Content interface. -func (_bg *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; +func (_bfd *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"};func (_fa *zipDirectory )zipBasePaths (_eaf _df .FileInfo ,_dfa ,_cc string ,_ce bool ,_be *_g .Builder )(string ,string ){_be .WriteString (_dfa );if !_g .HasSuffix (_dfa ,"\u002f"){_be .WriteRune ('/'); +};_be .WriteString (_eaf .Name ());if _ce {_be .WriteRune ('/');};_faa :=_be .String ();_be .Reset ();_be .WriteString (_cc );_be .WriteString (_eaf .Name ());if _ce {_be .WriteRune ('/');};_ag :=_be .String ();_be .Reset ();return _faa ,_ag ;};type webURL struct{_cb string }; -// StringContent implements Content interface for an HTML string. -type StringContent struct{_fdb string };func (_egf *zipDirectory )zipBasePaths (_ac _c .FileInfo ,_afe ,_ca string ,_cee bool ,_faf *_d .Builder )(string ,string ){_faf .WriteString (_afe );if !_d .HasSuffix (_afe ,"\u002f"){_faf .WriteRune ('/');};_faf .WriteString (_ac .Name ()); -if _cee {_faf .WriteRune ('/');};_efd :=_faf .String ();_faf .Reset ();_faf .WriteString (_ca );_faf .WriteString (_ac .Name ());if _cee {_faf .WriteRune ('/');};_dbef :=_faf .String ();_faf .Reset ();return _efd ,_dbef ;}; // ContentType implements Content interface. -func (_ab *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; - -// NewWebURL creates new Content webURL for provided input URL path. -func NewWebURL (path string )(Content ,error ){if _ ,_bfg :=_f .Parse (path );_bfg !=nil {return nil ,_bfg ;};return &webURL {_fc :path },nil ;}; - -// Method gets the zip directory method. -func (_ff *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; +func (_dfb *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; -// Data implements Content interface. -func (_e *webURL )Data ()[]byte {return []byte (_e ._fc )}; +// NewStringContent creates a new StringContent. +func NewStringContent (html string )(*StringContent ,error ){return &StringContent {_ae :html },nil }; -// NewHTMLFile creates new Content htmFile for provided input path. -func NewHTMLFile (path string )(Content ,error ){_bc ,_gd :=_c .Open (path );if _gd !=nil {return nil ,_gd ;};_dc :=&htmlFile {_a :_cg .Buffer {}};if _ ,_gd =_dc ._a .ReadFrom (_bc );_gd !=nil {return nil ,_gd ;};return _dc ,nil ;}; +// Method implements Content interface. +func (_bd *StringContent )Method ()string {return "\u0068\u0074\u006d\u006c"}; -// Data implements Content interface. -func (_ae *htmlFile )Data ()[]byte {return _ae ._a .Bytes ()}; \ No newline at end of file +// Method gets the zip directory method. +func (_bb *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; \ No newline at end of file diff --git a/go.mod b/go.mod index 9d7853e..f0ac166 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.16.0 github.com/stretchr/testify v1.10.0 - github.com/unidoc/unipdf/v3 v3.69.0 + github.com/unidoc/unipdf/v4 v4.0.0 ) require ( @@ -30,9 +30,7 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.6.0 // indirect - github.com/trimmer-io/go-xmp v1.0.0 // indirect github.com/unidoc/freetype v0.2.3 // indirect - github.com/unidoc/garabic v0.0.0-20220702200334-8c7cb25baa11 // indirect github.com/unidoc/pkcs7 v0.2.0 // indirect github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a // indirect github.com/unidoc/unichart v0.4.0 // indirect diff --git a/go.sum b/go.sum index 5b2be4b..7215156 100644 --- a/go.sum +++ b/go.sum @@ -70,12 +70,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -github.com/trimmer-io/go-xmp v1.0.0 h1:zY8bolSga5kOjBAaHS6hrdxLgEoYuT875xTy0QDwZWs= -github.com/trimmer-io/go-xmp v1.0.0/go.mod h1:Aaptr9sp1lLv7UnCAdQ+gSHZyY2miYaKmcNVj7HRBwA= github.com/unidoc/freetype v0.2.3 h1:uPqW+AY0vXN6K2tvtg8dMAtHTEvvHTN52b72XpZU+3I= github.com/unidoc/freetype v0.2.3/go.mod h1:mJ/Q7JnqEoWtajJVrV6S1InbRv0K/fJerPB5SQs32KI= -github.com/unidoc/garabic v0.0.0-20220702200334-8c7cb25baa11 h1:kExUKrbi429KdVVuAc85z4P+W/Rk4bjGWB5KzZLl/l8= -github.com/unidoc/garabic v0.0.0-20220702200334-8c7cb25baa11/go.mod h1:SX63w9Ww4+Z7E96B01OuG59SleQUb+m+dmapZ8o1Jac= github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= github.com/unidoc/pkcs7 v0.2.0 h1:0Y0RJR5Zu7OuD+/l7bODXARn6b8Ev2G4A8lI4rzy9kg= github.com/unidoc/pkcs7 v0.2.0/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= @@ -83,10 +79,8 @@ github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a h1:RLtvUhe4DsUDl6 github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a/go.mod h1:j+qMWZVpZFTvDey3zxUkSgPJZEX33tDgU/QIA0IzCUw= github.com/unidoc/unichart v0.4.0 h1:uXk9ZjbqzKb8Lt2Qv2oM9D2ftNRXvezPevgxQhsTQys= github.com/unidoc/unichart v0.4.0/go.mod h1:9QsE8RbS0fE7ndHNroeCEFkRPqqk47Qsoj6QSAtcwN0= -github.com/unidoc/unipdf/v3 v3.68.0 h1:AM1wKukv75hvCtTbiPb3HSIdHS5RbmR6aYTCE0jiO+A= -github.com/unidoc/unipdf/v3 v3.68.0/go.mod h1:4mQ4E8niuY+30TGxT1e/8aVoSk/nn0yCKfi+kYw98+I= -github.com/unidoc/unipdf/v3 v3.69.0 h1:lW9Ljmc/kHzNRqz7Oo9l2wG6G85mwIgBZuDqsTg1x2I= -github.com/unidoc/unipdf/v3 v3.69.0/go.mod h1:4mQ4E8niuY+30TGxT1e/8aVoSk/nn0yCKfi+kYw98+I= +github.com/unidoc/unipdf/v4 v4.0.0 h1:XxrrOMGLJ6HD7VBO6GpZL5wfoRDmLxawV+wkMXTuPeM= +github.com/unidoc/unipdf/v4 v4.0.0/go.mod h1:SbSYFUoutyBR+hLlsHyNiCzzcSVVuG10S5Xu8RIJ6EY= github.com/unidoc/unitype v0.5.1 h1:UwTX15K6bktwKocWVvLoijIeu4JAVEAIeFqMOjvxqQs= github.com/unidoc/unitype v0.5.1/go.mod h1:3dxbRL+f1otNqFQIRHho8fxdg3CcUKrqS8w1SXTsqcI= golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= diff --git a/selector/selector.go b/selector/selector.go index aadf285..d204a37 100644 --- a/selector/selector.go +++ b/selector/selector.go @@ -9,10 +9,11 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package selector ;import _g "errors"; +package selector ;import _b "errors"; // ByType is a 'By' selector type enumerator. -type ByType uint ;const (ByUndefined ByType =iota ;ByID ;ByQueryAll ;ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); +type ByType uint ; // Validate checks validity of the ByType. -func (_a ByType )Validate ()error {if _a >=ByID &&_a <=BySearch {return nil ;};return _g .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");}; \ No newline at end of file +func (_g ByType )Validate ()error {if _g >=ByID &&_g <=BySearch {return nil ;};return _b .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};const (ByUndefined ByType =iota ;ByID ;ByQueryAll ; +ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); \ No newline at end of file diff --git a/sizes/sizes.go b/sizes/sizes.go index 3aa1d9c..fd0e090 100644 --- a/sizes/sizes.go +++ b/sizes/sizes.go @@ -12,189 +12,190 @@ // Package sizes defines basic types that determines the size units i.e. lengths. // // -package sizes ;import (_ac "encoding/json";_a "flag";_ad "fmt";_e "strconv";_d "strings";); +package sizes ;import (_f "encoding/json";_ag "flag";_ae "fmt";_b "strconv";_e "strings";); -// ValueType implements viper.FlagValue interface. -func (_bcc Point )ValueType ()string {return _bcc .Type ()}; - -// PageSizeValues returns all values of the enum -func PageSizeValues ()[]PageSize {return _cbb }; - -// Millimeters gets the float64 millimeter value. -func (_eg Millimeter )Millimeters ()Millimeter {return _eg }; - -// LengthFlag is a pflag wrapper for the Length value. -type LengthFlag struct{Length Length ;}; - -// String implements fmt.Stringer interface. -func (_cg Point )String ()string {_ce :=_d .Builder {};_ce .WriteString (_e .FormatFloat (float64 (_cg ),'f',1,64));_ce .WriteString ("\u0070\u0074");return _ce .String ();}; +// MarshalJSON implements json.Marshaler interface +func (_cda Millimeter )MarshalJSON ()([]byte ,error ){return _fda (_cda )};var (_ Length =Millimeter (0);); -// Millimeters converts the inches value to the millimeters. -func (_eba Inch )Millimeters ()Millimeter {return Millimeter (float64 (_eba )*_g )}; +// Inches gets the inch value. Implements Length interface. +func (_da Inch )Inches ()Inch {return _da }; -// ValueType implements pflag.Value interface. -func (_db Inch )ValueType ()string {return _db .Type ()}; +// Name implements viper.FlagValue interface. +func (_ecf Point )Name ()string {return "\u0070\u006f\u0069n\u0074"};const (Portrait =Orientation (false );Landscape =Orientation (true );); -// Points implements Length interface. -func (_ee Millimeter )Points ()Point {return Point (_ee *_af )};func _aaf (_ggd string )(Point ,error ){_ggd =_d .TrimSpace (_d .Trim (_ggd ,"\u0070\u0074"));_dgc ,_cgaf :=_e .ParseFloat (_ggd ,64);if _cgaf !=nil {return 0,_cgaf ;};return Point (_dgc ),nil ; -}; +// MarshalPageSize marshals the page size into string. +func MarshalPageSize (p PageSize )(string ,error ){_eag ,_db :=p .MarshalText ();if _db !=nil {return "",_db ;};return string (_eag ),nil ;};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ; +B9 ;B10 ;Letter ;); // Type implements pflag.Value interface. -func (_beb Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; - -// Inches gets the inches equivalent from provided millimeter value. -func (_ga Millimeter )Inches ()Inch {return Inch (float64 (_ga )*_da )}; - -// HasChanged implements viper.FlagValue interface. -func (_cb *Point )HasChanged ()bool {return _cb !=nil }; +func (_ceg Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; -// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise -func (_fgg PageSize )IsAPageSize ()bool {for _ ,_gfae :=range _cbb {if _fgg ==_gfae {return true ;};};return false ;}; +// LengthFlag is a pflag wrapper for the Length value. +type LengthFlag struct{Length Length ;};const _cdaa ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; -// Inch is a unit that -type Inch float64 ; -// Inches gets the inch value. Implements Length interface. -func (_ba Inch )Inches ()Inch {return _ba }; +// Millimeters gets the float64 millimeter value. +func (_dgc Millimeter )Millimeters ()Millimeter {return _dgc }; -// Set implements flag.Value interface. -func (_dfd *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_dfd =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_dfd =Landscape ;default:return _ad .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); -};return nil ;};func _ec (_fg Length )([]byte ,error ){if _fg ==nil {return nil ,nil ;};_abd ,_fac :=MarshalUnit (_fg );if _fac !=nil {return nil ,_fac ;};return []byte ("\u0022"+_abd +"\u0022"),nil ;}; +// Name implements pflag.Value interface. +func (_be Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; -// Point is a unit of Length commonly used to measure the height of fonts. -type Point float64 ; +// Set implements pflag.Value interface. +func (_fd *Inch )Set (s string )error {_fdf ,_aec :=_b .ParseFloat (s ,64);if _aec !=nil {return _ae .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_aec );};*_fd =Inch (_fdf ); +return nil ;}; // String implements fmt.Stringer interface. -func (_acd Orientation )String ()string {if _acd ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; - -// PageSize is the enum used for defining the page size. -type PageSize int ; +func (_ga Inch )String ()string {_df :=_e .Builder {};_df .WriteString (_b .FormatFloat (float64 (_ga ),'f',1,64));_df .WriteString ("\u0069\u006e");return _df .String ();}; -// Orientation is the page orientation type wrapper. -type Orientation bool ; - -// HasChanged implements pflag.Value interface. -func (_be *Inch )HasChanged ()bool {return _be !=nil };var _ _a .Value =(*Point )(nil ); +// Length is it the default dimension unit. +type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; -// ValueString implements pflag.Value interface. -func (_bc Inch )ValueString ()string {return _bc .String ()}; +// Millimeters converts the inches value to the millimeters. +func (_fde Inch )Millimeters ()Millimeter {return Millimeter (float64 (_fde )*_d )};var _ _ag .Value =(*Point )(nil ); -// Type implements pflag.Value interface. -func (_bb Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; +// Set implements flag.Value interface. +func (_cb *Point )Set (s string )error {_bb ,_gf :=_b .ParseFloat (s ,64);if _gf !=nil {return _ae .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_gf );};*_cb =Point (_bb ); +return nil ;};var _ _ag .Value =(*Orientation )(nil ); -// Inches gets the inch value. Implements Length interface. -func (_ab Point )Inches ()Inch {return Inch (float64 (_ab )*_eb )}; +// Inch is a unit that +type Inch float64 ; -// Name implements pflag.Value interface. -func (_bbg Inch )Name ()string {return "\u0069\u006e\u0063\u0068"};const (_da =float64 (1)/float64 (25.4);_g =25.4;_eb =0.0139;_gg =0.3528;_f =1.0/64;_af =1.0/_gg ;); +// ValueType implements pflag.Value interface. +func (_ec Inch )ValueType ()string {return _ec .Type ()}; // Points implements Length interface. -func (_df Inch )Points ()Point {return Point (float64 (_df )*_f )}; +func (_ge Millimeter )Points ()Point {return Point (_ge *_ab )}; -// Millimeter is the dimension unit that defines a millimeter. -type Millimeter float64 ;var _cbb =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};func _gaa (_bcb string )(Millimeter ,error ){_bcb =_d .TrimSpace (_d .TrimSuffix (_bcb ,"\u006d\u006d"));_fb ,_gfa :=_e .ParseFloat (_bcb ,64); -if _gfa !=nil {return 0,_ad .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_gfa );};return Millimeter (_fb ),nil ;}; +// MarshalJSON implements json.Marshaler interface +func (_ea Inch )MarshalJSON ()([]byte ,error ){return _fda (_ea )}; -// UnmarshalPageSize unmarshals the page size from the string. -func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _dge PageSize ;if _aba :=(&_dge ).UnmarshalText ([]byte (pageSize ));_aba !=nil {return 0,_ad .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_aba ); -};return _dge ,nil ;};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;); +// Set implements flag.Value interface. +func (_baf *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_baf =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_baf =Landscape ;default:return _ae .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); +};return nil ;}; -// Points implements Length interface. -func (_ef Point )Points ()Point {return _ef };var _ Length =Inch (0); +// String gets the string value for given flag. +func (_ba *LengthFlag )String ()string {if _ba .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _ba .Length .String ();};func (_fba PageSize )String ()string {if _fba < 0||_fba >=PageSize (len (_ed )-1){return _ae .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_fba ); +};return _cdaa [_ed [_fba ]:_ed [_fba +1]];}; // UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize -func (_abf *PageSize )UnmarshalText (text []byte )error {var _gfg error ;*_abf ,_gfg =PageSizeString (string (text ));return _gfg ;}; +func (_cdgg *PageSize )UnmarshalText (text []byte )error {var _cde error ;*_cdgg ,_cde =PageSizeString (string (text ));return _cde ;};var _gc =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; -// Type implements pflag.Value interface. -func (_c *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; +// Points implements Length interface. +func (_baa Inch )Points ()Point {return Point (float64 (_baa )*_c )}; // MarshalJSON implements json.Marshaler interface. -func (_fd Point )MarshalJSON ()([]byte ,error ){return _ec (_fd )};func _ff (_aedb string )(Inch ,error ){_aedb =_d .TrimSpace (_d .Trim (_aedb ,"\u0069\u006e"));_ada ,_aea :=_e .ParseFloat (_aedb ,64);if _aea !=nil {return 0,_ad .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_aea ); -};return Inch (_ada ),nil ;}; +func (_dde Point )MarshalJSON ()([]byte ,error ){return _fda (_dde )}; + +// ValueString implements pflag.Value interface. +func (_fed Inch )ValueString ()string {return _fed .String ()}; // Set implements pflag.Value interface. -func (_ged *PageSize )Set (s string )error {_bg ,_egc :=UnmarshalPageSize (s );if _egc !=nil {return _egc ;};*_ged =_bg ;return nil ;};func (_cacd PageSize )String ()string {if _cacd < 0||_cacd >=PageSize (len (_caa )-1){return _ad .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_cacd ); -};return _cfa [_caa [_cacd ]:_caa [_cacd +1]];}; +func (_ddf *PageSize )Set (s string )error {_dfag ,_eba :=UnmarshalPageSize (s );if _eba !=nil {return _eba ;};*_ddf =_dfag ;return nil ;}; -// MarshalText implements the encoding.TextMarshaler interface for PageSize -func (_eacb PageSize )MarshalText ()([]byte ,error ){return []byte (_eacb .String ()),nil };var _caa =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; +// Type implements pflag.Value interface. +func (_g *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; -// Millimeters converts the inches value to the millimeters. -func (_ge Point )Millimeters ()Millimeter {return Millimeter (float64 (_ge )*_gg )}; +// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise +func (_fdec PageSize )IsAPageSize ()bool {for _ ,_efa :=range _gc {if _fdec ==_efa {return true ;};};return false ;}; + +// Inches gets the inch value. Implements Length interface. +func (_dd Point )Inches ()Inch {return Inch (float64 (_dd )*_eb )}; // Type implements pflag.Value interface. -func (_bee PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; +func (_dc Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; + +// Points implements Length interface. +func (_bf Point )Points ()Point {return _bf }; + +// UnmarshalJSON implements the json.Unmarshaler interface for PageSize +func (_ecfg *PageSize )UnmarshalJSON (data []byte )error {var _dga string ;if _cebf :=_f .Unmarshal (data ,&_dga );_cebf !=nil {return _ae .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); +};var _adg error ;*_ecfg ,_adg =PageSizeString (_dga );return _adg ;}; // String implements fmt.Stringer interface. -func (_gf Millimeter )String ()string {_gb :=_d .Builder {};_gb .WriteString (_e .FormatFloat (float64 (_gf ),'f',1,64));_gb .WriteString ("\u006d\u006d");return _gb .String ();}; +func (_ee Point )String ()string {_dfc :=_e .Builder {};_dfc .WriteString (_b .FormatFloat (float64 (_ee ),'f',1,64));_dfc .WriteString ("\u0070\u0074");return _dfc .String ();}; -// UnmarshalInch unmarshalls provided string into unit. -func UnmarshalInch (unit string )(Inch ,error ){if _d .HasSuffix (unit ,"\u006d\u006d"){_bd ,_ag :=_gaa (unit );if _ag !=nil {return 0,_ag ;};return _bd .Inches (),nil ;};if _d .HasSuffix (unit ,"\u0069\u006e"){return _ff (unit );};return 0,_ad .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); -};const _cfa ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; -var _ _a .Value =(*Orientation )(nil ); +// Orientation is the page orientation type wrapper. +type Orientation bool ; + +// ValueType implements viper.FlagValue interface. +func (_bg Point )ValueType ()string {return _bg .Type ()};var _ed =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; + +// PageSizeValues returns all values of the enum +func PageSizeValues ()[]PageSize {return _gc }; // PageSizeString retrieves an enum value from the enum constants string name. // Throws an error if the param is not part of the enum. -func PageSizeString (s string )(PageSize ,error ){if _bga ,_bdf :=_aafe [s ];_bdf {return _bga ,nil ;};return 0,_ad .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); -};var (_ Length =Millimeter (0);); - -// UnmarshalLength unmarshalls string value into Length. -func UnmarshalLength (length string )(Length ,error ){if _d .HasSuffix (length ,"\u006d\u006d"){return _gaa (length );};if _d .HasSuffix (length ,"\u0069\u006e"){return _ff (length );};if _d .HasSuffix (length ,"\u0070\u0074"){return _aaf (length );};return nil ,_ad .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length ); +func PageSizeString (s string )(PageSize ,error ){if _aecg ,_ede :=_ada [s ];_ede {return _aecg ,nil ;};return 0,_ae .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); }; -// MarshalJSON implements json.Marshaler interface -func (_egg Inch )MarshalJSON ()([]byte ,error ){return _ec (_egg )}; +// HasChanged implements viper.FlagValue interface. +func (_add *Point )HasChanged ()bool {return _add !=nil }; -// UnmarshalJSON implements the json.Unmarshaler interface for PageSize -func (_eac *PageSize )UnmarshalJSON (data []byte )error {var _bgaf string ;if _feb :=_ac .Unmarshal (data ,&_bgaf );_feb !=nil {return _ad .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); -};var _eeg error ;*_eac ,_eeg =PageSizeString (_bgaf );return _eeg ;}; +// PageSize is the enum used for defining the page size. +type PageSize int ; -// MarshalPageSize marshals the page size into string. -func MarshalPageSize (p PageSize )(string ,error ){_dfc ,_eea :=p .MarshalText ();if _eea !=nil {return "",_eea ;};return string (_dfc ),nil ;}; +// Dimensions gets the dimensions of the given page size. +// If provided page size is not valid than the function returns 0 values. +func (_cdg PageSize )Dimensions ()(_gfg ,_acd Millimeter ){switch _cdg {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; +case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; +case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _gfg ,_acd ;}; -// ValueString implements viper.FlagValue interface. -func (_cac Point )ValueString ()string {return _cac .String ()};const (Portrait =Orientation (false );Landscape =Orientation (true );); +// Point is a unit of Length commonly used to measure the height of fonts. +type Point float64 ; -// MarshalUnit marshals the unit into the string. -func MarshalUnit (unit Length )(string ,error ){switch _fe :=unit .(type ){case Millimeter :return _ad .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_fe ),nil ;case Inch :return _ad .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_fe ),nil ;case Point :return _ad .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_fe ),nil ; -default:return "",_ad .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; +// Millimeter is the dimension unit that defines a millimeter. +type Millimeter float64 ;func _fda (_cc Length )([]byte ,error ){if _cc ==nil {return nil ,nil ;};_af ,_cbd :=MarshalUnit (_cc );if _cbd !=nil {return nil ,_cbd ;};return []byte ("\u0022"+_af +"\u0022"),nil ;}; -// Name implements viper.FlagValue interface. -func (_aed Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; +// String implements fmt.Stringer interface. +func (_fbg Millimeter )String ()string {_ad :=_e .Builder {};_ad .WriteString (_b .FormatFloat (float64 (_fbg ),'f',1,64));_ad .WriteString ("\u006d\u006d");return _ad .String ();};func _abc (_ef string )(Point ,error ){_ef =_e .TrimSpace (_e .Trim (_ef ,"\u0070\u0074")); +_gaf ,_bef :=_b .ParseFloat (_ef ,64);if _bef !=nil {return 0,_bef ;};return Point (_gaf ),nil ;}; -// MarshalJSON implements json.Marshaler interface -func (_ae Millimeter )MarshalJSON ()([]byte ,error ){return _ec (_ae )}; +// MarshalJSON implements the json.Marshaler interface for PageSize +func (_ecd PageSize )MarshalJSON ()([]byte ,error ){return _f .Marshal (_ecd .String ())}; -// Type implements pflag.Value interface. -func (_cf Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; +// UnmarshalPageSize unmarshals the page size from the string. +func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _efe PageSize ;if _bae :=(&_efe ).UnmarshalText ([]byte (pageSize ));_bae !=nil {return 0,_ae .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_bae ); +};return _efe ,nil ;}; + +// MarshalText implements the encoding.TextMarshaler interface for PageSize +func (_ecfa PageSize )MarshalText ()([]byte ,error ){return []byte (_ecfa .String ()),nil };var _ Length =Inch (0); // Set sets the unit value. // Implements pflag.Value interface. -func (_aa *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_aa .Length =nil ;return nil ;};_ggf ,_bf :=UnmarshalLength (s );if _bf !=nil {return _bf ;};_aa .Length =_ggf ;return nil ;}; +func (_ce *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_ce .Length =nil ;return nil ;};_cd ,_dg :=UnmarshalLength (s );if _dg !=nil {return _dg ;};_ce .Length =_cd ;return nil ;}; -// Set implements flag.Value interface. -func (_dfa *Point )Set (s string )error {_bcd ,_cga :=_e .ParseFloat (s ,64);if _cga !=nil {return _ad .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_cga );};*_dfa =Point (_bcd ); -return nil ;}; +// Type implements pflag.Value interface. +func (_aeg PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"};const (_fb =float64 (1)/float64 (25.4);_d =25.4;_eb =0.0139;_bc =0.3528;_c =1.0/64;_ab =1.0/_bc ;); -// String gets the string value for given flag. -func (_gc *LengthFlag )String ()string {if _gc .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _gc .Length .String ();}; +// UnmarshalLength unmarshalls string value into Length. +func UnmarshalLength (length string )(Length ,error ){if _e .HasSuffix (length ,"\u006d\u006d"){return _dda (length );};if _e .HasSuffix (length ,"\u0069\u006e"){return _gfa (length );};if _e .HasSuffix (length ,"\u0070\u0074"){return _abc (length );}; +return nil ,_ae .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length );}; + +// Inches gets the inches equivalent from provided millimeter value. +func (_fe Millimeter )Inches ()Inch {return Inch (float64 (_fe )*_fb )};func _gfa (_eeb string )(Inch ,error ){_eeb =_e .TrimSpace (_e .Trim (_eeb ,"\u0069\u006e"));_dfa ,_ceb :=_b .ParseFloat (_eeb ,64);if _ceb !=nil {return 0,_ae .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ceb ); +};return Inch (_dfa ),nil ;}; // String implements fmt.Stringer interface. -func (_fa Inch )String ()string {_ca :=_d .Builder {};_ca .WriteString (_e .FormatFloat (float64 (_fa ),'f',1,64));_ca .WriteString ("\u0069\u006e");return _ca .String ();}; +func (_efd Orientation )String ()string {if _efd ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; -// Length is it the default dimension unit. -type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; +// Type implements pflag.Value interface. +func (_cg Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; -// Dimensions gets the dimensions of the given page size. -// If provided page size is not valid than the function returns 0 values. -func (_gfb PageSize )Dimensions ()(_dc ,_ecc Millimeter ){switch _gfb {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; -case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; -case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _dc ,_ecc ;}; +// UnmarshalInch unmarshalls provided string into unit. +func UnmarshalInch (unit string )(Inch ,error ){if _e .HasSuffix (unit ,"\u006d\u006d"){_eae ,_ddb :=_dda (unit );if _ddb !=nil {return 0,_ddb ;};return _eae .Inches (),nil ;};if _e .HasSuffix (unit ,"\u0069\u006e"){return _gfa (unit );};return 0,_ae .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); +}; -// Set implements pflag.Value interface. -func (_de *Inch )Set (s string )error {_ebd ,_dg :=_e .ParseFloat (s ,64);if _dg !=nil {return _ad .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_dg );};*_de =Inch (_ebd ); -return nil ;};var _aafe =map[string ]PageSize {_cfa [0:9]:0,_cfa [9:11]:1,_cfa [11:13]:2,_cfa [13:15]:3,_cfa [15:17]:4,_cfa [17:19]:5,_cfa [19:21]:6,_cfa [21:23]:7,_cfa [23:25]:8,_cfa [25:27]:9,_cfa [27:29]:10,_cfa [29:32]:11,_cfa [32:34]:12,_cfa [34:36]:13,_cfa [36:38]:14,_cfa [38:40]:15,_cfa [40:42]:16,_cfa [42:44]:17,_cfa [44:46]:18,_cfa [46:48]:19,_cfa [48:50]:20,_cfa [50:52]:21,_cfa [52:55]:22,_cfa [55:61]:23}; +// Millimeters converts the inches value to the millimeters. +func (_gb Point )Millimeters ()Millimeter {return Millimeter (float64 (_gb )*_bc )};func _dda (_dab string )(Millimeter ,error ){_dab =_e .TrimSpace (_e .TrimSuffix (_dab ,"\u006d\u006d"));_dae ,_ac :=_b .ParseFloat (_dab ,64);if _ac !=nil {return 0,_ae .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_ac ); +};return Millimeter (_dae ),nil ;}; + +// ValueString implements viper.FlagValue interface. +func (_dcd Point )ValueString ()string {return _dcd .String ()};var _ada =map[string ]PageSize {_cdaa [0:9]:0,_cdaa [9:11]:1,_cdaa [11:13]:2,_cdaa [13:15]:3,_cdaa [15:17]:4,_cdaa [17:19]:5,_cdaa [19:21]:6,_cdaa [21:23]:7,_cdaa [23:25]:8,_cdaa [25:27]:9,_cdaa [27:29]:10,_cdaa [29:32]:11,_cdaa [32:34]:12,_cdaa [34:36]:13,_cdaa [36:38]:14,_cdaa [38:40]:15,_cdaa [40:42]:16,_cdaa [42:44]:17,_cdaa [44:46]:18,_cdaa [46:48]:19,_cdaa [48:50]:20,_cdaa [50:52]:21,_cdaa [52:55]:22,_cdaa [55:61]:23}; -// MarshalJSON implements the json.Marshaler interface for PageSize -func (_fde PageSize )MarshalJSON ()([]byte ,error ){return _ac .Marshal (_fde .String ())}; \ No newline at end of file +// MarshalUnit marshals the unit into the string. +func MarshalUnit (unit Length )(string ,error ){switch _ff :=unit .(type ){case Millimeter :return _ae .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_ff ),nil ;case Inch :return _ae .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_ff ),nil ;case Point :return _ae .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_ff ),nil ; +default:return "",_ae .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; + +// HasChanged implements pflag.Value interface. +func (_agd *Inch )HasChanged ()bool {return _agd !=nil }; \ No newline at end of file diff --git a/unihtml.go b/unihtml.go index 467fa0d..613a3c2 100644 --- a/unihtml.go +++ b/unihtml.go @@ -10,8 +10,26 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package unihtml contains a plugin for the UniDoc. -package unihtml ;import (_g "bytes";_c "context";_db "errors";_a "fmt";_b "github.com/unidoc/unihtml/client";_gc "github.com/unidoc/unihtml/content";_dee "github.com/unidoc/unihtml/selector";_af "github.com/unidoc/unihtml/sizes";_gcg "github.com/unidoc/unipdf/v3/common"; -_da "github.com/unidoc/unipdf/v3/common/license";_cef "github.com/unidoc/unipdf/v3/creator";_ab "github.com/unidoc/unipdf/v3/model";_be "github.com/unidoc/unipdf/v3/render";_dc "image";_de "image/color";_dd "math";_ce "net/url";_d "os";_df "time";); +package unihtml ;import (_bb "bytes";_f "context";_bd "errors";_g "fmt";_cge "github.com/unidoc/unihtml/client";_fb "github.com/unidoc/unihtml/content";_fd "github.com/unidoc/unihtml/selector";_e "github.com/unidoc/unihtml/sizes";_ef "github.com/unidoc/unipdf/v4/common"; +_bgb "github.com/unidoc/unipdf/v4/common/license";_ca "github.com/unidoc/unipdf/v4/creator";_fa "github.com/unidoc/unipdf/v4/model";_ed "github.com/unidoc/unipdf/v4/render";_bf "image";_cg "image/color";_da "math";_b "net/url";_c "os";_bg "time";);func _eae ()error {_cd :=_bgb .GetLicenseKey (); +if _cd ==nil {return _bd .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};if !_cd .IsLicensed (){return _bd .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); +};return nil ;}; + +// Connect creates UniHTML HTTP Client and tries to establish connection with the server. +func Connect (path string )error {if _ec :=_eae ();_ec !=nil {return _ec ;};_fe ,_ba :=_cge .ParseOptions (path );if _ba !=nil {return _ba ;};_ff =_cge .New (_fe );_gd ,_ce :=_f .WithTimeout (_f .Background (),_bg .Second *5);defer _ce ();if _ea :=_ff .HealthCheck (_gd ); +_ea !=nil {return _ea ;};return nil ;}; + +// SetMarginRight sets the left margin. +func (_ebd *Document )SetMarginRight (margin _e .Length ){_ebd ._a .Right =margin }; + +// GeneratePageBlocks implements creator.Drawable interface. +func (_bbg *Document )GeneratePageBlocks (ctx _ca .DrawContext )([]*_ca .Block ,_ca .DrawContext ,error ){if _ab :=_bbg .validate ();_ab !=nil {return nil ,ctx ,_ab ;};var _ee []*_ca .Block ;_gaf :=_bbg .getMargins ();_eaa ,_ffg :=_bbg ._cdd ,_bbg ._cf ; +if _bbg ._bfd .IsRelative (){_eaa ,_ffg =_e .Point (ctx .Width ),_e .Point (ctx .Height );ctx .X -=float64 (_gaf .Left .Points ());}else {ctx .X =_bbg ._ae ;ctx .Y =_bbg ._cgd ;};_ag ,_efe :=_bbg .extract (_f .Background (),_eaa ,_ffg ,_gaf );if _efe !=nil {return nil ,_ca .DrawContext {},_efe ; +};for _edg ,_cee :=range _ag {_faa ,_db :=_ca .NewBlockFromPage (_cee );if _db !=nil {return nil ,_ca .DrawContext {},_db ;};var _caf float64 ;if _bbg ._cddf &&_edg ==len (_ag )-1{_ggc :=_ed .NewImageDevice ();_cdg ,_gfa :=_ggc .Render (_cee );if _gfa !=nil {return nil ,_ca .DrawContext {},_gfa ; +};_gc ,_gfa :=_cee .GetMediaBox ();if _gfa !=nil {return nil ,_ca .DrawContext {},_gfa ;};_fef :=_bg .Now ();_gfae :=_eg (_cdg );_caf =_gc .Height ()*_gfae ;_ef .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_bg .Since (_fef )); +if _bbg ._a .Bottom !=nil {_caf -=float64 (_bbg ._a .Bottom .Points ());};if _caf < 0{_caf =0;};_ef .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_caf ); +};_af ,_abf ,_db :=_faa .GeneratePageBlocks (ctx );if _db !=nil {return nil ,_ca .DrawContext {},_db ;};ctx =_abf ;ctx .Y -=_caf ;if _edg !=len (_ag )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; +ctx .Page ++;};_ee =append (_ee ,_af ...);};return _ee ,ctx ,nil ;};func (_fad *Document )getTimeoutDuration ()_bg .Duration {if _fad ._ga !=nil {return *_fad ._ga ;};return 0;}; // Options are the HTML Client options used for establishing the connection. type Options struct{ @@ -28,109 +46,91 @@ Secure bool ; // Prefix is an option setting used when the server is working with the URI prefix. Default Value: ''. Prefix string ;}; -// SetMarginTop sets the left margin. -func (_cdb *Document )SetMarginTop (margin _af .Length ){_cdb ._acb .Top =margin }; +// SetTimeoutDuration sets the timeout duration +// the default timeout is 15 seconds. +func (_cae *Document )SetTimeoutDuration (duration _bg .Duration ){_cae ._ga =&duration }; -// SetMarginBottom sets the left margin. -func (_cbg *Document )SetMarginBottom (margin _af .Length ){_cbg ._acb .Bottom =margin }; +// SetLandscapeOrientation sets document landscape page orientation. +func (_ebf *Document )SetLandscapeOrientation (){_ebf ._cfa =_e .Landscape }; -// SetMarginRight sets the left margin. -func (_bg *Document )SetMarginRight (margin _af .Length ){_bg ._acb .Right =margin }; +// ContainerComponent implements creator.containerElement interface. +func (_dcc *Document )ContainerComponent (container _ca .Drawable )(_ca .Drawable ,error ){switch container .(type ){case *_ca .Chapter :default:return nil ,_g .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); +};return _dcc ,nil ;}; -// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. -func (_ge *Document )TrimLastPageContent (){_ge ._eda =true };var ErrContentNotDefined =_db .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); -func (_baa *Document )getMargins ()margins {_abb :=_baa ._acb ;if _baa ._edb .IsRelative (){_abb .Top =_af .Millimeter (1);_abb .Left =_af .Millimeter (1);_abb .Bottom =_af .Millimeter (1);_abb .Right =_af .Millimeter (1);return _abb ;};if _abb .Top ==nil {_abb .Top =_af .Millimeter (10); -};if _abb .Bottom ==nil {_abb .Bottom =_af .Millimeter (10);};if _abb .Left ==nil {_abb .Left =_af .Millimeter (10);};if _abb .Right ==nil {_abb .Right =_af .Millimeter (10);};return _abb ;}; +// GetContent returns the content of the document. +func (_fdb *Document )GetContent ()_fb .Content {return _fdb ._bag }; -// SetMarginLeft sets the left margin. -func (_ead *Document )SetMarginLeft (margin _af .Length ){_ead ._acb .Left =margin }; +// NewDocumentFromString creates a new Document from the provided HTML string. +func NewDocumentFromString (html string )(*Document ,error ){_aef ,_cef :=_fb .NewStringContent (html );if _cef !=nil {return nil ,_cef ;};_eb :=&Document {};_eb ._bag =_aef ;return _eb ,nil ;};func (_eag *Document )getMargins ()margins {_dfa :=_eag ._a ; +if _eag ._bfd .IsRelative (){_dfa .Top =_e .Millimeter (1);_dfa .Left =_e .Millimeter (1);_dfa .Bottom =_e .Millimeter (1);_dfa .Right =_e .Millimeter (1);return _dfa ;};if _dfa .Top ==nil {_dfa .Top =_e .Millimeter (10);};if _dfa .Bottom ==nil {_dfa .Bottom =_e .Millimeter (10); +};if _dfa .Left ==nil {_dfa .Left =_e .Millimeter (10);};if _dfa .Right ==nil {_dfa .Right =_e .Millimeter (10);};return _dfa ;};var ErrNoClient =_bd .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); -// SetPageWidth sets the page width for given document. -func (_gdc *Document )SetPageWidth (pageWidth _af .Length )error {_gdc ._fb =pageWidth ;_gdc ._edb =_cef .PositionAbsolute ;return nil ;};func _aga (_afa _dc .Image )float64 {_fed :=_afa .Bounds ();var (_bf int ;_ebf _de .Color ;_fgd ,_fdg ,_bfa uint32 ; -);_bc ,_fgf :=_fed .Min .X ,_fed .Max .Y -1;_fae :=_afa .At (_bc ,_fgf );_ee ,_dbf ,_ced ,_ :=_fae .RGBA ();_gf :=_ee ==_dd .MaxUint16 &&_dbf ==_dd .MaxUint16 &&_ced ==_dd .MaxUint16 ;for _fgf =_fed .Max .Y -1;_fgf >=_fed .Min .Y ;_fgf --{var _fcg bool ; -for _bc =_fed .Min .X ;_bc < _fed .Max .X ;_bc ++{_ebf =_afa .At (_bc ,_fgf );_fgd ,_fdg ,_bfa ,_ =_ebf .RGBA ();if (_gf &&!(_fgd ==_ee &&_fdg ==_dbf &&_ced ==_bfa ))||(!_gf &&(_dd .Abs (float64 (_fgd )-float64 (_ee ))/float64 (_dd .MaxUint16 )> 0.03||_dd .Abs (float64 (_fdg )-float64 (_dbf ))/float64 (_dd .MaxUint16 )> 0.03||_dd .Abs (float64 (_bfa )-float64 (_ced ))/float64 (_dd .MaxUint16 )> 0.03)){_fcg =true ; -break ;};};if _fcg {break ;};_bf =_fgf ;};return float64 (_fed .Max .Y -_bf )/float64 (_fed .Max .Y );};func _ed ()error {_acc :=_da .GetLicenseKey ();if _acc ==nil {return _db .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); -};if !_acc .IsLicensed (){return _db .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};return nil ;};var ErrNoClient =_db .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); +// SetPageHeight sets the page height for given document. +func (_cab *Document )SetPageHeight (pageHeight _e .Length )error {_cab ._cf =pageHeight ;_cab ._bfd =_ca .PositionAbsolute ;return nil ;}; -// Connect creates UniHTML HTTP Client and tries to establish connection with the server. -func Connect (path string )error {if _fc :=_ed ();_fc !=nil {return _fc ;};_fa ,_cg :=_b .ParseOptions (path );if _cg !=nil {return _cg ;};_f =_b .New (_fa );_ba ,_fe :=_c .WithTimeout (_c .Background (),_df .Second *5);defer _fe ();if _cgc :=_f .HealthCheck (_ba ); -_cgc !=nil {return _cgc ;};return nil ;}; +// SetPageSize sets the page default size. +func (_bge *Document )SetPageSize (pageSize _e .PageSize )error {if !pageSize .IsAPageSize (){return _bd .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); +};_bge ._eca =pageSize ;_bge ._bfd =_ca .PositionAbsolute ;return nil ;}; -// WaitTime sets the waiting time before the webpage is rendered to PDF. -func (_eae *Document )WaitTime (duration _df .Duration ){_eae ._dda =duration }; +// GetPdfPages is a function that converts provided input content and +func (_cb *Document )GetPdfPages (ctx _f .Context )([]*_fa .PdfPage ,error ){if _dad :=_cb .validate ();_dad !=nil {return nil ,_dad ;};return _cb .extract (ctx ,_cb ._cdd ,_cb ._cf ,_cb .getMargins ());};func (_afg *Document )extract (_aa _f .Context ,_dgg ,_bgd _e .Length ,_aefe margins )([]*_fa .PdfPage ,error ){_dd :=_cge .BuildHTMLQuery ().SetContent (_afg ._bag ).PageSize (_afg ._eca ).PaperWidth (_dgg ).PaperHeight (_bgd ).Orientation (_afg ._cfa ).MarginLeft (_aefe .Left ).MarginRight (_aefe .Right ).MarginTop (_aefe .Top ).MarginBottom (_aefe .Bottom ).TimeoutDuration (_afg .getTimeoutDuration ()).WaitTime (_afg ._bfb ); +for _ ,_efeb :=range _afg ._cga {_dd .WaitReady (_efeb .Selector ,_efeb .By );};for _ ,_cgac :=range _afg ._fg {_dd .WaitVisible (_cgac .Selector ,_cgac .By );};_fff ,_gac :=_dd .Query ();if _gac !=nil {return nil ,_gac ;};var _ffa _f .CancelFunc ;if _afg ._ga !=nil {_aa ,_ffa =_f .WithTimeout (_aa ,*_afg ._ga ); +}else {_aa ,_ffa =_f .WithTimeout (_aa ,_bg .Second *15);};defer _ffa ();_fae ,_gac :=_ff .ConvertHTML (_aa ,_fff );if _gac !=nil {return nil ,_gac ;};_ebe :=_bb .NewReader (_fae .Data );_cdcd ,_gac :=_fa .NewPdfReader (_ebe );if _gac !=nil {return nil ,_gac ; +};return _cdcd .PageList ,nil ;};var _ff *_cge .Client ;var ErrContentNotDefined =_bd .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); +var _ _ca .Drawable =(*Document )(nil );type margins struct{Left ,Right ,Bottom ,Top _e .Length ;}; -// GetContent returns the content of the document. -func (_cgca *Document )GetContent ()_gc .Content {return _cgca ._ca };func (_ffa *Document )getTimeoutDuration ()_df .Duration {if _ffa ._fec !=nil {return *_ffa ._fec ;};return 0;}; +// SetPageWidth sets the page width for given document. +func (_dfd *Document )SetPageWidth (pageWidth _e .Length )error {_dfd ._cdd =pageWidth ;_dfd ._bfd =_ca .PositionAbsolute ;return nil ;}; + +// WaitVisible waits for the provided selector to be ready. +// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. +func (_deb *Document )WaitVisible (sel string ,by ..._fd .ByType ){_cgg :=_fd .BySearch ;if len (by )> 0{_cgg =by [0];};_deb ._fg =append (_deb ._fg ,_cge .BySelector {Selector :sel ,By :_cgg });}; // Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. -type Document struct{_ca _gc .Content ;_acb margins ;_edb _cef .Positioning ;_cb ,_dg float64 ;_gd _af .PageSize ;_fb ,_edf _af .Length ;_eff _af .Orientation ;_eda bool ;_dda _df .Duration ;_bd []_b .BySelector ;_gcd []_b .BySelector ;_fec *_df .Duration ; -}; +type Document struct{_bag _fb .Content ;_a margins ;_bfd _ca .Positioning ;_ae ,_cgd float64 ;_eca _e .PageSize ;_cdd ,_cf _e .Length ;_cfa _e .Orientation ;_cddf bool ;_bfb _bg .Duration ;_cga []_cge .BySelector ;_fg []_cge .BySelector ;_ga *_bg .Duration ; +};func (_gca *Document )validate ()error {if _ff ==nil {return ErrNoClient ;};if _gca ._bag ==nil {return ErrContentNotDefined ;};return nil ;}; -// WaitReady waits for the provided selector to be ready. -// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_ceb *Document )WaitReady (sel string ,by ..._dee .ByType ){_agbe :=_dee .BySearch ;if len (by )> 0{_agbe =by [0];};_ceb ._bd =append (_ceb ._bd ,_b .BySelector {Selector :sel ,By :_agbe });};func (_ebd *Document )validate ()error {if _f ==nil {return ErrNoClient ; -};if _ebd ._ca ==nil {return ErrContentNotDefined ;};return nil ;}; +// WaitTime sets the waiting time before the webpage is rendered to PDF. +func (_gbg *Document )WaitTime (duration _bg .Duration ){_gbg ._bfb =duration }; -// GeneratePageBlocks implements creator.Drawable interface. -func (_ag *Document )GeneratePageBlocks (ctx _cef .DrawContext )([]*_cef .Block ,_cef .DrawContext ,error ){if _dde :=_ag .validate ();_dde !=nil {return nil ,ctx ,_dde ;};var _ec []*_cef .Block ;_gdd :=_ag .getMargins ();_fdf ,_gg :=_ag ._fb ,_ag ._edf ; -if _ag ._edb .IsRelative (){_fdf ,_gg =_af .Point (ctx .Width ),_af .Point (ctx .Height );ctx .X -=float64 (_gdd .Left .Points ());}else {ctx .X =_ag ._cb ;ctx .Y =_ag ._dg ;};_ff ,_eg :=_ag .extract (_c .Background (),_fdf ,_gg ,_gdd );if _eg !=nil {return nil ,_cef .DrawContext {},_eg ; -};for _agb ,_efb :=range _ff {_cd ,_fcf :=_cef .NewBlockFromPage (_efb );if _fcf !=nil {return nil ,_cef .DrawContext {},_fcf ;};var _ga float64 ;if _ag ._eda &&_agb ==len (_ff )-1{_gdb :=_be .NewImageDevice ();_fda ,_cc :=_gdb .Render (_efb );if _cc !=nil {return nil ,_cef .DrawContext {},_cc ; -};_dae ,_cc :=_efb .GetMediaBox ();if _cc !=nil {return nil ,_cef .DrawContext {},_cc ;};_fce :=_df .Now ();_aeb :=_aga (_fda );_ga =_dae .Height ()*_aeb ;_gcg .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_df .Since (_fce )); -if _ag ._acb .Bottom !=nil {_ga -=float64 (_ag ._acb .Bottom .Points ());};if _ga < 0{_ga =0;};_gcg .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_ga ); -};_bad ,_gcgc ,_fcf :=_cd .GeneratePageBlocks (ctx );if _fcf !=nil {return nil ,_cef .DrawContext {},_fcf ;};ctx =_gcgc ;ctx .Y -=_ga ;if _agb !=len (_ff )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; -ctx .Page ++;};_ec =append (_ec ,_bad ...);};return _ec ,ctx ,nil ;}; +// SetPos sets the absolute position. Changes object positioning to absolute. +func (_gbc *Document )SetPos (x ,y float64 ){_gbc ._bfd =_ca .PositionAbsolute ;_gbc ._ae =x ;_gbc ._cgd =y ;}; -// GetPdfPages is a function that converts provided input content and -func (_ae *Document )GetPdfPages (ctx _c .Context )([]*_ab .PdfPage ,error ){if _abdd :=_ae .validate ();_abdd !=nil {return nil ,_abdd ;};return _ae .extract (ctx ,_ae ._fb ,_ae ._edf ,_ae .getMargins ());};var _ _cef .Drawable =(*Document )(nil ); +// SetMarginLeft sets the left margin. +func (_bdg *Document )SetMarginLeft (margin _e .Length ){_bdg ._a .Left =margin }; // SetMarkedContentID sets the marked content id for the document. -func (_fbd *Document )SetMarkedContentID (id int64 )*_ab .KDict {return nil }; +func (_bba *Document )SetMarkedContentID (id int64 )*_fa .KDict {return nil }; -// WaitVisible waits for the provided selector to be ready. +// WaitReady waits for the provided selector to be ready. // A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_gfc *Document )WaitVisible (sel string ,by ..._dee .ByType ){_bada :=_dee .BySearch ;if len (by )> 0{_bada =by [0];};_gfc ._gcd =append (_gfc ._gcd ,_b .BySelector {Selector :sel ,By :_bada });}; +func (_ebfa *Document )WaitReady (sel string ,by ..._fd .ByType ){_bfe :=_fd .BySearch ;if len (by )> 0{_bfe =by [0];};_ebfa ._cga =append (_ebfa ._cga ,_cge .BySelector {Selector :sel ,By :_bfe });}; -// SetLandscapeOrientation sets document landscape page orientation. -func (_fef *Document )SetLandscapeOrientation (){_fef ._eff =_af .Landscape }; - -// SetPageHeight sets the page height for given document. -func (_fgc *Document )SetPageHeight (pageHeight _af .Length )error {_fgc ._edf =pageHeight ;_fgc ._edb =_cef .PositionAbsolute ;return nil ;}; - -// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. -func ConnectOptions (o Options )error {_f =_b .New (_b .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_ac ,_fd :=_c .WithTimeout (_c .Background (),_df .Second *5);defer _fd ();if _ef :=_f .HealthCheck (_ac );_ef !=nil {return _ef ; -};return nil ;}; +// SetMarginTop sets the left margin. +func (_face *Document )SetMarginTop (margin _e .Length ){_face ._a .Top =margin }; -// SetPageSize sets the page default size. -func (_dge *Document )SetPageSize (pageSize _af .PageSize )error {if !pageSize .IsAPageSize (){return _db .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); -};_dge ._gd =pageSize ;_dge ._edb =_cef .PositionAbsolute ;return nil ;}; +// SetMarginBottom sets the left margin. +func (_dg *Document )SetMarginBottom (margin _e .Length ){_dg ._a .Bottom =margin };func _eg (_bca _bf .Image )float64 {_efa :=_bca .Bounds ();var (_dadf int ;_geb _cg .Color ;_faf ,_agc ,_dc uint32 ;);_gb ,_cc :=_efa .Min .X ,_efa .Max .Y -1;_dfb :=_bca .At (_gb ,_cc ); +_gdb ,_gfc ,_cdc ,_ :=_dfb .RGBA ();_ad :=_gdb ==_da .MaxUint16 &&_gfc ==_da .MaxUint16 &&_cdc ==_da .MaxUint16 ;for _cc =_efa .Max .Y -1;_cc >=_efa .Min .Y ;_cc --{var _gad bool ;for _gb =_efa .Min .X ;_gb < _efa .Max .X ;_gb ++{_geb =_bca .At (_gb ,_cc ); +_faf ,_agc ,_dc ,_ =_geb .RGBA ();if (_ad &&!(_faf ==_gdb &&_agc ==_gfc &&_cdc ==_dc ))||(!_ad &&(_da .Abs (float64 (_faf )-float64 (_gdb ))/float64 (_da .MaxUint16 )> 0.03||_da .Abs (float64 (_agc )-float64 (_gfc ))/float64 (_da .MaxUint16 )> 0.03||_da .Abs (float64 (_dc )-float64 (_cdc ))/float64 (_da .MaxUint16 )> 0.03)){_gad =true ; +break ;};};if _gad {break ;};_dadf =_cc ;};return float64 (_efa .Max .Y -_dadf )/float64 (_efa .Max .Y );}; -// SetTimeoutDuration sets the timeout duration -// the default timeout is 15 seconds. -func (_bfe *Document )SetTimeoutDuration (duration _df .Duration ){_bfe ._fec =&duration };type margins struct{Left ,Right ,Bottom ,Top _af .Length ;}; +// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. +func (_gg *Document )TrimLastPageContent (){_gg ._cddf =true }; // WriteToFile writes the document to a file defined by the output path. -func (_ccf *Document )WriteToFile (outputPath string )error {if _gca :=_ccf .validate ();_gca !=nil {return _gca ;};_aa :=_df .Second *20+_ccf ._dda ;_fg ,_eb :=_c .WithTimeout (_c .Background (),_aa );defer _eb ();_fbc ,_dag :=_ccf .extract (_fg ,_ccf ._fb ,_ccf ._edf ,_ccf .getMargins ()); -if _dag !=nil {return _dag ;};_dbe :=_cef .New ();for _ ,_dce :=range _fbc {if _dag =_dbe .AddPage (_dce );_dag !=nil {return _dag ;};};return _dbe .WriteToFile (outputPath );}; - -// NewDocument creates new HTML Document used as an input for the creator.Drawable. -func NewDocument (path string )(*Document ,error ){_bec :=&Document {};_cba ,_cee :=_ce .Parse (path );if _cee !=nil {return nil ,_cee ;};switch _cba .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_bec ._ca ,_cee =_gc .NewWebURL (path ); -if _cee !=nil {return nil ,_cee ;};return _bec ,nil ;};_abd ,_cee :=_d .Stat (path );if _cee !=nil {return nil ,_cee ;};if !_abd .IsDir (){_bec ._ca ,_cee =_gc .NewHTMLFile (path );}else {_bec ._ca ,_cee =_gc .NewZipDirectory (path );};if _cee !=nil {return nil ,_cee ; -};return _bec ,nil ;};var _f *_b .Client ; - -// SetPos sets the absolute position. Changes object positioning to absolute. -func (_beca *Document )SetPos (x ,y float64 ){_beca ._edb =_cef .PositionAbsolute ;_beca ._cb =x ;_beca ._dg =y ;}; +func (_bfc *Document )WriteToFile (outputPath string )error {if _bc :=_bfc .validate ();_bc !=nil {return _bc ;};_cfe :=_bg .Second *20+_bfc ._bfb ;_ged ,_gce :=_f .WithTimeout (_f .Background (),_cfe );defer _gce ();_de ,_df :=_bfc .extract (_ged ,_bfc ._cdd ,_bfc ._cf ,_bfc .getMargins ()); +if _df !=nil {return _df ;};_fac :=_ca .New ();for _ ,_baag :=range _de {if _df =_fac .AddPage (_baag );_df !=nil {return _df ;};};return _fac .WriteToFile (outputPath );}; -// ContainerComponent implements creator.containerElement interface. -func (_gde *Document )ContainerComponent (container _cef .Drawable )(_cef .Drawable ,error ){switch container .(type ){case *_cef .Chapter :default:return nil ,_a .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); -};return _gde ,nil ;}; - -// NewDocumentFromString creates a new Document from the provided HTML string. -func NewDocumentFromString (html string )(*Document ,error ){_abe ,_ea :=_gc .NewStringContent (html );if _ea !=nil {return nil ,_ea ;};_fac :=&Document {};_fac ._ca =_abe ;return _fac ,nil ;}; +// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. +func ConnectOptions (o Options )error {_ff =_cge .New (_cge .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_baa ,_bdd :=_f .WithTimeout (_f .Background (),_bg .Second *5);defer _bdd ();if _ecd :=_ff .HealthCheck (_baa );_ecd !=nil {return _ecd ; +};return nil ;}; // SetMargins sets the Document Margins. -func (_acbg *Document )SetMargins (left ,right ,top ,bottom float64 ){_acbg ._acb .Left =_af .Point (left );_acbg ._acb .Right =_af .Point (right );_acbg ._acb .Top =_af .Point (top );_acbg ._acb .Bottom =_af .Point (bottom );_acbg ._edb =_cef .PositionAbsolute ; -};func (_eaea *Document )extract (_ad _c .Context ,_ddc ,_dfa _af .Length ,_ceef margins )([]*_ab .PdfPage ,error ){_bcb :=_b .BuildHTMLQuery ().SetContent (_eaea ._ca ).PageSize (_eaea ._gd ).PaperWidth (_ddc ).PaperHeight (_dfa ).Orientation (_eaea ._eff ).MarginLeft (_ceef .Left ).MarginRight (_ceef .Right ).MarginTop (_ceef .Top ).MarginBottom (_ceef .Bottom ).TimeoutDuration (_eaea .getTimeoutDuration ()).WaitTime (_eaea ._dda ); -for _ ,_eadb :=range _eaea ._bd {_bcb .WaitReady (_eadb .Selector ,_eadb .By );};for _ ,_gge :=range _eaea ._gcd {_bcb .WaitVisible (_gge .Selector ,_gge .By );};_efc ,_cgb :=_bcb .Query ();if _cgb !=nil {return nil ,_cgb ;};var _baf _c .CancelFunc ;if _eaea ._fec !=nil {_ad ,_baf =_c .WithTimeout (_ad ,*_eaea ._fec ); -}else {_ad ,_baf =_c .WithTimeout (_ad ,_df .Second *15);};defer _baf ();_fbf ,_cgb :=_f .ConvertHTML (_ad ,_efc );if _cgb !=nil {return nil ,_cgb ;};_aad :=_g .NewReader (_fbf .Data );_cad ,_cgb :=_ab .NewPdfReader (_aad );if _cgb !=nil {return nil ,_cgb ; -};return _cad .PageList ,nil ;}; \ No newline at end of file +func (_caa *Document )SetMargins (left ,right ,top ,bottom float64 ){_caa ._a .Left =_e .Point (left );_caa ._a .Right =_e .Point (right );_caa ._a .Top =_e .Point (top );_caa ._a .Bottom =_e .Point (bottom );_caa ._bfd =_ca .PositionAbsolute ;}; + +// NewDocument creates new HTML Document used as an input for the creator.Drawable. +func NewDocument (path string )(*Document ,error ){_ge :=&Document {};_gf ,_fbg :=_b .Parse (path );if _fbg !=nil {return nil ,_fbg ;};switch _gf .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_ge ._bag ,_fbg =_fb .NewWebURL (path ); +if _fbg !=nil {return nil ,_fbg ;};return _ge ,nil ;};_be ,_fbg :=_c .Stat (path );if _fbg !=nil {return nil ,_fbg ;};if !_be .IsDir (){_ge ._bag ,_fbg =_fb .NewHTMLFile (path );}else {_ge ._bag ,_fbg =_fb .NewZipDirectory (path );};if _fbg !=nil {return nil ,_fbg ; +};return _ge ,nil ;}; \ No newline at end of file From 5b9ebaae136798a22927eb23b020eabc356c04a8 Mon Sep 17 00:00:00 2001 From: UniDoc Build Date: Sun, 25 May 2025 19:48:30 +0000 Subject: [PATCH 9/9] prepare release --- README.md | 4 + cli/cmd/cmd.go | 54 ++++---- cli/main.go | 2 +- client/client.go | 293 ++++++++++++++++++++++--------------------- common/common.go | 6 +- content/content.go | 77 ++++++------ selector/selector.go | 5 +- sizes/sizes.go | 243 +++++++++++++++++------------------ unihtml.go | 163 ++++++++++++------------ 9 files changed, 426 insertions(+), 421 deletions(-) diff --git a/README.md b/README.md index 7de904f..deb3156 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,10 @@ This license kind requires also an environment variable `UNIHTML_CUSTOMER_NAME` UniHTML Server accepts also a UniDoc metered license. This could be set by providing you **API Key** in the environment variable: - `UNIDOC_METERED_API_KEY` - the value of this variable should be an **API Key** matched to your license. +### Ignore Certificate Errors +If you are needed to access a self-signed certificate URL for the UniHTML, you can set the environment variable `UNIHTML_IGNORE_CERT_ERRORS` to `true` to ignore certificate errors. +*However, we did not recommend this for production use, or when you are sure it is safe to set this to `true`*. + ## Usage 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. diff --git a/cli/cmd/cmd.go b/cli/cmd/cmd.go index d3956bb..dd01db4 100644 --- a/cli/cmd/cmd.go +++ b/cli/cmd/cmd.go @@ -9,22 +9,23 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package cmd ;import (_b "context";_c "fmt";_g "github.com/mitchellh/go-homedir";_cc "github.com/spf13/cobra";_ef "github.com/spf13/viper";_ab "github.com/unidoc/unihtml/client";_ce "github.com/unidoc/unihtml/content";_d "github.com/unidoc/unihtml/sizes"; -_ea "github.com/unidoc/unipdf/v4/common";_ag "os";_a "path/filepath";_eg "time";);func _afg (){if _bef !=""{_ef .SetConfigFile (_bef );}else {_fa ,_fc :=_g .Dir ();if _fc !=nil {_c .Println (_fc );_ag .Exit (1);};_ef .AddConfigPath (_fa );_ef .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063"); -};_ef .AutomaticEnv ();if _fg :=_ef .ReadInConfig ();_fg ==nil {_c .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_ef .ConfigFileUsed ());};}; +package cmd ;import (_f "context";_c "fmt";_ca "github.com/mitchellh/go-homedir";_cc "github.com/spf13/cobra";_bg "github.com/spf13/viper";_af "github.com/unidoc/unihtml/client";_b "github.com/unidoc/unihtml/content";_d "github.com/unidoc/unihtml/sizes"; +_gg "github.com/unidoc/unipdf/v4/common";_g "os";_ff "path/filepath";_ac "time";);var (_e =generateConfig {};_fd =parametersConfig {PaperWidth :_d .LengthFlag {Length :_d .Inch (8.5).Millimeters ()},PaperHeight :_d .LengthFlag {Length :_d .Inch (11).Millimeters ()},Orientation :_d .Portrait ,MarginTop :_d .LengthFlag {Length :_d .Millimeter (10)},MarginBottom :_d .LengthFlag {Length :_d .Millimeter (10)},MarginLeft :_d .LengthFlag {Length :_d .Millimeter (10)},MarginRight :_d .LengthFlag {Length :_d .Millimeter (10)}}; +); // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. -func Execute (){if _gcg :=_aa .Execute ();_gcg !=nil {_c .Println (_gcg );_ag .Exit (1);};};var _aa =&_cc .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; -type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};func init (){_aa .AddCommand (_f );_f .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072"); -_f .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); -_f .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); -_f .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); -_f .Flags ().Var (&_ed .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_f .Flags ().Var (&_ed .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); -_f .Flags ().Var (&_ed .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_f .Flags ().Var (&_ed .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); -_f .Flags ().Var (&_ed .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_f .Flags ().Var (&_ed .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); -_f .Flags ().Var (&_ed .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_f .Flags ().Var (&_ed .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); -};type parametersConfig struct{ +func Execute (){if _ab :=_bd .Execute ();_ab !=nil {_c .Println (_ab );_g .Exit (1);};};func _gdd (){_bf :=_gg .LogLevelInfo ;if _dbe {_bf =_gg .LogLevelDebug ;};if _bc {_bf =_gg .LogLevelTrace ;};_gg .Log =_gg .NewConsoleLogger (_bf );};var _cf string ; +func init (){_bd .AddCommand (_fb );_fb .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072");_fb .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); +_fb .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); +_fb .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); +_fb .Flags ().Var (&_fd .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_fb .Flags ().Var (&_fd .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); +_fb .Flags ().Var (&_fd .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_fb .Flags ().Var (&_fd .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); +_fb .Flags ().Var (&_fd .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_fb .Flags ().Var (&_fd .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); +_fb .Flags ().Var (&_fd .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_fb .Flags ().Var (&_fd .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); +};func _feg (){if _cf !=""{_bg .SetConfigFile (_cf );}else {_ee ,_abae :=_ca .Dir ();if _abae !=nil {_c .Println (_abae );_g .Exit (1);};_bg .AddConfigPath (_ee );_bg .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063"); +};_bg .AutomaticEnv ();if _bdg :=_bg .ReadInConfig ();_bdg ==nil {_c .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_bg .ConfigFileUsed ());};};var _bd =&_cc .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; +type parametersConfig struct{ // PaperWidth sets the width of the paper. PaperWidth _d .LengthFlag `mapstructure:"paper-width"`; @@ -48,17 +49,16 @@ MarginBottom _d .LengthFlag `mapstructure:"margin-bottom"`; MarginLeft _d .LengthFlag `mapstructure:"margin-left"`; // MarginRight sets up the Right Margin for the output. -MarginRight _d .LengthFlag `mapstructure:"margin-right"`;};func _ae (cmd *_cc .Command ,_ec []string ){_egc :=_eg .Now ();if _efc :=_ef .BindPFlags (cmd .Flags ());_efc !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_efc );_ag .Exit (1); -};if _gad :=_ef .Unmarshal (&_ga );_gad !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gad );_ag .Exit (1);};_ecg ();_eb ,_ac :=_ag .Stat (_ec [0]);if _ac !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ac ); -_ag .Exit (1);};if !_eb .IsDir (){if _a .Ext (_eb .Name ())!="\u002e\u0068\u0074m\u006c"{_c .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_ec [0]); -_ag .Exit (1);};};_fb ,_ac :=_ag .OpenFile (_ec [1],_ag .O_CREATE |_ag .O_WRONLY |_ag .O_TRUNC ,0700);if _ac !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ac );_ag .Exit (1);};defer _fb .Close ();_ee :=_ab .New (_ab .Options {HTTPS :_ga .Https ,Hostname :_ga .Host ,Port :_ga .Port ,Prefix :_ga .Prefix }); -_be ,_gc :=_b .WithTimeout (_b .Background (),_eg .Second *10);defer _gc ();_cg :=_eg .Now ();var _aeg _ce .Content ;if _eb .IsDir (){_aeg ,_ac =_ce .NewZipDirectory (_ec [0]);}else {_aeg ,_ac =_ce .NewHTMLFile (_ec [0]);};if _ac !=nil {_c .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_ac ); -_ag .Exit (1);};_gada ,_ac :=_ab .BuildHTMLQuery ().PaperWidth (_ed .PaperWidth .Length ).PaperHeight (_ed .PaperHeight .Length ).PageSize (_ed .PageSize ).MarginTop (_ed .MarginTop .Length ).MarginBottom (_ed .MarginBottom .Length ).MarginLeft (_ed .MarginLeft .Length ).MarginRight (_ed .MarginRight .Length ).Orientation (_ed .Orientation ).SetContent (_aeg ).Query (); -if _ac !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ac );_ag .Exit (1);};_agf ,_ac :=_ee .ConvertHTML (_be ,_gada );if _ac !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ac );_ag .Exit (1);};_ea .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_eg .Since (_cg )); -_cg =_eg .Now ();_ ,_ac =_fb .Write (_agf .Data );if _ac !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ac );_ag .Exit (1);};_ea .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_eg .Since (_cg )); -_c .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_eg .Since (_egc ));};var _bef string ;var (_ga =generateConfig {};_ed =parametersConfig {PaperWidth :_d .LengthFlag {Length :_d .Inch (8.5).Millimeters ()},PaperHeight :_d .LengthFlag {Length :_d .Inch (11).Millimeters ()},Orientation :_d .Portrait ,MarginTop :_d .LengthFlag {Length :_d .Millimeter (10)},MarginBottom :_d .LengthFlag {Length :_d .Millimeter (10)},MarginLeft :_d .LengthFlag {Length :_d .Millimeter (10)},MarginRight :_d .LengthFlag {Length :_d .Millimeter (10)}}; -);var _f =&_cc .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_ae ,Args :_cc .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; -func init (){_cc .OnInitialize (_afg );_aa .PersistentFlags ().BoolVarP (&_gd ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065");_aa .PersistentFlags ().BoolVarP (&_gdd ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); -_aa .PersistentFlags ().StringVar (&_bef ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); -_aa .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};func _ecg (){_df :=_ea .LogLevelInfo ;if _gd {_df =_ea .LogLevelDebug ; -};if _gdd {_df =_ea .LogLevelTrace ;};_ea .Log =_ea .NewConsoleLogger (_df );};var (_gd ,_gdd bool ;); \ No newline at end of file +MarginRight _d .LengthFlag `mapstructure:"margin-right"`;};var _fb =&_cc .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_ga ,Args :_cc .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; +type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};func init (){_cc .OnInitialize (_feg );_bd .PersistentFlags ().BoolVarP (&_dbe ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065"); +_bd .PersistentFlags ().BoolVarP (&_bc ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); +_bd .PersistentFlags ().StringVar (&_cf ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); +_bd .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};var (_dbe ,_bc bool ;);func _ga (cmd *_cc .Command ,_da []string ){_gf :=_ac .Now (); +if _be :=_bg .BindPFlags (cmd .Flags ());_be !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_be );_g .Exit (1);};if _fff :=_bg .Unmarshal (&_e );_fff !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_fff );_g .Exit (1); +};_gdd ();_eb ,_dab :=_g .Stat (_da [0]);if _dab !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dab );_g .Exit (1);};if !_eb .IsDir (){if _ff .Ext (_eb .Name ())!="\u002e\u0068\u0074m\u006c"{_c .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_da [0]); +_g .Exit (1);};};_bga ,_dab :=_g .OpenFile (_da [1],_g .O_CREATE |_g .O_WRONLY |_g .O_TRUNC ,0700);if _dab !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dab );_g .Exit (1);};defer _bga .Close ();_db :=_af .New (_af .Options {HTTPS :_e .Https ,Hostname :_e .Host ,Port :_e .Port ,Prefix :_e .Prefix }); +_ffb ,_cae :=_f .WithTimeout (_f .Background (),_ac .Second *10);defer _cae ();_cad :=_ac .Now ();var _caf _b .Content ;if _eb .IsDir (){_caf ,_dab =_b .NewZipDirectory (_da [0]);}else {_caf ,_dab =_b .NewHTMLFile (_da [0]);};if _dab !=nil {_c .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_dab ); +_g .Exit (1);};_ggf ,_dab :=_af .BuildHTMLQuery ().PaperWidth (_fd .PaperWidth .Length ).PaperHeight (_fd .PaperHeight .Length ).PageSize (_fd .PageSize ).MarginTop (_fd .MarginTop .Length ).MarginBottom (_fd .MarginBottom .Length ).MarginLeft (_fd .MarginLeft .Length ).MarginRight (_fd .MarginRight .Length ).Orientation (_fd .Orientation ).SetContent (_caf ).Query (); +if _dab !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dab );_g .Exit (1);};_dc ,_dab :=_db .ConvertHTML (_ffb ,_ggf );if _dab !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dab );_g .Exit (1);};_gg .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_ac .Since (_cad )); +_cad =_ac .Now ();_ ,_dab =_bga .Write (_dc .Data );if _dab !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dab );_g .Exit (1);};_gg .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_ac .Since (_cad )); +_c .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_ac .Since (_gf ));}; \ No newline at end of file diff --git a/cli/main.go b/cli/main.go index 9be0d6b..3ba61aa 100644 --- a/cli/main.go +++ b/cli/main.go @@ -9,4 +9,4 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package main ;import _c "github.com/unidoc/unihtml/cli/cmd";func main (){_c .Execute ()}; \ No newline at end of file +package main ;import _ec "github.com/unidoc/unihtml/cli/cmd";func main (){_ec .Execute ()}; \ No newline at end of file diff --git a/client/client.go b/client/client.go index 16bf0cd..f2ae1f6 100644 --- a/client/client.go +++ b/client/client.go @@ -11,201 +11,202 @@ // Package client contains HTML Converter HTTP Client. The Client implements htmlcreator.HTMLConverter interface // for the UniPDF module and can be used as a plugin for the UniPDF creator.Creator. -package client ;import (_faf "bytes";_f "compress/flate";_fa "compress/gzip";_d "context";_e "encoding/json";_dc "errors";_ed "fmt";_dac "github.com/unidoc/unihtml/content";_bb "github.com/unidoc/unihtml/selector";_gc "github.com/unidoc/unihtml/sizes"; -_aa "github.com/unidoc/unipdf/v4/common";_a "io";_ae "net";_da "net/http";_bd "net/url";_af "strconv";_ff "strings";_b "time";); +package client ;import (_b "bytes";_ag "compress/flate";_aa "compress/gzip";_e "context";_g "encoding/json";_ee "errors";_eg "fmt";_be "github.com/unidoc/unihtml/content";_gf "github.com/unidoc/unihtml/selector";_dd "github.com/unidoc/unihtml/sizes";_dga "github.com/unidoc/unipdf/v4/common"; +_d "io";_gc "net";_ad "net/http";_eee "net/url";_bb "strconv";_dg "strings";_eb "time";); -// SetContent sets custom data with it's content type. -func (_cf *QueryBuilder )SetContent (content _dac .Content )*QueryBuilder {if _cf ._ddg !=nil {return _cf ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _cf ._bea .ContentType !=""{_cf ._ddg =ErrContentTypeDeclared ; -return _cf ;};if content .ContentType ()==""{_cf ._ddg =_ed .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _cf ;};_cf ._bea .Content =content .Data (); -_cf ._bea .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _cf ._bea .ContentType !=""{_cf ._ddg =ErrContentTypeDeclared ;return _cf ;};_cf ._bea .URL =string (content .Data ());_cf ._bea .ContentType =content .ContentType ();default:_cf ._ddg =_ed .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ()); -return _cf ;};_cf ._bea .Method =content .Method ();return _cf ;}; +// WithHostname sets the Hostname option for the client options. +func WithHostname (option string )Option {return func (_ba *Options ){_ba .Hostname =option }}; -// WithHTTPS sets the TLS option for the client options. -func WithHTTPS (useHTTPS bool )Option {return func (_daf *Options ){_daf .HTTPS =useHTTPS }}; +// BySelector is a structure that defines a selector with it's query 'by' type. +type BySelector struct{Selector string `json:"selector"`;By _gf .ByType `json:"by"`;}; -// Option is a function that changes client options. -type Option func (_ba *Options ); +// HealthCheck connects to the server and check the health status of the server. +func (_gcd *Client )HealthCheck (ctx _e .Context )error {_bd :=_gcd .Options .Addr ();_bd =_eg .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_bd );_c ,_ed :=_ad .NewRequest ("\u0047\u0045\u0054",_bd ,nil );if _ed !=nil {return _ed ;};_c =_c .WithContext (ctx ); +_ef ,_ed :=_gcd .Client .Do (_c );if _ed !=nil {return _ed ;};switch _ef .StatusCode {case _ad .StatusOK :return nil ;case _ad .StatusNotFound :return ErrNotFound ;case _ad .StatusInternalServerError :return ErrInternalError ;case _ad .StatusBadGateway :return ErrBadGateway ; +default:return ErrNotImplemented ;};}; // Validate checks if the QueryBuilder had no errors during composition and creation. -func (_abc *QueryBuilder )Validate ()error {if _abc ._ddg !=nil {return _abc ._ddg ;};return _abc ._bea .Validate ();};var (ErrNotFound =_dc .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_dc .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); -ErrNotImplemented =_dc .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_dc .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_dc .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079"); -ErrUnauthorized =_dc .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_dc .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); +func (_cfe *QueryBuilder )Validate ()error {if _cfe ._ge !=nil {return _cfe ._ge ;};return _cfe ._gfa .Validate ();}; -// Client is a structure that is a HTTP client for the unihtml server. -type Client struct{Options Options ;Client *_da .Client ;}; +// Addr gets the HTTP address URI used by the http.Client. +func (_gdc *Options )Addr ()string {_aga :=_dg .Builder {};_aga .WriteString ("\u0068\u0074\u0074\u0070");if _gdc .HTTPS {_aga .WriteRune ('s');};_aga .WriteString ("\u003a\u002f\u002f");_aga .WriteString (_gdc .Hostname );_aga .WriteRune (':');_aga .WriteString (_bb .Itoa (_gdc .Port )); +if _gdc .Prefix !=""{_aga .WriteString (_gdc .Prefix );};return _aga .String ();};func (_ae *Client )setQueryValues (_aac *_ad .Request ,_gdb *Query ){_gde :=_aac .URL .Query ();_egac :=_gdb .PageParameters ;if _egac .PageSize !=nil {_gde .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_egac .PageSize .String ()); +};if _egac .PaperHeight !=nil {_gde .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_egac .PaperHeight .String ());};if _egac .PaperWidth !=nil {_gde .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_egac .PaperWidth .String ()); +};if _egac .MarginTop !=nil {_gde .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_egac .MarginTop .String ());};if _egac .MarginBottom !=nil {_gde .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_egac .MarginBottom .String ()); +};if _egac .MarginRight !=nil {_gde .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_egac .MarginRight .String ());};if _egac .MarginLeft !=nil {_gde .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_egac .MarginLeft .String ()); +};if _egac .Orientation ==_dd .Landscape {_gde .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_egac .Orientation .String ());};if _gdb .RenderParameters .WaitTime !=0{_gde .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_bb .FormatInt (int64 (_gdb .RenderParameters .WaitTime /_eb .Millisecond ),10)); +};_aac .URL .RawQuery =_gde .Encode ();}; -// WaitTime sets the minimum load time parameter for the page rendering. -func (_fc *QueryBuilder )WaitTime (d _b .Duration )*QueryBuilder {_fc ._bea .RenderParameters .WaitTime =d ;return _fc ;}; +// MarginBottom sets up the MarginBottom parameter for the query. +func (_afc *QueryBuilder )MarginBottom (marginBottom _dd .Length )*QueryBuilder {_afc ._gfa .PageParameters .MarginBottom =marginBottom ;return _afc ;}; -// WithPort sets the Port option for the client options. -func WithPort (option int )Option {return func (_aea *Options ){_aea .Port =option }}; +// SetContent sets custom data with it's content type. +func (_dgad *QueryBuilder )SetContent (content _be .Content )*QueryBuilder {if _dgad ._ge !=nil {return _dgad ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _dgad ._gfa .ContentType !=""{_dgad ._ge =ErrContentTypeDeclared ; +return _dgad ;};if content .ContentType ()==""{_dgad ._ge =_eg .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _dgad ; +};_dgad ._gfa .Content =content .Data ();_dgad ._gfa .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _dgad ._gfa .ContentType !=""{_dgad ._ge =ErrContentTypeDeclared ;return _dgad ;};_dgad ._gfa .URL =string (content .Data ());_dgad ._gfa .ContentType =content .ContentType (); +default:_dgad ._ge =_eg .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ());return _dgad ;};_dgad ._gfa .Method =content .Method (); +return _dgad ;}; -// TimeoutDuration sets the server query duration timeout. -// Once the timeout is reached the server will return an error. -func (_ace *QueryBuilder )TimeoutDuration (d _b .Duration )*QueryBuilder {_ace ._bea .TimeoutDuration =d ;return _ace ;}; +// PageParameters are the query parameters used in the PDF generation. +type PageParameters struct{ -// Orientation sets the page orientation for the Query. -func (_fdb *QueryBuilder )Orientation (orientation _gc .Orientation )*QueryBuilder {_fdb ._bea .PageParameters .Orientation =orientation ;return _fdb ;}; +// PaperWidth sets the width of the paper. +PaperWidth _dd .Length `schema:"paper-width" json:"paperWidth"`; -// PaperWidth sets up the PaperWidth (in cm) parameter for the query. -func (_fdd *QueryBuilder )PaperWidth (paperWidth _gc .Length )*QueryBuilder {_fdd ._bea .PageParameters .PaperWidth =paperWidth ;return _fdd ;}; +// PaperHeight is the height of the output paper. +PaperHeight _dd .Length `schema:"paper-height" json:"paperHeight"`; -// DefaultPageParameters creates default parameters. -func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_gc .Portrait }}; +// PageSize is the page size string. +PageSize *_dd .PageSize `schema:"page-size" json:"pageSize"`; -// WithHostname sets the Hostname option for the client options. -func WithHostname (option string )Option {return func (_cef *Options ){_cef .Hostname =option }}; +// Orientation defines if the output should be in a landscape format. +Orientation _dd .Orientation `schema:"orientation" json:"orientation"`; -// Validate checks validity of the selector. -func (_cb BySelector )Validate ()error {if _cb .Selector ==""{return _dc .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _ec :=_cb .By .Validate ();_ec !=nil {return _ec ; -};return nil ;}; +// MarginTop sets up the Top Margin for the output. +MarginTop _dd .Length `schema:"margin-top" json:"marginTop"`; -// Validate checks the validity of the RenderParameters. -func (_ggf *RenderParameters )Validate ()error {if _ggf .WaitTime > _b .Minute *3{return _dc .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); -};for _ ,_fb :=range _ggf .WaitReady {if _afbb :=_fb .Validate ();_afbb !=nil {return _ed .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_afbb ); -};};return nil ;}; +// MarginBottom sets up the Bottom Margin for the output. +MarginBottom _dd .Length `schema:"margin-bottom" json:"marginBottom"`; -// RenderParameters are the parameters related with the rendering. -type RenderParameters struct{WaitTime _b .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; +// MarginLeft sets up the Left Margin for the output. +MarginLeft _dd .Length `schema:"margin-left" json:"marginLeft"`; -// WithPrefix sets the client prefix. -func WithPrefix (prefix string )Option {return func (_ede *Options ){_ede .Prefix =prefix }}; +// MarginRight sets up the Right Margin for the output. +MarginRight _dd .Length `schema:"margin-right" json:"marginRight"`;}; -// New creates new client with provided options. -func New (o Options )*Client {o .DefaultTimeout =_b .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _fe =&_da .Transport {DialContext :(&_ae .Dialer {Timeout :5*_b .Second }).DialContext ,TLSHandshakeTimeout :5*_b .Second }; -_aa .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_da .Client {Transport :_fe ,Timeout :o .DefaultTimeout }};}; +// Query gets the Query from provided query builder. If some error occurred during build process +// or the input is not valid the function would return an error. +func (_ege *QueryBuilder )Query ()(*Query ,error ){if _egd :=_ege .Validate ();_egd !=nil {return nil ,_egd ;};return &_ege ._gfa ,nil ;}; -// Landscape sets up the landscape portrait orientation. -func (_gbg *QueryBuilder )Landscape ()*QueryBuilder {_gbg ._bea .PageParameters .Orientation =_gc .Landscape ;return _gbg ;}; +// DefaultPageParameters creates default parameters. +func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_dd .Portrait }}; -// Validate checks if the parameters are valid. -func (_bbc *PageParameters )Validate ()error {if _bbc .PaperWidth !=nil {if _bbc .PaperWidth .Millimeters ()< 0{return _dc .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); -};};if _bbc .PaperHeight !=nil {if _bbc .PaperHeight .Millimeters ()< 0{return _dc .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); -};};if _bbc .MarginTop !=nil {if _bbc .MarginTop .Millimeters ()< 0{return _dc .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _bbc .MarginBottom !=nil {if _bbc .MarginBottom .Millimeters ()< 0{return _dc .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); -};};if _bbc .MarginLeft !=nil {if _bbc .MarginLeft .Millimeters ()< 0{return _dc .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");}; -};if _bbc .MarginRight !=nil {if _bbc .MarginRight .Millimeters ()< 0{return _dc .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); -};};if _bbc .PageSize !=nil &&!_bbc .PageSize .IsAPageSize (){return _dc .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; +// MarginLeft sets up the MarginLeft parameter for the query. +func (_fgg *QueryBuilder )MarginLeft (marginLeft _dd .Length )*QueryBuilder {_fgg ._gfa .PageParameters .MarginLeft =marginLeft ;return _fgg ;};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`; +Method string `json:"method"`;ExpiresAt int64 `json:"expiresAt"`;TimeoutDuration int64 `json:"timeoutDuration,omitempty"`;PageParameters ;RenderParameters ;}; -// BuildHTMLQuery creates a Query builder that is supposed to create valid -func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; +// WaitVisible waits for the selector to get visible. +func (_dbe *QueryBuilder )WaitVisible (selector string ,by _gf .ByType )*QueryBuilder {_dbe ._gfa .RenderParameters .WaitVisible =append (_dbe ._gfa .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _dbe ;}; -// PDFResponse is the response used by the HTMLConverter. -type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; +// Validate checks the validity of the RenderParameters. +func (_fg *RenderParameters )Validate ()error {if _fg .WaitTime > _eb .Minute *3{return _ee .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); +};for _ ,_bfd :=range _fg .WaitReady {if _gbc :=_bfd .Validate ();_gbc !=nil {return _eg .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_gbc ); +};};return nil ;}; -// WaitVisible waits for the selector to get visible. -func (_fcc *QueryBuilder )WaitVisible (selector string ,by _bb .ByType )*QueryBuilder {_fcc ._bea .RenderParameters .WaitVisible =append (_fcc ._bea .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _fcc ;}; +// Option is a function that changes client options. +type Option func (_ea *Options ); -// Addr gets the HTTP address URI used by the http.Client. -func (_bbb *Options )Addr ()string {_egf :=_ff .Builder {};_egf .WriteString ("\u0068\u0074\u0074\u0070");if _bbb .HTTPS {_egf .WriteRune ('s');};_egf .WriteString ("\u003a\u002f\u002f");_egf .WriteString (_bbb .Hostname );_egf .WriteRune (':');_egf .WriteString (_af .Itoa (_bbb .Port )); -if _bbb .Prefix !=""{_egf .WriteString (_bbb .Prefix );};return _egf .String ();}; +// ConvertHTML converts provided Query input into PDF file data. +// Implements creator.HTMLConverter interface. +func (_af *Client )ConvertHTML (ctx _e .Context ,q *Query )(*PDFResponse ,error ){if _db :=q .Validate ();_db !=nil {return nil ,_db ;};_ebc ,_bbf :=_af .getGenerateRequest (ctx ,q );if _bbf !=nil {return nil ,_bbf ;};_dga .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_ebc .Method ,_ebc .URL .Hostname (),_ebc .URL .Path ,_ebc .Header ,_ebc .URL .Query ()); +_eba :=*_af .Client ;if q .TimeoutDuration !=0{_eba .Timeout =q .TimeoutDuration ;};_ff ,_bbf :=_eba .Do (_ebc );if _bbf !=nil {return nil ,_bbf ;};var _ffe error ;switch _ff .StatusCode {case _ad .StatusNotFound :_ffe =ErrNotFound ;case _ad .StatusBadRequest :_ffe =ErrBadRequest ; +case _ad .StatusNotImplemented :_ffe =ErrNotImplemented ;case _ad .StatusUnauthorized :_ffe =ErrUnauthorized ;case _ad .StatusRequestTimeout :_ffe =ErrTimedOut ;case _ad .StatusCreated :default:_ffe =ErrInternalError ;};_cf :=_ff .Body ;switch _ff .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_cf ,_bbf =_aa .NewReader (_ff .Body ); +if _bbf !=nil {return nil ,_bbf ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_cf =_ag .NewReader (_ff .Body );case "":default:return nil ,_eg .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_ff .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); +};_ab ,_bbf :=_d .ReadAll (_cf );if _bbf !=nil &&_ffe ==nil {return nil ,_eg .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_bbf );};_dga .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_ff .StatusCode ,_ebc .Method ,_ebc .URL .Host ,_ebc .URL .Path ); +if _ffe !=nil {return nil ,_eg .Errorf ("\u0025\u0073\u0020%\u0077",string (_ab ),_ffe );};_eff :=_ff .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_dga .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_eff ); +return &PDFResponse {ID :_eff ,Data :_ab },nil ;}; -// BySelector is a structure that defines a selector with it's query 'by' type. -type BySelector struct{Selector string `json:"selector"`;By _bb .ByType `json:"by"`;}; +// Validate checks validity of the selector. +func (_ada BySelector )Validate ()error {if _ada .Selector ==""{return _ee .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _bf :=_ada .By .Validate ();_bf !=nil {return _bf ; +};return nil ;}; -// WithDefaultTimeout sets the DefaultTimeout option for the client options. -func WithDefaultTimeout (option _b .Duration )Option {return func (_egd *Options ){_egd .DefaultTimeout =option };}; +// Portrait sets up the portrait page orientation. +func (_fa *QueryBuilder )Portrait ()*QueryBuilder {_fa ._gfa .PageParameters .Orientation =_dd .Portrait ;return _fa ;}; -// QueryBuilder is the query that converts HTMLConverter defined data -type QueryBuilder struct{_bea Query ;_ddg error ;};func (_aaa *Client )getGenerateRequest (_gba _d .Context ,_gg *Query )(*_da .Request ,error ){_ce :=generatePDFRequestV1 {Method :_gg .Method ,PageParameters :_gg .PageParameters ,RenderParameters :_gg .RenderParameters ,TimeoutDuration :int64 (_gg .TimeoutDuration )}; -switch _gg .Method {case "\u0077\u0065\u0062":_ce .ContentURL =_gg .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_ce .ContentType =_gg .ContentType ;_ce .Content =_gg .Content ;};_gge :=new (_faf .Buffer );if _bee :=_e .NewEncoder (_gge ).Encode (&_ce ); -_bee !=nil {return nil ,_ed .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_bee );};_beeb :=_aaa .Options .Addr ();_beeb =_ed .Sprintf ("\u0025s\u002f\u0076\u0031\u002f\u0070\u0064f",_beeb ); -_fad ,_ea :=_da .NewRequest ("\u0050\u004f\u0053\u0054",_beeb ,_gge );if _ea !=nil {return nil ,_ea ;};_fad .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); -_fad .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); -_fad =_fad .WithContext (_gba );return _fad ,nil ;}; +// PaperHeight sets up the PaperHeight (in cm) parameter for the query. +func (_cd *QueryBuilder )PaperHeight (paperHeight _dd .Length )*QueryBuilder {_cd ._gfa .PageParameters .PaperHeight =paperHeight ;return _cd ;};var (ErrNotFound =_ee .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_ee .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); +ErrNotImplemented =_ee .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_ee .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_ee .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079"); +ErrUnauthorized =_ee .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_ee .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); -// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. -type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;TimeoutDuration _b .Duration ;}; +// Options are the client options used by the HTTP client. +type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _eb .Duration ;Prefix string ;}; -// MarginRight sets up the MarginRight parameter for the query. -func (_aeag *QueryBuilder )MarginRight (marginRight _gc .Length )*QueryBuilder {_aeag ._bea .PageParameters .MarginRight =marginRight ;return _aeag ;}; +// Orientation sets the page orientation for the Query. +func (_abg *QueryBuilder )Orientation (orientation _dd .Orientation )*QueryBuilder {_abg ._gfa .PageParameters .Orientation =orientation ;return _abg ;}; -// Err gets the error which could occur in the query. -func (_bbbe *QueryBuilder )Err ()error {return _bbbe ._ddg }; +// BuildHTMLQuery creates a Query builder that is supposed to create valid +func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; -// Query gets the Query from provided query builder. If some error occurred during build process -// or the input is not valid the function would return an error. -func (_aba *QueryBuilder )Query ()(*Query ,error ){if _dfc :=_aba .Validate ();_dfc !=nil {return nil ,_dfc ;};return &_aba ._bea ,nil ;};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`; -Method string `json:"method"`;ExpiresAt int64 `json:"expiresAt"`;TimeoutDuration int64 `json:"timeoutDuration,omitempty"`;PageParameters ;RenderParameters ;}; +// Validate checks if provided Query is valid. +func (_ffa *Query )Validate ()error {switch _ffa .Method {case "\u0077\u0065\u0062":if _ffa .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_ffa .Content )==0{return ErrMissingData ;};if _ffa .ContentType ==""{return ErrContentType ; +};default:return _eg .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_ffa .Method );};if _cg :=_ffa .PageParameters .Validate (); +_cg !=nil {return _cg ;};if _bff :=_ffa .RenderParameters .Validate ();_bff !=nil {return _bff ;};return nil ;}; -// PageParameters are the query parameters used in the PDF generation. -type PageParameters struct{ +// New creates new client with provided options. +func New (o Options )*Client {o .DefaultTimeout =_eb .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _ega =&_ad .Transport {DialContext :(&_gc .Dialer {Timeout :5*_eb .Second }).DialContext ,TLSHandshakeTimeout :5*_eb .Second }; +_dga .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_ad .Client {Transport :_ega ,Timeout :o .DefaultTimeout }};}; -// PaperWidth sets the width of the paper. -PaperWidth _gc .Length `schema:"paper-width" json:"paperWidth"`; +// RenderParameters are the parameters related with the rendering. +type RenderParameters struct{WaitTime _eb .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; -// PaperHeight is the height of the output paper. -PaperHeight _gc .Length `schema:"paper-height" json:"paperHeight"`; +// PaperWidth sets up the PaperWidth (in cm) parameter for the query. +func (_bfg *QueryBuilder )PaperWidth (paperWidth _dd .Length )*QueryBuilder {_bfg ._gfa .PageParameters .PaperWidth =paperWidth ;return _bfg ;};var (ErrMissingData =_ee .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061"); +ErrContentType =_ee .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065");ErrContentTypeDeclared =_ee .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064"); +); -// PageSize is the page size string. -PageSize *_gc .PageSize `schema:"page-size" json:"pageSize"`; +// PageSize sets up the PageSize parameter for the query. +func (_afb *QueryBuilder )PageSize (pageSize _dd .PageSize )*QueryBuilder {if pageSize !=_dd .Undefined {_afb ._gfa .PageParameters .PageSize =&pageSize ;};return _afb ;}; -// Orientation defines if the output should be in a landscape format. -Orientation _gc .Orientation `schema:"orientation" json:"orientation"`; +// WithPort sets the Port option for the client options. +func WithPort (option int )Option {return func (_dc *Options ){_dc .Port =option }}; -// MarginTop sets up the Top Margin for the output. -MarginTop _gc .Length `schema:"margin-top" json:"marginTop"`; +// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. +type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;TimeoutDuration _eb .Duration ;}; -// MarginBottom sets up the Bottom Margin for the output. -MarginBottom _gc .Length `schema:"margin-bottom" json:"marginBottom"`; +// WaitTime sets the minimum load time parameter for the page rendering. +func (_edf *QueryBuilder )WaitTime (d _eb .Duration )*QueryBuilder {_edf ._gfa .RenderParameters .WaitTime =d ;return _edf ;}; -// MarginLeft sets up the Left Margin for the output. -MarginLeft _gc .Length `schema:"margin-left" json:"marginLeft"`; +// WaitReady waits for the selector to get ready - 'loaded'. +func (_badc *QueryBuilder )WaitReady (selector string ,by _gf .ByType )*QueryBuilder {_badc ._gfa .RenderParameters .WaitReady =append (_badc ._gfa .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _badc ;};func (_fd *Client )getGenerateRequest (_gb _e .Context ,_fe *Query )(*_ad .Request ,error ){_bdg :=generatePDFRequestV1 {Method :_fe .Method ,PageParameters :_fe .PageParameters ,RenderParameters :_fe .RenderParameters ,TimeoutDuration :int64 (_fe .TimeoutDuration )}; +switch _fe .Method {case "\u0077\u0065\u0062":_bdg .ContentURL =_fe .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_bdg .ContentType =_fe .ContentType ;_bdg .Content =_fe .Content ;};_abe :=new (_b .Buffer );if _ce :=_g .NewEncoder (_abe ).Encode (&_bdg ); +_ce !=nil {return nil ,_eg .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_ce );};_beg :=_fd .Options .Addr ();_beg =_eg .Sprintf ("\u0025s\u002f\u0076\u0031\u002f\u0070\u0064f",_beg ); +_ca ,_bbg :=_ad .NewRequest ("\u0050\u004f\u0053\u0054",_beg ,_abe );if _bbg !=nil {return nil ,_bbg ;};_ca .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); +_ca .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); +_ca =_ca .WithContext (_gb );return _ca ,nil ;}; -// MarginRight sets up the Right Margin for the output. -MarginRight _gc .Length `schema:"margin-right" json:"marginRight"`;}; +// Validate checks if the parameters are valid. +func (_da *PageParameters )Validate ()error {if _da .PaperWidth !=nil {if _da .PaperWidth .Millimeters ()< 0{return _ee .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); +};};if _da .PaperHeight !=nil {if _da .PaperHeight .Millimeters ()< 0{return _ee .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); +};};if _da .MarginTop !=nil {if _da .MarginTop .Millimeters ()< 0{return _ee .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _da .MarginBottom !=nil {if _da .MarginBottom .Millimeters ()< 0{return _ee .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); +};};if _da .MarginLeft !=nil {if _da .MarginLeft .Millimeters ()< 0{return _ee .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};}; +if _da .MarginRight !=nil {if _da .MarginRight .Millimeters ()< 0{return _ee .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); +};};if _da .PageSize !=nil &&!_da .PageSize .IsAPageSize (){return _ee .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; -// MarginBottom sets up the MarginBottom parameter for the query. -func (_afd *QueryBuilder )MarginBottom (marginBottom _gc .Length )*QueryBuilder {_afd ._bea .PageParameters .MarginBottom =marginBottom ;return _afd ;}; +// QueryBuilder is the query that converts HTMLConverter defined data +type QueryBuilder struct{_gfa Query ;_ge error ;}; -// Validate checks if provided Query is valid. -func (_df *Query )Validate ()error {switch _df .Method {case "\u0077\u0065\u0062":if _df .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_df .Content )==0{return ErrMissingData ;};if _df .ContentType ==""{return ErrContentType ; -};default:return _ed .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_df .Method );};if _beg :=_df .PageParameters .Validate (); -_beg !=nil {return _beg ;};if _cc :=_df .RenderParameters .Validate ();_cc !=nil {return _cc ;};return nil ;};func (_bde *Client )setQueryValues (_cdc *_da .Request ,_bba *Query ){_db :=_cdc .URL .Query ();_eg :=_bba .PageParameters ;if _eg .PageSize !=nil {_db .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_eg .PageSize .String ()); -};if _eg .PaperHeight !=nil {_db .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_eg .PaperHeight .String ());};if _eg .PaperWidth !=nil {_db .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_eg .PaperWidth .String ()); -};if _eg .MarginTop !=nil {_db .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_eg .MarginTop .String ());};if _eg .MarginBottom !=nil {_db .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_eg .MarginBottom .String ()); -};if _eg .MarginRight !=nil {_db .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_eg .MarginRight .String ());};if _eg .MarginLeft !=nil {_db .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_eg .MarginLeft .String ()); -};if _eg .Orientation ==_gc .Landscape {_db .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_eg .Orientation .String ());};if _bba .RenderParameters .WaitTime !=0{_db .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_af .FormatInt (int64 (_bba .RenderParameters .WaitTime /_b .Millisecond ),10)); -};_cdc .URL .RawQuery =_db .Encode ();}; +// PDFResponse is the response used by the HTMLConverter. +type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; -// Options are the client options used by the HTTP client. -type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _b .Duration ;Prefix string ;}; +// ParseOptions parses options for the Client. +func ParseOptions (connectPath string )(Options ,error ){if !_dg .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_f ,_gd :=_eee .Parse (connectPath );if _gd !=nil {return Options {},_eg .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); +};var _gg int ;if _f .Port ()!=""{_gg ,_gd =_bb .Atoi (_f .Port ());if _gd !=nil {return Options {},_eg .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_gd );}; +};return Options {Hostname :_f .Hostname (),Port :_gg ,HTTPS :_f .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_f .Path },nil ;}; -// MarginLeft sets up the MarginLeft parameter for the query. -func (_ac *QueryBuilder )MarginLeft (marginLeft _gc .Length )*QueryBuilder {_ac ._bea .PageParameters .MarginLeft =marginLeft ;return _ac ;};var (ErrMissingData =_dc .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061"); -ErrContentType =_dc .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065");ErrContentTypeDeclared =_dc .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064"); -); +// MarginTop sets up the MarginTop parameter for the query. +func (_bdb *QueryBuilder )MarginTop (marginTop _dd .Length )*QueryBuilder {_bdb ._gfa .PageParameters .MarginTop =marginTop ;return _bdb ;}; -// PaperHeight sets up the PaperHeight (in cm) parameter for the query. -func (_cda *QueryBuilder )PaperHeight (paperHeight _gc .Length )*QueryBuilder {_cda ._bea .PageParameters .PaperHeight =paperHeight ;return _cda ;}; +// MarginRight sets up the MarginRight parameter for the query. +func (_efc *QueryBuilder )MarginRight (marginRight _dd .Length )*QueryBuilder {_efc ._gfa .PageParameters .MarginRight =marginRight ;return _efc ;}; -// ConvertHTML converts provided Query input into PDF file data. -// Implements creator.HTMLConverter interface. -func (_ad *Client )ConvertHTML (ctx _d .Context ,q *Query )(*PDFResponse ,error ){if _be :=q .Validate ();_be !=nil {return nil ,_be ;};_fd ,_de :=_ad .getGenerateRequest (ctx ,q );if _de !=nil {return nil ,_de ;};_aa .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_fd .Method ,_fd .URL .Hostname (),_fd .URL .Path ,_fd .Header ,_fd .URL .Query ()); -_gd :=*_ad .Client ;if q .TimeoutDuration !=0{_gd .Timeout =q .TimeoutDuration ;};_dd ,_de :=_gd .Do (_fd );if _de !=nil {return nil ,_de ;};var _afb error ;switch _dd .StatusCode {case _da .StatusNotFound :_afb =ErrNotFound ;case _da .StatusBadRequest :_afb =ErrBadRequest ; -case _da .StatusNotImplemented :_afb =ErrNotImplemented ;case _da .StatusUnauthorized :_afb =ErrUnauthorized ;case _da .StatusRequestTimeout :_afb =ErrTimedOut ;case _da .StatusCreated :default:_afb =ErrInternalError ;};_ab :=_dd .Body ;switch _dd .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_ab ,_de =_fa .NewReader (_dd .Body ); -if _de !=nil {return nil ,_de ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_ab =_f .NewReader (_dd .Body );case "":default:return nil ,_ed .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_dd .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); -};_feb ,_de :=_a .ReadAll (_ab );if _de !=nil &&_afb ==nil {return nil ,_ed .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_de );};_aa .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_dd .StatusCode ,_fd .Method ,_fd .URL .Host ,_fd .URL .Path ); -if _afb !=nil {return nil ,_ed .Errorf ("\u0025\u0073\u0020%\u0077",string (_feb ),_afb );};_eea :=_dd .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_aa .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_eea ); -return &PDFResponse {ID :_eea ,Data :_feb },nil ;}; +// WithDefaultTimeout sets the DefaultTimeout option for the client options. +func WithDefaultTimeout (option _eb .Duration )Option {return func (_bad *Options ){_bad .DefaultTimeout =option };}; -// WaitReady waits for the selector to get ready - 'loaded'. -func (_dacf *QueryBuilder )WaitReady (selector string ,by _bb .ByType )*QueryBuilder {_dacf ._bea .RenderParameters .WaitReady =append (_dacf ._bea .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _dacf ;}; +// WithHTTPS sets the TLS option for the client options. +func WithHTTPS (useHTTPS bool )Option {return func (_ggb *Options ){_ggb .HTTPS =useHTTPS }}; -// Portrait sets up the portrait page orientation. -func (_fff *QueryBuilder )Portrait ()*QueryBuilder {_fff ._bea .PageParameters .Orientation =_gc .Portrait ;return _fff ;}; +// Landscape sets up the landscape portrait orientation. +func (_de *QueryBuilder )Landscape ()*QueryBuilder {_de ._gfa .PageParameters .Orientation =_dd .Landscape ;return _de ;}; -// PageSize sets up the PageSize parameter for the query. -func (_ege *QueryBuilder )PageSize (pageSize _gc .PageSize )*QueryBuilder {if pageSize !=_gc .Undefined {_ege ._bea .PageParameters .PageSize =&pageSize ;};return _ege ;}; +// TimeoutDuration sets the server query duration timeout. +// Once the timeout is reached the server will return an error. +func (_aef *QueryBuilder )TimeoutDuration (d _eb .Duration )*QueryBuilder {_aef ._gfa .TimeoutDuration =d ;return _aef ;}; -// MarginTop sets up the MarginTop parameter for the query. -func (_ddd *QueryBuilder )MarginTop (marginTop _gc .Length )*QueryBuilder {_ddd ._bea .PageParameters .MarginTop =marginTop ;return _ddd ;}; +// Client is a structure that is a HTTP client for the unihtml server. +type Client struct{Options Options ;Client *_ad .Client ;}; -// HealthCheck connects to the server and check the health status of the server. -func (_cde *Client )HealthCheck (ctx _d .Context )error {_ffb :=_cde .Options .Addr ();_ffb =_ed .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_ffb );_dg ,_fg :=_da .NewRequest ("\u0047\u0045\u0054",_ffb ,nil );if _fg !=nil {return _fg ;};_dg =_dg .WithContext (ctx ); -_gb ,_fg :=_cde .Client .Do (_dg );if _fg !=nil {return _fg ;};switch _gb .StatusCode {case _da .StatusOK :return nil ;case _da .StatusNotFound :return ErrNotFound ;case _da .StatusInternalServerError :return ErrInternalError ;case _da .StatusBadGateway :return ErrBadGateway ; -default:return ErrNotImplemented ;};}; +// Err gets the error which could occur in the query. +func (_adg *QueryBuilder )Err ()error {return _adg ._ge }; -// ParseOptions parses options for the Client. -func ParseOptions (connectPath string )(Options ,error ){if !_ff .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_c ,_cd :=_bd .Parse (connectPath );if _cd !=nil {return Options {},_ed .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); -};var _ee int ;if _c .Port ()!=""{_ee ,_cd =_af .Atoi (_c .Port ());if _cd !=nil {return Options {},_ed .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_cd );}; -};return Options {Hostname :_c .Hostname (),Port :_ee ,HTTPS :_c .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_c .Path },nil ;}; \ No newline at end of file +// WithPrefix sets the client prefix. +func WithPrefix (prefix string )Option {return func (_aad *Options ){_aad .Prefix =prefix }}; \ No newline at end of file diff --git a/common/common.go b/common/common.go index 824c89f..f6ccc7c 100644 --- a/common/common.go +++ b/common/common.go @@ -10,8 +10,8 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package common contains common properties used by the subpackages. -package common ;import _f "time";const Version ="\u0030\u002e\u0031\u0032\u002e\u0030";const _gd =20;const _b =12;const _c ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034"; -var ReleasedAt =_f .Date (_g ,_e ,_ab ,_b ,_gd ,0,0,_f .UTC ); +package common ;import _b "time";const _ee =12;const _f =5; // UtcTimeFormat returns a formatted string describing a UTC timestamp. -func UtcTimeFormat (t _f .Time )string {return t .Format (_c )+"\u0020\u0055\u0054\u0043"};const _g =2025;const _ab =12;const _e =5; \ No newline at end of file +func UtcTimeFormat (t _b .Time )string {return t .Format (_e )+"\u0020\u0055\u0054\u0043"};var ReleasedAt =_b .Date (_d ,_f ,_dg ,_ee ,_be ,0,0,_b .UTC );const _be =20;const _dg =26;const _e ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034"; +const Version ="\u0030\u002e\u0031\u0033\u002e\u0030";const _d =2025; \ No newline at end of file diff --git a/content/content.go b/content/content.go index 1c0d70b..a7b8caf 100644 --- a/content/content.go +++ b/content/content.go @@ -9,64 +9,63 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package content ;import (_dc "archive/zip";_b "bytes";_e "fmt";_ga "net/url";_df "os";_g "strings";); - -// NewWebURL creates new Content webURL for provided input URL path. -func NewWebURL (path string )(Content ,error ){if _ ,_dcf :=_ga .Parse (path );_dcf !=nil {return nil ,_dcf ;};return &webURL {_cb :path },nil ;}; +package content ;import (_ea "archive/zip";_d "bytes";_fa "fmt";_ec "net/url";_fg "os";_f "strings";); // ContentType implements Content interface. -func (_dea *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; - -// Content is an interface used for putting the content into Client Query. -type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;}; - -// Data implements Content interface. -func (_gef *StringContent )Data ()[]byte {return []byte (_gef ._ae )}; +func (_fe *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; // ContentType implements Content interface. -func (_ac *StringContent )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; +func (_cg *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";};type htmlFile struct{_c _d .Buffer }; -// Data implements Content interface. -func (_gd *webURL )Data ()[]byte {return []byte (_gd ._cb )}; +// Method implements Content interface. +func (_gce *StringContent )Method ()string {return "\u0068\u0074\u006d\u006c"}; -// Data implements Content interface. -func (_ca *htmlFile )Data ()[]byte {return _ca ._bc .Bytes ()};type htmlFile struct{_bc _b .Buffer };func (_bg *zipDirectory )zipPath (_gf ,_eg string )error {_bfa ,_bfdb :=_df .ReadDir (_gf );if _bfdb !=nil {return _e .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_gf ,_bfdb ); -};_gfg :=&_g .Builder {};for _ ,_bcb :=range _bfa {_db ,_aa :=_bcb .Info ();if _aa !=nil {return _aa ;};_aaf ,_fge :=_bg .zipBasePaths (_db ,_gf ,_eg ,_bcb .IsDir (),_gfg );if _bcb .IsDir (){if _ge :=_bg .zipPath (_aaf ,_fge );_ge !=nil {return _ge ;}; -continue ;};_fb ,_aa :=_df .ReadFile (_aaf );if _aa !=nil {return _aa ;};_ebe ,_aa :=_bg ._a .Create (_fge );if _aa !=nil {return _aa ;};if _ ,_aa =_ebe .Write (_fb );_aa !=nil {return _aa ;};};return nil ;}; +// Method gets the web url query method. +func (_ff *webURL )Method ()string {return "\u0077\u0065\u0062"};type webURL struct{_ee string }; -// Data implements Content interface. -func (_ebf *zipDirectory )Data ()[]byte {return _ebf ._gae .Bytes ()}; +// NewWebURL creates new Content webURL for provided input URL path. +func NewWebURL (path string )(Content ,error ){if _ ,_dd :=_ec .Parse (path );_dd !=nil {return nil ,_dd ;};return &webURL {_ee :path },nil ;}; -// Method gets the web url query method. -func (_eb *webURL )Method ()string {return "\u0077\u0065\u0062"}; +// Content is an interface used for putting the content into Client Query. +type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;}; -// StringContent implements Content interface for an HTML string. -type StringContent struct{_ae string }; +// ContentType implements Content interface. +func (_ca *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"};func (_ge *zipDirectory )zipPath (_gd ,_gc string )error {_egf ,_gbg :=_fg .ReadDir (_gd );if _gbg !=nil {return _fa .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_gd ,_gbg ); +};_dde :=&_f .Builder {};for _ ,_fc :=range _egf {_ae ,_bg :=_fc .Info ();if _bg !=nil {return _bg ;};_fb ,_ed :=_ge .zipBasePaths (_ae ,_gd ,_gc ,_fc .IsDir (),_dde );if _fc .IsDir (){if _bf :=_ge .zipPath (_fb ,_ed );_bf !=nil {return _bf ;};continue ; +};_dab ,_bg :=_fg .ReadFile (_fb );if _bg !=nil {return _bg ;};_fce ,_bg :=_ge ._gb .Create (_ed );if _bg !=nil {return _bg ;};if _ ,_bg =_fce .Write (_dab );_bg !=nil {return _bg ;};};return nil ;}; // NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' // and stores in it's in-memory buffer. -func NewZipDirectory (dirPath string )(Content ,error ){_bcc :=&zipDirectory {_gae :_b .Buffer {}};_bcc ._a =_dc .NewWriter (&_bcc ._gae );if _gac :=_bcc .zipPath (dirPath ,"");_gac !=nil {return nil ,_gac ;};if _ad :=_bcc ._a .Close ();_ad !=nil {return nil ,_ad ; -};return _bcc ,nil ;}; +func NewZipDirectory (dirPath string )(Content ,error ){_db :=&zipDirectory {_cb :_d .Buffer {}};_db ._gb =_ea .NewWriter (&_db ._cb );if _cag :=_db .zipPath (dirPath ,"");_cag !=nil {return nil ,_cag ;};if _de :=_db ._gb .Close ();_de !=nil {return nil ,_de ; +};return _db ,nil ;}; -// NewHTMLFile creates new Content htmFile for provided input path. -func NewHTMLFile (path string )(Content ,error ){_de ,_ea :=_df .Open (path );if _ea !=nil {return nil ,_ea ;};_bf :=&htmlFile {_bc :_b .Buffer {}};if _ ,_ea =_bf ._bc .ReadFrom (_de );_ea !=nil {return nil ,_ea ;};return _bf ,nil ;}; +// Data implements Content interface. +func (_b *htmlFile )Data ()[]byte {return _b ._c .Bytes ()}; + +// NewStringContent creates a new StringContent. +func NewStringContent (html string )(*StringContent ,error ){return &StringContent {_faa :html },nil }; // Method gets the query method. -func (_f *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"};type zipDirectory struct{_gae _b .Buffer ;_a *_dc .Writer ;}; +func (_g *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"}; -// ContentType implements Content interface. -func (_bfd *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"};func (_fa *zipDirectory )zipBasePaths (_eaf _df .FileInfo ,_dfa ,_cc string ,_ce bool ,_be *_g .Builder )(string ,string ){_be .WriteString (_dfa );if !_g .HasSuffix (_dfa ,"\u002f"){_be .WriteRune ('/'); -};_be .WriteString (_eaf .Name ());if _ce {_be .WriteRune ('/');};_faa :=_be .String ();_be .Reset ();_be .WriteString (_cc );_be .WriteString (_eaf .Name ());if _ce {_be .WriteRune ('/');};_ag :=_be .String ();_be .Reset ();return _faa ,_ag ;};type webURL struct{_cb string }; +// StringContent implements Content interface for an HTML string. +type StringContent struct{_faa string };type zipDirectory struct{_cb _d .Buffer ;_gb *_ea .Writer ;};func (_cgc *zipDirectory )zipBasePaths (_fgf _fg .FileInfo ,_bfc ,_dc string ,_ac bool ,_cd *_f .Builder )(string ,string ){_cd .WriteString (_bfc );if !_f .HasSuffix (_bfc ,"\u002f"){_cd .WriteRune ('/'); +};_cd .WriteString (_fgf .Name ());if _ac {_cd .WriteRune ('/');};_ce :=_cd .String ();_cd .Reset ();_cd .WriteString (_dc );_cd .WriteString (_fgf .Name ());if _ac {_cd .WriteRune ('/');};_aec :=_cd .String ();_cd .Reset ();return _ce ,_aec ;}; +// Data implements Content interface. +func (_ag *webURL )Data ()[]byte {return []byte (_ag ._ee )}; // ContentType implements Content interface. -func (_dfb *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; +func (_eb *StringContent )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; -// NewStringContent creates a new StringContent. -func NewStringContent (html string )(*StringContent ,error ){return &StringContent {_ae :html },nil }; +// Method gets the zip directory method. +func (_eg *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; -// Method implements Content interface. -func (_bd *StringContent )Method ()string {return "\u0068\u0074\u006d\u006c"}; +// NewHTMLFile creates new Content htmFile for provided input path. +func NewHTMLFile (path string )(Content ,error ){_a ,_dg :=_fg .Open (path );if _dg !=nil {return nil ,_dg ;};_cf :=&htmlFile {_c :_d .Buffer {}};if _ ,_dg =_cf ._c .ReadFrom (_a );_dg !=nil {return nil ,_dg ;};return _cf ,nil ;}; -// Method gets the zip directory method. -func (_bb *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; \ No newline at end of file +// Data implements Content interface. +func (_abd *zipDirectory )Data ()[]byte {return _abd ._cb .Bytes ()}; + +// Data implements Content interface. +func (_fab *StringContent )Data ()[]byte {return []byte (_fab ._faa )}; \ No newline at end of file diff --git a/selector/selector.go b/selector/selector.go index d204a37..926a018 100644 --- a/selector/selector.go +++ b/selector/selector.go @@ -9,11 +9,10 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package selector ;import _b "errors"; +package selector ;import _g "errors";const (ByUndefined ByType =iota ;ByID ;ByQueryAll ;ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); // ByType is a 'By' selector type enumerator. type ByType uint ; // Validate checks validity of the ByType. -func (_g ByType )Validate ()error {if _g >=ByID &&_g <=BySearch {return nil ;};return _b .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};const (ByUndefined ByType =iota ;ByID ;ByQueryAll ; -ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); \ No newline at end of file +func (_gf ByType )Validate ()error {if _gf >=ByID &&_gf <=BySearch {return nil ;};return _g .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");}; \ No newline at end of file diff --git a/sizes/sizes.go b/sizes/sizes.go index fd0e090..af90983 100644 --- a/sizes/sizes.go +++ b/sizes/sizes.go @@ -12,190 +12,191 @@ // Package sizes defines basic types that determines the size units i.e. lengths. // // -package sizes ;import (_f "encoding/json";_ag "flag";_ae "fmt";_b "strconv";_e "strings";); +package sizes ;import (_f "encoding/json";_c "flag";_e "fmt";_d "strconv";_af "strings";); -// MarshalJSON implements json.Marshaler interface -func (_cda Millimeter )MarshalJSON ()([]byte ,error ){return _fda (_cda )};var (_ Length =Millimeter (0);); - -// Inches gets the inch value. Implements Length interface. -func (_da Inch )Inches ()Inch {return _da }; - -// Name implements viper.FlagValue interface. -func (_ecf Point )Name ()string {return "\u0070\u006f\u0069n\u0074"};const (Portrait =Orientation (false );Landscape =Orientation (true );); +// String implements fmt.Stringer interface. +func (_aed Millimeter )String ()string {_ba :=_af .Builder {};_ba .WriteString (_d .FormatFloat (float64 (_aed ),'f',1,64));_ba .WriteString ("\u006d\u006d");return _ba .String ();}; -// MarshalPageSize marshals the page size into string. -func MarshalPageSize (p PageSize )(string ,error ){_eag ,_db :=p .MarshalText ();if _db !=nil {return "",_db ;};return string (_eag ),nil ;};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ; -B9 ;B10 ;Letter ;); +// Set implements flag.Value interface. +func (_afe *Point )Set (s string )error {_ec ,_cb :=_d .ParseFloat (s ,64);if _cb !=nil {return _e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_cb );};*_afe =Point (_ec ); +return nil ;}; // Type implements pflag.Value interface. -func (_ceg Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; +func (_cf Inch )Type ()string {return "\u0069\u006e\u0063\u0068"};var _bdc =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; + +// Inch is a unit that +type Inch float64 ; // LengthFlag is a pflag wrapper for the Length value. -type LengthFlag struct{Length Length ;};const _cdaa ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; +type LengthFlag struct{Length Length ;};var _cdc =map[string ]PageSize {_bgc [0:9]:0,_bgc [9:11]:1,_bgc [11:13]:2,_bgc [13:15]:3,_bgc [15:17]:4,_bgc [17:19]:5,_bgc [19:21]:6,_bgc [21:23]:7,_bgc [23:25]:8,_bgc [25:27]:9,_bgc [27:29]:10,_bgc [29:32]:11,_bgc [32:34]:12,_bgc [34:36]:13,_bgc [36:38]:14,_bgc [38:40]:15,_bgc [40:42]:16,_bgc [42:44]:17,_bgc [44:46]:18,_bgc [46:48]:19,_bgc [48:50]:20,_bgc [50:52]:21,_bgc [52:55]:22,_bgc [55:61]:23}; // Millimeters gets the float64 millimeter value. -func (_dgc Millimeter )Millimeters ()Millimeter {return _dgc }; +func (_gg Millimeter )Millimeters ()Millimeter {return _gg }; // Name implements pflag.Value interface. -func (_be Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; - -// Set implements pflag.Value interface. -func (_fd *Inch )Set (s string )error {_fdf ,_aec :=_b .ParseFloat (s ,64);if _aec !=nil {return _ae .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_aec );};*_fd =Inch (_fdf ); -return nil ;}; +func (_gfa Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; -// String implements fmt.Stringer interface. -func (_ga Inch )String ()string {_df :=_e .Builder {};_df .WriteString (_b .FormatFloat (float64 (_ga ),'f',1,64));_df .WriteString ("\u0069\u006e");return _df .String ();}; - -// Length is it the default dimension unit. -type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; +// Type implements pflag.Value interface. +func (_gfd Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; -// Millimeters converts the inches value to the millimeters. -func (_fde Inch )Millimeters ()Millimeter {return Millimeter (float64 (_fde )*_d )};var _ _ag .Value =(*Point )(nil ); +// Name implements viper.FlagValue interface. +func (_cd Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; -// Set implements flag.Value interface. -func (_cb *Point )Set (s string )error {_bb ,_gf :=_b .ParseFloat (s ,64);if _gf !=nil {return _ae .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_gf );};*_cb =Point (_bb ); -return nil ;};var _ _ag .Value =(*Orientation )(nil ); +// ValueString implements pflag.Value interface. +func (_gfg Inch )ValueString ()string {return _gfg .String ()}; -// Inch is a unit that -type Inch float64 ; +// Point is a unit of Length commonly used to measure the height of fonts. +type Point float64 ;const (_fe =float64 (1)/float64 (25.4);_da =25.4;_cc =0.0139;_fd =0.3528;_b =1.0/64;_ad =1.0/_fd ;); -// ValueType implements pflag.Value interface. -func (_ec Inch )ValueType ()string {return _ec .Type ()}; +// Millimeters converts the inches value to the millimeters. +func (_bg Point )Millimeters ()Millimeter {return Millimeter (float64 (_bg )*_fd )};var _ _c .Value =(*Point )(nil );func _dca (_fbc string )(Point ,error ){_fbc =_af .TrimSpace (_af .Trim (_fbc ,"\u0070\u0074"));_bf ,_ade :=_d .ParseFloat (_fbc ,64);if _ade !=nil {return 0,_ade ; +};return Point (_bf ),nil ;};var _cee =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; // Points implements Length interface. -func (_ge Millimeter )Points ()Point {return Point (_ge *_ab )}; +func (_dcc Inch )Points ()Point {return Point (float64 (_dcc )*_b )}; -// MarshalJSON implements json.Marshaler interface -func (_ea Inch )MarshalJSON ()([]byte ,error ){return _fda (_ea )}; +// HasChanged implements viper.FlagValue interface. +func (_gfb *Point )HasChanged ()bool {return _gfb !=nil }; -// Set implements flag.Value interface. -func (_baf *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_baf =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_baf =Landscape ;default:return _ae .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); -};return nil ;}; +// String implements fmt.Stringer interface. +func (_aaf Orientation )String ()string {if _aaf ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; -// String gets the string value for given flag. -func (_ba *LengthFlag )String ()string {if _ba .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _ba .Length .String ();};func (_fba PageSize )String ()string {if _fba < 0||_fba >=PageSize (len (_ed )-1){return _ae .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_fba ); -};return _cdaa [_ed [_fba ]:_ed [_fba +1]];}; +// Set implements pflag.Value interface. +func (_dc *Inch )Set (s string )error {_bd ,_cg :=_d .ParseFloat (s ,64);if _cg !=nil {return _e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_cg );};*_dc =Inch (_bd ); +return nil ;}; -// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize -func (_cdgg *PageSize )UnmarshalText (text []byte )error {var _cde error ;*_cdgg ,_cde =PageSizeString (string (text ));return _cde ;};var _gc =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; +// Set implements pflag.Value interface. +func (_edc *PageSize )Set (s string )error {_adf ,_dgf :=UnmarshalPageSize (s );if _dgf !=nil {return _dgf ;};*_edc =_adf ;return nil ;};func _cac (_ed string )(Inch ,error ){_ed =_af .TrimSpace (_af .Trim (_ed ,"\u0069\u006e"));_ecg ,_add :=_d .ParseFloat (_ed ,64); +if _add !=nil {return 0,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_add );};return Inch (_ecg ),nil ;};const (Portrait =Orientation (false );Landscape =Orientation (true ); +); -// Points implements Length interface. -func (_baa Inch )Points ()Point {return Point (float64 (_baa )*_c )}; +// ValueType implements viper.FlagValue interface. +func (_efc Point )ValueType ()string {return _efc .Type ()}; -// MarshalJSON implements json.Marshaler interface. -func (_dde Point )MarshalJSON ()([]byte ,error ){return _fda (_dde )}; +// Set sets the unit value. +// Implements pflag.Value interface. +func (_ddb *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_ddb .Length =nil ;return nil ;};_ae ,_g :=UnmarshalLength (s );if _g !=nil {return _g ;};_ddb .Length =_ae ;return nil ;}; -// ValueString implements pflag.Value interface. -func (_fed Inch )ValueString ()string {return _fed .String ()}; +// UnmarshalLength unmarshalls string value into Length. +func UnmarshalLength (length string )(Length ,error ){if _af .HasSuffix (length ,"\u006d\u006d"){return _bgb (length );};if _af .HasSuffix (length ,"\u0069\u006e"){return _cac (length );};if _af .HasSuffix (length ,"\u0070\u0074"){return _dca (length ); +};return nil ,_e .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length );}; -// Set implements pflag.Value interface. -func (_ddf *PageSize )Set (s string )error {_dfag ,_eba :=UnmarshalPageSize (s );if _eba !=nil {return _eba ;};*_ddf =_dfag ;return nil ;}; +// Points implements Length interface. +func (_df Point )Points ()Point {return _df }; // Type implements pflag.Value interface. -func (_g *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; +func (_efd PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; -// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise -func (_fdec PageSize )IsAPageSize ()bool {for _ ,_efa :=range _gc {if _fdec ==_efa {return true ;};};return false ;}; +// Length is it the default dimension unit. +type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; + +// Millimeter is the dimension unit that defines a millimeter. +type Millimeter float64 ; // Inches gets the inch value. Implements Length interface. -func (_dd Point )Inches ()Inch {return Inch (float64 (_dd )*_eb )}; +func (_ea Point )Inches ()Inch {return Inch (float64 (_ea )*_cc )}; -// Type implements pflag.Value interface. -func (_dc Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; +// MarshalUnit marshals the unit into the string. +func MarshalUnit (unit Length )(string ,error ){switch _fed :=unit .(type ){case Millimeter :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_fed ),nil ;case Inch :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_fed ),nil ;case Point :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_fed ),nil ; +default:return "",_e .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; -// Points implements Length interface. -func (_bf Point )Points ()Point {return _bf }; +// MarshalJSON implements json.Marshaler interface +func (_gf Millimeter )MarshalJSON ()([]byte ,error ){return _bga (_gf )};func _bga (_gfc Length )([]byte ,error ){if _gfc ==nil {return nil ,nil ;};_bb ,_cca :=MarshalUnit (_gfc );if _cca !=nil {return nil ,_cca ;};return []byte ("\u0022"+_bb +"\u0022"),nil ; +}; -// UnmarshalJSON implements the json.Unmarshaler interface for PageSize -func (_ecfg *PageSize )UnmarshalJSON (data []byte )error {var _dga string ;if _cebf :=_f .Unmarshal (data ,&_dga );_cebf !=nil {return _ae .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); -};var _adg error ;*_ecfg ,_adg =PageSizeString (_dga );return _adg ;}; +// Type implements pflag.Value interface. +func (_ef *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; // String implements fmt.Stringer interface. -func (_ee Point )String ()string {_dfc :=_e .Builder {};_dfc .WriteString (_b .FormatFloat (float64 (_ee ),'f',1,64));_dfc .WriteString ("\u0070\u0074");return _dfc .String ();}; +func (_ce Inch )String ()string {_db :=_af .Builder {};_db .WriteString (_d .FormatFloat (float64 (_ce ),'f',1,64));_db .WriteString ("\u0069\u006e");return _db .String ();}; -// Orientation is the page orientation type wrapper. -type Orientation bool ; +// ValueString implements viper.FlagValue interface. +func (_ag Point )ValueString ()string {return _ag .String ()}; -// ValueType implements viper.FlagValue interface. -func (_bg Point )ValueType ()string {return _bg .Type ()};var _ed =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; +// Dimensions gets the dimensions of the given page size. +// If provided page size is not valid than the function returns 0 values. +func (_cgb PageSize )Dimensions ()(_ccg ,_bc Millimeter ){switch _cgb {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; +case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; +case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _ccg ,_bc ;}; -// PageSizeValues returns all values of the enum -func PageSizeValues ()[]PageSize {return _gc }; +// Points implements Length interface. +func (_gea Millimeter )Points ()Point {return Point (_gea *_ad )};var _ Length =Inch (0); + +// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise +func (_fa PageSize )IsAPageSize ()bool {for _ ,_gd :=range _bdc {if _fa ==_gd {return true ;};};return false ;}; // PageSizeString retrieves an enum value from the enum constants string name. // Throws an error if the param is not part of the enum. -func PageSizeString (s string )(PageSize ,error ){if _aecg ,_ede :=_ada [s ];_ede {return _aecg ,nil ;};return 0,_ae .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); +func PageSizeString (s string )(PageSize ,error ){if _ecga ,_bgad :=_cdc [s ];_bgad {return _ecga ,nil ;};return 0,_e .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); }; -// HasChanged implements viper.FlagValue interface. -func (_add *Point )HasChanged ()bool {return _add !=nil }; +// Inches gets the inch value. Implements Length interface. +func (_fgf Inch )Inches ()Inch {return _fgf }; // PageSize is the enum used for defining the page size. type PageSize int ; -// Dimensions gets the dimensions of the given page size. -// If provided page size is not valid than the function returns 0 values. -func (_cdg PageSize )Dimensions ()(_gfg ,_acd Millimeter ){switch _cdg {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; -case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; -case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _gfg ,_acd ;}; +// HasChanged implements pflag.Value interface. +func (_fg *Inch )HasChanged ()bool {return _fg !=nil };const _bgc ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; -// Point is a unit of Length commonly used to measure the height of fonts. -type Point float64 ; -// Millimeter is the dimension unit that defines a millimeter. -type Millimeter float64 ;func _fda (_cc Length )([]byte ,error ){if _cc ==nil {return nil ,nil ;};_af ,_cbd :=MarshalUnit (_cc );if _cbd !=nil {return nil ,_cbd ;};return []byte ("\u0022"+_af +"\u0022"),nil ;}; +// PageSizeValues returns all values of the enum +func PageSizeValues ()[]PageSize {return _bdc };func _bgb (_dgd string )(Millimeter ,error ){_dgd =_af .TrimSpace (_af .TrimSuffix (_dgd ,"\u006d\u006d"));_fc ,_gfbc :=_d .ParseFloat (_dgd ,64);if _gfbc !=nil {return 0,_e .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_gfbc ); +};return Millimeter (_fc ),nil ;}; -// String implements fmt.Stringer interface. -func (_fbg Millimeter )String ()string {_ad :=_e .Builder {};_ad .WriteString (_b .FormatFloat (float64 (_fbg ),'f',1,64));_ad .WriteString ("\u006d\u006d");return _ad .String ();};func _abc (_ef string )(Point ,error ){_ef =_e .TrimSpace (_e .Trim (_ef ,"\u0070\u0074")); -_gaf ,_bef :=_b .ParseFloat (_ef ,64);if _bef !=nil {return 0,_bef ;};return Point (_gaf ),nil ;}; +// Type implements pflag.Value interface. +func (_aec Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; -// MarshalJSON implements the json.Marshaler interface for PageSize -func (_ecd PageSize )MarshalJSON ()([]byte ,error ){return _f .Marshal (_ecd .String ())}; +// Inches gets the inches equivalent from provided millimeter value. +func (_ge Millimeter )Inches ()Inch {return Inch (float64 (_ge )*_fe )}; -// UnmarshalPageSize unmarshals the page size from the string. -func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _efe PageSize ;if _bae :=(&_efe ).UnmarshalText ([]byte (pageSize ));_bae !=nil {return 0,_ae .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_bae ); -};return _efe ,nil ;}; +// UnmarshalInch unmarshalls provided string into unit. +func UnmarshalInch (unit string )(Inch ,error ){if _af .HasSuffix (unit ,"\u006d\u006d"){_fb ,_dda :=_bgb (unit );if _dda !=nil {return 0,_dda ;};return _fb .Inches (),nil ;};if _af .HasSuffix (unit ,"\u0069\u006e"){return _cac (unit );};return 0,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); +}; -// MarshalText implements the encoding.TextMarshaler interface for PageSize -func (_ecfa PageSize )MarshalText ()([]byte ,error ){return []byte (_ecfa .String ()),nil };var _ Length =Inch (0); +// MarshalJSON implements json.Marshaler interface +func (_eb Inch )MarshalJSON ()([]byte ,error ){return _bga (_eb )}; -// Set sets the unit value. -// Implements pflag.Value interface. -func (_ce *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_ce .Length =nil ;return nil ;};_cd ,_dg :=UnmarshalLength (s );if _dg !=nil {return _dg ;};_ce .Length =_cd ;return nil ;}; +// MarshalJSON implements json.Marshaler interface. +func (_fge Point )MarshalJSON ()([]byte ,error ){return _bga (_fge )}; -// Type implements pflag.Value interface. -func (_aeg PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"};const (_fb =float64 (1)/float64 (25.4);_d =25.4;_eb =0.0139;_bc =0.3528;_c =1.0/64;_ab =1.0/_bc ;); +// UnmarshalPageSize unmarshals the page size from the string. +func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _cea PageSize ;if _dag :=(&_cea ).UnmarshalText ([]byte (pageSize ));_dag !=nil {return 0,_e .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_dag ); +};return _cea ,nil ;};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;);func (_ebg PageSize )String ()string {if _ebg < 0||_ebg >=PageSize (len (_cee )-1){return _e .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_ebg ); +};return _bgc [_cee [_ebg ]:_cee [_ebg +1]];}; -// UnmarshalLength unmarshalls string value into Length. -func UnmarshalLength (length string )(Length ,error ){if _e .HasSuffix (length ,"\u006d\u006d"){return _dda (length );};if _e .HasSuffix (length ,"\u0069\u006e"){return _gfa (length );};if _e .HasSuffix (length ,"\u0070\u0074"){return _abc (length );}; -return nil ,_ae .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length );}; +// Millimeters converts the inches value to the millimeters. +func (_gc Inch )Millimeters ()Millimeter {return Millimeter (float64 (_gc )*_da )}; -// Inches gets the inches equivalent from provided millimeter value. -func (_fe Millimeter )Inches ()Inch {return Inch (float64 (_fe )*_fb )};func _gfa (_eeb string )(Inch ,error ){_eeb =_e .TrimSpace (_e .Trim (_eeb ,"\u0069\u006e"));_dfa ,_ceb :=_b .ParseFloat (_eeb ,64);if _ceb !=nil {return 0,_ae .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ceb ); -};return Inch (_dfa ),nil ;}; +// MarshalText implements the encoding.TextMarshaler interface for PageSize +func (_cfd PageSize )MarshalText ()([]byte ,error ){return []byte (_cfd .String ()),nil }; -// String implements fmt.Stringer interface. -func (_efd Orientation )String ()string {if _efd ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; +// UnmarshalJSON implements the json.Unmarshaler interface for PageSize +func (_ede *PageSize )UnmarshalJSON (data []byte )error {var _bbc string ;if _ebe :=_f .Unmarshal (data ,&_bbc );_ebe !=nil {return _e .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); +};var _eg error ;*_ede ,_eg =PageSizeString (_bbc );return _eg ;}; -// Type implements pflag.Value interface. -func (_cg Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; +// Set implements flag.Value interface. +func (_dccc *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_dccc =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_dccc =Landscape ;default:return _e .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); +};return nil ;}; -// UnmarshalInch unmarshalls provided string into unit. -func UnmarshalInch (unit string )(Inch ,error ){if _e .HasSuffix (unit ,"\u006d\u006d"){_eae ,_ddb :=_dda (unit );if _ddb !=nil {return 0,_ddb ;};return _eae .Inches (),nil ;};if _e .HasSuffix (unit ,"\u0069\u006e"){return _gfa (unit );};return 0,_ae .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); -}; +// MarshalJSON implements the json.Marshaler interface for PageSize +func (_fbf PageSize )MarshalJSON ()([]byte ,error ){return _f .Marshal (_fbf .String ())}; -// Millimeters converts the inches value to the millimeters. -func (_gb Point )Millimeters ()Millimeter {return Millimeter (float64 (_gb )*_bc )};func _dda (_dab string )(Millimeter ,error ){_dab =_e .TrimSpace (_e .TrimSuffix (_dab ,"\u006d\u006d"));_dae ,_ac :=_b .ParseFloat (_dab ,64);if _ac !=nil {return 0,_ae .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_ac ); -};return Millimeter (_dae ),nil ;}; +// Orientation is the page orientation type wrapper. +type Orientation bool ; -// ValueString implements viper.FlagValue interface. -func (_dcd Point )ValueString ()string {return _dcd .String ()};var _ada =map[string ]PageSize {_cdaa [0:9]:0,_cdaa [9:11]:1,_cdaa [11:13]:2,_cdaa [13:15]:3,_cdaa [15:17]:4,_cdaa [17:19]:5,_cdaa [19:21]:6,_cdaa [21:23]:7,_cdaa [23:25]:8,_cdaa [25:27]:9,_cdaa [27:29]:10,_cdaa [29:32]:11,_cdaa [32:34]:12,_cdaa [34:36]:13,_cdaa [36:38]:14,_cdaa [38:40]:15,_cdaa [40:42]:16,_cdaa [42:44]:17,_cdaa [44:46]:18,_cdaa [46:48]:19,_cdaa [48:50]:20,_cdaa [50:52]:21,_cdaa [52:55]:22,_cdaa [55:61]:23}; +// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize +func (_cfe *PageSize )UnmarshalText (text []byte )error {var _ddf error ;*_cfe ,_ddf =PageSizeString (string (text ));return _ddf ;};var _ _c .Value =(*Orientation )(nil ); +// ValueType implements pflag.Value interface. +func (_ccf Inch )ValueType ()string {return _ccf .Type ()}; -// MarshalUnit marshals the unit into the string. -func MarshalUnit (unit Length )(string ,error ){switch _ff :=unit .(type ){case Millimeter :return _ae .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_ff ),nil ;case Inch :return _ae .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_ff ),nil ;case Point :return _ae .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_ff ),nil ; -default:return "",_ae .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; +// String implements fmt.Stringer interface. +func (_dg Point )String ()string {_fdd :=_af .Builder {};_fdd .WriteString (_d .FormatFloat (float64 (_dg ),'f',1,64));_fdd .WriteString ("\u0070\u0074");return _fdd .String ();}; -// HasChanged implements pflag.Value interface. -func (_agd *Inch )HasChanged ()bool {return _agd !=nil }; \ No newline at end of file +// String gets the string value for given flag. +func (_dd *LengthFlag )String ()string {if _dd .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _dd .Length .String ();}; + +// MarshalPageSize marshals the page size into string. +func MarshalPageSize (p PageSize )(string ,error ){_cgbd ,_addf :=p .MarshalText ();if _addf !=nil {return "",_addf ;};return string (_cgbd ),nil ;};var (_ Length =Millimeter (0);); \ No newline at end of file diff --git a/unihtml.go b/unihtml.go index 613a3c2..83b756c 100644 --- a/unihtml.go +++ b/unihtml.go @@ -10,26 +10,32 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package unihtml contains a plugin for the UniDoc. -package unihtml ;import (_bb "bytes";_f "context";_bd "errors";_g "fmt";_cge "github.com/unidoc/unihtml/client";_fb "github.com/unidoc/unihtml/content";_fd "github.com/unidoc/unihtml/selector";_e "github.com/unidoc/unihtml/sizes";_ef "github.com/unidoc/unipdf/v4/common"; -_bgb "github.com/unidoc/unipdf/v4/common/license";_ca "github.com/unidoc/unipdf/v4/creator";_fa "github.com/unidoc/unipdf/v4/model";_ed "github.com/unidoc/unipdf/v4/render";_bf "image";_cg "image/color";_da "math";_b "net/url";_c "os";_bg "time";);func _eae ()error {_cd :=_bgb .GetLicenseKey (); -if _cd ==nil {return _bd .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};if !_cd .IsLicensed (){return _bd .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); +package unihtml ;import (_fc "bytes";_e "context";_bgd "errors";_ba "fmt";_c "github.com/unidoc/unihtml/client";_cf "github.com/unidoc/unihtml/content";_af "github.com/unidoc/unihtml/selector";_ed "github.com/unidoc/unihtml/sizes";_bab "github.com/unidoc/unipdf/v4/common"; +_ac "github.com/unidoc/unipdf/v4/common/license";_ff "github.com/unidoc/unipdf/v4/creator";_ag "github.com/unidoc/unipdf/v4/model";_bf "github.com/unidoc/unipdf/v4/render";_eb "image";_f "image/color";_d "math";_bg "net/url";_b "os";_a "time";);var ErrNoClient =_bgd .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); + + +// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. +func ConnectOptions (o Options )error {_gf =_c .New (_c .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_ee ,_da :=_e .WithTimeout (_e .Background (),_a .Second *5);defer _da ();if _eg :=_gf .HealthCheck (_ee );_eg !=nil {return _eg ; };return nil ;}; -// Connect creates UniHTML HTTP Client and tries to establish connection with the server. -func Connect (path string )error {if _ec :=_eae ();_ec !=nil {return _ec ;};_fe ,_ba :=_cge .ParseOptions (path );if _ba !=nil {return _ba ;};_ff =_cge .New (_fe );_gd ,_ce :=_f .WithTimeout (_f .Background (),_bg .Second *5);defer _ce ();if _ea :=_ff .HealthCheck (_gd ); -_ea !=nil {return _ea ;};return nil ;}; +// WriteToFile writes the document to a file defined by the output path. +func (_gba *Document )WriteToFile (outputPath string )error {if _dbg :=_gba .validate ();_dbg !=nil {return _dbg ;};_cff :=_a .Second *20+_gba ._aff ;_dgg ,_afa :=_e .WithTimeout (_e .Background (),_cff );defer _afa ();_gad ,_aga :=_gba .extract (_dgg ,_gba ._gg ,_gba ._ab ,_gba .getMargins ()); +if _aga !=nil {return _aga ;};_acd :=_ff .New ();for _ ,_cgf :=range _gad {if _aga =_acd .AddPage (_cgf );_aga !=nil {return _aga ;};};return _acd .WriteToFile (outputPath );};func _gbe (_gfb _eb .Image )float64 {_fef :=_gfb .Bounds ();var (_bfe int ;_dag _f .Color ; +_cge ,_geb ,_eeb uint32 ;);_ada ,_agf :=_fef .Min .X ,_fef .Max .Y -1;_fcd :=_gfb .At (_ada ,_agf );_fg ,_cd ,_cgfe ,_ :=_fcd .RGBA ();_gec :=_fg ==_d .MaxUint16 &&_cd ==_d .MaxUint16 &&_cgfe ==_d .MaxUint16 ;for _agf =_fef .Max .Y -1;_agf >=_fef .Min .Y ; +_agf --{var _egg bool ;for _ada =_fef .Min .X ;_ada < _fef .Max .X ;_ada ++{_dag =_gfb .At (_ada ,_agf );_cge ,_geb ,_eeb ,_ =_dag .RGBA ();if (_gec &&!(_cge ==_fg &&_geb ==_cd &&_cgfe ==_eeb ))||(!_gec &&(_d .Abs (float64 (_cge )-float64 (_fg ))/float64 (_d .MaxUint16 )> 0.03||_d .Abs (float64 (_geb )-float64 (_cd ))/float64 (_d .MaxUint16 )> 0.03||_d .Abs (float64 (_eeb )-float64 (_cgfe ))/float64 (_d .MaxUint16 )> 0.03)){_egg =true ; +break ;};};if _egg {break ;};_bfe =_agf ;};return float64 (_fef .Max .Y -_bfe )/float64 (_fef .Max .Y );}; -// SetMarginRight sets the left margin. -func (_ebd *Document )SetMarginRight (margin _e .Length ){_ebd ._a .Right =margin }; +// SetMarkedContentID sets the marked content id for the document. +func (_fce *Document )SetMarkedContentID (id int64 )*_ag .KDict {return nil };var _ _ff .Drawable =(*Document )(nil ); -// GeneratePageBlocks implements creator.Drawable interface. -func (_bbg *Document )GeneratePageBlocks (ctx _ca .DrawContext )([]*_ca .Block ,_ca .DrawContext ,error ){if _ab :=_bbg .validate ();_ab !=nil {return nil ,ctx ,_ab ;};var _ee []*_ca .Block ;_gaf :=_bbg .getMargins ();_eaa ,_ffg :=_bbg ._cdd ,_bbg ._cf ; -if _bbg ._bfd .IsRelative (){_eaa ,_ffg =_e .Point (ctx .Width ),_e .Point (ctx .Height );ctx .X -=float64 (_gaf .Left .Points ());}else {ctx .X =_bbg ._ae ;ctx .Y =_bbg ._cgd ;};_ag ,_efe :=_bbg .extract (_f .Background (),_eaa ,_ffg ,_gaf );if _efe !=nil {return nil ,_ca .DrawContext {},_efe ; -};for _edg ,_cee :=range _ag {_faa ,_db :=_ca .NewBlockFromPage (_cee );if _db !=nil {return nil ,_ca .DrawContext {},_db ;};var _caf float64 ;if _bbg ._cddf &&_edg ==len (_ag )-1{_ggc :=_ed .NewImageDevice ();_cdg ,_gfa :=_ggc .Render (_cee );if _gfa !=nil {return nil ,_ca .DrawContext {},_gfa ; -};_gc ,_gfa :=_cee .GetMediaBox ();if _gfa !=nil {return nil ,_ca .DrawContext {},_gfa ;};_fef :=_bg .Now ();_gfae :=_eg (_cdg );_caf =_gc .Height ()*_gfae ;_ef .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_bg .Since (_fef )); -if _bbg ._a .Bottom !=nil {_caf -=float64 (_bbg ._a .Bottom .Points ());};if _caf < 0{_caf =0;};_ef .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_caf ); -};_af ,_abf ,_db :=_faa .GeneratePageBlocks (ctx );if _db !=nil {return nil ,_ca .DrawContext {},_db ;};ctx =_abf ;ctx .Y -=_caf ;if _edg !=len (_ag )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; -ctx .Page ++;};_ee =append (_ee ,_af ...);};return _ee ,ctx ,nil ;};func (_fad *Document )getTimeoutDuration ()_bg .Duration {if _fad ._ga !=nil {return *_fad ._ga ;};return 0;}; +// Connect creates UniHTML HTTP Client and tries to establish connection with the server. +func Connect (path string )error {if _ad :=_gb ();_ad !=nil {return _ad ;};_db ,_cg :=_c .ParseOptions (path );if _cg !=nil {return _cg ;};_gf =_c .New (_db );_ga ,_gfd :=_e .WithTimeout (_e .Background (),_a .Second *5);defer _gfd ();if _ebb :=_gf .HealthCheck (_ga ); +_ebb !=nil {return _ebb ;};return nil ;}; + +// NewDocument creates new HTML Document used as an input for the creator.Drawable. +func NewDocument (path string )(*Document ,error ){_ebe :=&Document {};_gae ,_df :=_bg .Parse (path );if _df !=nil {return nil ,_df ;};switch _gae .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_ebe ._cc ,_df =_cf .NewWebURL (path ); +if _df !=nil {return nil ,_df ;};return _ebe ,nil ;};_dbe ,_df :=_b .Stat (path );if _df !=nil {return nil ,_df ;};if !_dbe .IsDir (){_ebe ._cc ,_df =_cf .NewHTMLFile (path );}else {_ebe ._cc ,_df =_cf .NewZipDirectory (path );};if _df !=nil {return nil ,_df ; +};return _ebe ,nil ;}; // Options are the HTML Client options used for establishing the connection. type Options struct{ @@ -44,93 +50,88 @@ Port int ; Secure bool ; // Prefix is an option setting used when the server is working with the URI prefix. Default Value: ''. -Prefix string ;}; +Prefix string ;};var _gf *_c .Client ; -// SetTimeoutDuration sets the timeout duration -// the default timeout is 15 seconds. -func (_cae *Document )SetTimeoutDuration (duration _bg .Duration ){_cae ._ga =&duration }; +// WaitReady waits for the provided selector to be ready. +// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. +func (_deag *Document )WaitReady (sel string ,by ..._af .ByType ){_bdc :=_af .BySearch ;if len (by )> 0{_bdc =by [0];};_deag ._ae =append (_deag ._ae ,_c .BySelector {Selector :sel ,By :_bdc });}; -// SetLandscapeOrientation sets document landscape page orientation. -func (_ebf *Document )SetLandscapeOrientation (){_ebf ._cfa =_e .Landscape }; +// SetMarginTop sets the left margin. +func (_gee *Document )SetMarginTop (margin _ed .Length ){_gee ._gcg .Top =margin }; -// ContainerComponent implements creator.containerElement interface. -func (_dcc *Document )ContainerComponent (container _ca .Drawable )(_ca .Drawable ,error ){switch container .(type ){case *_ca .Chapter :default:return nil ,_g .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); -};return _dcc ,nil ;}; +// GetPdfPages is a function that converts provided input content and +func (_fe *Document )GetPdfPages (ctx _e .Context )([]*_ag .PdfPage ,error ){if _aee :=_fe .validate ();_aee !=nil {return nil ,_aee ;};return _fe .extract (ctx ,_fe ._gg ,_fe ._ab ,_fe .getMargins ());};type margins struct{Left ,Right ,Bottom ,Top _ed .Length ; +}; + +// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. +func (_bb *Document )TrimLastPageContent (){_bb ._dd =true };func (_dbea *Document )validate ()error {if _gf ==nil {return ErrNoClient ;};if _dbea ._cc ==nil {return ErrContentNotDefined ;};return nil ;}; // GetContent returns the content of the document. -func (_fdb *Document )GetContent ()_fb .Content {return _fdb ._bag }; +func (_ggc *Document )GetContent ()_cf .Content {return _ggc ._cc }; -// NewDocumentFromString creates a new Document from the provided HTML string. -func NewDocumentFromString (html string )(*Document ,error ){_aef ,_cef :=_fb .NewStringContent (html );if _cef !=nil {return nil ,_cef ;};_eb :=&Document {};_eb ._bag =_aef ;return _eb ,nil ;};func (_eag *Document )getMargins ()margins {_dfa :=_eag ._a ; -if _eag ._bfd .IsRelative (){_dfa .Top =_e .Millimeter (1);_dfa .Left =_e .Millimeter (1);_dfa .Bottom =_e .Millimeter (1);_dfa .Right =_e .Millimeter (1);return _dfa ;};if _dfa .Top ==nil {_dfa .Top =_e .Millimeter (10);};if _dfa .Bottom ==nil {_dfa .Bottom =_e .Millimeter (10); -};if _dfa .Left ==nil {_dfa .Left =_e .Millimeter (10);};if _dfa .Right ==nil {_dfa .Right =_e .Millimeter (10);};return _dfa ;};var ErrNoClient =_bd .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); +// SetPageSize sets the page default size. +func (_fdd *Document )SetPageSize (pageSize _ed .PageSize )error {if !pageSize .IsAPageSize (){return _bgd .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); +};_fdd ._ccf =pageSize ;_fdd ._de =_ff .PositionAbsolute ;return nil ;}; +// SetPos sets the absolute position. Changes object positioning to absolute. +func (_ec *Document )SetPos (x ,y float64 ){_ec ._de =_ff .PositionAbsolute ;_ec ._def =x ;_ec ._fd =y }; -// SetPageHeight sets the page height for given document. -func (_cab *Document )SetPageHeight (pageHeight _e .Length )error {_cab ._cf =pageHeight ;_cab ._bfd =_ca .PositionAbsolute ;return nil ;}; +// SetTimeoutDuration sets the timeout duration +// the default timeout is 15 seconds. +func (_dfd *Document )SetTimeoutDuration (duration _a .Duration ){_dfd ._agd =&duration };func (_ffc *Document )getTimeoutDuration ()_a .Duration {if _ffc ._agd !=nil {return *_ffc ._agd ;};return 0;}; -// SetPageSize sets the page default size. -func (_bge *Document )SetPageSize (pageSize _e .PageSize )error {if !pageSize .IsAPageSize (){return _bd .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); -};_bge ._eca =pageSize ;_bge ._bfd =_ca .PositionAbsolute ;return nil ;}; +// ContainerComponent implements creator.containerElement interface. +func (_gd *Document )ContainerComponent (container _ff .Drawable )(_ff .Drawable ,error ){switch container .(type ){case *_ff .Chapter :default:return nil ,_ba .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); +};return _gd ,nil ;}; -// GetPdfPages is a function that converts provided input content and -func (_cb *Document )GetPdfPages (ctx _f .Context )([]*_fa .PdfPage ,error ){if _dad :=_cb .validate ();_dad !=nil {return nil ,_dad ;};return _cb .extract (ctx ,_cb ._cdd ,_cb ._cf ,_cb .getMargins ());};func (_afg *Document )extract (_aa _f .Context ,_dgg ,_bgd _e .Length ,_aefe margins )([]*_fa .PdfPage ,error ){_dd :=_cge .BuildHTMLQuery ().SetContent (_afg ._bag ).PageSize (_afg ._eca ).PaperWidth (_dgg ).PaperHeight (_bgd ).Orientation (_afg ._cfa ).MarginLeft (_aefe .Left ).MarginRight (_aefe .Right ).MarginTop (_aefe .Top ).MarginBottom (_aefe .Bottom ).TimeoutDuration (_afg .getTimeoutDuration ()).WaitTime (_afg ._bfb ); -for _ ,_efeb :=range _afg ._cga {_dd .WaitReady (_efeb .Selector ,_efeb .By );};for _ ,_cgac :=range _afg ._fg {_dd .WaitVisible (_cgac .Selector ,_cgac .By );};_fff ,_gac :=_dd .Query ();if _gac !=nil {return nil ,_gac ;};var _ffa _f .CancelFunc ;if _afg ._ga !=nil {_aa ,_ffa =_f .WithTimeout (_aa ,*_afg ._ga ); -}else {_aa ,_ffa =_f .WithTimeout (_aa ,_bg .Second *15);};defer _ffa ();_fae ,_gac :=_ff .ConvertHTML (_aa ,_fff );if _gac !=nil {return nil ,_gac ;};_ebe :=_bb .NewReader (_fae .Data );_cdcd ,_gac :=_fa .NewPdfReader (_ebe );if _gac !=nil {return nil ,_gac ; -};return _cdcd .PageList ,nil ;};var _ff *_cge .Client ;var ErrContentNotDefined =_bd .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); -var _ _ca .Drawable =(*Document )(nil );type margins struct{Left ,Right ,Bottom ,Top _e .Length ;}; +// GeneratePageBlocks implements creator.Drawable interface. +func (_aa *Document )GeneratePageBlocks (ctx _ff .DrawContext )([]*_ff .Block ,_ff .DrawContext ,error ){if _ccd :=_aa .validate ();_ccd !=nil {return nil ,ctx ,_ccd ;};var _aec []*_ff .Block ;_ge :=_aa .getMargins ();_fda ,_ccc :=_aa ._gg ,_aa ._ab ;if _aa ._de .IsRelative (){_fda ,_ccc =_ed .Point (ctx .Width ),_ed .Point (ctx .Height ); +ctx .X -=float64 (_ge .Left .Points ());}else {ctx .X =_aa ._def ;ctx .Y =_aa ._fd ;};_cfa ,_gbb :=_aa .extract (_e .Background (),_fda ,_ccc ,_ge );if _gbb !=nil {return nil ,_ff .DrawContext {},_gbb ;};for _gff ,_fa :=range _cfa {_ccb ,_dg :=_ff .NewBlockFromPage (_fa ); +if _dg !=nil {return nil ,_ff .DrawContext {},_dg ;};var _ebf float64 ;if _aa ._dd &&_gff ==len (_cfa )-1{_aeb :=_bf .NewImageDevice ();_ea ,_ccdg :=_aeb .Render (_fa );if _ccdg !=nil {return nil ,_ff .DrawContext {},_ccdg ;};_ca ,_ccdg :=_fa .GetMediaBox (); +if _ccdg !=nil {return nil ,_ff .DrawContext {},_ccdg ;};_dde :=_a .Now ();_bba :=_gbe (_ea );_ebf =_ca .Height ()*_bba ;_bab .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_a .Since (_dde )); +if _aa ._gcg .Bottom !=nil {_ebf -=float64 (_aa ._gcg .Bottom .Points ());};if _ebf < 0{_ebf =0;};_bab .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_ebf ); +};_ega ,_gffa ,_dg :=_ccb .GeneratePageBlocks (ctx );if _dg !=nil {return nil ,_ff .DrawContext {},_dg ;};ctx =_gffa ;ctx .Y -=_ebf ;if _gff !=len (_cfa )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; +ctx .Page ++;};_aec =append (_aec ,_ega ...);};return _aec ,ctx ,nil ;}; // SetPageWidth sets the page width for given document. -func (_dfd *Document )SetPageWidth (pageWidth _e .Length )error {_dfd ._cdd =pageWidth ;_dfd ._bfd =_ca .PositionAbsolute ;return nil ;}; +func (_abf *Document )SetPageWidth (pageWidth _ed .Length )error {_abf ._gg =pageWidth ;_abf ._de =_ff .PositionAbsolute ;return nil ;}; -// WaitVisible waits for the provided selector to be ready. -// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_deb *Document )WaitVisible (sel string ,by ..._fd .ByType ){_cgg :=_fd .BySearch ;if len (by )> 0{_cgg =by [0];};_deb ._fg =append (_deb ._fg ,_cge .BySelector {Selector :sel ,By :_cgg });}; +// SetMarginBottom sets the left margin. +func (_ggg *Document )SetMarginBottom (margin _ed .Length ){_ggg ._gcg .Bottom =margin }; // Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. -type Document struct{_bag _fb .Content ;_a margins ;_bfd _ca .Positioning ;_ae ,_cgd float64 ;_eca _e .PageSize ;_cdd ,_cf _e .Length ;_cfa _e .Orientation ;_cddf bool ;_bfb _bg .Duration ;_cga []_cge .BySelector ;_fg []_cge .BySelector ;_ga *_bg .Duration ; -};func (_gca *Document )validate ()error {if _ff ==nil {return ErrNoClient ;};if _gca ._bag ==nil {return ErrContentNotDefined ;};return nil ;}; +type Document struct{_cc _cf .Content ;_gcg margins ;_de _ff .Positioning ;_def ,_fd float64 ;_ccf _ed .PageSize ;_gg ,_ab _ed .Length ;_cfe _ed .Orientation ;_dd bool ;_aff _a .Duration ;_ae []_c .BySelector ;_ce []_c .BySelector ;_agd *_a .Duration ; +}; -// WaitTime sets the waiting time before the webpage is rendered to PDF. -func (_gbg *Document )WaitTime (duration _bg .Duration ){_gbg ._bfb =duration }; +// NewDocumentFromString creates a new Document from the provided HTML string. +func NewDocumentFromString (html string )(*Document ,error ){_bfd ,_bff :=_cf .NewStringContent (html );if _bff !=nil {return nil ,_bff ;};_aea :=&Document {};_aea ._cc =_bfd ;return _aea ,nil ;}; -// SetPos sets the absolute position. Changes object positioning to absolute. -func (_gbc *Document )SetPos (x ,y float64 ){_gbc ._bfd =_ca .PositionAbsolute ;_gbc ._ae =x ;_gbc ._cgd =y ;}; +// WaitTime sets the waiting time before the webpage is rendered to PDF. +func (_bc *Document )WaitTime (duration _a .Duration ){_bc ._aff =duration }; -// SetMarginLeft sets the left margin. -func (_bdg *Document )SetMarginLeft (margin _e .Length ){_bdg ._a .Left =margin }; +// SetMarginRight sets the left margin. +func (_gbaa *Document )SetMarginRight (margin _ed .Length ){_gbaa ._gcg .Right =margin };func (_geg *Document )extract (_ege _e .Context ,_gbbg ,_dba _ed .Length ,_dc margins )([]*_ag .PdfPage ,error ){_ebd :=_c .BuildHTMLQuery ().SetContent (_geg ._cc ).PageSize (_geg ._ccf ).PaperWidth (_gbbg ).PaperHeight (_dba ).Orientation (_geg ._cfe ).MarginLeft (_dc .Left ).MarginRight (_dc .Right ).MarginTop (_dc .Top ).MarginBottom (_dc .Bottom ).TimeoutDuration (_geg .getTimeoutDuration ()).WaitTime (_geg ._aff ); +for _ ,_cffc :=range _geg ._ae {_ebd .WaitReady (_cffc .Selector ,_cffc .By );};for _ ,_bda :=range _geg ._ce {_ebd .WaitVisible (_bda .Selector ,_bda .By );};_cb ,_gfe :=_ebd .Query ();if _gfe !=nil {return nil ,_gfe ;};var _caf _e .CancelFunc ;if _geg ._agd !=nil {_ege ,_caf =_e .WithTimeout (_ege ,*_geg ._agd ); +}else {_ege ,_caf =_e .WithTimeout (_ege ,_a .Second *15);};defer _caf ();_ggf ,_gfe :=_gf .ConvertHTML (_ege ,_cb );if _gfe !=nil {return nil ,_gfe ;};_ccbc :=_fc .NewReader (_ggf .Data );_bad ,_gfe :=_ag .NewPdfReader (_ccbc );if _gfe !=nil {return nil ,_gfe ; +};return _bad .PageList ,nil ;}; -// SetMarkedContentID sets the marked content id for the document. -func (_bba *Document )SetMarkedContentID (id int64 )*_fa .KDict {return nil }; +// SetLandscapeOrientation sets document landscape page orientation. +func (_be *Document )SetLandscapeOrientation (){_be ._cfe =_ed .Landscape }; -// WaitReady waits for the provided selector to be ready. +// WaitVisible waits for the provided selector to be ready. // A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_ebfa *Document )WaitReady (sel string ,by ..._fd .ByType ){_bfe :=_fd .BySearch ;if len (by )> 0{_bfe =by [0];};_ebfa ._cga =append (_ebfa ._cga ,_cge .BySelector {Selector :sel ,By :_bfe });}; - -// SetMarginTop sets the left margin. -func (_face *Document )SetMarginTop (margin _e .Length ){_face ._a .Top =margin }; - -// SetMarginBottom sets the left margin. -func (_dg *Document )SetMarginBottom (margin _e .Length ){_dg ._a .Bottom =margin };func _eg (_bca _bf .Image )float64 {_efa :=_bca .Bounds ();var (_dadf int ;_geb _cg .Color ;_faf ,_agc ,_dc uint32 ;);_gb ,_cc :=_efa .Min .X ,_efa .Max .Y -1;_dfb :=_bca .At (_gb ,_cc ); -_gdb ,_gfc ,_cdc ,_ :=_dfb .RGBA ();_ad :=_gdb ==_da .MaxUint16 &&_gfc ==_da .MaxUint16 &&_cdc ==_da .MaxUint16 ;for _cc =_efa .Max .Y -1;_cc >=_efa .Min .Y ;_cc --{var _gad bool ;for _gb =_efa .Min .X ;_gb < _efa .Max .X ;_gb ++{_geb =_bca .At (_gb ,_cc ); -_faf ,_agc ,_dc ,_ =_geb .RGBA ();if (_ad &&!(_faf ==_gdb &&_agc ==_gfc &&_cdc ==_dc ))||(!_ad &&(_da .Abs (float64 (_faf )-float64 (_gdb ))/float64 (_da .MaxUint16 )> 0.03||_da .Abs (float64 (_agc )-float64 (_gfc ))/float64 (_da .MaxUint16 )> 0.03||_da .Abs (float64 (_dc )-float64 (_cdc ))/float64 (_da .MaxUint16 )> 0.03)){_gad =true ; -break ;};};if _gad {break ;};_dadf =_cc ;};return float64 (_efa .Max .Y -_dadf )/float64 (_efa .Max .Y );}; - -// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. -func (_gg *Document )TrimLastPageContent (){_gg ._cddf =true }; - -// WriteToFile writes the document to a file defined by the output path. -func (_bfc *Document )WriteToFile (outputPath string )error {if _bc :=_bfc .validate ();_bc !=nil {return _bc ;};_cfe :=_bg .Second *20+_bfc ._bfb ;_ged ,_gce :=_f .WithTimeout (_f .Background (),_cfe );defer _gce ();_de ,_df :=_bfc .extract (_ged ,_bfc ._cdd ,_bfc ._cf ,_bfc .getMargins ()); -if _df !=nil {return _df ;};_fac :=_ca .New ();for _ ,_baag :=range _de {if _df =_fac .AddPage (_baag );_df !=nil {return _df ;};};return _fac .WriteToFile (outputPath );}; - -// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. -func ConnectOptions (o Options )error {_ff =_cge .New (_cge .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_baa ,_bdd :=_f .WithTimeout (_f .Background (),_bg .Second *5);defer _bdd ();if _ecd :=_ff .HealthCheck (_baa );_ecd !=nil {return _ecd ; +func (_fdg *Document )WaitVisible (sel string ,by ..._af .ByType ){_eag :=_af .BySearch ;if len (by )> 0{_eag =by [0];};_fdg ._ce =append (_fdg ._ce ,_c .BySelector {Selector :sel ,By :_eag });};var ErrContentNotDefined =_bgd .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); +func _gb ()error {_ef :=_ac .GetLicenseKey ();if _ef ==nil {return _bgd .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};if !_ef .IsLicensed (){return _bgd .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); };return nil ;}; +// SetMarginLeft sets the left margin. +func (_fga *Document )SetMarginLeft (margin _ed .Length ){_fga ._gcg .Left =margin };func (_gadg *Document )getMargins ()margins {_cda :=_gadg ._gcg ;if _gadg ._de .IsRelative (){_cda .Top =_ed .Millimeter (1);_cda .Left =_ed .Millimeter (1);_cda .Bottom =_ed .Millimeter (1); +_cda .Right =_ed .Millimeter (1);return _cda ;};if _cda .Top ==nil {_cda .Top =_ed .Millimeter (10);};if _cda .Bottom ==nil {_cda .Bottom =_ed .Millimeter (10);};if _cda .Left ==nil {_cda .Left =_ed .Millimeter (10);};if _cda .Right ==nil {_cda .Right =_ed .Millimeter (10); +};return _cda ;}; + // SetMargins sets the Document Margins. -func (_caa *Document )SetMargins (left ,right ,top ,bottom float64 ){_caa ._a .Left =_e .Point (left );_caa ._a .Right =_e .Point (right );_caa ._a .Top =_e .Point (top );_caa ._a .Bottom =_e .Point (bottom );_caa ._bfd =_ca .PositionAbsolute ;}; +func (_age *Document )SetMargins (left ,right ,top ,bottom float64 ){_age ._gcg .Left =_ed .Point (left );_age ._gcg .Right =_ed .Point (right );_age ._gcg .Top =_ed .Point (top );_age ._gcg .Bottom =_ed .Point (bottom );_age ._de =_ff .PositionAbsolute ; +}; -// NewDocument creates new HTML Document used as an input for the creator.Drawable. -func NewDocument (path string )(*Document ,error ){_ge :=&Document {};_gf ,_fbg :=_b .Parse (path );if _fbg !=nil {return nil ,_fbg ;};switch _gf .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_ge ._bag ,_fbg =_fb .NewWebURL (path ); -if _fbg !=nil {return nil ,_fbg ;};return _ge ,nil ;};_be ,_fbg :=_c .Stat (path );if _fbg !=nil {return nil ,_fbg ;};if !_be .IsDir (){_ge ._bag ,_fbg =_fb .NewHTMLFile (path );}else {_ge ._bag ,_fbg =_fb .NewZipDirectory (path );};if _fbg !=nil {return nil ,_fbg ; -};return _ge ,nil ;}; \ No newline at end of file +// SetPageHeight sets the page height for given document. +func (_bd *Document )SetPageHeight (pageHeight _ed .Length )error {_bd ._ab =pageHeight ;_bd ._de =_ff .PositionAbsolute ;return nil ;}; \ No newline at end of file