From bb53e79e671d2e93c9ad3d8e2f858be7fb7c6df3 Mon Sep 17 00:00:00 2001 From: UniDoc Build Date: Fri, 10 Feb 2023 16:57:05 +0000 Subject: [PATCH] prepare release --- cli/cmd/cmd.go | 73 ++++++----- cli/main.go | 2 +- client/client.go | 282 ++++++++++++++++++++++--------------------- common/common.go | 6 +- content/content.go | 55 ++++----- selector/selector.go | 12 +- sizes/sizes.go | 250 +++++++++++++++++++------------------- unihtml.go | 150 +++++++++++------------ 8 files changed, 417 insertions(+), 413 deletions(-) diff --git a/cli/cmd/cmd.go b/cli/cmd/cmd.go index 0f9baa4..f5eaa9a 100644 --- a/cli/cmd/cmd.go +++ b/cli/cmd/cmd.go @@ -9,57 +9,56 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package cmd ;import (_g "context";_dc "fmt";_ec "github.com/mitchellh/go-homedir";_c "github.com/spf13/cobra";_ab "github.com/spf13/viper";_ee "github.com/unidoc/unihtml/client";_dd "github.com/unidoc/unihtml/content";_a "github.com/unidoc/unihtml/sizes"; -_cc "github.com/unidoc/unipdf/v3/common";_d "os";_b "path/filepath";_f "time";);func _cdc (cmd *_c .Command ,_gg []string ){_fb :=_f .Now ();if _fe :=_ab .BindPFlags (cmd .Flags ());_fe !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_fe ); -_d .Exit (1);};if _ac :=_ab .Unmarshal (&_cd );_ac !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ac );_d .Exit (1);};_def ();_bg :=_f .Now ();_db ,_gb :=_d .Stat (_gg [0]);if _gb !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gb ); -_d .Exit (1);};if !_db .IsDir (){if _b .Ext (_db .Name ())!="\u002e\u0068\u0074m\u006c"{_dc .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_gg [0]); -_d .Exit (1);};};_bc ,_gb :=_d .OpenFile (_gg [1],_d .O_CREATE |_d .O_WRONLY |_d .O_TRUNC ,0700);if _gb !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gb );_d .Exit (1);};defer _bc .Close ();_fc :=_ee .New (_ee .Options {HTTPS :_cd .Https ,Hostname :_cd .Host ,Port :_cd .Port ,Prefix :_cd .Prefix }); -_fae ,_fcb :=_g .WithTimeout (_g .Background (),_f .Second *10);defer _fcb ();_bg =_f .Now ();var _fba _dd .Content ;if _db .IsDir (){_fba ,_gb =_dd .NewZipDirectory (_gg [0]);}else {_fba ,_gb =_dd .NewHTMLFile (_gg [0]);};if _gb !=nil {_dc .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_gb ); -_d .Exit (1);};_df ,_gb :=_ee .BuildHTMLQuery ().PaperWidth (_cg .PaperWidth .Length ).PaperHeight (_cg .PaperHeight .Length ).PageSize (_cg .PageSize ).MarginTop (_cg .MarginTop .Length ).MarginBottom (_cg .MarginBottom .Length ).MarginLeft (_cg .MarginLeft .Length ).MarginRight (_cg .MarginRight .Length ).Orientation (_cg .Orientation ).SetContent (_fba ).Query (); -if _gb !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gb );_d .Exit (1);};_dg ,_gb :=_fc .ConvertHTML (_fae ,_df );if _gb !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gb );_d .Exit (1);};_cc .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_f .Since (_bg )); -_bg =_f .Now ();_ ,_gb =_bc .Write (_dg .Data );if _gb !=nil {_dc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gb );_d .Exit (1);};_cc .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_f .Since (_bg )); -_dc .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_f .Since (_fb ));};var (_cd =generateConfig {};_cg =parametersConfig {PaperWidth :_a .LengthFlag {Length :_a .Inch (8.5).Millimeters ()},PaperHeight :_a .LengthFlag {Length :_a .Inch (11).Millimeters ()},Orientation :_a .Portrait ,MarginTop :_a .LengthFlag {Length :_a .Millimeter (10)},MarginBottom :_a .LengthFlag {Length :_a .Millimeter (10)},MarginLeft :_a .LengthFlag {Length :_a .Millimeter (10)},MarginRight :_a .LengthFlag {Length :_a .Millimeter (10)}}; -); - -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. -func Execute (){if _ce :=_de .Execute ();_ce !=nil {_dc .Println (_ce );_d .Exit (1);};};func _def (){_fcg :=_cc .LogLevelInfo ;if _fad {_fcg =_cc .LogLevelDebug ;};if _ca {_fcg =_cc .LogLevelTrace ;};_cc .Log =_cc .NewConsoleLogger (_fcg );};func init (){_de .AddCommand (_fa ); -_fa .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072");_fa .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); -_fa .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); -_fa .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); -_fa .Flags ().Var (&_cg .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_fa .Flags ().Var (&_cg .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); -_fa .Flags ().Var (&_cg .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_fa .Flags ().Var (&_cg .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); -_fa .Flags ().Var (&_cg .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_fa .Flags ().Var (&_cg .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); -_fa .Flags ().Var (&_cg .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_fa .Flags ().Var (&_cg .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); -};var _fa =&_c .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_cdc ,Args :_c .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; -var (_fad ,_ca bool ;);type parametersConfig struct{ +package cmd ;import (_e "context";_bc "fmt";_efg "github.com/mitchellh/go-homedir";_g "github.com/spf13/cobra";_fd "github.com/spf13/viper";_fe "github.com/unidoc/unihtml/client";_ab "github.com/unidoc/unihtml/content";_d "github.com/unidoc/unihtml/sizes"; +_a "github.com/unidoc/unipdf/v3/common";_b "os";_ff "path/filepath";_ef "time";);var _egf =&_g .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; +var (_eb =generateConfig {};_ba =parametersConfig {PaperWidth :_d .LengthFlag {Length :_d .Inch (8.5).Millimeters ()},PaperHeight :_d .LengthFlag {Length :_d .Inch (11).Millimeters ()},Orientation :_d .Portrait ,MarginTop :_d .LengthFlag {Length :_d .Millimeter (10)},MarginBottom :_d .LengthFlag {Length :_d .Millimeter (10)},MarginLeft :_d .LengthFlag {Length :_d .Millimeter (10)},MarginRight :_d .LengthFlag {Length :_d .Millimeter (10)}}; +);func _gg (cmd *_g .Command ,_eg []string ){_gd :=_ef .Now ();if _abc :=_fd .BindPFlags (cmd .Flags ());_abc !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_abc );_b .Exit (1);};if _ebb :=_fd .Unmarshal (&_eb );_ebb !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ebb ); +_b .Exit (1);};_gfg ();_dg ,_c :=_b .Stat (_eg [0]);if _c !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_c );_b .Exit (1);};if !_dg .IsDir (){if _ff .Ext (_dg .Name ())!="\u002e\u0068\u0074m\u006c"{_bc .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_eg [0]); +_b .Exit (1);};};_fg ,_c :=_b .OpenFile (_eg [1],_b .O_CREATE |_b .O_WRONLY |_b .O_TRUNC ,0700);if _c !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_c );_b .Exit (1);};defer _fg .Close ();_fed :=_fe .New (_fe .Options {HTTPS :_eb .Https ,Hostname :_eb .Host ,Port :_eb .Port ,Prefix :_eb .Prefix }); +_ec ,_cd :=_e .WithTimeout (_e .Background (),_ef .Second *10);defer _cd ();_ed :=_ef .Now ();var _fa _ab .Content ;if _dg .IsDir (){_fa ,_c =_ab .NewZipDirectory (_eg [0]);}else {_fa ,_c =_ab .NewHTMLFile (_eg [0]);};if _c !=nil {_bc .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_c ); +_b .Exit (1);};_ea ,_c :=_fe .BuildHTMLQuery ().PaperWidth (_ba .PaperWidth .Length ).PaperHeight (_ba .PaperHeight .Length ).PageSize (_ba .PageSize ).MarginTop (_ba .MarginTop .Length ).MarginBottom (_ba .MarginBottom .Length ).MarginLeft (_ba .MarginLeft .Length ).MarginRight (_ba .MarginRight .Length ).Orientation (_ba .Orientation ).SetContent (_fa ).Query (); +if _c !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_c );_b .Exit (1);};_ece ,_c :=_fed .ConvertHTML (_ec ,_ea );if _c !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_c );_b .Exit (1);};_a .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_ef .Since (_ed )); +_ed =_ef .Now ();_ ,_c =_fg .Write (_ece .Data );if _c !=nil {_bc .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_c );_b .Exit (1);};_a .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_ef .Since (_ed )); +_bc .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_ef .Since (_gd ));};var _ac =&_g .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_gg ,Args :_g .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; +func init (){_egf .AddCommand (_ac );_ac .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072");_ac .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); +_ac .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); +_ac .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); +_ac .Flags ().Var (&_ba .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_ac .Flags ().Var (&_ba .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); +_ac .Flags ().Var (&_ba .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_ac .Flags ().Var (&_ba .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); +_ac .Flags ().Var (&_ba .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_ac .Flags ().Var (&_ba .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); +_ac .Flags ().Var (&_ba .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_ac .Flags ().Var (&_ba .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); +};func _gfg (){_ca :=_a .LogLevelInfo ;if _fb {_ca =_a .LogLevelDebug ;};if _abf {_ca =_a .LogLevelTrace ;};_a .Log =_a .NewConsoleLogger (_ca );};var (_fb ,_abf bool ;);type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`; +Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};var _gge string ;type parametersConfig struct{ // PaperWidth sets the width of the paper. -PaperWidth _a .LengthFlag `mapstructure:"paper-width"`; +PaperWidth _d .LengthFlag `mapstructure:"paper-width"`; // PaperHeight is the height of the output paper. -PaperHeight _a .LengthFlag `mapstructure:"paper-height"`; +PaperHeight _d .LengthFlag `mapstructure:"paper-height"`; // PageSize is the page size string. -PageSize _a .PageSize `mapstructure:"page-size"`; +PageSize _d .PageSize `mapstructure:"page-size"`; // Orientation defines if the output should be in a landscape format. -Orientation _a .Orientation `mapstructure:"orientation"`; +Orientation _d .Orientation `mapstructure:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _a .LengthFlag `mapstructure:"margin-top"`; +MarginTop _d .LengthFlag `mapstructure:"margin-top"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _a .LengthFlag `mapstructure:"margin-bottom"`; +MarginBottom _d .LengthFlag `mapstructure:"margin-bottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _a .LengthFlag `mapstructure:"margin-left"`; +MarginLeft _d .LengthFlag `mapstructure:"margin-left"`; // MarginRight sets up the Right Margin for the output. -MarginRight _a .LengthFlag `mapstructure:"margin-right"`;};var _de =&_c .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; -var _bb string ;func init (){_c .OnInitialize (_bf );_de .PersistentFlags ().BoolVarP (&_fad ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065");_de .PersistentFlags ().BoolVarP (&_ca ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); -_de .PersistentFlags ().StringVar (&_bb ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); -_de .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};type generateConfig struct{Port int `mapstructure:"port"`; -Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};func _bf (){if _bb !=""{_ab .SetConfigFile (_bb );}else {_cb ,_fcge :=_ec .Dir ();if _fcge !=nil {_dc .Println (_fcge );_d .Exit (1);};_ab .AddConfigPath (_cb ); -_ab .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063");};_ab .AutomaticEnv ();if _cgg :=_ab .ReadInConfig ();_cgg ==nil {_dc .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_ab .ConfigFileUsed ()); +MarginRight _d .LengthFlag `mapstructure:"margin-right"`;};func init (){_g .OnInitialize (_ga );_egf .PersistentFlags ().BoolVarP (&_fb ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065"); +_egf .PersistentFlags ().BoolVarP (&_abf ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); +_egf .PersistentFlags ().StringVar (&_gge ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); +_egf .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");}; + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute (){if _baa :=_egf .Execute ();_baa !=nil {_bc .Println (_baa );_b .Exit (1);};};func _ga (){if _gge !=""{_fd .SetConfigFile (_gge );}else {_fgf ,_bb :=_efg .Dir ();if _bb !=nil {_bc .Println (_bb );_b .Exit (1);};_fd .AddConfigPath (_fgf ); +_fd .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063");};_fd .AutomaticEnv ();if _gae :=_fd .ReadInConfig ();_gae ==nil {_bc .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_fd .ConfigFileUsed ()); };}; \ No newline at end of file diff --git a/cli/main.go b/cli/main.go index 7ce4592..f0b00cc 100644 --- a/cli/main.go +++ b/cli/main.go @@ -9,4 +9,4 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package main ;import _ca "github.com/unidoc/unihtml/cli/cmd";func main (){_ca .Execute ()}; \ No newline at end of file +package main ;import _g "github.com/unidoc/unihtml/cli/cmd";func main (){_g .Execute ()}; \ No newline at end of file diff --git a/client/client.go b/client/client.go index d98620b..65a50d7 100644 --- a/client/client.go +++ b/client/client.go @@ -11,198 +11,200 @@ // Package client contains HTML Converter HTTP Client. The Client implements htmlcreator.HTMLConverter interface // for the UniPDF module and can be used as a plugin for the UniPDF creator.Creator. -package client ;import (_db "bytes";_b "compress/flate";_cc "compress/gzip";_e "context";_ee "encoding/json";_d "errors";_gcg "fmt";_adf "github.com/unidoc/unihtml/content";_eb "github.com/unidoc/unihtml/selector";_gf "github.com/unidoc/unihtml/sizes"; -_bg "github.com/unidoc/unipdf/v3/common";_c "io/ioutil";_ccf "net";_ea "net/http";_gc "net/url";_ge "strconv";_g "strings";_ad "time";); +package client ;import (_cg "bytes";_ge "compress/flate";_af "compress/gzip";_a "context";_g "encoding/json";_f "errors";_eg "fmt";_fcg "github.com/unidoc/unihtml/content";_gedc "github.com/unidoc/unihtml/selector";_ae "github.com/unidoc/unihtml/sizes"; +_gb "github.com/unidoc/unipdf/v3/common";_c "io/ioutil";_e "net";_fc "net/http";_ga "net/url";_ged "strconv";_bg "strings";_d "time";); -// New creates new client with provided options. -func New (o Options )*Client {o .DefaultTimeout =_ad .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _fb =&_ea .Transport {DialContext :(&_ccf .Dialer {Timeout :5*_ad .Second }).DialContext ,TLSHandshakeTimeout :5*_ad .Second }; -_bg .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_ea .Client {Transport :_fb ,Timeout :o .DefaultTimeout }};}; +// WithHTTPS sets the TLS option for the client options. +func WithHTTPS (useHTTPS bool )Option {return func (_dfd *Options ){_dfd .HTTPS =useHTTPS }}; -// Query gets the Query from provided query builder. If some error occurred during build process -// or the input is not valid the function would return an error. -func (_cd *QueryBuilder )Query ()(*Query ,error ){if _efd :=_cd .Validate ();_efd !=nil {return nil ,_efd ;};return &_cd ._dbc ,nil ;}; +// ParseOptions parses options for the Client. +func ParseOptions (connectPath string )(Options ,error ){if !_bg .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_fg ,_gbg :=_ga .Parse (connectPath );if _gbg !=nil {return Options {},_eg .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); +};var _ac int ;if _fg .Port ()!=""{_ac ,_gbg =_ged .Atoi (_fg .Port ());if _gbg !=nil {return Options {},_eg .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_gbg ); +};};return Options {Hostname :_fg .Hostname (),Port :_ac ,HTTPS :_fg .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_fg .Path },nil ;};func (_aeb *Client )getGenerateRequest (_bc _a .Context ,_gc *Query )(*_fc .Request ,error ){_ag :=generatePDFRequestV1 {Method :_gc .Method ,PageParameters :_gc .PageParameters ,RenderParameters :_gc .RenderParameters ,TimeoutDuration :int64 (_gc .TimeoutDuration )}; +switch _gc .Method {case "\u0077\u0065\u0062":_ag .ContentURL =_gc .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_ag .ContentType =_gc .ContentType ;_ag .Content =_gc .Content ;};_fa :=new (_cg .Buffer );if _gda :=_g .NewEncoder (_fa ).Encode (&_ag ); +_gda !=nil {return nil ,_eg .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_gda );};_aa :=_aeb .Options .Addr ();_aa =_eg .Sprintf ("%\u0073\u002f\u0062\u0065\u0074\u0061\u002f\u0070\u0064\u0066",_aa ); +_fgd ,_dfe :=_fc .NewRequest ("\u0050\u004f\u0053\u0054",_aa ,_fa );if _dfe !=nil {return nil ,_dfe ;};_fgd .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); +_fgd .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); +_fgd =_fgd .WithContext (_bc );return _fgd ,nil ;}; -// WithPort sets the Port option for the client options. -func WithPort (option int )Option {return func (_gbg *Options ){_gbg .Port =option }}; +// MarginBottom sets up the MarginBottom parameter for the query. +func (_ece *QueryBuilder )MarginBottom (marginBottom _ae .Length )*QueryBuilder {_ece ._gaa .PageParameters .MarginBottom =marginBottom ;return _ece ;};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`; +ContentURL string `json:"contentURL"`;Method string `json:"method"`;ExpiresAt int64 `json:"expiresAt"`;TimeoutDuration int64 `json:"timeoutDuration,omitempty"`;PageParameters ;RenderParameters ;}; -// WaitTime sets the minimum load time parameter for the page rendering. -func (_gg *QueryBuilder )WaitTime (d _ad .Duration )*QueryBuilder {_gg ._dbc .RenderParameters .WaitTime =d ;return _gg ;};var (ErrNotFound =_d .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_d .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); -ErrNotImplemented =_d .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_d .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_d .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079"); -ErrUnauthorized =_d .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_d .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); +// HealthCheck connects to the server and check the health status of the server. +func (_cf *Client )HealthCheck (ctx _a .Context )error {_df :=_cf .Options .Addr ();_df =_eg .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_df );_cb ,_ec :=_fc .NewRequest ("\u0047\u0045\u0054",_df ,nil );if _ec !=nil {return _ec ;};_cb =_cb .WithContext (ctx ); +_ed ,_ec :=_cf .Client .Do (_cb );if _ec !=nil {return _ec ;};switch _ed .StatusCode {case _fc .StatusOK :return nil ;case _fc .StatusNotFound :return ErrNotFound ;case _fc .StatusInternalServerError :return ErrInternalError ;case _fc .StatusBadGateway :return ErrBadGateway ; +default:return ErrNotImplemented ;};}; -// DefaultPageParameters creates default parameters. -func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_gf .Portrait }}; +// Client is a structure that is a HTTP client for the unihtml server. +type Client struct{Options Options ;Client *_fc .Client ;}; -// Portrait sets up the portrait page orientation. -func (_ccae *QueryBuilder )Portrait ()*QueryBuilder {_ccae ._dbc .PageParameters .Orientation =_gf .Portrait ;return _ccae ;}; +// Landscape sets up the landscape portrait orientation. +func (_dac *QueryBuilder )Landscape ()*QueryBuilder {_dac ._gaa .PageParameters .Orientation =_ae .Landscape ;return _dac ;}; -// Options are the client options used by the HTTP client. -type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _ad .Duration ;Prefix string ;}; +// SetContent sets custom data with it's content type. +func (_bcb *QueryBuilder )SetContent (content _fcg .Content )*QueryBuilder {if _bcb ._gee !=nil {return _bcb ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _bcb ._gaa .ContentType !=""{_bcb ._gee =ErrContentTypeDeclared ; +return _bcb ;};if content .ContentType ()==""{_bcb ._gee =_eg .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _bcb ; +};_bcb ._gaa .Content =content .Data ();_bcb ._gaa .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _bcb ._gaa .ContentType !=""{_bcb ._gee =ErrContentTypeDeclared ;return _bcb ;};_bcb ._gaa .URL =string (content .Data ());_bcb ._gaa .ContentType =content .ContentType (); +default:_bcb ._gee =_eg .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ());return _bcb ;};_bcb ._gaa .Method =content .Method (); +return _bcb ;}; -// Err gets the error which could occur in the query. -func (_ga *QueryBuilder )Err ()error {return _ga ._dc };func (_fbbf *Client )setQueryValues (_eeb *_ea .Request ,_fga *Query ){_bgg :=_eeb .URL .Query ();_gb :=_fga .PageParameters ;if _gb .PageSize !=nil {_bgg .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_gb .PageSize .String ()); -};if _gb .PaperHeight !=nil {_bgg .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_gb .PaperHeight .String ());};if _gb .PaperWidth !=nil {_bgg .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_gb .PaperWidth .String ()); -};if _gb .MarginTop !=nil {_bgg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_gb .MarginTop .String ());};if _gb .MarginBottom !=nil {_bgg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_gb .MarginBottom .String ()); -};if _gb .MarginRight !=nil {_bgg .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_gb .MarginRight .String ());};if _gb .MarginLeft !=nil {_bgg .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_gb .MarginLeft .String ()); -};if _gb .Orientation ==_gf .Landscape {_bgg .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_gb .Orientation .String ());};if _fga .RenderParameters .WaitTime !=0{_bgg .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_ge .FormatInt (int64 (_fga .RenderParameters .WaitTime /_ad .Millisecond ),10)); -};_eeb .URL .RawQuery =_bgg .Encode ();}; +// WaitTime sets the minimum load time parameter for the page rendering. +func (_gfc *QueryBuilder )WaitTime (d _d .Duration )*QueryBuilder {_gfc ._gaa .RenderParameters .WaitTime =d ;return _gfc ;}; -// Orientation sets the page orientation for the Query. -func (_geff *QueryBuilder )Orientation (orientation _gf .Orientation )*QueryBuilder {_geff ._dbc .PageParameters .Orientation =orientation ;return _geff ;};var (ErrMissingData =_d .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061"); -ErrContentType =_d .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065");ErrContentTypeDeclared =_d .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064"); -); +// PaperHeight sets up the PaperHeight (in cm) parameter for the query. +func (_da *QueryBuilder )PaperHeight (paperHeight _ae .Length )*QueryBuilder {_da ._gaa .PageParameters .PaperHeight =paperHeight ;return _da ;}; + +// Addr gets the HTTP address URI used by the http.Client. +func (_ee *Options )Addr ()string {_dc :=_bg .Builder {};_dc .WriteString ("\u0068\u0074\u0074\u0070");if _ee .HTTPS {_dc .WriteRune ('s');};_dc .WriteString ("\u003a\u002f\u002f");_dc .WriteString (_ee .Hostname );_dc .WriteRune (':');_dc .WriteString (_ged .Itoa (_ee .Port )); +if _ee .Prefix !=""{_dc .WriteString (_ee .Prefix );};return _dc .String ();}; + +// MarginRight sets up the MarginRight parameter for the query. +func (_fd *QueryBuilder )MarginRight (marginRight _ae .Length )*QueryBuilder {_fd ._gaa .PageParameters .MarginRight =marginRight ;return _fd ;};var (ErrNotFound =_f .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_f .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); +ErrNotImplemented =_f .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_f .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_f .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079"); +ErrUnauthorized =_f .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_f .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); // Validate checks the validity of the RenderParameters. -func (_cge *RenderParameters )Validate ()error {if _cge .WaitTime > _ad .Minute *3{return _d .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); -};for _ ,_bc :=range _cge .WaitReady {if _cgeb :=_bc .Validate ();_cgeb !=nil {return _gcg .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_cgeb ); +func (_cbc *RenderParameters )Validate ()error {if _cbc .WaitTime > _d .Minute *3{return _f .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); +};for _ ,_bcg :=range _cbc .WaitReady {if _ca :=_bcg .Validate ();_ca !=nil {return _eg .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_ca ); };};return nil ;}; +// MarginTop sets up the MarginTop parameter for the query. +func (_gdag *QueryBuilder )MarginTop (marginTop _ae .Length )*QueryBuilder {_gdag ._gaa .PageParameters .MarginTop =marginTop ;return _gdag ;}; + +// Query gets the Query from provided query builder. If some error occurred during build process +// or the input is not valid the function would return an error. +func (_eda *QueryBuilder )Query ()(*Query ,error ){if _gbe :=_eda .Validate ();_gbe !=nil {return nil ,_gbe ;};return &_eda ._gaa ,nil ;}; + +// PaperWidth sets up the PaperWidth (in cm) parameter for the query. +func (_bb *QueryBuilder )PaperWidth (paperWidth _ae .Length )*QueryBuilder {_bb ._gaa .PageParameters .PaperWidth =paperWidth ;return _bb ;}; + +// Validate checks if the parameters are valid. +func (_be *PageParameters )Validate ()error {if _be .PaperWidth !=nil {if _be .PaperWidth .Millimeters ()< 0{return _f .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); +};};if _be .PaperHeight !=nil {if _be .PaperHeight .Millimeters ()< 0{return _f .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); +};};if _be .MarginTop !=nil {if _be .MarginTop .Millimeters ()< 0{return _f .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _be .MarginBottom !=nil {if _be .MarginBottom .Millimeters ()< 0{return _f .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); +};};if _be .MarginLeft !=nil {if _be .MarginLeft .Millimeters ()< 0{return _f .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};};if _be .MarginRight !=nil {if _be .MarginRight .Millimeters ()< 0{return _f .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); +};};if _be .PageSize !=nil &&!_be .PageSize .IsAPageSize (){return _f .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; + +// MarginLeft sets up the MarginLeft parameter for the query. +func (_fcd *QueryBuilder )MarginLeft (marginLeft _ae .Length )*QueryBuilder {_fcd ._gaa .PageParameters .MarginLeft =marginLeft ;return _fcd ;}; + +// BuildHTMLQuery creates a Query builder that is supposed to create valid +func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; + +// PDFResponse is the response used by the HTMLConverter. +type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; + +// TimeoutDuration sets the server query duration timeout. +// Once the timeout is reached the server will return an error. +func (_gafe *QueryBuilder )TimeoutDuration (d _d .Duration )*QueryBuilder {_gafe ._gaa .TimeoutDuration =d ;return _gafe ;};func (_cbf *Client )setQueryValues (_dfb *_fc .Request ,_edd *Query ){_gdg :=_dfb .URL .Query ();_fe :=_edd .PageParameters ;if _fe .PageSize !=nil {_gdg .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_fe .PageSize .String ()); +};if _fe .PaperHeight !=nil {_gdg .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_fe .PaperHeight .String ());};if _fe .PaperWidth !=nil {_gdg .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_fe .PaperWidth .String ()); +};if _fe .MarginTop !=nil {_gdg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_fe .MarginTop .String ());};if _fe .MarginBottom !=nil {_gdg .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_fe .MarginBottom .String ()); +};if _fe .MarginRight !=nil {_gdg .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_fe .MarginRight .String ());};if _fe .MarginLeft !=nil {_gdg .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_fe .MarginLeft .String ()); +};if _fe .Orientation ==_ae .Landscape {_gdg .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_fe .Orientation .String ());};if _edd .RenderParameters .WaitTime !=0{_gdg .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_ged .FormatInt (int64 (_edd .RenderParameters .WaitTime /_d .Millisecond ),10)); +};_dfb .URL .RawQuery =_gdg .Encode ();}; + // Validate checks if provided Query is valid. -func (_caf *Query )Validate ()error {switch _caf .Method {case "\u0077\u0065\u0062":if _caf .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_caf .Content )==0{return ErrMissingData ;};if _caf .ContentType ==""{return ErrContentType ; -};default:return _gcg .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_caf .Method );};if _cca :=_caf .PageParameters .Validate (); -_cca !=nil {return _cca ;};if _ebe :=_caf .RenderParameters .Validate ();_ebe !=nil {return _ebe ;};return nil ;}; +func (_dg *Query )Validate ()error {switch _dg .Method {case "\u0077\u0065\u0062":if _dg .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_dg .Content )==0{return ErrMissingData ;};if _dg .ContentType ==""{return ErrContentType ; +};default:return _eg .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_dg .Method );};if _acg :=_dg .PageParameters .Validate (); +_acg !=nil {return _acg ;};if _bef :=_dg .RenderParameters .Validate ();_bef !=nil {return _bef ;};return nil ;}; -// ConvertHTML converts provided Query input into PDF file data. -// Implements creator.HTMLConverter interface. -func (_ca *Client )ConvertHTML (ctx _e .Context ,q *Query )(*PDFResponse ,error ){if _gfb :=q .Validate ();_gfb !=nil {return nil ,_gfb ;};_bb ,_ef :=_ca .getGenerateRequest (ctx ,q );if _ef !=nil {return nil ,_ef ;};_bg .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_bb .Method ,_bb .URL .Hostname (),_bb .URL .Path ,_bb .Header ,_bb .URL .Query ()); -_af ,_ef :=_ca .Client .Do (_bb );if _ef !=nil {return nil ,_ef ;};var _ec error ;switch _af .StatusCode {case _ea .StatusNotFound :_ec =ErrNotFound ;case _ea .StatusBadRequest :_ec =ErrBadRequest ;case _ea .StatusNotImplemented :_ec =ErrNotImplemented ; -case _ea .StatusUnauthorized :_ec =ErrUnauthorized ;case _ea .StatusRequestTimeout :_ec =ErrTimedOut ;case _ea .StatusCreated :default:_ec =ErrInternalError ;};_bga :=_af .Body ;switch _af .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_bga ,_ef =_cc .NewReader (_af .Body ); -if _ef !=nil {return nil ,_ef ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_bga =_b .NewReader (_af .Body );case "":default:return nil ,_gcg .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_af .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); -};_ba ,_ef :=_c .ReadAll (_bga );if _ef !=nil &&_ec ==nil {return nil ,_gcg .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_ef );};_bg .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_af .StatusCode ,_bb .Method ,_bb .URL .Host ,_bb .URL .Path ); -if _ec !=nil {return nil ,_gcg .Errorf ("\u0025\u0073\u0020%\u0077",string (_ba ),_ec );};_cg :=_af .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_bg .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_cg ); -return &PDFResponse {ID :_cg ,Data :_ba },nil ;}; +// Orientation sets the page orientation for the Query. +func (_efc *QueryBuilder )Orientation (orientation _ae .Orientation )*QueryBuilder {_efc ._gaa .PageParameters .Orientation =orientation ;return _efc ;}; -// QueryBuilder is the query that converts HTMLConverter defined data -type QueryBuilder struct{_dbc Query ;_dc error ;}; +// WithHostname sets the Hostname option for the client options. +func WithHostname (option string )Option {return func (_dff *Options ){_dff .Hostname =option }};var (ErrMissingData =_f .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061");ErrContentType =_f .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065"); +ErrContentTypeDeclared =_f .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064");); -// WithPrefix sets the client prefix. -func WithPrefix (prefix string )Option {return func (_aag *Options ){_aag .Prefix =prefix }}; +// DefaultPageParameters creates default parameters. +func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_ae .Portrait }}; -// WithHTTPS sets the TLS option for the client options. -func WithHTTPS (useHTTPS bool )Option {return func (_gcf *Options ){_gcf .HTTPS =useHTTPS }}; +// BySelector is a structure that defines a selector with it's query 'by' type. +type BySelector struct{Selector string `json:"selector"`;By _gedc .ByType `json:"by"`;}; + +// Err gets the error which could occur in the query. +func (_efg *QueryBuilder )Err ()error {return _efg ._gee }; + +// Option is a function that changes client options. +type Option func (_age *Options ); + +// Validate checks if the QueryBuilder had no errors during composition and creation. +func (_ab *QueryBuilder )Validate ()error {if _ab ._gee !=nil {return _ab ._gee ;};return _ab ._gaa .Validate ();}; // PageParameters are the query parameters used in the PDF generation. type PageParameters struct{ // PaperWidth sets the width of the paper. -PaperWidth _gf .Length `schema:"paper-width" json:"paperWidth"`; +PaperWidth _ae .Length `schema:"paper-width" json:"paperWidth"`; // PaperHeight is the height of the output paper. -PaperHeight _gf .Length `schema:"paper-height" json:"paperHeight"`; +PaperHeight _ae .Length `schema:"paper-height" json:"paperHeight"`; // PageSize is the page size string. -PageSize *_gf .PageSize `schema:"page-size" json:"pageSize"`; +PageSize *_ae .PageSize `schema:"page-size" json:"pageSize"`; // Orientation defines if the output should be in a landscape format. -Orientation _gf .Orientation `schema:"orientation" json:"orientation"`; +Orientation _ae .Orientation `schema:"orientation" json:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _gf .Length `schema:"margin-top" json:"marginTop"`; +MarginTop _ae .Length `schema:"margin-top" json:"marginTop"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _gf .Length `schema:"margin-bottom" json:"marginBottom"`; +MarginBottom _ae .Length `schema:"margin-bottom" json:"marginBottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _gf .Length `schema:"margin-left" json:"marginLeft"`; +MarginLeft _ae .Length `schema:"margin-left" json:"marginLeft"`; // MarginRight sets up the Right Margin for the output. -MarginRight _gf .Length `schema:"margin-right" json:"marginRight"`;};func (_de *Client )getGenerateRequest (_aga _e .Context ,_ce *Query )(*_ea .Request ,error ){_fbb :=generatePDFRequestV1 {Method :_ce .Method ,PageParameters :_ce .PageParameters ,RenderParameters :_ce .RenderParameters }; -switch _ce .Method {case "\u0077\u0065\u0062":_fbb .ContentURL =_ce .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_fbb .ContentType =_ce .ContentType ;_fbb .Content =_ce .Content ;};_eef :=new (_db .Buffer );if _eg :=_ee .NewEncoder (_eef ).Encode (&_fbb ); -_eg !=nil {return nil ,_gcg .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_eg );};_aa :=_de .Options .Addr ();_aa =_gcg .Sprintf ("%\u0073\u002f\u0062\u0065\u0074\u0061\u002f\u0070\u0064\u0066",_aa ); -_fg ,_efg :=_ea .NewRequest ("\u0050\u004f\u0053\u0054",_aa ,_eef );if _efg !=nil {return nil ,_efg ;};_fg .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); -_fg .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); -_fg =_fg .WithContext (_aga );return _fg ,nil ;}; - -// SetContent sets custom data with it's content type. -func (_abg *QueryBuilder )SetContent (content _adf .Content )*QueryBuilder {if _abg ._dc !=nil {return _abg ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _abg ._dbc .ContentType !=""{_abg ._dc =ErrContentTypeDeclared ; -return _abg ;};if content .ContentType ()==""{_abg ._dc =_gcg .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _abg ; -};_abg ._dbc .Content =content .Data ();_abg ._dbc .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _abg ._dbc .ContentType !=""{_abg ._dc =ErrContentTypeDeclared ;return _abg ;};_abg ._dbc .URL =string (content .Data ());_abg ._dbc .ContentType =content .ContentType (); -default:_abg ._dc =_gcg .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ());return _abg ;};_abg ._dbc .Method =content .Method (); -return _abg ;}; - -// BuildHTMLQuery creates a Query builder that is supposed to create valid -func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`;Method string `json:"method"`;ExpiresAt int64 `json:"expiresAt"`; -PageParameters ;RenderParameters ;}; - -// MarginTop sets up the MarginTop parameter for the query. -func (_dfb *QueryBuilder )MarginTop (marginTop _gf .Length )*QueryBuilder {_dfb ._dbc .PageParameters .MarginTop =marginTop ;return _dfb ;}; - -// Option is a function that changes client options. -type Option func (_ae *Options ); - -// WaitReady waits for the selector to get ready - 'loaded'. -func (_bac *QueryBuilder )WaitReady (selector string ,by _eb .ByType )*QueryBuilder {_bac ._dbc .RenderParameters .WaitReady =append (_bac ._dbc .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _bac ;}; +MarginRight _ae .Length `schema:"margin-right" json:"marginRight"`;}; -// Validate checks if the QueryBuilder had no errors during composition and creation. -func (_gef *QueryBuilder )Validate ()error {if _gef ._dc !=nil {return _gef ._dc ;};return _gef ._dbc .Validate ();}; - -// MarginBottom sets up the MarginBottom parameter for the query. -func (_ceb *QueryBuilder )MarginBottom (marginBottom _gf .Length )*QueryBuilder {_ceb ._dbc .PageParameters .MarginBottom =marginBottom ;return _ceb ;}; - -// PDFResponse is the response used by the HTMLConverter. -type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; +// QueryBuilder is the query that converts HTMLConverter defined data +type QueryBuilder struct{_gaa Query ;_gee error ;}; -// PaperHeight sets up the PaperHeight (in cm) parameter for the query. -func (_bdd *QueryBuilder )PaperHeight (paperHeight _gf .Length )*QueryBuilder {_bdd ._dbc .PageParameters .PaperHeight =paperHeight ;return _bdd ;}; +// ConvertHTML converts provided Query input into PDF file data. +// Implements creator.HTMLConverter interface. +func (_gg *Client )ConvertHTML (ctx _a .Context ,q *Query )(*PDFResponse ,error ){if _bf :=q .Validate ();_bf !=nil {return nil ,_bf ;};_eb ,_gaf :=_gg .getGenerateRequest (ctx ,q );if _gaf !=nil {return nil ,_gaf ;};_gb .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_eb .Method ,_eb .URL .Hostname (),_eb .URL .Path ,_eb .Header ,_eb .URL .Query ()); +_cd :=*_gg .Client ;if q .TimeoutDuration !=0{_cd .Timeout =q .TimeoutDuration ;};_gd ,_gaf :=_cd .Do (_eb );if _gaf !=nil {return nil ,_gaf ;};var _gef error ;switch _gd .StatusCode {case _fc .StatusNotFound :_gef =ErrNotFound ;case _fc .StatusBadRequest :_gef =ErrBadRequest ; +case _fc .StatusNotImplemented :_gef =ErrNotImplemented ;case _fc .StatusUnauthorized :_gef =ErrUnauthorized ;case _fc .StatusRequestTimeout :_gef =ErrTimedOut ;case _fc .StatusCreated :default:_gef =ErrInternalError ;};_ba :=_gd .Body ;switch _gd .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_ba ,_gaf =_af .NewReader (_gd .Body ); +if _gaf !=nil {return nil ,_gaf ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_ba =_ge .NewReader (_gd .Body );case "":default:return nil ,_eg .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_gd .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); +};_fge ,_gaf :=_c .ReadAll (_ba );if _gaf !=nil &&_gef ==nil {return nil ,_eg .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_gaf );};_gb .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_gd .StatusCode ,_eb .Method ,_eb .URL .Host ,_eb .URL .Path ); +if _gef !=nil {return nil ,_eg .Errorf ("\u0025\u0073\u0020%\u0077",string (_fge ),_gef );};_acc :=_gd .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_gb .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_acc ); +return &PDFResponse {ID :_acc ,Data :_fge },nil ;}; -// Landscape sets up the landscape portrait orientation. -func (_cgd *QueryBuilder )Landscape ()*QueryBuilder {_cgd ._dbc .PageParameters .Orientation =_gf .Landscape ;return _cgd ;}; +// New creates new client with provided options. +func New (o Options )*Client {o .DefaultTimeout =_d .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _dd =&_fc .Transport {DialContext :(&_e .Dialer {Timeout :5*_d .Second }).DialContext ,TLSHandshakeTimeout :5*_d .Second }; +_gb .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_fc .Client {Transport :_dd ,Timeout :o .DefaultTimeout }};}; // Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. -type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;}; - -// HealthCheck connects to the server and check the health status of the server. -func (_ada *Client )HealthCheck (ctx _e .Context )error {_da :=_ada .Options .Addr ();_da =_gcg .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_da );_ab ,_be :=_ea .NewRequest ("\u0047\u0045\u0054",_da ,nil );if _be !=nil {return _be ;};_ab =_ab .WithContext (ctx ); -_bd ,_be :=_ada .Client .Do (_ab );if _be !=nil {return _be ;};switch _bd .StatusCode {case _ea .StatusOK :return nil ;case _ea .StatusNotFound :return ErrNotFound ;case _ea .StatusInternalServerError :return ErrInternalError ;case _ea .StatusBadGateway :return ErrBadGateway ; -default:return ErrNotImplemented ;};}; - -// MarginLeft sets up the MarginLeft parameter for the query. -func (_gcd *QueryBuilder )MarginLeft (marginLeft _gf .Length )*QueryBuilder {_gcd ._dbc .PageParameters .MarginLeft =marginLeft ;return _gcd ;}; +type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;TimeoutDuration _d .Duration ;}; -// Client is a structure that is a HTTP client for the unihtml server. -type Client struct{Options Options ;Client *_ea .Client ;}; - -// Validate checks if the parameters are valid. -func (_fgg *PageParameters )Validate ()error {if _fgg .PaperWidth !=nil {if _fgg .PaperWidth .Millimeters ()< 0{return _d .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); -};};if _fgg .PaperHeight !=nil {if _fgg .PaperHeight .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); -};};if _fgg .MarginTop !=nil {if _fgg .MarginTop .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _fgg .MarginBottom !=nil {if _fgg .MarginBottom .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); -};};if _fgg .MarginLeft !=nil {if _fgg .MarginLeft .Millimeters ()< 0{return _d .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};}; -if _fgg .MarginRight !=nil {if _fgg .MarginRight .Millimeters ()< 0{return _d .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); -};};if _fgg .PageSize !=nil &&!_fgg .PageSize .IsAPageSize (){return _d .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; - -// PageSize sets up the PageSize parameter for the query. -func (_bde *QueryBuilder )PageSize (pageSize _gf .PageSize )*QueryBuilder {if pageSize !=_gf .Undefined {_bde ._dbc .PageParameters .PageSize =&pageSize ;};return _bde ;}; +// Options are the client options used by the HTTP client. +type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _d .Duration ;Prefix string ;}; -// WaitVisible waits for the selector to get visible. -func (_gab *QueryBuilder )WaitVisible (selector string ,by _eb .ByType )*QueryBuilder {_gab ._dbc .RenderParameters .WaitVisible =append (_gab ._dbc .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _gab ;}; +// Portrait sets up the portrait page orientation. +func (_gf *QueryBuilder )Portrait ()*QueryBuilder {_gf ._gaa .PageParameters .Orientation =_ae .Portrait ;return _gf ;}; // WithDefaultTimeout sets the DefaultTimeout option for the client options. -func WithDefaultTimeout (option _ad .Duration )Option {return func (_ade *Options ){_ade .DefaultTimeout =option };}; - -// Addr gets the HTTP address URI used by the http.Client. -func (_fc *Options )Addr ()string {_fa :=_g .Builder {};_fa .WriteString ("\u0068\u0074\u0074\u0070");if _fc .HTTPS {_fa .WriteRune ('s');};_fa .WriteString ("\u003a\u002f\u002f");_fa .WriteString (_fc .Hostname );_fa .WriteRune (':');_fa .WriteString (_ge .Itoa (_fc .Port )); -if _fc .Prefix !=""{_fa .WriteString (_fc .Prefix );};return _fa .String ();}; +func WithDefaultTimeout (option _d .Duration )Option {return func (_gdc *Options ){_gdc .DefaultTimeout =option };}; // RenderParameters are the parameters related with the rendering. -type RenderParameters struct{WaitTime _ad .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; - -// MarginRight sets up the MarginRight parameter for the query. -func (_ed *QueryBuilder )MarginRight (marginRight _gf .Length )*QueryBuilder {_ed ._dbc .PageParameters .MarginRight =marginRight ;return _ed ;}; +type RenderParameters struct{WaitTime _d .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; -// WithHostname sets the Hostname option for the client options. -func WithHostname (option string )Option {return func (_daf *Options ){_daf .Hostname =option }}; +// WithPrefix sets the client prefix. +func WithPrefix (prefix string )Option {return func (_gae *Options ){_gae .Prefix =prefix }}; -// PaperWidth sets up the PaperWidth (in cm) parameter for the query. -func (_gfg *QueryBuilder )PaperWidth (paperWidth _gf .Length )*QueryBuilder {_gfg ._dbc .PageParameters .PaperWidth =paperWidth ;return _gfg ;}; +// WaitReady waits for the selector to get ready - 'loaded'. +func (_eeg *QueryBuilder )WaitReady (selector string ,by _gedc .ByType )*QueryBuilder {_eeg ._gaa .RenderParameters .WaitReady =append (_eeg ._gaa .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _eeg ;}; // Validate checks validity of the selector. -func (_fbe BySelector )Validate ()error {if _fbe .Selector ==""{return _d .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _ece :=_fbe .By .Validate ();_ece !=nil {return _ece ; +func (_bfb BySelector )Validate ()error {if _bfb .Selector ==""{return _f .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _afd :=_bfb .By .Validate ();_afd !=nil {return _afd ; };return nil ;}; -// BySelector is a structure that defines a selector with it's query 'by' type. -type BySelector struct{Selector string `json:"selector"`;By _eb .ByType `json:"by"`;}; +// WaitVisible waits for the selector to get visible. +func (_cad *QueryBuilder )WaitVisible (selector string ,by _gedc .ByType )*QueryBuilder {_cad ._gaa .RenderParameters .WaitVisible =append (_cad ._gaa .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _cad ;}; -// ParseOptions parses options for the Client. -func ParseOptions (connectPath string )(Options ,error ){if !_g .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_ag ,_df :=_gc .Parse (connectPath );if _df !=nil {return Options {},_gcg .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); -};var _f int ;if _ag .Port ()!=""{_f ,_df =_ge .Atoi (_ag .Port ());if _df !=nil {return Options {},_gcg .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_df );}; -};return Options {Hostname :_ag .Hostname (),Port :_f ,HTTPS :_ag .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_ag .Path },nil ;}; \ No newline at end of file +// WithPort sets the Port option for the client options. +func WithPort (option int )Option {return func (_ef *Options ){_ef .Port =option }}; + +// PageSize sets up the PageSize parameter for the query. +func (_fb *QueryBuilder )PageSize (pageSize _ae .PageSize )*QueryBuilder {if pageSize !=_ae .Undefined {_fb ._gaa .PageParameters .PageSize =&pageSize ;};return _fb ;}; \ No newline at end of file diff --git a/common/common.go b/common/common.go index bab43e1..ae303be 100644 --- a/common/common.go +++ b/common/common.go @@ -10,8 +10,8 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package common contains common properties used by the subpackages. -package common ;import _e "time";var ReleasedAt =_e .Date (_a ,_g ,_ea ,_dg ,_ab ,0,0,_e .UTC );const _dg =12;const Version ="\u0030\u002e\u0036.\u0030"; +package common ;import _b "time";const Version ="\u0030\u002e\u0037.\u0030"; // UtcTimeFormat returns a formatted string describing a UTC timestamp. -func UtcTimeFormat (t _e .Time )string {return t .Format (_f )+"\u0020\u0055\u0054\u0043"};const _ea =5;const _f ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";const _ab =20; -const _a =2022;const _g =5; \ No newline at end of file +func UtcTimeFormat (t _b .Time )string {return t .Format (_ga )+"\u0020\u0055\u0054\u0043"};var ReleasedAt =_b .Date (_gf ,_f ,_be ,_e ,_ba ,0,0,_b .UTC );const _gf =2023;const _e =12;const _f =2;const _ga ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034"; +const _be =10;const _ba =20; \ No newline at end of file diff --git a/content/content.go b/content/content.go index 2e6ed95..9a9fc61 100644 --- a/content/content.go +++ b/content/content.go @@ -9,49 +9,50 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package content ;import (_a "archive/zip";_gc "bytes";_g "fmt";_de "io/ioutil";_c "net/url";_d "os";_f "strings";); +package content ;import (_d "archive/zip";_fa "bytes";_f "fmt";_c "io/ioutil";_a "net/url";_b "os";_g "strings";); -// Method gets the query method. -func (_gb *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"}; - -// NewHTMLFile creates new Content htmFile for provided input path. -func NewHTMLFile (path string )(Content ,error ){_fb ,_e :=_d .Open (path );if _e !=nil {return nil ,_e ;};_ee :=&htmlFile {_ff :_gc .Buffer {}};if _ ,_e =_ee ._ff .ReadFrom (_fb );_e !=nil {return nil ,_e ;};return _ee ,nil ;}; - -// Data implements Content interface. -func (_cd *webURL )Data ()[]byte {return []byte (_cd ._db )};type zipDirectory struct{_dd _gc .Buffer ;_bgg *_a .Writer ;}; +// ContentType implements Content interface. +func (_bac *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; // Data implements Content interface. -func (_bg *htmlFile )Data ()[]byte {return _bg ._ff .Bytes ()}; - -// Method gets the zip directory method. -func (_bgd *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; +func (_ef *webURL )Data ()[]byte {return []byte (_ef ._fb )};type webURL struct{_fb string }; // ContentType implements Content interface. -func (_fd *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; +func (_ge *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; // NewWebURL creates new Content webURL for provided input URL path. -func NewWebURL (path string )(Content ,error ){if _ ,_gg :=_c .Parse (path );_gg !=nil {return nil ,_gg ;};return &webURL {_db :path },nil ;}; - -// ContentType implements Content interface. -func (_fg *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; +func NewWebURL (path string )(Content ,error ){if _ ,_dc :=_a .Parse (path );_dc !=nil {return nil ,_dc ;};return &webURL {_fb :path },nil ;}; // NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' // and stores in it's in-memory buffer. -func NewZipDirectory (dirPath string )(Content ,error ){_ga :=&zipDirectory {_dd :_gc .Buffer {}};_ga ._bgg =_a .NewWriter (&_ga ._dd );if _ec :=_ga .zipPath (dirPath ,"");_ec !=nil {return nil ,_ec ;};if _eeb :=_ga ._bgg .Close ();_eeb !=nil {return nil ,_eeb ; -};return _ga ,nil ;};func (_ac *zipDirectory )zipBasePaths (_dbf _d .FileInfo ,_bfe ,_ffc string ,_ece bool ,_gfb *_f .Builder )(string ,string ){_gfb .WriteString (_bfe );if !_f .HasSuffix (_bfe ,"\u002f"){_gfb .WriteRune ('/');};_gfb .WriteString (_dbf .Name ()); -if _ece {_gfb .WriteRune ('/');};_fbd :=_gfb .String ();_gfb .Reset ();_gfb .WriteString (_ffc );_gfb .WriteString (_dbf .Name ());if _ece {_gfb .WriteRune ('/');};_fge :=_gfb .String ();_gfb .Reset ();return _fbd ,_fge ;};type webURL struct{_db string }; +func NewZipDirectory (dirPath string )(Content ,error ){_fd :=&zipDirectory {_ga :_fa .Buffer {}};_fd ._gb =_d .NewWriter (&_fd ._ga );if _bb :=_fd .zipPath (dirPath ,"");_bb !=nil {return nil ,_bb ;};if _ee :=_fd ._gb .Close ();_ee !=nil {return nil ,_ee ; +};return _fd ,nil ;}; +// Method gets the query method. +func (_aa *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"}; + +// ContentType implements Content interface. +func (_ba *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; + +// Data implements Content interface. +func (_ea *zipDirectory )Data ()[]byte {return _ea ._ga .Bytes ()}; + +// Method gets the zip directory method. +func (_efc *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; // Method gets the web url query method. -func (_df *webURL )Method ()string {return "\u0077\u0065\u0062"};func (_bda *zipDirectory )zipPath (_cg ,_eb string )error {_gad ,_gce :=_de .ReadDir (_cg );if _gce !=nil {return _g .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_cg ,_gce ); -};_bb :=&_f .Builder {};for _ ,_bf :=range _gad {_bbc ,_af :=_bda .zipBasePaths (_bf ,_cg ,_eb ,_bf .IsDir (),_bb );if _bf .IsDir (){if _gaf :=_bda .zipPath (_bbc ,_af );_gaf !=nil {return _gaf ;};continue ;};_dde ,_ffb :=_de .ReadFile (_bbc );if _ffb !=nil {return _ffb ; -};_bad ,_ffb :=_bda ._bgg .Create (_af );if _ffb !=nil {return _ffb ;};if _ ,_ffb =_bad .Write (_dde );_ffb !=nil {return _ffb ;};};return nil ;}; +func (_da *webURL )Method ()string {return "\u0077\u0065\u0062"};func (_cb *zipDirectory )zipBasePaths (_df _b .FileInfo ,_eg ,_dce string ,_fe bool ,_ffa *_g .Builder )(string ,string ){_ffa .WriteString (_eg );if !_g .HasSuffix (_eg ,"\u002f"){_ffa .WriteRune ('/'); +};_ffa .WriteString (_df .Name ());if _fe {_ffa .WriteRune ('/');};_fc :=_ffa .String ();_ffa .Reset ();_ffa .WriteString (_dce );_ffa .WriteString (_df .Name ());if _fe {_ffa .WriteRune ('/');};_fcb :=_ffa .String ();_ffa .Reset ();return _fc ,_fcb ;}; + // Content is an interface used for putting the content into Client Query. type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;}; -// ContentType implements Content interface. -func (_bd *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; +// NewHTMLFile creates new Content htmFile for provided input path. +func NewHTMLFile (path string )(Content ,error ){_gfd ,_ca :=_b .Open (path );if _ca !=nil {return nil ,_ca ;};_bf :=&htmlFile {_gf :_fa .Buffer {}};if _ ,_ca =_bf ._gf .ReadFrom (_gfd );_ca !=nil {return nil ,_ca ;};return _bf ,nil ;};type zipDirectory struct{_ga _fa .Buffer ; +_gb *_d .Writer ;}; // Data implements Content interface. -func (_ba *zipDirectory )Data ()[]byte {return _ba ._dd .Bytes ()};type htmlFile struct{_ff _gc .Buffer }; \ No newline at end of file +func (_ce *htmlFile )Data ()[]byte {return _ce ._gf .Bytes ()};type htmlFile struct{_gf _fa .Buffer };func (_aaa *zipDirectory )zipPath (_af ,_gg string )error {_dg ,_dd :=_c .ReadDir (_af );if _dd !=nil {return _f .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_af ,_dd ); +};_ggd :=&_g .Builder {};for _ ,_eae :=range _dg {_cd ,_eb :=_aaa .zipBasePaths (_eae ,_af ,_gg ,_eae .IsDir (),_ggd );if _eae .IsDir (){if _cg :=_aaa .zipPath (_cd ,_eb );_cg !=nil {return _cg ;};continue ;};_gge ,_ed :=_c .ReadFile (_cd );if _ed !=nil {return _ed ; +};_dab ,_ed :=_aaa ._gb .Create (_eb );if _ed !=nil {return _ed ;};if _ ,_ed =_dab .Write (_gge );_ed !=nil {return _ed ;};};return nil ;}; \ No newline at end of file diff --git a/selector/selector.go b/selector/selector.go index 0bf0252..97f80a6 100644 --- a/selector/selector.go +++ b/selector/selector.go @@ -9,11 +9,11 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package selector ;import _f "errors"; - -// Validate checks validity of the ByType. -func (_aa ByType )Validate ()error {if _aa >=ByID &&_aa <=BySearch {return nil ;};return _f .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};const (ByUndefined ByType =iota ;ByID ;ByQueryAll ; -ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); +package selector ;import _ff "errors"; // ByType is a 'By' selector type enumerator. -type ByType uint ; \ No newline at end of file +type ByType uint ; + +// Validate checks validity of the ByType. +func (_b ByType )Validate ()error {if _b >=ByID &&_b <=BySearch {return nil ;};return _ff .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};const (ByUndefined ByType =iota ;ByID ;ByQueryAll ; +ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); \ No newline at end of file diff --git a/sizes/sizes.go b/sizes/sizes.go index 4aac165..ca1d9dd 100644 --- a/sizes/sizes.go +++ b/sizes/sizes.go @@ -12,190 +12,190 @@ // Package sizes defines basic types that determines the size units i.e. lengths. // // -package sizes ;import (_d "encoding/json";_g "flag";_e "fmt";_c "strconv";_b "strings";);var _abc =map[string ]PageSize {_efbf [0:9]:0,_efbf [9:11]:1,_efbf [11:13]:2,_efbf [13:15]:3,_efbf [15:17]:4,_efbf [17:19]:5,_efbf [19:21]:6,_efbf [21:23]:7,_efbf [23:25]:8,_efbf [25:27]:9,_efbf [27:29]:10,_efbf [29:32]:11,_efbf [32:34]:12,_efbf [34:36]:13,_efbf [36:38]:14,_efbf [38:40]:15,_efbf [40:42]:16,_efbf [42:44]:17,_efbf [44:46]:18,_efbf [46:48]:19,_efbf [48:50]:20,_efbf [50:52]:21,_efbf [52:55]:22,_efbf [55:61]:23}; -var _ _g .Value =(*Orientation )(nil );var _egg =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; +package sizes ;import (_e "encoding/json";_b "flag";_a "fmt";_d "strconv";_bg "strings";);var (_ Length =Millimeter (0);); -// Inches gets the inches equivalent from provided millimeter value. -func (_eb Millimeter )Inches ()Inch {return Inch (float64 (_eb )*_cb )}; - -// Millimeters converts the inches value to the millimeters. -func (_fda Point )Millimeters ()Millimeter {return Millimeter (float64 (_fda )*_ce )};func _af (_gbb string )(Millimeter ,error ){_gbb =_b .TrimSpace (_b .TrimSuffix (_gbb ,"\u006d\u006d"));_fdg ,_bb :=_c .ParseFloat (_gbb ,64);if _bb !=nil {return 0,_e .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_bb ); -};return Millimeter (_fdg ),nil ;}; +// Set implements pflag.Value interface. +func (_eba *PageSize )Set (s string )error {_cca ,_aeb :=UnmarshalPageSize (s );if _aeb !=nil {return _aeb ;};*_eba =_cca ;return nil ;}; -// Name implements pflag.Value interface. -func (_ed Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; +// Type implements pflag.Value interface. +func (_gc Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; -// Millimeter is the dimension unit that defines a millimeter. -type Millimeter float64 ; +// UnmarshalInch unmarshalls provided string into unit. +func UnmarshalInch (unit string )(Inch ,error ){if _bg .HasSuffix (unit ,"\u006d\u006d"){_gg ,_ce :=_cc (unit );if _ce !=nil {return 0,_ce ;};return _gg .Inches (),nil ;};if _bg .HasSuffix (unit ,"\u0069\u006e"){return _bfa (unit );};return 0,_a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); +}; -// Type implements pflag.Value interface. -func (_eab Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; +// MarshalJSON implements the json.Marshaler interface for PageSize +func (_eecb PageSize )MarshalJSON ()([]byte ,error ){return _e .Marshal (_eecb .String ())}; -// String implements fmt.Stringer interface. -func (_gf Point )String ()string {_fba :=_b .Builder {};_fba .WriteString (_c .FormatFloat (float64 (_gf ),'f',1,64));_fba .WriteString ("\u0070\u0074");return _fba .String ();}; +// ValueType implements pflag.Value interface. +func (_bd Inch )ValueType ()string {return _bd .Type ()}; // Type implements pflag.Value interface. -func (_ebg PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; +func (_abc PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; -// Inches gets the inch value. Implements Length interface. -func (_eg Inch )Inches ()Inch {return _eg };func (_ceb PageSize )String ()string {if _ceb < 0||_ceb >=PageSize (len (_egg )-1){return _e .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_ceb );};return _efbf [_egg [_ceb ]:_egg [_ceb +1]]; +// Inches gets the inches equivalent from provided millimeter value. +func (_ca Millimeter )Inches ()Inch {return Inch (float64 (_ca )*_f )};func _eb (_fg Length )([]byte ,error ){if _fg ==nil {return nil ,nil ;};_gde ,_cd :=MarshalUnit (_fg );if _cd !=nil {return nil ,_cd ;};return []byte ("\u0022"+_gde +"\u0022"),nil ; }; -// MarshalText implements the encoding.TextMarshaler interface for PageSize -func (_fdef PageSize )MarshalText ()([]byte ,error ){return []byte (_fdef .String ()),nil }; +// Length is it the default dimension unit. +type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; -// UnmarshalJSON implements the json.Unmarshaler interface for PageSize -func (_eeg *PageSize )UnmarshalJSON (data []byte )error {var _eega string ;if _gfg :=_d .Unmarshal (data ,&_eega );_gfg !=nil {return _e .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); -};var _bee error ;*_eeg ,_bee =PageSizeString (_eega );return _bee ;}; +// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise +func (_faca PageSize )IsAPageSize ()bool {for _ ,_aaa :=range _dcb {if _faca ==_aaa {return true ;};};return false ;}; -// ValueType implements viper.FlagValue interface. -func (_da Point )ValueType ()string {return _da .Type ()}; +// Set sets the unit value. +// Implements pflag.Value interface. +func (_fc *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_fc .Length =nil ;return nil ;};_eaf ,_ag :=UnmarshalLength (s );if _ag !=nil {return _ag ;};_fc .Length =_eaf ;return nil ;}; -// Length is it the default dimension unit. -type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; +// HasChanged implements viper.FlagValue interface. +func (_dca *Point )HasChanged ()bool {return _dca !=nil }; -// Point is a unit of Length commonly used to measure the height of fonts. -type Point float64 ; +// Millimeters gets the float64 millimeter value. +func (_gd Millimeter )Millimeters ()Millimeter {return _gd }; -// MarshalJSON implements json.Marshaler interface. -func (_ggd Point )MarshalJSON ()([]byte ,error ){return _eaab (_ggd )}; +// MarshalJSON implements json.Marshaler interface +func (_fe Millimeter )MarshalJSON ()([]byte ,error ){return _eb (_fe )}; -// LengthFlag is a pflag wrapper for the Length value. -type LengthFlag struct{Length Length ;};const (Portrait =Orientation (false );Landscape =Orientation (true );); +// Type implements pflag.Value interface. +func (_ef Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; -// MarshalPageSize marshals the page size into string. -func MarshalPageSize (p PageSize )(string ,error ){_dae ,_ebf :=p .MarshalText ();if _ebf !=nil {return "",_ebf ;};return string (_dae ),nil ;}; +// PageSizeValues returns all values of the enum +func PageSizeValues ()[]PageSize {return _dcb }; -// PageSize is the enum used for defining the page size. -type PageSize int ; +// Name implements pflag.Value interface. +func (_eef Inch )Name ()string {return "\u0069\u006e\u0063\u0068"};var _ _b .Value =(*Orientation )(nil );func _cc (_fdg string )(Millimeter ,error ){_fdg =_bg .TrimSpace (_bg .TrimSuffix (_fdg ,"\u006d\u006d"));_fdd ,_dff :=_d .ParseFloat (_fdg ,64);if _dff !=nil {return 0,_a .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_dff ); +};return Millimeter (_fdd ),nil ;}; -// UnmarshalInch unmarshalls provided string into unit. -func UnmarshalInch (unit string )(Inch ,error ){if _b .HasSuffix (unit ,"\u006d\u006d"){_fc ,_cab :=_af (unit );if _cab !=nil {return 0,_cab ;};return _fc .Inches (),nil ;};if _b .HasSuffix (unit ,"\u0069\u006e"){return _eaa (unit );};return 0,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); -}; +// Dimensions gets the dimensions of the given page size. +// If provided page size is not valid than the function returns 0 values. +func (_baf PageSize )Dimensions ()(_dde ,_fac Millimeter ){switch _baf {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; +case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; +case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _dde ,_fac ;}; -// Inch is a unit that -type Inch float64 ;var _ _g .Value =(*Point )(nil ); +// ValueString implements pflag.Value interface. +func (_bf Inch )ValueString ()string {return _bf .String ()}; -// UnmarshalLength unmarshalls string value into Length. -func UnmarshalLength (length string )(Length ,error ){if _b .HasSuffix (length ,"\u006d\u006d"){return _af (length );};if _b .HasSuffix (length ,"\u0069\u006e"){return _eaa (length );};if _b .HasSuffix (length ,"\u0070\u0074"){return _gbd (length );};return nil ,_e .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length ); -};func _gbd (_ebb string )(Point ,error ){_ebb =_b .TrimSpace (_b .Trim (_ebb ,"\u0070\u0074"));_efba ,_gbc :=_c .ParseFloat (_ebb ,64);if _gbc !=nil {return 0,_gbc ;};return Point (_efba ),nil ;}; +// Orientation is the page orientation type wrapper. +type Orientation bool ; -// Inches gets the inch value. Implements Length interface. -func (_gbe Point )Inches ()Inch {return Inch (float64 (_gbe )*_ef )};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;); +// PageSize is the enum used for defining the page size. +type PageSize int ; -// Set implements flag.Value interface. -func (_bbg *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_bbg =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_bbg =Landscape ;default:return _e .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); -};return nil ;}; +// Point is a unit of Length commonly used to measure the height of fonts. +type Point float64 ; -// Set sets the unit value. -// Implements pflag.Value interface. -func (_fd *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_fd .Length =nil ;return nil ;};_ca ,_fde :=UnmarshalLength (s );if _fde !=nil {return _fde ;};_fd .Length =_ca ;return nil ;}; +// LengthFlag is a pflag wrapper for the Length value. +type LengthFlag struct{Length Length ;}; + +// Points implements Length interface. +func (_ff Inch )Points ()Point {return Point (float64 (_ff )*_bb )};const (Portrait =Orientation (false );Landscape =Orientation (true );); // String implements fmt.Stringer interface. -func (_gge Orientation )String ()string {if _gge ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";};var _ba =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; +func (_dd Millimeter )String ()string {_ge :=_bg .Builder {};_ge .WriteString (_d .FormatFloat (float64 (_dd ),'f',1,64));_ge .WriteString ("\u006d\u006d");return _ge .String ();}; +// UnmarshalPageSize unmarshals the page size from the string. +func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _gef PageSize ;if _aa :=(&_gef ).UnmarshalText ([]byte (pageSize ));_aa !=nil {return 0,_a .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_aa ); +};return _gef ,nil ;}; // String implements fmt.Stringer interface. -func (_efd Inch )String ()string {_gb :=_b .Builder {};_gb .WriteString (_c .FormatFloat (float64 (_efd ),'f',1,64));_gb .WriteString ("\u0069\u006e");return _gb .String ();}; +func (_bc Inch )String ()string {_eea :=_bg .Builder {};_eea .WriteString (_d .FormatFloat (float64 (_bc ),'f',1,64));_eea .WriteString ("\u0069\u006e");return _eea .String ();};const _bfg ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; +const (_f =float64 (1)/float64 (25.4);_ee =25.4;_c =0.0139;_ae =0.3528;_bb =1.0/64;_ea =1.0/_ae ;); -// ValueString implements pflag.Value interface. -func (_ddd Inch )ValueString ()string {return _ddd .String ()}; +// Points implements Length interface. +func (_eg Millimeter )Points ()Point {return Point (_eg *_ea )}; -// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize -func (_cda *PageSize )UnmarshalText (text []byte )error {var _ac error ;*_cda ,_ac =PageSizeString (string (text ));return _ac ;}; +// Type implements pflag.Value interface. +func (_bbb Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; -// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise -func (_gdd PageSize )IsAPageSize ()bool {for _ ,_ede :=range _ba {if _gdd ==_ede {return true ;};};return false ;}; +// MarshalUnit marshals the unit into the string. +func MarshalUnit (unit Length )(string ,error ){switch _da :=unit .(type ){case Millimeter :return _a .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_da ),nil ;case Inch :return _a .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_da ),nil ;case Point :return _a .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_da ),nil ; +default:return "",_a .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; -// Name implements viper.FlagValue interface. -func (_gfe Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; +// Millimeter is the dimension unit that defines a millimeter. +type Millimeter float64 ; -// MarshalJSON implements json.Marshaler interface -func (_cd Millimeter )MarshalJSON ()([]byte ,error ){return _eaab (_cd )}; +// MarshalJSON implements json.Marshaler interface. +func (_ad Point )MarshalJSON ()([]byte ,error ){return _eb (_ad )}; -// Orientation is the page orientation type wrapper. -type Orientation bool ; +// Name implements viper.FlagValue interface. +func (_fa Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; -// Type implements pflag.Value interface. -func (_efe *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"};func _eaa (_efb string )(Inch ,error ){_efb =_b .TrimSpace (_b .Trim (_efb ,"\u0069\u006e"));_dab ,_ebd :=_c .ParseFloat (_efb ,64);if _ebd !=nil {return 0,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ebd ); -};return Inch (_dab ),nil ;}; +// Millimeters converts the inches value to the millimeters. +func (_ba Inch )Millimeters ()Millimeter {return Millimeter (float64 (_ba )*_ee )}; -// Set implements flag.Value interface. -func (_fbd *Point )Set (s string )error {_cc ,_ea :=_c .ParseFloat (s ,64);if _ea !=nil {return _e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ea );};*_fbd =Point (_cc ); -return nil ;}; +// MarshalJSON implements json.Marshaler interface +func (_dc Inch )MarshalJSON ()([]byte ,error ){return _eb (_dc )};func _bfa (_ed string )(Inch ,error ){_ed =_bg .TrimSpace (_bg .Trim (_ed ,"\u0069\u006e"));_db ,_ac :=_d .ParseFloat (_ed ,64);if _ac !=nil {return 0,_a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ac ); +};return Inch (_db ),nil ;};var _gcc =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; -// Type implements pflag.Value interface. -func (_fb Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; +// Millimeters converts the inches value to the millimeters. +func (_aee Point )Millimeters ()Millimeter {return Millimeter (float64 (_aee )*_ae )}; -// Points implements Length interface. -func (_cde Point )Points ()Point {return _cde }; +// ValueString implements viper.FlagValue interface. +func (_cag Point )ValueString ()string {return _cag .String ()}; // String gets the string value for given flag. -func (_df *LengthFlag )String ()string {if _df .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _df .Length .String ();}; - -// MarshalJSON implements json.Marshaler interface -func (_egc Inch )MarshalJSON ()([]byte ,error ){return _eaab (_egc )}; +func (_bgd *LengthFlag )String ()string {if _bgd .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _bgd .Length .String ();}; -// MarshalUnit marshals the unit into the string. -func MarshalUnit (unit Length )(string ,error ){switch _aa :=unit .(type ){case Millimeter :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_aa ),nil ;case Inch :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_aa ),nil ;case Point :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_aa ),nil ; -default:return "",_e .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};};var (_ Length =Millimeter (0);); +// MarshalText implements the encoding.TextMarshaler interface for PageSize +func (_ada PageSize )MarshalText ()([]byte ,error ){return []byte (_ada .String ()),nil }; -// ValueType implements pflag.Value interface. -func (_dfc Inch )ValueType ()string {return _dfc .Type ()}; +// Inches gets the inch value. Implements Length interface. +func (_fb Point )Inches ()Inch {return Inch (float64 (_fb )*_c )};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;);func (_fab PageSize )String ()string {if _fab < 0||_fab >=PageSize (len (_gcc )-1){return _a .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_fab ); +};return _bfg [_gcc [_fab ]:_gcc [_fab +1]];};var _dcb =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; -// ValueString implements viper.FlagValue interface. -func (_db Point )ValueString ()string {return _db .String ()}; +// Inches gets the inch value. Implements Length interface. +func (_ab Inch )Inches ()Inch {return _ab }; -// Dimensions gets the dimensions of the given page size. -// If provided page size is not valid than the function returns 0 values. -func (_bcc PageSize )Dimensions ()(_bcd ,_ebba Millimeter ){switch _bcc {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; -case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; -case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _bcd ,_ebba ;}; +// Set implements flag.Value interface. +func (_egg *Point )Set (s string )error {_aed ,_abaa :=_d .ParseFloat (s ,64);if _abaa !=nil {return _a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_abaa );};*_egg =Point (_aed ); +return nil ;}; // Points implements Length interface. -func (_caa Millimeter )Points ()Point {return Point (_caa *_fa )}; +func (_dfa Point )Points ()Point {return _dfa }; -// Millimeters gets the float64 millimeter value. -func (_fe Millimeter )Millimeters ()Millimeter {return _fe }; - -// Type implements pflag.Value interface. -func (_fg Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; - -// UnmarshalPageSize unmarshals the page size from the string. -func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _egce PageSize ;if _cf :=(&_egce ).UnmarshalText ([]byte (pageSize ));_cf !=nil {return 0,_e .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_cf ); -};return _egce ,nil ;}; +// String implements fmt.Stringer interface. +func (_ddd Point )String ()string {_aba :=_bg .Builder {};_aba .WriteString (_d .FormatFloat (float64 (_ddd ),'f',1,64));_aba .WriteString ("\u0070\u0074");return _aba .String ();}; -// HasChanged implements pflag.Value interface. -func (_ee *Inch )HasChanged ()bool {return _ee !=nil }; +// Set implements flag.Value interface. +func (_ga *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_ga =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_ga =Landscape ;default:return _a .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); +};return nil ;}; -// PageSizeValues returns all values of the enum -func PageSizeValues ()[]PageSize {return _ba };const (_cb =float64 (1)/float64 (25.4);_f =25.4;_ef =0.0139;_ce =0.3528;_bf =1.0/64;_fa =1.0/_ce ;);var _ Length =Inch (0); +// Type implements pflag.Value interface. +func (_cg *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; -// Set implements pflag.Value interface. -func (_afg *PageSize )Set (s string )error {_dg ,_dga :=UnmarshalPageSize (s );if _dga !=nil {return _dga ;};*_afg =_dg ;return nil ;}; +// UnmarshalJSON implements the json.Unmarshaler interface for PageSize +func (_ccf *PageSize )UnmarshalJSON (data []byte )error {var _bafa string ;if _gae :=_e .Unmarshal (data ,&_bafa );_gae !=nil {return _a .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); +};var _dg error ;*_ccf ,_dg =PageSizeString (_bafa );return _dg ;}; -// Points implements Length interface. -func (_edf Inch )Points ()Point {return Point (float64 (_edf )*_bf )}; +// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize +func (_aef *PageSize )UnmarshalText (text []byte )error {var _de error ;*_aef ,_de =PageSizeString (string (text ));return _de ;}; -// String implements fmt.Stringer interface. -func (_cag Millimeter )String ()string {_ab :=_b .Builder {};_ab .WriteString (_c .FormatFloat (float64 (_cag ),'f',1,64));_ab .WriteString ("\u006d\u006d");return _ab .String ();}; +// ValueType implements viper.FlagValue interface. +func (_abf Point )ValueType ()string {return _abf .Type ()};var _eec =map[string ]PageSize {_bfg [0:9]:0,_bfg [9:11]:1,_bfg [11:13]:2,_bfg [13:15]:3,_bfg [15:17]:4,_bfg [17:19]:5,_bfg [19:21]:6,_bfg [21:23]:7,_bfg [23:25]:8,_bfg [25:27]:9,_bfg [27:29]:10,_bfg [29:32]:11,_bfg [32:34]:12,_bfg [34:36]:13,_bfg [36:38]:14,_bfg [38:40]:15,_bfg [40:42]:16,_bfg [42:44]:17,_bfg [44:46]:18,_bfg [46:48]:19,_bfg [48:50]:20,_bfg [50:52]:21,_bfg [52:55]:22,_bfg [55:61]:23}; -// Set implements pflag.Value interface. -func (_bc *Inch )Set (s string )error {_cg ,_bg :=_c .ParseFloat (s ,64);if _bg !=nil {return _e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_bg );};*_bc =Inch (_cg ); -return nil ;}; // PageSizeString retrieves an enum value from the enum constants string name. // Throws an error if the param is not part of the enum. -func PageSizeString (s string )(PageSize ,error ){if _fab ,_fae :=_abc [s ];_fae {return _fab ,nil ;};return 0,_e .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); +func PageSizeString (s string )(PageSize ,error ){if _cgf ,_dffb :=_eec [s ];_dffb {return _cgf ,nil ;};return 0,_a .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); }; -// Millimeters converts the inches value to the millimeters. -func (_eea Inch )Millimeters ()Millimeter {return Millimeter (float64 (_eea )*_f )};const _efbf ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; +// String implements fmt.Stringer interface. +func (_egf Orientation )String ()string {if _egf ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; +// UnmarshalLength unmarshalls string value into Length. +func UnmarshalLength (length string )(Length ,error ){if _bg .HasSuffix (length ,"\u006d\u006d"){return _cc (length );};if _bg .HasSuffix (length ,"\u0069\u006e"){return _bfa (length );};if _bg .HasSuffix (length ,"\u0070\u0074"){return _cee (length ); +};return nil ,_a .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length );}; -// MarshalJSON implements the json.Marshaler interface for PageSize -func (_ad PageSize )MarshalJSON ()([]byte ,error ){return _d .Marshal (_ad .String ())};func _eaab (_gga Length )([]byte ,error ){if _gga ==nil {return nil ,nil ;};_dfb ,_be :=MarshalUnit (_gga );if _be !=nil {return nil ,_be ;};return []byte ("\u0022"+_dfb +"\u0022"),nil ; -}; +// MarshalPageSize marshals the page size into string. +func MarshalPageSize (p PageSize )(string ,error ){_cbg ,_ebf :=p .MarshalText ();if _ebf !=nil {return "",_ebf ;};return string (_cbg ),nil ;}; -// HasChanged implements viper.FlagValue interface. -func (_gd *Point )HasChanged ()bool {return _gd !=nil }; \ No newline at end of file +// Inch is a unit that +type Inch float64 ; + +// Set implements pflag.Value interface. +func (_fd *Inch )Set (s string )error {_cb ,_feb :=_d .ParseFloat (s ,64);if _feb !=nil {return _a .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_feb );};*_fd =Inch (_cb ); +return nil ;}; + +// HasChanged implements pflag.Value interface. +func (_fde *Inch )HasChanged ()bool {return _fde !=nil };func _cee (_ec string )(Point ,error ){_ec =_bg .TrimSpace (_bg .Trim (_ec ,"\u0070\u0074"));_adf ,_dbb :=_d .ParseFloat (_ec ,64);if _dbb !=nil {return 0,_dbb ;};return Point (_adf ),nil ;};var _ _b .Value =(*Point )(nil ); +var _ Length =Inch (0); \ No newline at end of file diff --git a/unihtml.go b/unihtml.go index 28b7810..bcfc514 100644 --- a/unihtml.go +++ b/unihtml.go @@ -10,59 +10,55 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package unihtml contains a plugin for the UniDoc. -package unihtml ;import (_df "bytes";_c "context";_cb "errors";_eg "fmt";_fc "github.com/unidoc/unihtml/client";_ce "github.com/unidoc/unihtml/content";_b "github.com/unidoc/unihtml/selector";_de "github.com/unidoc/unihtml/sizes";_fd "github.com/unidoc/unipdf/v3/common"; -_dd "github.com/unidoc/unipdf/v3/common/license";_dc "github.com/unidoc/unipdf/v3/creator";_be "github.com/unidoc/unipdf/v3/model";_ec "github.com/unidoc/unipdf/v3/render";_d "image";_e "image/color";_f "math";_a "net/url";_gc "os";_fb "time";); - -// WaitVisible waits for the provided selector to be ready. -// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_fdd *Document )WaitVisible (sel string ,by ..._b .ByType ){_gfe :=_b .BySearch ;if len (by )> 0{_gfe =by [0];};_fdd ._dbf =append (_fdd ._dbf ,_fc .BySelector {Selector :sel ,By :_gfe });}; - -// SetPageHeight sets the page height for given document. -func (_dfg *Document )SetPageHeight (pageHeight _de .Length )error {_dfg ._gd =pageHeight ;_dfg ._ccg =_dc .PositionAbsolute ;return nil ;};var ErrContentNotDefined =_cb .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); - +package unihtml ;import (_ga "bytes";_e "context";_ea "errors";_f "fmt";_eg "github.com/unidoc/unihtml/client";_b "github.com/unidoc/unihtml/content";_ge "github.com/unidoc/unihtml/selector";_ag "github.com/unidoc/unihtml/sizes";_eab "github.com/unidoc/unipdf/v3/common"; +_c "github.com/unidoc/unipdf/v3/common/license";_bg "github.com/unidoc/unipdf/v3/creator";_egd "github.com/unidoc/unipdf/v3/model";_ce "github.com/unidoc/unipdf/v3/render";_g "image";_ab "image/color";_af "math";_a "net/url";_de "os";_fg "time";);func (_ccf *Document )validate ()error {if _cee ==nil {return ErrNoClient ; +};if _ccf ._egf ==nil {return ErrContentNotDefined ;};return nil ;}; // ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. -func ConnectOptions (o Options )error {_fcd =_fc .New (_fc .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_dcc ,_cf :=_c .WithTimeout (_c .Background (),_fb .Second *5);defer _cf ();if _db :=_fcd .HealthCheck (_dcc );_db !=nil {return _db ; -};return nil ;};var ErrNoClient =_cb .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); - -// Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. -type Document struct{_fg _ce .Content ;_fe margins ;_ccg _dc .Positioning ;_dbg ,_gf float64 ;_feb _de .PageSize ;_ggd ,_gd _de .Length ;_aa _de .Orientation ;_ea bool ;_ccgd _fb .Duration ;_ccb []_fc .BySelector ;_dbf []_fc .BySelector ;_fa *_fb .Duration ; -}; - -// NewDocument creates new HTML Document used as an input for the creator.Drawable. -func NewDocument (path string )(*Document ,error ){_ddc :=&Document {};_fac ,_cea :=_a .Parse (path );if _cea !=nil {return nil ,_cea ;};switch _fac .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_ddc ._fg ,_cea =_ce .NewWebURL (path ); -if _cea !=nil {return nil ,_cea ;};return _ddc ,nil ;};_gdg ,_cea :=_gc .Stat (path );if _cea !=nil {return nil ,_cea ;};if !_gdg .IsDir (){_ddc ._fg ,_cea =_ce .NewHTMLFile (path );}else {_ddc ._fg ,_cea =_ce .NewZipDirectory (path );};if _cea !=nil {return nil ,_cea ; -};return _ddc ,nil ;}; +func ConnectOptions (o Options )error {_cee =_eg .New (_eg .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_cd ,_ed :=_e .WithTimeout (_e .Background (),_fg .Second *5);defer _ed ();if _afb :=_cee .HealthCheck (_cd );_afb !=nil {return _afb ; +};return nil ;};func (_gef *Document )extract (_aca _e .Context ,_dcf ,_eacf _ag .Length ,_eae margins )([]*_egd .PdfPage ,error ){_cbc :=_eg .BuildHTMLQuery ().SetContent (_gef ._egf ).PageSize (_gef ._geb ).PaperWidth (_dcf ).PaperHeight (_eacf ).Orientation (_gef ._gg ).MarginLeft (_eae .Left ).MarginRight (_eae .Right ).MarginTop (_eae .Top ).MarginBottom (_eae .Bottom ).TimeoutDuration (_gef .getTimeoutDuration ()).WaitTime (_gef ._egfb ); +for _ ,_cf :=range _gef ._ebc {_cbc .WaitReady (_cf .Selector ,_cf .By );};for _ ,_bbc :=range _gef ._dc {_cbc .WaitVisible (_bbc .Selector ,_bbc .By );};_gab ,_ee :=_cbc .Query ();if _ee !=nil {return nil ,_ee ;};var _dfaf _e .CancelFunc ;if _gef ._fae !=nil {_aca ,_dfaf =_e .WithTimeout (_aca ,*_gef ._fae ); +}else {_aca ,_dfaf =_e .WithTimeout (_aca ,_fg .Second *15);};defer _dfaf ();_ddg ,_ee :=_cee .ConvertHTML (_aca ,_gab );if _ee !=nil {return nil ,_ee ;};_egb :=_ga .NewReader (_ddg .Data );_dcb ,_ee :=_egd .NewPdfReader (_egb );if _ee !=nil {return nil ,_ee ; +};return _dcb .PageList ,nil ;}; // SetMargins sets the Document Margins. -func (_dac *Document )SetMargins (left ,right ,top ,bottom float64 ){_dac ._fe .Left =_de .Point (left );_dac ._fe .Right =_de .Point (right );_dac ._fe .Top =_de .Point (top );_dac ._fe .Bottom =_de .Point (bottom );_dac ._ccg =_dc .PositionAbsolute ; -}; - -// SetPos sets the absolute position. Changes object positioning to absolute. -func (_ede *Document )SetPos (x ,y float64 ){_ede ._ccg =_dc .PositionAbsolute ;_ede ._dbg =x ;_ede ._gf =y ;}; +func (_afd *Document )SetMargins (left ,right ,top ,bottom float64 ){_afd ._gc .Left =_ag .Point (left );_afd ._gc .Right =_ag .Point (right );_afd ._gc .Top =_ag .Point (top );_afd ._gc .Bottom =_ag .Point (bottom );_afd ._daf =_bg .PositionAbsolute ; +};func _aad ()error {_cb :=_c .GetLicenseKey ();if _cb ==nil {return _ea .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};if !_cb .IsLicensed (){return _ea .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); +};return nil ;}; -// WaitReady waits for the provided selector to be ready. +// WaitVisible waits for the provided selector to be ready. // A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. -func (_gb *Document )WaitReady (sel string ,by ..._b .ByType ){_eeg :=_b .BySearch ;if len (by )> 0{_eeg =by [0];};_gb ._ccb =append (_gb ._ccb ,_fc .BySelector {Selector :sel ,By :_eeg });}; +func (_abfb *Document )WaitVisible (sel string ,by ..._ge .ByType ){_egff :=_ge .BySearch ;if len (by )> 0{_egff =by [0];};_abfb ._dc =append (_abfb ._dc ,_eg .BySelector {Selector :sel ,By :_egff });}; + +// WaitTime sets the waiting time before the webpage is rendered to PDF. +func (_dd *Document )WaitTime (duration _fg .Duration ){_dd ._egfb =duration }; + +// ContainerComponent implements creator.containerElement interface. +func (_fbd *Document )ContainerComponent (container _bg .Drawable )(_bg .Drawable ,error ){switch container .(type ){case *_bg .Chapter :default:return nil ,_f .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); +};return _fbd ,nil ;}; // SetMarginTop sets the left margin. -func (_ceaa *Document )SetMarginTop (margin _de .Length ){_ceaa ._fe .Top =margin };func (_acc *Document )getMargins ()margins {_gafg :=_acc ._fe ;if _acc ._ccg .IsRelative (){_gafg .Top =_de .Millimeter (1);_gafg .Left =_de .Millimeter (1);_gafg .Bottom =_de .Millimeter (1); -_gafg .Right =_de .Millimeter (1);return _gafg ;};if _gafg .Top ==nil {_gafg .Top =_de .Millimeter (10);};if _gafg .Bottom ==nil {_gafg .Bottom =_de .Millimeter (10);};if _gafg .Left ==nil {_gafg .Left =_de .Millimeter (10);};if _gafg .Right ==nil {_gafg .Right =_de .Millimeter (10); -};return _gafg ;}; +func (_dae *Document )SetMarginTop (margin _ag .Length ){_dae ._gc .Top =margin };func _aaa (_ac _g .Image )float64 {_eacc :=_ac .Bounds ();var (_dfa int ;_gcg _ab .Color ;_dbbc ,_adb ,_afg uint32 ;);_cea ,_aae :=_eacc .Min .X ,_eacc .Max .Y -1;_bcc :=_ac .At (_cea ,_aae ); +_aff ,_aadb ,_egee ,_ :=_bcc .RGBA ();_gcaa :=_aff ==_af .MaxUint16 &&_aadb ==_af .MaxUint16 &&_egee ==_af .MaxUint16 ;for _aae =_eacc .Max .Y -1;_aae >=_eacc .Min .Y ;_aae --{var _age bool ;for _cea =_eacc .Min .X ;_cea < _eacc .Max .X ;_cea ++{_gcg =_ac .At (_cea ,_aae ); +_dbbc ,_adb ,_afg ,_ =_gcg .RGBA ();if (_gcaa &&!(_dbbc ==_aff &&_adb ==_aadb &&_egee ==_afg ))||(!_gcaa &&(_af .Abs (float64 (_dbbc )-float64 (_aff ))/float64 (_af .MaxUint16 )> 0.03||_af .Abs (float64 (_adb )-float64 (_aadb ))/float64 (_af .MaxUint16 )> 0.03||_af .Abs (float64 (_afg )-float64 (_egee ))/float64 (_af .MaxUint16 )> 0.03)){_age =true ; +break ;};};if _age {break ;};_dfa =_aae ;};return float64 (_eacc .Max .Y -_dfa )/float64 (_eacc .Max .Y );};func (_eaeb *Document )getTimeoutDuration ()_fg .Duration {if _eaeb ._fae !=nil {return *_eaeb ._fae ;};return 0;}; -// WriteToFile writes the document to a file defined by the output path. -func (_abd *Document )WriteToFile (outputPath string )error {if _daa :=_abd .validate ();_daa !=nil {return _daa ;};_dbbe :=_fb .Second *20+_abd ._ccgd ;_fgf ,_ade :=_c .WithTimeout (_c .Background (),_dbbe );defer _ade ();_aaf ,_ebc :=_abd .extract (_fgf ,_abd ._ggd ,_abd ._gd ,_abd .getMargins ()); -if _ebc !=nil {return _ebc ;};_eaf :=_dc .New ();for _ ,_dec :=range _aaf {if _ebc =_eaf .AddPage (_dec );_ebc !=nil {return _ebc ;};};return _eaf .WriteToFile (outputPath );}; +// GeneratePageBlocks implements creator.Drawable interface. +func (_df *Document )GeneratePageBlocks (ctx _bg .DrawContext )([]*_bg .Block ,_bg .DrawContext ,error ){if _ecg :=_df .validate ();_ecg !=nil {return nil ,ctx ,_ecg ;};var _bc []*_bg .Block ;_cef :=_df .getMargins ();_eca ,_dbb :=_df ._db ,_df ._gca ; +if _df ._daf .IsRelative (){_eca ,_dbb =_ag .Point (ctx .Width ),_ag .Point (ctx .Height );ctx .X -=float64 (_cef .Left .Points ());};_gb ,_bae :=_df .extract (_e .Background (),_eca ,_dbb ,_cef );if _bae !=nil {return nil ,_bg .DrawContext {},_bae ;}; +for _geg ,_be :=range _gb {_ebe ,_bca :=_bg .NewBlockFromPage (_be );if _bca !=nil {return nil ,_bg .DrawContext {},_bca ;};var _fe float64 ;if _df ._bd &&_geg ==len (_gb )-1{_ca :=_ce .NewImageDevice ();_agc ,_bf :=_ca .Render (_be );if _bf !=nil {return nil ,_bg .DrawContext {},_bf ; +};_aed ,_bf :=_be .GetMediaBox ();if _bf !=nil {return nil ,_bg .DrawContext {},_bf ;};_abf :=_fg .Now ();_bee :=_aaa (_agc );_fe =_aed .Height ()*_bee ;_eab .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_fg .Since (_abf )); +if _df ._gc .Bottom !=nil {_fe -=float64 (_df ._gc .Bottom .Points ());};if _fe < 0{_fe =0;};_eab .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_fe ); +};_aec ,_cc ,_bca :=_ebe .GeneratePageBlocks (ctx );if _bca !=nil {return nil ,_bg .DrawContext {},_bca ;};ctx =_cc ;ctx .Y -=_fe ;if _geg !=len (_gb )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; +ctx .Page ++;};_bc =append (_bc ,_aec ...);};return _bc ,ctx ,nil ;}; -// SetLandscapeOrientation sets document landscape page orientation. -func (_adf *Document )SetLandscapeOrientation (){_adf ._aa =_de .Landscape };func _cae (_ga _d .Image )float64 {_faa :=_ga .Bounds ();var (_ed int ;_cge _e .Color ;_cgd ,_beg ,_daf uint32 ;);_cgc ,_bga :=_faa .Min .X ,_faa .Max .Y -1;_gaf :=_ga .At (_cgc ,_bga ); -_bdg ,_faf ,_begb ,_ :=_gaf .RGBA ();_decb :=_bdg ==_f .MaxUint16 &&_faf ==_f .MaxUint16 &&_begb ==_f .MaxUint16 ;for _bga =_faa .Max .Y -1;_bga >=_faa .Min .Y ;_bga --{var _bf bool ;for _cgc =_faa .Min .X ;_cgc < _faa .Max .X ;_cgc ++{_cge =_ga .At (_cgc ,_bga ); -_cgd ,_beg ,_daf ,_ =_cge .RGBA ();if (_decb &&!(_cgd ==_bdg &&_beg ==_faf &&_begb ==_daf ))||(!_decb &&(_f .Abs (float64 (_cgd )-float64 (_bdg ))/float64 (_f .MaxUint16 )> 0.03||_f .Abs (float64 (_beg )-float64 (_faf ))/float64 (_f .MaxUint16 )> 0.03||_f .Abs (float64 (_daf )-float64 (_begb ))/float64 (_f .MaxUint16 )> 0.03)){_bf =true ; -break ;};};if _bf {break ;};_ed =_bga ;};return float64 (_faa .Max .Y -_ed )/float64 (_faa .Max .Y );};type margins struct{Left ,Right ,Bottom ,Top _de .Length ;}; +// SetPos sets the absolute position. Changes object positioning to absolute. +func (_aeb *Document )SetPos (x ,y float64 ){_aeb ._daf =_bg .PositionAbsolute ;_aeb ._fa =x ;_aeb ._eb =y ;}; -// ContainerComponent implements creator.containerElement interface. -func (_ddg *Document )ContainerComponent (container _dc .Drawable )(_dc .Drawable ,error ){switch container .(type ){case *_dc .Chapter :default:return nil ,_eg .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); -};return _ddg ,nil ;}; +// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. +func (_cg *Document )TrimLastPageContent (){_cg ._bd =true };type margins struct{Left ,Right ,Bottom ,Top _ag .Length ;};func (_ede *Document )getMargins ()margins {_ef :=_ede ._gc ;if _ede ._daf .IsRelative (){_ef .Top =_ag .Millimeter (1);_ef .Left =_ag .Millimeter (1); +_ef .Bottom =_ag .Millimeter (1);_ef .Right =_ag .Millimeter (1);return _ef ;};if _ef .Top ==nil {_ef .Top =_ag .Millimeter (10);};if _ef .Bottom ==nil {_ef .Bottom =_ag .Millimeter (10);};if _ef .Left ==nil {_ef .Left =_ag .Millimeter (10);};if _ef .Right ==nil {_ef .Right =_ag .Millimeter (10); +};return _ef ;}; // Options are the HTML Client options used for establishing the connection. type Options struct{ @@ -77,50 +73,56 @@ Port int ; Secure bool ; // Prefix is an option setting used when the server is working with the URI prefix. Default Value: ''. -Prefix string ;};var _ _dc .Drawable =(*Document )(nil ); +Prefix string ;}; -// SetMarginBottom sets the left margin. -func (_begbg *Document )SetMarginBottom (margin _de .Length ){_begbg ._fe .Bottom =margin }; +// SetTimeoutDuration sets the timeout duration +// the default timeout is 15 seconds. +func (_gcc *Document )SetTimeoutDuration (duration _fg .Duration ){_gcc ._fae =&duration };var ErrContentNotDefined =_ea .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); -// TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. -func (_cac *Document )TrimLastPageContent (){_cac ._ea =true }; -// SetMarginRight sets the left margin. -func (_fed *Document )SetMarginRight (margin _de .Length ){_fed ._fe .Right =margin };func (_eac *Document )validate ()error {if _fcd ==nil {return ErrNoClient ;};if _eac ._fg ==nil {return ErrContentNotDefined ;};return nil ;};var _fcd *_fc .Client ; +// WaitReady waits for the provided selector to be ready. +// A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. +func (_bdd *Document )WaitReady (sel string ,by ..._ge .ByType ){_faef :=_ge .BySearch ;if len (by )> 0{_faef =by [0];};_bdd ._ebc =append (_bdd ._ebc ,_eg .BySelector {Selector :sel ,By :_faef });}; + +// NewDocument creates new HTML Document used as an input for the creator.Drawable. +func NewDocument (path string )(*Document ,error ){_bb :=&Document {};_bgc ,_eabf :=_a .Parse (path );if _eabf !=nil {return nil ,_eabf ;};switch _bgc .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_bb ._egf ,_eabf =_b .NewWebURL (path ); +if _eabf !=nil {return nil ,_eabf ;};return _bb ,nil ;};_ae ,_eabf :=_de .Stat (path );if _eabf !=nil {return nil ,_eabf ;};if !_ae .IsDir (){_bb ._egf ,_eabf =_b .NewHTMLFile (path );}else {_bb ._egf ,_eabf =_b .NewZipDirectory (path );};if _eabf !=nil {return nil ,_eabf ; +};return _bb ,nil ;}; + +// SetLandscapeOrientation sets document landscape page orientation. +func (_eaf *Document )SetLandscapeOrientation (){_eaf ._gg =_ag .Landscape }; // Connect creates UniHTML HTTP Client and tries to establish connection with the server. -func Connect (path string )error {if _ef :=_gg ();_ef !=nil {return _ef ;};_ge ,_dg :=_fc .ParseOptions (path );if _dg !=nil {return _dg ;};_fcd =_fc .New (_ge );_ca ,_ab :=_c .WithTimeout (_c .Background (),_fb .Second *5);defer _ab ();if _eb :=_fcd .HealthCheck (_ca ); -_eb !=nil {return _eb ;};return nil ;}; +func Connect (path string )error {if _da :=_aad ();_da !=nil {return _da ;};_ad ,_aa :=_eg .ParseOptions (path );if _aa !=nil {return _aa ;};_cee =_eg .New (_ad );_ceg ,_fc :=_e .WithTimeout (_e .Background (),_fg .Second *5);defer _fc ();if _ba :=_cee .HealthCheck (_ceg ); +_ba !=nil {return _ba ;};return nil ;}; -// SetPageSize sets the page default size. -func (_cba *Document )SetPageSize (pageSize _de .PageSize )error {if !pageSize .IsAPageSize (){return _cb .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); -};_cba ._feb =pageSize ;_cba ._ccg =_dc .PositionAbsolute ;return nil ;};func (_cebe *Document )extract (_ccc _c .Context ,_bef ,_dga _de .Length ,_ggg margins )([]*_be .PdfPage ,error ){_daca :=_fc .BuildHTMLQuery ().SetContent (_cebe ._fg ).PageSize (_cebe ._feb ).PaperWidth (_bef ).PaperHeight (_dga ).Orientation (_cebe ._aa ).MarginLeft (_ggg .Left ).MarginRight (_ggg .Right ).MarginTop (_ggg .Top ).MarginBottom (_ggg .Bottom ).WaitTime (_cebe ._ccgd ); -for _ ,_eea :=range _cebe ._ccb {_daca .WaitReady (_eea .Selector ,_eea .By );};for _ ,_cef :=range _cebe ._dbf {_daca .WaitVisible (_cef .Selector ,_cef .By );};_fdc ,_fca :=_daca .Query ();if _fca !=nil {return nil ,_fca ;};var _ae _c .CancelFunc ;if _cebe ._fa !=nil {_ccc ,_ae =_c .WithTimeout (_ccc ,*_cebe ._fa ); -}else {_ccc ,_ae =_c .WithTimeout (_ccc ,_fb .Second *15);};defer _ae ();_ege ,_fca :=_fcd .ConvertHTML (_ccc ,_fdc );if _fca !=nil {return nil ,_fca ;};_bcb :=_df .NewReader (_ege .Data );_geb ,_fca :=_be .NewPdfReader (_bcb );if _fca !=nil {return nil ,_fca ; -};return _geb .PageList ,nil ;}; +// WriteToFile writes the document to a file defined by the output path. +func (_dbd *Document )WriteToFile (outputPath string )error {if _adf :=_dbd .validate ();_adf !=nil {return _adf ;};_fcf :=_fg .Second *20+_dbd ._egfb ;_ecd ,_fcfd :=_e .WithTimeout (_e .Background (),_fcf );defer _fcfd ();_fb ,_faa :=_dbd .extract (_ecd ,_dbd ._db ,_dbd ._gca ,_dbd .getMargins ()); +if _faa !=nil {return _faa ;};_ege :=_bg .New ();for _ ,_dbg :=range _fb {if _faa =_ege .AddPage (_dbg );_faa !=nil {return _faa ;};};return _ege .WriteToFile (outputPath );};var ErrNoClient =_ea .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); -// SetTimeoutDuration sets the timeout duration -// the default timeout is 15 seconds. -func (_gbg *Document )SetTimeoutDuration (duration _fb .Duration ){_gbg ._fa =&duration }; + +// Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. +type Document struct{_egf _b .Content ;_gc margins ;_daf _bg .Positioning ;_fa ,_eb float64 ;_geb _ag .PageSize ;_db ,_gca _ag .Length ;_gg _ag .Orientation ;_bd bool ;_egfb _fg .Duration ;_ebc []_eg .BySelector ;_dc []_eg .BySelector ;_fae *_fg .Duration ; +}; // SetPageWidth sets the page width for given document. -func (_ag *Document )SetPageWidth (pageWidth _de .Length )error {_ag ._ggd =pageWidth ;_ag ._ccg =_dc .PositionAbsolute ;return nil ;}; +func (_cbf *Document )SetPageWidth (pageWidth _ag .Length )error {_cbf ._db =pageWidth ;_cbf ._daf =_bg .PositionAbsolute ;return nil ;}; + +// SetMarginRight sets the left margin. +func (_fcb *Document )SetMarginRight (margin _ag .Length ){_fcb ._gc .Right =margin }; + +// SetPageSize sets the page default size. +func (_gcgg *Document )SetPageSize (pageSize _ag .PageSize )error {if !pageSize .IsAPageSize (){return _ea .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); +};_gcgg ._geb =pageSize ;_gcgg ._daf =_bg .PositionAbsolute ;return nil ;}; // GetPdfPages is a function that converts provided input content and -func (_ee *Document )GetPdfPages (ctx _c .Context )([]*_be .PdfPage ,error ){if _cce :=_ee .validate ();_cce !=nil {return nil ,_cce ;};return _ee .extract (ctx ,_ee ._ggd ,_ee ._gd ,_ee .getMargins ());};func _gg ()error {_cc :=_dd .GetLicenseKey ();if _cc ==nil {return _cb .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); -};if !_cc .IsLicensed (){return _cb .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};return nil ;}; +func (_fgb *Document )GetPdfPages (ctx _e .Context )([]*_egd .PdfPage ,error ){if _eac :=_fgb .validate ();_eac !=nil {return nil ,_eac ;};return _fgb .extract (ctx ,_fgb ._db ,_fgb ._gca ,_fgb .getMargins ());}; -// GeneratePageBlocks implements creator.Drawable interface. -func (_dbb *Document )GeneratePageBlocks (ctx _dc .DrawContext )([]*_dc .Block ,_dc .DrawContext ,error ){if _ceb :=_dbb .validate ();_ceb !=nil {return nil ,ctx ,_ceb ;};var _cg []*_dc .Block ;_bg :=_dbb .getMargins ();_dcb ,_fbd :=_dbb ._ggd ,_dbb ._gd ; -if _dbb ._ccg .IsRelative (){_dcb ,_fbd =_de .Point (ctx .Width ),_de .Point (ctx .Height );ctx .X -=float64 (_bg .Left .Points ());};_fbf ,_fbe :=_dbb .extract (_c .Background (),_dcb ,_fbd ,_bg );if _fbe !=nil {return nil ,_dc .DrawContext {},_fbe ;}; -for _bb ,_bd :=range _fbf {_dde ,_da :=_dc .NewBlockFromPage (_bd );if _da !=nil {return nil ,_dc .DrawContext {},_da ;};var _gdf float64 ;if _dbb ._ea &&_bb ==len (_fbf )-1{_def :=_ec .NewImageDevice ();_ddf ,_ddb :=_def .Render (_bd );if _ddb !=nil {return nil ,_dc .DrawContext {},_ddb ; -};_abg ,_ddb :=_bd .GetMediaBox ();if _ddb !=nil {return nil ,_dc .DrawContext {},_ddb ;};_ad :=_fb .Now ();_cgb :=_cae (_ddf );_gdf =_abg .Height ()*_cgb ;_fd .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_fb .Since (_ad )); -if _dbb ._fe .Bottom !=nil {_gdf -=float64 (_dbb ._fe .Bottom .Points ());};if _gdf < 0{_gdf =0;};_fd .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_gdf ); -};_ba ,_fcc ,_da :=_dde .GeneratePageBlocks (ctx );if _da !=nil {return nil ,_dc .DrawContext {},_da ;};ctx =_fcc ;ctx .Y -=_gdf ;if _bb !=len (_fbf )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; -ctx .Page ++;};_cg =append (_cg ,_ba ...);};return _cg ,ctx ,nil ;}; +// SetPageHeight sets the page height for given document. +func (_eda *Document )SetPageHeight (pageHeight _ag .Length )error {_eda ._gca =pageHeight ;_eda ._daf =_bg .PositionAbsolute ;return nil ;};var _ _bg .Drawable =(*Document )(nil );var _cee *_eg .Client ; // SetMarginLeft sets the left margin. -func (_fbdd *Document )SetMarginLeft (margin _de .Length ){_fbdd ._fe .Left =margin }; +func (_gga *Document )SetMarginLeft (margin _ag .Length ){_gga ._gc .Left =margin }; -// WaitTime sets the waiting time before the webpage is rendered to PDF. -func (_cace *Document )WaitTime (duration _fb .Duration ){_cace ._ccgd =duration }; \ No newline at end of file +// SetMarginBottom sets the left margin. +func (_gcb *Document )SetMarginBottom (margin _ag .Length ){_gcb ._gc .Bottom =margin }; \ No newline at end of file