From de38674ce48ab5ac727547a260097a35a5603dee Mon Sep 17 00:00:00 2001 From: UniDoc Build Date: Wed, 24 Mar 2021 00:33:01 +0000 Subject: [PATCH] prepare release --- README.md | 24 ++++- cli/cmd/cmd.go | 65 ++++++------ cli/main.go | 2 +- client/client.go | 223 ++++++++++++++++++++--------------------- common/common.go | 6 +- content/content.go | 48 ++++----- go.mod | 2 +- go.sum | 6 +- sizes/sizes.go | 241 ++++++++++++++++++++++----------------------- unihtml.go | 127 ++++++++++++------------ 10 files changed, 382 insertions(+), 362 deletions(-) diff --git a/README.md b/README.md index e01c2b1..b640e35 100644 --- a/README.md +++ b/README.md @@ -34,10 +34,30 @@ This plugin works in a pair with the UniHTML server. It is distributed using Doc 1. Get UniHTML-Server Docker image: `docker pull unidoccloud/unihtml:latest` -2. Start UniHTML server with some output port defined: `docker run -p 8080:8080 -e UNIHTML_LICENSE=path/to/license unidoccloud/unihtml` +2. Start UniHTML server with some output port defined: + ```shell + docker run -p 8080:8080 -e UNIHTML_LICENSE_PATH=path/to/license -e UNIHTML_CUSTOMER_NAME=customer_name unidoccloud/unihtml + ``` 3. Define environment variable: `UNIPDF_LICENSE_PATH` with the path to the UniDoc license. 4. Define environment variable: `UNIPDF_CUSTOMER_NAME` with your customer name matching your license. -5. Get latest version of the `github.com/unidoc/unipdf/v3` module: `go get github.com/unidoc/unipdf/v3` +5. Get the latest version of the `github.com/unidoc/unipdf/v3` module: `go get github.com/unidoc/unipdf/v3` + +## UniHTML Server Licenses + +UniHTML Server accepts both the offline and metered UniDoc licenses. A license with a UniHTML module is required to run both the server and client. + +### UniHTML Offline License + +A regular license could be set on the server by setting one of two possible environment variables: +- `UNIHTML_LICENSE_PATH` - the value should be the path to the UniDoc license file with the UniHTML module. +- `UNIHTML_LICENSE` - full content of valid UniDoc license with the UniHTML module. + +This license kind requires also an environment variable `UNIHTML_CUSTOMER_NAME` which defines the customer name provided with the UniDoc license. + +### UniDoc Metered License + +UniHTML Server accepts also a UniDoc metered license. This could be set by providing you **API Key** in the environment variable: +- `UNIDOC_METERED_API_KEY` - the value of this variable should be an **API Key** matched to your license. ## Usage diff --git a/cli/cmd/cmd.go b/cli/cmd/cmd.go index 753c347..f1900ce 100644 --- a/cli/cmd/cmd.go +++ b/cli/cmd/cmd.go @@ -9,55 +9,54 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package cmd ;import (_f "context";_e "fmt";_ec "github.com/mitchellh/go-homedir";_ee "github.com/spf13/cobra";_ae "github.com/spf13/viper";_fa "github.com/unidoc/unihtml/client";_ef "github.com/unidoc/unihtml/content";_g "github.com/unidoc/unihtml/sizes"; -_eea "github.com/unidoc/unipdf/v3/common";_a "os";_de "path/filepath";_b "time";);var _dg =&_ee .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 :_fg ,Args :_ee .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"}; - +package cmd ;import (_ec "context";_bb "fmt";_bf "github.com/mitchellh/go-homedir";_f "github.com/spf13/cobra";_be "github.com/spf13/viper";_c "github.com/unidoc/unihtml/client";_bc "github.com/unidoc/unihtml/content";_af "github.com/unidoc/unihtml/sizes"; +_ce "github.com/unidoc/unipdf/v3/common";_ef "os";_a "path/filepath";_b "time";);func _ad (){_bdf :=_ce .LogLevelInfo ;if _fg {_bdf =_ce .LogLevelDebug ;};if _ed {_bdf =_ce .LogLevelTrace ;};_ce .Log =_ce .NewConsoleLogger (_bdf );};var _gca string ;type generateConfig struct{Port int `mapstructure:"port"`; +Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;}; // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. -func Execute (){if _aec :=_fbc .Execute ();_aec !=nil {_e .Println (_aec );_a .Exit (1);};};var _c string ;var _fbc =&_ee .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; -func init (){_fbc .AddCommand (_dg );_dg .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072");_dg .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); -_dg .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); -_dg .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); -_dg .Flags ().Var (&_dfc .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_dg .Flags ().Var (&_dfc .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); -_dg .Flags ().Var (&_dfc .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_dg .Flags ().Var (&_dfc .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); -_dg .Flags ().Var (&_dfc .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_dg .Flags ().Var (&_dfc .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); -_dg .Flags ().Var (&_dfc .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_dg .Flags ().Var (&_dfc .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 _dfd (){_fae :=_eea .LogLevelInfo ;if _ed {_fae =_eea .LogLevelDebug ;};if _fb {_fae =_eea .LogLevelTrace ;};_eea .Log =_eea .NewConsoleLogger (_fae );};type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`; -Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};func _dca (){if _c !=""{_ae .SetConfigFile (_c );}else {_cc ,_gf :=_ec .Dir ();if _gf !=nil {_e .Println (_gf );_a .Exit (1);};_ae .AddConfigPath (_cc );_ae .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063"); -};_ae .AutomaticEnv ();if _ba :=_ae .ReadInConfig ();_ba ==nil {_e .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_ae .ConfigFileUsed ());};};func _fg (cmd *_ee .Command ,_dcc []string ){_def :=_b .Now (); -if _ga :=_ae .BindPFlags (cmd .Flags ());_ga !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ga );_a .Exit (1);};if _gg :=_ae .Unmarshal (&_df );_gg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gg );_a .Exit (1); -};_dfd ();_ggb :=_b .Now ();_bf ,_eg :=_a .Stat (_dcc [0]);if _eg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_eg );_a .Exit (1);};if !_bf .IsDir (){if _de .Ext (_bf .Name ())!="\u002e\u0068\u0074m\u006c"{_e .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_dcc [0]); -_a .Exit (1);};};_bg ,_eg :=_a .OpenFile (_dcc [1],_a .O_CREATE |_a .O_WRONLY |_a .O_TRUNC ,0700);if _eg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_eg );_a .Exit (1);};defer _bg .Close ();_fc :=_fa .New (_fa .Options {HTTPS :_df .Https ,Hostname :_df .Host ,Port :_df .Port ,Prefix :_df .Prefix }); -_fcc ,_gc :=_f .WithTimeout (_f .Background (),_b .Second *10);defer _gc ();_ggb =_b .Now ();var _ege _ef .Content ;if _bf .IsDir (){_ege ,_eg =_ef .NewZipDirectory (_dcc [0]);}else {_ege ,_eg =_ef .NewHTMLFile (_dcc [0]);};if _eg !=nil {_e .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_eg ); -_a .Exit (1);};_aea ,_eg :=_fa .BuildHTMLQuery ().PaperWidth (_dfc .PaperWidth .Length ).PaperHeight (_dfc .PaperHeight .Length ).PageSize (_dfc .PageSize ).MarginTop (_dfc .MarginTop .Length ).MarginBottom (_dfc .MarginBottom .Length ).MarginLeft (_dfc .MarginLeft .Length ).MarginRight (_dfc .MarginRight .Length ).Orientation (_dfc .Orientation ).SetContent (_ege ).Query (); -if _eg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_eg );_a .Exit (1);};_be ,_eg :=_fc .ConvertHTML (_fcc ,_aea );if _eg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_eg );_a .Exit (1);};_eea .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_b .Since (_ggb )); -_ggb =_b .Now ();_ ,_eg =_bg .Write (_be .Data );if _eg !=nil {_e .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_eg );_a .Exit (1);};_eea .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_b .Since (_ggb )); -_e .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_b .Since (_def ));};var (_df =generateConfig {};_dfc =parametersConfig {PaperWidth :_g .LengthFlag {Length :_g .Inch (8.5).Millimeters ()},PaperHeight :_g .LengthFlag {Length :_g .Inch (11).Millimeters ()},Orientation :_g .Portrait ,MarginTop :_g .LengthFlag {Length :_g .Millimeter (10)},MarginBottom :_g .LengthFlag {Length :_g .Millimeter (10)},MarginLeft :_g .LengthFlag {Length :_g .Millimeter (10)},MarginRight :_g .LengthFlag {Length :_g .Millimeter (10)}}; -);func init (){_ee .OnInitialize (_dca );_fbc .PersistentFlags ().BoolVarP (&_ed ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065");_fbc .PersistentFlags ().BoolVarP (&_fb ,"\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"); -_fbc .PersistentFlags ().StringVar (&_c ,"\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"); -_fbc .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};var (_ed ,_fb bool ;);type parametersConfig struct{ +func Execute (){if _ecb :=_dgb .Execute ();_ecb !=nil {_bb .Println (_ecb );_ef .Exit (1);};};func init (){_dgb .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 (&_ge .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 (&_ge .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 (&_ge .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 (&_ge .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 (&_ge .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 (&_ge .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 (&_ge .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 (&_ge .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 _bd (cmd *_f .Command ,_gf []string ){_cd :=_b .Now ();if _gec :=_be .BindPFlags (cmd .Flags ());_gec !=nil {_bb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gec );_ef .Exit (1);};if _gecd :=_be .Unmarshal (&_g );_gecd !=nil {_bb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_gecd ); +_ef .Exit (1);};_ad ();_d :=_b .Now ();_eg ,_ab :=_ef .Stat (_gf [0]);if _ab !=nil {_bb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ab );_ef .Exit (1);};if !_eg .IsDir (){if _a .Ext (_eg .Name ())!="\u002e\u0068\u0074m\u006c"{_bb .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",_gf [0]); +_ef .Exit (1);};};_ced ,_ab :=_ef .OpenFile (_gf [1],_ef .O_CREATE |_ef .O_WRONLY |_ef .O_TRUNC ,0700);if _ab !=nil {_bb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ab );_ef .Exit (1);};defer _ced .Close ();_dg :=_c .New (_c .Options {HTTPS :_g .Https ,Hostname :_g .Host ,Port :_g .Port ,Prefix :_g .Prefix }); +_ba ,_gg :=_ec .WithTimeout (_ec .Background (),_b .Second *10);defer _gg ();_d =_b .Now ();var _ac _bc .Content ;if _eg .IsDir (){_ac ,_ab =_bc .NewZipDirectory (_gf [0]);}else {_ac ,_ab =_bc .NewHTMLFile (_gf [0]);};if _ab !=nil {_bb .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_ab ); +_ef .Exit (1);};_dd ,_ab :=_c .BuildHTMLQuery ().PaperWidth (_ge .PaperWidth .Length ).PaperHeight (_ge .PaperHeight .Length ).PageSize (_ge .PageSize ).MarginTop (_ge .MarginTop .Length ).MarginBottom (_ge .MarginBottom .Length ).MarginLeft (_ge .MarginLeft .Length ).MarginRight (_ge .MarginRight .Length ).Orientation (_ge .Orientation ).SetContent (_ac ).Query (); +if _ab !=nil {_bb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ab );_ef .Exit (1);};_gge ,_ab :=_dg .ConvertHTML (_ba ,_dd );if _ab !=nil {_bb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ab );_ef .Exit (1);};_ce .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_b .Since (_d )); +_d =_b .Now ();_ ,_ab =_ced .Write (_gge .Data );if _ab !=nil {_bb .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ab );_ef .Exit (1);};_ce .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_b .Since (_d )); +_bb .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_b .Since (_cd ));};var (_fg ,_ed bool ;);type parametersConfig struct{ // PaperWidth sets the width of the paper. -PaperWidth _g .LengthFlag `mapstructure:"paper-width"`; +PaperWidth _af .LengthFlag `mapstructure:"paper-width"`; // PaperHeight is the height of the output paper. -PaperHeight _g .LengthFlag `mapstructure:"paper-height"`; +PaperHeight _af .LengthFlag `mapstructure:"paper-height"`; // PageSize is the page size string. -PageSize _g .PageSize `mapstructure:"page-size"`; +PageSize _af .PageSize `mapstructure:"page-size"`; // Orientation defines if the output should be in a landscape format. -Orientation _g .Orientation `mapstructure:"orientation"`; +Orientation _af .Orientation `mapstructure:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _g .LengthFlag `mapstructure:"margin-top"`; +MarginTop _af .LengthFlag `mapstructure:"margin-top"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _g .LengthFlag `mapstructure:"margin-bottom"`; +MarginBottom _af .LengthFlag `mapstructure:"margin-bottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _g .LengthFlag `mapstructure:"margin-left"`; +MarginLeft _af .LengthFlag `mapstructure:"margin-left"`; // MarginRight sets up the Right Margin for the output. -MarginRight _g .LengthFlag `mapstructure:"margin-right"`;}; \ No newline at end of file +MarginRight _af .LengthFlag `mapstructure:"margin-right"`;};func _ee (){if _gca !=""{_be .SetConfigFile (_gca );}else {_daf ,_cdd :=_bf .Dir ();if _cdd !=nil {_bb .Println (_cdd );_ef .Exit (1);};_be .AddConfigPath (_daf );_be .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063"); +};_be .AutomaticEnv ();if _afa :=_be .ReadInConfig ();_afa ==nil {_bb .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_be .ConfigFileUsed ());};};var (_g =generateConfig {};_ge =parametersConfig {PaperWidth :_af .LengthFlag {Length :_af .Inch (8.5).Millimeters ()},PaperHeight :_af .LengthFlag {Length :_af .Inch (11).Millimeters ()},Orientation :_af .Portrait ,MarginTop :_af .LengthFlag {Length :_af .Millimeter (10)},MarginBottom :_af .LengthFlag {Length :_af .Millimeter (10)},MarginLeft :_af .LengthFlag {Length :_af .Millimeter (10)},MarginRight :_af .LengthFlag {Length :_af .Millimeter (10)}}; +);func init (){_f .OnInitialize (_ee );_dgb .PersistentFlags ().BoolVarP (&_fg ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065");_dgb .PersistentFlags ().BoolVarP (&_ed ,"\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"); +_dgb .PersistentFlags ().StringVar (&_gca ,"\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"); +_dgb .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};var _fa =&_f .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 :_bd ,Args :_f .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 _dgb =&_f .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; diff --git a/cli/main.go b/cli/main.go index f0b00cc..9f8b2c2 100644 --- a/cli/main.go +++ b/cli/main.go @@ -9,4 +9,4 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package main ;import _g "github.com/unidoc/unihtml/cli/cmd";func main (){_g .Execute ()}; \ No newline at end of file +package main ;import _cc "github.com/unidoc/unihtml/cli/cmd";func main (){_cc .Execute ()}; \ No newline at end of file diff --git a/client/client.go b/client/client.go index 0fb6a46..c37ede6 100644 --- a/client/client.go +++ b/client/client.go @@ -11,163 +11,164 @@ // 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 (_dc "bytes";_d "compress/flate";_f "compress/gzip";_bc "context";_aa "errors";_dcd "fmt";_da "github.com/unidoc/unihtml/content";_fa "github.com/unidoc/unihtml/sizes";_e "github.com/unidoc/unipdf/v3/common";_ff "golang.org/x/xerrors"; -_a "io/ioutil";_g "net";_ba "net/http";_cc "net/url";_bcb "strconv";_ae "strings";_c "time";); +package client ;import (_eb "bytes";_b "compress/flate";_c "compress/gzip";_f "context";_ee "errors";_eafc "fmt";_db "github.com/unidoc/unihtml/content";_dc "github.com/unidoc/unihtml/sizes";_bd "github.com/unidoc/unipdf/v3/common";_dg "golang.org/x/xerrors"; +_ea "io/ioutil";_d "net";_eaf "net/http";_a "net/url";_fc "strconv";_cb "strings";_ef "time";); -// Landscape sets up the landscape portrait orientation. -func (_ab *QueryBuilder )Landscape ()*QueryBuilder {_ab ._cea .PageParameters .Orientation =_fa .Landscape ;return _ab ;}; +// New creates new client with provided options. +func New (o Options )*Client {o .DefaultTimeout =_ef .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _ag =&_eaf .Transport {DialContext :(&_d .Dialer {Timeout :5*_ef .Second }).DialContext ,TLSHandshakeTimeout :5*_ef .Second }; +_bd .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_eaf .Client {Transport :_ag ,Timeout :o .DefaultTimeout }};}; -// Orientation sets the page orientation for the Query. -func (_bgg *QueryBuilder )Orientation (orientation _fa .Orientation )*QueryBuilder {_bgg ._cea .PageParameters .Orientation =orientation ;return _bgg ;}; +// Client is a structure that is a HTTP client for the unihtml server. +type Client struct{Options Options ;Client *_eaf .Client ;}; -// PDFResponse is the response used by the HTMLConverter. -type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; +// Err gets the error which could occur in the query. +func (_aad *QueryBuilder )Err ()error {return _aad ._fd }; -// New creates new client with provided options. -func New (o Options )*Client {o .DefaultTimeout =_c .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _bad =&_ba .Transport {DialContext :(&_g .Dialer {Timeout :5*_c .Second }).DialContext ,TLSHandshakeTimeout :5*_c .Second }; -_e .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_ba .Client {Transport :_bad ,Timeout :o .DefaultTimeout }};}; +// Validate checks if the parameters are valid. +func (_af *PageParameters )Validate ()error {if _af .PaperWidth !=nil {if _af .PaperWidth .Millimeters ()< 0{return _ee .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); +};};if _af .PaperHeight !=nil {if _af .PaperHeight .Millimeters ()< 0{return _ee .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); +};};if _af .MarginTop !=nil {if _af .MarginTop .Millimeters ()< 0{return _ee .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _af .MarginBottom !=nil {if _af .MarginBottom .Millimeters ()< 0{return _ee .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); +};};if _af .MarginLeft !=nil {if _af .MarginLeft .Millimeters ()< 0{return _ee .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};}; +if _af .MarginRight !=nil {if _af .MarginRight .Millimeters ()< 0{return _ee .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); +};};if _af .PageSize !=nil &&!_af .PageSize .IsAPageSize (){return _ee .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; -// ParseOptions parses options for the Client. -func ParseOptions (connectPath string )(Options ,error ){if !_ae .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_aeg ,_ee :=_cc .Parse (connectPath );if _ee !=nil {return Options {},_ff .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 _af int ;if _aeg .Port ()!=""{_af ,_ee =_bcb .Atoi (_aeg .Port ());if _ee !=nil {return Options {},_ff .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_ee ); -};};return Options {Hostname :_aeg .Hostname (),Port :_af ,HTTPS :_aeg .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_aeg .Path },nil ;}; +// HealthCheck connects to the server and check the health status of the server. +func (_cd *Client )HealthCheck (ctx _f .Context )error {_aa :=_cd .Options .Addr ();_aa =_eafc .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_aa );_bdg ,_cc :=_eaf .NewRequest ("\u0047\u0045\u0054",_aa ,nil );if _cc !=nil {return _cc ;};_bdg =_bdg .WithContext (ctx ); +_dbg ,_cc :=_cd .Client .Do (_bdg );if _cc !=nil {return _cc ;};switch _dbg .StatusCode {case _eaf .StatusOK :return nil ;case _eaf .StatusNotFound :return ErrNotFound ;case _eaf .StatusInternalServerError :return ErrInternalError ;case _eaf .StatusBadGateway :return ErrBadGateway ; +default:return ErrNotImplemented ;};};func (_eeg *Client )getRequest (_eeb _f .Context ,_ff *Query )(*_eaf .Request ,error ){_gg :=_eeg .Options .Addr ();_gg =_eafc .Sprintf ("\u0025\u0073\u002f\u0070\u0064\u0066",_gg );_cg ,_dgg :=_eaf .NewRequest ("\u0050\u004f\u0053\u0054",_gg ,_eb .NewReader (_ff .Data )); +if _dgg !=nil {return nil ,_dgg ;};_cg .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065",_ff .ContentType );_cg .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"); +_cg =_cg .WithContext (_eeb );_gf :=_cg .URL .Query ();_ad :=_ff .PageParameters ;if _ad .PageSize !=nil {_gf .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_ad .PageSize .String ());};if _ad .PaperHeight !=nil {_gf .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_ad .PaperHeight .String ()); +};if _ad .PaperWidth !=nil {_gf .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_ad .PaperWidth .String ());};if _ad .MarginTop !=nil {_gf .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_ad .MarginTop .String ()); +};if _ad .MarginBottom !=nil {_gf .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_ad .MarginBottom .String ());};if _ad .MarginRight !=nil {_gf .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_ad .MarginRight .String ()); +};if _ad .MarginLeft !=nil {_gf .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_ad .MarginLeft .String ());};if _ad .Orientation ==_dc .Landscape {_gf .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_ad .Orientation .String ()); +};_cg .URL .RawQuery =_gf .Encode ();return _cg ,nil ;}; -// WithPrefix sets the client prefix. -func WithPrefix (prefix string )Option {return func (_be *Options ){_be .Prefix =prefix }}; +// WithHTTPS sets the TLS option for the client options. +func WithHTTPS (useHTTPS bool )Option {return func (_cga *Options ){_cga .HTTPS =useHTTPS }}; + +// Options are the client options used by the HTTP client. +type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _ef .Duration ;Prefix string ;}; + +// Orientation sets the page orientation for the Query. +func (_dga *QueryBuilder )Orientation (orientation _dc .Orientation )*QueryBuilder {_dga ._ca .PageParameters .Orientation =orientation ;return _dga ;}; // BuildHTMLQuery creates a Query builder that is supposed to create valid func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; -// QueryBuilder is the query that converts HTMLConverter defined data -type QueryBuilder struct{_cea Query ;_bf error ;};var (ErrNotFound =_aa .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_aa .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074");ErrNotImplemented =_aa .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064"); -ErrInternalError =_aa .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_aa .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079");); +// MarginLeft sets up the MarginLeft parameter for the query. +func (_fe *QueryBuilder )MarginLeft (marginLeft _dc .Length )*QueryBuilder {_fe ._ca .PageParameters .MarginLeft =marginLeft ;return _fe ;}; -// Err gets the error which could occur in the query. -func (_fg *QueryBuilder )Err ()error {return _fg ._bf }; +// Validate checks if the QueryBuilder had no errors during composition and creation. +func (_aac *QueryBuilder )Validate ()error {if _aac ._fd !=nil {return _aac ._fd ;};return _aac ._ca .Validate ();}; -// MarginRight sets up the MarginRight parameter for the query. -func (_baae *QueryBuilder )MarginRight (marginRight _fa .Length )*QueryBuilder {_baae ._cea .PageParameters .MarginRight =marginRight ;return _baae ;}; +// Portrait sets up the portrait page orientation. +func (_bb *QueryBuilder )Portrait ()*QueryBuilder {_bb ._ca .PageParameters .Orientation =_dc .Portrait ;return _bb ;}; -// SetContent sets custom data with it's content type. -func (_ad *QueryBuilder )SetContent (content _da .Content )*QueryBuilder {if _ad ._bf !=nil {return _ad ;};if _ad ._cea .ContentType !=""{_ad ._bf =ErrContentTypeDeclared ;return _ad ;};if content .ContentType ()==""{_ad ._bf =_ff .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 _ad ;};_ad ._cea .Data =content .Data ();_ad ._cea .ContentType =content .ContentType ();return _ad ;}; +// PaperHeight sets up the PaperHeight (in cm) parameter for the query. +func (_cef *QueryBuilder )PaperHeight (paperHeight _dc .Length )*QueryBuilder {_cef ._ca .PageParameters .PaperHeight =paperHeight ;return _cef ;}; -// PaperWidth sets up the PaperWidth (in cm) parameter for the query. -func (_de *QueryBuilder )PaperWidth (paperWidth _fa .Length )*QueryBuilder {_de ._cea .PageParameters .PaperWidth =paperWidth ;return _de ;}; +// WithDefaultTimeout sets the DefaultTimeout option for the client options. +func WithDefaultTimeout (option _ef .Duration )Option {return func (_cbd *Options ){_cbd .DefaultTimeout =option };}; -// PageSize sets up the PageSize parameter for the query. -func (_df *QueryBuilder )PageSize (pageSize _fa .PageSize )*QueryBuilder {if pageSize !=_fa .Undefined {_df ._cea .PageParameters .PageSize =&pageSize ;};return _df ;}; +// Option is a function that changes client options. +type Option func (_adb *Options ); -// Validate checks if the parameters are valid. -func (_eg *PageParameters )Validate ()error {if _eg .PaperWidth !=nil {if _eg .PaperWidth .Millimeters ()< 0{return _aa .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 _eg .PaperHeight !=nil {if _eg .PaperHeight .Millimeters ()< 0{return _aa .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 _eg .MarginTop !=nil {if _eg .MarginTop .Millimeters ()< 0{return _aa .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 _eg .MarginBottom !=nil {if _eg .MarginBottom .Millimeters ()< 0{return _aa .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 _eg .MarginLeft !=nil {if _eg .MarginLeft .Millimeters ()< 0{return _aa .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 _eg .MarginRight !=nil {if _eg .MarginRight .Millimeters ()< 0{return _aa .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 _eg .PageSize !=nil &&!_eg .PageSize .IsAPageSize (){return _aa .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; +// DefaultPageParameters creates default parameters. +func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_dc .Portrait }}; -// ConvertHTML converts provided Query input into PDF file data. -// Implements creator.HTMLConverter interface. -func (_ce *Client )ConvertHTML (ctx _bc .Context ,q *Query )(*PDFResponse ,error ){if _cb :=q .Validate ();_cb !=nil {return nil ,_cb ;};_bb ,_bg :=_ce .getRequest (ctx ,q );if _bg !=nil {return nil ,_bg ;};_e .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 ()); -_ea ,_bg :=_ce .Client .Do (_bb );if _bg !=nil {return nil ,_bg ;};var _dcc error ;switch _ea .StatusCode {case _ba .StatusNotFound :_dcc =ErrNotFound ;case _ba .StatusBadRequest :_dcc =ErrBadRequest ;case _ba .StatusNotImplemented :_dcc =ErrNotImplemented ; -case _ba .StatusCreated :default:_dcc =ErrInternalError ;};_gg :=_ea .Body ;switch _ea .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_gg ,_bg =_f .NewReader (_ea .Body ); -if _bg !=nil {return nil ,_bg ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_gg =_d .NewReader (_ea .Body );case "":default:return nil ,_dcd .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",_ea .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); -};_dcg ,_bg :=_a .ReadAll (_gg );if _bg !=nil &&_dcc ==nil {return nil ,_bg ;};_e .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_ea .StatusCode ,_bb .Method ,_bb .URL .Host ,_bb .URL .Path );if _dcc !=nil {return nil ,_dcd .Errorf ("\u0025\u0073\u0020%\u0077",string (_dcg ),_dcc ); -};_dg :=_ea .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_e .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_dg );return &PDFResponse {ID :_dg ,Data :_dcg },nil ;};var (ErrMissingData =_aa .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061"); -ErrContentType =_aa .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065");ErrContentTypeDeclared =_aa .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064"); -); +// WithPort sets the Port option for the client options. +func WithPort (option int )Option {return func (_efbc *Options ){_efbc .Port =option }}; -// HealthCheck connects to the server and check the health status of the server. -func (_ac *Client )HealthCheck (ctx _bc .Context )error {_dca :=_ac .Options .Addr ();_dca =_dcd .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_dca );_ag ,_bd :=_ba .NewRequest ("\u0047\u0045\u0054",_dca ,nil );if _bd !=nil {return _bd ;};_ag =_ag .WithContext (ctx ); -_cf ,_bd :=_ac .Client .Do (_ag );if _bd !=nil {return _bd ;};switch _cf .StatusCode {case _ba .StatusOK :return nil ;case _ba .StatusNotFound :return ErrNotFound ;case _ba .StatusInternalServerError :return ErrInternalError ;case _ba .StatusBadGateway :return ErrBadGateway ; -default:return ErrNotImplemented ;};}; +// MarginBottom sets up the MarginBottom parameter for the query. +func (_efb *QueryBuilder )MarginBottom (marginBottom _dc .Length )*QueryBuilder {_efb ._ca .PageParameters .MarginBottom =marginBottom ;return _efb ;}; -// WithHostname sets the Hostname option for the client options. -func WithHostname (option string )Option {return func (_afb *Options ){_afb .Hostname =option }}; +// PDFResponse is the response used by the HTMLConverter. +type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; -// Validate checks if the QueryBuilder had no errors during composition and creation. -func (_aab *QueryBuilder )Validate ()error {if _aab ._bf !=nil {return _aab ._bf ;};return _aab ._cea .Validate ();}; +// Landscape sets up the landscape portrait orientation. +func (_cf *QueryBuilder )Landscape ()*QueryBuilder {_cf ._ca .PageParameters .Orientation =_dc .Landscape ;return _cf ;}; + +// MarginTop sets up the MarginTop parameter for the query. +func (_ga *QueryBuilder )MarginTop (marginTop _dc .Length )*QueryBuilder {_ga ._ca .PageParameters .MarginTop =marginTop ;return _ga ;}; + +// PaperWidth sets up the PaperWidth (in cm) parameter for the query. +func (_da *QueryBuilder )PaperWidth (paperWidth _dc .Length )*QueryBuilder {_da ._ca .PageParameters .PaperWidth =paperWidth ;return _da ;};var (ErrMissingData =_ee .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061"); +ErrContentType =_ee .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065");ErrContentTypeDeclared =_ee .New ("\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u0073 \u0061l\u0072\u0065\u0061\u0064\u0079\u0020\u0064\u0065\u0063\u006c\u0061\u0072\u0065\u0064"); +); // Addr gets the HTTP address URI used by the http.Client. -func (_fe *Options )Addr ()string {_dce :=_ae .Builder {};_dce .WriteString ("\u0068\u0074\u0074\u0070");if _fe .HTTPS {_dce .WriteRune ('s');};_dce .WriteString ("\u003a\u002f\u002f");_dce .WriteString (_fe .Hostname );_dce .WriteRune (':');_dce .WriteString (_bcb .Itoa (_fe .Port )); -if _fe .Prefix !=""{_dce .WriteString (_fe .Prefix );};return _dce .String ();}; +func (_ae *Options )Addr ()string {_aacf :=_cb .Builder {};_aacf .WriteString ("\u0068\u0074\u0074\u0070");if _ae .HTTPS {_aacf .WriteRune ('s');};_aacf .WriteString ("\u003a\u002f\u002f");_aacf .WriteString (_ae .Hostname );_aacf .WriteRune (':');_aacf .WriteString (_fc .Itoa (_ae .Port )); +if _ae .Prefix !=""{_aacf .WriteString (_ae .Prefix );};return _aacf .String ();}; -// WithPort sets the Port option for the client options. -func WithPort (option int )Option {return func (_ggg *Options ){_ggg .Port =option }}; +// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. +type Query struct{Data []byte ;ContentType string ;PageParameters PageParameters ;}; -// MarginTop sets up the MarginTop parameter for the query. -func (_ead *QueryBuilder )MarginTop (marginTop _fa .Length )*QueryBuilder {_ead ._cea .PageParameters .MarginTop =marginTop ;return _ead ;}; +// QueryBuilder is the query that converts HTMLConverter defined data +type QueryBuilder struct{_ca Query ;_fd error ;}; -// MarginLeft sets up the MarginLeft parameter for the query. -func (_eb *QueryBuilder )MarginLeft (marginLeft _fa .Length )*QueryBuilder {_eb ._cea .PageParameters .MarginLeft =marginLeft ;return _eb ;}; +// MarginRight sets up the MarginRight parameter for the query. +func (_dbe *QueryBuilder )MarginRight (marginRight _dc .Length )*QueryBuilder {_dbe ._ca .PageParameters .MarginRight =marginRight ;return _dbe ;}; + +// WithHostname sets the Hostname option for the client options. +func WithHostname (option string )Option {return func (_ba *Options ){_ba .Hostname =option }}; + +// Validate checks if provided Query is valid. +func (_aab *Query )Validate ()error {if len (_aab .Data )==0{return ErrMissingData ;};if _aab .ContentType ==""{return ErrContentType ;};if _aga :=_aab .PageParameters .Validate ();_aga !=nil {return _aga ;};return nil ;}; + +// SetContent sets custom data with it's content type. +func (_bee *QueryBuilder )SetContent (content _db .Content )*QueryBuilder {if _bee ._fd !=nil {return _bee ;};if _bee ._ca .ContentType !=""{_bee ._fd =ErrContentTypeDeclared ;return _bee ;};if content .ContentType ()==""{_bee ._fd =_dg .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 _bee ;};_bee ._ca .Data =content .Data ();_bee ._ca .ContentType =content .ContentType ();return _bee ;}; + +// WithPrefix sets the client prefix. +func WithPrefix (prefix string )Option {return func (_eab *Options ){_eab .Prefix =prefix }}; + +// ParseOptions parses options for the Client. +func ParseOptions (connectPath string )(Options ,error ){if !_cb .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_g ,_be :=_a .Parse (connectPath );if _be !=nil {return Options {},_dg .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 _eff int ;if _g .Port ()!=""{_eff ,_be =_fc .Atoi (_g .Port ());if _be !=nil {return Options {},_dg .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_be ); +};};return Options {Hostname :_g .Hostname (),Port :_eff ,HTTPS :_g .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_g .Path },nil ;}; // 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 _dcf :=_cd .Validate ();_dcf !=nil {return nil ,_dcf ;};return &_cd ._cea ,nil ;};func (_fb *Client )getRequest (_baa _bc .Context ,_dcgc *Query )(*_ba .Request ,error ){_bcc :=_fb .Options .Addr (); -_bcc =_dcd .Sprintf ("\u0025\u0073\u002f\u0070\u0064\u0066",_bcc );_gf ,_ef :=_ba .NewRequest ("\u0050\u004f\u0053\u0054",_bcc ,_dc .NewReader (_dcgc .Data ));if _ef !=nil {return nil ,_ef ;};_gf .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065",_dcgc .ContentType ); -_gf .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"); -_gf =_gf .WithContext (_baa );_bga :=_gf .URL .Query ();_bbd :=_dcgc .PageParameters ;if _bbd .PageSize !=nil {_bga .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_bbd .PageSize .String ());};if _bbd .PaperHeight !=nil {_bga .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_bbd .PaperHeight .String ()); -};if _bbd .PaperWidth !=nil {_bga .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_bbd .PaperWidth .String ());};if _bbd .MarginTop !=nil {_bga .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_bbd .MarginTop .String ()); -};if _bbd .MarginBottom !=nil {_bga .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_bbd .MarginBottom .String ());};if _bbd .MarginRight !=nil {_bga .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_bbd .MarginRight .String ()); -};if _bbd .MarginLeft !=nil {_bga .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_bbd .MarginLeft .String ());};if _bbd .Orientation ==_fa .Landscape {_bga .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_bbd .Orientation .String ()); -};_gf .URL .RawQuery =_bga .Encode ();return _gf ,nil ;}; - -// WithDefaultTimeout sets the DefaultTimeout option for the client options. -func WithDefaultTimeout (option _c .Duration )Option {return func (_efd *Options ){_efd .DefaultTimeout =option };}; +func (_agad *QueryBuilder )Query ()(*Query ,error ){if _dcb :=_agad .Validate ();_dcb !=nil {return nil ,_dcb ;};return &_agad ._ca ,nil ;};var (ErrNotFound =_ee .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_ee .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); +ErrNotImplemented =_ee .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_ee .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_ee .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079"); +ErrUnauthorized =_ee .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");); // PageParameters are the query parameters used in the PDF generation. type PageParameters struct{ // PaperWidth sets the width of the paper. -PaperWidth _fa .Length `schema:"paper-width" json:"paperWidth"`; +PaperWidth _dc .Length `schema:"paper-width" json:"paperWidth"`; // PaperHeight is the height of the output paper. -PaperHeight _fa .Length `schema:"paper-height" json:"paperHeight"`; +PaperHeight _dc .Length `schema:"paper-height" json:"paperHeight"`; // PageSize is the page size string. -PageSize *_fa .PageSize `schema:"page-size" json:"pageSize"`; +PageSize *_dc .PageSize `schema:"page-size" json:"pageSize"`; // Orientation defines if the output should be in a landscape format. -Orientation _fa .Orientation `schema:"orientation" json:"orientation"`; +Orientation _dc .Orientation `schema:"orientation" json:"orientation"`; // MarginTop sets up the Top Margin for the output. -MarginTop _fa .Length `schema:"margin-top" json:"marginTop"`; +MarginTop _dc .Length `schema:"margin-top" json:"marginTop"`; // MarginBottom sets up the Bottom Margin for the output. -MarginBottom _fa .Length `schema:"margin-bottom" json:"marginBottom"`; +MarginBottom _dc .Length `schema:"margin-bottom" json:"marginBottom"`; // MarginLeft sets up the Left Margin for the output. -MarginLeft _fa .Length `schema:"margin-left" json:"marginLeft"`; +MarginLeft _dc .Length `schema:"margin-left" json:"marginLeft"`; // MarginRight sets up the Right Margin for the output. -MarginRight _fa .Length `schema:"margin-right" json:"marginRight"`;}; +MarginRight _dc .Length `schema:"margin-right" json:"marginRight"`;}; -// PaperHeight sets up the PaperHeight (in cm) parameter for the query. -func (_cdc *QueryBuilder )PaperHeight (paperHeight _fa .Length )*QueryBuilder {_cdc ._cea .PageParameters .PaperHeight =paperHeight ;return _cdc ;}; - -// DefaultPageParameters creates default parameters. -func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_fa .Portrait }}; - -// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. -type Query struct{Data []byte ;ContentType string ;PageParameters PageParameters ;}; - -// MarginBottom sets up the MarginBottom parameter for the query. -func (_cbb *QueryBuilder )MarginBottom (marginBottom _fa .Length )*QueryBuilder {_cbb ._cea .PageParameters .MarginBottom =marginBottom ;return _cbb ;}; - -// Option is a function that changes client options. -type Option func (_ffg *Options ); - -// WithHTTPS sets the TLS option for the client options. -func WithHTTPS (useHTTPS bool )Option {return func (_cfe *Options ){_cfe .HTTPS =useHTTPS }}; - -// Client is a structure that is a HTTP client for the unihtml server. -type Client struct{Options Options ;Client *_ba .Client ;}; - -// Validate checks if provided Query is valid. -func (_acd *Query )Validate ()error {if len (_acd .Data )==0{return ErrMissingData ;};if _acd .ContentType ==""{return ErrContentType ;};if _baag :=_acd .PageParameters .Validate ();_baag !=nil {return _baag ;};return nil ;}; - -// Options are the client options used by the HTTP client. -type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _c .Duration ;Prefix string ;}; +// PageSize sets up the PageSize parameter for the query. +func (_gc *QueryBuilder )PageSize (pageSize _dc .PageSize )*QueryBuilder {if pageSize !=_dc .Undefined {_gc ._ca .PageParameters .PageSize =&pageSize ;};return _gc ;}; -// Portrait sets up the portrait page orientation. -func (_cfd *QueryBuilder )Portrait ()*QueryBuilder {_cfd ._cea .PageParameters .Orientation =_fa .Portrait ;return _cfd ;}; \ No newline at end of file +// ConvertHTML converts provided Query input into PDF file data. +// Implements creator.HTMLConverter interface. +func (_ec *Client )ConvertHTML (ctx _f .Context ,q *Query )(*PDFResponse ,error ){if _cde :=q .Validate ();_cde !=nil {return nil ,_cde ;};_ebb ,_agd :=_ec .getRequest (ctx ,q );if _agd !=nil {return nil ,_agd ;};_bd .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",_ebb .Method ,_ebb .URL .Hostname (),_ebb .URL .Path ,_ebb .Header ,_ebb .URL .Query ()); +_bdc ,_agd :=_ec .Client .Do (_ebb );if _agd !=nil {return nil ,_agd ;};var _ce error ;switch _bdc .StatusCode {case _eaf .StatusNotFound :_ce =ErrNotFound ;case _eaf .StatusBadRequest :_ce =ErrBadRequest ;case _eaf .StatusNotImplemented :_ce =ErrNotImplemented ; +case _eaf .StatusUnauthorized :_ce =ErrUnauthorized ;case _eaf .StatusCreated :default:_ce =ErrInternalError ;};_eg :=_bdc .Body ;switch _bdc .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_eg ,_agd =_c .NewReader (_bdc .Body ); +if _agd !=nil {return nil ,_agd ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_eg =_b .NewReader (_bdc .Body );case "":default:return nil ,_eafc .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",_bdc .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); +};_bdgb ,_agd :=_ea .ReadAll (_eg );if _agd !=nil &&_ce ==nil {return nil ,_eafc .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_agd );};_bd .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_bdc .StatusCode ,_ebb .Method ,_ebb .URL .Host ,_ebb .URL .Path ); +if _ce !=nil {return nil ,_eafc .Errorf ("\u0025\u0073\u0020%\u0077",string (_bdgb ),_ce );};_df :=_bdc .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_bd .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_df ); +return &PDFResponse {ID :_df ,Data :_bdgb },nil ;}; \ No newline at end of file diff --git a/common/common.go b/common/common.go index 4318b81..6bfa89b 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 _a "time";const _c ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";const _bd =22;const Version ="\u0030\u002e\u0032.\u0030";const _ce =12;const _bdc =20; -var ReleasedAt =_a .Date (_b ,_cd ,_bd ,_ce ,_bdc ,0,0,_a .UTC ); +package common ;import _e "time";const _f ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";var ReleasedAt =_e .Date (_ac ,_b ,_bg ,_ba ,_ad ,0,0,_e .UTC );const _ba =12; + // UtcTimeFormat returns a formatted string describing a UTC timestamp. -func UtcTimeFormat (t _a .Time )string {return t .Format (_c )+"\u0020\u0055\u0054\u0043"};const _b =2021;const _cd =2; \ No newline at end of file +func UtcTimeFormat (t _e .Time )string {return t .Format (_f )+"\u0020\u0055\u0054\u0043"};const _ac =2021;const Version ="\u0030\u002e\u0033.\u0030";const _bg =23;const _ad =20;const _b =3; \ No newline at end of file diff --git a/content/content.go b/content/content.go index 2a043d7..d72cb23 100644 --- a/content/content.go +++ b/content/content.go @@ -9,41 +9,41 @@ // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ -package content ;import (_e "archive/zip";_ba "bytes";_de "encoding/json";_db "golang.org/x/xerrors";_a "io/ioutil";_b "net/url";_eb "os";_eg "strings";);type zipDirectory struct{_bdd _ba .Buffer ;_dc *_e .Writer ;}; +package content ;import (_f "archive/zip";_ca "bytes";_fc "encoding/json";_a "golang.org/x/xerrors";_g "io/ioutil";_bd "net/url";_d "os";_b "strings";); // NewHTMLFile creates new Content htmFile for provided input path. -func NewHTMLFile (path string )(Content ,error ){_f ,_bf :=_eb .Open (path );if _bf !=nil {return nil ,_bf ;};_bc :=&htmFile {_g :_ba .Buffer {}};if _ ,_bf =_bc ._g .ReadFrom (_f );_bf !=nil {return nil ,_bf ;};return _bc ,nil ;}; - -// Data implements Content interface. -func (_ga *webURL )Data ()[]byte {return _ga ._bd };type htmFile struct{_g _ba .Buffer }; - -// ContentType implements Content interface. -func (_ae *htmFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; +func NewHTMLFile (path string )(Content ,error ){_cad ,_ag :=_d .Open (path );if _ag !=nil {return nil ,_ag ;};_df :=&htmFile {_cf :_ca .Buffer {}};if _ ,_ag =_df ._cf .ReadFrom (_cad );_ag !=nil {return nil ,_ag ;};return _df ,nil ;}; // ContentType implements Content interface. -func (_bab *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";};type webURL struct{_bg string ;_bd []byte ;}; +func (_ce *webURL )ContentType ()string {return "\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e";}; // NewWebURL creates new Content webURL for provided input URL path. -func NewWebURL (path string )(Content ,error ){if _ ,_dec :=_b .Parse (path );_dec !=nil {return nil ,_dec ;};type urlOutput struct{URL string `json:"url"`;};_ac :=urlOutput {URL :path };_bad ,_ab :=_de .Marshal (_ac );if _ab !=nil {return nil ,_ab ;}; -return &webURL {_bg :path ,_bd :_bad },nil ;}; +func NewWebURL (path string )(Content ,error ){if _ ,_aa :=_bd .Parse (path );_aa !=nil {return nil ,_aa ;};type urlOutput struct{URL string `json:"url"`;};_cb :=urlOutput {URL :path };_e ,_ae :=_fc .Marshal (_cb );if _ae !=nil {return nil ,_ae ;};return &webURL {_bb :path ,_fg :_e },nil ; +};type webURL struct{_bb string ;_fg []byte ;}; // Data implements Content interface. -func (_ef *zipDirectory )Data ()[]byte {return _ef ._bdd .Bytes ()};func (_eaf *zipDirectory )zipBasePaths (_gb _eb .FileInfo ,_bdg ,_dae string ,_ad bool ,_dcd *_eg .Builder )(string ,string ){_dcd .WriteString (_bdg );if !_eg .HasSuffix (_bdg ,"\u002f"){_dcd .WriteRune ('/'); -};_dcd .WriteString (_gb .Name ());if _ad {_dcd .WriteRune ('/');};_gacc :=_dcd .String ();_dcd .Reset ();_dcd .WriteString (_dae );_dcd .WriteString (_gb .Name ());if _ad {_dcd .WriteRune ('/');};_fe :=_dcd .String ();_dcd .Reset ();return _gacc ,_fe ; -}; +func (_ggd *webURL )Data ()[]byte {return _ggd ._fg }; + +// ContentType implements Content interface. +func (_ab *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";}; // Data implements Content interface. -func (_da *htmFile )Data ()[]byte {return _da ._g .Bytes ()}; +func (_gf *htmFile )Data ()[]byte {return _gf ._cf .Bytes ()};type htmFile struct{_cf _ca .Buffer }; -// Content is an interface used for putting the content into Client Query. -type Content interface{ContentType ()string ;Data ()[]byte ;}; +// 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 ){_bc :=&zipDirectory {_bf :_ca .Buffer {}};_bc ._cba =_f .NewWriter (&_bc ._bf );if _gff :=_bc .zipPath (dirPath ,"");_gff !=nil {return nil ,_gff ;};if _ad :=_bc ._cba .Close ();_ad !=nil {return nil ,_ad ; +};return _bc ,nil ;}; // ContentType implements Content interface. -func (_fdb *webURL )ContentType ()string {return "\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e";}; +func (_gg *htmFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; -// NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' -// and stores in it's in-memory buffer. -func NewZipDirectory (dirPath string )(Content ,error ){_ea :=&zipDirectory {_bdd :_ba .Buffer {}};_ea ._dc =_e .NewWriter (&_ea ._bdd );if _fb :=_ea .zipPath (dirPath ,"");_fb !=nil {return nil ,_fb ;};if _aa :=_ea ._dc .Close ();_aa !=nil {return nil ,_aa ; -};return _ea ,nil ;};func (_bb *zipDirectory )zipPath (_ebf ,_c string )error {_cg ,_gaa :=_a .ReadDir (_ebf );if _gaa !=nil {return _db .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",_ebf ,_gaa ); -};_gf :=&_eg .Builder {};for _ ,_gc :=range _cg {_ebb ,_gac :=_bb .zipBasePaths (_gc ,_ebf ,_c ,_gc .IsDir (),_gf );if _gc .IsDir (){if _fg :=_bb .zipPath (_ebb ,_gac );_fg !=nil {return _fg ;};continue ;};_eag ,_fa :=_a .ReadFile (_ebb );if _fa !=nil {return _fa ; -};_cd ,_fa :=_bb ._dc .Create (_gac );if _fa !=nil {return _fa ;};if _ ,_fa =_cd .Write (_eag );_fa !=nil {return _fa ;};};return nil ;}; \ No newline at end of file +// Content is an interface used for putting the content into Client Query. +type Content interface{ContentType ()string ;Data ()[]byte ;};func (_cc *zipDirectory )zipBasePaths (_fbc _d .FileInfo ,_aeb ,_dgg string ,_ec bool ,_abe *_b .Builder )(string ,string ){_abe .WriteString (_aeb );if !_b .HasSuffix (_aeb ,"\u002f"){_abe .WriteRune ('/'); +};_abe .WriteString (_fbc .Name ());if _ec {_abe .WriteRune ('/');};_bfg :=_abe .String ();_abe .Reset ();_abe .WriteString (_dgg );_abe .WriteString (_fbc .Name ());if _ec {_abe .WriteRune ('/');};_gc :=_abe .String ();_abe .Reset ();return _bfg ,_gc ; +};func (_dde *zipDirectory )zipPath (_aed ,_de string )error {_ded ,_dg :=_g .ReadDir (_aed );if _dg !=nil {return _a .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",_aed ,_dg ); +};_add :=&_b .Builder {};for _ ,_cfd :=range _ded {_ceg ,_fb :=_dde .zipBasePaths (_cfd ,_aed ,_de ,_cfd .IsDir (),_add );if _cfd .IsDir (){if _ea :=_dde .zipPath (_ceg ,_fb );_ea !=nil {return _ea ;};continue ;};_bfb ,_gfg :=_g .ReadFile (_ceg );if _gfg !=nil {return _gfg ; +};_cd ,_gfg :=_dde ._cba .Create (_fb );if _gfg !=nil {return _gfg ;};if _ ,_gfg =_cd .Write (_bfb );_gfg !=nil {return _gfg ;};};return nil ;};type zipDirectory struct{_bf _ca .Buffer ;_cba *_f .Writer ;}; + +// Data implements Content interface. +func (_bdc *zipDirectory )Data ()[]byte {return _bdc ._bf .Bytes ()}; \ No newline at end of file diff --git a/go.mod b/go.mod index bec65d1..0108857 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,6 @@ require ( github.com/mitchellh/go-homedir v1.1.0 github.com/spf13/cobra v1.1.1 github.com/spf13/viper v1.7.1 - github.com/unidoc/unipdf/v3 v3.19.1 + github.com/unidoc/unipdf/v3 v3.20.0 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 ) diff --git a/go.sum b/go.sum index 80b810b..92807d6 100644 --- a/go.sum +++ b/go.sum @@ -201,10 +201,8 @@ github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df h1:1RV3lxQ6L6xGFNhngp github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a h1:RLtvUhe4DsUDl66m7MJ8OqBjq8jpWBXPK6/RKtqeTkc= github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a/go.mod h1:j+qMWZVpZFTvDey3zxUkSgPJZEX33tDgU/QIA0IzCUw= -github.com/unidoc/unipdf/v3 v3.19.0 h1:DGa6xAMSXfRhcK4TPVzrSmSh0MvJ8aoB0Kcv8waCGTM= -github.com/unidoc/unipdf/v3 v3.19.0/go.mod h1:WdRz3hVhi/M0jFGXhsT5/9FDyRfga6KgI2ZQqjiOXaM= -github.com/unidoc/unipdf/v3 v3.19.1 h1:YCiKtYek7aHHsc3gx6ls6NlxY0+CfXy3KY4cCvyjqgY= -github.com/unidoc/unipdf/v3 v3.19.1/go.mod h1:WdRz3hVhi/M0jFGXhsT5/9FDyRfga6KgI2ZQqjiOXaM= +github.com/unidoc/unipdf/v3 v3.20.0 h1:efG2Y99K9xTELWmZuKGMgVYIhPsI0QbkNxx97IDMyyU= +github.com/unidoc/unipdf/v3 v3.20.0/go.mod h1:WdRz3hVhi/M0jFGXhsT5/9FDyRfga6KgI2ZQqjiOXaM= github.com/unidoc/unitype v0.2.1 h1:x0jMn7pB/tNrjEVjy3Ukpxo++HOBQaTCXcTYFA6BH3w= github.com/unidoc/unitype v0.2.1/go.mod h1:mafyug7zYmDOusqa7G0dJV45qp4b6TDAN+pHN7ZUIBU= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= diff --git a/sizes/sizes.go b/sizes/sizes.go index 52aba20..79ebbfc 100644 --- a/sizes/sizes.go +++ b/sizes/sizes.go @@ -12,181 +12,180 @@ // Package sizes defines basic types that determines the size units i.e. lengths. // // -package sizes ;import (_fg "encoding/json";_a "flag";_g "fmt";_cb "strconv";_c "strings";);var _ _a .Value =(*Point )(nil ); +package sizes ;import (_ac "encoding/json";_ad "flag";_c "fmt";_g "strconv";_f "strings";); -// Millimeters converts the inches value to the millimeters. -func (_fd Inch )Millimeters ()Millimeter {return Millimeter (float64 (_fd )*_ca )}; - -// Point is a unit of Length commonly used to measure the height of fonts. -type Point float64 ; +// ValueString implements pflag.Value interface. +func (_be Inch )ValueString ()string {return _be .String ()}; // String implements fmt.Stringer interface. -func (_ba Inch )String ()string {_gfe :=_c .Builder {};_gfe .WriteString (_cb .FormatFloat (float64 (_ba ),'f',1,64));_gfe .WriteString ("\u0069\u006e");return _gfe .String ();}; +func (_gdg Point )String ()string {_ff :=_f .Builder {};_ff .WriteString (_g .FormatFloat (float64 (_gdg ),'f',1,64));_ff .WriteString ("\u0070\u0074");return _ff .String ();}; -// HasChanged implements viper.FlagValue interface. -func (_ge *Point )HasChanged ()bool {return _ge !=nil }; +// Set implements flag.Value interface. +func (_cdg *Point )Set (s string )error {_cbb ,_cba :=_g .ParseFloat (s ,64);if _cba !=nil {return _c .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_cba );};*_cdg =Point (_cbb ); +return nil ;}; -// Inch is a unit that -type Inch float64 ; +// Type implements pflag.Value interface. +func (_fgd PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; + +// MarshalText implements the encoding.TextMarshaler interface for PageSize +func (_egf PageSize )MarshalText ()([]byte ,error ){return []byte (_egf .String ()),nil }; // Type implements pflag.Value interface. -func (_gd Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; +func (_dac Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; -// Orientation is the page orientation type wrapper. -type Orientation bool ; +// Millimeters converts the inches value to the millimeters. +func (_eef Inch )Millimeters ()Millimeter {return Millimeter (float64 (_eef )*_cc )}; -// Set sets the unit value. -// Implements pflag.Value interface. -func (_gf *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_gf .Length =nil ;return nil ;};_df ,_ec :=UnmarshalLength (s );if _ec !=nil {return _ec ;};_gf .Length =_df ;return nil ;}; +// Points implements Length interface. +func (_bed Point )Points ()Point {return _bed }; -// Name implements pflag.Value interface. -func (_eg Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; +// HasChanged implements pflag.Value interface. +func (_db *Inch )HasChanged ()bool {return _db !=nil }; -// Name implements viper.FlagValue interface. -func (_de Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; +// ValueType implements pflag.Value interface. +func (_fdc Inch )ValueType ()string {return _fdc .Type ()}; -// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise -func (_fdg PageSize )IsAPageSize ()bool {for _ ,_ffb :=range _da {if _fdg ==_ffb {return true ;};};return false ;}; +// Set implements pflag.Value interface. +func (_abac *PageSize )Set (s string )error {_fdb ,_eea :=UnmarshalPageSize (s );if _eea !=nil {return _eea ;};*_abac =_fdb ;return nil ;}; -// String implements fmt.Stringer interface. -func (_ecb Millimeter )String ()string {_ag :=_c .Builder {};_ag .WriteString (_cb .FormatFloat (float64 (_ecb ),'f',1,64));_ag .WriteString ("\u006d\u006d");return _ag .String ();}; +// MarshalUnit marshals the unit into the string. +func MarshalUnit (unit Length )(string ,error ){switch _cgf :=unit .(type ){case Millimeter :return _c .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_cgf ),nil ;case Inch :return _c .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_cgf ),nil ;case Point :return _c .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_cgf ),nil ; +default:return "",_c .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; -// Type implements pflag.Value interface. -func (_bb Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; +// UnmarshalPageSize unmarshals the page size from the string. +func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _cgb PageSize ;if _aed :=(&_cgb ).UnmarshalText ([]byte (pageSize ));_aed !=nil {return 0,_c .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",_aed ); +};return _cgb ,nil ;}; // Set implements flag.Value interface. -func (_dg *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_dg =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_dg =Landscape ;default:return _g .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); -};return nil ;}; +func (_fg *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_fg =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_fg =Landscape ;default:return _c .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); +};return nil ;};const (_d =float64 (1)/float64 (25.4);_cc =25.4;_e =0.0139;_fe =0.3528;_af =1/64;_cf =1/_fe ;); -// ValueType implements pflag.Value interface. -func (_fee Inch )ValueType ()string {return _fee .Type ()}; - -// Set implements pflag.Value interface. -func (_fgd *PageSize )Set (s string )error {_cf ,_efe :=UnmarshalPageSize (s );if _efe !=nil {return _efe ;};*_fgd =_cf ;return nil ;}; +// Inches gets the inch value. Implements Length interface. +func (_bb Point )Inches ()Inch {return Inch (float64 (_bb )*_e )}; -// 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 _cgc ,_fcd :=_ada [s ];_fcd {return _cgc ,nil ;};return 0,_g .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 ); -}; +// Points implements Length interface. +func (_cdb Inch )Points ()Point {return Point (float64 (_cdb )*_af )}; -// Millimeters gets the float64 millimeter value. -func (_ea Millimeter )Millimeters ()Millimeter {return _ea }; +// String implements fmt.Stringer interface. +func (_cbg Inch )String ()string {_dd :=_f .Builder {};_dd .WriteString (_g .FormatFloat (float64 (_cbg ),'f',1,64));_dd .WriteString ("\u0069\u006e");return _dd .String ();};var _age =map[string ]PageSize {_gb [0:9]:0,_gb [9:11]:1,_gb [11:13]:2,_gb [13:15]:3,_gb [15:17]:4,_gb [17:19]:5,_gb [19:21]:6,_gb [21:23]:7,_gb [23:25]:8,_gb [25:27]:9,_gb [27:29]:10,_gb [29:32]:11,_gb [32:34]:12,_gb [34:36]:13,_gb [36:38]:14,_gb [38:40]:15,_gb [40:42]:16,_gb [42:44]:17,_gb [44:46]:18,_gb [46:48]:19,_gb [48:50]:20,_gb [50:52]:21,_gb [52:55]:22,_gb [55:61]:23}; +func _aea (_cbac string )(Point ,error ){_cbac =_f .TrimSpace (_f .Trim (_cbac ,"\u0070\u0074"));_aff ,_ggf :=_g .ParseFloat (_cbac ,64);if _ggf !=nil {return 0,_ggf ;};return Point (_aff ),nil ;};func (_cad PageSize )String ()string {if _cad < 0||_cad >=PageSize (len (_dee )-1){return _c .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_cad ); +};return _gb [_dee [_cad ]:_dee [_cad +1]];};const (Portrait =Orientation (false );Landscape =Orientation (true );); -// PageSizeValues returns all values of the enum -func PageSizeValues ()[]PageSize {return _da };var _da =[]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}; +// Dimensions gets the dimensions of the given page size. +// If provided page size is not valid than the function returns 0 values. +func (_dg PageSize )Dimensions ()(_eedd ,_fee Millimeter ){switch _dg {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; +case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125; +case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _eedd ,_fee ;}; -// UnmarshalPageSize unmarshals the page size from the string. -func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _bd PageSize ;if _ecg :=(&_bd ).UnmarshalText ([]byte (pageSize ));_ecg !=nil {return 0,_g .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",_ecg ); -};return _bd ,nil ;};var (_ Length =Millimeter (0););var _ada =map[string ]PageSize {_ace [0:9]:0,_ace [9:11]:1,_ace [11:13]:2,_ace [13:15]:3,_ace [15:17]:4,_ace [17:19]:5,_ace [19:21]:6,_ace [21:23]:7,_ace [23:25]:8,_ace [25:27]:9,_ace [27:29]:10,_ace [29:32]:11,_ace [32:34]:12,_ace [34:36]:13,_ace [36:38]:14,_ace [38:40]:15,_ace [40:42]:16,_ace [42:44]:17,_ace [44:46]:18,_ace [46:48]:19,_ace [48:50]:20,_ace [50:52]:21,_ace [52:55]:22,_ace [55:61]:23}; -func _cbab (_dc string )(Inch ,error ){_dc =_c .TrimSpace (_c .Trim (_dc ,"\u0069\u006e"));_cg ,_ed :=_cb .ParseFloat (_dc ,64);if _ed !=nil {return 0,_g .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ed ); -};return Inch (_cg ),nil ;}; +// Type implements pflag.Value interface. +func (_gc *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; -// Set implements flag.Value interface. -func (_bae *Point )Set (s string )error {_fec ,_ab :=_cb .ParseFloat (s ,64);if _ab !=nil {return _g .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_ab );};*_bae =Point (_fec ); -return nil ;}; +// Type implements pflag.Value interface. +func (_ggg Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; -// String implements fmt.Stringer interface. -func (_ae Point )String ()string {_cbfc :=_c .Builder {};_cbfc .WriteString (_cb .FormatFloat (float64 (_ae ),'f',1,64));_cbfc .WriteString ("\u0070\u0074");return _cbfc .String ();}; +// Inches gets the inches equivalent from provided millimeter value. +func (_b Millimeter )Inches ()Inch {return Inch (float64 (_b )*_d )}; -// MarshalUnit marshals the unit into the string. -func MarshalUnit (unit Length )(string ,error ){switch _ac :=unit .(type ){case Millimeter :return _g .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_ac ),nil ;case Inch :return _g .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_ac ),nil ;case Point :return _g .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_ac ),nil ; -default:return "",_g .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};};var _ _a .Value =(*Orientation )(nil ); +// Name implements viper.FlagValue interface. +func (_cg Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; -// String gets the string value for given flag. -func (_e *LengthFlag )String ()string {if _e .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _e .Length .String ();}; +// Millimeter is the dimension unit that defines a millimeter. +type Millimeter float64 ;func _ab (_ag string )(Millimeter ,error ){_ag =_f .TrimSpace (_f .TrimSuffix (_ag ,"\u006d\u006d"));_bg ,_ga :=_g .ParseFloat (_ag ,64);if _ga !=nil {return 0,_c .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",_ga ); +};return Millimeter (_bg ),nil ;};var _ _ad .Value =(*Orientation )(nil ); -// Points implements Length interface. -func (_ef Point )Points ()Point {return _ef }; +// String implements fmt.Stringer interface. +func (_eg Millimeter )String ()string {_gg :=_f .Builder {};_gg .WriteString (_g .FormatFloat (float64 (_eg ),'f',1,64));_gg .WriteString ("\u006d\u006d");return _gg .String ();};var _gad =[]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}; -// Millimeters converts the inches value to the millimeters. -func (_agc Point )Millimeters ()Millimeter {return Millimeter (float64 (_agc )*_dd )}; // MarshalJSON implements the json.Marshaler interface for PageSize -func (_aeg PageSize )MarshalJSON ()([]byte ,error ){return _fg .Marshal (_aeg .String ())};func (_gc PageSize )String ()string {if _gc < 0||_gc >=PageSize (len (_aa )-1){return _g .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_gc ); -};return _ace [_aa [_gc ]:_aa [_gc +1]];}; +func (_adcg PageSize )MarshalJSON ()([]byte ,error ){return _ac .Marshal (_adcg .String ())}; -// LengthFlag is a pflag wrapper for the Length value. -type LengthFlag struct{Length Length ;}; +// PageSize is the enum used for defining the page size. +type PageSize int ; -// UnmarshalInch unmarshalls provided string into unit. -func UnmarshalInch (unit string )(Inch ,error ){if _c .HasSuffix (unit ,"\u006d\u006d"){_fca ,_eca :=_bg (unit );if _eca !=nil {return 0,_eca ;};return _fca .Inches (),nil ;};if _c .HasSuffix (unit ,"\u0069\u006e"){return _cbab (unit );};return 0,_g .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); -}; +// Millimeters gets the float64 millimeter value. +func (_cfd Millimeter )Millimeters ()Millimeter {return _cfd };var (_ Length =Millimeter (0);); -// MarshalText implements the encoding.TextMarshaler interface for PageSize -func (_aed PageSize )MarshalText ()([]byte ,error ){return []byte (_aed .String ()),nil }; +// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize +func (_ea *PageSize )UnmarshalText (text []byte )error {var _dda error ;*_ea ,_dda =PageSizeString (string (text ));return _dda ;};var _dee =[...]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 (_cba *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; +// Orientation is the page orientation type wrapper. +type Orientation bool ;func _da (_ega string )(Inch ,error ){_ega =_f .TrimSpace (_f .Trim (_ega ,"\u0069\u006e"));_fa ,_aba :=_g .ParseFloat (_ega ,64);if _aba !=nil {return 0,_c .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_aba ); +};return Inch (_fa ),nil ;}; -// Millimeter is the dimension unit that defines a millimeter. -type Millimeter float64 ;const (Portrait =Orientation (false );Landscape =Orientation (true );); +// String gets the string value for given flag. +func (_adc *LengthFlag )String ()string {if _adc .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _adc .Length .String ();}; + +// PageSizeValues returns all values of the enum +func PageSizeValues ()[]PageSize {return _gad }; + +// 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 _dae ,_ddc :=_age [s ];_ddc {return _dae ,nil ;};return 0,_c .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 ); +}; // MarshalPageSize marshals the page size into string. -func MarshalPageSize (p PageSize )(string ,error ){_adb ,_ee :=p .MarshalText ();if _ee !=nil {return "",_ee ;};return string (_adb ),nil ;}; +func MarshalPageSize (p PageSize )(string ,error ){_bc ,_fc :=p .MarshalText ();if _fc !=nil {return "",_fc ;};return string (_bc ),nil ;}; -// Points implements Length interface. -func (_fef Inch )Points ()Point {return Point (float64 (_fef )*_cbf )}; +// Point is a unit of Length commonly used to measure the height of fonts. +type Point float64 ;const _gb ="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 (_baa Orientation )String ()string {if _baa ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";};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 ;); -// ValueType implements viper.FlagValue interface. -func (_ecc Point )ValueType ()string {return _ecc .Type ()}; +// UnmarshalLength unmarshalls string value into Length. +func UnmarshalLength (length string )(Length ,error ){if _f .HasSuffix (length ,"\u006d\u006d"){return _ab (length );};if _f .HasSuffix (length ,"\u0069\u006e"){return _da (length );};if _f .HasSuffix (length ,"\u0070\u0074"){return _aea (length );};return nil ,_c .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length ); +};var _ _ad .Value =(*Point )(nil ); // Inches gets the inch value. Implements Length interface. -func (_feef Point )Inches ()Inch {return Inch (float64 (_feef )*_d )}; +func (_df Inch )Inches ()Inch {return _df }; -// Dimensions gets the dimensions of the given page size. -// If provided page size is not valid than the function returns 0 values. -func (_adc PageSize )Dimensions ()(_cgf ,_bbe Millimeter ){switch _adc {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 _cgf ,_bbe ;};const _ace ="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"; +// Points implements Length interface. +func (_ee Millimeter )Points ()Point {return Point (_ee *_cf )};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 ;); +// ValueType implements viper.FlagValue interface. +func (_ecb Point )ValueType ()string {return _ecb .Type ()}; -// UnmarshalLength unmarshalls string value into Length. -func UnmarshalLength (length string )(Length ,error ){if _c .HasSuffix (length ,"\u006d\u006d"){return _bg (length );};if _c .HasSuffix (length ,"\u0069\u006e"){return _cbab (length );};if _c .HasSuffix (length ,"\u0070\u0074"){return _ddc (length );}; -return nil ,_g .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length );}; +// String implements fmt.Stringer interface. +func (_bf Orientation )String ()string {if _bf ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";};var _ Length =Inch (0); -// ValueString implements pflag.Value interface. -func (_be Inch )ValueString ()string {return _be .String ()}; +// Set sets the unit value. +// Implements pflag.Value interface. +func (_ca *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_ca .Length =nil ;return nil ;};_gd ,_cd :=UnmarshalLength (s );if _cd !=nil {return _cd ;};_ca .Length =_gd ;return nil ;}; -// Type implements pflag.Value interface. -func (_aec Point )Type ()string {return "\u0070\u006f\u0069n\u0074"};func _bg (_bf string )(Millimeter ,error ){_bf =_c .TrimSpace (_c .TrimSuffix (_bf ,"\u006d\u006d"));_fcg ,_cdd :=_cb .ParseFloat (_bf ,64);if _cdd !=nil {return 0,_g .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",_cdd ); -};return Millimeter (_fcg ),nil ;}; +// Name implements pflag.Value interface. +func (_ae Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; -// ValueString implements viper.FlagValue interface. -func (_fae Point )ValueString ()string {return _fae .String ()}; +// Length is it the default dimension unit. +type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; -// Points implements Length interface. -func (_fa Millimeter )Points ()Point {return Point (_fa *_b )}; +// Type implements pflag.Value interface. +func (_fd Inch )Type ()string {return "\u0069\u006e\u0063\u0068"}; -// Inches gets the inch value. Implements Length interface. -func (_egf Inch )Inches ()Inch {return _egf }; +// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise +func (_gac PageSize )IsAPageSize ()bool {for _ ,_ecc :=range _gad {if _gac ==_ecc {return true ;};};return false ;}; -// Length is it the default dimension unit. -type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; +// ValueString implements viper.FlagValue interface. +func (_de Point )ValueString ()string {return _de .String ()}; -// Inches gets the inches equivalent from provided millimeter value. -func (_fe Millimeter )Inches ()Inch {return Inch (float64 (_fe )*_cd )}; +// Millimeters converts the inches value to the millimeters. +func (_fdd Point )Millimeters ()Millimeter {return Millimeter (float64 (_fdd )*_fe )}; -// UnmarshalJSON implements the json.Unmarshaler interface for PageSize -func (_dcd *PageSize )UnmarshalJSON (data []byte )error {var _cc string ;if _cde :=_fg .Unmarshal (data ,&_cc );_cde !=nil {return _g .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 _gff error ;*_dcd ,_gff =PageSizeString (_cc );return _gff ;};func _ddc (_abg string )(Point ,error ){_abg =_c .TrimSpace (_c .Trim (_abg ,"\u0070\u0074"));_ecbc ,_ad :=_cb .ParseFloat (_abg ,64);if _ad !=nil {return 0,_ad ;};return Point (_ecbc ),nil ; -};var _aa =[...]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}; +// HasChanged implements viper.FlagValue interface. +func (_ed *Point )HasChanged ()bool {return _ed !=nil }; -// HasChanged implements pflag.Value interface. -func (_bbc *Inch )HasChanged ()bool {return _bbc !=nil }; +// Set implements pflag.Value interface. +func (_gcf *Inch )Set (s string )error {_cdf ,_fb :=_g .ParseFloat (s ,64);if _fb !=nil {return _c .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_fb );};*_gcf =Inch (_cdf ); +return nil ;}; -// Type implements pflag.Value interface. -func (_deb PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"};var _ Length =Inch (0);const (_cd =float64 (1)/float64 (25.4);_ca =25.4;_d =0.0139;_dd =0.3528;_cbf =1/64;_b =1/_dd ;); +// UnmarshalInch unmarshalls provided string into unit. +func UnmarshalInch (unit string )(Inch ,error ){if _f .HasSuffix (unit ,"\u006d\u006d"){_aa ,_add :=_ab (unit );if _add !=nil {return 0,_add ;};return _aa .Inches (),nil ;};if _f .HasSuffix (unit ,"\u0069\u006e"){return _da (unit );};return 0,_c .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); +}; -// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize -func (_fab *PageSize )UnmarshalText (text []byte )error {var _gee error ;*_fab ,_gee =PageSizeString (string (text ));return _gee ;}; +// Inch is a unit that +type Inch float64 ; -// PageSize is the enum used for defining the page size. -type PageSize int ; +// LengthFlag is a pflag wrapper for the Length value. +type LengthFlag struct{Length Length ;}; -// Set implements pflag.Value interface. -func (_fc *Inch )Set (s string )error {_ff ,_fed :=_cb .ParseFloat (s ,64);if _fed !=nil {return _g .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_fed );};*_fc =Inch (_ff ); -return nil ;}; \ No newline at end of file +// UnmarshalJSON implements the json.Unmarshaler interface for PageSize +func (_bce *PageSize )UnmarshalJSON (data []byte )error {var _eb string ;if _aad :=_ac .Unmarshal (data ,&_eb );_aad !=nil {return _c .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 _fgce error ;*_bce ,_fgce =PageSizeString (_eb );return _fgce ;}; \ No newline at end of file diff --git a/unihtml.go b/unihtml.go index 973835a..591a11e 100644 --- a/unihtml.go +++ b/unihtml.go @@ -10,16 +10,48 @@ // terms that can be accessed at https://unidoc.io/eula/ // Package unihtml contains a plugin for the UniDoc. -package unihtml ;import (_cc "bytes";_d "context";_fc "errors";_ga "fmt";_dba "github.com/unidoc/unihtml/client";_ba "github.com/unidoc/unihtml/content";_df "github.com/unidoc/unihtml/sizes";_ff "github.com/unidoc/unipdf/v3/common";_gaa "github.com/unidoc/unipdf/v3/common/license"; -_fe "github.com/unidoc/unipdf/v3/creator";_fd "github.com/unidoc/unipdf/v3/model";_dc "github.com/unidoc/unipdf/v3/render";_db "image";_a "image/color";_c "math";_g "net/url";_e "os";_f "time";);var _ef *_dba .Client ;func (_bc *Document )getMargins ()margins {_fec :=_bc ._cce ; -if _bc ._dg .IsRelative (){_fec .Top =_df .Millimeter (1);_fec .Left =_df .Millimeter (1);_fec .Bottom =_df .Millimeter (1);_fec .Right =_df .Millimeter (1);return _fec ;};if _fec .Top ==nil {_fec .Top =_df .Millimeter (10);};if _fec .Bottom ==nil {_fec .Bottom =_df .Millimeter (10); -};if _fec .Left ==nil {_fec .Left =_df .Millimeter (10);};if _fec .Right ==nil {_fec .Right =_df .Millimeter (10);};return _fec ;};type margins struct{Left ,Right ,Bottom ,Top _df .Length ;}; +package unihtml ;import (_ba "bytes";_b "context";_e "errors";_ca "fmt";_bab "github.com/unidoc/unihtml/client";_g "github.com/unidoc/unihtml/content";_fe "github.com/unidoc/unihtml/sizes";_bd "github.com/unidoc/unipdf/v3/common";_ee "github.com/unidoc/unipdf/v3/common/license"; +_ef "github.com/unidoc/unipdf/v3/creator";_af "github.com/unidoc/unipdf/v3/model";_cf "github.com/unidoc/unipdf/v3/render";_fc "image";_c "image/color";_f "math";_db "net/url";_d "os";_dbe "time";);func (_fcf *Document )validate ()error {if _gb ==nil {return ErrNoClient ; +};if _fcf ._ea ==nil {return ErrContentNotDefined ;};return nil ;};func _fg (_baec _fc .Image )float64 {_gcc :=_baec .Bounds ();var (_gff int ;_df _c .Color ;_ebg ,_gcg ,_efbd uint32 ;);_bgd ,_bcc :=_gcc .Min .X ,_gcc .Max .Y -1;_bccf :=_baec .At (_bgd ,_bcc ); +_bca ,_ab ,_gcf ,_ :=_bccf .RGBA ();_ggd :=_bca ==_f .MaxUint16 &&_ab ==_f .MaxUint16 &&_gcf ==_f .MaxUint16 ;for _bcc =_gcc .Max .Y -1;_bcc >=_gcc .Min .Y ;_bcc --{var _aec bool ;for _bgd =_gcc .Min .X ;_bgd < _gcc .Max .X ;_bgd ++{_df =_baec .At (_bgd ,_bcc ); +_ebg ,_gcg ,_efbd ,_ =_df .RGBA ();if (_ggd &&!(_ebg ==_bca &&_gcg ==_ab &&_gcf ==_efbd ))||(!_ggd &&(_f .Abs (float64 (_ebg )-float64 (_bca ))/float64 (_f .MaxUint16 )> 0.03||_f .Abs (float64 (_gcg )-float64 (_ab ))/float64 (_f .MaxUint16 )> 0.03||_f .Abs (float64 (_efbd )-float64 (_gcf ))/float64 (_f .MaxUint16 )> 0.03)){_aec =true ; +break ;};};if _aec {break ;};_gff =_bcc ;};return float64 (_gcc .Max .Y -_gff )/float64 (_gcc .Max .Y );};func (_bed *Document )extract (_gda _b .Context ,_ecb ,_bee _fe .Length ,_aecc margins )([]*_af .PdfPage ,error ){_bcg :=_bab .BuildHTMLQuery ().SetContent (_bed ._ea ).PageSize (_bed ._cd ).PaperWidth (_ecb ).PaperHeight (_bee ).Orientation (_bed ._gd ).MarginLeft (_aecc .Left ).MarginRight (_aecc .Right ).MarginTop (_aecc .Top ).MarginBottom (_aecc .Bottom ); +_fgb ,_gdc :=_bcg .Query ();if _gdc !=nil {return nil ,_gdc ;};_gda ,_ge :=_b .WithTimeout (_gda ,_dbe .Second *15);defer _ge ();_egfa ,_gdc :=_gb .ConvertHTML (_gda ,_fgb );if _gdc !=nil {return nil ,_gdc ;};_bbb :=_ba .NewReader (_egfa .Data );_aag ,_gdc :=_af .NewPdfReader (_bbb ); +if _gdc !=nil {return nil ,_gdc ;};return _aag .PageList ,nil ;}; + +// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. +func ConnectOptions (o Options )error {_gb =_bab .New (_bab .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_bg ,_gc :=_b .WithTimeout (_b .Background (),_dbe .Second *5);defer _gc ();if _cfg :=_gb .HealthCheck (_bg );_cfg !=nil {return _cfg ; +};return nil ;};func _cg ()error {_gbd :=_ee .GetLicenseKey ();if _gbd ==nil {return _e .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};if !_gbd .IsLicensed (){return _e .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"); +};if !_gbd .UniHTML {return _e .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020l\u0069\u0063e\u006e\u0073\u0065\u0020\u0069\u0073 \u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069d\u0020\u0066\u006f\u0072\u0020\u0074\u0068\u0065\u0020U\u006e\u0069\u0048\u0054\u004d\u004c\u0020\u0065\u0078\u0074\u0065n\u0073\u0069\u006f\u006e.\u0020\u0056i\u0073i\u0074\u003a\u0020\u0068\u0074\u0074\u0070s\u003a/\u002f\u0077\u0077\u0077\u002e\u0075\u006e\u0069\u0064\u006f\u0063\u002e\u0069\u006f\u0020\u0061\u006ed\u0020c\u006f\u006e\u0074\u0061\u0063\u0074\u0020\u0073\u0075\u0070\u0070\u006f\u0072t"); +};return nil ;}; + +// GetPdfPages is a function that converts provided input content and +func (_ff *Document )GetPdfPages (ctx _b .Context )([]*_af .PdfPage ,error ){if _dc :=_ff .validate ();_dc !=nil {return nil ,_dc ;};return _ff .extract (ctx ,_ff ._dbb ,_ff ._gcd ,_ff .getMargins ());}; + +// SetMarginLeft sets the left margin. +func (_dg *Document )SetMarginLeft (margin _fe .Length ){_dg ._cc .Left =margin }; + +// SetPageSize sets the page default size. +func (_bcb *Document )SetPageSize (pageSize _fe .PageSize )error {if !pageSize .IsAPageSize (){return _e .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"); +};_bcb ._cd =pageSize ;_bcb ._cfb =_ef .PositionAbsolute ;return nil ;}; + +// SetLandscapeOrientation sets document landscape page orientation. +func (_dfg *Document )SetLandscapeOrientation (){_dfg ._gd =_fe .Landscape };type margins struct{Left ,Right ,Bottom ,Top _fe .Length ;}; + +// SetPageHeight sets the page height for given document. +func (_baa *Document )SetPageHeight (pageHeight _fe .Length )error {_baa ._gcd =pageHeight ;_baa ._cfb =_ef .PositionAbsolute ;return nil ;};var ErrNoClient =_e .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); + + +// SetMargins sets the Document Margins. +func (_dd *Document )SetMargins (left ,right ,top ,bottom float64 ){_dd ._cc .Left =_fe .Point (left );_dd ._cc .Right =_fe .Point (right );_dd ._cc .Top =_fe .Point (top );_dd ._cc .Bottom =_fe .Point (bottom );_dd ._cfb =_ef .PositionAbsolute ;}; // Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. -type Document struct{_dbc _ba .Content ;_cce margins ;_dg _fe .Positioning ;_eb ,_fcd float64 ;_gd _df .PageSize ;_ge ,_gec _df .Length ;_ggb _df .Orientation ;_ce bool ;}; +type Document struct{_ea _g .Content ;_cc margins ;_cfb _ef .Positioning ;_eg ,_fb float64 ;_cd _fe .PageSize ;_dbb ,_gcd _fe .Length ;_gd _fe .Orientation ;_eb bool ;};var _gb *_bab .Client ; -// SetPageWidth sets the page width for given document. -func (_af *Document )SetPageWidth (pageWidth _df .Length )error {_af ._ge =pageWidth ;_af ._dg =_fe .PositionAbsolute ;return nil ;};var _ _fe .Drawable =(*Document )(nil ); +// SetMarginRight sets the left margin. +func (_ded *Document )SetMarginRight (margin _fe .Length ){_ded ._cc .Right =margin };func (_cfa *Document )getMargins ()margins {_afa :=_cfa ._cc ;if _cfa ._cfb .IsRelative (){_afa .Top =_fe .Millimeter (1);_afa .Left =_fe .Millimeter (1);_afa .Bottom =_fe .Millimeter (1); +_afa .Right =_fe .Millimeter (1);return _afa ;};if _afa .Top ==nil {_afa .Top =_fe .Millimeter (10);};if _afa .Bottom ==nil {_afa .Bottom =_fe .Millimeter (10);};if _afa .Left ==nil {_afa .Left =_fe .Millimeter (10);};if _afa .Right ==nil {_afa .Right =_fe .Millimeter (10); +};return _afa ;}; // Options are the HTML Client options used for establishing the connection. type Options struct{ @@ -34,71 +66,42 @@ Port int ; Secure bool ; // Prefix is an option setting used when the server is working with the URI prefix. Default Value: ''. -Prefix string ;};func _gecf (_dff _db .Image )float64 {_eaa :=_dff .Bounds ();var (_fgeg int ;_aa _a .Color ;_ae ,_bbe ,_gcc uint32 ;);_agd ,_ada :=_eaa .Min .X ,_eaa .Max .Y -1;_caa :=_dff .At (_agd ,_ada );_ab ,_bd ,_egb ,_ :=_caa .RGBA ();_ebc :=_ab ==_c .MaxUint16 &&_bd ==_c .MaxUint16 &&_egb ==_c .MaxUint16 ; -for _ada =_eaa .Max .Y -1;_ada >=_eaa .Min .Y ;_ada --{var _abe bool ;for _agd =_eaa .Min .X ;_agd < _eaa .Max .X ;_agd ++{_aa =_dff .At (_agd ,_ada );_ae ,_bbe ,_gcc ,_ =_aa .RGBA ();if (_ebc &&!(_ae ==_ab &&_bbe ==_bd &&_egb ==_gcc ))||(!_ebc &&(_c .Abs (float64 (_ae )-float64 (_ab ))/float64 (_c .MaxUint16 )> 0.03||_c .Abs (float64 (_bbe )-float64 (_bd ))/float64 (_c .MaxUint16 )> 0.03||_c .Abs (float64 (_gcc )-float64 (_egb ))/float64 (_c .MaxUint16 )> 0.03)){_abe =true ; -break ;};};if _abe {break ;};_fgeg =_ada ;};return float64 (_eaa .Max .Y -_fgeg )/float64 (_eaa .Max .Y );}; +Prefix string ;}; -// Connect creates UniHTML HTTP Client and tries to establish connection with the server. -func Connect (path string )error {if _ee :=_eeb ();_ee !=nil {return _ee ;};_gb ,_cd :=_dba .ParseOptions (path );if _cd !=nil {return _cd ;};_ef =_dba .New (_gb );_ec ,_bg :=_d .WithTimeout (_d .Background (),_f .Second *5);defer _bg ();if _ea :=_ef .HealthCheck (_ec ); -_ea !=nil {return _ea ;};return nil ;}; - -// ChapterDraw implements creator.containerElement interface. -func (_ac *Document )ContainerComponent (container _fe .Drawable )(_fe .Drawable ,error ){switch container .(type ){case *_fe .Chapter :default:return nil ,_ga .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 _ac ,nil ;};var ErrNoClient =_fc .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); - -// GetPdfPages is a function that converts provided input content and -func (_bb *Document )GetPdfPages (ctx _d .Context )([]*_fd .PdfPage ,error ){if _ca :=_bb .validate ();_ca !=nil {return nil ,_ca ;};return _bb .extract (ctx ,_bb ._ge ,_bb ._gec ,_bb .getMargins ());}; +// SetPos sets the absolute position. Changes object positioning to absolute. +func (_aeb *Document )SetPos (x ,y float64 ){_aeb ._cfb =_ef .PositionAbsolute ;_aeb ._eg =x ;_aeb ._fb =y ;}; -// SetPageHeight sets the page height for given document. -func (_fed *Document )SetPageHeight (pageHeight _df .Length )error {_fed ._gec =pageHeight ;_fed ._dg =_fe .PositionAbsolute ;return nil ;}; +// SetMarginTop sets the left margin. +func (_fdg *Document )SetMarginTop (margin _fe .Length ){_fdg ._cc .Top =margin }; -// SetMarginLeft sets the left margin. -func (_cdf *Document )SetMarginLeft (margin _df .Length ){_cdf ._cce .Left =margin };func (_abf *Document )validate ()error {if _ef ==nil {return ErrNoClient ;};if _abf ._dbc ==nil {return ErrContentNotDefined ;};return nil ;};func (_cffb *Document )extract (_gdf _d .Context ,_ebb ,_def _df .Length ,_ade margins )([]*_fd .PdfPage ,error ){_dbcf :=_dba .BuildHTMLQuery ().SetContent (_cffb ._dbc ).PageSize (_cffb ._gd ).PaperWidth (_ebb ).PaperHeight (_def ).Orientation (_cffb ._ggb ).MarginLeft (_ade .Left ).MarginRight (_ade .Right ).MarginTop (_ade .Top ).MarginBottom (_ade .Bottom ); -_dgde ,_fcf :=_dbcf .Query ();if _fcf !=nil {return nil ,_fcf ;};_gdf ,_gecg :=_d .WithTimeout (_gdf ,_f .Second *15);defer _gecg ();_agc ,_fcf :=_ef .ConvertHTML (_gdf ,_dgde );if _fcf !=nil {return nil ,_fcf ;};_dgg :=_cc .NewReader (_agc .Data );_cg ,_fcf :=_fd .NewPdfReader (_dgg ); -if _fcf !=nil {return nil ,_fcf ;};return _cg .PageList ,nil ;}; +// SetPageWidth sets the page width for given document. +func (_bf *Document )SetPageWidth (pageWidth _fe .Length )error {_bf ._dbb =pageWidth ;_bf ._cfb =_ef .PositionAbsolute ;return nil ;}; -// SetMarginBottom sets the left margin. -func (_feff *Document )SetMarginBottom (margin _df .Length ){_feff ._cce .Bottom =margin }; +// Connect creates UniHTML HTTP Client and tries to establish connection with the server. +func Connect (path string )error {if _caa :=_cg ();_caa !=nil {return _caa ;};_bac ,_ae :=_bab .ParseOptions (path );if _ae !=nil {return _ae ;};_gb =_bab .New (_bac );_be ,_bad :=_b .WithTimeout (_b .Background (),_dbe .Second *5);defer _bad ();if _efb :=_gb .HealthCheck (_be ); +_efb !=nil {return _efb ;};return nil ;}; // GeneratePageBlocks implements creator.Drawable interface. -func (_cb *Document )GeneratePageBlocks (ctx _fe .DrawContext )([]*_fe .Block ,_fe .DrawContext ,error ){if _bad :=_cb .validate ();_bad !=nil {return nil ,ctx ,_bad ;};var _gc []*_fe .Block ;_dbe :=_cb .getMargins ();_ad ,_bf :=_cb ._ge ,_cb ._gec ;if _cb ._dg .IsRelative (){_ad ,_bf =_df .Point (ctx .Width ),_df .Point (ctx .Height ); -ctx .X -=float64 (_dbe .Left .Points ());};_gee ,_geeg :=_cb .extract (_d .Background (),_ad ,_bf ,_dbe );if _geeg !=nil {return nil ,_fe .DrawContext {},_geeg ;};for _da ,_be :=range _gee {_fa ,_bbd :=_fe .NewBlockFromPage (_be );if _bbd !=nil {return nil ,_fe .DrawContext {},_bbd ; -};var _dgd float64 ;if _cb ._ce &&_da ==len (_gee )-1{_eg :=_dc .NewImageDevice ();_fae ,_dab :=_eg .Render (_be );if _dab !=nil {return nil ,_fe .DrawContext {},_dab ;};_gf ,_dab :=_be .GetMediaBox ();if _dab !=nil {return nil ,_fe .DrawContext {},_dab ; -};_gdb :=_f .Now ();_de :=_gecf (_fae );_dgd =_gf .Height ()*_de ;_ff .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",_f .Since (_gdb )); -if _cb ._cce .Bottom !=nil {_dgd -=float64 (_cb ._cce .Bottom .Points ());};if _dgd < 0{_dgd =0;};_ff .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",_dgd ); -};_dbee ,_fge ,_bbd :=_fa .GeneratePageBlocks (ctx );if _bbd !=nil {return nil ,_fe .DrawContext {},_bbd ;};ctx =_fge ;ctx .Y -=_dgd ;if _da !=len (_gee )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; -ctx .Page ++;};_gc =append (_gc ,_dbee ...);};return _gc ,ctx ,nil ;};func _eeb ()error {_gg :=_gaa .GetLicenseKey ();if _gg ==nil {return _fc .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); -};if !_gg .IsLicensed (){return _fc .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");};if !_gg .UniHTML {return _fc .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020l\u0069\u0063e\u006e\u0073\u0065\u0020\u0069\u0073 \u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069d\u0020\u0066\u006f\u0072\u0020\u0074\u0068\u0065\u0020U\u006e\u0069\u0048\u0054\u004d\u004c\u0020\u0065\u0078\u0074\u0065n\u0073\u0069\u006f\u006e.\u0020\u0056i\u0073i\u0074\u003a\u0020\u0068\u0074\u0074\u0070s\u003a/\u002f\u0077\u0077\u0077\u002e\u0075\u006e\u0069\u0064\u006f\u0063\u002e\u0069\u006f\u0020\u0061\u006ed\u0020c\u006f\u006e\u0074\u0061\u0063\u0074\u0020\u0073\u0075\u0070\u0070\u006f\u0072t"); -};return nil ;}; +func (_bb *Document )GeneratePageBlocks (ctx _ef .DrawContext )([]*_ef .Block ,_ef .DrawContext ,error ){if _beca :=_bb .validate ();_beca !=nil {return nil ,ctx ,_beca ;};var _ac []*_ef .Block ;_dcg :=_bb .getMargins ();_ebd ,_aca :=_bb ._dbb ,_bb ._gcd ; +if _bb ._cfb .IsRelative (){_ebd ,_aca =_fe .Point (ctx .Width ),_fe .Point (ctx .Height );ctx .X -=float64 (_dcg .Left .Points ());};_beb ,_bc :=_bb .extract (_b .Background (),_ebd ,_aca ,_dcg );if _bc !=nil {return nil ,_ef .DrawContext {},_bc ;};for _ffg ,_fd :=range _beb {_bae ,_gf :=_ef .NewBlockFromPage (_fd ); +if _gf !=nil {return nil ,_ef .DrawContext {},_gf ;};var _ebc float64 ;if _bb ._eb &&_ffg ==len (_beb )-1{_gba :=_cf .NewImageDevice ();_fff ,_cgb :=_gba .Render (_fd );if _cgb !=nil {return nil ,_ef .DrawContext {},_cgb ;};_egf ,_cgb :=_fd .GetMediaBox (); +if _cgb !=nil {return nil ,_ef .DrawContext {},_cgb ;};_aa :=_dbe .Now ();_gg :=_fg (_fff );_ebc =_egf .Height ()*_gg ;_bd .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",_dbe .Since (_aa )); +if _bb ._cc .Bottom !=nil {_ebc -=float64 (_bb ._cc .Bottom .Points ());};if _ebc < 0{_ebc =0;};_bd .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",_ebc ); +};_adf ,_fcc ,_gf :=_bae .GeneratePageBlocks (ctx );if _gf !=nil {return nil ,_ef .DrawContext {},_gf ;};ctx =_fcc ;ctx .Y -=_ebc ;if _ffg !=len (_beb )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; +ctx .Page ++;};_ac =append (_ac ,_adf ...);};return _ac ,ctx ,nil ;};var ErrContentNotDefined =_e .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); -// SetMarginTop sets the left margin. -func (_eag *Document )SetMarginTop (margin _df .Length ){_eag ._cce .Top =margin }; - -// SetMarginRight sets the left margin. -func (_cff *Document )SetMarginRight (margin _df .Length ){_cff ._cce .Right =margin }; // TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. -func (_dfa *Document )TrimLastPageContent (){_dfa ._ce =true }; +func (_egg *Document )TrimLastPageContent (){_egg ._eb =true }; -// SetMargins sets the Document Margins. -func (_cea *Document )SetMargins (left ,right ,top ,bottom float64 ){_cea ._cce .Left =_df .Point (left );_cea ._cce .Right =_df .Point (right );_cea ._cce .Top =_df .Point (top );_cea ._cce .Bottom =_df .Point (bottom );_cea ._dg =_fe .PositionAbsolute ; -};var ErrContentNotDefined =_fc .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"); - -// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. -func ConnectOptions (o Options )error {_ef =_dba .New (_dba .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_fef ,_gaf :=_d .WithTimeout (_d .Background (),_f .Second *5);defer _gaf ();if _cf :=_ef .HealthCheck (_fef );_cf !=nil {return _cf ; -};return nil ;}; - -// SetPageSize sets the page default size. -func (_dcd *Document )SetPageSize (pageSize _df .PageSize )error {if !pageSize .IsAPageSize (){return _fc .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"); -};_dcd ._gd =pageSize ;_dcd ._dg =_fe .PositionAbsolute ;return nil ;}; - -// SetPos sets the absolute position. Changes object positioning to absolute. -func (_dfd *Document )SetPos (x ,y float64 ){_dfd ._dg =_fe .PositionAbsolute ;_dfd ._eb =x ;_dfd ._fcd =y ;}; +// SetMarginBottom sets the left margin. +func (_ace *Document )SetMarginBottom (margin _fe .Length ){_ace ._cc .Bottom =margin };var _ _ef .Drawable =(*Document )(nil ); // NewDocument creates new HTML Document used as an input for the creator.Drawable. -func NewDocument (path string )(*Document ,error ){_geb :=&Document {};_eba ,_ag :=_g .Parse (path );if _ag !=nil {return nil ,_ag ;};switch _eba .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_geb ._dbc ,_ag =_ba .NewWebURL (path ); -if _ag !=nil {return nil ,_ag ;};return _geb ,nil ;};_ebd ,_ag :=_e .Stat (path );if _ag !=nil {return nil ,_ag ;};if !_ebd .IsDir (){_geb ._dbc ,_ag =_ba .NewHTMLFile (path );}else {_geb ._dbc ,_ag =_ba .NewZipDirectory (path );};if _ag !=nil {return nil ,_ag ; -};return _geb ,nil ;}; +func NewDocument (path string )(*Document ,error ){_eaa :=&Document {};_bec ,_aed :=_db .Parse (path );if _aed !=nil {return nil ,_aed ;};switch _bec .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_eaa ._ea ,_aed =_g .NewWebURL (path ); +if _aed !=nil {return nil ,_aed ;};return _eaa ,nil ;};_ec ,_aed :=_d .Stat (path );if _aed !=nil {return nil ,_aed ;};if !_ec .IsDir (){_eaa ._ea ,_aed =_g .NewHTMLFile (path );}else {_eaa ._ea ,_aed =_g .NewZipDirectory (path );};if _aed !=nil {return nil ,_aed ; +};return _eaa ,nil ;}; -// SetLandscapeOrientation sets document landscape page orientation. -func (_aga *Document )SetLandscapeOrientation (){_aga ._ggb =_df .Landscape }; \ No newline at end of file +// ChapterDraw implements creator.containerElement interface. +func (_dce *Document )ContainerComponent (container _ef .Drawable )(_ef .Drawable ,error ){switch container .(type ){case *_ef .Chapter :default:return nil ,_ca .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 _dce ,nil ;}; \ No newline at end of file