From 998f569de226f2172bdf8c1d60c5a1a13dd772de Mon Sep 17 00:00:00 2001 From: UniDoc Build Date: Mon, 8 Feb 2021 19:36:06 +0000 Subject: [PATCH] prepare release --- .github/ISSUE_TEMPLATE/bug_report.md | 24 +++ .github/ISSUE_TEMPLATE/feature_request.md | 20 +++ .github/workflows/greetings.yml | 22 +++ ACKNOWLEDGEMENTS.md | 37 +++++ LICENSE.md | 10 ++ README.md | 122 ++++++++++++++- cli/cmd/cmd.go | 40 +++++ cli/main.go | 12 ++ client/client.go | 145 ++++++++++++++++++ common/common.go | 16 ++ content/content.go | 43 ++++++ go.mod | 12 ++ sizes/sizes.go | 174 ++++++++++++++++++++++ unihtml.go | 79 ++++++++++ 14 files changed, 754 insertions(+), 2 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/workflows/greetings.yml create mode 100644 ACKNOWLEDGEMENTS.md create mode 100644 LICENSE.md create mode 100644 cli/cmd/cmd.go create mode 100644 cli/main.go create mode 100644 client/client.go create mode 100644 common/common.go create mode 100644 content/content.go create mode 100644 go.mod create mode 100644 sizes/sizes.go create mode 100644 unihtml.go diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..ee0d623 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,24 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "[BUG]" +labels: '' +assignees: '' + +--- + +## Description +A clear and concise description of what the bug is. + +## Expected Behavior +A clear and concise description of what you expected to happen. + +## Actual Behavior +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +## Attachments +Include a self-contained reproducible code snippet and PDF file that demonstrates the issue. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..6dd8285 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: "[FEATURE]" +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml new file mode 100644 index 0000000..0bb4907 --- /dev/null +++ b/.github/workflows/greetings.yml @@ -0,0 +1,22 @@ +name: Greetings + +on: [issues] + +jobs: + greeting: + runs-on: ubuntu-latest + steps: + - uses: actions/first-interaction@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + issue-message: > + Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, + other issues go into our backlog where they are assessed and fitted into the roadmap when suitable. + If you need to get this done, consider buying a license which also enables you to use it in your commercial products. + More information can be found on https://unidoc.io/ + pr-message: > + Thanks for posting your first PR. Please be sure to sign the CLA and make sure that the + the Developer Guidelines https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide were followed. + You can expect that we will review the PR and post comments. The timeframe fpr this can vary depending + on various factors, including which issue(s) the PR addresses and where it fits in the roadmap. + Note also that customer PRs are prioritized. diff --git a/ACKNOWLEDGEMENTS.md b/ACKNOWLEDGEMENTS.md new file mode 100644 index 0000000..c124fc8 --- /dev/null +++ b/ACKNOWLEDGEMENTS.md @@ -0,0 +1,37 @@ +Acknowledgements +---------------- + +UniHTML contains code from or depends on the following open source projects: + +* [The standard Go library](https://golang.org/pkg/#stdlib). + +``` +Copyright (c) 2009 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +``` + diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..3540346 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,10 @@ +## Licensing Information + +This software package is a commercial product and requires a license +code to operate. + +The use of this software package is governed by the end-user license agreement +(EULA) available at: https://unidoc.io/eula/ + +To obtain a Trial license code to evaluate the software, please visit +https://unidoc.io/ diff --git a/README.md b/README.md index ea73abb..e01c2b1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,120 @@ -# unihtml -UniHTML client for UniHTML +# UniHTML + +[UniDoc](https://unidoc.io) UniHTML is a [UniPDF](https://github.com/unidoc/unipdf) library plugin module with capability +of extracting and converting HTML files and inject into PDF document. + +It requires a UniHTML Server component to work. Visit [https://unidoc.io](https://unidoc.io). + +[![License: UniDoc EULA](https://img.shields.io/badge/license-UniDoc%20EULA-blue)](https://unidoc.io/eula/) +[![GoDoc](https://godoc.org/github.com/unidoc/unipdf?status.svg)](https://godoc.org/github.com/unidoc/unihtml) + +## Features + +- Create a PDF file from simple HTML file. +- Create PDF file based on the directory that contains HTML along with CSS, JavaScript and Images. +- Create PDF file based on the external web link. +- Define output page dimensions in metric or imperial systems. +- 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`. +- Define output page orientation. +- Define custom margin sizes for the output document. +- Injection of HTML defined document into existing PDF document. +- CLI that allows to execute HTML -> PDF conversion. + + +## Preparation + +UniHTML is a plugin for the [UniPDF](https://github.com/unidoc/unipdf) Golang library. + +It requires valid UniPDF license with the UniHTML plugin. Visit [https://unidoc.io](https://unidoc.io) to get more information. + +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 + + +## Installation + +1. Get UniHTML-Server Docker image: + `docker pull unidoccloud/unihtml:latest` +2. Start UniHTML server with some output port defined: `docker run -p 8080:8080 -e UNIHTML_LICENSE=path/to/license unidoccloud/unihtml` +3. Define environment variable: `UNIPDF_LICENSE_PATH` with the path to the UniDoc license. +4. Define environment variable: `UNIPDF_CUSTOMER_NAME` with your customer name matching your license. +5. Get latest version of the `github.com/unidoc/unipdf/v3` module: `go get github.com/unidoc/unipdf/v3` + +## Usage + +Following example connects to the UniHTML server, reads the content of the input file and converts it using `github.com/unidoc/unipdf/v3/creator` package. + +```go +package main + +import ( + "fmt" + "os" + + "github.com/unidoc/unihtml" + "github.com/unidoc/unipdf/v3/creator" +) + +func main() { + // UniHTML requires two arguments: + // - Connection path to the unihtml-server i.e.: https://localhost:8080 + // - Input path for the file / directory to convert + if len(os.Args) != 3 { + fmt.Println("Err: provided invalid arguments. No UniHTML server path provided") + os.Exit(1) + } + + // Establish connection with the UniHTML Server. + if err := unihtml.Connect(os.Args[1]); err != nil { + fmt.Printf("Err: Connect failed: %v\n", err) + os.Exit(1) + } + + // Get new PDF Creator. + c := creator.New() + + // Read the content of the simple.html file and load it to the conversion. + doc, err := unihtml.NewDocument(os.Args[2]) + if err != nil { + fmt.Printf("Err: NewDocument failed: %v\n", err) + os.Exit(1) + } + + // Draw the html document file in the context of the creator. + if err = c.Draw(doc); err != nil { + fmt.Printf("Err: Draw failed: %v\n", err) + os.Exit(1) + } + + // Write the result file to PDF. + if err = c.WriteToFile("document.pdf"); err != nil { + fmt.Printf("Err: %v\n", err) + os.Exit(1) + } +} +``` + + +## Contributing + +[![CLA assistant](https://cla-assistant.io/readme/badge/unidoc/unipdf)](https://cla-assistant.io/unidoc/unipdf) + +All contributors must sign a contributor license agreement before their code will be reviewed and merged. + +## Support and consulting + +Please email us at support@unidoc.io for any queries. + +If you have any specific tasks that need to be done, we offer consulting in certain cases. +Please contact us with a brief summary of what you need and we will get back to you with a quote, if appropriate. + +## Licensing Information + +This software package (unihtml) is a commercial product and requires a license +code to operate. + +The use of this software package is governed by the end-user license agreement +(EULA) available at: https://unidoc.io/eula/ + +To obtain a Trial license code to evaluate the software, please visit +https://unidoc.io/ + diff --git a/cli/cmd/cmd.go b/cli/cmd/cmd.go new file mode 100644 index 0000000..7a3605f --- /dev/null +++ b/cli/cmd/cmd.go @@ -0,0 +1,40 @@ +// +// Copyright 2020 FoxyUtils ehf. All rights reserved. +// +// This is a commercial product and requires a license to operate. +// A trial license can be obtained at https://unidoc.io +// +// DO NOT EDIT: generated by unitwist Go source code obfuscator. +// +// Use of this source code is governed by the UniDoc End User License Agreement +// terms that can be accessed at https://unidoc.io/eula/ + +package cmd ;import (_da "context";_dd "fmt";_cb "github.com/mitchellh/go-homedir";_a "github.com/spf13/cobra";_cee "github.com/spf13/viper";_dadd "github.com/unidoc/unihtml/client";_bc "github.com/unidoc/unihtml/content";_cf "github.com/unidoc/unihtml/sizes";_ce "github.com/unidoc/unipdf/v3/common";_c "os";_dad "path/filepath";_b "time";);func _gg (){if _dcb !=""{_cee .SetConfigFile (_dcb );}else {_beb ,_gb :=_cb .Dir ();if _gb !=nil {_dd .Println (_gb );_c .Exit (1);};_cee .AddConfigPath (_beb );_cee .SetConfigName ("\u002e\u0075\u006ei\u0068\u0074\u006d\u006c\u002d\u0073\u0072\u0063");};_cee .AutomaticEnv ();if _gbb :=_cee .ReadInConfig ();_gbb ==nil {_dd .Println ("\u0055s\u0069n\u0067\u0020\u0063\u006f\u006ef\u0069\u0067 \u0066\u0069\u006c\u0065\u003a",_cee .ConfigFileUsed ());};};var _bf =&_a .Command {Use :"\u0075n\u0069\u0068\u0074\u006d\u006c",Short :"\u0041\u0020\u0062\u0072\u0069\u0065\u0066\u0020\u0064\u0065\u0073\u0063\u0072i\u0070\u0074\u0069\u006f\u006e\u0020o\u0066\u0020\u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063a\u0074\u0069\u006f\u006e",Long :"\u0041\u0020\u006c\u006f\u006e\u0067\u0065\u0072\u0020\u0064\u0065\u0073c\u0072\u0069\u0070\u0074i\u006f\u006e\u0020\u0074\u0068\u0061\u0074\u0020s\u0070\u0061n\u0073\u0020\u006d\u0075\u006ct\u0069\u0070\u006c\u0065\u0020\u006c\u0069\u006e\u0065\u0073\u0020\u0061nd\u0020\u006c\u0069\u006b\u0065\u006cy\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0073\u000a\u0065\u0078\u0061\u006d\u0070\u006c\u0065\u0073\u0020\u0061n\u0064\u0020\u0075s\u0061\u0067\u0065\u0020\u006ff\u0020\u0075\u0073\u0069\u006eg \u0079\u006f\u0075\u0072\u0020\u0061\u0070\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006fn\u002e\u0020\u0046\u006f\u0072\u0020e\u0078\u0061\u006dp\u006c\u0065\u003a\u000a\u000a\u0043\u006f\u0062\u0072\u0061\u0020\u0069s\u0020\u0061\u0020\u0043L\u0049\u0020\u006c\u0069\u0062\u0072\u0061\u0072\u0079\u0020f\u006f\u0072\u0020\u0047\u006f\u0020t\u0068\u0061t\u0020\u0065\u006dp\u006f\u0077\u0065\u0072\u0073\u0020\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u0073\u002e\u000a\u0054\u0068\u0069\u0073\u0020\u0061\u0070p\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e \u0069\u0073 \u0061\u0020\u0074\u006f\u006f\u006c\u0020\u0074o\u0020g\u0065\u006e\u0065\u0072a\u0074\u0065 \u0074\u0068e\u0020\u006e\u0065\u0065\u0064\u0065\u0064\u0020\u0066\u0069\u006ce\u0073\u000a\u0074\u006f\u0020\u0071\u0075\u0069\u0063\u006b\u006cy\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020\u0061\u0020\u0043\u006f\u0062\u0072\u0061\u0020\u0061\u0070pl\u0069ca\u0074\u0069on\u002e"};var _dcb string ;type parametersConfig struct{ + +// PaperWidth sets the width of the paper. +PaperWidth _cf .LengthFlag `mapstructure:"paper-width"`; + +// PaperHeight is the height of the output paper. +PaperHeight _cf .LengthFlag `mapstructure:"paper-height"`; + +// PageSize is the page size string. +PageSize _cf .PageSize `mapstructure:"page-size"`; + +// Orientation defines if the output should be in a landscape format. +Orientation _cf .Orientation `mapstructure:"orientation"`; + +// MarginTop sets up the Top Margin for the output. +MarginTop _cf .LengthFlag `mapstructure:"margin-top"`; + +// MarginBottom sets up the Bottom Margin for the output. +MarginBottom _cf .LengthFlag `mapstructure:"margin-bottom"`; + +// MarginLeft sets up the Left Margin for the output. +MarginLeft _cf .LengthFlag `mapstructure:"margin-left"`; + +// MarginRight sets up the Right Margin for the output. +MarginRight _cf .LengthFlag `mapstructure:"margin-right"`;};func init (){_bf .AddCommand (_be );_be .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");_be .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");_be .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");_be .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");_be .Flags ().Var (&_f .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");_be .Flags ().Var (&_f .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");_be .Flags ().Var (&_f .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");_be .Flags ().Var (&_f .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");_be .Flags ().Var (&_f .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");_be .Flags ().Var (&_f .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");_be .Flags ().Var (&_f .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");_be .Flags ().Var (&_f .MarginLeft ,"m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074","\u0073\u0065\u0074\u0073 u\u0070\u0020\u0074\u0068\u0065\u0020\u0070\u0061\u0070\u0065\u0072\u002d\u006c\u0065f\u0074");};var (_dae =generateConfig {};_f =parametersConfig {PaperWidth :_cf .LengthFlag {Length :_cf .Inch (8.5).Millimeters ()},PaperHeight :_cf .LengthFlag {Length :_cf .Inch (11).Millimeters ()},Orientation :_cf .Portrait ,MarginTop :_cf .LengthFlag {Length :_cf .Millimeter (10)},MarginBottom :_cf .LengthFlag {Length :_cf .Millimeter (10)},MarginLeft :_cf .LengthFlag {Length :_cf .Millimeter (10)},MarginRight :_cf .LengthFlag {Length :_cf .Millimeter (10)}};);var _be =&_a .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 :_ced ,Args :_a .ExactArgs (2),ArgAliases :[]string {"\u0069\u006e\u0070u\u0074","\u006f\u0075\u0074\u0070\u0075\u0074\u002d\u0070\u0064\u0066"},Example :"\u0067\u0065\u006e\u0065\u0072\u0061\u0074\u0065\u0020\u0069\u006ep\u0075\u0074\u002e\u0068\u0074\u006d\u006c\u0020o\u0075t\u0070\u0075\u0074\u002e\u0070\u0064\u0066\u0020\u002d\u002d\u006f\u0072\u0069\u0065\u006e\u0074\u0061\u0074i\u006f\u006e\u0020\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074"}; + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute (){if _fd :=_bf .Execute ();_fd !=nil {_dd .Println (_fd );_c .Exit (1);};};func _de (){_cg :=_ce .LogLevelInfo ;if _ef {_cg =_ce .LogLevelDebug ;};if _ac {_cg =_ce .LogLevelTrace ;};_ce .Log =_ce .NewConsoleLogger (_cg );};type generateConfig struct{Port int `mapstructure:"port"`;Host string `mapstructure:"host"`;Https bool `mapstructure:"https"`;Prefix string `mapstructure:"prefix"`;};func init (){_a .OnInitialize (_gg );_bf .PersistentFlags ().BoolVarP (&_ef ,"\u0064\u0065\u0062u\u0067","\u0064",false ,"\u0044e\u0066i\u006e\u0065\u0073\u0020\u0064e\u0062\u0075g\u0020\u006d\u006f\u0064\u0065");_bf .PersistentFlags ().BoolVarP (&_ac ,"\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");_bf .PersistentFlags ().StringVar (&_dcb ,"\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");_bf .Flags ().BoolP ("\u0074\u006f\u0067\u0067\u006c\u0065","\u0074",false ,"\u0048\u0065\u006cp \u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0066\u006f\u0072\u0020\u0074\u006f\u0067\u0067\u006c\u0065");};func _ced (cmd *_a .Command ,_dc []string ){_g :=_b .Now ();if _ad :=_cee .BindPFlags (cmd .Flags ());_ad !=nil {_dd .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ad );_c .Exit (1);};if _daf :=_cee .Unmarshal (&_dae );_daf !=nil {_dd .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_daf );_c .Exit (1);};_de ();_aa :=_b .Now ();_gf ,_ga :=_c .Stat (_dc [0]);if _ga !=nil {_dd .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ga );_c .Exit (1);};if !_gf .IsDir (){if _dad .Ext (_gf .Name ())!="\u002e\u0068\u0074m\u006c"{_dd .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",_dc [0]);_c .Exit (1);};};_df ,_ga :=_c .OpenFile (_dc [1],_c .O_CREATE |_c .O_WRONLY |_c .O_TRUNC ,0700);if _ga !=nil {_dd .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ga );_c .Exit (1);};defer _df .Close ();_gfa :=_dadd .New (_dadd .Options {HTTPS :_dae .Https ,Hostname :_dae .Host ,Port :_dae .Port ,Prefix :_dae .Prefix });_adf ,_gab :=_da .WithTimeout (_da .Background (),_b .Second *10);defer _gab ();_aa =_b .Now ();var _ba _bc .Content ;if _gf .IsDir (){_ba ,_ga =_bc .NewZipDirectory (_dc [0]);}else {_ba ,_ga =_bc .NewHTMLFile (_dc [0]);};if _ga !=nil {_dd .Printf ("\u0045r\u0072\u003a\u0020\u0025\u0076",_ga );_c .Exit (1);};_bcc ,_ga :=_dadd .BuildHTMLQuery ().PaperWidth (_f .PaperWidth .Length ).PaperHeight (_f .PaperHeight .Length ).PageSize (_f .PageSize ).MarginTop (_f .MarginTop .Length ).MarginBottom (_f .MarginBottom .Length ).MarginLeft (_f .MarginLeft .Length ).MarginRight (_f .MarginRight .Length ).Orientation (_f .Orientation ).SetContent (_ba ).Query ();if _ga !=nil {_dd .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ga );_c .Exit (1);};_ee ,_ga :=_gfa .ConvertHTML (_adf ,_bcc );if _ga !=nil {_dd .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ga );_c .Exit (1);};_ce .Log .Trace ("\u0045\u0078\u0065cu\u0074\u0069\u006e\u0067\u0020\u0067\u0065\u006e\u0065r\u0061t\u0065 \u0071u\u0065\u0072\u0079\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020\u0025\u0073",_b .Since (_aa ));_aa =_b .Now ();_ ,_ga =_df .Write (_ee .Data );if _ga !=nil {_dd .Printf ("\u0045\u0072\u0072\u003a\u0020\u0025\u0076\u000a",_ga );_c .Exit (1);};_ce .Log .Trace ("\u0057\u0072\u0069\u0074in\u0067\u0020\u0066\u0069\u006c\u0065\u0020\u0074\u0061\u006b\u0065\u006e\u003a\u0020%\u0073",_b .Since (_aa ));_dd .Printf ("\u0047\u0065n\u0065\u0072\u0061\u0074\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0075\u0063\u0063\u0065\u0073\u0073\u0020\u0069\u006e %\u0073\u000a",_b .Since (_g ));};var (_ef ,_ac bool ;); \ No newline at end of file diff --git a/cli/main.go b/cli/main.go new file mode 100644 index 0000000..48b52ba --- /dev/null +++ b/cli/main.go @@ -0,0 +1,12 @@ +// +// Copyright 2020 FoxyUtils ehf. All rights reserved. +// +// This is a commercial product and requires a license to operate. +// A trial license can be obtained at https://unidoc.io +// +// DO NOT EDIT: generated by unitwist Go source code obfuscator. +// +// Use of this source code is governed by the UniDoc End User License Agreement +// terms that can be accessed at https://unidoc.io/eula/ + +package main ;import _a "github.com/unidoc/unihtml/cli/cmd";func main (){_a .Execute ()}; \ No newline at end of file diff --git a/client/client.go b/client/client.go new file mode 100644 index 0000000..0b37a96 --- /dev/null +++ b/client/client.go @@ -0,0 +1,145 @@ +// +// Copyright 2020 FoxyUtils ehf. All rights reserved. +// +// This is a commercial product and requires a license to operate. +// A trial license can be obtained at https://unidoc.io +// +// DO NOT EDIT: generated by unitwist Go source code obfuscator. +// +// Use of this source code is governed by the UniDoc End User License Agreement +// terms that can be accessed at https://unidoc.io/eula/ + +// Package client contains HTML Converter HTTP Client. The Client implements htmlcreator.HTMLConverter interface +// for the UniPDF module and can be used as a plugin for the UniPDF creator.Creator. +package client ;import (_ec "bytes";_e "context";_g "errors";_ge "fmt";_gfc "github.com/unidoc/unihtml/content";_ecf "github.com/unidoc/unihtml/sizes";_ag "github.com/unidoc/unipdf/v3/common";_f "golang.org/x/xerrors";_a "io/ioutil";_df "net";_gf "net/http";_b "net/url";_dc "strconv";_ee "strings";_gc "time";); + +// ConvertHTML converts provided Query input into PDF file data. +// Implements creator.HTMLConverter interface. +func (_ca *Client )ConvertHTML (ctx _e .Context ,q *Query )(*PDFResponse ,error ){if _ae :=q .Validate ();_ae !=nil {return nil ,_ae ;};_ab ,_cc :=_ca .getRequest (ctx ,q );if _cc !=nil {return nil ,_cc ;};_ag .Log .Trace ("\u0052\u0065\u0071\u0075\u0065\u0073\u0074 \u002d\u0020\u0025s\u0020\u002d\u0020\u0025s\u0025\u0073\u002c\u0020\u0048\u0065\u0061\u0064\u0065\u0072\u0073\u003a\u0020\u0025\u0076\u002c\u0020\u0051\u0075\u0065\u0072\u0079\u003a\u0020\u0025\u0076",_ab .Method ,_ab .URL .Hostname (),_ab .URL .Path ,_ab .Header ,_ab .URL .Query ());_dd ,_cc :=_ca .Client .Do (_ab );if _cc !=nil {return nil ,_cc ;};var _fa error ;switch _dd .StatusCode {case _gf .StatusNotFound :_fa =ErrNotFound ;case _gf .StatusBadRequest :_fa =ErrBadRequest ;case _gf .StatusNotImplemented :_fa =ErrNotImplemented ;case _gf .StatusCreated :default:_fa =ErrInternalError ;};_bcc ,_cc :=_a .ReadAll (_dd .Body );if _cc !=nil &&_fa ==nil {return nil ,_cc ;};_ag .Log .Trace ("\u005b\u0025\u0064]\u0020\u0025\u0073\u0020\u0025\u0073\u0025\u0073",_dd .StatusCode ,_ab .Method ,_ab .URL .Host ,_ab .URL .Path );if _fa !=nil {return nil ,_ge .Errorf ("\u0025\u0073\u0020%\u0077",string (_bcc ),_fa );};_fab :=_dd .Header .Get ("\u0058\u002d\u004a\u006f\u0062\u002d\u0049\u0044");_ag .Log .Trace ("\u0052\u0065\u0073\u0070\u006f\u006e\u0073\u0065\u0020I\u0044\u0020\u0025\u0073",_fab );return &PDFResponse {ID :_fab ,Data :_bcc },nil ;}; + +// New creates new client with provided options. +func New (o Options )*Client {o .DefaultTimeout =_gc .Second *30;if o .Port <=0{o .Port =8080;};if o .Hostname ==""{o .Hostname ="\u00312\u0037\u002e\u0030\u002e\u0030\u002e1";};var _ce =&_gf .Transport {DialContext :(&_df .Dialer {Timeout :5*_gc .Second }).DialContext ,TLSHandshakeTimeout :5*_gc .Second };_ag .Log .Info ("\u0043l\u0069e\u006e\u0074\u0020\u0041\u0064\u0064\u0072\u003a\u0020\u0025\u0073",o .Addr ());return &Client {Options :o ,Client :&_gf .Client {Transport :_ce ,Timeout :o .DefaultTimeout }};}; + +// PaperHeight sets up the PaperHeight (in cm) parameter for the query. +func (_bf *QueryBuilder )PaperHeight (paperHeight _ecf .Length )*QueryBuilder {_bf ._gd .PageParameters .PaperHeight =paperHeight ;return _bf ;}; + +// Err gets the error which could occur in the query. +func (_ecfg *QueryBuilder )Err ()error {return _ecfg ._eec }; + +// MarginTop sets up the MarginTop parameter for the query. +func (_geb *QueryBuilder )MarginTop (marginTop _ecf .Length )*QueryBuilder {_geb ._gd .PageParameters .MarginTop =marginTop ;return _geb ;}; + +// BuildHTMLQuery creates a Query builder that is supposed to create valid +func BuildHTMLQuery ()*QueryBuilder {return &QueryBuilder {}}; + +// MarginBottom sets up the MarginBottom parameter for the query. +func (_dg *QueryBuilder )MarginBottom (marginBottom _ecf .Length )*QueryBuilder {_dg ._gd .PageParameters .MarginBottom =marginBottom ;return _dg ;}; + +// PageSize sets up the PageSize parameter for the query. +func (_gb *QueryBuilder )PageSize (pageSize _ecf .PageSize )*QueryBuilder {_gb ._gd .PageParameters .PageSize =&pageSize ;return _gb ;}; + +// Query gets the Query from provided query builder. If some error occurred during build process +// or the input is not valid the function would return an error. +func (_bce *QueryBuilder )Query ()(*Query ,error ){if _ceg :=_bce .Validate ();_ceg !=nil {return nil ,_ceg ;};return &_bce ._gd ,nil ;}; + +// PaperWidth sets up the PaperWidth (in cm) parameter for the query. +func (_fabd *QueryBuilder )PaperWidth (paperWidth _ecf .Length )*QueryBuilder {_fabd ._gd .PageParameters .PaperWidth =paperWidth ;return _fabd ;};var (ErrNotFound =_g .New ("\u006eo\u0074\u0020\u0066\u006f\u0075\u006ed");ErrBadRequest =_g .New ("b\u0061\u0064\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074");ErrNotImplemented =_g .New ("\u006eo\u0074 \u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0064");ErrInternalError =_g .New ("i\u006e\u0074\u0065\u0072na\u006c \u0073\u0065\u0072\u0076\u0065r\u0020\u0065\u0072\u0072\u006f\u0072");ErrBadGateway =_g .New ("b\u0061\u0064\u0020\u0067\u0061\u0074\u0065\u0077\u0061\u0079");); + +// ParseOptions parses options for the Client. +func ParseOptions (connectPath string )(Options ,error ){if !_ee .HasPrefix (connectPath ,"\u0068\u0074\u0074\u0070"){connectPath ="\u0068t\u0074\u0070\u003a\u002f\u002f"+connectPath ;};_c ,_cb :=_b .Parse (connectPath );if _cb !=nil {return Options {},_f .Errorf ("p\u0072\u006f\u0076\u0069\u0064\u0065d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0075\u006e\u0069\u0068\u0074m\u006c\u002d\u0073\u0065\u0072\u0076\u0065\u0072\u0020\u0075r\u006c");};var _fg int ;if _c .Port ()!=""{_fg ,_cb =_dc .Atoi (_c .Port ());if _cb !=nil {return Options {},_f .Errorf ("\u0070\u0061\u0072si\u006e\u0067\u0020\u0070\u006f\u0072\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_cb );};};return Options {Hostname :_c .Hostname (),Port :_fg ,HTTPS :_c .Scheme =="\u0068\u0074\u0074p\u0073",Prefix :_c .Path },nil ;}; + +// HealthCheck connects to the server and check the health status of the server. +func (_be *Client )HealthCheck (ctx _e .Context )error {_de :=_be .Options .Addr ();_de =_ge .Sprintf ("\u0025s\u002f\u0068\u0065\u0061\u006c\u0074h",_de );_aa ,_gca :=_gf .NewRequest ("\u0047\u0045\u0054",_de ,nil );if _gca !=nil {return _gca ;};_aa =_aa .WithContext (ctx );_bc ,_gca :=_be .Client .Do (_aa );if _gca !=nil {return _gca ;};switch _bc .StatusCode {case _gf .StatusOK :return nil ;case _gf .StatusNotFound :return ErrNotFound ;case _gf .StatusInternalServerError :return ErrInternalError ;case _gf .StatusBadGateway :return ErrBadGateway ;default:return ErrNotImplemented ;};}; + +// WithPort sets the Port option for the client options. +func WithPort (option int )Option {return func (_da *Options ){_da .Port =option }}; + +// Addr gets the HTTP address URI used by the http.Client. +func (_ac *Options )Addr ()string {_efc :=_ee .Builder {};_efc .WriteString ("\u0068\u0074\u0074\u0070");if _ac .HTTPS {_efc .WriteRune ('s');};_efc .WriteString ("\u003a\u002f\u002f");_efc .WriteString (_ac .Hostname );_efc .WriteRune (':');_efc .WriteString (_dc .Itoa (_ac .Port ));if _ac .Prefix !=""{_efc .WriteString (_ac .Prefix );};return _efc .String ();}; + +// Orientation sets the page orientation for the Query. +func (_fgb *QueryBuilder )Orientation (orientation _ecf .Orientation )*QueryBuilder {_fgb ._gd .PageParameters .Orientation =orientation ;return _fgb ;}; + +// Validate checks if the QueryBuilder had no errors during composition and creation. +func (_baf *QueryBuilder )Validate ()error {if _baf ._eec !=nil {return _baf ._eec ;};return _baf ._gd .Validate ();};var (ErrMissingData =_g .New ("\u006di\u0073s\u0069\u006e\u0067\u0020\u0069n\u0070\u0075t\u0020\u0064\u0061\u0074\u0061");ErrContentType =_g .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u006f\u006et\u0065\u006e\u0074\u0020ty\u0070\u0065");ErrContentTypeDeclared =_g .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");); + +// Client is a structure that is a HTTP client for the unihtml server. +type Client struct{Options Options ;Client *_gf .Client ;}; + +// Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process. +type Query struct{Data []byte ;ContentType string ;PageParameters PageParameters ;}; + +// Landscape sets up the landscape portrait orientation. +func (_db *QueryBuilder )Landscape ()*QueryBuilder {_db ._gd .PageParameters .Orientation =_ecf .Landscape ;return _db ;}; + +// Option is a function that changes client options. +type Option func (_cf *Options );func (_ba *Client )getRequest (_eb _e .Context ,_ef *Query )(*_gf .Request ,error ){_cd :=_ba .Options .Addr ();_cd =_ge .Sprintf ("\u0025\u0073\u002f\u0070\u0064\u0066",_cd );_fd ,_fdb :=_gf .NewRequest ("\u0050\u004f\u0053\u0054",_cd ,_ec .NewReader (_ef .Data ));if _fdb !=nil {return nil ,_fdb ;};_fd .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065",_ef .ContentType );_fd =_fd .WithContext (_eb );_eba :=_fd .URL .Query ();_ccb :=_ef .PageParameters ;if _ccb .PageSize !=nil {_eba .Set ("\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae",_ccb .PageSize .String ());};if _ccb .PaperHeight !=nil {_eba .Set ("\u0070\u0061\u0070e\u0072\u002d\u0068\u0065\u0069\u0067\u0068\u0074",_ccb .PaperHeight .String ());};if _ccb .PaperWidth !=nil {_eba .Set ("p\u0061\u0070\u0065\u0072\u002d\u0077\u0069\u0064\u0074\u0068",_ccb .PaperWidth .String ());};if _ccb .MarginTop !=nil {_eba .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0074\u006f\u0070",_ccb .MarginTop .String ());};if _ccb .MarginBottom !=nil {_eba .Set ("\u006d\u0061\u0072\u0067\u0069\u006e\u002d\u0062\u006f\u0074\u0074\u006f\u006d",_ccb .MarginBottom .String ());};if _ccb .MarginRight !=nil {_eba .Set ("\u006d\u0061\u0072g\u0069\u006e\u002d\u0072\u0069\u0067\u0068\u0074",_ccb .MarginRight .String ());};if _ccb .MarginLeft !=nil {_eba .Set ("m\u0061\u0072\u0067\u0069\u006e\u002d\u006c\u0065\u0066\u0074",_ccb .MarginLeft .String ());};if _ccb .Orientation ==_ecf .Landscape {_eba .Set ("o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e",_ccb .Orientation .String ());};_fd .URL .RawQuery =_eba .Encode ();return _fd ,nil ;}; + +// MarginLeft sets up the MarginLeft parameter for the query. +func (_fb *QueryBuilder )MarginLeft (marginLeft _ecf .Length )*QueryBuilder {_fb ._gd .PageParameters .MarginLeft =marginLeft ;return _fb ;}; + +// WithHTTPS sets the TLS option for the client options. +func WithHTTPS (useHTTPS bool )Option {return func (_bfd *Options ){_bfd .HTTPS =useHTTPS }}; + +// Options are the client options used by the HTTP client. +type Options struct{HTTPS bool ;Hostname string ;Port int ;DefaultTimeout _gc .Duration ;Prefix string ;}; + +// WithPrefix sets the client prefix. +func WithPrefix (prefix string )Option {return func (_bea *Options ){_bea .Prefix =prefix }}; + +// WithDefaultTimeout sets the DefaultTimeout option for the client options. +func WithDefaultTimeout (option _gc .Duration )Option {return func (_caa *Options ){_caa .DefaultTimeout =option };}; + +// MarginRight sets up the MarginRight parameter for the query. +func (_eef *QueryBuilder )MarginRight (marginRight _ecf .Length )*QueryBuilder {_eef ._gd .PageParameters .MarginRight =marginRight ;return _eef ;}; + +// Validate checks if provided Query is valid. +func (_aad *Query )Validate ()error {if len (_aad .Data )==0{return ErrMissingData ;};if _aad .ContentType ==""{return ErrContentType ;};if _ga :=_aad .PageParameters .Validate ();_ga !=nil {return _ga ;};return nil ;}; + +// Portrait sets up the portrait page orientation. +func (_bd *QueryBuilder )Portrait ()*QueryBuilder {_bd ._gd .PageParameters .Orientation =_ecf .Portrait ;return _bd ;}; + +// Validate checks if the parameters are valid. +func (_fbb *PageParameters )Validate ()error {if _fbb .PaperWidth !=nil {if _fbb .PaperWidth .Millimeters ()< 0{return _g .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u0050\u0061\u0070\u0065\u0072\u0057id\u0074\u0068");};};if _fbb .PaperHeight !=nil {if _fbb .PaperHeight .Millimeters ()< 0{return _g .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u0050\u0061\u0070\u0065\u0072\u0048\u0065\u0069\u0067\u0068\u0074");};};if _fbb .MarginTop !=nil {if _fbb .MarginTop .Millimeters ()< 0{return _g .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 _fbb .MarginBottom !=nil {if _fbb .MarginBottom .Millimeters ()< 0{return _g .New ("\u006e\u0065\u0067a\u0074\u0069\u0076\u0065 \u0076\u0061\u006c\u0075\u0065\u0020\u0066o\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006e\u0042\u006f\u0074\u0074\u006f\u006d");};};if _fbb .MarginLeft !=nil {if _fbb .MarginLeft .Millimeters ()< 0{return _g .New ("\u006e\u0065g\u0061\u0074\u0069\u0076\u0065\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u0066\u006f\u0072\u0020\u004d\u0061\u0072\u0067\u0069\u006eLe\u0066\u0074");};};if _fbb .MarginRight !=nil {if _fbb .MarginRight .Millimeters ()< 0{return _g .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0076a\u006c\u0075\u0065\u0020\u0066\u006f\u0072 \u004d\u0061\u0072\u0067\u0069\u006e\u0052\u0069\u0067\u0068\u0074");};};if _fbb .PageSize !=nil &&!_fbb .PageSize .IsAPageSize (){return _g .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065 \u0073\u0069\u007a\u0065");};return nil ;}; + +// WithHostname sets the Hostname option for the client options. +func WithHostname (option string )Option {return func (_deg *Options ){_deg .Hostname =option }}; + +// QueryBuilder is the query that converts HTMLConverter defined data +type QueryBuilder struct{_gd Query ;_eec error ;}; + +// SetContent sets custom data with it's content type. +func (_dbd *QueryBuilder )SetContent (content _gfc .Content )*QueryBuilder {if _dbd ._eec !=nil {return _dbd ;};if _dbd ._gd .ContentType !=""{_dbd ._eec =ErrContentTypeDeclared ;return _dbd ;};if content .ContentType ()==""{_dbd ._eec =_f .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 _dbd ;};_dbd ._gd .Data =content .Data ();_dbd ._gd .ContentType =content .ContentType ();return _dbd ;}; + +// DefaultPageParameters creates default parameters. +func DefaultPageParameters ()PageParameters {return PageParameters {Orientation :_ecf .Portrait }}; + +// PageParameters are the query parameters used in the PDF generation. +type PageParameters struct{ + +// PaperWidth sets the width of the paper. +PaperWidth _ecf .Length `schema:"paper-width" json:"paperWidth"`; + +// PaperHeight is the height of the output paper. +PaperHeight _ecf .Length `schema:"paper-height" json:"paperHeight"`; + +// PageSize is the page size string. +PageSize *_ecf .PageSize `schema:"page-size" json:"pageSize"`; + +// Orientation defines if the output should be in a landscape format. +Orientation _ecf .Orientation `schema:"orientation" json:"orientation"`; + +// MarginTop sets up the Top Margin for the output. +MarginTop _ecf .Length `schema:"margin-top" json:"marginTop"`; + +// MarginBottom sets up the Bottom Margin for the output. +MarginBottom _ecf .Length `schema:"margin-bottom" json:"marginBottom"`; + +// MarginLeft sets up the Left Margin for the output. +MarginLeft _ecf .Length `schema:"margin-left" json:"marginLeft"`; + +// MarginRight sets up the Right Margin for the output. +MarginRight _ecf .Length `schema:"margin-right" json:"marginRight"`;}; + +// PDFResponse is the response used by the HTMLConverter. +type PDFResponse struct{ID string `json:"id"`;Data []byte `json:"data"`;}; \ No newline at end of file diff --git a/common/common.go b/common/common.go new file mode 100644 index 0000000..c287a7f --- /dev/null +++ b/common/common.go @@ -0,0 +1,16 @@ +// +// Copyright 2020 FoxyUtils ehf. All rights reserved. +// +// This is a commercial product and requires a license to operate. +// A trial license can be obtained at https://unidoc.io +// +// DO NOT EDIT: generated by unitwist Go source code obfuscator. +// +// Use of this source code is governed by the UniDoc End User License Agreement +// terms that can be accessed at https://unidoc.io/eula/ + +// Package common contains common properties used by the subpackages. +package common ;import _c "time";const _a =2021;const _ab =2; + +// UtcTimeFormat returns a formatted string describing a UTC timestamp. +func UtcTimeFormat (t _c .Time )string {return t .Format (_b )+"\u0020\u0055\u0054\u0043"};const _bf =8;const Version ="\u0030\u002e\u0031.\u0030";const _aa =12;const _b ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";var ReleasedAt =_c .Date (_a ,_ab ,_bf ,_aa ,_ag ,0,0,_c .UTC );const _ag =20; \ No newline at end of file diff --git a/content/content.go b/content/content.go new file mode 100644 index 0000000..a4925d6 --- /dev/null +++ b/content/content.go @@ -0,0 +1,43 @@ +// +// Copyright 2020 FoxyUtils ehf. All rights reserved. +// +// This is a commercial product and requires a license to operate. +// A trial license can be obtained at https://unidoc.io +// +// DO NOT EDIT: generated by unitwist Go source code obfuscator. +// +// Use of this source code is governed by the UniDoc End User License Agreement +// terms that can be accessed at https://unidoc.io/eula/ + +package content ;import (_c "archive/zip";_fb "bytes";_f "encoding/json";_e "golang.org/x/xerrors";_ac "io/ioutil";_cd "net/url";_a "os";_g "strings";); + +// ContentType implements Content interface. +func (_cdd *webURL )ContentType ()string {return "\u0061\u0070p\u006c\u0069\u0063a\u0074\u0069\u006f\u006e\u002f\u006a\u0073\u006f\u006e";}; + +// Data implements Content interface. +func (_ga *zipDirectory )Data ()[]byte {return _ga ._bf .Bytes ()}; + +// NewWebURL creates new Content webURL for provided input URL path. +func NewWebURL (path string )(Content ,error ){if _ ,_ff :=_cd .Parse (path );_ff !=nil {return nil ,_ff ;};type urlOutput struct{URL string `json:"url"`;};_eb :=urlOutput {URL :path };_ae ,_fff :=_f .Marshal (_eb );if _fff !=nil {return nil ,_fff ;};return &webURL {_dd :path ,_cf :_ae },nil ;}; + +// ContentType implements Content interface. +func (_ab *zipDirectory )ContentType ()string {return "\u0061p\u0070l\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u007a\u0069\u0070";};func (_ca *zipDirectory )zipBasePaths (_ge _a .FileInfo ,_ega ,_eeb string ,_bfa bool ,_gg *_g .Builder )(string ,string ){_gg .WriteString (_ega );if !_g .HasSuffix (_ega ,"\u002f"){_gg .WriteRune ('/');};_gg .WriteString (_ge .Name ());if _bfa {_gg .WriteRune ('/');};_ged :=_gg .String ();_gg .Reset ();_gg .WriteString (_eeb );_gg .WriteString (_ge .Name ());if _bfa {_gg .WriteRune ('/');};_ad :=_gg .String ();_gg .Reset ();return _ged ,_ad ;}; + +// Data implements Content interface. +func (_acc *webURL )Data ()[]byte {return _acc ._cf }; + +// Content is an interface used for putting the content into Client Query. +type Content interface{ContentType ()string ;Data ()[]byte ;}; + +// ContentType implements Content interface. +func (_da *htmFile )ContentType ()string {return "\u0074e\u0078\u0074\u002f\u0068\u0074\u006dl"}; + +// NewZipDirectory creates new zip compressed file that recursively reads the directory at the 'dirPath' +// and stores in it's in-memory buffer. +func NewZipDirectory (dirPath string )(Content ,error ){_gbb :=&zipDirectory {_bf :_fb .Buffer {}};_gbb ._fe =_c .NewWriter (&_gbb ._bf );if _ee :=_gbb .zipPath (dirPath ,"");_ee !=nil {return nil ,_ee ;};if _dc :=_gbb ._fe .Close ();_dc !=nil {return nil ,_dc ;};return _gbb ,nil ;};type webURL struct{_dd string ;_cf []byte ;}; + +// Data implements Content interface. +func (_gb *htmFile )Data ()[]byte {return _gb ._d .Bytes ()};func (_eg *zipDirectory )zipPath (_cc ,_gaa string )error {_de ,_cfb :=_ac .ReadDir (_cc );if _cfb !=nil {return _e .Errorf ("\u0072\u0065\u0061di\u006e\u0067\u0020\u0064\u0069\u0072\u0065\u0063\u0074o\u0072y\u003a \u0027%\u0073\u0027\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0077",_cc ,_cfb );};_fc :=&_g .Builder {};for _ ,_ce :=range _de {_df ,_gf :=_eg .zipBasePaths (_ce ,_cc ,_gaa ,_ce .IsDir (),_fc );if _ce .IsDir (){if _acd :=_eg .zipPath (_df ,_gf );_acd !=nil {return _acd ;};continue ;};_fcd ,_beg :=_ac .ReadFile (_df );if _beg !=nil {return _beg ;};_ebg ,_beg :=_eg ._fe .Create (_gf );if _beg !=nil {return _beg ;};if _ ,_beg =_ebg .Write (_fcd );_beg !=nil {return _beg ;};};return nil ;};type htmFile struct{_d _fb .Buffer }; + +// NewHTMLFile creates new Content htmFile for provided input path. +func NewHTMLFile (path string )(Content ,error ){_aa ,_be :=_a .Open (path );if _be !=nil {return nil ,_be ;};_af :=&htmFile {_d :_fb .Buffer {}};if _ ,_be =_af ._d .ReadFrom (_aa );_be !=nil {return nil ,_be ;};return _af ,nil ;};type zipDirectory struct{_bf _fb .Buffer ;_fe *_c .Writer ;}; \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..908a8b1 --- /dev/null +++ b/go.mod @@ -0,0 +1,12 @@ +module github.com/unidoc/unihtml + +go 1.15 + +require ( + github.com/mitchellh/go-homedir v1.1.0 + github.com/pkg/errors v0.9.1 + github.com/spf13/cobra v1.1.1 + github.com/spf13/viper v1.7.1 + github.com/unidoc/unipdf/v3 v3.18.0 + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 +) diff --git a/sizes/sizes.go b/sizes/sizes.go new file mode 100644 index 0000000..2259313 --- /dev/null +++ b/sizes/sizes.go @@ -0,0 +1,174 @@ +// +// Copyright 2020 FoxyUtils ehf. All rights reserved. +// +// This is a commercial product and requires a license to operate. +// A trial license can be obtained at https://unidoc.io +// +// DO NOT EDIT: generated by unitwist Go source code obfuscator. +// +// Use of this source code is governed by the UniDoc End User License Agreement +// terms that can be accessed at https://unidoc.io/eula/ + +// Package sizes defines basic types that determines the size units i.e. lengths. +// +// +package sizes ;import (_c "encoding/json";_d "flag";_ee "fmt";_fb "github.com/pkg/errors";_e "strconv";_a "strings";); + +// Type implements pflag.Value interface. +func (_fab PageSize )Type ()string {return "\u0070a\u0067\u0065\u002d\u0073\u0069\u007ae"}; + +// UnmarshalPageSize unmarshals the page size from the string. +func UnmarshalPageSize (pageSize string )(PageSize ,error ){var _cb PageSize ;if _ecf :=(&_cb ).UnmarshalText ([]byte (pageSize ));_ecf !=nil {return 0,_fb .Wrap (_ecf ,"\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065");};return _cb ,nil ;}; + +// PageSizeString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func PageSizeString (s string )(PageSize ,error ){if _dcb ,_aafe :=_bd [s ];_aafe {return _dcb ,nil ;};return 0,_ee .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 );};const (Portrait =Orientation (false );Landscape =Orientation (true );); + +// Set implements flag.Value interface. +func (_fde *Orientation )Set (s string )error {switch s {case "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074":*_fde =Portrait ;case "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e":*_fde =Landscape ;default:return _ee .Errorf ("\u0069n\u0076\u0061\u006c\u0069d\u0020\u006f\u0072\u0069\u0065n\u0074a\u0074i\u006f\u006e\u003a\u0020\u0027\u0025\u0073'",s );};return nil ;}; + +// Inch is a unit that +type Inch float64 ; + +// Type implements pflag.Value interface. +func (_ae *LengthFlag )Type ()string {return "\u0075\u006e\u0069\u0074"};func _bce (_ga string )(Inch ,error ){_ga =_a .TrimSpace (_a .Trim (_ga ,"\u0069\u006e"));_ddg ,_be :=_e .ParseFloat (_ga ,64);if _be !=nil {return 0,_fb .Wrap (_be ,"\u0069n\u0076a\u006c\u0069\u0064\u0020\u0069n\u0063\u0068 \u0076\u0061\u006c\u0075\u0065");};return Inch (_ddg ),nil ;};var _ Length =Inch (0); + +// Set implements flag.Value interface. +func (_gbb *Point )Set (s string )error {_ad ,_aa :=_e .ParseFloat (s ,64);if _aa !=nil {return _fb .Wrap (_aa ,"\u0069n\u0076a\u006c\u0069\u0064\u0020\u0069n\u0063\u0068 \u0076\u0061\u006c\u0075\u0065");};*_gbb =Point (_ad );return nil ;}; + +// String implements fmt.Stringer interface. +func (_dec Point )String ()string {_af :=_a .Builder {};_af .WriteString (_e .FormatFloat (float64 (_dec ),'f',1,64));_af .WriteString ("\u0070\u0074");return _af .String ();};var _ _d .Value =(*Orientation )(nil ); + +// Inches gets the inch value. Implements Length interface. +func (_fc Inch )Inches ()Inch {return _fc }; + +// Point is a unit of Length commonly used to measure the height of fonts. +type Point float64 ; + +// Millimeter is the dimension unit that defines a millimeter. +type Millimeter float64 ; + +// IsAPageSize returns "true" if the value is listed in the enum definition. "false" otherwise +func (_gbe PageSize )IsAPageSize ()bool {for _ ,_gc :=range _eeb {if _gbe ==_gc {return true ;};};return false ;}; + +// MarshalUnit marshals the unit into the string. +func MarshalUnit (unit Length )(string ,error ){switch _aaf :=unit .(type ){case Millimeter :return _ee .Sprintf ("\u0025\u002e\u0030\u0066\u006d\u006d",_aaf ),nil ;case Inch :return _ee .Sprintf ("\u0025\u002e\u0030\u0066\u0069\u006e",_aaf ),nil ;case Point :return _ee .Sprintf ("\u0025\u002e\u0030\u0066\u0070\u0074",_aaf ),nil ;default:return "",_ee .Errorf ("i\u006e\u0076\u0061\u006cid\u0020u\u006e\u0069\u0074\u0020\u0074y\u0070\u0065\u003a\u0020\u0025\u0054",unit );};}; + +// Set implements pflag.Value interface. +func (_dfb *PageSize )Set (s string )error {_cad ,_bcg :=UnmarshalPageSize (s );if _bcg !=nil {return _bcg ;};*_dfb =_cad ;return nil ;}; + +// Points implements Length interface. +func (_ebf Millimeter )Points ()Point {return Point (_ebf *_db )}; + +// Name implements viper.FlagValue interface. +func (_dc Point )Name ()string {return "\u0070\u006f\u0069n\u0074"}; + +// UnmarshalLength unmarshalls string value into Length. +func UnmarshalLength (length string )(Length ,error ){if _a .HasSuffix (length ,"\u006d\u006d"){return _faf (length );};if _a .HasSuffix (length ,"\u0069\u006e"){return _bce (length );};if _a .HasSuffix (length ,"\u0070\u0074"){return _ggb (length );};return nil ,_ee .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020\u0025\u0073",length );};func _ggb (_afg string )(Point ,error ){_afg =_a .TrimSpace (_a .Trim (_afg ,"\u0070\u0074"));_bb ,_cf :=_e .ParseFloat (_afg ,64);if _cf !=nil {return 0,_cf ;};return Point (_bb ),nil ;}; + +// Dimensions gets the dimensions of the given page size. +// If provided page size is not valid than the function returns 0 values. +func (_gf PageSize )Dimensions ()(_eaa ,_dbad Millimeter ){switch _gf {case A0 :return 841,1189;case A1 :return 594,841;case A2 :return 420,594;case A3 :return 297,420;case A4 :return 210,297;case A5 :return 148,210;case A6 :return 105,148;case A7 :return 74,105;case A8 :return 52,74;case A9 :return 37,52;case A10 :return 26,37;case B0 :return 1000,1414;case B1 :return 707,1000;case B2 :return 500,707;case B3 :return 353,500;case B4 :return 250,353;case B5 :return 176,250;case B6 :return 125,176;case B7 :return 88,125;case B8 :return 66,88;case B9 :return 44,62;case B10 :return 31,44;case Letter :return 215.9,279.4;};return _eaa ,_dbad ;}; + +// String gets the string value for given flag. +func (_fa *LengthFlag )String ()string {if _fa .Length ==nil {return "\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d";};return _fa .Length .String ();}; + +// Type implements pflag.Value interface. +func (_aee Orientation )Type ()string {return "o\u0072\u0069\u0065\u006e\u0074\u0061\u0074\u0069\u006f\u006e";};var _ce =[...]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}; + +// Inches gets the inches equivalent from provided millimeter value. +func (_ccf Millimeter )Inches ()Inch {return Inch (float64 (_ccf )*_de )}; + +// Millimeters converts the inches value to the millimeters. +func (_ggc Point )Millimeters ()Millimeter {return Millimeter (float64 (_ggc )*_da )}; + +// ValueString implements pflag.Value interface. +func (_dba Inch )ValueString ()string {return _dba .String ()}; + +// HasChanged implements pflag.Value interface. +func (_ca *Inch )HasChanged ()bool {return _ca !=nil };const (_de =float64 (1)/float64 (25.4);_g =25.4;_gd =0.0139;_da =0.3528;_eb =1/64;_db =1/_da ;); + +// Type implements pflag.Value interface. +func (_bc Inch )Type ()string {return "\u0069\u006e\u0063\u0068"};var _bd =map[string ]PageSize {_dbe [0:9]:0,_dbe [9:11]:1,_dbe [11:13]:2,_dbe [13:15]:3,_dbe [15:17]:4,_dbe [17:19]:5,_dbe [19:21]:6,_dbe [21:23]:7,_dbe [23:25]:8,_dbe [25:27]:9,_dbe [27:29]:10,_dbe [29:32]:11,_dbe [32:34]:12,_dbe [34:36]:13,_dbe [36:38]:14,_dbe [38:40]:15,_dbe [40:42]:16,_dbe [42:44]:17,_dbe [44:46]:18,_dbe [46:48]:19,_dbe [48:50]:20,_dbe [50:52]:21,_dbe [52:55]:22,_dbe [55:61]:23};const (Undefined PageSize =iota ;A0 ;A1 ;A2 ;A3 ;A4 ;A5 ;A6 ;A7 ;A8 ;A9 ;A10 ;B0 ;B1 ;B2 ;B3 ;B4 ;B5 ;B6 ;B7 ;B8 ;B9 ;B10 ;Letter ;); + +// String implements fmt.Stringer interface. +func (_fd Millimeter )String ()string {_fe :=_a .Builder {};_fe .WriteString (_e .FormatFloat (float64 (_fd ),'f',1,64));_fe .WriteString ("\u006d\u006d");return _fe .String ();}; + +// Points implements Length interface. +func (_gdc Point )Points ()Point {return _gdc }; + +// ValueType implements viper.FlagValue interface. +func (_ec Point )ValueType ()string {return _ec .Type ()}; + +// UnmarshalInch unmarshalls provided string into unit. +func UnmarshalInch (unit string )(Inch ,error ){if _a .HasSuffix (unit ,"\u006d\u006d"){_aed ,_aec :=_faf (unit );if _aec !=nil {return 0,_aec ;};return _aed .Inches (),nil ;};if _a .HasSuffix (unit ,"\u0069\u006e"){return _bce (unit );};return 0,_ee .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0069\u006e\u0063\u0068\u0020\u0069\u006e\u0070\u0075\u0074\u003a\u0020%\u0073",unit );};const _dbe ="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"; + +// MarshalText implements the encoding.TextMarshaler interface for PageSize +func (_fcf PageSize )MarshalText ()([]byte ,error ){return []byte (_fcf .String ()),nil }; + +// Set sets the unit value. +// Implements pflag.Value interface. +func (_b *LengthFlag )Set (s string )error {if s =="\u0075n\u0064\u0065\u0066\u0069\u006e\u0065d"{_b .Length =nil ;return nil ;};_gb ,_cc :=UnmarshalLength (s );if _cc !=nil {return _cc ;};_b .Length =_gb ;return nil ;}; + +// String implements fmt.Stringer interface. +func (_cg Orientation )String ()string {if _cg ==Portrait {return "\u0070\u006f\u0072\u0074\u0072\u0061\u0069\u0074";};return "\u006ca\u006e\u0064\u0073\u0063\u0061\u0070e";}; + +// MarshalPageSize marshals the page size into string. +func MarshalPageSize (p PageSize )(string ,error ){_adg ,_ece :=p .MarshalText ();if _ece !=nil {return "",_ece ;};return string (_adg ),nil ;}; + +// PageSize is the enum used for defining the page size. +type PageSize int ; + +// Inches gets the inch value. Implements Length interface. +func (_bg Point )Inches ()Inch {return Inch (float64 (_bg )*_gd )}; + +// Orientation is the page orientation type wrapper. +type Orientation bool ; + +// Points implements Length interface. +func (_bfeg Inch )Points ()Point {return Point (float64 (_bfeg )*_eb )}; + +// Name implements pflag.Value interface. +func (_bcc Inch )Name ()string {return "\u0069\u006e\u0063\u0068"}; + +// HasChanged implements viper.FlagValue interface. +func (_ef *Point )HasChanged ()bool {return _ef !=nil }; + +// ValueType implements pflag.Value interface. +func (_ge Inch )ValueType ()string {return _ge .Type ()}; + +// ValueString implements viper.FlagValue interface. +func (_adf Point )ValueString ()string {return _adf .String ()}; + +// MarshalJSON implements the json.Marshaler interface for PageSize +func (_fbe PageSize )MarshalJSON ()([]byte ,error ){return _c .Marshal (_fbe .String ())};var (_ Length =Millimeter (0);); + +// String implements fmt.Stringer interface. +func (_bf Inch )String ()string {_ebb :=_a .Builder {};_ebb .WriteString (_e .FormatFloat (float64 (_bf ),'f',1,64));_ebb .WriteString ("\u0069\u006e");return _ebb .String ();};func _faf (_dcf string )(Millimeter ,error ){_dcf =_a .TrimSpace (_a .TrimSuffix (_dcf ,"\u006d\u006d"));_gea ,_ed :=_e .ParseFloat (_dcf ,64);if _ed !=nil {return 0,_fb .Wrap (_ed ,"\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u006d\u0069\u006c\u006c\u0069m\u0065\u0074\u0065\u0072\u0020\u0076\u0061\u006c\u0075\u0065");};return Millimeter (_gea ),nil ;}; + +// Millimeters converts the inches value to the millimeters. +func (_bfe Inch )Millimeters ()Millimeter {return Millimeter (float64 (_bfe )*_g )}; + +// Set implements pflag.Value interface. +func (_dd *Inch )Set (s string )error {_ab ,_daf :=_e .ParseFloat (s ,64);if _daf !=nil {return _fb .Wrap (_daf ,"\u0069n\u0076a\u006c\u0069\u0064\u0020\u0069n\u0063\u0068 \u0076\u0061\u006c\u0075\u0065");};*_dd =Inch (_ab );return nil ;}; + +// Length is it the default dimension unit. +type Length interface{Millimeters ()Millimeter ;Inches ()Inch ;Points ()Point ;String ()string ;}; + +// UnmarshalJSON implements the json.Unmarshaler interface for PageSize +func (_abb *PageSize )UnmarshalJSON (data []byte )error {var _ddb string ;if _ag :=_c .Unmarshal (data ,&_ddb );_ag !=nil {return _ee .Errorf ("P\u0061\u0067\u0065\u0053\u0069\u007ae\u0020\u0073\u0068\u006f\u0075\u006cd\u0020\u0062\u0065\u0020\u0061\u0020\u0073t\u0072\u0069\u006e\u0067\u002c\u0020\u0067\u006f\u0074\u0020%\u0073",data );};var _aba error ;*_abb ,_aba =PageSizeString (_ddb );return _aba ;}; + +// PageSizeValues returns all values of the enum +func PageSizeValues ()[]PageSize {return _eeb }; + +// Type implements pflag.Value interface. +func (_gg Point )Type ()string {return "\u0070\u006f\u0069n\u0074"};var _ _d .Value =(*Point )(nil ); + +// LengthFlag is a pflag wrapper for the Length value. +type LengthFlag struct{Length Length ;};var _eeb =[]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}; + +// UnmarshalText implements the encoding.TextUnmarshaler interface for PageSize +func (_bef *PageSize )UnmarshalText (text []byte )error {var _ded error ;*_bef ,_ded =PageSizeString (string (text ));return _ded ;};func (_edc PageSize )String ()string {if _edc < 0||_edc >=PageSize (len (_ce )-1){return _ee .Sprintf ("\u0050\u0061\u0067e\u0053\u0069\u007a\u0065\u0028\u0025\u0064\u0029",_edc );};return _dbe [_ce [_edc ]:_ce [_edc +1]];}; + +// Millimeters gets the float64 millimeter value. +func (_ea Millimeter )Millimeters ()Millimeter {return _ea }; \ No newline at end of file diff --git a/unihtml.go b/unihtml.go new file mode 100644 index 0000000..98407e2 --- /dev/null +++ b/unihtml.go @@ -0,0 +1,79 @@ +// +// Copyright 2020 FoxyUtils ehf. All rights reserved. +// +// This is a commercial product and requires a license to operate. +// A trial license can be obtained at https://unidoc.io +// +// DO NOT EDIT: generated by unitwist Go source code obfuscator. +// +// Use of this source code is governed by the UniDoc End User License Agreement +// terms that can be accessed at https://unidoc.io/eula/ + +// Package unihtml contains a plugin for the UniDoc. +package unihtml ;import (_b "bytes";_c "context";_fc "errors";_db "fmt";_g "github.com/unidoc/unihtml/client";_dce "github.com/unidoc/unihtml/content";_dc "github.com/unidoc/unihtml/sizes";_gg "github.com/unidoc/unipdf/v3/common/license";_dbf "github.com/unidoc/unipdf/v3/creator";_e "github.com/unidoc/unipdf/v3/model";_dg "net/url";_f "os";_fg "time";);func (_eb *Document )extract (_ge _c .Context ,_gf ,_ce _dc .Length ,_dfef margins )([]*_e .PdfPage ,error ){_cbg :=_g .BuildHTMLQuery ().SetContent (_eb ._df ).PageSize (_eb ._ec ).PaperWidth (_gf ).PaperHeight (_ce ).Orientation (_eb ._bda ).MarginLeft (_dfef .Left ).MarginRight (_dfef .Right ).MarginTop (_dfef .Top ).MarginBottom (_dfef .Bottom );_faa ,_fac :=_cbg .Query ();if _fac !=nil {return nil ,_fac ;};_ge ,_cbd :=_c .WithTimeout (_ge ,_fg .Second *15);defer _cbd ();_bfa ,_fac :=_ea .ConvertHTML (_ge ,_faa );if _fac !=nil {return nil ,_fac ;};_ffa :=_b .NewReader (_bfa .Data );_ebc ,_fac :=_e .NewPdfReader (_ffa );if _fac !=nil {return nil ,_fac ;};return _ebc .PageList ,nil ;}; + +// SetLandscapeOrientation sets document landscape page orientation. +func (_beb *Document )SetLandscapeOrientation (){_beb ._bda =_dc .Landscape }; + +// GeneratePageBlocks implements creator.Drawable interface. +func (_be *Document )GeneratePageBlocks (ctx _dbf .DrawContext )([]*_dbf .Block ,_dbf .DrawContext ,error ){if _dgg :=_be .validate ();_dgg !=nil {return nil ,ctx ,_dgg ;};var _ad []*_dbf .Block ;_cf :=_be .getMargins ();_eg ,_de :=_be ._dfc ,_be ._dd ;if _be ._dcc .IsRelative (){_eg ,_de =_dc .Point (ctx .Width ),_dc .Point (ctx .Height );};_bed ,_bf :=_be .extract (_c .Background (),_eg ,_de ,_cf );if _bf !=nil {return nil ,_dbf .DrawContext {},_bf ;};for _cdc ,_ffbe :=range _bed {_ecd ,_ae :=_dbf .NewBlockFromPage (_ffbe );if _ae !=nil {return nil ,_dbf .DrawContext {},_ae ;};_acf ,_acb ,_ae :=_ecd .GeneratePageBlocks (ctx );if _ae !=nil {return nil ,_dbf .DrawContext {},_ae ;};ctx =_acb ;if _cdc !=len (_bed )-1&&ctx .Y > (ctx .PageHeight -ctx .Margins .Bottom )*.95{ctx .X =ctx .Margins .Left ;ctx .Y =ctx .Margins .Top ;ctx .Page ++;};_ad =append (_ad ,_acf ...);};return _ad ,ctx ,nil ;};var ErrNoClient =_fc .New ("\u0055n\u0069\u0048\u0054\u004d\u004c\u0020\u0063\u006c\u0069\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");func (_gc *Document )getMargins ()margins {_cde :=_gc ._bg ;if _gc ._dcc .IsRelative (){_cde .Top =_dc .Millimeter (0);_cde .Left =_dc .Millimeter (0);_cde .Bottom =_dc .Millimeter (0);_cde .Right =_dc .Millimeter (0);return _cde ;};if _cde .Top ==nil {_cde .Top =_dc .Millimeter (10);};if _cde .Bottom ==nil {_cde .Bottom =_dc .Millimeter (10);};if _cde .Left ==nil {_cde .Left =_dc .Millimeter (10);};if _cde .Right ==nil {_cde .Right =_dc .Millimeter (10);};return _cde ;}; + +// GetPdfPages is a function that converts provided input content and +func (_dde *Document )GetPdfPages (ctx _c .Context )([]*_e .PdfPage ,error ){if _cd :=_dde .validate ();_cd !=nil {return nil ,_cd ;};return _dde .extract (ctx ,_dde ._dfc ,_dde ._dd ,_dde .getMargins ());};type margins struct{Left ,Right ,Bottom ,Top _dc .Length ;}; + +// SetMargins sets the Document Margins. +func (_bfc *Document )SetMargins (left ,right ,top ,bottom float64 ){_bfc ._bg .Left =_dc .Point (left );_bfc ._bg .Right =_dc .Point (right );_bfc ._bg .Top =_dc .Point (top );_bfc ._bg .Bottom =_dc .Point (bottom );_bfc ._dcc =_dbf .PositionAbsolute ;}; + +// Document is HTML document wrapper that is used for extracting and converting HTML document into PDF pages. +type Document struct{_df _dce .Content ;_bg margins ;_dcc _dbf .Positioning ;_ac ,_ff float64 ;_ec _dc .PageSize ;_dfc ,_dd _dc .Length ;_bda _dc .Orientation ;}; + +// SetMarginLeft sets the left margin. +func (_fb *Document )SetMarginLeft (margin _dc .Length ){_fb ._bg .Left =margin }; + +// SetPos sets the absolute position. Changes object positioning to absolute. +func (_ab *Document )SetPos (x ,y float64 ){_ab ._dcc =_dbf .PositionAbsolute ;_ab ._ac =x ;_ab ._ff =y }; + +// SetPageWidth sets the page width for given document. +func (_cb *Document )SetPageWidth (pageWidth _dc .Length )error {_cb ._dfc =pageWidth ;_cb ._dcc =_dbf .PositionAbsolute ;return nil ;}; + +// SetMarginBottom sets the left margin. +func (_egf *Document )SetMarginBottom (margin _dc .Length ){_egf ._bg .Bottom =margin };func _aa ()error {_fa :=_gg .GetLicenseKey ();if _fa ==nil {return _fc .New ("\u006e\u006f\u0020\u006cic\u0065\u006e\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};if !_fa .IsLicensed (){return _fc .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006f\u0072 \u006e\u006f\u0020\u006c\u0069\u0063\u0065n\u0073\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};if !_fa .UniHTML {return _fc .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020l\u0069\u0063e\u006e\u0073\u0065\u0020\u0069\u0073 \u006e\u006f\u0074\u0020\u0076\u0061\u006c\u0069d\u0020\u0066\u006f\u0072\u0020\u0074\u0068\u0065\u0020U\u006e\u0069\u0048\u0054\u004d\u004c\u0020\u0065\u0078\u0074\u0065n\u0073\u0069\u006f\u006e.\u0020\u0056i\u0073i\u0074\u003a\u0020\u0068\u0074\u0074\u0070s\u003a/\u002f\u0077\u0077\u0077\u002e\u0075\u006e\u0069\u0064\u006f\u0063\u002e\u0069\u006f\u0020\u0061\u006ed\u0020c\u006f\u006e\u0074\u0061\u0063\u0074\u0020\u0073\u0075\u0070\u0070\u006f\u0072t");};return nil ;}; + +// ChapterDraw implements creator.containerElement interface. +func (_dfec *Document )ContainerComponent (container _dbf .Drawable )(_dbf .Drawable ,error ){switch container .(type ){case *_dbf .Chapter :default:return nil ,_db .Errorf ("\u0075\u006e\u0069\u0068t\u006d\u006c\u002e\u0044\u006f\u0063\u0075\u006d\u0065n\u0074\u0020\u0063\u0061\u006e\u0027\u0074\u0020\u0062\u0065\u0020\u0061\u0020\u0063\u006f\u006d\u0070\u006fn\u0065\u006e\u0074\u0020\u006ff\u0020\u0074\u0068\u0065\u0020\u0025\u0054\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0065\u0072",container );};return _dfec ,nil ;}; + +// ConnectOptions creates UniHTML HTTP Client and tries to establish connection with the server. +func ConnectOptions (o Options )error {_ea =_g .New (_g .Options {Hostname :o .Hostname ,Port :o .Port ,HTTPS :o .Secure });_bc ,_a :=_c .WithTimeout (_c .Background (),_fg .Second *5);defer _a ();if _bd :=_ea .HealthCheck (_bc );_bd !=nil {return _bd ;};return nil ;}; + +// Connect creates UniHTML HTTP Client and tries to establish connection with the server. +func Connect (path string )error {if _fd :=_aa ();_fd !=nil {return _fd ;};_fcg ,_fe :=_g .ParseOptions (path );if _fe !=nil {return _fe ;};_ea =_g .New (_fcg );_ee ,_eae :=_c .WithTimeout (_c .Background (),_fg .Second *5);defer _eae ();if _ba :=_ea .HealthCheck (_ee );_ba !=nil {return _ba ;};return nil ;};var ErrContentNotDefined =_fc .New ("\u0068\u0074\u006d\u006c\u0020\u0064o\u0063\u0075\u006d\u0065\u006e\u0074\u0020\u0063\u006f\u006e\u0074\u0065\u006et\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); + +// SetMarginTop sets the left margin. +func (_cc *Document )SetMarginTop (margin _dc .Length ){_cc ._bg .Top =margin };var _ _dbf .Drawable =(*Document )(nil ); + +// SetMarginRight sets the left margin. +func (_bb *Document )SetMarginRight (margin _dc .Length ){_bb ._bg .Right =margin }; + +// SetPageSize sets the page default size. +func (_cfe *Document )SetPageSize (pageSize _dc .PageSize )error {if !pageSize .IsAPageSize (){return _fc .New ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0067\u0065\u0020s\u0069\u007a\u0065");};_cfe ._ec =pageSize ;_cfe ._dcc =_dbf .PositionAbsolute ;return nil ;}; + +// NewDocument creates new HTML Document used as an input for the creator.Drawable. +func NewDocument (path string )(*Document ,error ){_dfe :=&Document {};_ef ,_fce :=_dg .Parse (path );if _fce !=nil {return nil ,_fce ;};switch _ef .Scheme {case "\u0068\u0074\u0074\u0070","\u0068\u0074\u0074p\u0073":_dfe ._df ,_fce =_dce .NewWebURL (path );if _fce !=nil {return nil ,_fce ;};return _dfe ,nil ;};_ffb ,_fce :=_f .Stat (path );if _fce !=nil {return nil ,_fce ;};if !_ffb .IsDir (){_dfe ._df ,_fce =_dce .NewHTMLFile (path );}else {_dfe ._df ,_fce =_dce .NewZipDirectory (path );};if _fce !=nil {return nil ,_fce ;};return _dfe ,nil ;}; + +// Options are the HTML Client options used for establishing the connection. +type Options struct{ + +// Hostname defines the hostname for the client. Default value: 'localhost'. +Hostname string ; + +// Port defines the port at which the server works. Default value: '8080' +Port int ; + +// Secure is the flag that states if the connection uses HTTPS protocol. Default Value: 'false'. +Secure bool ; + +// Prefix is an option setting used when the server is working with the URI prefix. Default Value: ''. +Prefix string ;};func (_ed *Document )validate ()error {if _ea ==nil {return ErrNoClient ;};if _ed ._df ==nil {return ErrContentNotDefined ;};return nil ;};var _ea *_g .Client ; + +// SetPageHeight sets the page height for given document. +func (_gd *Document )SetPageHeight (pageHeight _dc .Length )error {_gd ._dd =pageHeight ;_gd ._dcc =_dbf .PositionAbsolute ;return nil ;}; \ No newline at end of file