From e55a4f57a8d341f32c5e165dd06de752a1225447 Mon Sep 17 00:00:00 2001 From: UniDoc Build Date: Sun, 27 Apr 2025 14:57:20 +0000 Subject: [PATCH 1/3] 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 2/3] 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 3/3] 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