├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── greetings.yml ├── ACKNOWLEDGEMENTS.md ├── LICENSE.md ├── README.md ├── cli ├── cmd │ └── cmd.go └── main.go ├── client └── client.go ├── common └── common.go ├── content └── content.go ├── go.mod ├── go.sum ├── selector └── selector.go ├── sizes └── sizes.go └── unihtml.go /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Description 11 | A clear and concise description of what the bug is. 12 | 13 | ## Expected Behavior 14 | A clear and concise description of what you expected to happen. 15 | 16 | ## Actual Behavior 17 | Steps to reproduce the behavior: 18 | 1. Go to '...' 19 | 2. Click on '....' 20 | 3. Scroll down to '....' 21 | 4. See error 22 | 23 | ## Attachments 24 | Include a self-contained reproducible code snippet and PDF file that demonstrates the issue. 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[FEATURE]" 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/greetings.yml: -------------------------------------------------------------------------------- 1 | name: Greetings 2 | 3 | on: [issues] 4 | 5 | jobs: 6 | greeting: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/first-interaction@v1 10 | with: 11 | repo-token: ${{ secrets.GITHUB_TOKEN }} 12 | issue-message: > 13 | Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, 14 | other issues go into our backlog where they are assessed and fitted into the roadmap when suitable. 15 | If you need to get this done, consider buying a license which also enables you to use it in your commercial products. 16 | More information can be found on https://unidoc.io/ 17 | pr-message: > 18 | Thanks for posting your first PR. Please be sure to sign the CLA and make sure that the 19 | the Developer Guidelines https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide were followed. 20 | You can expect that we will review the PR and post comments. The timeframe fpr this can vary depending 21 | on various factors, including which issue(s) the PR addresses and where it fits in the roadmap. 22 | Note also that customer PRs are prioritized. 23 | -------------------------------------------------------------------------------- /ACKNOWLEDGEMENTS.md: -------------------------------------------------------------------------------- 1 | Acknowledgements 2 | ---------------- 3 | 4 | UniHTML contains code from or depends on the following open source projects: 5 | 6 | * [The standard Go library](https://golang.org/pkg/#stdlib). 7 | 8 | ``` 9 | Copyright (c) 2009 The Go Authors. All rights reserved. 10 | 11 | Redistribution and use in source and binary forms, with or without 12 | modification, are permitted provided that the following conditions are 13 | met: 14 | 15 | * Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | * Redistributions in binary form must reproduce the above 18 | copyright notice, this list of conditions and the following disclaimer 19 | in the documentation and/or other materials provided with the 20 | distribution. 21 | * Neither the name of Google Inc. nor the names of its 22 | contributors may be used to endorse or promote products derived from 23 | this software without specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | ``` 37 | 38 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ## Licensing Information 2 | 3 | This software package is a commercial product and requires a license 4 | code to operate. 5 | 6 | The use of this software package is governed by the end-user license agreement 7 | (EULA) available at: https://unidoc.io/eula/ 8 | 9 | To obtain a Trial license code to evaluate the software, please visit 10 | https://unidoc.io/ 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UniHTML 2 | 3 | [UniDoc](https://unidoc.io) UniHTML is a [UniPDF](https://github.com/unidoc/unipdf) library plugin module with capability 4 | of extracting and converting HTML files and inject into PDF document. 5 | 6 | For the golang documentation check: [GoDoc](https://apidocs.unidoc.io/unihtml/latest). 7 | 8 | It requires a UniHTML Server component to work. Visit [https://unidoc.io](https://unidoc.io). 9 | 10 | [![License: UniDoc EULA](https://img.shields.io/badge/license-UniDoc%20EULA-blue)](https://unidoc.io/eula/) 11 | [![GoDoc](https://godoc.org/github.com/unidoc/unipdf?status.svg)](https://apidocs.unidoc.io/unihtml/latest/) 12 | 13 | ## Features 14 | 15 | - Create a PDF file from simple HTML file. 16 | - Create PDF file based on the directory that contains HTML along with CSS, JavaScript and Images. 17 | - Create PDF file based on the external web link. 18 | - Define output page dimensions in metric or imperial systems. 19 | - Define output page size based on the [ISO Paper Sizes](https://en.wikipedia.org/wiki/Paper_size#International_paper_sizes) for `A`, `B` series and a `Letter`. 20 | - Define output page orientation. 21 | - Define custom margin sizes for the output document. 22 | - Injection of HTML defined document into existing PDF document. 23 | - CLI that allows to execute HTML -> PDF conversion. 24 | 25 | 26 | ## Preparation 27 | 28 | UniHTML is a plugin for the [UniPDF](https://github.com/unidoc/unipdf) Golang library. 29 | 30 | It requires valid UniPDF license with the UniHTML plugin. Visit [https://unidoc.io](https://unidoc.io) to get more information. 31 | 32 | This plugin works in a pair with the UniHTML server. It is distributed using Docker images and could be downloaded directly from the `unidoccloud/unihtml` DockerHub repository 33 | 34 | 35 | ## Installation 36 | 37 | 1. Get UniHTML-Server Docker image: 38 | `docker pull unidoccloud/unihtml:latest` 39 | 2. Start UniHTML server with some output port defined: 40 | ```shell 41 | docker run -p 8080:8080 -e UNIHTML_LICENSE_PATH=path/to/license -e UNIHTML_CUSTOMER_NAME=customer_name unidoccloud/unihtml 42 | ``` 43 | 3. Define environment variable: `UNIPDF_LICENSE_PATH` with the path to the UniDoc license. 44 | 4. Define environment variable: `UNIPDF_CUSTOMER_NAME` with your customer name matching your license. 45 | 5. Get the latest version of the `github.com/unidoc/unipdf/v4` module: `go get github.com/unidoc/unipdf/v4` 46 | 47 | ## UniHTML Server Licenses 48 | 49 | 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. 50 | 51 | ### UniHTML Offline License 52 | 53 | A regular license could be set on the server by setting one of two possible environment variables: 54 | - `UNIHTML_LICENSE_PATH` - the value should be the path to the UniDoc license file with the UniHTML module. 55 | - `UNIHTML_LICENSE` - full content of valid UniDoc license with the UniHTML module. 56 | 57 | This license kind requires also an environment variable `UNIHTML_CUSTOMER_NAME` which defines the customer name provided with the UniDoc license. 58 | 59 | ### UniDoc Metered License 60 | 61 | UniHTML Server accepts also a UniDoc metered license. This could be set by providing you **API Key** in the environment variable: 62 | - `UNIDOC_METERED_API_KEY` - the value of this variable should be an **API Key** matched to your license. 63 | 64 | ### Ignore Certificate Errors 65 | If you are needed to access a self-signed certificate URL for the UniHTML, you can set the environment variable `UNIHTML_IGNORE_CERT_ERRORS` to `true` to ignore certificate errors. 66 | *However, we did not recommend this for production use, or when you are sure it is safe to set this to `true`*. 67 | 68 | ## Usage 69 | 70 | Following example connects to the UniHTML server, reads the content of the input file and converts it using `github.com/unidoc/unipdf/v3/creator` package. 71 | 72 | ```go 73 | package main 74 | 75 | import ( 76 | "fmt" 77 | "os" 78 | 79 | "github.com/unidoc/unihtml" 80 | "github.com/unidoc/unipdf/v4/creator" 81 | ) 82 | 83 | func main() { 84 | // UniHTML requires two arguments: 85 | // - Connection path to the unihtml-server i.e.: https://localhost:8080 86 | // - Input path for the file / directory to convert 87 | if len(os.Args) != 3 { 88 | fmt.Println("Err: provided invalid arguments. No UniHTML server path provided") 89 | os.Exit(1) 90 | } 91 | 92 | // Establish connection with the UniHTML Server. 93 | if err := unihtml.Connect(os.Args[1]); err != nil { 94 | fmt.Printf("Err: Connect failed: %v\n", err) 95 | os.Exit(1) 96 | } 97 | 98 | // Get new PDF Creator. 99 | c := creator.New() 100 | 101 | // Read the content of the simple.html file and load it to the conversion. 102 | doc, err := unihtml.NewDocument(os.Args[2]) 103 | if err != nil { 104 | fmt.Printf("Err: NewDocument failed: %v\n", err) 105 | os.Exit(1) 106 | } 107 | 108 | // Draw the html document file in the context of the creator. 109 | if err = c.Draw(doc); err != nil { 110 | fmt.Printf("Err: Draw failed: %v\n", err) 111 | os.Exit(1) 112 | } 113 | 114 | // Write the result file to PDF. 115 | if err = c.WriteToFile("document.pdf"); err != nil { 116 | fmt.Printf("Err: %v\n", err) 117 | os.Exit(1) 118 | } 119 | } 120 | ``` 121 | 122 | 123 | ## Contributing 124 | 125 | [![CLA assistant](https://cla-assistant.io/readme/badge/unidoc/unipdf)](https://cla-assistant.io/unidoc/unipdf) 126 | 127 | All contributors must sign a contributor license agreement before their code will be reviewed and merged. 128 | 129 | ## Support and consulting 130 | 131 | Please email us at support@unidoc.io for any queries. 132 | 133 | If you have any specific tasks that need to be done, we offer consulting in certain cases. 134 | Please contact us with a brief summary of what you need and we will get back to you with a quote, if appropriate. 135 | 136 | ## Licensing Information 137 | 138 | This software package (unihtml) is a commercial product and requires a license 139 | code to operate. 140 | 141 | The use of this software package is governed by the end-user license agreement 142 | (EULA) available at: https://unidoc.io/eula/ 143 | 144 | To obtain a Trial license code to evaluate the software, please visit 145 | https://unidoc.io/ 146 | 147 | -------------------------------------------------------------------------------- /cli/cmd/cmd.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package cmd ;import (_f "context";_c "fmt";_ca "github.com/mitchellh/go-homedir";_cc "github.com/spf13/cobra";_bg "github.com/spf13/viper";_af "github.com/unidoc/unihtml/client";_b "github.com/unidoc/unihtml/content";_d "github.com/unidoc/unihtml/sizes"; 13 | _gg "github.com/unidoc/unipdf/v4/common";_g "os";_ff "path/filepath";_ac "time";);var (_e =generateConfig {};_fd =parametersConfig {PaperWidth :_d .LengthFlag {Length :_d .Inch (8.5).Millimeters ()},PaperHeight :_d .LengthFlag {Length :_d .Inch (11).Millimeters ()},Orientation :_d .Portrait ,MarginTop :_d .LengthFlag {Length :_d .Millimeter (10)},MarginBottom :_d .LengthFlag {Length :_d .Millimeter (10)},MarginLeft :_d .LengthFlag {Length :_d .Millimeter (10)},MarginRight :_d .LengthFlag {Length :_d .Millimeter (10)}}; 14 | ); 15 | 16 | // Execute adds all child commands to the root command and sets flags appropriately. 17 | // This is called by main.main(). It only needs to happen once to the rootCmd. 18 | func Execute (){if _ab :=_bd .Execute ();_ab !=nil {_c .Println (_ab );_g .Exit (1);};};func _gdd (){_bf :=_gg .LogLevelInfo ;if _dbe {_bf =_gg .LogLevelDebug ;};if _bc {_bf =_gg .LogLevelTrace ;};_gg .Log =_gg .NewConsoleLogger (_bf );};var _cf string ; 19 | func init (){_bd .AddCommand (_fb );_fb .Flags ().IntP ("\u0070\u006f\u0072\u0074","\u0070",8080,"\u0050\u006f\u0072\u0074\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065r\u0076\u0065\u0072");_fb .Flags ().String ("\u0068\u006f\u0073\u0074","\u006co\u0063\u0061\u006c\u0068\u006f\u0073t","\u0048\u006f\u0073t\u0020\u006e\u0061\u006de\u0020\u006f\u0066\u0020\u0074\u0068\u0065 \u0075\u006e\u0069\u0068\u0074\u006d\u006c\u0020\u0073\u0065\u0072\u0076\u0065\u0072"); 20 | _fb .Flags ().BoolP ("\u0068\u0074\u0074p\u0073","\u0073",false ,"\u0050\u0072o\u0074\u006f\u0063\u006fl\u0020\u0075s\u0065\u0064\u0020\u0069\u006e\u0020\u0073\u0065r\u0076\u0065\u0072\u0020\u0063\u006f\u006d\u006d\u0075\u006e\u0069\u0063a\u0074\u0069\u006f\u006e"); 21 | _fb .Flags ().StringP ("\u0070\u0072\u0065\u0066\u0069\u0078","\u0078","","\u0050u\u0062\u006ci\u0063\u0020\u0061\u0070i\u0020\u0070\u0072e\u0066\u0069\u0078\u0020\u0075\u0073\u0065\u0064\u0020by\u0020\u0074\u0068e\u0020\u0075n\u0069\u0068\u0074\u006d\u006c\u0020s\u0065\u0072v\u0065\u0072"); 22 | _fb .Flags ().Var (&_fd .PaperWidth ,"p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068","\u0073\u0065\u0074s \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068");_fb .Flags ().Var (&_fd .PaperHeight ,"\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070a\u0070\u0065\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074"); 23 | _fb .Flags ().Var (&_fd .PageSize ,"\u0070\u0061\u0070\u0065\u0072\u002d\u0073\u0069\u007a\u0065","s\u0065\u0074\u0073\u0020up\u0020t\u0068\u0065\u0020\u0070\u0061g\u0065\u0020\u0073\u0069\u007a\u0065");_fb .Flags ().Var (&_fd .Orientation ,"o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e","\u0073\u0065\u0074\u0073 \u0075\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0067e\u0020o\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e"); 24 | _fb .Flags ().Var (&_fd .MarginTop ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074o\u0070");_fb .Flags ().Var (&_fd .MarginBottom ,"\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d","\u0073e\u0074\u0073\u0020\u0075p\u0020\u0074\u0068\u0065\u0020m\u0061r\u0067i\u006e\u002d\u0062\u006f\u0074\u0074\u006fm"); 25 | _fb .Flags ().Var (&_fd .MarginRight ,"\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074","\u0073e\u0074\u0073\u0020\u0075\u0070\u0020\u0074\u0068\u0065\u0020\u006da\u0072\u0067\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074");_fb .Flags ().Var (&_fd .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074"); 26 | };func _feg (){if _cf !=""{_bg .SetConfigFile (_cf );}else {_ee ,_abae :=_ca .Dir ();if _abae !=nil {_c .Println (_abae );_g .Exit (1);};_bg .AddConfigPath (_ee );_bg .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063"); 27 | };_bg .AutomaticEnv ();if _bdg :=_bg .ReadInConfig ();_bdg ==nil {_c .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_bg .ConfigFileUsed ());};};var _bd =&_cc .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"}; 28 | type parametersConfig struct{ 29 | 30 | // PaperWidth sets the width of the paper. 31 | PaperWidth _d .LengthFlag `mapstructure:"paper-width"`; 32 | 33 | // PaperHeight is the height of the output paper. 34 | PaperHeight _d .LengthFlag `mapstructure:"paper-height"`; 35 | 36 | // PageSize is the page size string. 37 | PageSize _d .PageSize `mapstructure:"page-size"`; 38 | 39 | // Orientation defines if the output should be in a landscape format. 40 | Orientation _d .Orientation `mapstructure:"orientation"`; 41 | 42 | // MarginTop sets up the Top Margin for the output. 43 | MarginTop _d .LengthFlag `mapstructure:"margin-top"`; 44 | 45 | // MarginBottom sets up the Bottom Margin for the output. 46 | MarginBottom _d .LengthFlag `mapstructure:"margin-bottom"`; 47 | 48 | // MarginLeft sets up the Left Margin for the output. 49 | MarginLeft _d .LengthFlag `mapstructure:"margin-left"`; 50 | 51 | // MarginRight sets up the Right Margin for the output. 52 | MarginRight _d .LengthFlag `mapstructure:"margin-right"`;};var _fb =&_cc .Command {Use :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065",Short :"\u0047\u0065\u006e\u0065\u0072a\u0074\u0065\u0073\u0020\u0050\u0044F\u0020\u0062\u0061\u0073\u0065\u0064\u0020o\u006e\u0020\u0074h\u0065\u0020\u0070\u0072o\u0076\u0069\u0064\u0065\u0064\u0020H\u0054\u004d\u004c\u0020\u006f\u0072\u0020\u0064\u0069\u0072\u0065\u0063\u0074\u006f\u0072\u0079\u0020w\u0069\u0074\u0068\u0020\u0074\u0068\u0065\u0020\u0048\u0054\u004d\u004c\u0020\u0066\u0069\u006c\u0065\u0073\u002e",Long :"A\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064e\u0073\u0063\u0072\u0069\u0070\u0074\u0069on\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061\u006e\u0073\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073 \u0061\u006e\u0064\u0020\u006c\u0069\u006b\u0065l\u0079\u0020\u0063o\u006e\u0074\u0061\u0069\u006e\u0073\u0020\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u000a\u0061\u006e\u0064\u0020\u0075\u0073\u0061\u0067\u0065\u0020\u006f\u0066\u0020u\u0073\u0069\u006e\u0067\u0020\u0079o\u0075\u0072\u0020\u0063o\u006d\u006d\u0061\u006e\u0064\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006d\u0070\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062r\u0061\u0020\u0069\u0073\u0020\u0061\u0020\u0043\u004c\u0049\u0020\u006c\u0069\u0062\u0072\u0061r\u0079 \u0066\u006f\u0072\u0020\u0047\u006f\u0020\u0074\u0068\u0061\u0074\u0020\u0065\u006d\u0070\u006f\u0077\u0065\u0072\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0020\u0069s\u0020\u0061\u0020\u0074\u006f\u006fl\u0020\u0074\u006f\u0020\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0074\u0068e\u0020n\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006c\u0065s\u000a\u0074o\u0020\u0071\u0075\u0069\u0063\u006b\u006c\u0079\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020C\u006fb\u0072\u0061\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074io\u006e\u002e",Run :_ga ,Args :_cc .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; 53 | type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};func init (){_cc .OnInitialize (_feg );_bd .PersistentFlags ().BoolVarP (&_dbe ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065"); 54 | _bd .PersistentFlags ().BoolVarP (&_bc ,"\u0076e\u0072\u0062\u006f\u0073\u0065","\u0076",false ,"\u0056\u0065\u0072\u0062\u006f\u0073e\u0020\u0069\u006e\u0066\u006f\u0072\u006d\u0061\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0074\u0068\u0065\u0020\u0063l\u0069\u0065\u006e\u0074"); 55 | _bd .PersistentFlags ().StringVar (&_cf ,"\u0063\u006f\u006e\u0066\u0069\u0067","","\u0063\u006f\u006e\u0066\u0069\u0067\u0020\u0066i\u006c\u0065\u0020(d\u0065\u0066\u0061\u0075\u006c\u0074 \u0069\u0073\u0020\u0024\u0048\u004f\u004d\u0045\u002f\u002e\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0072\u0063\u002e\u0079\u0061m\u006c\u0029"); 56 | _bd .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};var (_dbe ,_bc bool ;);func _ga (cmd *_cc .Command ,_da []string ){_gf :=_ac .Now (); 57 | if _be :=_bg .BindPFlags (cmd .Flags ());_be !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_be );_g .Exit (1);};if _fff :=_bg .Unmarshal (&_e );_fff !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_fff );_g .Exit (1); 58 | };_gdd ();_eb ,_dab :=_g .Stat (_da [0]);if _dab !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dab );_g .Exit (1);};if !_eb .IsDir (){if _ff .Ext (_eb .Name ())!="\u002e\u0068\u0074m\u006c"{_c .Printf ("\u0045\u0072r\u003a\u0020\u0043\u0075\u0072\u0072\u0065\u006e\u0074\u006c\u0079\u0020\u006f\u006e\u006c\u0079\u0020\u0048\u0054M\u004c\u0020\u0066\u0069\u006c\u0065s\u0020\u0069\u006e\u0070\u0075\u0074\u0053\u0074\u0061\u0074\u0020\u0061\u0072\u0065 \u0073\u0075p\u0070\u006f\u0072\u0074e\u0064\u002e\u0020\u0049\u006ep\u0075\u0074\u003a\u0020\u0025\u0073\u000a",_da [0]); 59 | _g .Exit (1);};};_bga ,_dab :=_g .OpenFile (_da [1],_g .O_CREATE |_g .O_WRONLY |_g .O_TRUNC ,0700);if _dab !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dab );_g .Exit (1);};defer _bga .Close ();_db :=_af .New (_af .Options {HTTPS :_e .Https ,Hostname :_e .Host ,Port :_e .Port ,Prefix :_e .Prefix }); 60 | _ffb ,_cae :=_f .WithTimeout (_f .Background (),_ac .Second *10);defer _cae ();_cad :=_ac .Now ();var _caf _b .Content ;if _eb .IsDir (){_caf ,_dab =_b .NewZipDirectory (_da [0]);}else {_caf ,_dab =_b .NewHTMLFile (_da [0]);};if _dab !=nil {_c .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_dab ); 61 | _g .Exit (1);};_ggf ,_dab :=_af .BuildHTMLQuery ().PaperWidth (_fd .PaperWidth .Length ).PaperHeight (_fd .PaperHeight .Length ).PageSize (_fd .PageSize ).MarginTop (_fd .MarginTop .Length ).MarginBottom (_fd .MarginBottom .Length ).MarginLeft (_fd .MarginLeft .Length ).MarginRight (_fd .MarginRight .Length ).Orientation (_fd .Orientation ).SetContent (_caf ).Query (); 62 | if _dab !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dab );_g .Exit (1);};_dc ,_dab :=_db .ConvertHTML (_ffb ,_ggf );if _dab !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dab );_g .Exit (1);};_gg .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_ac .Since (_cad )); 63 | _cad =_ac .Now ();_ ,_dab =_bga .Write (_dc .Data );if _dab !=nil {_c .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_dab );_g .Exit (1);};_gg .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_ac .Since (_cad )); 64 | _c .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_ac .Since (_gf ));}; -------------------------------------------------------------------------------- /cli/main.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package main ;import _ec "github.com/unidoc/unihtml/cli/cmd";func main (){_ec .Execute ()}; -------------------------------------------------------------------------------- /client/client.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | // Package client contains HTML Converter HTTP Client. The Client implements htmlcreator.HTMLConverter interface 13 | // for the UniPDF module and can be used as a plugin for the UniPDF creator.Creator. 14 | package client ;import (_b "bytes";_ag "compress/flate";_aa "compress/gzip";_e "context";_g "encoding/json";_ee "errors";_eg "fmt";_be "github.com/unidoc/unihtml/content";_gf "github.com/unidoc/unihtml/selector";_dd "github.com/unidoc/unihtml/sizes";_dga "github.com/unidoc/unipdf/v4/common"; 15 | _d "io";_gc "net";_ad "net/http";_eee "net/url";_bb "strconv";_dg "strings";_eb "time";); 16 | 17 | // WithHostname sets the Hostname option for the client options. 18 | func WithHostname (option string )Option {return func (_ba *Options ){_ba .Hostname =option }}; 19 | 20 | // BySelector is a structure that defines a selector with it's query 'by' type. 21 | type BySelector struct{Selector string `json:"selector"`;By _gf .ByType `json:"by"`;}; 22 | 23 | // HealthCheck connects to the server and check the health status of the server. 24 | func (_gcd *Client )HealthCheck (ctx _e .Context )error {_bd :=_gcd .Options .Addr ();_bd =_eg .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_bd );_c ,_ed :=_ad .NewRequest ("\u0047\u0045\u0054",_bd ,nil );if _ed !=nil {return _ed ;};_c =_c .WithContext (ctx ); 25 | _ef ,_ed :=_gcd .Client .Do (_c );if _ed !=nil {return _ed ;};switch _ef .StatusCode {case _ad .StatusOK :return nil ;case _ad .StatusNotFound :return ErrNotFound ;case _ad .StatusInternalServerError :return ErrInternalError ;case _ad .StatusBadGateway :return ErrBadGateway ; 26 | default:return ErrNotImplemented ;};}; 27 | 28 | // Validate checks if the QueryBuilder had no errors during composition and creation. 29 | func (_cfe *QueryBuilder )Validate ()error {if _cfe ._ge !=nil {return _cfe ._ge ;};return _cfe ._gfa .Validate ();}; 30 | 31 | // Addr gets the HTTP address URI used by the http.Client. 32 | func (_gdc *Options )Addr ()string {_aga :=_dg .Builder {};_aga .WriteString ("\u0068\u0074\u0074\u0070");if _gdc .HTTPS {_aga .WriteRune ('s');};_aga .WriteString ("\u003a\u002f\u002f");_aga .WriteString (_gdc .Hostname );_aga .WriteRune (':');_aga .WriteString (_bb .Itoa (_gdc .Port )); 33 | if _gdc .Prefix !=""{_aga .WriteString (_gdc .Prefix );};return _aga .String ();};func (_ae *Client )setQueryValues (_aac *_ad .Request ,_gdb *Query ){_gde :=_aac .URL .Query ();_egac :=_gdb .PageParameters ;if _egac .PageSize !=nil {_gde .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_egac .PageSize .String ()); 34 | };if _egac .PaperHeight !=nil {_gde .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_egac .PaperHeight .String ());};if _egac .PaperWidth !=nil {_gde .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_egac .PaperWidth .String ()); 35 | };if _egac .MarginTop !=nil {_gde .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_egac .MarginTop .String ());};if _egac .MarginBottom !=nil {_gde .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_egac .MarginBottom .String ()); 36 | };if _egac .MarginRight !=nil {_gde .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_egac .MarginRight .String ());};if _egac .MarginLeft !=nil {_gde .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_egac .MarginLeft .String ()); 37 | };if _egac .Orientation ==_dd .Landscape {_gde .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_egac .Orientation .String ());};if _gdb .RenderParameters .WaitTime !=0{_gde .Set ("\u006d\u0069\u006e\u0069\u006d\u0075\u006d\u002d\u006c\u006f\u0061\u0064-\u0074\u0069\u006d\u0065",_bb .FormatInt (int64 (_gdb .RenderParameters .WaitTime /_eb .Millisecond ),10)); 38 | };_aac .URL .RawQuery =_gde .Encode ();}; 39 | 40 | // MarginBottom sets up the MarginBottom parameter for the query. 41 | func (_afc *QueryBuilder )MarginBottom (marginBottom _dd .Length )*QueryBuilder {_afc ._gfa .PageParameters .MarginBottom =marginBottom ;return _afc ;}; 42 | 43 | // SetContent sets custom data with it's content type. 44 | func (_dgad *QueryBuilder )SetContent (content _be .Content )*QueryBuilder {if _dgad ._ge !=nil {return _dgad ;};switch content .Method (){case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if _dgad ._gfa .ContentType !=""{_dgad ._ge =ErrContentTypeDeclared ; 45 | return _dgad ;};if content .ContentType ()==""{_dgad ._ge =_eg .Errorf ("\u0065\u006d\u0070\u0074y\u0020\u0063\u0075\u0073\u0074\u006f\u006d\u0020\u0063\u006fn\u0074e\u006e\u0074\u0020\u0074\u0079\u0070\u0065 \u0025\u0077",ErrContentType );return _dgad ; 46 | };_dgad ._gfa .Content =content .Data ();_dgad ._gfa .ContentType =content .ContentType ();case "\u0077\u0065\u0062":if _dgad ._gfa .ContentType !=""{_dgad ._ge =ErrContentTypeDeclared ;return _dgad ;};_dgad ._gfa .URL =string (content .Data ());_dgad ._gfa .ContentType =content .ContentType (); 47 | default:_dgad ._ge =_eg .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020\u006d\u0065\u0074\u0068\u006f\u0064:\u0020\u0025\u0073",content .Method ());return _dgad ;};_dgad ._gfa .Method =content .Method (); 48 | return _dgad ;}; 49 | 50 | // PageParameters are the query parameters used in the PDF generation. 51 | type PageParameters struct{ 52 | 53 | // PaperWidth sets the width of the paper. 54 | PaperWidth _dd .Length `schema:"paper-width" json:"paperWidth"`; 55 | 56 | // PaperHeight is the height of the output paper. 57 | PaperHeight _dd .Length `schema:"paper-height" json:"paperHeight"`; 58 | 59 | // PageSize is the page size string. 60 | PageSize *_dd .PageSize `schema:"page-size" json:"pageSize"`; 61 | 62 | // Orientation defines if the output should be in a landscape format. 63 | Orientation _dd .Orientation `schema:"orientation" json:"orientation"`; 64 | 65 | // MarginTop sets up the Top Margin for the output. 66 | MarginTop _dd .Length `schema:"margin-top" json:"marginTop"`; 67 | 68 | // MarginBottom sets up the Bottom Margin for the output. 69 | MarginBottom _dd .Length `schema:"margin-bottom" json:"marginBottom"`; 70 | 71 | // MarginLeft sets up the Left Margin for the output. 72 | MarginLeft _dd .Length `schema:"margin-left" json:"marginLeft"`; 73 | 74 | // MarginRight sets up the Right Margin for the output. 75 | MarginRight _dd .Length `schema:"margin-right" json:"marginRight"`;}; 76 | 77 | // Query gets the Query from provided query builder. If some error occurred during build process 78 | // or the input is not valid the function would return an error. 79 | func (_ege *QueryBuilder )Query ()(*Query ,error ){if _egd :=_ege .Validate ();_egd !=nil {return nil ,_egd ;};return &_ege ._gfa ,nil ;}; 80 | 81 | // DefaultPageParameters creates default parameters. 82 | func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_dd .Portrait }}; 83 | 84 | // MarginLeft sets up the MarginLeft parameter for the query. 85 | func (_fgg *QueryBuilder )MarginLeft (marginLeft _dd .Length )*QueryBuilder {_fgg ._gfa .PageParameters .MarginLeft =marginLeft ;return _fgg ;};type generatePDFRequestV1 struct{Content []byte `json:"content"`;ContentType string `json:"contentType"`;ContentURL string `json:"contentURL"`; 86 | Method string `json:"method"`;ExpiresAt int64 `json:"expiresAt"`;TimeoutDuration int64 `json:"timeoutDuration,omitempty"`;PageParameters ;RenderParameters ;}; 87 | 88 | // WaitVisible waits for the selector to get visible. 89 | func (_dbe *QueryBuilder )WaitVisible (selector string ,by _gf .ByType )*QueryBuilder {_dbe ._gfa .RenderParameters .WaitVisible =append (_dbe ._gfa .RenderParameters .WaitVisible ,BySelector {Selector :selector ,By :by });return _dbe ;}; 90 | 91 | // Validate checks the validity of the RenderParameters. 92 | func (_fg *RenderParameters )Validate ()error {if _fg .WaitTime > _eb .Minute *3{return _ee .New ("\u0074\u006f\u006f\u0020\u006c\u006f\u006e\u0067 \u006d\u0069\u006eim\u0075\u006d\u0020\u006c\u006f\u0061d\u0020\u0074\u0069\u006d\u0065\u002e\u0020\u004d\u0061\u0078\u0069\u006d\u0075\u006d\u0020i\u0073\u0020\u0033\u0020\u006d\u0069\u006e\u0075t\u0065\u0073"); 93 | };for _ ,_bfd :=range _fg .WaitReady {if _gbc :=_bfd .Validate ();_gbc !=nil {return _eg .Errorf ("\u006f\u006e\u0065\u0020\u006f\u0066\u0020w\u0061\u0069\u0074 \u0072\u0065\u0061\u0064y\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072\u0020\u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069\u0064\u003a\u0020\u0025\u0077",_gbc ); 94 | };};return nil ;}; 95 | 96 | // Option is a function that changes client options. 97 | type Option func (_ea *Options ); 98 | 99 | // ConvertHTML converts provided Query input into PDF file data. 100 | // Implements creator.HTMLConverter interface. 101 | func (_af *Client )ConvertHTML (ctx _e .Context ,q *Query )(*PDFResponse ,error ){if _db :=q .Validate ();_db !=nil {return nil ,_db ;};_ebc ,_bbf :=_af .getGenerateRequest (ctx ,q );if _bbf !=nil {return nil ,_bbf ;};_dga .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_ebc .Method ,_ebc .URL .Hostname (),_ebc .URL .Path ,_ebc .Header ,_ebc .URL .Query ()); 102 | _eba :=*_af .Client ;if q .TimeoutDuration !=0{_eba .Timeout =q .TimeoutDuration ;};_ff ,_bbf :=_eba .Do (_ebc );if _bbf !=nil {return nil ,_bbf ;};var _ffe error ;switch _ff .StatusCode {case _ad .StatusNotFound :_ffe =ErrNotFound ;case _ad .StatusBadRequest :_ffe =ErrBadRequest ; 103 | case _ad .StatusNotImplemented :_ffe =ErrNotImplemented ;case _ad .StatusUnauthorized :_ffe =ErrUnauthorized ;case _ad .StatusRequestTimeout :_ffe =ErrTimedOut ;case _ad .StatusCreated :default:_ffe =ErrInternalError ;};_cf :=_ff .Body ;switch _ff .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067"){case "\u0067\u007a\u0069\u0070":_cf ,_bbf =_aa .NewReader (_ff .Body ); 104 | if _bbf !=nil {return nil ,_bbf ;};case "\u0064e\u0066\u006c\u0061\u0074\u0065":_cf =_ag .NewReader (_ff .Body );case "":default:return nil ,_eg .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0043o\u006e\u0074\u0065\u006e\u0074\u002dE\u006e\u0063\u006f\u0064\u0069\u006e\u0067\u003a\u0020\u0025\u0073\u0020\u0068e\u0061\u0064\u0065\u0072",_ff .Header .Get ("\u0043\u006fn\u0074\u0065\u006et\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067")); 105 | };_ab ,_bbf :=_d .ReadAll (_cf );if _bbf !=nil &&_ffe ==nil {return nil ,_eg .Errorf ("\u0055\u006e\u0069HT\u004d\u004c\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_bbf );};_dga .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_ff .StatusCode ,_ebc .Method ,_ebc .URL .Host ,_ebc .URL .Path ); 106 | if _ffe !=nil {return nil ,_eg .Errorf ("\u0025\u0073\u0020%\u0077",string (_ab ),_ffe );};_eff :=_ff .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_dga .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_eff ); 107 | return &PDFResponse {ID :_eff ,Data :_ab },nil ;}; 108 | 109 | // Validate checks validity of the selector. 110 | func (_ada BySelector )Validate ()error {if _ada .Selector ==""{return _ee .New ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0065\u006d\u0070\u0074\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");};if _bf :=_ada .By .Validate ();_bf !=nil {return _bf ; 111 | };return nil ;}; 112 | 113 | // Portrait sets up the portrait page orientation. 114 | func (_fa *QueryBuilder )Portrait ()*QueryBuilder {_fa ._gfa .PageParameters .Orientation =_dd .Portrait ;return _fa ;}; 115 | 116 | // PaperHeight sets up the PaperHeight (in cm) parameter for the query. 117 | func (_cd *QueryBuilder )PaperHeight (paperHeight _dd .Length )*QueryBuilder {_cd ._gfa .PageParameters .PaperHeight =paperHeight ;return _cd ;};var (ErrNotFound =_ee .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_ee .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074"); 118 | 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"); 119 | ErrUnauthorized =_ee .New ("\u0075\u006e\u0061u\u0074\u0068\u006f\u0072\u0069\u007a\u0065\u0064");ErrTimedOut =_ee .New ("\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020\u0074\u0069\u006d\u0065d\u0020\u006f\u0075\u0074");); 120 | 121 | // Options are the client options used by the HTTP client. 122 | type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _eb .Duration ;Prefix string ;}; 123 | 124 | // Orientation sets the page orientation for the Query. 125 | func (_abg *QueryBuilder )Orientation (orientation _dd .Orientation )*QueryBuilder {_abg ._gfa .PageParameters .Orientation =orientation ;return _abg ;}; 126 | 127 | // BuildHTMLQuery creates a Query builder that is supposed to create valid 128 | func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; 129 | 130 | // Validate checks if provided Query is valid. 131 | func (_ffa *Query )Validate ()error {switch _ffa .Method {case "\u0077\u0065\u0062":if _ffa .URL ==""{return ErrMissingData ;};case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":if len (_ffa .Content )==0{return ErrMissingData ;};if _ffa .ContentType ==""{return ErrContentType ; 132 | };default:return _eg .Errorf ("\u0075\u006e\u0064ef\u0069\u006e\u0065\u0064\u0020\u0063\u006f\u006e\u0074e\u006et\u0020q\u0075e\u0072\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0072\u003a\u0020\u0025\u0073",_ffa .Method );};if _cg :=_ffa .PageParameters .Validate (); 133 | _cg !=nil {return _cg ;};if _bff :=_ffa .RenderParameters .Validate ();_bff !=nil {return _bff ;};return nil ;}; 134 | 135 | // New creates new client with provided options. 136 | func New (o Options )*Client {o .DefaultTimeout =_eb .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _ega =&_ad .Transport {DialContext :(&_gc .Dialer {Timeout :5*_eb .Second }).DialContext ,TLSHandshakeTimeout :5*_eb .Second }; 137 | _dga .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_ad .Client {Transport :_ega ,Timeout :o .DefaultTimeout }};}; 138 | 139 | // RenderParameters are the parameters related with the rendering. 140 | type RenderParameters struct{WaitTime _eb .Duration `schema:"minimum-load-time" json:"waitTime"`;WaitReady []BySelector `json:"waitReady"`;WaitVisible []BySelector `json:"waitVisible"`;}; 141 | 142 | // PaperWidth sets up the PaperWidth (in cm) parameter for the query. 143 | func (_bfg *QueryBuilder )PaperWidth (paperWidth _dd .Length )*QueryBuilder {_bfg ._gfa .PageParameters .PaperWidth =paperWidth ;return _bfg ;};var (ErrMissingData =_ee .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061"); 144 | 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"); 145 | ); 146 | 147 | // PageSize sets up the PageSize parameter for the query. 148 | func (_afb *QueryBuilder )PageSize (pageSize _dd .PageSize )*QueryBuilder {if pageSize !=_dd .Undefined {_afb ._gfa .PageParameters .PageSize =&pageSize ;};return _afb ;}; 149 | 150 | // WithPort sets the Port option for the client options. 151 | func WithPort (option int )Option {return func (_dc *Options ){_dc .Port =option }}; 152 | 153 | // Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. 154 | type Query struct{Content []byte ;ContentType string ;URL string ;Method string ;PageParameters PageParameters ;RenderParameters RenderParameters ;TimeoutDuration _eb .Duration ;}; 155 | 156 | // WaitTime sets the minimum load time parameter for the page rendering. 157 | func (_edf *QueryBuilder )WaitTime (d _eb .Duration )*QueryBuilder {_edf ._gfa .RenderParameters .WaitTime =d ;return _edf ;}; 158 | 159 | // WaitReady waits for the selector to get ready - 'loaded'. 160 | func (_badc *QueryBuilder )WaitReady (selector string ,by _gf .ByType )*QueryBuilder {_badc ._gfa .RenderParameters .WaitReady =append (_badc ._gfa .RenderParameters .WaitReady ,BySelector {Selector :selector ,By :by });return _badc ;};func (_fd *Client )getGenerateRequest (_gb _e .Context ,_fe *Query )(*_ad .Request ,error ){_bdg :=generatePDFRequestV1 {Method :_fe .Method ,PageParameters :_fe .PageParameters ,RenderParameters :_fe .RenderParameters ,TimeoutDuration :int64 (_fe .TimeoutDuration )}; 161 | switch _fe .Method {case "\u0077\u0065\u0062":_bdg .ContentURL =_fe .URL ;case "\u0064\u0069\u0072","\u0068\u0074\u006d\u006c":_bdg .ContentType =_fe .ContentType ;_bdg .Content =_fe .Content ;};_abe :=new (_b .Buffer );if _ce :=_g .NewEncoder (_abe ).Encode (&_bdg ); 162 | _ce !=nil {return nil ,_eg .Errorf ("e\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0076",_ce );};_beg :=_fd .Options .Addr ();_beg =_eg .Sprintf ("\u0025s\u002f\u0076\u0031\u002f\u0070\u0064f",_beg ); 163 | _ca ,_bbg :=_ad .NewRequest ("\u0050\u004f\u0053\u0054",_beg ,_abe );if _bbg !=nil {return nil ,_bbg ;};_ca .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e"); 164 | _ca .Header .Set ("\u0041c\u0063e\u0070\u0074\u002d\u0045\u006e\u0063\u006f\u0064\u0069\u006e\u0067","\u0064\u0065\u0066\u006ca\u0074\u0065\u002c\u0020\u0067\u007a\u0069\u0070\u003b\u0071=\u0031.\u0030\u002c\u0020\u002a\u003b\u0071\u003d0\u002e\u0035"); 165 | _ca =_ca .WithContext (_gb );return _ca ,nil ;}; 166 | 167 | // Validate checks if the parameters are valid. 168 | func (_da *PageParameters )Validate ()error {if _da .PaperWidth !=nil {if _da .PaperWidth .Millimeters ()< 0{return _ee .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068"); 169 | };};if _da .PaperHeight !=nil {if _da .PaperHeight .Millimeters ()< 0{return _ee .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074"); 170 | };};if _da .MarginTop !=nil {if _da .MarginTop .Millimeters ()< 0{return _ee .New ("\u006e\u0065\u0067\u0061t\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020f\u006fr\u0020\u004d\u0061\u0072\u0067\u0069\u006eT\u006f\u0070");};};if _da .MarginBottom !=nil {if _da .MarginBottom .Millimeters ()< 0{return _ee .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d"); 171 | };};if _da .MarginLeft !=nil {if _da .MarginLeft .Millimeters ()< 0{return _ee .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};}; 172 | if _da .MarginRight !=nil {if _da .MarginRight .Millimeters ()< 0{return _ee .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074"); 173 | };};if _da .PageSize !=nil &&!_da .PageSize .IsAPageSize (){return _ee .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; 174 | 175 | // QueryBuilder is the query that converts HTMLConverter defined data 176 | type QueryBuilder struct{_gfa Query ;_ge error ;}; 177 | 178 | // PDFResponse is the response used by the HTMLConverter. 179 | type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; 180 | 181 | // ParseOptions parses options for the Client. 182 | func ParseOptions (connectPath string )(Options ,error ){if !_dg .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_f ,_gd :=_eee .Parse (connectPath );if _gd !=nil {return Options {},_eg .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c"); 183 | };var _gg int ;if _f .Port ()!=""{_gg ,_gd =_bb .Atoi (_f .Port ());if _gd !=nil {return Options {},_eg .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_gd );}; 184 | };return Options {Hostname :_f .Hostname (),Port :_gg ,HTTPS :_f .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_f .Path },nil ;}; 185 | 186 | // MarginTop sets up the MarginTop parameter for the query. 187 | func (_bdb *QueryBuilder )MarginTop (marginTop _dd .Length )*QueryBuilder {_bdb ._gfa .PageParameters .MarginTop =marginTop ;return _bdb ;}; 188 | 189 | // MarginRight sets up the MarginRight parameter for the query. 190 | func (_efc *QueryBuilder )MarginRight (marginRight _dd .Length )*QueryBuilder {_efc ._gfa .PageParameters .MarginRight =marginRight ;return _efc ;}; 191 | 192 | // WithDefaultTimeout sets the DefaultTimeout option for the client options. 193 | func WithDefaultTimeout (option _eb .Duration )Option {return func (_bad *Options ){_bad .DefaultTimeout =option };}; 194 | 195 | // WithHTTPS sets the TLS option for the client options. 196 | func WithHTTPS (useHTTPS bool )Option {return func (_ggb *Options ){_ggb .HTTPS =useHTTPS }}; 197 | 198 | // Landscape sets up the landscape portrait orientation. 199 | func (_de *QueryBuilder )Landscape ()*QueryBuilder {_de ._gfa .PageParameters .Orientation =_dd .Landscape ;return _de ;}; 200 | 201 | // TimeoutDuration sets the server query duration timeout. 202 | // Once the timeout is reached the server will return an error. 203 | func (_aef *QueryBuilder )TimeoutDuration (d _eb .Duration )*QueryBuilder {_aef ._gfa .TimeoutDuration =d ;return _aef ;}; 204 | 205 | // Client is a structure that is a HTTP client for the unihtml server. 206 | type Client struct{Options Options ;Client *_ad .Client ;}; 207 | 208 | // Err gets the error which could occur in the query. 209 | func (_adg *QueryBuilder )Err ()error {return _adg ._ge }; 210 | 211 | // WithPrefix sets the client prefix. 212 | func WithPrefix (prefix string )Option {return func (_aad *Options ){_aad .Prefix =prefix }}; -------------------------------------------------------------------------------- /common/common.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | // Package common contains common properties used by the subpackages. 13 | package common ;import _b "time";const _ee =12;const _f =5; 14 | 15 | // UtcTimeFormat returns a formatted string describing a UTC timestamp. 16 | func UtcTimeFormat (t _b .Time )string {return t .Format (_e )+"\u0020\u0055\u0054\u0043"};var ReleasedAt =_b .Date (_d ,_f ,_dg ,_ee ,_be ,0,0,_b .UTC );const _be =20;const _dg =26;const _e ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034"; 17 | const Version ="\u0030\u002e\u0031\u0033\u002e\u0030";const _d =2025; -------------------------------------------------------------------------------- /content/content.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package content ;import (_ea "archive/zip";_d "bytes";_fa "fmt";_ec "net/url";_fg "os";_f "strings";); 13 | 14 | // ContentType implements Content interface. 15 | func (_fe *webURL )ContentType ()string {return "\u0074\u0065\u0078\u0074\u002f\u0070\u006c\u0061\u0069\u006e";}; 16 | 17 | // ContentType implements Content interface. 18 | func (_cg *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";};type htmlFile struct{_c _d .Buffer }; 19 | 20 | // Method implements Content interface. 21 | func (_gce *StringContent )Method ()string {return "\u0068\u0074\u006d\u006c"}; 22 | 23 | // Method gets the web url query method. 24 | func (_ff *webURL )Method ()string {return "\u0077\u0065\u0062"};type webURL struct{_ee string }; 25 | 26 | // NewWebURL creates new Content webURL for provided input URL path. 27 | func NewWebURL (path string )(Content ,error ){if _ ,_dd :=_ec .Parse (path );_dd !=nil {return nil ,_dd ;};return &webURL {_ee :path },nil ;}; 28 | 29 | // Content is an interface used for putting the content into Client Query. 30 | type Content interface{ContentType ()string ;Method ()string ;Data ()[]byte ;}; 31 | 32 | // ContentType implements Content interface. 33 | func (_ca *htmlFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"};func (_ge *zipDirectory )zipPath (_gd ,_gc string )error {_egf ,_gbg :=_fg .ReadDir (_gd );if _gbg !=nil {return _fa .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_gd ,_gbg ); 34 | };_dde :=&_f .Builder {};for _ ,_fc :=range _egf {_ae ,_bg :=_fc .Info ();if _bg !=nil {return _bg ;};_fb ,_ed :=_ge .zipBasePaths (_ae ,_gd ,_gc ,_fc .IsDir (),_dde );if _fc .IsDir (){if _bf :=_ge .zipPath (_fb ,_ed );_bf !=nil {return _bf ;};continue ; 35 | };_dab ,_bg :=_fg .ReadFile (_fb );if _bg !=nil {return _bg ;};_fce ,_bg :=_ge ._gb .Create (_ed );if _bg !=nil {return _bg ;};if _ ,_bg =_fce .Write (_dab );_bg !=nil {return _bg ;};};return nil ;}; 36 | 37 | // NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' 38 | // and stores in it's in-memory buffer. 39 | func NewZipDirectory (dirPath string )(Content ,error ){_db :=&zipDirectory {_cb :_d .Buffer {}};_db ._gb =_ea .NewWriter (&_db ._cb );if _cag :=_db .zipPath (dirPath ,"");_cag !=nil {return nil ,_cag ;};if _de :=_db ._gb .Close ();_de !=nil {return nil ,_de ; 40 | };return _db ,nil ;}; 41 | 42 | // Data implements Content interface. 43 | func (_b *htmlFile )Data ()[]byte {return _b ._c .Bytes ()}; 44 | 45 | // NewStringContent creates a new StringContent. 46 | func NewStringContent (html string )(*StringContent ,error ){return &StringContent {_faa :html },nil }; 47 | 48 | // Method gets the query method. 49 | func (_g *htmlFile )Method ()string {return "\u0068\u0074\u006d\u006c"}; 50 | 51 | // StringContent implements Content interface for an HTML string. 52 | type StringContent struct{_faa string };type zipDirectory struct{_cb _d .Buffer ;_gb *_ea .Writer ;};func (_cgc *zipDirectory )zipBasePaths (_fgf _fg .FileInfo ,_bfc ,_dc string ,_ac bool ,_cd *_f .Builder )(string ,string ){_cd .WriteString (_bfc );if !_f .HasSuffix (_bfc ,"\u002f"){_cd .WriteRune ('/'); 53 | };_cd .WriteString (_fgf .Name ());if _ac {_cd .WriteRune ('/');};_ce :=_cd .String ();_cd .Reset ();_cd .WriteString (_dc );_cd .WriteString (_fgf .Name ());if _ac {_cd .WriteRune ('/');};_aec :=_cd .String ();_cd .Reset ();return _ce ,_aec ;}; 54 | 55 | // Data implements Content interface. 56 | func (_ag *webURL )Data ()[]byte {return []byte (_ag ._ee )}; 57 | 58 | // ContentType implements Content interface. 59 | func (_eb *StringContent )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; 60 | 61 | // Method gets the zip directory method. 62 | func (_eg *zipDirectory )Method ()string {return "\u0064\u0069\u0072"}; 63 | 64 | // NewHTMLFile creates new Content htmFile for provided input path. 65 | func NewHTMLFile (path string )(Content ,error ){_a ,_dg :=_fg .Open (path );if _dg !=nil {return nil ,_dg ;};_cf :=&htmlFile {_c :_d .Buffer {}};if _ ,_dg =_cf ._c .ReadFrom (_a );_dg !=nil {return nil ,_dg ;};return _cf ,nil ;}; 66 | 67 | // Data implements Content interface. 68 | func (_abd *zipDirectory )Data ()[]byte {return _abd ._cb .Bytes ()}; 69 | 70 | // Data implements Content interface. 71 | func (_fab *StringContent )Data ()[]byte {return []byte (_fab ._faa )}; -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/unidoc/unihtml 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/mitchellh/go-homedir v1.1.0 7 | github.com/spf13/cobra v1.8.0 8 | github.com/spf13/viper v1.16.0 9 | github.com/stretchr/testify v1.10.0 10 | github.com/unidoc/unipdf/v4 v4.0.0 11 | ) 12 | 13 | require ( 14 | github.com/adrg/strutil v0.3.1 // indirect 15 | github.com/adrg/sysfont v0.1.2 // indirect 16 | github.com/adrg/xdg v0.5.3 // indirect 17 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect 18 | github.com/fsnotify/fsnotify v1.7.0 // indirect 19 | github.com/gabriel-vasile/mimetype v1.4.8 // indirect 20 | github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46 // indirect 21 | github.com/hashicorp/hcl v1.0.0 // indirect 22 | github.com/inconshreveable/mousetrap v1.1.0 // indirect 23 | github.com/magiconair/properties v1.8.7 // indirect 24 | github.com/mitchellh/mapstructure v1.5.0 // indirect 25 | github.com/pelletier/go-toml/v2 v2.2.1 // indirect 26 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect 27 | github.com/sirupsen/logrus v1.9.3 // indirect 28 | github.com/spf13/afero v1.11.0 // indirect 29 | github.com/spf13/cast v1.6.0 // indirect 30 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 31 | github.com/spf13/pflag v1.0.5 // indirect 32 | github.com/subosito/gotenv v1.6.0 // indirect 33 | github.com/unidoc/freetype v0.2.3 // indirect 34 | github.com/unidoc/pkcs7 v0.2.0 // indirect 35 | github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a // indirect 36 | github.com/unidoc/unichart v0.4.0 // indirect 37 | github.com/unidoc/unitype v0.5.1 // indirect 38 | golang.org/x/crypto v0.33.0 // indirect 39 | golang.org/x/image v0.24.0 // indirect 40 | golang.org/x/net v0.35.0 // indirect 41 | golang.org/x/sys v0.30.0 // indirect 42 | golang.org/x/text v0.22.0 // indirect 43 | golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect 44 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect 45 | gopkg.in/ini.v1 v1.67.0 // indirect 46 | gopkg.in/yaml.v3 v3.0.1 // indirect 47 | ) 48 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/adrg/strutil v0.2.2/go.mod h1:EF2fjOFlGTepljfI+FzgTG13oXthR7ZAil9/aginnNQ= 2 | github.com/adrg/strutil v0.3.1 h1:OLvSS7CSJO8lBii4YmBt8jiK9QOtB9CzCzwl4Ic/Fz4= 3 | github.com/adrg/strutil v0.3.1/go.mod h1:8h90y18QLrs11IBffcGX3NW/GFBXCMcNg4M7H6MspPA= 4 | github.com/adrg/sysfont v0.1.2 h1:MSU3KREM4RhsQ+7QgH7wPEPTgAgBIz0Hw6Nd4u7QgjE= 5 | github.com/adrg/sysfont v0.1.2/go.mod h1:6d3l7/BSjX9VaeXWJt9fcrftFaD/t7l11xgSywCPZGk= 6 | github.com/adrg/xdg v0.3.0/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ= 7 | github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78= 8 | github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ= 9 | github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 10 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 11 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 12 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= 13 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 14 | github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= 15 | github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= 16 | github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= 17 | github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= 18 | github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= 19 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 20 | github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46 h1:N+R2A3fGIr5GucoRMu2xpqyQWQlfY31orbofBCdjMz8= 21 | github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46/go.mod h1:2Yoiy15Cf7Q3NFwfaJquh7Mk1uGI09ytcD7CUhn8j7s= 22 | github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= 23 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 24 | github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= 25 | github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= 26 | github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 27 | github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= 28 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 29 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 30 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 31 | github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= 32 | github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= 33 | github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= 34 | github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 35 | github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= 36 | github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= 37 | github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg= 38 | github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= 39 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 40 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= 41 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 42 | github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= 43 | github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 44 | github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= 45 | github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 46 | github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= 47 | github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= 48 | github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= 49 | github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= 50 | github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= 51 | github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= 52 | github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= 53 | github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= 54 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 55 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 56 | github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc= 57 | github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= 58 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 59 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 60 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 61 | github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= 62 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 63 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 64 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 65 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 66 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 67 | github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 68 | github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 69 | github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= 70 | github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 71 | github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= 72 | github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= 73 | github.com/unidoc/freetype v0.2.3 h1:uPqW+AY0vXN6K2tvtg8dMAtHTEvvHTN52b72XpZU+3I= 74 | github.com/unidoc/freetype v0.2.3/go.mod h1:mJ/Q7JnqEoWtajJVrV6S1InbRv0K/fJerPB5SQs32KI= 75 | github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= 76 | github.com/unidoc/pkcs7 v0.2.0 h1:0Y0RJR5Zu7OuD+/l7bODXARn6b8Ev2G4A8lI4rzy9kg= 77 | github.com/unidoc/pkcs7 v0.2.0/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= 78 | github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a h1:RLtvUhe4DsUDl66m7MJ8OqBjq8jpWBXPK6/RKtqeTkc= 79 | github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a/go.mod h1:j+qMWZVpZFTvDey3zxUkSgPJZEX33tDgU/QIA0IzCUw= 80 | github.com/unidoc/unichart v0.4.0 h1:uXk9ZjbqzKb8Lt2Qv2oM9D2ftNRXvezPevgxQhsTQys= 81 | github.com/unidoc/unichart v0.4.0/go.mod h1:9QsE8RbS0fE7ndHNroeCEFkRPqqk47Qsoj6QSAtcwN0= 82 | github.com/unidoc/unipdf/v4 v4.0.0 h1:XxrrOMGLJ6HD7VBO6GpZL5wfoRDmLxawV+wkMXTuPeM= 83 | github.com/unidoc/unipdf/v4 v4.0.0/go.mod h1:SbSYFUoutyBR+hLlsHyNiCzzcSVVuG10S5Xu8RIJ6EY= 84 | github.com/unidoc/unitype v0.5.1 h1:UwTX15K6bktwKocWVvLoijIeu4JAVEAIeFqMOjvxqQs= 85 | github.com/unidoc/unitype v0.5.1/go.mod h1:3dxbRL+f1otNqFQIRHho8fxdg3CcUKrqS8w1SXTsqcI= 86 | golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= 87 | golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= 88 | golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= 89 | golang.org/x/image v0.24.0 h1:AN7zRgVsbvmTfNyqIbbOraYL8mSwcKncEj8ofjgzcMQ= 90 | golang.org/x/image v0.24.0/go.mod h1:4b/ITuLfqYq1hqZcjofwctIhi7sZh2WaCjvsBNjjya8= 91 | golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= 92 | golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= 93 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 94 | golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= 95 | golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 96 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 97 | golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= 98 | golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= 99 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 100 | golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da h1:noIWHXmPHxILtqtCOPIhSt0ABwskkZKjD3bXGnZGpNY= 101 | golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= 102 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 103 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 104 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= 105 | gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= 106 | gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 107 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 108 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 109 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 110 | -------------------------------------------------------------------------------- /selector/selector.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package selector ;import _g "errors";const (ByUndefined ByType =iota ;ByID ;ByQueryAll ;ByQuery ;ByNodeID ;ByJSPath ;BySearch ;); 13 | 14 | // ByType is a 'By' selector type enumerator. 15 | type ByType uint ; 16 | 17 | // Validate checks validity of the ByType. 18 | func (_gf ByType )Validate ()error {if _gf >=ByID &&_gf <=BySearch {return nil ;};return _g .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0062\u0079\u0020\u0073\u0065\u006c\u0065\u0063\u0074\u006f\u0072");}; -------------------------------------------------------------------------------- /sizes/sizes.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | // Package sizes defines basic types that determines the size units i.e. lengths. 13 | // 14 | // 15 | package sizes ;import (_f "encoding/json";_c "flag";_e "fmt";_d "strconv";_af "strings";); 16 | 17 | // String implements fmt.Stringer interface. 18 | func (_aed Millimeter )String ()string {_ba :=_af .Builder {};_ba .WriteString (_d .FormatFloat (float64 (_aed ),'f',1,64));_ba .WriteString ("\u006d\u006d");return _ba .String ();}; 19 | 20 | // Set implements flag.Value interface. 21 | func (_afe *Point )Set (s string )error {_ec ,_cb :=_d .ParseFloat (s ,64);if _cb !=nil {return _e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_cb );};*_afe =Point (_ec ); 22 | return nil ;}; 23 | 24 | // Type implements pflag.Value interface. 25 | func (_cf Inch )Type ()string {return "\u0069\u006e\u0063\u0068"};var _bdc =[]PageSize {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; 26 | 27 | // Inch is a unit that 28 | type Inch float64 ; 29 | 30 | // LengthFlag is a pflag wrapper for the Length value. 31 | type LengthFlag struct{Length Length ;};var _cdc =map[string ]PageSize {_bgc [0:9]:0,_bgc [9:11]:1,_bgc [11:13]:2,_bgc [13:15]:3,_bgc [15:17]:4,_bgc [17:19]:5,_bgc [19:21]:6,_bgc [21:23]:7,_bgc [23:25]:8,_bgc [25:27]:9,_bgc [27:29]:10,_bgc [29:32]:11,_bgc [32:34]:12,_bgc [34:36]:13,_bgc [36:38]:14,_bgc [38:40]:15,_bgc [40:42]:16,_bgc [42:44]:17,_bgc [44:46]:18,_bgc [46:48]:19,_bgc [48:50]:20,_bgc [50:52]:21,_bgc [52:55]:22,_bgc [55:61]:23}; 32 | 33 | 34 | // Millimeters gets the float64 millimeter value. 35 | func (_gg Millimeter )Millimeters ()Millimeter {return _gg }; 36 | 37 | // Name implements pflag.Value interface. 38 | func (_gfa Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; 39 | 40 | // Type implements pflag.Value interface. 41 | func (_gfd Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";}; 42 | 43 | // Name implements viper.FlagValue interface. 44 | func (_cd Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; 45 | 46 | // ValueString implements pflag.Value interface. 47 | func (_gfg Inch )ValueString ()string {return _gfg .String ()}; 48 | 49 | // Point is a unit of Length commonly used to measure the height of fonts. 50 | type Point float64 ;const (_fe =float64 (1)/float64 (25.4);_da =25.4;_cc =0.0139;_fd =0.3528;_b =1.0/64;_ad =1.0/_fd ;); 51 | 52 | // Millimeters converts the inches value to the millimeters. 53 | func (_bg Point )Millimeters ()Millimeter {return Millimeter (float64 (_bg )*_fd )};var _ _c .Value =(*Point )(nil );func _dca (_fbc string )(Point ,error ){_fbc =_af .TrimSpace (_af .Trim (_fbc ,"\u0070\u0074"));_bf ,_ade :=_d .ParseFloat (_fbc ,64);if _ade !=nil {return 0,_ade ; 54 | };return Point (_bf ),nil ;};var _cee =[...]uint8 {0,9,11,13,15,17,19,21,23,25,27,29,32,34,36,38,40,42,44,46,48,50,52,55,61}; 55 | 56 | // Points implements Length interface. 57 | func (_dcc Inch )Points ()Point {return Point (float64 (_dcc )*_b )}; 58 | 59 | // HasChanged implements viper.FlagValue interface. 60 | func (_gfb *Point )HasChanged ()bool {return _gfb !=nil }; 61 | 62 | // String implements fmt.Stringer interface. 63 | func (_aaf Orientation )String ()string {if _aaf ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; 64 | 65 | // Set implements pflag.Value interface. 66 | func (_dc *Inch )Set (s string )error {_bd ,_cg :=_d .ParseFloat (s ,64);if _cg !=nil {return _e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_cg );};*_dc =Inch (_bd ); 67 | return nil ;}; 68 | 69 | // Set implements pflag.Value interface. 70 | func (_edc *PageSize )Set (s string )error {_adf ,_dgf :=UnmarshalPageSize (s );if _dgf !=nil {return _dgf ;};*_edc =_adf ;return nil ;};func _cac (_ed string )(Inch ,error ){_ed =_af .TrimSpace (_af .Trim (_ed ,"\u0069\u006e"));_ecg ,_add :=_d .ParseFloat (_ed ,64); 71 | if _add !=nil {return 0,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0076\u0061\u006c\u0075\u0065\u003a\u0020%\u0077",_add );};return Inch (_ecg ),nil ;};const (Portrait =Orientation (false );Landscape =Orientation (true ); 72 | ); 73 | 74 | // ValueType implements viper.FlagValue interface. 75 | func (_efc Point )ValueType ()string {return _efc .Type ()}; 76 | 77 | // Set sets the unit value. 78 | // Implements pflag.Value interface. 79 | func (_ddb *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_ddb .Length =nil ;return nil ;};_ae ,_g :=UnmarshalLength (s );if _g !=nil {return _g ;};_ddb .Length =_ae ;return nil ;}; 80 | 81 | // UnmarshalLength unmarshalls string value into Length. 82 | func UnmarshalLength (length string )(Length ,error ){if _af .HasSuffix (length ,"\u006d\u006d"){return _bgb (length );};if _af .HasSuffix (length ,"\u0069\u006e"){return _cac (length );};if _af .HasSuffix (length ,"\u0070\u0074"){return _dca (length ); 83 | };return nil ,_e .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length );}; 84 | 85 | // Points implements Length interface. 86 | func (_df Point )Points ()Point {return _df }; 87 | 88 | // Type implements pflag.Value interface. 89 | func (_efd PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; 90 | 91 | // Length is it the default dimension unit. 92 | type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; 93 | 94 | // Millimeter is the dimension unit that defines a millimeter. 95 | type Millimeter float64 ; 96 | 97 | // Inches gets the inch value. Implements Length interface. 98 | func (_ea Point )Inches ()Inch {return Inch (float64 (_ea )*_cc )}; 99 | 100 | // MarshalUnit marshals the unit into the string. 101 | func MarshalUnit (unit Length )(string ,error ){switch _fed :=unit .(type ){case Millimeter :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_fed ),nil ;case Inch :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_fed ),nil ;case Point :return _e .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_fed ),nil ; 102 | default:return "",_e .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; 103 | 104 | // MarshalJSON implements json.Marshaler interface 105 | func (_gf Millimeter )MarshalJSON ()([]byte ,error ){return _bga (_gf )};func _bga (_gfc Length )([]byte ,error ){if _gfc ==nil {return nil ,nil ;};_bb ,_cca :=MarshalUnit (_gfc );if _cca !=nil {return nil ,_cca ;};return []byte ("\u0022"+_bb +"\u0022"),nil ; 106 | }; 107 | 108 | // Type implements pflag.Value interface. 109 | func (_ef *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"}; 110 | 111 | // String implements fmt.Stringer interface. 112 | func (_ce Inch )String ()string {_db :=_af .Builder {};_db .WriteString (_d .FormatFloat (float64 (_ce ),'f',1,64));_db .WriteString ("\u0069\u006e");return _db .String ();}; 113 | 114 | // ValueString implements viper.FlagValue interface. 115 | func (_ag Point )ValueString ()string {return _ag .String ()}; 116 | 117 | // Dimensions gets the dimensions of the given page size. 118 | // If provided page size is not valid than the function returns 0 values. 119 | func (_cgb PageSize )Dimensions ()(_ccg ,_bc Millimeter ){switch _cgb {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105; 120 | 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; 121 | case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _ccg ,_bc ;}; 122 | 123 | // Points implements Length interface. 124 | func (_gea Millimeter )Points ()Point {return Point (_gea *_ad )};var _ Length =Inch (0); 125 | 126 | // IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise 127 | func (_fa PageSize )IsAPageSize ()bool {for _ ,_gd :=range _bdc {if _fa ==_gd {return true ;};};return false ;}; 128 | 129 | // PageSizeString retrieves an enum value from the enum constants string name. 130 | // Throws an error if the param is not part of the enum. 131 | func PageSizeString (s string )(PageSize ,error ){if _ecga ,_bgad :=_cdc [s ];_bgad {return _ecga ,nil ;};return 0,_e .Errorf ("\u0025\u0073 \u0064\u006f\u0065\u0073 \u006e\u006ft\u0020\u0062\u0065\u006c\u006f\u006e\u0067\u0020t\u006f\u0020\u0050\u0061\u0067\u0065\u0053\u0069\u007a\u0065\u0020\u0076a\u006c\u0075\u0065\u0073",s ); 132 | }; 133 | 134 | // Inches gets the inch value. Implements Length interface. 135 | func (_fgf Inch )Inches ()Inch {return _fgf }; 136 | 137 | // PageSize is the enum used for defining the page size. 138 | type PageSize int ; 139 | 140 | // HasChanged implements pflag.Value interface. 141 | func (_fg *Inch )HasChanged ()bool {return _fg !=nil };const _bgc ="U\u006e\u0064\u0065\u0066\u0069\u006e\u0065\u0064\u0041\u0030\u0041\u0031\u0041\u0032\u0041\u0033\u0041\u0034\u0041\u0035\u0041\u0036\u0041\u0037\u0041\u0038A\u0039A\u0031\u0030\u0042\u0030B\u0031\u00422\u0042\u0033\u0042\u0034\u0042\u0035\u0042\u0036\u0042\u0037\u0042\u0038\u0042\u0039\u0042\u0031\u0030\u004c\u0065\u0074\u0074\u0065\u0072"; 142 | 143 | 144 | // PageSizeValues returns all values of the enum 145 | func PageSizeValues ()[]PageSize {return _bdc };func _bgb (_dgd string )(Millimeter ,error ){_dgd =_af .TrimSpace (_af .TrimSuffix (_dgd ,"\u006d\u006d"));_fc ,_gfbc :=_d .ParseFloat (_dgd ,64);if _gfbc !=nil {return 0,_e .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069\u006d\u0065t\u0065r\u0020\u0076\u0061\u006c\u0075\u0065\u003a \u0025\u0077",_gfbc ); 146 | };return Millimeter (_fc ),nil ;}; 147 | 148 | // Type implements pflag.Value interface. 149 | func (_aec Point )Type ()string {return "\u0070\u006f\u0069n\u0074"}; 150 | 151 | // Inches gets the inches equivalent from provided millimeter value. 152 | func (_ge Millimeter )Inches ()Inch {return Inch (float64 (_ge )*_fe )}; 153 | 154 | // UnmarshalInch unmarshalls provided string into unit. 155 | func UnmarshalInch (unit string )(Inch ,error ){if _af .HasSuffix (unit ,"\u006d\u006d"){_fb ,_dda :=_bgb (unit );if _dda !=nil {return 0,_dda ;};return _fb .Inches (),nil ;};if _af .HasSuffix (unit ,"\u0069\u006e"){return _cac (unit );};return 0,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit ); 156 | }; 157 | 158 | // MarshalJSON implements json.Marshaler interface 159 | func (_eb Inch )MarshalJSON ()([]byte ,error ){return _bga (_eb )}; 160 | 161 | // MarshalJSON implements json.Marshaler interface. 162 | func (_fge Point )MarshalJSON ()([]byte ,error ){return _bga (_fge )}; 163 | 164 | // UnmarshalPageSize unmarshals the page size from the string. 165 | func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _cea PageSize ;if _dag :=(&_cea ).UnmarshalText ([]byte (pageSize ));_dag !=nil {return 0,_e .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0070a\u0067\u0065\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0077",_dag ); 166 | };return _cea ,nil ;};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;);func (_ebg PageSize )String ()string {if _ebg < 0||_ebg >=PageSize (len (_cee )-1){return _e .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_ebg ); 167 | };return _bgc [_cee [_ebg ]:_cee [_ebg +1]];}; 168 | 169 | // Millimeters converts the inches value to the millimeters. 170 | func (_gc Inch )Millimeters ()Millimeter {return Millimeter (float64 (_gc )*_da )}; 171 | 172 | // MarshalText implements the encoding.TextMarshaler interface for PageSize 173 | func (_cfd PageSize )MarshalText ()([]byte ,error ){return []byte (_cfd .String ()),nil }; 174 | 175 | // UnmarshalJSON implements the json.Unmarshaler interface for PageSize 176 | func (_ede *PageSize )UnmarshalJSON (data []byte )error {var _bbc string ;if _ebe :=_f .Unmarshal (data ,&_bbc );_ebe !=nil {return _e .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data ); 177 | };var _eg error ;*_ede ,_eg =PageSizeString (_bbc );return _eg ;}; 178 | 179 | // Set implements flag.Value interface. 180 | func (_dccc *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_dccc =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_dccc =Landscape ;default:return _e .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s ); 181 | };return nil ;}; 182 | 183 | // MarshalJSON implements the json.Marshaler interface for PageSize 184 | func (_fbf PageSize )MarshalJSON ()([]byte ,error ){return _f .Marshal (_fbf .String ())}; 185 | 186 | // Orientation is the page orientation type wrapper. 187 | type Orientation bool ; 188 | 189 | // UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize 190 | func (_cfe *PageSize )UnmarshalText (text []byte )error {var _ddf error ;*_cfe ,_ddf =PageSizeString (string (text ));return _ddf ;};var _ _c .Value =(*Orientation )(nil ); 191 | 192 | // ValueType implements pflag.Value interface. 193 | func (_ccf Inch )ValueType ()string {return _ccf .Type ()}; 194 | 195 | // String implements fmt.Stringer interface. 196 | func (_dg Point )String ()string {_fdd :=_af .Builder {};_fdd .WriteString (_d .FormatFloat (float64 (_dg ),'f',1,64));_fdd .WriteString ("\u0070\u0074");return _fdd .String ();}; 197 | 198 | // String gets the string value for given flag. 199 | func (_dd *LengthFlag )String ()string {if _dd .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _dd .Length .String ();}; 200 | 201 | // MarshalPageSize marshals the page size into string. 202 | func MarshalPageSize (p PageSize )(string ,error ){_cgbd ,_addf :=p .MarshalText ();if _addf !=nil {return "",_addf ;};return string (_cgbd ),nil ;};var (_ Length =Millimeter (0);); -------------------------------------------------------------------------------- /unihtml.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | // Package unihtml contains a plugin for the UniDoc. 13 | package unihtml ;import (_fc "bytes";_e "context";_bgd "errors";_ba "fmt";_c "github.com/unidoc/unihtml/client";_cf "github.com/unidoc/unihtml/content";_af "github.com/unidoc/unihtml/selector";_ed "github.com/unidoc/unihtml/sizes";_bab "github.com/unidoc/unipdf/v4/common"; 14 | _ac "github.com/unidoc/unipdf/v4/common/license";_ff "github.com/unidoc/unipdf/v4/creator";_ag "github.com/unidoc/unipdf/v4/model";_bf "github.com/unidoc/unipdf/v4/render";_eb "image";_f "image/color";_d "math";_bg "net/url";_b "os";_a "time";);var ErrNoClient =_bgd .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064"); 15 | 16 | 17 | // ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. 18 | func ConnectOptions (o Options )error {_gf =_c .New (_c .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_ee ,_da :=_e .WithTimeout (_e .Background (),_a .Second *5);defer _da ();if _eg :=_gf .HealthCheck (_ee );_eg !=nil {return _eg ; 19 | };return nil ;}; 20 | 21 | // WriteToFile writes the document to a file defined by the output path. 22 | func (_gba *Document )WriteToFile (outputPath string )error {if _dbg :=_gba .validate ();_dbg !=nil {return _dbg ;};_cff :=_a .Second *20+_gba ._aff ;_dgg ,_afa :=_e .WithTimeout (_e .Background (),_cff );defer _afa ();_gad ,_aga :=_gba .extract (_dgg ,_gba ._gg ,_gba ._ab ,_gba .getMargins ()); 23 | if _aga !=nil {return _aga ;};_acd :=_ff .New ();for _ ,_cgf :=range _gad {if _aga =_acd .AddPage (_cgf );_aga !=nil {return _aga ;};};return _acd .WriteToFile (outputPath );};func _gbe (_gfb _eb .Image )float64 {_fef :=_gfb .Bounds ();var (_bfe int ;_dag _f .Color ; 24 | _cge ,_geb ,_eeb uint32 ;);_ada ,_agf :=_fef .Min .X ,_fef .Max .Y -1;_fcd :=_gfb .At (_ada ,_agf );_fg ,_cd ,_cgfe ,_ :=_fcd .RGBA ();_gec :=_fg ==_d .MaxUint16 &&_cd ==_d .MaxUint16 &&_cgfe ==_d .MaxUint16 ;for _agf =_fef .Max .Y -1;_agf >=_fef .Min .Y ; 25 | _agf --{var _egg bool ;for _ada =_fef .Min .X ;_ada < _fef .Max .X ;_ada ++{_dag =_gfb .At (_ada ,_agf );_cge ,_geb ,_eeb ,_ =_dag .RGBA ();if (_gec &&!(_cge ==_fg &&_geb ==_cd &&_cgfe ==_eeb ))||(!_gec &&(_d .Abs (float64 (_cge )-float64 (_fg ))/float64 (_d .MaxUint16 )> 0.03||_d .Abs (float64 (_geb )-float64 (_cd ))/float64 (_d .MaxUint16 )> 0.03||_d .Abs (float64 (_eeb )-float64 (_cgfe ))/float64 (_d .MaxUint16 )> 0.03)){_egg =true ; 26 | break ;};};if _egg {break ;};_bfe =_agf ;};return float64 (_fef .Max .Y -_bfe )/float64 (_fef .Max .Y );}; 27 | 28 | // SetMarkedContentID sets the marked content id for the document. 29 | func (_fce *Document )SetMarkedContentID (id int64 )*_ag .KDict {return nil };var _ _ff .Drawable =(*Document )(nil ); 30 | 31 | // Connect creates UniHTML HTTP Client and tries to establish connection with the server. 32 | func Connect (path string )error {if _ad :=_gb ();_ad !=nil {return _ad ;};_db ,_cg :=_c .ParseOptions (path );if _cg !=nil {return _cg ;};_gf =_c .New (_db );_ga ,_gfd :=_e .WithTimeout (_e .Background (),_a .Second *5);defer _gfd ();if _ebb :=_gf .HealthCheck (_ga ); 33 | _ebb !=nil {return _ebb ;};return nil ;}; 34 | 35 | // NewDocument creates new HTML Document used as an input for the creator.Drawable. 36 | func NewDocument (path string )(*Document ,error ){_ebe :=&Document {};_gae ,_df :=_bg .Parse (path );if _df !=nil {return nil ,_df ;};switch _gae .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_ebe ._cc ,_df =_cf .NewWebURL (path ); 37 | if _df !=nil {return nil ,_df ;};return _ebe ,nil ;};_dbe ,_df :=_b .Stat (path );if _df !=nil {return nil ,_df ;};if !_dbe .IsDir (){_ebe ._cc ,_df =_cf .NewHTMLFile (path );}else {_ebe ._cc ,_df =_cf .NewZipDirectory (path );};if _df !=nil {return nil ,_df ; 38 | };return _ebe ,nil ;}; 39 | 40 | // Options are the HTML Client options used for establishing the connection. 41 | type Options struct{ 42 | 43 | // Hostname defines the hostname for the client. Default value: 'localhost'. 44 | Hostname string ; 45 | 46 | // Port defines the port at which the server works. Default value: '8080' 47 | Port int ; 48 | 49 | // Secure is the flag that states if the connection uses HTTPS protocol. Default Value: 'false'. 50 | Secure bool ; 51 | 52 | // Prefix is an option setting used when the server is working with the URI prefix. Default Value: ''. 53 | Prefix string ;};var _gf *_c .Client ; 54 | 55 | // WaitReady waits for the provided selector to be ready. 56 | // A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. 57 | func (_deag *Document )WaitReady (sel string ,by ..._af .ByType ){_bdc :=_af .BySearch ;if len (by )> 0{_bdc =by [0];};_deag ._ae =append (_deag ._ae ,_c .BySelector {Selector :sel ,By :_bdc });}; 58 | 59 | // SetMarginTop sets the left margin. 60 | func (_gee *Document )SetMarginTop (margin _ed .Length ){_gee ._gcg .Top =margin }; 61 | 62 | // GetPdfPages is a function that converts provided input content and 63 | func (_fe *Document )GetPdfPages (ctx _e .Context )([]*_ag .PdfPage ,error ){if _aee :=_fe .validate ();_aee !=nil {return nil ,_aee ;};return _fe .extract (ctx ,_fe ._gg ,_fe ._ab ,_fe .getMargins ());};type margins struct{Left ,Right ,Bottom ,Top _ed .Length ; 64 | }; 65 | 66 | // TrimLastPageContent trims the last page content so that next creator blocks are located just at the end of given block. 67 | func (_bb *Document )TrimLastPageContent (){_bb ._dd =true };func (_dbea *Document )validate ()error {if _gf ==nil {return ErrNoClient ;};if _dbea ._cc ==nil {return ErrContentNotDefined ;};return nil ;}; 68 | 69 | // GetContent returns the content of the document. 70 | func (_ggc *Document )GetContent ()_cf .Content {return _ggc ._cc }; 71 | 72 | // SetPageSize sets the page default size. 73 | func (_fdd *Document )SetPageSize (pageSize _ed .PageSize )error {if !pageSize .IsAPageSize (){return _bgd .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065"); 74 | };_fdd ._ccf =pageSize ;_fdd ._de =_ff .PositionAbsolute ;return nil ;}; 75 | 76 | // SetPos sets the absolute position. Changes object positioning to absolute. 77 | func (_ec *Document )SetPos (x ,y float64 ){_ec ._de =_ff .PositionAbsolute ;_ec ._def =x ;_ec ._fd =y }; 78 | 79 | // SetTimeoutDuration sets the timeout duration 80 | // the default timeout is 15 seconds. 81 | func (_dfd *Document )SetTimeoutDuration (duration _a .Duration ){_dfd ._agd =&duration };func (_ffc *Document )getTimeoutDuration ()_a .Duration {if _ffc ._agd !=nil {return *_ffc ._agd ;};return 0;}; 82 | 83 | // ContainerComponent implements creator.containerElement interface. 84 | func (_gd *Document )ContainerComponent (container _ff .Drawable )(_ff .Drawable ,error ){switch container .(type ){case *_ff .Chapter :default:return nil ,_ba .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container ); 85 | };return _gd ,nil ;}; 86 | 87 | // GeneratePageBlocks implements creator.Drawable interface. 88 | func (_aa *Document )GeneratePageBlocks (ctx _ff .DrawContext )([]*_ff .Block ,_ff .DrawContext ,error ){if _ccd :=_aa .validate ();_ccd !=nil {return nil ,ctx ,_ccd ;};var _aec []*_ff .Block ;_ge :=_aa .getMargins ();_fda ,_ccc :=_aa ._gg ,_aa ._ab ;if _aa ._de .IsRelative (){_fda ,_ccc =_ed .Point (ctx .Width ),_ed .Point (ctx .Height ); 89 | ctx .X -=float64 (_ge .Left .Points ());}else {ctx .X =_aa ._def ;ctx .Y =_aa ._fd ;};_cfa ,_gbb :=_aa .extract (_e .Background (),_fda ,_ccc ,_ge );if _gbb !=nil {return nil ,_ff .DrawContext {},_gbb ;};for _gff ,_fa :=range _cfa {_ccb ,_dg :=_ff .NewBlockFromPage (_fa ); 90 | if _dg !=nil {return nil ,_ff .DrawContext {},_dg ;};var _ebf float64 ;if _aa ._dd &&_gff ==len (_cfa )-1{_aeb :=_bf .NewImageDevice ();_ea ,_ccdg :=_aeb .Render (_fa );if _ccdg !=nil {return nil ,_ff .DrawContext {},_ccdg ;};_ca ,_ccdg :=_fa .GetMediaBox (); 91 | if _ccdg !=nil {return nil ,_ff .DrawContext {},_ccdg ;};_dde :=_a .Now ();_bba :=_gbe (_ea );_ebf =_ca .Height ()*_bba ;_bab .Log .Trace ("\u0054\u0072i\u006d\u006d\u0069\u006eg\u0020\u006ca\u0073\u0074\u0020\u0064\u006f\u0063\u0075\u006de\u006e\u0074\u0020\u0070\u0061\u0067\u0065\u0020\u0074\u0061\u006b\u0065n\u003a\u0020\u0025\u0076",_a .Since (_dde )); 92 | if _aa ._gcg .Bottom !=nil {_ebf -=float64 (_aa ._gcg .Bottom .Points ());};if _ebf < 0{_ebf =0;};_bab .Log .Trace ("C\u0072\u006f\u0070\u0070\u0069\u006e\u0067\u0020\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074\u0027\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0025\u002e2\u0066 \u0070\u006f\u0069\u006et\u0073\u0020o\u0066\u0066\u0020\u0062\u006f\u0074\u0074\u006f\u006d\u0020\u006f\u0066\u0020\u006d\u0065\u0064\u0069\u0061\u0020\u0062\u006f\u0078\u000a",_ebf ); 93 | };_ega ,_gffa ,_dg :=_ccb .GeneratePageBlocks (ctx );if _dg !=nil {return nil ,_ff .DrawContext {},_dg ;};ctx =_gffa ;ctx .Y -=_ebf ;if _gff !=len (_cfa )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ; 94 | ctx .Page ++;};_aec =append (_aec ,_ega ...);};return _aec ,ctx ,nil ;}; 95 | 96 | // SetPageWidth sets the page width for given document. 97 | func (_abf *Document )SetPageWidth (pageWidth _ed .Length )error {_abf ._gg =pageWidth ;_abf ._de =_ff .PositionAbsolute ;return nil ;}; 98 | 99 | // SetMarginBottom sets the left margin. 100 | func (_ggg *Document )SetMarginBottom (margin _ed .Length ){_ggg ._gcg .Bottom =margin }; 101 | 102 | // Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. 103 | type Document struct{_cc _cf .Content ;_gcg margins ;_de _ff .Positioning ;_def ,_fd float64 ;_ccf _ed .PageSize ;_gg ,_ab _ed .Length ;_cfe _ed .Orientation ;_dd bool ;_aff _a .Duration ;_ae []_c .BySelector ;_ce []_c .BySelector ;_agd *_a .Duration ; 104 | }; 105 | 106 | // NewDocumentFromString creates a new Document from the provided HTML string. 107 | func NewDocumentFromString (html string )(*Document ,error ){_bfd ,_bff :=_cf .NewStringContent (html );if _bff !=nil {return nil ,_bff ;};_aea :=&Document {};_aea ._cc =_bfd ;return _aea ,nil ;}; 108 | 109 | // WaitTime sets the waiting time before the webpage is rendered to PDF. 110 | func (_bc *Document )WaitTime (duration _a .Duration ){_bc ._aff =duration }; 111 | 112 | // SetMarginRight sets the left margin. 113 | func (_gbaa *Document )SetMarginRight (margin _ed .Length ){_gbaa ._gcg .Right =margin };func (_geg *Document )extract (_ege _e .Context ,_gbbg ,_dba _ed .Length ,_dc margins )([]*_ag .PdfPage ,error ){_ebd :=_c .BuildHTMLQuery ().SetContent (_geg ._cc ).PageSize (_geg ._ccf ).PaperWidth (_gbbg ).PaperHeight (_dba ).Orientation (_geg ._cfe ).MarginLeft (_dc .Left ).MarginRight (_dc .Right ).MarginTop (_dc .Top ).MarginBottom (_dc .Bottom ).TimeoutDuration (_geg .getTimeoutDuration ()).WaitTime (_geg ._aff ); 114 | for _ ,_cffc :=range _geg ._ae {_ebd .WaitReady (_cffc .Selector ,_cffc .By );};for _ ,_bda :=range _geg ._ce {_ebd .WaitVisible (_bda .Selector ,_bda .By );};_cb ,_gfe :=_ebd .Query ();if _gfe !=nil {return nil ,_gfe ;};var _caf _e .CancelFunc ;if _geg ._agd !=nil {_ege ,_caf =_e .WithTimeout (_ege ,*_geg ._agd ); 115 | }else {_ege ,_caf =_e .WithTimeout (_ege ,_a .Second *15);};defer _caf ();_ggf ,_gfe :=_gf .ConvertHTML (_ege ,_cb );if _gfe !=nil {return nil ,_gfe ;};_ccbc :=_fc .NewReader (_ggf .Data );_bad ,_gfe :=_ag .NewPdfReader (_ccbc );if _gfe !=nil {return nil ,_gfe ; 116 | };return _bad .PageList ,nil ;}; 117 | 118 | // SetLandscapeOrientation sets document landscape page orientation. 119 | func (_be *Document )SetLandscapeOrientation (){_be ._cfe =_ed .Landscape }; 120 | 121 | // WaitVisible waits for the provided selector to be ready. 122 | // A selector might be i.e. `#example` for id and `.example` for classes. The second parameter defines how to match given selector. 123 | func (_fdg *Document )WaitVisible (sel string ,by ..._af .ByType ){_eag :=_af .BySearch ;if len (by )> 0{_eag =by [0];};_fdg ._ce =append (_fdg ._ce ,_c .BySelector {Selector :sel ,By :_eag });};var ErrContentNotDefined =_bgd .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); 124 | func _gb ()error {_ef :=_ac .GetLicenseKey ();if _ef ==nil {return _bgd .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};if !_ef .IsLicensed (){return _bgd .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064"); 125 | };return nil ;}; 126 | 127 | // SetMarginLeft sets the left margin. 128 | func (_fga *Document )SetMarginLeft (margin _ed .Length ){_fga ._gcg .Left =margin };func (_gadg *Document )getMargins ()margins {_cda :=_gadg ._gcg ;if _gadg ._de .IsRelative (){_cda .Top =_ed .Millimeter (1);_cda .Left =_ed .Millimeter (1);_cda .Bottom =_ed .Millimeter (1); 129 | _cda .Right =_ed .Millimeter (1);return _cda ;};if _cda .Top ==nil {_cda .Top =_ed .Millimeter (10);};if _cda .Bottom ==nil {_cda .Bottom =_ed .Millimeter (10);};if _cda .Left ==nil {_cda .Left =_ed .Millimeter (10);};if _cda .Right ==nil {_cda .Right =_ed .Millimeter (10); 130 | };return _cda ;}; 131 | 132 | // SetMargins sets the Document Margins. 133 | func (_age *Document )SetMargins (left ,right ,top ,bottom float64 ){_age ._gcg .Left =_ed .Point (left );_age ._gcg .Right =_ed .Point (right );_age ._gcg .Top =_ed .Point (top );_age ._gcg .Bottom =_ed .Point (bottom );_age ._de =_ff .PositionAbsolute ; 134 | }; 135 | 136 | // SetPageHeight sets the page height for given document. 137 | func (_bd *Document )SetPageHeight (pageHeight _ed .Length )error {_bd ._ab =pageHeight ;_bd ._de =_ff .PositionAbsolute ;return nil ;}; --------------------------------------------------------------------------------