2021-02-08 19:36:06 +00:00
|
|
|
//
|
|
|
|
// Copyright 2020 FoxyUtils ehf. All rights reserved.
|
|
|
|
//
|
|
|
|
// This is a commercial product and requires a license to operate.
|
|
|
|
// A trial license can be obtained at https://unidoc.io
|
|
|
|
//
|
|
|
|
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by the UniDoc End User License Agreement
|
|
|
|
// terms that can be accessed at https://unidoc.io/eula/
|
|
|
|
|
2021-02-23 00:54:34 +00:00
|
|
|
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"};
|
|
|
|
|
|
|
|
|
|
|
|
// 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{
|
2021-02-08 19:36:06 +00:00
|
|
|
|
|
|
|
// PaperWidth sets the width of the paper.
|
2021-02-23 00:54:34 +00:00
|
|
|
PaperWidth _g .LengthFlag `mapstructure:"paper-width"`;
|
2021-02-08 19:36:06 +00:00
|
|
|
|
|
|
|
// PaperHeight is the height of the output paper.
|
2021-02-23 00:54:34 +00:00
|
|
|
PaperHeight _g .LengthFlag `mapstructure:"paper-height"`;
|
2021-02-08 19:36:06 +00:00
|
|
|
|
|
|
|
// PageSize is the page size string.
|
2021-02-23 00:54:34 +00:00
|
|
|
PageSize _g .PageSize `mapstructure:"page-size"`;
|
2021-02-08 19:36:06 +00:00
|
|
|
|
|
|
|
// Orientation defines if the output should be in a landscape format.
|
2021-02-23 00:54:34 +00:00
|
|
|
Orientation _g .Orientation `mapstructure:"orientation"`;
|
2021-02-08 19:36:06 +00:00
|
|
|
|
|
|
|
// MarginTop sets up the Top Margin for the output.
|
2021-02-23 00:54:34 +00:00
|
|
|
MarginTop _g .LengthFlag `mapstructure:"margin-top"`;
|
2021-02-08 19:36:06 +00:00
|
|
|
|
|
|
|
// MarginBottom sets up the Bottom Margin for the output.
|
2021-02-23 00:54:34 +00:00
|
|
|
MarginBottom _g .LengthFlag `mapstructure:"margin-bottom"`;
|
2021-02-08 19:36:06 +00:00
|
|
|
|
|
|
|
// MarginLeft sets up the Left Margin for the output.
|
2021-02-23 00:54:34 +00:00
|
|
|
MarginLeft _g .LengthFlag `mapstructure:"margin-left"`;
|
2021-02-08 19:36:06 +00:00
|
|
|
|
|
|
|
// MarginRight sets up the Right Margin for the output.
|
2021-02-23 00:54:34 +00:00
|
|
|
MarginRight _g .LengthFlag `mapstructure:"margin-right"`;};
|