├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── greetings.yml ├── ACKNOWLEDGEMENTS.md ├── LICENSE.md ├── README.md ├── annotator └── annotator.go ├── common ├── common.go └── license │ └── license.go ├── contentstream ├── contentstream.go └── draw │ └── draw.go ├── core ├── core.go └── security │ ├── crypt │ └── crypt.go │ └── security.go ├── creator └── creator.go ├── extractor └── extractor.go ├── fdf └── fdf.go ├── fjson └── fjson.go ├── go.mod ├── go.sum ├── internal ├── bitwise │ └── bitwise.go ├── ccittfax │ └── ccittfax.go ├── cmap │ ├── bcmaps │ │ └── bcmaps.go │ └── cmap.go ├── endian │ └── endian.go ├── graphic2d │ └── graphic2d.go ├── imageutil │ └── imageutil.go ├── integrations │ └── unichart │ │ └── unichart.go ├── jbig2 │ ├── basic │ │ └── basic.go │ ├── bench │ │ └── bench.go │ ├── bitmap │ │ └── bitmap.go │ ├── decoder │ │ ├── arithmetic │ │ │ └── arithmetic.go │ │ ├── decoder.go │ │ ├── huffman │ │ │ └── huffman.go │ │ └── mmr │ │ │ └── mmr.go │ ├── document │ │ ├── document.go │ │ └── segments │ │ │ └── segments.go │ ├── encoder │ │ ├── arithmetic │ │ │ └── arithmetic.go │ │ └── classer │ │ │ └── classer.go │ ├── errors │ │ └── errors.go │ ├── internal │ │ └── internal.go │ └── jbig2.go ├── license │ └── license.go ├── precision │ └── precision.go ├── sampling │ └── sampling.go ├── strutils │ └── strutils.go ├── testutils │ └── testutils.go ├── textencoding │ ├── internal │ │ └── syncmap │ │ │ └── syncmap.go │ └── textencoding.go ├── timeutils │ └── timeutils.go ├── transform │ └── transform.go └── uuid │ └── uuid.go ├── model ├── internal │ ├── colorprofile │ │ └── colorprofile.go │ ├── docutil │ │ └── docutil.go │ └── fonts │ │ └── fonts.go ├── mdp │ └── mdp.go ├── model.go ├── optimize │ ├── optimize.go │ └── tests │ │ └── tests.go ├── pdfa │ └── pdfa.go ├── sighandler │ └── sighandler.go ├── sigutil │ └── sigutil.go └── xmputil │ ├── pdfaextension │ └── pdfaextension.go │ ├── pdfaid │ └── pdfaid.go │ └── xmputil.go ├── pdfutil └── pdfutil.go ├── ps └── ps.go ├── redactor └── redactor.go ├── render ├── internal │ └── context │ │ ├── context.go │ │ └── imagerender │ │ └── imagerender.go └── render.go ├── sanitize └── sanitize.go ├── textshaping └── textshaping.go └── unipdf.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 | The UniDoc library uses resources from the following open source projects: 5 | 6 | * [The standard Go library](https://golang.org/pkg/#stdlib), 7 | and [Go supplementary image libraries](https://godoc.org/golang.org/x/image/tiff/lzw), BSD-3 license: 8 | - Used for TIFF LZW encoding support. 9 | - PNG paeth algorithm 10 | 11 | ``` 12 | Copyright (c) 2009 The Go Authors. All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without 15 | modification, are permitted provided that the following conditions are 16 | met: 17 | 18 | * Redistributions of source code must retain the above copyright 19 | notice, this list of conditions and the following disclaimer. 20 | * Redistributions in binary form must reproduce the above 21 | copyright notice, this list of conditions and the following disclaimer 22 | in the documentation and/or other materials provided with the 23 | distribution. 24 | * Neither the name of Google Inc. nor the names of its 25 | contributors may be used to endorse or promote products derived from 26 | this software without specific prior written permission. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | ``` 40 | 41 | 42 | * [fpdf - Kurt Jung](https://github.com/jung-kurt/gofpdf), MIT license. 43 | 44 | - Used for TrueType (TTF) font file parsing (unidoc/pdf/model/fonts/ttfparser.go). 45 | ``` 46 | MIT License 47 | 48 | Copyright (c) 2017 Kurt Jung and contributors acknowledged in the documentation 49 | 50 | Permission is hereby granted, free of charge, to any person obtaining a copy 51 | of this software and associated documentation files (the "Software"), to deal 52 | in the Software without restriction, including without limitation the rights 53 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 54 | copies of the Software, and to permit persons to whom the Software is 55 | furnished to do so, subject to the following conditions: 56 | 57 | The above copyright notice and this permission notice shall be included in all 58 | copies or substantial portions of the Software. 59 | 60 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 61 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 62 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 63 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 64 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 65 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 66 | SOFTWARE. 67 | ``` 68 | 69 | * [Adobe Font Metrics PDF Core 14 fonts](http://www.adobe.com/devnet/font.html), with the following license: 70 | ``` 71 | This file and the 14 PostScript(R) AFM files it accompanies may be used, 72 | copied, and distributed for any purpose and without charge, with or without 73 | modification, provided that all copyright notices are retained; that the 74 | AFM files are not distributed without this file; that all modifications 75 | to this file or any of the AFM files are prominently noted in the modified 76 | file(s); and that this paragraph is not modified. Adobe Systems has no 77 | responsibility or obligation to support the use of the AFM files. 78 | ``` 79 | 80 | - Used for support of the 14 core fonts (see unidoc/pdf/model/fonts/afms). 81 | 82 | * [Adobe Glyph List](https://github.com/adobe-type-tools/agl-aglfn), BSD-3 license. 83 | - Used for glyph and textencoding support (see unidoc/pdf/model/textencoding/glyphlist). 84 | 85 | ``` 86 | Redistribution and use in source and binary forms, with or without 87 | modification, are permitted provided that the following conditions are 88 | met: 89 | 90 | Redistributions of source code must retain the above copyright notice, 91 | this list of conditions and the following disclaimer. 92 | 93 | Redistributions in binary form must reproduce the above copyright 94 | notice, this list of conditions and the following disclaimer in the 95 | documentation and/or other materials provided with the distribution. 96 | 97 | Neither the name of Adobe Systems Incorporated nor the names of its 98 | contributors may be used to endorse or promote products derived from 99 | this software without specific prior written permission. 100 | 101 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 102 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 103 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 104 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 105 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 106 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 107 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 108 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 109 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 110 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 111 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 112 | ``` 113 | 114 | * [Apache Java PDFBox JBIG2 Decoder](https://github.com/apache/pdfbox-jbig2), Apache License 2.0. 115 | In order to achieve full support for the JBIG2 Decoder, it was necessary to implement all possible decoding 116 | combinations defined in the JBIG2 standard, aka ITU T.88 and ISO/IEC 14492. 117 | With a lack of Golang JBIG2 Open Source package, we’ve decided that it would be best to base our own implementation 118 | on some solid and reliable library. 119 | The Apache PDFBox JBIG2 library fulfilled all our requirements. It has a really good quality of the code along with 120 | the detailed comments on each function and class. It also implemented MMR, Huffman tables and arithmetic 121 | decompressors along with all JBIG2 segments. 122 | 123 | * [AGL JBIG2 Encoder](https://github.com/agl/jbig2enc), Apache License 2.0. 124 | The complexity and lack of comprehensive documentation for the JBIG2 encoding process, lead us to look at the 125 | AGL JBIG2 Encoder library. At the moment of implementing our encoder it was the only Open Source JBIG2 encoder. 126 | It’s a C++ based library that implements both lossless and lossy encoding methods, where most of the image 127 | operations are done using DanBloomberg Leptonica library. 128 | 129 | The core encoding processes in the UniPDF JBIG2 Encoder were based on that well documented and solid library 130 | 131 | 132 | * [DanBloomberg Leptonica](https://github.com/DanBloomberg/leptonica), The 2-Clause BSD License, 133 | DanBloomberg Leptonica is an amazing C/C++ Open Source library. It provides raster operations, binary expansion and 134 | reduction, JBIG2 component creators, correlation scoring and a lot more perfectly commented image operation functions. 135 | That library was used as a very solid base for our image operation algorithms used by the JBIG2 Encoder. 136 | 137 | * [sRGB2014 - Color Profile](http://www.color.org/srgbprofiles.xalter), Copyright International Color Consortium, 2015 138 | This profile is made available by the International Color Consortium, and may be copied, 139 | distributed, embedded, made, used, and sold without restriction. Altered versions of this 140 | profile shall have the original identification and copyright information removed and 141 | shall not be misrepresented as the original profile. 142 | 143 | * [sRGB v4 ICC preference - Color Profile](http://www.color.org/srgbprofiles.xalter), Copyright 2007 International Color Consortium 144 | This profile is made available by the International Color Consortium, and may be copied, 145 | distributed, embedded, made, used, and sold without restriction. Altered versions of this 146 | profile shall have the original identification and copyright information removed and 147 | shall not be misrepresented as the original profile. 148 | 149 | * [ISO Coated v2 Grey1c bas - Color Profile](https://www.colormanagement.org/en/isoprofile2009.html#ISOcoated_v2_grey1c_bas), 150 | Copyright (c) 2007, basICColor GmbH 151 | 152 | This software is provided 'as-is', without any express or implied 153 | warranty. In no event will the authors be held liable for any damages 154 | arising from the use of this software. 155 | 156 | Permission is granted to anyone to use this software for any purpose, 157 | including commercial applications, and to alter it and redistribute it 158 | freely, subject to the following restrictions: 159 | 160 | 1. The origin of this software must not be misrepresented; you must 161 | not 162 | claim that you wrote the original software. If you use this software 163 | in a product, an acknowledgment in the product documentation would be 164 | appreciated but is not required. 165 | 166 | 2. Altered source versions must be plainly marked as such, and must 167 | not be 168 | misrepresented as being the original software. 169 | 170 | 3. This notice may not be removed or altered from any source 171 | distribution. 172 | 173 | * [ISO Coated v2 300 bas - Color Profile](https://www.colormanagement.org/en/isoprofile2009.html#ISOcoated_v2_300_bas), 174 | Copyright (c) 2007-2010, basICColor GmbH 175 | 176 | This software is provided 'as-is', without any express or implied 177 | warranty. In no event will the authors be held liable for any damages 178 | arising from the use of this software. 179 | 180 | Permission is granted to anyone to use this software for any purpose, 181 | including commercial applications, and to alter it and redistribute it 182 | freely, subject to the following restrictions: 183 | 184 | 1. The origin of this software must not be misrepresented; you must 185 | not 186 | claim that you wrote the original software. If you use this software 187 | in a product, an acknowledgment in the product documentation would be 188 | appreciated but is not required. 189 | 190 | 2. Altered source versions must be plainly marked as such, and must 191 | not be 192 | misrepresented as being the original software. 193 | 194 | 3. This notice may not be removed or altered from any source 195 | distribution. 196 | 197 | * [Go-XMP Native SDK](https://github.com/trimmer-io/go-xmp), Copyright 2017 Alexander Eichhorn 198 | 199 | Licensed under the Apache License, Version 2.0 (the "License"); 200 | you may not use this file except in compliance with the License. 201 | You may obtain a copy of the License at 202 | http://www.apache.org/licenses/LICENSE-2.0 203 | 204 | The native Go-XMP SDK was used as a core of the XMP utilities in the package 205 | `github.com/unidoc/unipdf/model/xmputil`. 206 | 207 | * [CCITTFax Decoder](https://github.com/haraldk/TwelveMonkeys/blob/master/imageio/imageio-tiff/src/main/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxDecoderStream.java), Copyright (c) 2008-2020, Harald Kuhr 208 | All rights reserved. 209 | 210 | Redistribution and use in source and binary forms, with or without 211 | modification, are permitted provided that the following conditions are met: 212 | 213 | o Redistributions of source code must retain the above copyright notice, this 214 | list of conditions and the following disclaimer. 215 | 216 | o Redistributions in binary form must reproduce the above copyright notice, 217 | this list of conditions and the following disclaimer in the documentation 218 | and/or other materials provided with the distribution. 219 | 220 | o Neither the name of the copyright holder nor the names of its 221 | contributors may be used to endorse or promote products derived from 222 | this software without specific prior written permission. 223 | 224 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 225 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 226 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 227 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 228 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 229 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 230 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 231 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 232 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 233 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 234 | 235 | UniPDF architectural concept of ccittfax decoder was based on the Java implementation defined in the https://github.com/haraldk/TwelveMonkeys. 236 | 237 | * [i18n/linebreak](https://github.com/gorilla/i18n), BSD-3 license: 238 | - Used for word line break. 239 | 240 | ``` 241 | Copyright (c) 2013, Gorilla web toolkit 242 | All rights reserved. 243 | 244 | Redistribution and use in source and binary forms, with or without modification, 245 | are permitted provided that the following conditions are met: 246 | 247 | Redistributions of source code must retain the above copyright notice, this 248 | list of conditions and the following disclaimer. 249 | 250 | Redistributions in binary form must reproduce the above copyright notice, this 251 | list of conditions and the following disclaimer in the documentation and/or 252 | other materials provided with the distribution. 253 | 254 | Neither the name of the {organization} nor the names of its 255 | contributors may be used to endorse or promote products derived from 256 | this software without specific prior written permission. 257 | 258 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 259 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 260 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 261 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 262 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 263 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 264 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 265 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 266 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 267 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 268 | ``` 269 | 270 | * [Bidi implementation of pdf.js](https://github.com/mozilla/pdf.js/blob/master/src/core/bidi.js), Apache License, Version 2.0: 271 | 272 | - Used to process Bidirectional text extraction. 273 | ``` 274 | 275 | Copyright 2012 Mozilla Foundation 276 | 277 | Licensed under the Apache License, Version 2.0 (the "License"); 278 | you may not use this file except in compliance with the License. 279 | You may obtain a copy of the License at 280 | 281 | http://www.apache.org/licenses/LICENSE-2.0 282 | 283 | Unless required by applicable law or agreed to in writing, software 284 | distributed under the License is distributed on an "AS IS" BASIS, 285 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 286 | See the License for the specific language governing permissions and 287 | limitations under the License. 288 | 289 | ``` -------------------------------------------------------------------------------- /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 | # UniPDF - PDF for Go 2 | 3 | [UniDoc](http://unidoc.io) UniPDF is a PDF library for Go (golang) with capabilities for 4 | creating and reading, processing PDF files. The library is written and supported by 5 | [FoxyUtils.com](https://foxyutils.com), where the library is used to power many of its services. 6 | 7 | [![GitHub (pre-)release](https://img.shields.io/github/release/unidoc/unipdf/all.svg)](https://github.com/unidoc/unipdf/releases) 8 | [![License: UniDoc EULA](https://img.shields.io/badge/license-UniDoc%20EULA-blue)](https://unidoc.io/eula/) 9 | [![ApiDocs](https://img.shields.io/badge/godoc-reference-blue.svg)](https://apidocs.unidoc.io/unipdf/latest/) 10 | 11 | ## Features 12 | 13 | - [Create PDF reports](https://github.com/unidoc/unipdf-examples/blob/master/report/pdf_report.go). Example output: [unidoc-report.pdf](https://github.com/unidoc/unipdf-examples/blob/master/report/unidoc-report.pdf). 14 | - [Table PDF reports](https://github.com/unidoc/unipdf-examples/blob/master/report/pdf_tables.go). Example output: [unipdf-tables.pdf](https://github.com/unidoc/unipdf-examples/blob/master/report/unipdf-tables.pdf). 15 | - [Invoice creation](https://unidoc.io/news/simple-invoices) 16 | - [Styled paragraphs](https://github.com/unidoc/unipdf-examples/blob/master/text/pdf_formatted_text.go) 17 | - [Merge PDF pages](https://github.com/unidoc/unipdf-examples/blob/master/pages/pdf_merge.go) 18 | - [Split PDF pages](https://github.com/unidoc/unipdf-examples/blob/master/pages/pdf_split.go) and change page order 19 | - [Rotate pages](https://github.com/unidoc/unipdf-examples/blob/master/pages/pdf_rotate.go) 20 | - [Extract text from PDF files](https://github.com/unidoc/unipdf-examples/blob/master/extract/pdf_extract_text.go) 21 | - [Text extraction support with size, position and formatting info](https://github.com/unidoc/unipdf-examples/blob/master/text/pdf_text_locations.go) 22 | - [PDF to CSV](https://github.com/unidoc/unipdf-examples/blob/master/text/pdf_to_csv.go) illustrates extracting tabular data from PDF. 23 | - [Extract images](https://github.com/unidoc/unipdf-examples/blob/master/extract/pdf_extract_images.go) with coordinates 24 | - [Images to PDF](https://github.com/unidoc/unipdf-examples/blob/master/image/pdf_images_to_pdf.go) 25 | - [Add images to pages](https://github.com/unidoc/unipdf-examples/blob/master/image/pdf_add_image_to_page.go) 26 | - [Compress and optimize PDF](https://github.com/unidoc/unipdf-examples/blob/master/compress/pdf_optimize.go) 27 | - [Watermark PDF files](https://github.com/unidoc/unipdf-examples/blob/master/image/pdf_watermark_image.go) 28 | - Advanced page manipulation: [Put 4 pages on 1](https://github.com/unidoc/unipdf-examples/blob/master/pages/pdf_4up.go) 29 | - Load PDF templates and modify 30 | - [Form creation](https://github.com/unidoc/unipdf-examples/blob/master/forms/pdf_form_add.go) 31 | - [Fill and flatten forms](https://github.com/unidoc/unipdf-examples/blob/master/forms/pdf_form_flatten.go) 32 | - [Fill out forms](https://github.com/unidoc/unipdf-examples/blob/master/forms/pdf_form_fill_json.go) and [FDF merging](https://github.com/unidoc/unipdf-examples/blob/master/forms/pdf_form_fill_fdf_merge.go) 33 | - [Unlock PDF files / remove password](https://github.com/unidoc/unipdf-examples/blob/master/security/pdf_unlock.go) 34 | - [Protect PDF files with a password](https://github.com/unidoc/unipdf-examples/blob/master/security/pdf_protect.go) 35 | - [Digital signing validation and signing](https://github.com/unidoc/unipdf-examples/tree/master/signatures) 36 | - CCITTFaxDecode decoding and encoding support 37 | - JBIG2 decoding support 38 | 39 | Multiple examples are provided in our example repository https://github.com/unidoc/unipdf-examples. 40 | 41 | Contact us if you need any specific examples. 42 | 43 | ## Installation 44 | With modules: 45 | ~~~ 46 | go get github.com/unidoc/unipdf/v4 47 | ~~~ 48 | 49 | ## License key 50 | This software package (unipdf) is a commercial product and requires a license code to operate. 51 | 52 | To Get a Metered License API Key in for free in the Free Tier, sign up on https://cloud.unidoc.io 53 | 54 | 55 | ## How can I convince myself and my boss to buy unipdf rather using a free alternative? 56 | 57 | The choice is yours. There are multiple respectable efforts out there that can do many useful things. 58 | 59 | In UniDoc, we work hard to provide production quality builds taking every detail into consideration and providing excellent support to our customers. See our [testimonials](https://unidoc.io) for example. 60 | 61 | Security. We take security very seriously and we restrict access to github.com/unidoc/unipdf repository with protected branches and only the founders have access and every commit is reviewed prior to being accepted. 62 | 63 | The profits are invested back into making unipdf better. We want to make the best possible product and in order to do that we need the best people to contribute. A large fraction of the profits made goes back into developing unipdf. That way we have been able to get many excellent people to work and contribute to unipdf that would not be able to contribute their work for free. 64 | 65 | 66 | ## Contributing 67 | 68 | If you are interested in contributing, please contact us. 69 | 70 | ## Go Version Compatibility 71 | 72 | Officially we support three latest Go versions, but internally we would test the build with up to five latest Go versions in our CI runner. 73 | 74 | ## Support and consulting 75 | 76 | Please email us at support@unidoc.io for any queries. 77 | 78 | If you have any specific tasks that need to be done, we offer consulting in certain cases. 79 | Please contact us with a brief summary of what you need and we will get back to you with a quote, if appropriate. 80 | 81 | ## License agreement 82 | 83 | The use of this software package is governed by the end-user license agreement 84 | (EULA) available at: https://unidoc.io/eula/ 85 | -------------------------------------------------------------------------------- /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 (_c "fmt";_gf "io";_a "os";_g "path/filepath";_f "runtime";_cg "time";);const (LogLevelTrace LogLevel =5;LogLevelDebug LogLevel =4;LogLevelInfo LogLevel =3;LogLevelNotice LogLevel =2;LogLevelWarning LogLevel =1;LogLevelError LogLevel =0; 14 | ); 15 | 16 | // IsLogLevel returns true from dummy logger. 17 | func (DummyLogger )IsLogLevel (level LogLevel )bool {return true };func (_bg WriterLogger )logToWriter (_ga _gf .Writer ,_gec string ,_fgd string ,_bec ...interface{}){_gbg (_ga ,_gec ,_fgd ,_bec );}; 18 | 19 | // Logger is the interface used for logging in the unipdf package. 20 | type Logger interface{Error (_d string ,_fg ...interface{});Warning (_e string ,_de ...interface{});Notice (_ff string ,_gb ...interface{});Info (_fc string ,_aa ...interface{});Debug (_eb string ,_fa ...interface{});Trace (_ad string ,_bb ...interface{}); 21 | IsLogLevel (_dc LogLevel )bool ;}; 22 | 23 | // Info logs info message. 24 | func (_gg ConsoleLogger )Info (format string ,args ...interface{}){if _gg .LogLevel >=LogLevelInfo {_dd :="\u005bI\u004e\u0046\u004f\u005d\u0020";_gg .output (_a .Stdout ,_dd ,format ,args ...);};}; 25 | 26 | // Warning logs warning message. 27 | func (_dcg WriterLogger )Warning (format string ,args ...interface{}){if _dcg .LogLevel >=LogLevelWarning {_be :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_dcg .logToWriter (_dcg .Output ,_be ,format ,args ...);};}; 28 | 29 | // IsLogLevel returns true if log level is greater or equal than `level`. 30 | // Can be used to avoid resource intensive calls to loggers. 31 | func (_bf ConsoleLogger )IsLogLevel (level LogLevel )bool {return _bf .LogLevel >=level };const _ab =2025; 32 | 33 | // DummyLogger does nothing. 34 | type DummyLogger struct{}; 35 | 36 | // WriterLogger is the logger that writes data to the Output writer 37 | type WriterLogger struct{LogLevel LogLevel ;Output _gf .Writer ;}; 38 | 39 | // Warning logs warning message. 40 | func (_ba ConsoleLogger )Warning (format string ,args ...interface{}){if _ba .LogLevel >=LogLevelWarning {_faa :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_ba .output (_a .Stdout ,_faa ,format ,args ...);};};const _ef =15; 41 | 42 | // Error logs error message. 43 | func (_fce WriterLogger )Error (format string ,args ...interface{}){if _fce .LogLevel >=LogLevelError {_gdc :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_fce .logToWriter (_fce .Output ,_gdc ,format ,args ...);};}; 44 | 45 | // Trace logs trace message. 46 | func (_gbf WriterLogger )Trace (format string ,args ...interface{}){if _gbf .LogLevel >=LogLevelTrace {_fgc :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_gbf .logToWriter (_gbf .Output ,_fgc ,format ,args ...);};};var Log Logger =DummyLogger {}; 47 | 48 | 49 | // UtcTimeFormat returns a formatted string describing a UTC timestamp. 50 | func UtcTimeFormat (t _cg .Time )string {return t .Format (_fbf )+"\u0020\u0055\u0054\u0043"}; 51 | 52 | // Warning does nothing for dummy logger. 53 | func (DummyLogger )Warning (format string ,args ...interface{}){};const _fbf ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034"; 54 | 55 | // NewConsoleLogger creates new console logger. 56 | func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }}; 57 | 58 | // Info does nothing for dummy logger. 59 | func (DummyLogger )Info (format string ,args ...interface{}){};func (_bab ConsoleLogger )output (_fcg _gf .Writer ,_gd string ,_gee string ,_eg ...interface{}){_gbg (_fcg ,_gd ,_gee ,_eg ...);}; 60 | 61 | // LogLevel is the verbosity level for logging. 62 | type LogLevel int ; 63 | 64 | // IsLogLevel returns true if log level is greater or equal than `level`. 65 | // Can be used to avoid resource intensive calls to loggers. 66 | func (_cd WriterLogger )IsLogLevel (level LogLevel )bool {return _cd .LogLevel >=level }; 67 | 68 | // Info logs info message. 69 | func (_cf WriterLogger )Info (format string ,args ...interface{}){if _cf .LogLevel >=LogLevelInfo {_fb :="\u005bI\u004e\u0046\u004f\u005d\u0020";_cf .logToWriter (_cf .Output ,_fb ,format ,args ...);};}; 70 | 71 | // Error logs error message. 72 | func (_ge ConsoleLogger )Error (format string ,args ...interface{}){if _ge .LogLevel >=LogLevelError {_cc :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_ge .output (_a .Stdout ,_cc ,format ,args ...);};}; 73 | 74 | // Debug logs debug message. 75 | func (_gff WriterLogger )Debug (format string ,args ...interface{}){if _gff .LogLevel >=LogLevelDebug {_ffa :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_gff .logToWriter (_gff .Output ,_ffa ,format ,args ...);};};const _bbg =5; 76 | 77 | // Debug logs debug message. 78 | func (_gbe ConsoleLogger )Debug (format string ,args ...interface{}){if _gbe .LogLevel >=LogLevelDebug {_ebe :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_gbe .output (_a .Stdout ,_ebe ,format ,args ...);};}; 79 | 80 | // Debug does nothing for dummy logger. 81 | func (DummyLogger )Debug (format string ,args ...interface{}){}; 82 | 83 | // Notice logs notice message. 84 | func (_fe ConsoleLogger )Notice (format string ,args ...interface{}){if _fe .LogLevel >=LogLevelNotice {_fed :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_fe .output (_a .Stdout ,_fed ,format ,args ...);};};const _ce =30; 85 | 86 | // ConsoleLogger is a logger that writes logs to the 'os.Stdout' 87 | type ConsoleLogger struct{LogLevel LogLevel ;};var ReleasedAt =_cg .Date (_ab ,_bbg ,_db ,_ef ,_ce ,0,0,_cg .UTC ); 88 | 89 | // Notice does nothing for dummy logger. 90 | func (DummyLogger )Notice (format string ,args ...interface{}){}; 91 | 92 | // SetLogger sets 'logger' to be used by the unidoc unipdf library. 93 | func SetLogger (logger Logger ){Log =logger }; 94 | 95 | // NewWriterLogger creates new 'writer' logger. 96 | func NewWriterLogger (logLevel LogLevel ,writer _gf .Writer )*WriterLogger {_cgff :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_cgff ;};const Version ="\u0034\u002e\u0030.\u0030";func _gbg (_bc _gf .Writer ,_bdbb string ,_ed string ,_ac ...interface{}){_ ,_ec ,_eca ,_ged :=_f .Caller (3); 97 | if !_ged {_ec ="\u003f\u003f\u003f";_eca =0;}else {_ec =_g .Base (_ec );};_ded :=_c .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_bdbb ,_ec ,_eca )+_ed +"\u000a";_c .Fprintf (_bc ,_ded ,_ac ...);}; 98 | 99 | // Trace logs trace message. 100 | func (_cgf ConsoleLogger )Trace (format string ,args ...interface{}){if _cgf .LogLevel >=LogLevelTrace {_bd :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_cgf .output (_a .Stdout ,_bd ,format ,args ...);};}; 101 | 102 | // Error does nothing for dummy logger. 103 | func (DummyLogger )Error (format string ,args ...interface{}){};const _db =9; 104 | 105 | // Trace does nothing for dummy logger. 106 | func (DummyLogger )Trace (format string ,args ...interface{}){}; 107 | 108 | // Notice logs notice message. 109 | func (_bdb WriterLogger )Notice (format string ,args ...interface{}){if _bdb .LogLevel >=LogLevelNotice {_dee :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_bdb .logToWriter (_bdb .Output ,_dee ,format ,args ...);};}; -------------------------------------------------------------------------------- /common/license/license.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 license helps manage commercial licenses and check if they are valid for the version of unipdf used. 13 | package license ;import _ed "github.com/unidoc/unipdf/v4/internal/license"; 14 | 15 | // LicenseKey represents a loaded license key. 16 | type LicenseKey =_ed .LicenseKey ; 17 | 18 | // SetLicenseKey sets and validates the license key. 19 | func SetLicenseKey (content string ,customerName string )error {return _ed .SetLicenseKey (content ,customerName );}; 20 | 21 | // GetMeteredState checks the currently used metered document usage status, 22 | // documents used and credits available. 23 | func GetMeteredState ()(_ed .MeteredStatus ,error ){return _ed .GetMeteredState ()};const (LicenseTierUnlicensed =_ed .LicenseTierUnlicensed ;LicenseTierCommunity =_ed .LicenseTierCommunity ;LicenseTierIndividual =_ed .LicenseTierIndividual ;LicenseTierBusiness =_ed .LicenseTierBusiness ; 24 | );func SetMeteredKeyUsageLogVerboseMode (val bool ){_ed .SetMeteredKeyUsageLogVerboseMode (val )}; 25 | 26 | // GetLicenseKey returns the currently loaded license key. 27 | func GetLicenseKey ()*LicenseKey {return _ed .GetLicenseKey ()}; 28 | 29 | // SetMeteredKey sets the metered API key required for SaaS operation. 30 | // Document usage is reported periodically for the product to function correctly. 31 | func SetMeteredKey (apiKey string )error {return _ed .SetMeteredKey (apiKey )}; 32 | 33 | // SetMeteredKeyPersistentCache sets the metered License API Key persistent cache. 34 | // Default value 'true', set to `false` will report the usage immediately to license server, 35 | // this can be used when there's no access to persistent data storage. 36 | func SetMeteredKeyPersistentCache (val bool ){_ed .SetMeteredKeyPersistentCache (val )}; 37 | 38 | // MakeUnlicensedKey returns a default key. 39 | func MakeUnlicensedKey ()*LicenseKey {return _ed .MakeUnlicensedKey ()}; -------------------------------------------------------------------------------- /core/security/crypt/crypt.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 crypt ;import (_fb "crypto/aes";_d "crypto/cipher";_b "crypto/md5";_g "crypto/rand";_a "crypto/rc4";_cc "fmt";_af "github.com/unidoc/unipdf/v4/common";_ae "github.com/unidoc/unipdf/v4/core/security";_f "io";);func init (){_bb ("\u0041\u0045\u0053V\u0032",_e )}; 13 | 14 | 15 | // HandlerVersion implements Filter interface. 16 | func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;}; 17 | 18 | // KeyLength implements Filter interface. 19 | func (filterAESV2 )KeyLength ()int {return 128/8}; 20 | 21 | // HandlerVersion implements Filter interface. 22 | func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_cfe ,_dag :=_fb .NewCipher (okey );if _dag !=nil {return nil ,_dag ;};if len (buf )< 16{_af .Log .Debug ("\u0045R\u0052\u004f\u0052\u0020\u0041\u0045\u0053\u0020\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0062\u0075\u0066\u0020\u0025\u0073",buf ); 23 | return buf ,_cc .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf ));};_be :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_af .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_be ),_be ); 24 | _af .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,_cc .Errorf ("\u0041\u0045\u0053\u0020\u0062\u0075\u0066\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069p\u006c\u0065\u0020\u006f\u0066 \u0031\u0036 \u0028\u0025\u0064\u0029",len (buf )); 25 | };_bec :=_d .NewCBCDecrypter (_cfe ,_be );_af .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_af .Log .Trace ("\u0063\u0068\u006f\u0070\u0020\u0041\u0045\u0053\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u0020\u0028\u0025\u0064\u0029\u003a \u0025\u0020\u0078",len (buf ),buf ); 26 | _bec .CryptBlocks (buf ,buf );_af .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_af .Log .Trace ("\u0045\u006d\u0070\u0074\u0079\u0020b\u0075\u0066\u002c\u0020\u0072\u0065\u0074\u0075\u0072\u006e\u0069\u006e\u0067 \u0065\u006d\u0070\u0074\u0079\u0020\u0073t\u0072\u0069\u006e\u0067"); 27 | return buf ,nil ;};_cee :=int (buf [len (buf )-1]);if _cee > len (buf ){_af .Log .Debug ("\u0049\u006c\u006c\u0065g\u0061\u006c\u0020\u0070\u0061\u0064\u0020\u006c\u0065\u006eg\u0074h\u0020\u0028\u0025\u0064\u0020\u003e\u0020%\u0064\u0029",_cee ,len (buf )); 28 | return buf ,_cc .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_cee ];return buf ,nil ;}; 29 | 30 | // PDFVersion implements Filter interface. 31 | func (_bee filterV2 )PDFVersion ()[2]int {return [2]int {}}; 32 | 33 | // Name implements Filter interface. 34 | func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};func _e (_bg FilterDict )(Filter ,error ){if _bg .Length ==128{_af .Log .Debug ("\u0041\u0045S\u0056\u0032\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_bg .Length ); 35 | _bg .Length /=8;};if _bg .Length !=0&&_bg .Length !=16{return nil ,_cc .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0032\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_bg .Length ); 36 | };return filterAESV2 {},nil ;};type filterAESV2 struct{filterAES }; 37 | 38 | // Name implements Filter interface. 39 | func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};func init (){_bb ("\u0041\u0045\u0053V\u0033",_ed )};var _ Filter =filterAESV2 {};type filterAESV3 struct{filterAES }; 40 | 41 | // KeyLength implements Filter interface. 42 | func (filterAESV3 )KeyLength ()int {return 256/8}; 43 | 44 | // Name implements Filter interface. 45 | func (filterV2 )Name ()string {return "\u0056\u0032"}; 46 | 47 | // PDFVersion implements Filter interface. 48 | func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}}; 49 | 50 | // NewIdentity creates an identity filter that bypasses all data without changes. 51 | func NewIdentity ()Filter {return filterIdentity {}}; 52 | 53 | // PDFVersion implements Filter interface. 54 | func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}}; 55 | 56 | // NewFilter creates CryptFilter from a corresponding dictionary. 57 | func NewFilter (d FilterDict )(Filter ,error ){_ggf ,_fg :=_fba (d .CFM );if _fg !=nil {return nil ,_fg ;};_cb ,_fg :=_ggf (d );if _fg !=nil {return nil ,_fg ;};return _cb ,nil ;};var (_ded =make (map[string ]filterFunc );); 58 | 59 | // MakeKey implements Filter interface. 60 | func (_bf filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _gc (objNum ,genNum ,ekey ,false );}; 61 | 62 | // KeyLength implements Filter interface. 63 | func (_ga filterV2 )KeyLength ()int {return _ga ._ccg }; 64 | 65 | // EncryptBytes implements Filter interface. 66 | func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_cece ,_dc :=_a .NewCipher (okey );if _dc !=nil {return nil ,_dc ;};_af .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf ); 67 | _cece .XORKeyStream (buf ,buf );_af .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func init (){_bb ("\u0056\u0032",_ebb )};func _ebb (_ca FilterDict )(Filter ,error ){if _ca .Length %8!=0{return nil ,_cc .Errorf ("\u0063\u0072\u0079p\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020o\u0066\u0020\u0038\u0020\u0028\u0025\u0064\u0029",_ca .Length ); 68 | };if _ca .Length < 5||_ca .Length > 16{if _ca .Length ==40||_ca .Length ==64||_ca .Length ==128{_af .Log .Debug ("\u0053\u0054\u0041\u004e\u0044AR\u0044\u0020V\u0049\u004f\u004c\u0041\u0054\u0049\u004f\u004e\u003a\u0020\u0043\u0072\u0079\u0070\u0074\u0020\u004c\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072s\u0020\u0074\u006f \u0062\u0065\u0020\u0069\u006e\u0020\u0062\u0069\u0074\u0073\u0020\u0072\u0061t\u0068\u0065\u0072\u0020\u0074h\u0061\u006e\u0020\u0062\u0079\u0074\u0065\u0073\u0020-\u0020\u0061s\u0073u\u006d\u0069\u006e\u0067\u0020\u0062\u0069t\u0073\u0020\u0028\u0025\u0064\u0029",_ca .Length ); 69 | _ca .Length /=8;}else {return nil ,_cc .Errorf ("\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u006e\u006f\u0074\u0020\u0069\u006e \u0072\u0061\u006e\u0067\u0065\u0020\u0034\u0030\u0020\u002d\u00201\u0032\u0038\u0020\u0062\u0069\u0074\u0020\u0028\u0025\u0064\u0029",_ca .Length ); 70 | };};return filterV2 {_ccg :_ca .Length },nil ;}; 71 | 72 | // NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2). 73 | func NewFilterAESV2 ()Filter {_aa ,_gg :=_e (FilterDict {});if _gg !=nil {_af .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_gg ); 74 | return filterAESV2 {};};return _aa ;};func _ed (_de FilterDict )(Filter ,error ){if _de .Length ==256{_af .Log .Debug ("\u0041\u0045S\u0056\u0033\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_de .Length ); 75 | _de .Length /=8;};if _de .Length !=0&&_de .Length !=32{return nil ,_cc .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0033\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_de .Length ); 76 | };return filterAESV3 {},nil ;};type filterAES struct{};func _bb (_agb string ,_cae filterFunc ){if _ ,_ee :=_ded [_agb ];_ee {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_ded [_agb ]=_cae ;}; 77 | 78 | // FilterDict represents information from a CryptFilter dictionary. 79 | type FilterDict struct{CFM string ;AuthEvent _ae .AuthEvent ;Length int ;}; 80 | 81 | // DecryptBytes implements Filter interface. 82 | func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_acgf ,_dg :=_a .NewCipher (okey );if _dg !=nil {return nil ,_dg ;};_af .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf ); 83 | _acgf .XORKeyStream (buf ,buf );_af .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;}; 84 | 85 | // MakeKey implements Filter interface. 86 | func (filterAESV3 )MakeKey (_ ,_ uint32 ,ekey []byte )([]byte ,error ){return ekey ,nil };func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_fa ,_ce :=_fb .NewCipher (okey );if _ce !=nil {return nil ,_ce ;};_af .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf ); 87 | const _fc =_fb .BlockSize ;_ec :=_fc -len (buf )%_fc ;for _dfa :=0;_dfa < _ec ;_dfa ++{buf =append (buf ,byte (_ec ));};_af .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_bc :=make ([]byte ,_fc +len (buf )); 88 | _cf :=_bc [:_fc ];if _ ,_ag :=_f .ReadFull (_g .Reader ,_cf );_ag !=nil {return nil ,_ag ;};_eb :=_d .NewCBCEncrypter (_fa ,_cf );_eb .CryptBlocks (_bc [_fc :],buf );buf =_bc ;_af .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf ); 89 | return buf ,nil ;};func _fba (_ede string )(filterFunc ,error ){_cg :=_ded [_ede ];if _cg ==nil {return nil ,_cc .Errorf ("\u0075\u006e\u0073\u0075p\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u0072\u0079p\u0074 \u0066\u0069\u006c\u0074\u0065\u0072\u003a \u0025\u0071",_ede ); 90 | };return _cg ,nil ;};func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil }; 91 | func _gc (_fbe ,_ggg uint32 ,_dec []byte ,_ad bool )([]byte ,error ){_def :=make ([]byte ,len (_dec )+5);copy (_def ,_dec );for _cab :=0;_cab < 3;_cab ++{_cec :=byte ((_fbe >>uint32 (8*_cab ))&0xff);_def [_cab +len (_dec )]=_cec ;};for _deg :=0;_deg < 2; 92 | _deg ++{_ef :=byte ((_ggg >>uint32 (8*_deg ))&0xff);_def [_deg +len (_dec )+3]=_ef ;};if _ad {_def =append (_def ,0x73);_def =append (_def ,0x41);_def =append (_def ,0x6C);_def =append (_def ,0x54);};_caf :=_b .New ();_caf .Write (_def );_aae :=_caf .Sum (nil ); 93 | if len (_dec )+5< 16{return _aae [0:len (_dec )+5],nil ;};return _aae ,nil ;}; 94 | 95 | // NewFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3). 96 | func NewFilterAESV3 ()Filter {_df ,_da :=_ed (FilterDict {});if _da !=nil {_af .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0033\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_da ); 97 | return filterAESV3 {};};return _df ;}; 98 | 99 | // NewFilterV2 creates a RC4-based filter with a specified key length (in bytes). 100 | func NewFilterV2 (length int )Filter {_bd ,_db :=_ebb (FilterDict {Length :length });if _db !=nil {_af .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020R\u0043\u0034\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_db ); 101 | return filterV2 {_ccg :length };};return _bd ;}; 102 | 103 | // MakeKey implements Filter interface. 104 | func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _gc (objNum ,genNum ,ekey ,true );};func (filterIdentity )HandlerVersion ()(V ,R int ){return ;}; 105 | 106 | // HandlerVersion implements Filter interface. 107 | func (_aba filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};func (filterIdentity )DecryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };type filterV2 struct{_ccg int }; 108 | type filterFunc func (_efa FilterDict )(Filter ,error );type filterIdentity struct{};func (filterIdentity )KeyLength ()int {return 0};var _ Filter =filterV2 {};var _ Filter =filterAESV3 {}; 109 | 110 | // Filter is a common interface for crypt filter methods. 111 | type Filter interface{ 112 | 113 | // Name returns a name of the filter that should be used in CFM field of Encrypt dictionary. 114 | Name ()string ; 115 | 116 | // KeyLength returns a length of the encryption key in bytes. 117 | KeyLength ()int ; 118 | 119 | // PDFVersion reports the minimal version of PDF document that introduced this filter. 120 | PDFVersion ()[2]int ; 121 | 122 | // HandlerVersion reports V and R parameters that should be used for this filter. 123 | HandlerVersion ()(V ,R int ); 124 | 125 | // MakeKey generates a object encryption key based on file encryption key and object numbers. 126 | // Used only for legacy filters - AESV3 doesn't change the key for each object. 127 | MakeKey (_aca ,_dd uint32 ,_cabc []byte )([]byte ,error ); 128 | 129 | // EncryptBytes encrypts a buffer using object encryption key, as returned by MakeKey. 130 | // Implementation may reuse a buffer and encrypt data in-place. 131 | EncryptBytes (_ea []byte ,_ceg []byte )([]byte ,error ); 132 | 133 | // DecryptBytes decrypts a buffer using object encryption key, as returned by MakeKey. 134 | // Implementation may reuse a buffer and decrypt data in-place. 135 | DecryptBytes (_ff []byte ,_eg []byte )([]byte ,error );}; -------------------------------------------------------------------------------- /fjson/fjson.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 fjson provides support for loading PDF form field data from JSON data/files. 13 | package fjson ;import (_c "encoding/json";_cc "github.com/unidoc/unipdf/v4/common";_ag "github.com/unidoc/unipdf/v4/core";_a "github.com/unidoc/unipdf/v4/model";_dc "io";_ca "os";); 14 | 15 | // JSON returns the field data as a string in JSON format. 16 | func (_bcb FieldData )JSON ()(string ,error ){_ecg ,_agg :=_c .MarshalIndent (_bcb ._e ,"","\u0020\u0020\u0020\u0020");return string (_ecg ),_agg ;}; 17 | 18 | // FieldValues implements model.FieldValueProvider interface. 19 | func (_gfg *FieldData )FieldValues ()(map[string ]_ag .PdfObject ,error ){_bbb :=make (map[string ]_ag .PdfObject );for _ ,_ffd :=range _gfg ._e {if len (_ffd .Value )> 0{_bbb [_ffd .Name ]=_ag .MakeString (_ffd .Value );};};return _bbb ,nil ;};type fieldValue struct{Name string `json:"name"`; 20 | Value string `json:"value"`;ImageValue *_a .Image `json:"-"`; 21 | 22 | // Options lists allowed values if present. 23 | Options []string `json:"options,omitempty"`;}; 24 | 25 | // LoadFromJSON loads JSON form data from `r`. 26 | func LoadFromJSON (r _dc .Reader )(*FieldData ,error ){var _g FieldData ;_cd :=_c .NewDecoder (r ).Decode (&_g ._e );if _cd !=nil {return nil ,_cd ;};return &_g ,nil ;}; 27 | 28 | // LoadFromPDFFile loads form field data from a PDF file. 29 | func LoadFromPDFFile (filePath string )(*FieldData ,error ){_agd ,_db :=_ca .Open (filePath );if _db !=nil {return nil ,_db ;};defer _agd .Close ();return LoadFromPDF (_agd );}; 30 | 31 | // LoadFromJSONFile loads form field data from a JSON file. 32 | func LoadFromJSONFile (filePath string )(*FieldData ,error ){_cg ,_ef :=_ca .Open (filePath );if _ef !=nil {return nil ,_ef ;};defer _cg .Close ();return LoadFromJSON (_cg );}; 33 | 34 | // SetImage assign model.Image to a specific field identified by fieldName. 35 | func (_ccd *FieldData )SetImage (fieldName string ,img *_a .Image ,opt []string )error {_feg :=fieldValue {Name :fieldName ,ImageValue :img ,Options :opt };_ccd ._e =append (_ccd ._e ,_feg );return nil ;}; 36 | 37 | // SetImageFromFile assign image file to a specific field identified by fieldName. 38 | func (_ab *FieldData )SetImageFromFile (fieldName string ,imagePath string ,opt []string )error {_edce ,_bfa :=_ca .Open (imagePath );if _bfa !=nil {return _bfa ;};defer _edce .Close ();_gb ,_bfa :=_a .ImageHandling .Read (_edce );if _bfa !=nil {_cc .Log .Error ("\u0045\u0072\u0072or\u0020\u006c\u006f\u0061\u0064\u0069\u006e\u0067\u0020\u0069\u006d\u0061\u0067\u0065\u003a\u0020\u0025\u0073",_bfa ); 39 | return _bfa ;};return _ab .SetImage (fieldName ,_gb ,opt );}; 40 | 41 | // FieldImageValues implements model.FieldImageProvider interface. 42 | func (_df *FieldData )FieldImageValues ()(map[string ]*_a .Image ,error ){_gd :=make (map[string ]*_a .Image );for _ ,_cec :=range _df ._e {if _cec .ImageValue !=nil {_gd [_cec .Name ]=_cec .ImageValue ;};};return _gd ,nil ;}; 43 | 44 | // FieldData represents form field data loaded from JSON file. 45 | type FieldData struct{_e []fieldValue }; 46 | 47 | // LoadFromPDF loads form field data from a PDF. 48 | func LoadFromPDF (rs _dc .ReadSeeker )(*FieldData ,error ){_ea ,_f :=_a .NewPdfReader (rs );if _f !=nil {return nil ,_f ;};if _ea .AcroForm ==nil {return nil ,nil ;};var _cdg []fieldValue ;_eb :=_ea .AcroForm .AllFields ();for _ ,_fg :=range _eb {var _ed []string ; 49 | _b :=make (map[string ]struct{});_da ,_efc :=_fg .FullName ();if _efc !=nil {return nil ,_efc ;};if _bb ,_ff :=_fg .V .(*_ag .PdfObjectString );_ff {_cdg =append (_cdg ,fieldValue {Name :_da ,Value :_bb .Decoded ()});continue ;};var _ec string ;for _ ,_fa :=range _fg .Annotations {_fgg ,_fe :=_ag .GetName (_fa .AS ); 50 | if _fe {_ec =_fgg .String ();};_ac ,_gf :=_ag .GetDict (_fa .AP );if !_gf {continue ;};_af ,_ :=_ag .GetDict (_ac .Get ("\u004e"));for _ ,_gea :=range _af .Keys (){_dd :=_gea .String ();if _ ,_gg :=_b [_dd ];!_gg {_ed =append (_ed ,_dd );_b [_dd ]=struct{}{}; 51 | };};_edc ,_ :=_ag .GetDict (_ac .Get ("\u0044"));for _ ,_bf :=range _edc .Keys (){_de :=_bf .String ();if _ ,_ebc :=_b [_de ];!_ebc {_ed =append (_ed ,_de );_b [_de ]=struct{}{};};};};_gee :=fieldValue {Name :_da ,Value :_ec ,Options :_ed };_cdg =append (_cdg ,_gee ); 52 | };_cdc :=FieldData {_e :_cdg };return &_cdc ,nil ;}; -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/unidoc/unipdf/v4 2 | 3 | go 1.20 4 | 5 | require ( 6 | github.com/adrg/sysfont v0.1.2 7 | github.com/boombuler/barcode v1.0.2 8 | github.com/gabriel-vasile/mimetype v1.4.8 9 | github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46 10 | github.com/stretchr/testify v1.10.0 11 | github.com/trimmer-io/go-xmp v1.0.0 12 | github.com/unidoc/freetype v0.2.3 13 | github.com/unidoc/garabic v0.0.0-20220702200334-8c7cb25baa11 14 | github.com/unidoc/pkcs7 v0.2.0 15 | github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a 16 | github.com/unidoc/unichart v0.4.0 17 | github.com/unidoc/unitype v0.5.1 18 | golang.org/x/crypto v0.33.0 19 | golang.org/x/image v0.24.0 20 | golang.org/x/net v0.35.0 21 | golang.org/x/text v0.22.0 22 | golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da 23 | ) 24 | 25 | require ( 26 | github.com/adrg/strutil v0.3.1 // indirect 27 | github.com/adrg/xdg v0.5.3 // indirect 28 | github.com/davecgh/go-spew v1.1.1 // indirect 29 | github.com/kr/text v0.2.0 // indirect 30 | github.com/pmezard/go-difflib v1.0.0 // indirect 31 | github.com/sirupsen/logrus v1.9.3 // indirect 32 | golang.org/x/sys v0.30.0 // indirect 33 | gopkg.in/yaml.v3 v3.0.1 // indirect 34 | ) 35 | -------------------------------------------------------------------------------- /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/boombuler/barcode v1.0.2 h1:79yrbttoZrLGkL/oOI8hBrUKucwOL0oOjUgEguGMcJ4= 10 | github.com/boombuler/barcode v1.0.2/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= 11 | github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 12 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 13 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 14 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 15 | github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= 16 | github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= 17 | github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46 h1:N+R2A3fGIr5GucoRMu2xpqyQWQlfY31orbofBCdjMz8= 18 | github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46/go.mod h1:2Yoiy15Cf7Q3NFwfaJquh7Mk1uGI09ytcD7CUhn8j7s= 19 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 20 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 21 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 22 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 23 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 24 | github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= 25 | github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 26 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 27 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 28 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 29 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 30 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 31 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 32 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 33 | github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 34 | github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= 35 | github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 36 | github.com/trimmer-io/go-xmp v1.0.0 h1:zY8bolSga5kOjBAaHS6hrdxLgEoYuT875xTy0QDwZWs= 37 | github.com/trimmer-io/go-xmp v1.0.0/go.mod h1:Aaptr9sp1lLv7UnCAdQ+gSHZyY2miYaKmcNVj7HRBwA= 38 | github.com/unidoc/freetype v0.2.3 h1:uPqW+AY0vXN6K2tvtg8dMAtHTEvvHTN52b72XpZU+3I= 39 | github.com/unidoc/freetype v0.2.3/go.mod h1:mJ/Q7JnqEoWtajJVrV6S1InbRv0K/fJerPB5SQs32KI= 40 | github.com/unidoc/garabic v0.0.0-20220702200334-8c7cb25baa11 h1:kExUKrbi429KdVVuAc85z4P+W/Rk4bjGWB5KzZLl/l8= 41 | github.com/unidoc/garabic v0.0.0-20220702200334-8c7cb25baa11/go.mod h1:SX63w9Ww4+Z7E96B01OuG59SleQUb+m+dmapZ8o1Jac= 42 | github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= 43 | github.com/unidoc/pkcs7 v0.2.0 h1:0Y0RJR5Zu7OuD+/l7bODXARn6b8Ev2G4A8lI4rzy9kg= 44 | github.com/unidoc/pkcs7 v0.2.0/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= 45 | github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a h1:RLtvUhe4DsUDl66m7MJ8OqBjq8jpWBXPK6/RKtqeTkc= 46 | github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a/go.mod h1:j+qMWZVpZFTvDey3zxUkSgPJZEX33tDgU/QIA0IzCUw= 47 | github.com/unidoc/unichart v0.4.0 h1:uXk9ZjbqzKb8Lt2Qv2oM9D2ftNRXvezPevgxQhsTQys= 48 | github.com/unidoc/unichart v0.4.0/go.mod h1:9QsE8RbS0fE7ndHNroeCEFkRPqqk47Qsoj6QSAtcwN0= 49 | github.com/unidoc/unitype v0.5.1 h1:UwTX15K6bktwKocWVvLoijIeu4JAVEAIeFqMOjvxqQs= 50 | github.com/unidoc/unitype v0.5.1/go.mod h1:3dxbRL+f1otNqFQIRHho8fxdg3CcUKrqS8w1SXTsqcI= 51 | golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= 52 | golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= 53 | golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= 54 | golang.org/x/image v0.24.0 h1:AN7zRgVsbvmTfNyqIbbOraYL8mSwcKncEj8ofjgzcMQ= 55 | golang.org/x/image v0.24.0/go.mod h1:4b/ITuLfqYq1hqZcjofwctIhi7sZh2WaCjvsBNjjya8= 56 | golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= 57 | golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= 58 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 59 | golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= 60 | golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 61 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 62 | golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= 63 | golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= 64 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 65 | golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da h1:noIWHXmPHxILtqtCOPIhSt0ABwskkZKjD3bXGnZGpNY= 66 | golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= 67 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 68 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= 69 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 70 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 71 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 72 | -------------------------------------------------------------------------------- /internal/endian/endian.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 endian ;import (_f "encoding/binary";_d "unsafe";);var (ByteOrder _f .ByteOrder ;_a bool ;);func init (){const _cf =int (_d .Sizeof (0));_de :=1;_b :=(*[_cf ]byte )(_d .Pointer (&_de ));if _b [0]==0{_a =true ;ByteOrder =_f .BigEndian ;}else {ByteOrder =_f .LittleEndian ; 13 | };};func IsBig ()bool {return _a };func IsLittle ()bool {return !_a }; -------------------------------------------------------------------------------- /internal/integrations/unichart/unichart.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 unichart ;import (_e "bytes";_c "fmt";_gg "github.com/unidoc/unichart/render";_eb "github.com/unidoc/unipdf/v4/common";_a "github.com/unidoc/unipdf/v4/contentstream";_fe "github.com/unidoc/unipdf/v4/contentstream/draw";_eed "github.com/unidoc/unipdf/v4/core"; 13 | _ee "github.com/unidoc/unipdf/v4/model";_f "image/color";_ge "io";_d "math";);func (_adg *Renderer )Text (text string ,x ,y int ){_adg ._gef .Add_q ();_adg .SetFont (_adg ._ebg );_dee ,_agd ,_fgg ,_ :=_dab (_adg ._db );_adg ._gef .Add_rg (_dee ,_agd ,_fgg ); 14 | _adg ._gef .Translate (float64 (x ),float64 (y )).Scale (1,-1);if _aee :=_adg ._gb ;_aee !=0{_adg ._gef .RotateDeg (_aee );};_adg ._gef .Add_BT ().Add_TL (_adg ._b );var (_afe =_adg ._ebg .Encoder ();_dg =_adg .wrapText (text );_cd =len (_dg ););for _ga ,_aff :=range _dg {_adg ._gef .Add_TJ (_eed .MakeStringFromBytes (_afe .Encode (_aff ))); 15 | if _ga !=_cd -1{_adg ._gef .Add_Tstar ();};};_adg ._gef .Add_ET ();_adg ._gef .Add_Q ();};func (_agb *Renderer )Close (){_agb ._gef .Add_h ()};func (_gcd *Renderer )MoveTo (x ,y int ){_gcd ._gef .Add_m (float64 (x ),float64 (y ))};func (_ege *Renderer )ArcTo (cx ,cy int ,rx ,ry ,startAngle ,deltaAngle float64 ){startAngle =_cdbc (2.0*_d .Pi -startAngle ); 16 | deltaAngle =_cdbc (-deltaAngle );_fa ,_bf :=deltaAngle ,1;if _d .Abs (deltaAngle )> 90.0{_bf =int (_d .Ceil (_d .Abs (deltaAngle )/90.0));_fa =deltaAngle /float64 (_bf );};var (_fge =_abd (_fa /2);_bcb =_d .Abs (4.0/3.0*(1.0-_d .Cos (_fge ))/_d .Sin (_fge )); 17 | _gd =float64 (cx );_cg =float64 (cy ););for _cfc :=0;_cfc < _bf ;_cfc ++{_cfa :=_abd (startAngle +float64 (_cfc )*_fa );_eeb :=_abd (startAngle +float64 (_cfc +1)*_fa );_deg :=_d .Cos (_cfa );_feg :=_d .Cos (_eeb );_acc :=_d .Sin (_cfa );_ea :=_d .Sin (_eeb ); 18 | var _fgc []float64 ;if _fa > 0{_fgc =[]float64 {_gd +rx *_deg ,_cg -ry *_acc ,_gd +rx *(_deg -_bcb *_acc ),_cg -ry *(_acc +_bcb *_deg ),_gd +rx *(_feg +_bcb *_ea ),_cg -ry *(_ea -_bcb *_feg ),_gd +rx *_feg ,_cg -ry *_ea };}else {_fgc =[]float64 {_gd +rx *_deg ,_cg -ry *_acc ,_gd +rx *(_deg +_bcb *_acc ),_cg -ry *(_acc -_bcb *_deg ),_gd +rx *(_feg -_bcb *_ea ),_cg -ry *(_ea +_bcb *_feg ),_gd +rx *_feg ,_cg -ry *_ea }; 19 | };if _cfc ==0{_ege ._gef .Add_l (_fgc [0],_fgc [1]);};_ege ._gef .Add_c (_fgc [2],_fgc [3],_fgc [4],_fgc [5],_fgc [6],_fgc [7]);};};func _abd (_bda float64 )float64 {return _bda *_d .Pi /180.0};func (_ec *Renderer )SetStrokeColor (color _f .Color ){_ec ._ad =color ; 20 | _efc ,_cf ,_ebf ,_ :=_dab (color );_ec ._gef .Add_RG (_efc ,_cf ,_ebf );};func NewRenderer (cc *_a .ContentCreator ,res *_ee .PdfPageResources )func (int ,int )(_gg .Renderer ,error ){return func (_aa ,_adc int )(_gg .Renderer ,error ){_bd :=&Renderer {_eg :_aa ,_ae :_adc ,_ef :72,_gef :cc ,_ce :res ,_dec :map[*_ee .PdfFont ]_eed .PdfObjectName {}}; 21 | _bd .ResetStyle ();return _bd ,nil ;};};func (_gc *Renderer )SetStrokeWidth (width float64 ){_gc ._aea =width ;_gc ._gef .Add_w (width )};func (_cfe *Renderer )QuadCurveTo (cx ,cy ,x ,y int ){_cfe ._gef .Add_v (float64 (x ),float64 (y ),float64 (cx ),float64 (cy )); 22 | };func (_ca *Renderer )Stroke (){_ca ._gef .Add_S ()};func (_ebc *Renderer )MeasureText (text string )_gg .Box {_afd :=_ebc ._b ;_aba ,_gge :=_ebc ._ebg .GetFontDescriptor ();if _gge !=nil {_eb .Log .Debug ("W\u0041\u0052\u004e\u003a\u0020\u0055n\u0061\u0062\u006c\u0065\u0020\u0074o\u0020\u0067\u0065\u0074\u0020\u0066\u006fn\u0074\u0020\u0064\u0065\u0073\u0063\u0072\u0069\u0070\u0074o\u0072"); 23 | }else {_bbg ,_ecc :=_aba .GetCapHeight ();if _ecc !=nil {_eb .Log .Debug ("\u0057\u0041\u0052\u004e\u003a\u0020\u0055\u006e\u0061\u0062\u006c\u0065\u0020t\u006f\u0020\u0067\u0065\u0074\u0020f\u006f\u006e\u0074\u0020\u0063\u0061\u0070\u0020\u0068\u0065\u0069\u0067\u0068t\u003a\u0020\u0025\u0076",_ecc ); 24 | }else {_afd =_bbg /1000.0*_ebc ._b ;};};var (_bcbg =0.0;_eee =_ebc .wrapText (text ););for _ ,_ed :=range _eee {if _eda :=_ebc .getTextWidth (_ed );_eda > _bcbg {_bcbg =_eda ;};};_dgf :=_gg .NewBox (0,0,int (_bcbg ),int (_afd ));if _fb :=_ebc ._gb ;_fb !=0{_dgf =_dgf .Corners ().Rotate (_fb ).Box (); 25 | };return _dgf ;};func (_ace *Renderer )GetDPI ()float64 {return _ace ._ef };func _cdbc (_egee float64 )float64 {return _egee *180/_d .Pi };func (_cgb *Renderer )ClearTextRotation (){_cgb ._gb =0};func _dab (_faa _f .Color )(float64 ,float64 ,float64 ,float64 ){_fc ,_caa ,_bec ,_bgf :=_cbg (_faa ); 26 | return float64 (_fc )/255,float64 (_caa )/255,float64 (_bec )/255,float64 (_bgf )/255;};func (_ggb *Renderer )Fill (){_ggb ._gef .Add_f ()};func _cc (_gbf string ,_aed int ,_cee func (_eed .PdfObjectName )bool )_eed .PdfObjectName {_bga :=_eed .PdfObjectName (_c .Sprintf ("\u0025\u0073\u0025\u0064",_gbf ,_aed )); 27 | for _egg :=_aed ;_cee (_bga );{_egg ++;_bga =_eed .PdfObjectName (_c .Sprintf ("\u0025\u0073\u0025\u0064",_gbf ,_egg ));};return _bga ;};func (_bg *Renderer )getTextWidth (_cfcd string )float64 {var _ggf float64 ;for _ ,_cda :=range _cfcd {_gcc ,_eae :=_bg ._ebg .GetRuneMetrics (_cda ); 28 | if !_eae {_eb .Log .Debug ("\u0045\u0052\u0052OR\u003a\u0020\u0075\u006e\u0073\u0075\u0070\u0070\u006fr\u0074e\u0064 \u0072u\u006e\u0065\u0020\u0025\u0076\u0020\u0069\u006e\u0020\u0066\u006f\u006e\u0074",_cda );};_ggf +=_gcc .Wx ;};return _bg ._b *_ggf /1000.0; 29 | };func (_bb *Renderer )SetFont (font _gg .Font ){_gefa ,_gga :=font .(*_ee .PdfFont );if !_gga {_eb .Log .Debug ("\u0045R\u0052\u004f\u0052\u003a\u0020\u0069\u006e\u0076\u0061\u006c\u0069d\u0020\u0066\u006f\u006e\u0074\u0020\u0074\u0079\u0070\u0065");return ; 30 | };_ega ,_gga :=_bb ._dec [_gefa ];if !_gga {_ega =_cc ("\u0046\u006f\u006e\u0074",1,_bb ._ce .HasFontByName );if _cec :=_bb ._ce .SetFontByName (_ega ,_gefa .ToPdfObject ());_cec !=nil {_eb .Log .Debug ("\u0045\u0052\u0052\u004f\u0052:\u0020\u0063\u006f\u0075\u006c\u0064\u0020\u006e\u006f\u0074\u0020\u0061\u0064d\u0020\u0066\u006f\u006e\u0074\u0020\u0025\u0076\u0020\u0074\u006f\u0020\u0072\u0065\u0073\u006f\u0075\u0072\u0063\u0065\u0073",_gefa ); 31 | };_bb ._dec [_gefa ]=_ega ;};_bb ._gef .Add_Tf (_ega ,_bb ._b );_bb ._ebg =_gefa ;};func (_eef *Renderer )FillStroke (){_eef ._gef .Add_B ()};func (_ac *Renderer )ResetStyle (){_ac .SetFillColor (_f .Black );_ac .SetStrokeColor (_f .Transparent );_ac .SetStrokeWidth (0); 32 | _ac .SetFont (_ee .DefaultFont ());_ac .SetFontColor (_f .Black );_ac .SetFontSize (12);_ac .SetTextRotation (0);};func (_deb *Renderer )LineTo (x ,y int ){_deb ._gef .Add_l (float64 (x ),float64 (y ))};func (_ffa *Renderer )Save (w _ge .Writer )error {if w ==nil {return nil ; 33 | };_ ,_ecg :=_ge .Copy (w ,_e .NewBuffer (_ffa ._gef .Bytes ()));return _ecg ;};func (_aae *Renderer )Circle (radius float64 ,x ,y int ){_eebc :=radius ;if _ff :=_aae ._aea ;_ff !=0{_eebc -=_ff /2;};_dc :=_eebc *0.551784;_be :=_fe .CubicBezierPath {Curves :[]_fe .CubicBezierCurve {_fe .NewCubicBezierCurve (-_eebc ,0,-_eebc ,_dc ,-_dc ,_eebc ,0,_eebc ),_fe .NewCubicBezierCurve (0,_eebc ,_dc ,_eebc ,_eebc ,_dc ,_eebc ,0),_fe .NewCubicBezierCurve (_eebc ,0,_eebc ,-_dc ,_dc ,-_eebc ,0,-_eebc ),_fe .NewCubicBezierCurve (0,-_eebc ,-_dc ,-_eebc ,-_eebc ,-_dc ,-_eebc ,0)}}; 34 | if _cba :=_aae ._aea ;_cba !=0{_be =_be .Offset (_cba /2,_cba /2);};_be =_be .Offset (float64 (x ),float64 (y ));_fe .DrawBezierPathWithCreator (_be ,_aae ._gef );};func (_ada *Renderer )SetTextRotation (radians float64 ){_ada ._gb =_cdbc (-radians )}; 35 | func (_bc *Renderer )SetDPI (dpi float64 ){_bc ._ef =dpi };func (_eeff *Renderer )SetFontColor (color _f .Color ){_eeff ._db =color };func _cbg (_cad _f .Color )(uint8 ,uint8 ,uint8 ,uint8 ){_df ,_bfe ,_bde ,_fgb :=_cad .RGBA ();return uint8 (_df >>8),uint8 (_bfe >>8),uint8 (_bde >>8),uint8 (_fgb >>8); 36 | };func (_ab *Renderer )SetFillColor (color _f .Color ){_ab ._de =color ;_ag ,_cb ,_fee ,_ :=_dab (color );_ab ._gef .Add_rg (_ag ,_cb ,_fee );};func (_fg *Renderer )SetStrokeDashArray (dashArray []float64 ){_af :=make ([]int64 ,len (dashArray ));for _ceb ,_da :=range dashArray {_af [_ceb ]=int64 (_da ); 37 | };_fg ._gef .Add_d (_af ,0);};func (_eca *Renderer )wrapText (_cdb string )[]string {var (_ffc []string ;_ece []rune ;);for _ ,_cff :=range _cdb {if _cff =='\n'{_ffc =append (_ffc ,string (_ece ));_ece =[]rune {};continue ;};_ece =append (_ece ,_cff ); 38 | };if len (_ece )> 0{_ffc =append (_ffc ,string (_ece ));};return _ffc ;};func (_egae *Renderer )SetFontSize (size float64 ){_egae ._b =size };type Renderer struct{_eg int ;_ae int ;_ef float64 ;_gef *_a .ContentCreator ;_ce *_ee .PdfPageResources ;_de _f .Color ; 39 | _ad _f .Color ;_aea float64 ;_ebg *_ee .PdfFont ;_b float64 ;_db _f .Color ;_gb float64 ;_dec map[*_ee .PdfFont ]_eed .PdfObjectName ;};func (_efb *Renderer )SetClassName (name string ){}; -------------------------------------------------------------------------------- /internal/jbig2/basic/basic.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 basic ;import _a "github.com/unidoc/unipdf/v4/internal/jbig2/errors";func (_ed *Stack )Push (v interface{}){_ed .Data =append (_ed .Data ,v )};func (_ea IntSlice )Size ()int {return len (_ea )};func (_cf IntsMap )GetSlice (key uint64 )([]int ,bool ){_df ,_dg :=_cf [key ]; 13 | if !_dg {return nil ,false ;};return _df ,true ;};func NewNumSlice (i int )*NumSlice {_cc :=NumSlice (make ([]float32 ,i ));return &_cc };func (_af *Stack )Peek ()(_ca interface{},_ae bool ){return _af .peek ()};func (_be *Stack )peek ()(interface{},bool ){_ec :=_be .top (); 14 | if _ec ==-1{return nil ,false ;};return _be .Data [_ec ],true ;};func (_fd NumSlice )GetInt (i int )(int ,error ){const _dga ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_fd )-1{return 0,_a .Errorf (_dga ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i ); 15 | };_ce :=_fd [i ];return int (_ce +Sign (_ce )*0.5),nil ;};func (_egb *Stack )Len ()int {return len (_egb .Data )};type IntsMap map[uint64 ][]int ;func NewIntSlice (i int )*IntSlice {_f :=IntSlice (make ([]int ,i ));return &_f };func Min (x ,y int )int {if x < y {return x ; 16 | };return y ;};func (_dgf *NumSlice )AddInt (v int ){*_dgf =append (*_dgf ,float32 (v ))};func (_cg *Stack )top ()int {return len (_cg .Data )-1};func (_ag IntsMap )Get (key uint64 )(int ,bool ){_e ,_c :=_ag [key ];if !_c {return 0,false ;};if len (_e )==0{return 0,false ; 17 | };return _e [0],true ;};type Stack struct{Data []interface{};Aux *Stack ;};func (_fe *NumSlice )Add (v float32 ){*_fe =append (*_fe ,v )};func (_eg NumSlice )GetIntSlice ()[]int {_abf :=make ([]int ,len (_eg ));for _dd ,_fdf :=range _eg {_abf [_dd ]=int (_fdf ); 18 | };return _abf ;};func (_ab NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_ab )-1{return 0,_a .Errorf ("\u004e\u0075\u006dS\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i ); 19 | };return _ab [i ],nil ;};func Abs (v int )int {if v > 0{return v ;};return -v ;};func (_da IntsMap )Delete (key uint64 ){delete (_da ,key )};func (_b IntsMap )Add (key uint64 ,value int ){_b [key ]=append (_b [key ],value )};func (_g *IntSlice )Add (v int )error {if _g ==nil {return _a .Error ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0041\u0064\u0064","\u0073\u006c\u0069\u0063\u0065\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064"); 20 | };*_g =append (*_g ,v );return nil ;};func Max (x ,y int )int {if x > y {return x ;};return y ;};func (_ceb *Stack )Pop ()(_bg interface{},_cb bool ){_bg ,_cb =_ceb .peek ();if !_cb {return nil ,_cb ;};_ceb .Data =_ceb .Data [:_ceb .top ()];return _bg ,true ; 21 | };func (_gc IntSlice )Get (index int )(int ,error ){if index > len (_gc )-1{return 0,_a .Errorf ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069\u006e\u0064\u0065x:\u0020\u0025\u0064\u0020\u006f\u0075\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006eg\u0065",index ); 22 | };return _gc [index ],nil ;};type IntSlice []int ;type NumSlice []float32 ;func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};func Sign (v float32 )float32 {if v >=0.0{return 1.0; 23 | };return -1.0;};func (_aa *IntSlice )Copy ()*IntSlice {_fb :=IntSlice (make ([]int ,len (*_aa )));copy (_fb ,*_aa );return &_fb ;}; -------------------------------------------------------------------------------- /internal/jbig2/bench/bench.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 bench ; -------------------------------------------------------------------------------- /internal/jbig2/decoder/arithmetic/arithmetic.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 arithmetic ;import (_eg "fmt";_fd "github.com/unidoc/unipdf/v4/common";_ee "github.com/unidoc/unipdf/v4/internal/bitwise";_ac "github.com/unidoc/unipdf/v4/internal/jbig2/internal";_e "io";_f "strings";);func (_aba *Decoder )decodeIntBit (_ec *DecoderStats )(int ,error ){_ec .SetIndex (int32 (_aba ._gf )); 13 | _bdd ,_gd :=_aba .DecodeBit (_ec );if _gd !=nil {_fd .Log .Debug ("\u0041\u0072\u0069\u0074\u0068\u006d\u0065t\u0069\u0063\u0044e\u0063\u006f\u0064e\u0072\u0020'\u0064\u0065\u0063\u006f\u0064\u0065I\u006etB\u0069\u0074\u0027\u002d\u003e\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0042\u0069\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u002e\u0020\u0025\u0076",_gd ); 14 | return _bdd ,_gd ;};if _aba ._gf < 256{_aba ._gf =((_aba ._gf < 0{return -_bcc ,nil ;};return 0,_ac .ErrOOB ;};func (_ff *Decoder )init ()error {_ff ._ad =_ff ._b .AbsolutePosition ();_ab ,_abb :=_ff ._b .ReadByte ();if _abb !=nil {_fd .Log .Debug ("B\u0075\u0066\u0066\u0065\u0072\u0030 \u0072\u0065\u0061\u0064\u0042\u0079\u0074\u0065\u0020f\u0061\u0069\u006ce\u0064.\u0020\u0025\u0076",_abb ); 22 | return _abb ;};_ff ._c =_ab ;_ff ._cf =uint64 (_ab )<<16;if _abb =_ff .readByte ();_abb !=nil {return _abb ;};_ff ._cf <<=7;_ff ._ge -=7;_ff ._g =0x8000;_ff ._ea ++;return nil ;};func (_bbg *DecoderStats )SetIndex (index int32 ){_bbg ._bb =index };func (_bdc *DecoderStats )Reset (){for _ggg :=0; 23 | _ggg < len (_bdc ._gdf );_ggg ++{_bdc ._gdf [_ggg ]=0;_bdc ._eb [_ggg ]=0;};};func (_fa *Decoder )mpsExchange (_cba *DecoderStats ,_agg int32 )int {_bgb :=_cba ._eb [_cba ._bb ];if _fa ._g < _d [_agg ][0]{if _d [_agg ][3]==1{_cba .toggleMps ();};_cba .setEntry (int (_d [_agg ][2])); 24 | return int (1-_bgb );};_cba .setEntry (int (_d [_agg ][1]));return int (_bgb );};func (_eff *DecoderStats )Overwrite (dNew *DecoderStats ){for _dba :=0;_dba < len (_eff ._gdf );_dba ++{_eff ._gdf [_dba ]=dNew ._gdf [_dba ];_eff ._eb [_dba ]=dNew ._eb [_dba ]; 25 | };};func (_ag *Decoder )readByte ()error {if _ag ._b .AbsolutePosition ()> _ag ._ad {if _ ,_eae :=_ag ._b .Seek (-1,_e .SeekCurrent );_eae !=nil {return _eae ;};};_fdb ,_ffc :=_ag ._b .ReadByte ();if _ffc !=nil {return _ffc ;};_ag ._c =_fdb ;if _ag ._c ==0xFF{_geb ,_ffd :=_ag ._b .ReadByte (); 26 | if _ffd !=nil {return _ffd ;};if _geb > 0x8F{_ag ._cf +=0xFF00;_ag ._ge =8;if _ ,_ef :=_ag ._b .Seek (-2,_e .SeekCurrent );_ef !=nil {return _ef ;};}else {_ag ._cf +=uint64 (_geb )<<9;_ag ._ge =7;};}else {_fdb ,_ffc =_ag ._b .ReadByte ();if _ffc !=nil {return _ffc ; 27 | };_ag ._c =_fdb ;_ag ._cf +=uint64 (_ag ._c )<<8;_ag ._ge =8;};_ag ._cf &=0xFFFFFFFFFF;return nil ;};func (_gc *DecoderStats )setEntry (_cg int ){_gde :=byte (_cg &0x7f);_gc ._gdf [_gc ._bb ]=_gde };var (_d =[][4]uint32 {{0x5601,1,1,1},{0x3401,2,6,0},{0x1801,3,9,0},{0x0AC1,4,12,0},{0x0521,5,29,0},{0x0221,38,33,0},{0x5601,7,6,1},{0x5401,8,14,0},{0x4801,9,14,0},{0x3801,10,14,0},{0x3001,11,17,0},{0x2401,12,18,0},{0x1C01,13,20,0},{0x1601,29,21,0},{0x5601,15,14,1},{0x5401,16,14,0},{0x5101,17,15,0},{0x4801,18,16,0},{0x3801,19,17,0},{0x3401,20,18,0},{0x3001,21,19,0},{0x2801,22,19,0},{0x2401,23,20,0},{0x2201,24,21,0},{0x1C01,25,22,0},{0x1801,26,23,0},{0x1601,27,24,0},{0x1401,28,25,0},{0x1201,29,26,0},{0x1101,30,27,0},{0x0AC1,31,28,0},{0x09C1,32,29,0},{0x08A1,33,30,0},{0x0521,34,31,0},{0x0441,35,32,0},{0x02A1,36,33,0},{0x0221,37,34,0},{0x0141,38,35,0},{0x0111,39,36,0},{0x0085,40,37,0},{0x0049,41,38,0},{0x0025,42,39,0},{0x0015,43,40,0},{0x0009,44,41,0},{0x0005,45,42,0},{0x0001,45,43,0},{0x5601,46,46,0}}; 28 | );func (_fdd *Decoder )lpsExchange (_aa *DecoderStats ,_cc int32 ,_baa uint32 )int {_cfg :=_aa .getMps ();if _fdd ._g < _baa {_aa .setEntry (int (_d [_cc ][1]));_fdd ._g =_baa ;return int (_cfg );};if _d [_cc ][3]==1{_aa .toggleMps ();};_aa .setEntry (int (_d [_cc ][2])); 29 | _fdd ._g =_baa ;return int (1-_cfg );};func (_fb *DecoderStats )Copy ()*DecoderStats {_fbf :=&DecoderStats {_bgg :_fb ._bgg ,_gdf :make ([]byte ,_fb ._bgg )};copy (_fbf ._gdf ,_fb ._gdf );return _fbf ;};func (_ega *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_acg int ; 30 | _ba =_d [stats .cx ()][0];_fc =int32 (stats .cx ()););defer func (){_ega ._ea ++}();_ega ._g -=_ba ;if (_ega ._cf >>16)< uint64 (_ba ){_acg =_ega .lpsExchange (stats ,_fc ,_ba );if _gg :=_ega .renormalize ();_gg !=nil {return 0,_gg ;};}else {_ega ._cf -=uint64 (_ba )<<16; 31 | if (_ega ._g &0x8000)==0{_acg =_ega .mpsExchange (stats ,_fc );if _df :=_ega .renormalize ();_df !=nil {return 0,_df ;};}else {_acg =int (stats .getMps ());};};return _acg ,nil ;};func (_ffb *DecoderStats )String ()string {_aae :=&_f .Builder {};_aae .WriteString (_eg .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_ffb ._gdf ))); 32 | for _ffdc ,_baag :=range _ffb ._gdf {if _baag !=0{_aae .WriteString (_eg .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_ffdc ,_baag ));};};return _aae .String ();};func (_dg *DecoderStats )getMps ()byte {return _dg ._eb [_dg ._bb ]}; 33 | func New (r *_ee .Reader )(*Decoder ,error ){_bc :=&Decoder {_b :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};if _fe :=_bc .init ();_fe !=nil {return nil ,_fe ;};return _bc ,nil ;};func (_da *DecoderStats )toggleMps (){_da ._eb [_da ._bb ]^=1}; 34 | func NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_bb :index ,_bgg :contextSize ,_gdf :make ([]byte ,contextSize ),_eb :make ([]byte ,contextSize )};};type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ; 35 | _b *_ee .Reader ;_c uint8 ;_cf uint64 ;_g uint32 ;_gf int64 ;_ge int32 ;_ea int32 ;_ad int64 ;}; -------------------------------------------------------------------------------- /internal/jbig2/decoder/decoder.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 decoder ;import (_d "github.com/unidoc/unipdf/v4/internal/bitwise";_bg "github.com/unidoc/unipdf/v4/internal/jbig2/bitmap";_g "github.com/unidoc/unipdf/v4/internal/jbig2/document";_e "github.com/unidoc/unipdf/v4/internal/jbig2/errors";_c "image"; 13 | );func (_cc *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _cc .decodePage (pageNumber )};func Decode (input []byte ,parameters Parameters ,globals *_g .Globals )(*Decoder ,error ){_egg :=_d .NewReader (input );_eb ,_def :=_g .DecodeDocument (_egg ,globals ); 14 | if _def !=nil {return nil ,_def ;};return &Decoder {_a :_egg ,_ea :_eb ,_ed :parameters },nil ;};func (_ac *Decoder )decodePage (_fcd int )([]byte ,error ){const _be ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _fcd < 0{return nil ,_e .Errorf (_be ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_fcd ); 15 | };if _fcd > int (_ac ._ea .NumberOfPages ){return nil ,_e .Errorf (_be ,"p\u0061\u0067\u0065\u003a\u0020\u0027%\u0064\u0027\u0020\u006e\u006f\u0074 \u0066\u006f\u0075\u006e\u0064\u0020\u0069n\u0020\u0074\u0068\u0065\u0020\u0064\u0065\u0063\u006f\u0064e\u0072",_fcd ); 16 | };_aa ,_de :=_ac ._ea .GetPage (_fcd );if _de !=nil {return nil ,_e .Wrap (_de ,_be ,"");};_dea ,_de :=_aa .GetBitmap ();if _de !=nil {return nil ,_e .Wrap (_de ,_be ,"");};_dea .InverseData ();if !_ac ._ed .UnpaddedData {return _dea .Data ,nil ;};return _dea .GetUnpaddedData (); 17 | };func (_ca *Decoder )DecodePageImage (pageNumber int )(_c .Image ,error ){const _eab ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";_cf ,_ga :=_ca .decodePageImage (pageNumber ); 18 | if _ga !=nil {return nil ,_e .Wrap (_ga ,_eab ,"");};return _cf ,nil ;};type Parameters struct{UnpaddedData bool ;Color _bg .Color ;};func (_ge *Decoder )PageNumber ()(int ,error ){const _fc ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072"; 19 | if _ge ._ea ==nil {return 0,_e .Error (_fc ,"d\u0065\u0063\u006f\u0064\u0065\u0072 \u006e\u006f\u0074\u0020\u0069\u006e\u0069\u0074\u0069a\u006c\u0069\u007ae\u0064 \u0079\u0065\u0074");};return int (_ge ._ea .NumberOfPages ),nil ;};func (_gb *Decoder )DecodeNextPage ()([]byte ,error ){_gb ._f ++; 20 | _cb :=_gb ._f ;return _gb .decodePage (_cb );};type Decoder struct{_a *_d .Reader ;_ea *_g .Document ;_f int ;_ed Parameters ;};func (_geg *Decoder )decodePageImage (_bgg int )(_c .Image ,error ){const _eg ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065"; 21 | if _bgg < 0{return nil ,_e .Errorf (_eg ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_bgg );};if _bgg > int (_geg ._ea .NumberOfPages ){return nil ,_e .Errorf (_eg ,"p\u0061\u0067\u0065\u003a\u0020\u0027%\u0064\u0027\u0020\u006e\u006f\u0074 \u0066\u006f\u0075\u006e\u0064\u0020\u0069n\u0020\u0074\u0068\u0065\u0020\u0064\u0065\u0063\u006f\u0064e\u0072",_bgg ); 22 | };_df ,_gf :=_geg ._ea .GetPage (_bgg );if _gf !=nil {return nil ,_e .Wrap (_gf ,_eg ,"");};_bb ,_gf :=_df .GetBitmap ();if _gf !=nil {return nil ,_e .Wrap (_gf ,_eg ,"");};_bb .InverseData ();return _bb .ToImage (),nil ;}; -------------------------------------------------------------------------------- /internal/jbig2/decoder/huffman/huffman.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 huffman ;import (_ba "errors";_e "fmt";_b "github.com/unidoc/unipdf/v4/internal/bitwise";_f "github.com/unidoc/unipdf/v4/internal/jbig2/internal";_c "math";_a "strings";);func NewFixedSizeTable (codeTable []*Code )(*FixedSizeTable ,error ){_ag :=&FixedSizeTable {_gf :&InternalNode {}}; 13 | if _ecc :=_ag .InitTree (codeTable );_ecc !=nil {return nil ,_ecc ;};return _ag ,nil ;};type InternalNode struct{_gc int32 ;_ecgf Node ;_fgcf Node ;};func _bbf (_cd *Code )*ValueNode {return &ValueNode {_fa :_cd ._dga ,_fcd :_cd ._aeg ,_ged :_cd ._fdg }}; 14 | func (_edg *FixedSizeTable )InitTree (codeTable []*Code )error {_eg (codeTable );for _ ,_dcg :=range codeTable {_dfg :=_edg ._gf .append (_dcg );if _dfg !=nil {return _dfg ;};};return nil ;};func (_ff *ValueNode )Decode (r *_b .Reader )(int64 ,error ){_bbg ,_gedg :=r .ReadBits (byte (_ff ._fa )); 15 | if _gedg !=nil {return 0,_gedg ;};if _ff ._ged {_bbg =-_bbg ;};return int64 (_ff ._fcd )+int64 (_bbg ),nil ;};type Node interface{Decode (_bg *_b .Reader )(int64 ,error );String ()string ;};func NewEncodedTable (table BasicTabler )(*EncodedTable ,error ){_d :=&EncodedTable {_fb :&InternalNode {},BasicTabler :table }; 16 | if _be :=_d .parseTable ();_be !=nil {return nil ,_be ;};return _d ,nil ;};var _ Node =&ValueNode {};func (_ca *EncodedTable )parseTable ()error {var (_bf []*Code ;_df ,_aa ,_ab int32 ;_fc uint64 ;_bd error ;);_ga :=_ca .StreamReader ();_ecg :=_ca .HtLow (); 17 | for _ecg < _ca .HtHigh (){_fc ,_bd =_ga .ReadBits (byte (_ca .HtPS ()));if _bd !=nil {return _bd ;};_df =int32 (_fc );_fc ,_bd =_ga .ReadBits (byte (_ca .HtRS ()));if _bd !=nil {return _bd ;};_aa =int32 (_fc );_bf =append (_bf ,NewCode (_df ,_aa ,_ab ,false )); 18 | _ecg +=1<>uint (_ffe -_bdf )&1;if _bc !=0{_de [_bdf -1]='1';}else {_de [_bdf -1]='0';};};return string (_de );};func _db (_gfc [][]int32 )(*StandardTable ,error ){var _dgg []*Code ; 26 | for _fac :=0;_fac < len (_gfc );_fac ++{_bba :=_gfc [_fac ][0];_gb :=_gfc [_fac ][1];_bfg :=_gfc [_fac ][2];var _bga bool ;if len (_gfc [_fac ])> 3{_bga =true ;};_dgg =append (_dgg ,NewCode (_bba ,_gb ,_bfg ,_bga ));};_cdgd :=&StandardTable {_ae :_eca (0)}; 27 | if _fce :=_cdgd .InitTree (_dgg );_fce !=nil {return nil ,_fce ;};return _cdgd ,nil ;};func (_bec *StandardTable )Decode (r *_b .Reader )(int64 ,error ){return _bec ._ae .Decode (r )};func (_ee *InternalNode )append (_gae *Code )(_eec error ){if _gae ._edd ==0{return nil ; 28 | };_dfc :=_gae ._edd -1-_ee ._gc ;if _dfc < 0{return _ba .New ("\u004e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0073\u0068\u0069\u0066\u0074\u0069n\u0067 \u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0061\u006c\u006c\u006f\u0077\u0065\u0064");};_cfab :=(_gae ._cc >>uint (_dfc ))&0x1; 29 | if _dfc ==0{if _gae ._dga ==-1{if _cfab ==1{if _ee ._fgcf !=nil {return _e .Errorf ("O\u004f\u0042\u0020\u0061\u006c\u0072e\u0061\u0064\u0079\u0020\u0073\u0065\u0074\u0020\u0066o\u0072\u0020\u0063o\u0064e\u0020\u0025\u0073",_gae );};_ee ._fgcf =_agf (_gae ); 30 | }else {if _ee ._ecgf !=nil {return _e .Errorf ("O\u004f\u0042\u0020\u0061\u006c\u0072e\u0061\u0064\u0079\u0020\u0073\u0065\u0074\u0020\u0066o\u0072\u0020\u0063o\u0064e\u0020\u0025\u0073",_gae );};_ee ._ecgf =_agf (_gae );};}else {if _cfab ==1{if _ee ._fgcf !=nil {return _e .Errorf ("\u0056\u0061\u006cue\u0020\u004e\u006f\u0064\u0065\u0020\u0061\u006c\u0072e\u0061d\u0079 \u0073e\u0074\u0020\u0066\u006f\u0072\u0020\u0063\u006f\u0064\u0065\u0020\u0025\u0073",_gae ); 31 | };_ee ._fgcf =_bbf (_gae );}else {if _ee ._ecgf !=nil {return _e .Errorf ("\u0056\u0061\u006cue\u0020\u004e\u006f\u0064\u0065\u0020\u0061\u006c\u0072e\u0061d\u0079 \u0073e\u0074\u0020\u0066\u006f\u0072\u0020\u0063\u006f\u0064\u0065\u0020\u0025\u0073",_gae ); 32 | };_ee ._ecgf =_bbf (_gae );};};}else {if _cfab ==1{if _ee ._fgcf ==nil {_ee ._fgcf =_eca (_ee ._gc +1);};if _eec =_ee ._fgcf .(*InternalNode ).append (_gae );_eec !=nil {return _eec ;};}else {if _ee ._ecgf ==nil {_ee ._ecgf =_eca (_ee ._gc +1);};if _eec =_ee ._ecgf .(*InternalNode ).append (_gae ); 33 | _eec !=nil {return _eec ;};};};return nil ;};func (_da *FixedSizeTable )RootNode ()*InternalNode {return _da ._gf };func (_ed *EncodedTable )InitTree (codeTable []*Code )error {_eg (codeTable );for _ ,_fe :=range codeTable {if _ece :=_ed ._fb .append (_fe ); 34 | _ece !=nil {return _ece ;};};return nil ;};func _abe (_edc ,_aeb int32 )int32 {if _edc > _aeb {return _edc ;};return _aeb ;};func (_baa *InternalNode )String ()string {_gee :=&_a .Builder {};_gee .WriteString ("\u000a");_baa .pad (_gee );_gee .WriteString ("\u0030\u003a\u0020"); 35 | _gee .WriteString (_baa ._ecgf .String ()+"\u000a");_baa .pad (_gee );_gee .WriteString ("\u0031\u003a\u0020");_gee .WriteString (_baa ._fgcf .String ()+"\u000a");return _gee .String ();};func (_fd *StandardTable )String ()string {return _fd ._ae .String ()+"\u000a"}; 36 | func (_ad *InternalNode )pad (_dfb *_a .Builder ){for _cfe :=int32 (0);_cfe < _ad ._gc ;_cfe ++{_dfb .WriteString ("\u0020\u0020\u0020");};};func _agf (_cfa *Code )*OutOfBandNode {return &OutOfBandNode {}};func (_af *OutOfBandNode )Decode (r *_b .Reader )(int64 ,error ){return 0,_f .ErrOOB }; 37 | func (_agc *FixedSizeTable )Decode (r *_b .Reader )(int64 ,error ){return _agc ._gf .Decode (r )};func (_gfe *StandardTable )RootNode ()*InternalNode {return _gfe ._ae };func (_fbd *Code )String ()string {var _bff string ;if _fbd ._cc !=-1{_bff =_aee (_fbd ._cc ,_fbd ._edd ); 38 | }else {_bff ="\u003f";};return _e .Sprintf ("%\u0073\u002f\u0025\u0064\u002f\u0025\u0064\u002f\u0025\u0064",_bff ,_fbd ._edd ,_fbd ._dga ,_fbd ._aeg );};func GetStandardTable (number int )(Tabler ,error ){if number <=0||number > len (_aec ){return nil ,_ba .New ("\u0049n\u0064e\u0078\u0020\u006f\u0075\u0074 \u006f\u0066 \u0072\u0061\u006e\u0067\u0065"); 39 | };_gca :=_aec [number -1];if _gca ==nil {var _eeg error ;_gca ,_eeg =_db (_afd [number -1]);if _eeg !=nil {return nil ,_eeg ;};_aec [number -1]=_gca ;};return _gca ,nil ;};func NewCode (prefixLength ,rangeLength ,rangeLow int32 ,isLowerRange bool )*Code {return &Code {_edd :prefixLength ,_dga :rangeLength ,_aeg :rangeLow ,_fdg :isLowerRange ,_cc :-1}; 40 | };func (_dg *StandardTable )InitTree (codeTable []*Code )error {_eg (codeTable );for _ ,_ac :=range codeTable {if _ce :=_dg ._ae .append (_ac );_ce !=nil {return _ce ;};};return nil ;};func (_ef *FixedSizeTable )String ()string {return _ef ._gf .String ()+"\u000a"}; 41 | var _aec =make ([]Tabler ,len (_afd ));type EncodedTable struct{BasicTabler ;_fb *InternalNode ;};var _ Tabler =&EncodedTable {};type Tabler interface{Decode (_bgf *_b .Reader )(int64 ,error );InitTree (_fcg []*Code )error ;String ()string ;RootNode ()*InternalNode ; 42 | };type ValueNode struct{_fa int32 ;_fcd int32 ;_ged bool ;};func _eca (_baab int32 )*InternalNode {return &InternalNode {_gc :_baab }};func (_cf *OutOfBandNode )String ()string {return _e .Sprintf ("\u0025\u0030\u00364\u0062",int64 (_c .MaxInt64 ));};type Code struct{_edd int32 ; 43 | _dga int32 ;_aeg int32 ;_fdg bool ;_cc int32 ;};func (_ec *EncodedTable )Decode (r *_b .Reader )(int64 ,error ){return _ec ._fb .Decode (r )};type BasicTabler interface{HtHigh ()int32 ;HtLow ()int32 ;StreamReader ()*_b .Reader ;HtPS ()int32 ;HtRS ()int32 ; 44 | HtOOB ()int32 ;}; -------------------------------------------------------------------------------- /internal/jbig2/decoder/mmr/mmr.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 mmr ;import (_eg "errors";_g "fmt";_ga "github.com/unidoc/unipdf/v4/common";_gd "github.com/unidoc/unipdf/v4/internal/bitwise";_d "github.com/unidoc/unipdf/v4/internal/jbig2/bitmap";_e "io";);type mmrCode int ;func (_af *runData )uncompressGetCode (_gad []*code )(*code ,error ){return _af .uncompressGetCodeLittleEndian (_gad ); 13 | };func (_bbeb *Decoder )uncompress1d (_gdf *runData ,_fg []int ,_bfb int )(int ,error ){var (_aac =true ;_gda int ;_adg *code ;_cdd int ;_faf error ;);_be :for _gda < _bfb {_eae :for {if _aac {_adg ,_faf =_gdf .uncompressGetCode (_bbeb ._bad );if _faf !=nil {return 0,_faf ; 14 | };}else {_adg ,_faf =_gdf .uncompressGetCode (_bbeb ._efa );if _faf !=nil {return 0,_faf ;};};_gdf ._fcf +=_adg ._b ;if _adg ._dd < 0{break _be ;};_gda +=_adg ._dd ;if _adg ._dd < 64{_aac =!_aac ;_fg [_cdd ]=_gda ;_cdd ++;break _eae ;};};};if _fg [_cdd ]!=_bfb {_fg [_cdd ]=_bfb ; 15 | };_cddc :=EOL ;if _adg !=nil &&_adg ._dd !=EOL {_cddc =_cdd ;};return _cddc ,nil ;};func (_bf *Decoder )createLittleEndianTable (_fac [][3]int )([]*code ,error ){_ggb :=make ([]*code ,_dfc +1);for _bbe :=0;_bbe < len (_fac );_bbe ++{_agb :=_cd (_fac [_bbe ]); 16 | if _agb ._b <=_gcf {_cg :=_gcf -_agb ._b ;_ebd :=_agb ._a <=0;_cf --{_face :=_ebd |_cf ;_ggb [_face ]=_agb ;};}else {_edg :=_agb ._a >>uint (_agb ._b -_gcf );if _ggb [_edg ]==nil {var _add =_cd ([3]int {}); 17 | _add ._ef =make ([]*code ,_ag +1);_ggb [_edg ]=_add ;};if _agb ._b <=_gcf +_dfe {_agg :=_gcf +_dfe -_agb ._b ;_gae :=(_agb ._a <=0;_dcee --{_ggb [_edg ]._ef [_gae |_dcee ]=_agb ; 18 | };}else {return nil ,_eg .New ("\u0043\u006f\u0064\u0065\u0020\u0074a\u0062\u006c\u0065\u0020\u006f\u0076\u0065\u0072\u0066\u006c\u006f\u0077\u0020i\u006e\u0020\u004d\u004d\u0052\u0044\u0065c\u006f\u0064\u0065\u0072");};};};return _ggb ,nil ;};const (EOF =-3; 19 | _fc =-2;EOL =-1;_gcf =8;_dfc =(1<<_gcf )-1;_dfe =5;_ag =(1<<_dfe )-1;);type code struct{_b int ;_a int ;_dd int ;_ef []*code ;_df bool ;};func _ba (_ca ,_dc int )int {if _ca > _dc {return _dc ;};return _ca ;};func (_efb *runData )uncompressGetNextCodeLittleEndian ()(int ,error ){_gef :=_efb ._fcf -_efb ._abf ; 20 | if _gef < 0||_gef > 24{_dcd :=(_efb ._fcf >>3)-_efb ._gdd ;if _dcd >=_efb ._ebdc {_dcd +=_efb ._gdd ;if _begg :=_efb .fillBuffer (_dcd );_begg !=nil {return 0,_begg ;};_dcd -=_efb ._gdd ;};_fee :=(uint32 (_efb ._dcbf [_dcd ]&0xFF)<<16)|(uint32 (_efb ._dcbf [_dcd +1]&0xFF)<<8)|(uint32 (_efb ._dcbf [_dcd +2]&0xFF)); 21 | _aeb :=uint32 (_efb ._fcf &7);_fee <<=_aeb ;_efb ._beg =int (_fee );}else {_decf :=_efb ._abf &7;_fdc :=7-_decf ;if _gef <=_fdc {_efb ._beg <<=uint (_gef );}else {_befg :=(_efb ._abf >>3)+3-_efb ._gdd ;if _befg >=_efb ._ebdc {_befg +=_efb ._gdd ;if _gbba :=_efb .fillBuffer (_befg ); 22 | _gbba !=nil {return 0,_gbba ;};_befg -=_efb ._gdd ;};_decf =8-_decf ;for {_efb ._beg <<=uint (_decf );_efb ._beg |=int (uint (_efb ._dcbf [_befg ])&0xFF);_gef -=_decf ;_befg ++;_decf =8;if !(_gef >=8){break ;};};_efb ._beg <<=uint (_gef );};};_efb ._abf =_efb ._fcf ; 23 | return _efb ._beg ,nil ;};func (_gebb *runData )align (){_gebb ._fcf =((_gebb ._fcf +7)>>3)<<3};func (_gde *Decoder )detectAndSkipEOL ()error {for {_cfa ,_cae :=_gde ._fa .uncompressGetCode (_gde ._ae );if _cae !=nil {return _cae ;};if _cfa !=nil &&_cfa ._dd ==EOL {_gde ._fa ._fcf +=_cfa ._b ; 24 | }else {return nil ;};};};const (_dce mmrCode =iota ;_gg ;_gc ;_eb ;_ce ;_ee ;_f ;_cab ;_cb ;_dcg ;_aa ;);type runData struct{_dcb *_gd .Reader ;_fcf int ;_abf int ;_beg int ;_dcbf []byte ;_gdd int ;_ebdc int ;};const (_cga int =1024<<7;_caf int =3;_bed uint =24; 25 | );var (_edd =[][3]int {{4,0x1,int (_dce )},{3,0x1,int (_gg )},{1,0x1,int (_gc )},{3,0x3,int (_eb )},{6,0x3,int (_ce )},{7,0x3,int (_ee )},{3,0x2,int (_f )},{6,0x2,int (_cab )},{7,0x2,int (_cb )},{10,0xf,int (_dcg )},{12,0xf,int (_aa )},{12,0x1,int (EOL )}}; 26 | _bag =[][3]int {{4,0x07,2},{4,0x08,3},{4,0x0B,4},{4,0x0C,5},{4,0x0E,6},{4,0x0F,7},{5,0x12,128},{5,0x13,8},{5,0x14,9},{5,0x1B,64},{5,0x07,10},{5,0x08,11},{6,0x17,192},{6,0x18,1664},{6,0x2A,16},{6,0x2B,17},{6,0x03,13},{6,0x34,14},{6,0x35,15},{6,0x07,1},{6,0x08,12},{7,0x13,26},{7,0x17,21},{7,0x18,28},{7,0x24,27},{7,0x27,18},{7,0x28,24},{7,0x2B,25},{7,0x03,22},{7,0x37,256},{7,0x04,23},{7,0x08,20},{7,0xC,19},{8,0x12,33},{8,0x13,34},{8,0x14,35},{8,0x15,36},{8,0x16,37},{8,0x17,38},{8,0x1A,31},{8,0x1B,32},{8,0x02,29},{8,0x24,53},{8,0x25,54},{8,0x28,39},{8,0x29,40},{8,0x2A,41},{8,0x2B,42},{8,0x2C,43},{8,0x2D,44},{8,0x03,30},{8,0x32,61},{8,0x33,62},{8,0x34,63},{8,0x35,0},{8,0x36,320},{8,0x37,384},{8,0x04,45},{8,0x4A,59},{8,0x4B,60},{8,0x5,46},{8,0x52,49},{8,0x53,50},{8,0x54,51},{8,0x55,52},{8,0x58,55},{8,0x59,56},{8,0x5A,57},{8,0x5B,58},{8,0x64,448},{8,0x65,512},{8,0x67,640},{8,0x68,576},{8,0x0A,47},{8,0x0B,48},{9,0x01,_fc },{9,0x98,1472},{9,0x99,1536},{9,0x9A,1600},{9,0x9B,1728},{9,0xCC,704},{9,0xCD,768},{9,0xD2,832},{9,0xD3,896},{9,0xD4,960},{9,0xD5,1024},{9,0xD6,1088},{9,0xD7,1152},{9,0xD8,1216},{9,0xD9,1280},{9,0xDA,1344},{9,0xDB,1408},{10,0x01,_fc },{11,0x01,_fc },{11,0x08,1792},{11,0x0C,1856},{11,0x0D,1920},{12,0x00,EOF },{12,0x01,EOL },{12,0x12,1984},{12,0x13,2048},{12,0x14,2112},{12,0x15,2176},{12,0x16,2240},{12,0x17,2304},{12,0x1C,2368},{12,0x1D,2432},{12,0x1E,2496},{12,0x1F,2560}}; 27 | _ge =[][3]int {{2,0x02,3},{2,0x03,2},{3,0x02,1},{3,0x03,4},{4,0x02,6},{4,0x03,5},{5,0x03,7},{6,0x04,9},{6,0x05,8},{7,0x04,10},{7,0x05,11},{7,0x07,12},{8,0x04,13},{8,0x07,14},{9,0x01,_fc },{9,0x18,15},{10,0x01,_fc },{10,0x17,16},{10,0x18,17},{10,0x37,0},{10,0x08,18},{10,0x0F,64},{11,0x01,_fc },{11,0x17,24},{11,0x18,25},{11,0x28,23},{11,0x37,22},{11,0x67,19},{11,0x68,20},{11,0x6C,21},{11,0x08,1792},{11,0x0C,1856},{11,0x0D,1920},{12,0x00,EOF },{12,0x01,EOL },{12,0x12,1984},{12,0x13,2048},{12,0x14,2112},{12,0x15,2176},{12,0x16,2240},{12,0x17,2304},{12,0x1C,2368},{12,0x1D,2432},{12,0x1E,2496},{12,0x1F,2560},{12,0x24,52},{12,0x27,55},{12,0x28,56},{12,0x2B,59},{12,0x2C,60},{12,0x33,320},{12,0x34,384},{12,0x35,448},{12,0x37,53},{12,0x38,54},{12,0x52,50},{12,0x53,51},{12,0x54,44},{12,0x55,45},{12,0x56,46},{12,0x57,47},{12,0x58,57},{12,0x59,58},{12,0x5A,61},{12,0x5B,256},{12,0x64,48},{12,0x65,49},{12,0x66,62},{12,0x67,63},{12,0x68,30},{12,0x69,31},{12,0x6A,32},{12,0x6B,33},{12,0x6C,40},{12,0x6D,41},{12,0xC8,128},{12,0xC9,192},{12,0xCA,26},{12,0xCB,27},{12,0xCC,28},{12,0xCD,29},{12,0xD2,34},{12,0xD3,35},{12,0xD4,36},{12,0xD5,37},{12,0xD6,38},{12,0xD7,39},{12,0xDA,42},{12,0xDB,43},{13,0x4A,640},{13,0x4B,704},{13,0x4C,768},{13,0x4D,832},{13,0x52,1280},{13,0x53,1344},{13,0x54,1408},{13,0x55,1472},{13,0x5A,1536},{13,0x5B,1600},{13,0x64,1664},{13,0x65,1728},{13,0x6C,512},{13,0x6D,576},{13,0x72,896},{13,0x73,960},{13,0x74,1024},{13,0x75,1088},{13,0x76,1152},{13,0x77,1216}}; 28 | );func _cd (_de [3]int )*code {return &code {_b :_de [0],_a :_de [1],_dd :_de [2]}};func (_bbf *Decoder )fillBitmap (_eeb *_d .Bitmap ,_dbe int ,_gf []int ,_ded int )error {var _gec byte ;_ddb :=0;_da :=_eeb .GetByteIndex (_ddb ,_dbe );for _bd :=0;_bd < _ded ; 29 | _bd ++{_gbe :=byte (1);_cc :=_gf [_bd ];if (_bd &1)==0{_gbe =0;};for _ddb < _cc {_gec =(_gec <<1)|_gbe ;_ddb ++;if (_ddb &7)==0{if _eab :=_eeb .SetByte (_da ,_gec );_eab !=nil {return _eab ;};_da ++;_gec =0;};};};if (_ddb &7)!=0{_gec <<=uint (8-(_ddb &7)); 30 | if _dcf :=_eeb .SetByte (_da ,_gec );_dcf !=nil {return _dcf ;};};return nil ;};func _egc (_dgg *_gd .Reader )(*runData ,error ){_gac :=&runData {_dcb :_dgg ,_fcf :0,_abf :1};_gddc :=_ba (_ed (_caf ,int (_dgg .Length ())),_cga );_gac ._dcbf =make ([]byte ,_gddc ); 31 | if _fde :=_gac .fillBuffer (0);_fde !=nil {if _fde ==_e .EOF {_gac ._dcbf =make ([]byte ,10);_ga .Log .Debug ("F\u0069\u006c\u006c\u0042uf\u0066e\u0072\u0020\u0066\u0061\u0069l\u0065\u0064\u003a\u0020\u0025\u0076",_fde );}else {return nil ,_fde ;};};return _gac ,nil ; 32 | };func (_cbe *Decoder )UncompressMMR ()(_geb *_d .Bitmap ,_eda error ){_geb =_d .New (_cbe ._db ,_cbe ._bb );_egg :=make ([]int ,_geb .Width +5);_bg :=make ([]int ,_geb .Width +5);_bg [0]=_geb .Width ;_ec :=1;var _gcg int ;for _ff :=0;_ff < _geb .Height ; 33 | _ff ++{_gcg ,_eda =_cbe .uncompress2d (_cbe ._fa ,_bg ,_ec ,_egg ,_geb .Width );if _eda !=nil {return nil ,_eda ;};if _gcg ==EOF {break ;};if _gcg > 0{_eda =_cbe .fillBitmap (_geb ,_ff ,_egg ,_gcg );if _eda !=nil {return nil ,_eda ;};};_bg ,_egg =_egg ,_bg ; 34 | _ec =_gcg ;};if _eda =_cbe .detectAndSkipEOL ();_eda !=nil {return nil ,_eda ;};_cbe ._fa .align ();return _geb ,nil ;};func (_eaf *runData )fillBuffer (_bfbb int )error {_eaf ._gdd =_bfbb ;_ ,_ade :=_eaf ._dcb .Seek (int64 (_bfbb ),_e .SeekStart );if _ade !=nil {if _ade ==_e .EOF {_ga .Log .Debug ("\u0053\u0065\u0061\u006b\u0020\u0045\u004f\u0046"); 35 | _eaf ._ebdc =-1;}else {return _ade ;};};if _ade ==nil {_eaf ._ebdc ,_ade =_eaf ._dcb .Read (_eaf ._dcbf );if _ade !=nil {if _ade ==_e .EOF {_ga .Log .Trace ("\u0052\u0065\u0061\u0064\u0020\u0045\u004f\u0046");_eaf ._ebdc =-1;}else {return _ade ;};};};if _eaf ._ebdc > -1&&_eaf ._ebdc < 3{for _eaf ._ebdc < 3{_aad ,_cgd :=_eaf ._dcb .ReadByte (); 36 | if _cgd !=nil {if _cgd ==_e .EOF {_eaf ._dcbf [_eaf ._ebdc ]=0;}else {return _cgd ;};}else {_eaf ._dcbf [_eaf ._ebdc ]=_aad &0xFF;};_eaf ._ebdc ++;};};_eaf ._ebdc -=3;if _eaf ._ebdc < 0{_eaf ._dcbf =make ([]byte ,len (_eaf ._dcbf ));_eaf ._ebdc =len (_eaf ._dcbf )-3; 37 | };return nil ;};func New (r *_gd .Reader ,width ,height int ,dataOffset ,dataLength int64 )(*Decoder ,error ){_aga :=&Decoder {_db :width ,_bb :height };_ea ,_deb :=r .NewPartialReader (int (dataOffset ),int (dataLength ),false );if _deb !=nil {return nil ,_deb ; 38 | };_ged ,_deb :=_egc (_ea );if _deb !=nil {return nil ,_deb ;};_ ,_deb =r .Seek (_ea .RelativePosition (),_e .SeekCurrent );if _deb !=nil {return nil ,_deb ;};_aga ._fa =_ged ;if _fd :=_aga .initTables ();_fd !=nil {return nil ,_fd ;};return _aga ,nil ; 39 | };func (_fga *Decoder )uncompress2d (_bc *runData ,_egga []int ,_gcb int ,_bdf []int ,_eaed int )(int ,error ){var (_bbd int ;_gbb int ;_efac int ;_aggc =true ;_ccc error ;_dgc *code ;);_egga [_gcb ]=_eaed ;_egga [_gcb +1]=_eaed ;_egga [_gcb +2]=_eaed +1; 40 | _egga [_gcb +3]=_eaed +1;_bef :for _efac < _eaed {_dgc ,_ccc =_bc .uncompressGetCode (_fga ._ae );if _ccc !=nil {return EOL ,nil ;};if _dgc ==nil {_bc ._fcf ++;break _bef ;};_bc ._fcf +=_dgc ._b ;switch mmrCode (_dgc ._dd ){case _gc :_efac =_egga [_bbd ]; 41 | case _eb :_efac =_egga [_bbd ]+1;case _f :_efac =_egga [_bbd ]-1;case _gg :for {var _fb []*code ;if _aggc {_fb =_fga ._bad ;}else {_fb =_fga ._efa ;};_dgc ,_ccc =_bc .uncompressGetCode (_fb );if _ccc !=nil {return 0,_ccc ;};if _dgc ==nil {break _bef ;}; 42 | _bc ._fcf +=_dgc ._b ;if _dgc ._dd < 64{if _dgc ._dd < 0{_bdf [_gbb ]=_efac ;_gbb ++;_dgc =nil ;break _bef ;};_efac +=_dgc ._dd ;_bdf [_gbb ]=_efac ;_gbb ++;break ;};_efac +=_dgc ._dd ;};_gce :=_efac ;_eef :for {var _fe []*code ;if !_aggc {_fe =_fga ._bad ; 43 | }else {_fe =_fga ._efa ;};_dgc ,_ccc =_bc .uncompressGetCode (_fe );if _ccc !=nil {return 0,_ccc ;};if _dgc ==nil {break _bef ;};_bc ._fcf +=_dgc ._b ;if _dgc ._dd < 64{if _dgc ._dd < 0{_bdf [_gbb ]=_efac ;_gbb ++;break _bef ;};_efac +=_dgc ._dd ;if _efac < _eaed ||_efac !=_gce {_bdf [_gbb ]=_efac ; 44 | _gbb ++;};break _eef ;};_efac +=_dgc ._dd ;};for _efac < _eaed &&_egga [_bbd ]<=_efac {_bbd +=2;};continue _bef ;case _dce :_bbd ++;_efac =_egga [_bbd ];_bbd ++;continue _bef ;case _ce :_efac =_egga [_bbd ]+2;case _cab :_efac =_egga [_bbd ]-2;case _ee :_efac =_egga [_bbd ]+3; 45 | case _cb :_efac =_egga [_bbd ]-3;default:if _bc ._fcf ==12&&_dgc ._dd ==EOL {_bc ._fcf =0;if _ ,_ccc =_fga .uncompress1d (_bc ,_egga ,_eaed );_ccc !=nil {return 0,_ccc ;};_bc ._fcf ++;if _ ,_ccc =_fga .uncompress1d (_bc ,_bdf ,_eaed );_ccc !=nil {return 0,_ccc ; 46 | };_abb ,_ceg :=_fga .uncompress1d (_bc ,_egga ,_eaed );if _ceg !=nil {return EOF ,_ceg ;};_bc ._fcf ++;return _abb ,nil ;};_efac =_eaed ;continue _bef ;};if _efac <=_eaed {_aggc =!_aggc ;_bdf [_gbb ]=_efac ;_gbb ++;if _bbd > 0{_bbd --;}else {_bbd ++;}; 47 | for _efac < _eaed &&_egga [_bbd ]<=_efac {_bbd +=2;};};};if _bdf [_gbb ]!=_eaed {_bdf [_gbb ]=_eaed ;};if _dgc ==nil {return EOL ,nil ;};return _gbb ,nil ;};type Decoder struct{_db ,_bb int ;_fa *runData ;_bad []*code ;_efa []*code ;_ae []*code ;};func (_dg *Decoder )initTables ()(_ggd error ){if _dg ._bad ==nil {_dg ._bad ,_ggd =_dg .createLittleEndianTable (_bag ); 48 | if _ggd !=nil {return ;};_dg ._efa ,_ggd =_dg .createLittleEndianTable (_ge );if _ggd !=nil {return ;};_dg ._ae ,_ggd =_dg .createLittleEndianTable (_edd );if _ggd !=nil {return ;};};return nil ;};func (_ad *code )String ()string {return _g .Sprintf ("\u0025\u0064\u002f\u0025\u0064\u002f\u0025\u0064",_ad ._b ,_ad ._a ,_ad ._dd ); 49 | };func (_fce *runData )uncompressGetCodeLittleEndian (_bbg []*code )(*code ,error ){_bfd ,_gbg :=_fce .uncompressGetNextCodeLittleEndian ();if _gbg !=nil {_ga .Log .Debug ("\u0055n\u0063\u006fm\u0070\u0072\u0065\u0073s\u0047\u0065\u0074N\u0065\u0078\u0074\u0043\u006f\u0064\u0065\u004c\u0069tt\u006c\u0065\u0045n\u0064\u0069a\u006e\u0020\u0066\u0061\u0069\u006ce\u0064\u003a \u0025\u0076",_gbg ); 50 | return nil ,_gbg ;};_bfd &=0xffffff;_dec :=_bfd >>(_bed -_gcf );_ddg :=_bbg [_dec ];if _ddg !=nil &&_ddg ._df {_dec =(_bfd >>(_bed -_gcf -_dfe ))&_ag ;_ddg =_ddg ._ef [_dec ];};return _ddg ,nil ;};func _ed (_ab ,_gb int )int {if _ab < _gb {return _gb ; 51 | };return _ab ;}; -------------------------------------------------------------------------------- /internal/jbig2/encoder/arithmetic/arithmetic.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 arithmetic ;import (_f "bytes";_d "github.com/unidoc/unipdf/v4/common";_g "github.com/unidoc/unipdf/v4/internal/jbig2/bitmap";_dd "github.com/unidoc/unipdf/v4/internal/jbig2/errors";_b "io";);func (_cc *Encoder )Flush (){_cc ._ec =0;_cc ._fb =nil ; 13 | _cc ._ce =-1};var _cde =[]state {{0x5601,1,1,1},{0x3401,2,6,0},{0x1801,3,9,0},{0x0AC1,4,12,0},{0x0521,5,29,0},{0x0221,38,33,0},{0x5601,7,6,1},{0x5401,8,14,0},{0x4801,9,14,0},{0x3801,10,14,0},{0x3001,11,17,0},{0x2401,12,18,0},{0x1C01,13,20,0},{0x1601,29,21,0},{0x5601,15,14,1},{0x5401,16,14,0},{0x5101,17,15,0},{0x4801,18,16,0},{0x3801,19,17,0},{0x3401,20,18,0},{0x3001,21,19,0},{0x2801,22,19,0},{0x2401,23,20,0},{0x2201,24,21,0},{0x1C01,25,22,0},{0x1801,26,23,0},{0x1601,27,24,0},{0x1401,28,25,0},{0x1201,29,26,0},{0x1101,30,27,0},{0x0AC1,31,28,0},{0x09C1,32,29,0},{0x08A1,33,30,0},{0x0521,34,31,0},{0x0441,35,32,0},{0x02A1,36,33,0},{0x0221,37,34,0},{0x0141,38,35,0},{0x0111,39,36,0},{0x0085,40,37,0},{0x0049,41,38,0},{0x0025,42,39,0},{0x0015,43,40,0},{0x0009,44,41,0},{0x0005,45,42,0},{0x0001,45,43,0},{0x5601,46,46,0}}; 14 | func (_dgf *Encoder )renormalize (){for {_dgf ._c <<=1;_dgf ._ff <<=1;_dgf ._bf --;if _dgf ._bf ==0{_dgf .byteOut ();};if (_dgf ._c &0x8000)!=0{break ;};};};const (_dcd =65536;_befb =20*1024;);func (_af *Encoder )EncodeIAID (symbolCodeLength ,value int )(_ceg error ){_d .Log .Trace ("\u0045\u006e\u0063\u006f\u0064\u0065\u0020\u0049A\u0049\u0044\u002e S\u0079\u006d\u0062\u006f\u006c\u0043o\u0064\u0065\u004c\u0065\u006e\u0067\u0074\u0068\u003a\u0020\u0027\u0025\u0064\u0027\u002c \u0056\u0061\u006c\u0075\u0065\u003a\u0020\u0027%\u0064\u0027",symbolCodeLength ,value ); 15 | if _ceg =_af .encodeIAID (symbolCodeLength ,value );_ceg !=nil {return _dd .Wrap (_ceg ,"\u0045\u006e\u0063\u006f\u0064\u0065\u0049\u0041\u0049\u0044","");};return nil ;};func (_faga *Encoder )WriteTo (w _b .Writer )(int64 ,error ){const _bec ="\u0045n\u0063o\u0064\u0065\u0072\u002e\u0057\u0072\u0069\u0074\u0065\u0054\u006f"; 16 | var _bad int64 ;for _db ,_fdf :=range _faga ._fb {_cga ,_afb :=w .Write (_fdf );if _afb !=nil {return 0,_dd .Wrapf (_afb ,_bec ,"\u0066\u0061\u0069\u006c\u0065\u0064\u0020\u0061\u0074\u0020\u0069'\u0074\u0068\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u0063h\u0075\u006e\u006b",_db ); 17 | };_bad +=int64 (_cga );};_faga ._a =_faga ._a [:_faga ._ec ];_ggg ,_bac :=w .Write (_faga ._a );if _bac !=nil {return 0,_dd .Wrap (_bac ,_bec ,"\u0062u\u0066f\u0065\u0072\u0065\u0064\u0020\u0063\u0068\u0075\u006e\u006b\u0073");};_bad +=int64 (_ggg );return _bad ,nil ; 18 | };func (_cf *Encoder )encodeInteger (_fdg Class ,_aabg int )error {const _ced ="E\u006e\u0063\u006f\u0064er\u002ee\u006e\u0063\u006f\u0064\u0065I\u006e\u0074\u0065\u0067\u0065\u0072";if _aabg > 2000000000||_aabg < -2000000000{return _dd .Errorf (_ced ,"\u0061\u0072\u0069\u0074\u0068\u006d\u0065\u0074i\u0063\u0020\u0065nc\u006f\u0064\u0065\u0072\u0020\u002d \u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0069\u006e\u0074\u0065\u0067\u0065\u0072 \u0076\u0061\u006c\u0075\u0065\u003a\u0020\u0027%\u0064\u0027",_aabg ); 19 | };_cge :=_cf ._ca [_fdg ];_efc :=uint32 (1);var _cdb int ;for ;;_cdb ++{if _gb [_cdb ]._eb <=_aabg &&_gb [_cdb ]._bg >=_aabg {break ;};};if _aabg < 0{_aabg =-_aabg ;};_aabg -=int (_gb [_cdb ]._ge );_bcb :=_gb [_cdb ]._fa ;for _dac :=uint8 (0);_dac < _gb [_cdb ]._fc ; 20 | _dac ++{_egf :=_bcb &1;if _gba :=_cf .encodeBit (_cge ,_efc ,_egf );_gba !=nil {return _dd .Wrap (_gba ,_ced ,"");};_bcb >>=1;if _efc &0x100> 0{_efc =(((_efc <<1)|uint32 (_egf ))&0x1ff)|0x100;}else {_efc =(_efc <<1)|uint32 (_egf );};};_aabg <<=32-_gb [_cdb ]._fac ; 21 | for _bea :=uint8 (0);_bea < _gb [_cdb ]._fac ;_bea ++{_fcb :=uint8 ((uint32 (_aabg )&0x80000000)>>31);if _fbf :=_cf .encodeBit (_cge ,_efc ,_fcb );_fbf !=nil {return _dd .Wrap (_fbf ,_ced ,"\u006d\u006f\u0076\u0065 \u0064\u0061\u0074\u0061\u0020\u0074\u006f\u0020\u0074\u0068e\u0020t\u006f\u0070\u0020\u006f\u0066\u0020\u0077o\u0072\u0064"); 22 | };_aabg <<=1;if _efc &0x100!=0{_efc =(((_efc <<1)|uint32 (_fcb ))&0x1ff)|0x100;}else {_efc =(_efc <<1)|uint32 (_fcb );};};return nil ;};func (_aeb *Encoder )byteOut (){if _aeb ._fag ==0xff{_aeb .rBlock ();return ;};if _aeb ._ff < 0x8000000{_aeb .lBlock (); 23 | return ;};_aeb ._fag ++;if _aeb ._fag !=0xff{_aeb .lBlock ();return ;};_aeb ._ff &=0x7ffffff;_aeb .rBlock ();};func (_cgf *Encoder )Reset (){_cgf ._c =0x8000;_cgf ._ff =0;_cgf ._bf =12;_cgf ._ce =-1;_cgf ._fag =0;_cgf ._fd =nil ;_cgf ._dc =_fce (_dcd ); 24 | };func (_fee *Encoder )EncodeOOB (proc Class )(_bc error ){_d .Log .Trace ("E\u006e\u0063\u006f\u0064\u0065\u0020O\u004f\u0042\u0020\u0077\u0069\u0074\u0068\u0020\u0043l\u0061\u0073\u0073:\u0020'\u0025\u0073\u0027",proc );if _bc =_fee .encodeOOB (proc ); 25 | _bc !=nil {return _dd .Wrap (_bc ,"\u0045n\u0063\u006f\u0064\u0065\u004f\u004fB","");};return nil ;};func (_de *Encoder )EncodeBitmap (bm *_g .Bitmap ,duplicateLineRemoval bool )error {_d .Log .Trace ("\u0045n\u0063\u006f\u0064\u0065 \u0042\u0069\u0074\u006d\u0061p\u0020[\u0025d\u0078\u0025\u0064\u005d\u002c\u0020\u0025s",bm .Width ,bm .Height ,bm ); 26 | var (_ecf ,_bfd uint8 ;_dcb ,_cef ,_dg uint16 ;_deb ,_gc ,_gdf byte ;_aag ,_ddd ,_beb int ;_gca ,_ac []byte ;);for _cea :=0;_cea < bm .Height ;_cea ++{_deb ,_gc =0,0;if _cea >=2{_deb =bm .Data [(_cea -2)*bm .RowStride ];};if _cea >=1{_gc =bm .Data [(_cea -1)*bm .RowStride ]; 27 | if duplicateLineRemoval {_ddd =_cea *bm .RowStride ;_gca =bm .Data [_ddd :_ddd +bm .RowStride ];_beb =(_cea -1)*bm .RowStride ;_ac =bm .Data [_beb :_beb +bm .RowStride ];if _f .Equal (_gca ,_ac ){_bfd =_ecf ^1;_ecf =1;}else {_bfd =_ecf ;_ecf =0;};};};if duplicateLineRemoval {if _eaf :=_de .encodeBit (_de ._dc ,_gd ,_bfd ); 28 | _eaf !=nil {return _eaf ;};if _ecf !=0{continue ;};};_gdf =bm .Data [_cea *bm .RowStride ];_dcb =uint16 (_deb >>5);_cef =uint16 (_gc >>4);_deb <<=3;_gc <<=4;_dg =0;for _aag =0;_aag < bm .Width ;_aag ++{_ded :=uint32 (_dcb <<11|_cef <<4|_dg );_bef :=(_gdf &0x80)>>7; 29 | _ab :=_de .encodeBit (_de ._dc ,_ded ,_bef );if _ab !=nil {return _ab ;};_dcb <<=1;_cef <<=1;_dg <<=1;_dcb |=uint16 ((_deb &0x80)>>7);_cef |=uint16 ((_gc &0x80)>>7);_dg |=uint16 (_bef );_fbe :=_aag %8;_ege :=_aag /8+1;if _fbe ==4&&_cea >=2{_deb =0;if _ege < bm .RowStride {_deb =bm .Data [(_cea -2)*bm .RowStride +_ege ]; 30 | };}else {_deb <<=1;};if _fbe ==3&&_cea >=1{_gc =0;if _ege < bm .RowStride {_gc =bm .Data [(_cea -1)*bm .RowStride +_ege ];};}else {_gc <<=1;};if _fbe ==7{_gdf =0;if _ege < bm .RowStride {_gdf =bm .Data [_cea *bm .RowStride +_ege ];};}else {_gdf <<=1;}; 31 | _dcb &=31;_cef &=127;_dg &=15;};};return nil ;};func (_ffcg *Encoder )lBlock (){if _ffcg ._ce >=0{_ffcg .emit ();};_ffcg ._ce ++;_ffcg ._fag =uint8 (_ffcg ._ff >>19);_ffcg ._ff &=0x7ffff;_ffcg ._bf =8;};func (_gac *Encoder )encodeBit (_gf *codingContext ,_bcf uint32 ,_bgcg uint8 )error {const _aab ="\u0045\u006e\u0063\u006f\u0064\u0065\u0072\u002e\u0065\u006e\u0063\u006fd\u0065\u0042\u0069\u0074"; 32 | _gac ._ffb ++;if _bcf >=uint32 (len (_gf ._da )){return _dd .Errorf (_aab ,"\u0061r\u0069\u0074h\u006d\u0065\u0074i\u0063\u0020\u0065\u006e\u0063\u006f\u0064e\u0072\u0020\u002d\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0074\u0078\u0020\u006e\u0075m\u0062\u0065\u0072\u003a\u0020\u0027\u0025\u0064\u0027",_bcf ); 33 | };_ged :=_gf ._da [_bcf ];_acff :=_gf .mps (_bcf );_ggga :=_cde [_ged ]._ag ;_d .Log .Trace ("\u0045\u0043\u003a\u0020\u0025d\u0009\u0020D\u003a\u0020\u0025d\u0009\u0020\u0049\u003a\u0020\u0025d\u0009\u0020\u004dPS\u003a \u0025\u0064\u0009\u0020\u0051\u0045\u003a \u0025\u0030\u0034\u0058\u0009\u0020\u0020\u0041\u003a\u0020\u0025\u0030\u0034\u0058\u0009\u0020\u0043\u003a %\u0030\u0038\u0058\u0009\u0020\u0043\u0054\u003a\u0020\u0025\u0064\u0009\u0020\u0042\u003a\u0020\u0025\u0030\u0032\u0058\u0009\u0020\u0042\u0050\u003a\u0020\u0025\u0064",_gac ._ffb ,_bgcg ,_ged ,_acff ,_ggga ,_gac ._c ,_gac ._ff ,_gac ._bf ,_gac ._fag ,_gac ._ce ); 34 | if _bgcg ==0{_gac .code0 (_gf ,_bcf ,_ggga ,_ged );}else {_gac .code1 (_gf ,_bcf ,_ggga ,_ged );};return nil ;};func (_gad *Encoder )encodeIAID (_gff ,_eda int )error {if _gad ._fd ==nil {_gad ._fd =_fce (1<>31);if _cgc :=_gad .encodeBit (_gad ._fd ,_eag ,_egd );_cgc !=nil {return _cgc ;};_gcf =(_gcf <<1)|uint32 (_egd ); 36 | _eda <<=1;};return nil ;};func (_bda *Encoder )flush (){_bda .setBits ();_bda ._ff <<=_bda ._bf ;_bda .byteOut ();_bda ._ff <<=_bda ._bf ;_bda .byteOut ();_bda .emit ();if _bda ._fag !=0xff{_bda ._ce ++;_bda ._fag =0xff;_bda .emit ();};_bda ._ce ++;_bda ._fag =0xac; 37 | _bda ._ce ++;_bda .emit ();};func (_ga *Encoder )codeMPS (_dff *codingContext ,_cd uint32 ,_ede uint16 ,_aff byte ){_ga ._c -=_ede ;if _ga ._c &0x8000!=0{_ga ._ff +=uint32 (_ede );return ;};if _ga ._c < _ede {_ga ._c =_ede ;}else {_ga ._ff +=uint32 (_ede ); 38 | };_dff ._da [_cd ]=_cde [_aff ]._dbb ;_ga .renormalize ();};func (_cage *Encoder )code0 (_aee *codingContext ,_bbac uint32 ,_fff uint16 ,_gdd byte ){if _aee .mps (_bbac )==0{_cage .codeMPS (_aee ,_bbac ,_fff ,_gdd );}else {_cage .codeLPS (_aee ,_bbac ,_fff ,_gdd ); 39 | };};type state struct{_ag uint16 ;_dbb ,_daa uint8 ;_gggb uint8 ;};type codingContext struct{_da []byte ;_eg []byte ;};var _gb =[]intEncRangeS {{0,3,0,2,0,2},{-1,-1,9,4,0,0},{-3,-2,5,3,2,1},{4,19,2,3,4,4},{-19,-4,3,3,4,4},{20,83,6,4,20,6},{-83,-20,7,4,20,6},{84,339,14,5,84,8},{-339,-84,15,5,84,8},{340,4435,30,6,340,12},{-4435,-340,31,6,340,12},{4436,2000000000,62,6,4436,32},{-2000000000,-4436,63,6,4436,32}}; 40 | func (_ed *codingContext )flipMps (_ea uint32 ){_ed ._eg [_ea ]=1-_ed ._eg [_ea ]};func (_bfb *Encoder )emit (){if _bfb ._ec ==_befb {_bfb ._fb =append (_bfb ._fb ,_bfb ._a );_bfb ._a =make ([]byte ,_befb );_bfb ._ec =0;};_bfb ._a [_bfb ._ec ]=_bfb ._fag ; 41 | _bfb ._ec ++;};type intEncRangeS struct{_eb ,_bg int ;_fa ,_fc uint8 ;_ge uint16 ;_fac uint8 ;};const (IAAI Class =iota ;IADH ;IADS ;IADT ;IADW ;IAEX ;IAFS ;IAIT ;IARDH ;IARDW ;IARDX ;IARDY ;IARI ;);type Encoder struct{_ff uint32 ;_c uint16 ;_bf ,_fag uint8 ; 42 | _ce int ;_ffb int ;_fb [][]byte ;_a []byte ;_ec int ;_dc *codingContext ;_ca [13]*codingContext ;_fd *codingContext ;};func _fce (_fe int )*codingContext {return &codingContext {_da :make ([]byte ,_fe ),_eg :make ([]byte ,_fe )};};func (_fagc *Encoder )setBits (){_ebb :=_fagc ._ff +uint32 (_fagc ._c ); 43 | _fagc ._ff |=0xffff;if _fagc ._ff >=_ebb {_fagc ._ff -=0x8000;};};func (_cae *Encoder )dataSize ()int {return _befb *len (_cae ._fb )+_cae ._ec };func (_bb *Encoder )Refine (iTemp ,iTarget *_g .Bitmap ,ox ,oy int )error {for _gda :=0;_gda < iTarget .Height ; 44 | _gda ++{var _cee int ;_ceac :=_gda +oy ;var (_ecb ,_ef ,_bba ,_ecc ,_gcb uint16 ;_cag ,_fdb ,_ceb ,_bfg ,_bfa byte ;);if _ceac >=1&&(_ceac -1)< iTemp .Height {_cag =iTemp .Data [(_ceac -1)*iTemp .RowStride ];};if _ceac >=0&&_ceac < iTemp .Height {_fdb =iTemp .Data [_ceac *iTemp .RowStride ]; 45 | };if _ceac >=-1&&_ceac +1< iTemp .Height {_ceb =iTemp .Data [(_ceac +1)*iTemp .RowStride ];};if _gda >=1{_bfg =iTarget .Data [(_gda -1)*iTarget .RowStride ];};_bfa =iTarget .Data [_gda *iTarget .RowStride ];_caa :=uint (6+ox );_ecb =uint16 (_cag >>_caa ); 46 | _ef =uint16 (_fdb >>_caa );_bba =uint16 (_ceb >>_caa );_ecc =uint16 (_bfg >>6);_df :=uint (2-ox );_cag <<=_df ;_fdb <<=_df ;_ceb <<=_df ;_bfg <<=2;for _cee =0;_cee < iTarget .Width ;_cee ++{_bgd :=(_ecb <<10)|(_ef <<7)|(_bba <<4)|(_ecc <<1)|_gcb ;_cebf :=_bfa >>7; 47 | _ffc :=_bb .encodeBit (_bb ._dc ,uint32 (_bgd ),_cebf );if _ffc !=nil {return _ffc ;};_ecb <<=1;_ef <<=1;_bba <<=1;_ecc <<=1;_ecb |=uint16 (_cag >>7);_ef |=uint16 (_fdb >>7);_bba |=uint16 (_ceb >>7);_ecc |=uint16 (_bfg >>7);_gcb =uint16 (_cebf );_ceeg :=_cee %8; 48 | _ae :=_cee /8+1;if _ceeg ==5+ox {_cag ,_fdb ,_ceb =0,0,0;if _ae < iTemp .RowStride &&_ceac >=1&&(_ceac -1)< iTemp .Height {_cag =iTemp .Data [(_ceac -1)*iTemp .RowStride +_ae ];};if _ae < iTemp .RowStride &&_ceac >=0&&_ceac < iTemp .Height {_fdb =iTemp .Data [_ceac *iTemp .RowStride +_ae ]; 49 | };if _ae < iTemp .RowStride &&_ceac >=-1&&(_ceac +1)< iTemp .Height {_ceb =iTemp .Data [(_ceac +1)*iTemp .RowStride +_ae ];};}else {_cag <<=1;_fdb <<=1;_ceb <<=1;};if _ceeg ==5&&_gda >=1{_bfg =0;if _ae < iTarget .RowStride {_bfg =iTarget .Data [(_gda -1)*iTarget .RowStride +_ae ]; 50 | };}else {_bfg <<=1;};if _ceeg ==7{_bfa =0;if _ae < iTarget .RowStride {_bfa =iTarget .Data [_gda *iTarget .RowStride +_ae ];};}else {_bfa <<=1;};_ecb &=7;_ef &=7;_bba &=7;_ecc &=7;};};return nil ;};type Class int ;func (_cg *Encoder )DataSize ()int {return _cg .dataSize ()}; 51 | func (_fec *Encoder )Init (){_fec ._dc =_fce (_dcd );_fec ._c =0x8000;_fec ._ff =0;_fec ._bf =12;_fec ._ce =-1;_fec ._fag =0;_fec ._ec =0;_fec ._a =make ([]byte ,_befb );for _aa :=0;_aa < len (_fec ._ca );_aa ++{_fec ._ca [_aa ]=_fce (512);};_fec ._fd =nil ; 52 | };var _ _b .WriterTo =&Encoder {};func (_bgc *Encoder )Final (){_bgc .flush ()};func (_acc *Encoder )code1 (_bgg *codingContext ,_ccc uint32 ,_cce uint16 ,_cebd byte ){if _bgg .mps (_ccc )==1{_acc .codeMPS (_bgg ,_ccc ,_cce ,_cebd );}else {_acc .codeLPS (_bgg ,_ccc ,_cce ,_cebd ); 53 | };};func (_gg *Encoder )EncodeInteger (proc Class ,value int )(_ba error ){_d .Log .Trace ("\u0045\u006eco\u0064\u0065\u0020I\u006e\u0074\u0065\u0067er:\u0027%d\u0027\u0020\u0077\u0069\u0074\u0068\u0020Cl\u0061\u0073\u0073\u003a\u0020\u0027\u0025s\u0027",value ,proc ); 54 | if _ba =_gg .encodeInteger (proc ,value );_ba !=nil {return _dd .Wrap (_ba ,"\u0045\u006e\u0063\u006f\u0064\u0065\u0049\u006e\u0074\u0065\u0067\u0065\u0072","");};return nil ;};func (_fgc *Encoder )rBlock (){if _fgc ._ce >=0{_fgc .emit ();};_fgc ._ce ++; 55 | _fgc ._fag =uint8 (_fgc ._ff >>20);_fgc ._ff &=0xfffff;_fgc ._bf =7;};const _gd =0x9b25;func (_be *codingContext )mps (_bd uint32 )int {return int (_be ._eg [_bd ])};func (_acf *Encoder )codeLPS (_ddb *codingContext ,_bdb uint32 ,_ee uint16 ,_egc byte ){_acf ._c -=_ee ; 56 | if _acf ._c < _ee {_acf ._ff +=uint32 (_ee );}else {_acf ._c =_ee ;};if _cde [_egc ]._gggb ==1{_ddb .flipMps (_bdb );};_ddb ._da [_bdb ]=_cde [_egc ]._daa ;_acf .renormalize ();};func (_fg Class )String ()string {switch _fg {case IAAI :return "\u0049\u0041\u0041\u0049"; 57 | case IADH :return "\u0049\u0041\u0044\u0048";case IADS :return "\u0049\u0041\u0044\u0053";case IADT :return "\u0049\u0041\u0044\u0054";case IADW :return "\u0049\u0041\u0044\u0057";case IAEX :return "\u0049\u0041\u0045\u0058";case IAFS :return "\u0049\u0041\u0046\u0053"; 58 | case IAIT :return "\u0049\u0041\u0049\u0054";case IARDH :return "\u0049\u0041\u0052D\u0048";case IARDW :return "\u0049\u0041\u0052D\u0057";case IARDX :return "\u0049\u0041\u0052D\u0058";case IARDY :return "\u0049\u0041\u0052D\u0059";case IARI :return "\u0049\u0041\u0052\u0049"; 59 | default:return "\u0055N\u004b\u004e\u004f\u0057\u004e";};};func (_ecfa *Encoder )encodeOOB (_gae Class )error {_ece :=_ecfa ._ca [_gae ];_bbf :=_ecfa .encodeBit (_ece ,1,1);if _bbf !=nil {return _bbf ;};_bbf =_ecfa .encodeBit (_ece ,3,0);if _bbf !=nil {return _bbf ; 60 | };_bbf =_ecfa .encodeBit (_ece ,6,0);if _bbf !=nil {return _bbf ;};_bbf =_ecfa .encodeBit (_ece ,12,0);if _bbf !=nil {return _bbf ;};return nil ;};func New ()*Encoder {_ad :=&Encoder {};_ad .Init ();return _ad }; -------------------------------------------------------------------------------- /internal/jbig2/errors/errors.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 errors ;import (_b "fmt";_de "golang.org/x/xerrors";);type processError struct{_g string ;_aa string ;_dc string ;_f error ;};func (_gc *processError )Error ()string {var _c string ;if _gc ._g !=""{_c =_gc ._g ;};_c +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_gc ._aa ; 13 | if _gc ._dc !=""{_c +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_gc ._dc ;};if _gc ._f !=nil {_c +="\u002e\u0020"+_gc ._f .Error ();};return _c ;};func (_ac *processError )Unwrap ()error {return _ac ._f };var _ _de .Wrapper =(*processError )(nil ); 14 | func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _eg ,_be :=err .(*processError );_be {_eg ._g ="";};_df :=_bb (_b .Sprintf (message ,arguments ...),processName );_df ._f =err ;return _df ;};func _bb (_deg ,_e string )*processError {return &processError {_g :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_dc :_deg ,_aa :_e }; 15 | };func Wrap (err error ,processName ,message string )error {if _cd ,_bg :=err .(*processError );_bg {_cd ._g ="";};_dcd :=_bb (message ,processName );_dcd ._f =err ;return _dcd ;};func Error (processName ,message string )error {return _bb (message ,processName )}; 16 | func Errorf (processName ,message string ,arguments ...interface{})error {return _bb (_b .Sprintf (message ,arguments ...),processName );}; -------------------------------------------------------------------------------- /internal/jbig2/internal/internal.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 internal ;import _b "errors";var ErrOOB =_b .New ("o\u0075\u0074\u0020\u006f\u0066\u0020\u0062\u0061\u006e\u0064"); -------------------------------------------------------------------------------- /internal/jbig2/jbig2.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 jbig2 ;import (_f "github.com/unidoc/unipdf/v4/internal/bitwise";_a "github.com/unidoc/unipdf/v4/internal/jbig2/decoder";_e "github.com/unidoc/unipdf/v4/internal/jbig2/document";_d "github.com/unidoc/unipdf/v4/internal/jbig2/document/segments"; 13 | _ba "github.com/unidoc/unipdf/v4/internal/jbig2/errors";_g "sort";);type Globals map[int ]*_d .Header ;func (_ge Globals )ToDocumentGlobals ()*_e .Globals {if _ge ==nil {return nil ;};_ec :=[]*_d .Header {};for _ ,_eb :=range _ge {_ec =append (_ec ,_eb ); 14 | };_g .Slice (_ec ,func (_bc ,_aa int )bool {return _ec [_bc ].SegmentNumber < _ec [_aa ].SegmentNumber });return &_e .Globals {Segments :_ec };};func DecodeGlobals (encoded []byte )(Globals ,error ){const _c ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073"; 15 | _ea :=_f .NewReader (encoded );_ab ,_fd :=_e .DecodeDocument (_ea ,nil );if _fd !=nil {return nil ,_ba .Wrap (_fd ,_c ,"");};if _ab .GlobalSegments ==nil ||(_ab .GlobalSegments .Segments ==nil ){return nil ,_ba .Error (_c ,"\u006eo\u0020\u0067\u006c\u006f\u0062\u0061\u006c\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064"); 16 | };_fb :=Globals {};for _ ,_bf :=range _ab .GlobalSegments .Segments {_fb [int (_bf .SegmentNumber )]=_bf ;};return _fb ,nil ;};func DecodeBytes (encoded []byte ,parameters _a .Parameters ,globals ...Globals )([]byte ,error ){var _ad Globals ;if len (globals )> 0{_ad =globals [0]; 17 | };_ac ,_df :=_a .Decode (encoded ,parameters ,_ad .ToDocumentGlobals ());if _df !=nil {return nil ,_df ;};return _ac .DecodeNextPage ();}; -------------------------------------------------------------------------------- /internal/precision/precision.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 precision ;import _g "math";func RoundDefault (value float64 )float64 {return RoundFloat (value ,DefaultPrecision )};const (DefaultPrecision =4;);func RoundFloat (value float64 ,precision int )float64 {_f :=_g .Pow (10,float64 (precision ));return _g .Round (value *_f )/_f ; 13 | }; -------------------------------------------------------------------------------- /internal/sampling/sampling.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 sampling ;import (_fb "github.com/unidoc/unipdf/v4/internal/bitwise";_e "github.com/unidoc/unipdf/v4/internal/imageutil";_d "io";);func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _cg []uint32 ;_aa :=bitsPerSample ;var _b uint32 ; 13 | var _ca byte ;_ee :=0;_bc :=0;_fg :=0;for _fg < len (data ){if _ee > 0{_agd :=_ee ;if _aa < _agd {_agd =_aa ;};_b =(_b <>uint (8-_agd ));_ee -=_agd ;if _ee > 0{_ca =_ca <>uint (_ee ));if _cbb < 8{_ca =_aef <=bitsPerSample {_bb :=_ee ;if _aa < _bb {_bb =_aa ;};_b =(_b <>uint (8-_bb ));_ee -=_bb ;if _ee > 0{_ca =_ca < 0{_bd :=_ff ;if _bg < _bd {_bd =_bg ;};_ed =(_ed <>uint (bitsPerInputSample -_bd ));_ff -=_bd ;if _ff > 0{_eb =_eb <>uint (_ff )); 25 | if _age < bitsPerInputSample {_eb =_ffe <=bitsPerOutputSample {_bbf :=_ff ;if _bg < _bbf {_bbf =_bg ;};_ed =(_ed <>uint (bitsPerInputSample -_bbf )); 26 | _ff -=_bbf ;if _ff > 0{_eb =_eb < 0&&_bg < bitsPerOutputSample {_ed <<=uint (_bg );_deb =append (_deb ,_ed );};return _deb ; 27 | }; -------------------------------------------------------------------------------- /internal/strutils/strutils.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 strutils ;import (_e "bytes";_df "github.com/unidoc/unipdf/v4/common";_f "unicode/utf16";);func PDFDocEncodingToString (b []byte )string {return string (PDFDocEncodingToRunes (b ))};func init (){_b =map[rune ]byte {};for _a ,_bb :=range _bge {_b [_bb ]=_a ; 13 | };};var _b map[rune ]byte ;func StringToUTF16 (s string )string {_dd :=_f .Encode ([]rune (s ));var _g _e .Buffer ;for _ ,_egb :=range _dd {_g .WriteByte (byte ((_egb >>8)&0xff));_g .WriteByte (byte (_egb &0xff));};return _g .String ();};func PDFDocEncodingToRunes (b []byte )[]rune {var _da []rune ; 14 | for _ ,_bd :=range b {_ag ,_bg :=_bge [_bd ];if !_bg {_df .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u003a\u0020P\u0044\u0046\u0044o\u0063\u0045\u006ec\u006f\u0064i\u006e\u0067\u0020\u0069\u006e\u0070u\u0074 m\u0061\u0070\u0070\u0069\u006e\u0067\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0064\u0020\u002d\u0020\u0073\u006b\u0069\u0070\u0070\u0069\u006e\u0067",_bd ); 15 | continue ;};_da =append (_da ,_ag );};return _da ;};var _bge =map[byte ]rune {0x01:'\u0001',0x02:'\u0002',0x03:'\u0003',0x04:'\u0004',0x05:'\u0005',0x06:'\u0006',0x07:'\u0007',0x08:'\u0008',0x09:'\u0009',0x0a:'\u000a',0x0b:'\u000b',0x0c:'\u000c',0x0d:'\u000d',0x0e:'\u000e',0x0f:'\u000f',0x10:'\u0010',0x11:'\u0011',0x12:'\u0012',0x13:'\u0013',0x14:'\u0014',0x15:'\u0015',0x16:'\u0017',0x17:'\u0017',0x18:'\u02d8',0x19:'\u02c7',0x1a:'\u02c6',0x1b:'\u02d9',0x1c:'\u02dd',0x1d:'\u02db',0x1e:'\u02da',0x1f:'\u02dc',0x20:'\u0020',0x21:'\u0021',0x22:'\u0022',0x23:'\u0023',0x24:'\u0024',0x25:'\u0025',0x26:'\u0026',0x27:'\u0027',0x28:'\u0028',0x29:'\u0029',0x2a:'\u002a',0x2b:'\u002b',0x2c:'\u002c',0x2d:'\u002d',0x2e:'\u002e',0x2f:'\u002f',0x30:'\u0030',0x31:'\u0031',0x32:'\u0032',0x33:'\u0033',0x34:'\u0034',0x35:'\u0035',0x36:'\u0036',0x37:'\u0037',0x38:'\u0038',0x39:'\u0039',0x3a:'\u003a',0x3b:'\u003b',0x3c:'\u003c',0x3d:'\u003d',0x3e:'\u003e',0x3f:'\u003f',0x40:'\u0040',0x41:'\u0041',0x42:'\u0042',0x43:'\u0043',0x44:'\u0044',0x45:'\u0045',0x46:'\u0046',0x47:'\u0047',0x48:'\u0048',0x49:'\u0049',0x4a:'\u004a',0x4b:'\u004b',0x4c:'\u004c',0x4d:'\u004d',0x4e:'\u004e',0x4f:'\u004f',0x50:'\u0050',0x51:'\u0051',0x52:'\u0052',0x53:'\u0053',0x54:'\u0054',0x55:'\u0055',0x56:'\u0056',0x57:'\u0057',0x58:'\u0058',0x59:'\u0059',0x5a:'\u005a',0x5b:'\u005b',0x5c:'\u005c',0x5d:'\u005d',0x5e:'\u005e',0x5f:'\u005f',0x60:'\u0060',0x61:'\u0061',0x62:'\u0062',0x63:'\u0063',0x64:'\u0064',0x65:'\u0065',0x66:'\u0066',0x67:'\u0067',0x68:'\u0068',0x69:'\u0069',0x6a:'\u006a',0x6b:'\u006b',0x6c:'\u006c',0x6d:'\u006d',0x6e:'\u006e',0x6f:'\u006f',0x70:'\u0070',0x71:'\u0071',0x72:'\u0072',0x73:'\u0073',0x74:'\u0074',0x75:'\u0075',0x76:'\u0076',0x77:'\u0077',0x78:'\u0078',0x79:'\u0079',0x7a:'\u007a',0x7b:'\u007b',0x7c:'\u007c',0x7d:'\u007d',0x7e:'\u007e',0x80:'\u2022',0x81:'\u2020',0x82:'\u2021',0x83:'\u2026',0x84:'\u2014',0x85:'\u2013',0x86:'\u0192',0x87:'\u2044',0x88:'\u2039',0x89:'\u203a',0x8a:'\u2212',0x8b:'\u2030',0x8c:'\u201e',0x8d:'\u201c',0x8e:'\u201d',0x8f:'\u2018',0x90:'\u2019',0x91:'\u201a',0x92:'\u2122',0x93:'\ufb01',0x94:'\ufb02',0x95:'\u0141',0x96:'\u0152',0x97:'\u0160',0x98:'\u0178',0x99:'\u017d',0x9a:'\u0131',0x9b:'\u0142',0x9c:'\u0153',0x9d:'\u0161',0x9e:'\u017e',0xa0:'\u20ac',0xa1:'\u00a1',0xa2:'\u00a2',0xa3:'\u00a3',0xa4:'\u00a4',0xa5:'\u00a5',0xa6:'\u00a6',0xa7:'\u00a7',0xa8:'\u00a8',0xa9:'\u00a9',0xaa:'\u00aa',0xab:'\u00ab',0xac:'\u00ac',0xae:'\u00ae',0xaf:'\u00af',0xb0:'\u00b0',0xb1:'\u00b1',0xb2:'\u00b2',0xb3:'\u00b3',0xb4:'\u00b4',0xb5:'\u00b5',0xb6:'\u00b6',0xb7:'\u00b7',0xb8:'\u00b8',0xb9:'\u00b9',0xba:'\u00ba',0xbb:'\u00bb',0xbc:'\u00bc',0xbd:'\u00bd',0xbe:'\u00be',0xbf:'\u00bf',0xc0:'\u00c0',0xc1:'\u00c1',0xc2:'\u00c2',0xc3:'\u00c3',0xc4:'\u00c4',0xc5:'\u00c5',0xc6:'\u00c6',0xc7:'\u00c7',0xc8:'\u00c8',0xc9:'\u00c9',0xca:'\u00ca',0xcb:'\u00cb',0xcc:'\u00cc',0xcd:'\u00cd',0xce:'\u00ce',0xcf:'\u00cf',0xd0:'\u00d0',0xd1:'\u00d1',0xd2:'\u00d2',0xd3:'\u00d3',0xd4:'\u00d4',0xd5:'\u00d5',0xd6:'\u00d6',0xd7:'\u00d7',0xd8:'\u00d8',0xd9:'\u00d9',0xda:'\u00da',0xdb:'\u00db',0xdc:'\u00dc',0xdd:'\u00dd',0xde:'\u00de',0xdf:'\u00df',0xe0:'\u00e0',0xe1:'\u00e1',0xe2:'\u00e2',0xe3:'\u00e3',0xe4:'\u00e4',0xe5:'\u00e5',0xe6:'\u00e6',0xe7:'\u00e7',0xe8:'\u00e8',0xe9:'\u00e9',0xea:'\u00ea',0xeb:'\u00eb',0xec:'\u00ec',0xed:'\u00ed',0xee:'\u00ee',0xef:'\u00ef',0xf0:'\u00f0',0xf1:'\u00f1',0xf2:'\u00f2',0xf3:'\u00f3',0xf4:'\u00f4',0xf5:'\u00f5',0xf6:'\u00f6',0xf7:'\u00f7',0xf8:'\u00f8',0xf9:'\u00f9',0xfa:'\u00fa',0xfb:'\u00fb',0xfc:'\u00fc',0xfd:'\u00fd',0xfe:'\u00fe',0xff:'\u00ff'}; 16 | func UTF16ToString (b []byte )string {return string (UTF16ToRunes (b ))};func UTF16ToRunes (b []byte )[]rune {if len (b )==1{return []rune {rune (b [0])};};if len (b )%2!=0{b =append (b ,0);_df .Log .Debug ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0055\u0054\u0046\u0031\u0036\u0054\u006f\u0052\u0075\u006e\u0065\u0073.\u0020\u0050\u0061\u0064\u0064\u0069\u006e\u0067\u0020\u0077it\u0068\u0020\u007ae\u0072o\u0073\u002e"); 17 | };_fc :=len (b )>>1;_db :=make ([]uint16 ,_fc );for _c :=0;_c < _fc ;_c ++{_db [_c ]=uint16 (b [_c <<1])<<8+uint16 (b [_c <<1+1]);};_bc :=_f .Decode (_db );return _bc ;};func StringToPDFDocEncoding (s string )[]byte {var _gg _e .Buffer ;for _ ,_ddg :=range s {_ed ,_ae :=_b [_ddg ]; 18 | if !_ae {_df .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0050\u0044\u0046\u0044\u006f\u0063\u0045\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0075\u006e\u0065\u0020\u006d\u0061\u0070\u0070\u0069\u006e\u0067\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067\u0020\u0025\u0063\u002f\u0025\u0058\u0020\u002d\u0020s\u006b\u0069\u0070\u0070\u0069n\u0067",_ddg ,_ddg ); 19 | continue ;};_gg .WriteByte (_ed );};return _gg .Bytes ();}; -------------------------------------------------------------------------------- /internal/testutils/testutils.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 testutils ;import (_a "crypto/md5";_gf "encoding/hex";_bb "errors";_b "fmt";_cf "github.com/unidoc/unipdf/v4/common";_df "github.com/unidoc/unipdf/v4/core";_ge "image";_g "image/png";_e "io";_d "os";_fd "os/exec";_ab "path/filepath";_fb "strings"; 13 | _f "testing";);func ComparePNGFiles (file1 ,file2 string )(bool ,error ){_ed ,_ff :=HashFile (file1 );if _ff !=nil {return false ,_ff ;};_fcg ,_ff :=HashFile (file2 );if _ff !=nil {return false ,_ff ;};if _ed ==_fcg {return true ,nil ;};_afa ,_ff :=ReadPNG (file1 ); 14 | if _ff !=nil {return false ,_ff ;};_gce ,_ff :=ReadPNG (file2 );if _ff !=nil {return false ,_ff ;};if _afa .Bounds ()!=_gce .Bounds (){return false ,nil ;};return CompareImages (_afa ,_gce );};func CompareDictionariesDeep (d1 ,d2 *_df .PdfObjectDictionary )bool {if len (d1 .Keys ())!=len (d2 .Keys ()){_cf .Log .Debug ("\u0044\u0069\u0063\u0074\u0020\u0065\u006e\u0074\u0072\u0069\u0065\u0073\u0020\u006d\u0069s\u006da\u0074\u0063\u0068\u0020\u0028\u0025\u0064\u0020\u0021\u003d\u0020\u0025\u0064\u0029",len (d1 .Keys ()),len (d2 .Keys ())); 15 | _cf .Log .Debug ("\u0057\u0061s\u0020\u0027\u0025s\u0027\u0020\u0076\u0073\u0020\u0027\u0025\u0073\u0027",d1 .Write (),d2 .Write ());return false ;};for _ ,_bcb :=range d1 .Keys (){if _bcb =="\u0050\u0061\u0072\u0065\u006e\u0074"{continue ;};_ecc :=_df .TraceToDirectObject (d1 .Get (_bcb )); 16 | _gfa :=_df .TraceToDirectObject (d2 .Get (_bcb ));if _ecc ==nil {_cf .Log .Debug ("\u00761\u0020\u0069\u0073\u0020\u006e\u0069l");return false ;};if _gfa ==nil {_cf .Log .Debug ("\u00762\u0020\u0069\u0073\u0020\u006e\u0069l");return false ;};switch _cbf :=_ecc .(type ){case *_df .PdfObjectDictionary :_ca ,_gfe :=_gfa .(*_df .PdfObjectDictionary ); 17 | if !_gfe {_cf .Log .Debug ("\u0054\u0079\u0070\u0065 m\u0069\u0073\u006d\u0061\u0074\u0063\u0068\u0020\u0025\u0054\u0020\u0076\u0073\u0020%\u0054",_ecc ,_gfa );return false ;};if !CompareDictionariesDeep (_cbf ,_ca ){return false ;};continue ;case *_df .PdfObjectArray :_dbc ,_eag :=_gfa .(*_df .PdfObjectArray ); 18 | if !_eag {_cf .Log .Debug ("\u00762\u0020n\u006f\u0074\u0020\u0061\u006e\u0020\u0061\u0072\u0072\u0061\u0079");return false ;};if _cbf .Len ()!=_dbc .Len (){_cf .Log .Debug ("\u0061\u0072\u0072\u0061\u0079\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006d\u0069s\u006da\u0074\u0063\u0068\u0020\u0028\u0025\u0064\u0020\u0021\u003d\u0020\u0025\u0064\u0029",_cbf .Len (),_dbc .Len ()); 19 | return false ;};for _da :=0;_da < _cbf .Len ();_da ++{_cfc :=_df .TraceToDirectObject (_cbf .Get (_da ));_cba :=_df .TraceToDirectObject (_dbc .Get (_da ));if _cd ,_acg :=_cfc .(*_df .PdfObjectDictionary );_acg {_aegg ,_dgb :=_cba .(*_df .PdfObjectDictionary ); 20 | if !_dgb {return false ;};if !CompareDictionariesDeep (_cd ,_aegg ){return false ;};}else {_abe :=_cfc .Write ();_acd :=_cba .Write ();if string (_abe )!=string (_acd ){_cf .Log .Debug ("M\u0069\u0073\u006d\u0061tc\u0068 \u0027\u0025\u0073\u0027\u0020!\u003d\u0020\u0027\u0025\u0073\u0027",_abe ,_acd ); 21 | return false ;};};};continue ;};if _ecc .String ()!=_gfa .String (){_cf .Log .Debug ("\u006b\u0065y\u003d\u0025\u0073\u0020\u004d\u0069\u0073\u006d\u0061\u0074\u0063\u0068\u0021\u0020\u0027\u0025\u0073\u0027\u0020\u0021\u003d\u0020'%\u0073\u0027",_bcb ,_ecc .String (),_gfa .String ()); 22 | _cf .Log .Debug ("\u0046o\u0072 \u0027\u0025\u0054\u0027\u0020\u002d\u0020\u0027\u0025\u0054\u0027",_ecc ,_gfa );_cf .Log .Debug ("\u0046\u006f\u0072\u0020\u0027\u0025\u002b\u0076\u0027\u0020\u002d\u0020'\u0025\u002b\u0076\u0027",_ecc ,_gfa );return false ; 23 | };};return true ;};func ReadPNG (file string )(_ge .Image ,error ){_fa ,_af :=_d .Open (file );if _af !=nil {return nil ,_af ;};defer _fa .Close ();return _g .Decode (_fa );};func RenderPDFToPNGs (pdfPath string ,dpi int ,outpathTpl string )error {if dpi <=0{dpi =100; 24 | };if _ ,_dc :=_fd .LookPath ("\u0067\u0073");_dc !=nil {return ErrRenderNotSupported ;};return _fd .Command ("\u0067\u0073","\u002d\u0073\u0044\u0045\u0056\u0049\u0043\u0045\u003d\u0070\u006e\u0067a\u006c\u0070\u0068\u0061","\u002d\u006f",outpathTpl ,_b .Sprintf ("\u002d\u0072\u0025\u0064",dpi ),pdfPath ).Run (); 25 | };var (ErrRenderNotSupported =_bb .New ("\u0072\u0065\u006e\u0064\u0065r\u0069\u006e\u0067\u0020\u0050\u0044\u0046\u0020\u0066\u0069\u006c\u0065\u0073 \u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u006f\u006e\u0020\u0074\u0068\u0069\u0073\u0020\u0073\u0079\u0073\u0074\u0065m"); 26 | );func CopyFile (src ,dst string )error {_cfd ,_bc :=_d .Open (src );if _bc !=nil {return _bc ;};defer _cfd .Close ();_ea ,_bc :=_d .Create (dst );if _bc !=nil {return _bc ;};defer _ea .Close ();_ ,_bc =_e .Copy (_ea ,_cfd );return _bc ;};func ParseIndirectObjects (rawpdf string )(map[int64 ]_df .PdfObject ,error ){_dbg :=_df .NewParserFromString (rawpdf ); 27 | _faac :=map[int64 ]_df .PdfObject {};for {_dg ,_ef :=_dbg .ParseIndirectObject ();if _ef !=nil {if _ef ==_e .EOF {break ;};return nil ,_ef ;};switch _gcf :=_dg .(type ){case *_df .PdfIndirectObject :_faac [_gcf .ObjectNumber ]=_dg ;case *_df .PdfObjectStream :_faac [_gcf .ObjectNumber ]=_dg ; 28 | };};for _ ,_egg :=range _faac {_fef (_egg ,_faac );};return _faac ,nil ;};func CompareImages (img1 ,img2 _ge .Image )(bool ,error ){_gc :=img1 .Bounds ();_bbb :=0;for _cb :=0;_cb < _gc .Size ().X ;_cb ++{for _afc :=0;_afc < _gc .Size ().Y ;_afc ++{_agf ,_ad ,_bf ,_ :=img1 .At (_cb ,_afc ).RGBA (); 29 | _agd ,_fe ,_fac ,_ :=img2 .At (_cb ,_afc ).RGBA ();if _agf !=_agd ||_ad !=_fe ||_bf !=_fac {_bbb ++;};};};_egd :=float64 (_bbb )/float64 (_gc .Dx ()*_gc .Dy ());if _egd > 0.0001{_b .Printf ("\u0064\u0069\u0066f \u0066\u0072\u0061\u0063\u0074\u0069\u006f\u006e\u003a\u0020\u0025\u0076\u0020\u0028\u0025\u0064\u0029\u000a",_egd ,_bbb ); 30 | return false ,nil ;};return true ,nil ;};func RunRenderTest (t *_f .T ,pdfPath ,outputDir ,baselineRenderPath string ,saveBaseline bool ){_dff :=_fb .TrimSuffix (_ab .Base (pdfPath ),_ab .Ext (pdfPath ));t .Run ("\u0072\u0065\u006e\u0064\u0065\u0072",func (_eac *_f .T ){_aeg :=_ab .Join (outputDir ,_dff ); 31 | _faa :=_aeg +"\u002d%\u0064\u002e\u0070\u006e\u0067";if _gd :=RenderPDFToPNGs (pdfPath ,0,_faa );_gd !=nil {_eac .Skip (_gd );};for _gad :=1;true ;_gad ++{_fce :=_b .Sprintf ("\u0025s\u002d\u0025\u0064\u002e\u0070\u006eg",_aeg ,_gad );_fab :=_ab .Join (baselineRenderPath ,_b .Sprintf ("\u0025\u0073\u002d\u0025\u0064\u005f\u0065\u0078\u0070\u002e\u0070\u006e\u0067",_dff ,_gad )); 32 | if _ ,_afe :=_d .Stat (_fce );_afe !=nil {break ;};_eac .Logf ("\u0025\u0073",_fab );if saveBaseline {_eac .Logf ("\u0043\u006fp\u0079\u0069\u006eg\u0020\u0025\u0073\u0020\u002d\u003e\u0020\u0025\u0073",_fce ,_fab );_cfdb :=CopyFile (_fce ,_fab );if _cfdb !=nil {_eac .Fatalf ("\u0045\u0052\u0052OR\u0020\u0063\u006f\u0070\u0079\u0069\u006e\u0067\u0020\u0074\u006f\u0020\u0025\u0073\u003a\u0020\u0025\u0076",_fab ,_cfdb ); 33 | };continue ;};_eac .Run (_b .Sprintf ("\u0070\u0061\u0067\u0065\u0025\u0064",_gad ),func (_bdd *_f .T ){_bdd .Logf ("\u0043o\u006dp\u0061\u0072\u0069\u006e\u0067 \u0025\u0073 \u0076\u0073\u0020\u0025\u0073",_fce ,_fab );_gfd ,_cff :=ComparePNGFiles (_fce ,_fab ); 34 | if _d .IsNotExist (_cff ){_bdd .Fatal ("\u0069m\u0061g\u0065\u0020\u0066\u0069\u006ce\u0020\u006di\u0073\u0073\u0069\u006e\u0067");}else if !_gfd {_bdd .Fatal ("\u0077\u0072\u006f\u006eg \u0070\u0061\u0067\u0065\u0020\u0072\u0065\u006e\u0064\u0065\u0072\u0065\u0064"); 35 | };});};});};func HashFile (file string )(string ,error ){_ae ,_ag :=_d .Open (file );if _ag !=nil {return "",_ag ;};defer _ae .Close ();_eg :=_a .New ();if _ ,_ag =_e .Copy (_eg ,_ae );_ag !=nil {return "",_ag ;};return _gf .EncodeToString (_eg .Sum (nil )),nil ; 36 | };func _fef (_cc _df .PdfObject ,_gag map[int64 ]_df .PdfObject )error {switch _ee :=_cc .(type ){case *_df .PdfIndirectObject :_fdd :=_ee ;_fef (_fdd .PdfObject ,_gag );case *_df .PdfObjectDictionary :_ec :=_ee ;for _ ,_eda :=range _ec .Keys (){_dbb :=_ec .Get (_eda ); 37 | if _fdc ,_ba :=_dbb .(*_df .PdfObjectReference );_ba {_gae ,_aa :=_gag [_fdc .ObjectNumber ];if !_aa {return _bb .New ("r\u0065\u0066\u0065\u0072\u0065\u006ec\u0065\u0020\u0074\u006f\u0020\u006f\u0075\u0074\u0073i\u0064\u0065\u0020o\u0062j\u0065\u0063\u0074"); 38 | };_ec .Set (_eda ,_gae );}else {_fef (_dbb ,_gag );};};case *_df .PdfObjectArray :_cce :=_ee ;for _efc ,_fea :=range _cce .Elements (){if _edac ,_edad :=_fea .(*_df .PdfObjectReference );_edad {_de ,_aed :=_gag [_edac .ObjectNumber ];if !_aed {return _bb .New ("r\u0065\u0066\u0065\u0072\u0065\u006ec\u0065\u0020\u0074\u006f\u0020\u006f\u0075\u0074\u0073i\u0064\u0065\u0020o\u0062j\u0065\u0063\u0074"); 39 | };_cce .Set (_efc ,_de );}else {_fef (_fea ,_gag );};};};return nil ;}; -------------------------------------------------------------------------------- /internal/textencoding/internal/syncmap/syncmap.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 syncmap ;import _c "sync";func (_b *ByteRuneMap )Read (b byte )(rune ,bool ){_b ._a .RLock ();defer _b ._a .RUnlock ();_d ,_be :=_b ._g [b ];return _d ,_be ;};func MakeRuneSet (length int )*RuneSet {return &RuneSet {_cd :make (map[rune ]struct{},length )}}; 13 | func (_baf *RuneUint16Map )Length ()int {_baf ._gae .RLock ();defer _baf ._gae .RUnlock ();return len (_baf ._ded );};func (_cb *RuneByteMap )Range (f func (_eb rune ,_bg byte )(_ag bool )){_cb ._gc .RLock ();defer _cb ._gc .RUnlock ();for _eg ,_ba :=range _cb ._ge {if f (_eg ,_ba ){break ; 14 | };};};type RuneSet struct{_cd map[rune ]struct{};_cba _c .RWMutex ;};func (_deb *RuneByteMap )Read (r rune )(byte ,bool ){_deb ._gc .RLock ();defer _deb ._gc .RUnlock ();_ac ,_af :=_deb ._ge [r ];return _ac ,_af ;};func (_ec *RuneStringMap )Write (r rune ,s string ){_ec ._egb .Lock (); 15 | defer _ec ._egb .Unlock ();_ec ._bd [r ]=s ;};func (_bae *RuneByteMap )Length ()int {_bae ._gc .RLock ();defer _bae ._gc .RUnlock ();return len (_bae ._ge );};type StringsTuple struct{Key ,Value string ;};func (_de *ByteRuneMap )Write (b byte ,r rune ){_de ._a .Lock (); 16 | defer _de ._a .Unlock ();_de ._g [b ]=r };func (_ggg *RuneByteMap )Write (r rune ,b byte ){_ggg ._gc .Lock ();defer _ggg ._gc .Unlock ();_ggg ._ge [r ]=b ;};func (_ebf *StringRuneMap )Write (g string ,r rune ){_ebf ._feb .Lock ();defer _ebf ._feb .Unlock (); 17 | _ebf ._dda [g ]=r ;};func (_bfd *StringsMap )Range (f func (_dbb ,_cdd string )(_ffae bool )){_bfd ._ffa .RLock ();defer _bfd ._ffa .RUnlock ();for _bfde ,_ebdf :=range _bfd ._cdc {if f (_bfde ,_ebdf ){break ;};};};func (_ab *ByteRuneMap )Length ()int {_ab ._a .RLock (); 18 | defer _ab ._a .RUnlock ();return len (_ab ._g )};func (_fd *RuneUint16Map )Write (r rune ,g uint16 ){_fd ._gae .Lock ();defer _fd ._gae .Unlock ();_fd ._ded [r ]=g ;};func NewStringsMap (tuples []StringsTuple )*StringsMap {_ca :=map[string ]string {};for _ ,_fbg :=range tuples {_ca [_fbg .Key ]=_fbg .Value ; 19 | };return &StringsMap {_cdc :_ca };};func NewByteRuneMap (m map[byte ]rune )*ByteRuneMap {return &ByteRuneMap {_g :m }};func (_gaa *RuneStringMap )Read (r rune )(string ,bool ){_gaa ._egb .RLock ();defer _gaa ._egb .RUnlock ();_fbe ,_ad :=_gaa ._bd [r ]; 20 | return _fbe ,_ad ;};type StringsMap struct{_cdc map[string ]string ;_ffa _c .RWMutex ;};func (_fdb *RuneUint16Map )Range (f func (_gfd rune ,_dd uint16 )(_bea bool )){_fdb ._gae .RLock ();defer _fdb ._gae .RUnlock ();for _ega ,_edb :=range _fdb ._ded {if f (_ega ,_edb ){break ; 21 | };};};type RuneUint16Map struct{_ded map[rune ]uint16 ;_gae _c .RWMutex ;};func (_dba *StringRuneMap )Length ()int {_dba ._feb .RLock ();defer _dba ._feb .RUnlock ();return len (_dba ._dda );};type StringRuneMap struct{_dda map[string ]rune ;_feb _c .RWMutex ; 22 | };func (_fff *StringRuneMap )Range (f func (_adf string ,_db rune )(_gac bool )){_fff ._feb .RLock ();defer _fff ._feb .RUnlock ();for _fegg ,_baaa :=range _fff ._dda {if f (_fegg ,_baaa ){break ;};};};func (_edg *StringRuneMap )Read (g string )(rune ,bool ){_edg ._feb .RLock (); 23 | defer _edg ._feb .RUnlock ();_cg ,_bcb :=_edg ._dda [g ];return _cg ,_bcb ;};type ByteRuneMap struct{_g map[byte ]rune ;_a _c .RWMutex ;};func MakeRuneByteMap (length int )*RuneByteMap {_gf :=make (map[rune ]byte ,length );return &RuneByteMap {_ge :_gf }; 24 | };type RuneByteMap struct{_ge map[rune ]byte ;_gc _c .RWMutex ;};func (_gec *RuneSet )Length ()int {_gec ._cba .RLock ();defer _gec ._cba .RUnlock ();return len (_gec ._cd )};func (_ede *RuneUint16Map )Read (r rune )(uint16 ,bool ){_ede ._gae .RLock (); 25 | defer _ede ._gae .RUnlock ();_ae ,_bf :=_ede ._ded [r ];return _ae ,_bf ;};func (_fg *RuneStringMap )Length ()int {_fg ._egb .RLock ();defer _fg ._egb .RUnlock ();return len (_fg ._bd );};func (_cde *StringsMap )Copy ()*StringsMap {_cde ._ffa .RLock (); 26 | defer _cde ._ffa .RUnlock ();_bag :=map[string ]string {};for _fc ,_bga :=range _cde ._cdc {_bag [_fc ]=_bga ;};return &StringsMap {_cdc :_bag };};func MakeByteRuneMap (length int )*ByteRuneMap {return &ByteRuneMap {_g :make (map[byte ]rune ,length )}}; 27 | type RuneStringMap struct{_bd map[rune ]string ;_egb _c .RWMutex ;};func (_fbf *StringsMap )Write (g1 ,g2 string ){_fbf ._ffa .Lock ();defer _fbf ._ffa .Unlock ();_fbf ._cdc [g1 ]=g2 ;};func (_aa *RuneSet )Exists (r rune )bool {_aa ._cba .RLock ();defer _aa ._cba .RUnlock (); 28 | _ ,_fe :=_aa ._cd [r ];return _fe ;};func (_cc *RuneUint16Map )Delete (r rune ){_cc ._gae .Lock ();defer _cc ._gae .Unlock ();delete (_cc ._ded ,r );};func (_dcd *StringsMap )Read (g string )(string ,bool ){_dcd ._ffa .RLock ();defer _dcd ._ffa .RUnlock (); 29 | _dgf ,_adg :=_dcd ._cdc [g ];return _dgf ,_adg ;};func (_geb *RuneUint16Map )RangeDelete (f func (_edbe rune ,_baaf uint16 )(_dc bool ,_abg bool )){_geb ._gae .Lock ();defer _geb ._gae .Unlock ();for _ace ,_bca :=range _geb ._ded {_ebd ,_gee :=f (_ace ,_bca ); 30 | if _ebd {delete (_geb ._ded ,_ace );};if _gee {break ;};};};func NewStringRuneMap (m map[string ]rune )*StringRuneMap {return &StringRuneMap {_dda :m }};func NewRuneStringMap (m map[rune ]string )*RuneStringMap {return &RuneStringMap {_bd :m }};func (_feg *RuneSet )Write (r rune ){_feg ._cba .Lock (); 31 | defer _feg ._cba .Unlock ();_feg ._cd [r ]=struct{}{};};func MakeRuneUint16Map (length int )*RuneUint16Map {return &RuneUint16Map {_ded :make (map[rune ]uint16 ,length )};};func (_gg *ByteRuneMap )Range (f func (_e byte ,_fb rune )(_ed bool )){_gg ._a .RLock (); 32 | defer _gg ._a .RUnlock ();for _ga ,_ef :=range _gg ._g {if f (_ga ,_ef ){break ;};};};func (_baa *RuneSet )Range (f func (_bc rune )(_gad bool )){_baa ._cba .RLock ();defer _baa ._cba .RUnlock ();for _dg :=range _baa ._cd {if f (_dg ){break ;};};};func (_efa *RuneStringMap )Range (f func (_ff rune ,_eac string )(_fbeg bool )){_efa ._egb .RLock (); 33 | defer _efa ._egb .RUnlock ();for _acc ,_efe :=range _efa ._bd {if f (_acc ,_efe ){break ;};};}; -------------------------------------------------------------------------------- /internal/timeutils/timeutils.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 timeutils ;import (_a "errors";_b "fmt";_ecc "regexp";_ec "strconv";_g "time";);func FormatPdfTime (in _g .Time )string {_bd :=in .Format ("\u002d\u0030\u0037\u003a\u0030\u0030");_f ,_ :=_ec .ParseInt (_bd [1:3],10,32);_af ,_ :=_ec .ParseInt (_bd [4:6],10,32); 13 | _fd :=int64 (in .Year ());_gd :=int64 (in .Month ());_aa :=int64 (in .Day ());_fa :=int64 (in .Hour ());_ef :=int64 (in .Minute ());_bf :=int64 (in .Second ());_ca :=_bd [0];return _b .Sprintf ("\u0044\u003a\u0025\u002e\u0034\u0064\u0025\u002e\u0032\u0064\u0025\u002e\u0032\u0064\u0025\u002e\u0032\u0064\u0025\u002e\u0032\u0064\u0025\u002e2\u0064\u0025\u0063\u0025\u002e2\u0064\u0027%\u002e\u0032\u0064\u0027",_fd ,_gd ,_aa ,_fa ,_ef ,_bf ,_ca ,_f ,_af ); 14 | };func ParsePdfTime (pdfTime string )(_g .Time ,error ){_d :=_acb .FindAllStringSubmatch (pdfTime ,1);if len (_d )< 1{if len (pdfTime )> 0&&pdfTime [0]!='D'{pdfTime =_b .Sprintf ("\u0044\u003a\u0025\u0073",pdfTime );return ParsePdfTime (pdfTime );};return _g .Time {},_b .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0064\u0061\u0074\u0065\u0020s\u0074\u0072\u0069\u006e\u0067\u0020\u0028\u0025\u0073\u0029",pdfTime ); 15 | };if len (_d [0])!=10{return _g .Time {},_a .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0065\u0067\u0065\u0078p\u0020\u0067\u0072\u006f\u0075\u0070 \u006d\u0061\u0074\u0063\u0068\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020!\u003d\u0020\u0031\u0030"); 16 | };_bg ,_ :=_ec .ParseInt (_d [0][1],10,32);_agd ,_ :=_ec .ParseInt (_d [0][2],10,32);_ab ,_ :=_ec .ParseInt (_d [0][3],10,32);_gdc ,_ :=_ec .ParseInt (_d [0][4],10,32);_cf ,_ :=_ec .ParseInt (_d [0][5],10,32);_fg ,_ :=_ec .ParseInt (_d [0][6],10,32);var (_cg byte ; 17 | _ce int64 ;_bfc int64 ;);_cg ='+';if len (_d [0][7])> 0{if _d [0][7]=="\u002d"{_cg ='-';}else if _d [0][7]=="\u005a"{_cg ='Z';};};if len (_d [0][8])> 0{_ce ,_ =_ec .ParseInt (_d [0][8],10,32);}else {_ce =0;};if len (_d [0][9])> 0{_bfc ,_ =_ec .ParseInt (_d [0][9],10,32); 18 | }else {_bfc =0;};_ac :=int (_ce *60*60+_bfc *60);switch _cg {case '-':_ac =-_ac ;case 'Z':_ac =0;};_bgd :=_b .Sprintf ("\u0055\u0054\u0043\u0025\u0063\u0025\u002e\u0032\u0064\u0025\u002e\u0032\u0064",_cg ,_ce ,_bfc );_fe :=_g .FixedZone (_bgd ,_ac );return _g .Date (int (_bg ),_g .Month (_agd ),int (_ab ),int (_gdc ),int (_cf ),int (_fg ),0,_fe ),nil ; 19 | };var _acb =_ecc .MustCompile ("\u005cs\u002a\u0044\u005cs\u002a\u003a\u005cs\u002a(\\\u0064\u007b\u0034\u007d\u0029\u0028\u005cd\u007b\u0032\u007d\u0029\u0028\u005c\u0064\u007b\u0032\u007d\u0029\u0028\u005c\u0064\u007b\u0032\u007d\u0029\u0028\u005c\u0064\u007b\u0032\u007d\u0029\u0028\u005c\u0064{2\u007d)\u003f\u0028\u005b\u002b\u002d\u005a]\u0029\u003f\u0028\u005c\u0064{\u0032\u007d\u0029\u003f\u0027\u003f\u0028\u005c\u0064\u007b\u0032}\u0029\u003f"); 20 | -------------------------------------------------------------------------------- /internal/transform/transform.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 transform ;import (_c "fmt";_fe "github.com/unidoc/unipdf/v4/common";_a "math";);func (_bf Matrix )Scale (xScale ,yScale float64 )Matrix {return _bf .Mult (ScaleMatrix (xScale ,yScale ))};func (_bdef Point )Distance (b Point )float64 {return _a .Hypot (_bdef .X -b .X ,_bdef .Y -b .Y )}; 13 | func (_bbe Point )Displace (delta Point )Point {return Point {_bbe .X +delta .X ,_bbe .Y +delta .Y }};func (_gg Matrix )Mult (b Matrix )Matrix {_gg .Concat (b );return _gg };func (_fgd Matrix )Unrealistic ()bool {_af ,_da ,_cae ,_eaa :=_a .Abs (_fgd [0]),_a .Abs (_fgd [1]),_a .Abs (_fgd [3]),_a .Abs (_fgd [4]); 14 | _bbb :=_af > _cea &&_eaa > _cea ;_ee :=_da > _cea &&_cae > _cea ;return !(_bbb ||_ee );};type Point struct{X float64 ;Y float64 ;};func (_dg Matrix )ScalingFactorX ()float64 {return _a .Hypot (_dg [0],_dg [1])};func NewMatrixFromTransforms (xScale ,yScale ,theta ,tx ,ty float64 )Matrix {return IdentityMatrix ().Scale (xScale ,yScale ).Rotate (theta ).Translate (tx ,ty ); 15 | };const _ef =1e-10;func IdentityMatrix ()Matrix {return NewMatrix (1,0,0,1,0,0)};func NewMatrix (a ,b ,c ,d ,tx ,ty float64 )Matrix {_ga :=Matrix {a ,b ,0,c ,d ,0,tx ,ty ,1};_ga .clampRange ();return _ga ;};func (_b Matrix )Identity ()bool {return _b [0]==1&&_b [1]==0&&_b [2]==0&&_b [3]==0&&_b [4]==1&&_b [5]==0&&_b [6]==0&&_b [7]==0&&_b [8]==1; 16 | };func (_cee *Point )transformByMatrix (_ccf Matrix ){_cee .X ,_cee .Y =_ccf .Transform (_cee .X ,_cee .Y )};func (_cfc *Matrix )Shear (x ,y float64 ){_cfc .Concat (ShearMatrix (x ,y ))};func (_db Matrix )Singular ()bool {return _a .Abs (_db [0]*_db [4]-_db [1]*_db [3])< _ef }; 17 | func (_ad Matrix )Inverse ()(Matrix ,bool ){_cgc ,_be :=_ad [0],_ad [1];_ab ,_bfa :=_ad [3],_ad [4];_ge ,_fd :=_ad [6],_ad [7];_ce :=_cgc *_bfa -_be *_ab ;if _a .Abs (_ce )< _ffc {return Matrix {},false ;};_bde ,_dce :=_bfa /_ce ,-_be /_ce ;_dd ,_gce :=-_ab /_ce ,_cgc /_ce ; 18 | _fde :=-(_bde *_ge +_dd *_fd );_gea :=-(_dce *_ge +_gce *_fd );return NewMatrix (_bde ,_dce ,_dd ,_gce ,_fde ,_gea ),true ;};func (_fa Matrix )ScalingFactorY ()float64 {return _a .Hypot (_fa [3],_fa [4])};func (_eb *Matrix )Concat (b Matrix ){*_eb =Matrix {b [0]*_eb [0]+b [1]*_eb [3],b [0]*_eb [1]+b [1]*_eb [4],0,b [3]*_eb [0]+b [4]*_eb [3],b [3]*_eb [1]+b [4]*_eb [4],0,b [6]*_eb [0]+b [7]*_eb [3]+_eb [6],b [6]*_eb [1]+b [7]*_eb [4]+_eb [7],1}; 19 | _eb .clampRange ();};const _cea =1e-6;func ScaleMatrix (x ,y float64 )Matrix {return NewMatrix (x ,0,0,y ,0,0)};func (_cf Matrix )Round (precision float64 )Matrix {for _cg :=range _cf {_cf [_cg ]=_a .Round (_cf [_cg ]/precision )*precision ;};return _cf ; 20 | };func (_ac Point )Interpolate (b Point ,t float64 )Point {return Point {X :(1-t )*_ac .X +t *b .X ,Y :(1-t )*_ac .Y +t *b .Y };};func (_fb Matrix )String ()string {_gf ,_d ,_ff ,_de ,_dc ,_cc :=_fb [0],_fb [1],_fb [3],_fb [4],_fb [6],_fb [7];return _c .Sprintf ("\u005b\u00257\u002e\u0034\u0066\u002c%\u0037\u002e4\u0066\u002c\u0025\u0037\u002e\u0034\u0066\u002c%\u0037\u002e\u0034\u0066\u003a\u0025\u0037\u002e\u0034\u0066\u002c\u00257\u002e\u0034\u0066\u005d",_gf ,_d ,_ff ,_de ,_dc ,_cc ); 21 | };const _ffc =1.0e-6;func (_bdg *Point )Transform (a ,b ,c ,d ,tx ,ty float64 ){_ag :=NewMatrix (a ,b ,c ,d ,tx ,ty );_bdg .transformByMatrix (_ag );};func RotationMatrix (angle float64 )Matrix {_cfa :=_a .Cos (angle );_g :=_a .Sin (angle );return NewMatrix (_cfa ,_g ,-_g ,_cfa ,0,0); 22 | };func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};func (_dgb Point )Rotate (theta float64 )Point {_dea :=_a .Hypot (_dgb .X ,_dgb .Y );_gfc :=_a .Atan2 (_dgb .Y ,_dgb .X );_eab ,_dda :=_a .Sincos (_gfc +theta /180.0*_a .Pi );return Point {_dea *_dda ,_dea *_eab }; 23 | };const _gb =1e9;func (_ggc *Point )Set (x ,y float64 ){_ggc .X ,_ggc .Y =x ,y };func (_cdg *Matrix )clampRange (){for _gd ,_ca :=range _cdg {if _ca > _gb {_fe .Log .Debug ("\u0043L\u0041M\u0050\u003a\u0020\u0025\u0067\u0020\u002d\u003e\u0020\u0025\u0067",_ca ,_gb ); 24 | _cdg [_gd ]=_gb ;}else if _ca < -_gb {_fe .Log .Debug ("\u0043L\u0041M\u0050\u003a\u0020\u0025\u0067\u0020\u002d\u003e\u0020\u0025\u0067",_ca ,-_gb );_cdg [_gd ]=-_gb ;};};};func (_dbf Point )String ()string {return _c .Sprintf ("(\u0025\u002e\u0032\u0066\u002c\u0025\u002e\u0032\u0066\u0029",_dbf .X ,_dbf .Y ); 25 | };type Matrix [9]float64 ;func (_eg *Matrix )Clone ()Matrix {return NewMatrix (_eg [0],_eg [1],_eg [3],_eg [4],_eg [6],_eg [7])};func (_ea Matrix )Transform (x ,y float64 )(float64 ,float64 ){_cd :=x *_ea [0]+y *_ea [3]+_ea [6];_ec :=x *_ea [1]+y *_ea [4]+_ea [7]; 26 | return _cd ,_ec ;};func (_cfb Matrix )Translate (tx ,ty float64 )Matrix {return _cfb .Mult (TranslationMatrix (tx ,ty ))};func ShearMatrix (x ,y float64 )Matrix {return NewMatrix (1,y ,x ,1,0,0)};func TranslationMatrix (tx ,ty float64 )Matrix {return NewMatrix (1,0,0,1,tx ,ty )}; 27 | func (_fg Matrix )Rotate (theta float64 )Matrix {return _fg .Mult (RotationMatrix (theta ))};func (_gc Matrix )Translation ()(float64 ,float64 ){return _gc [6],_gc [7]};func (_bb Matrix )Angle ()float64 {_bd :=_a .Atan2 (-_bb [1],_bb [0]);if _bd < 0.0{_bd +=2*_a .Pi ; 28 | };return _bd /_a .Pi *180.0;};func (_e *Matrix )Set (a ,b ,c ,d ,tx ,ty float64 ){_e [0],_e [1]=a ,b ;_e [3],_e [4]=c ,d ;_e [6],_e [7]=tx ,ty ;_e .clampRange ();}; -------------------------------------------------------------------------------- /internal/uuid/uuid.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 uuid ;import (_a "crypto/rand";_e "encoding/hex";_g "io";);var _ee =_a .Reader ;func _gd (_agb []byte ,_ae UUID ){_e .Encode (_agb ,_ae [:4]);_agb [8]='-';_e .Encode (_agb [9:13],_ae [4:6]);_agb [13]='-';_e .Encode (_agb [14:18],_ae [6:8]);_agb [18]='-'; 13 | _e .Encode (_agb [19:23],_ae [8:10]);_agb [23]='-';_e .Encode (_agb [24:],_ae [10:]);};var _cd UUID ;func MustUUID ()UUID {uuid ,_b :=NewUUID ();if _b !=nil {panic (_b );};return uuid ;};func NewUUID ()(UUID ,error ){var uuid UUID ;_ ,_f :=_g .ReadFull (_ee ,uuid [:]); 14 | if _f !=nil {return _cd ,_f ;};uuid [6]=(uuid [6]&0x0f)|0x40;uuid [8]=(uuid [8]&0x3f)|0x80;return uuid ,nil ;};type UUID [16]byte ;var Nil =_cd ;func (_c UUID )String ()string {var _ff [36]byte ;_gd (_ff [:],_c );return string (_ff [:])}; -------------------------------------------------------------------------------- /model/internal/docutil/docutil.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 docutil ;import (_d "errors";_c "fmt";_f "github.com/unidoc/unipdf/v4/common";_a "github.com/unidoc/unipdf/v4/core";);func (_edf Page )GetResourcesXObject ()(*_a .PdfObjectDictionary ,bool ){_cbe ,_ega :=_edf .GetResources ();if !_ega {return nil ,false ; 13 | };return _a .GetDict (_cbe .Get ("\u0058O\u0062\u006a\u0065\u0063\u0074"));};func (_edb Page )GetContents ()([]Content ,bool ){_gdeb ,_cad :=_a .GetArray (_edb .Object .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073"));if !_cad {_ecb ,_cffa :=_a .GetStream (_edb .Object .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073")); 14 | if !_cffa {return nil ,false ;};return []Content {{Stream :_ecb ,_eef :_edb ,_deg :0}},true ;};_bg :=make ([]Content ,_gdeb .Len ());for _dga ,_fd :=range _gdeb .Elements (){_gfg ,_bbf :=_a .GetStream (_fd );if !_bbf {continue ;};_bg [_dga ]=Content {Stream :_gfg ,_eef :_edb ,_deg :_dga }; 15 | };return _bg ,true ;};func (_gd *Catalog )GetStructTreeRoot ()(*_a .PdfObjectDictionary ,bool ){return _a .GetDict (_gd .Object .Get ("\u0053\u0074\u0072\u0075\u0063\u0074\u0054\u0072\u0065e\u0052\u006f\u006f\u0074"));};func (_cb *Document )FindCatalog ()(*Catalog ,bool ){var _ggb *_a .PdfObjectDictionary ; 16 | for _ ,_afg :=range _cb .Objects {_ac ,_aac :=_a .GetDict (_afg );if !_aac {continue ;};if _fed ,_afa :=_a .GetName (_ac .Get ("\u0054\u0079\u0070\u0065"));_afa &&*_fed =="\u0043a\u0074\u0061\u006c\u006f\u0067"{_ggb =_ac ;break ;};};if _ggb ==nil {return nil ,false ; 17 | };return &Catalog {Object :_ggb ,_e :_cb },true ;};func (_dfge Page )GetResources ()(*_a .PdfObjectDictionary ,bool ){return _a .GetDict (_dfge .Object .Get ("\u0052e\u0073\u006f\u0075\u0072\u0063\u0065s"));};func (_ge *Catalog )SetStructTreeRoot (structTreeRoot _a .PdfObject ){if structTreeRoot ==nil {_ge .Object .Remove ("\u0053\u0074\u0072\u0075\u0063\u0074\u0054\u0072\u0065e\u0052\u006f\u006f\u0074"); 18 | return ;};_fec :=_a .MakeIndirectObject (structTreeRoot );_ge .Object .Set ("\u0053\u0074\u0072\u0075\u0063\u0074\u0054\u0072\u0065e\u0052\u006f\u006f\u0074",_fec );_ge ._e .Objects =append (_ge ._e .Objects ,_fec );};type Document struct{ID [2]string ; 19 | Version _a .Version ;Objects []_a .PdfObject ;Info _a .PdfObject ;Crypt *_a .PdfCrypt ;UseHashBasedID bool ;};func (_ffd Page )FindXObjectImages ()([]*Image ,error ){_aag ,_adb :=_ffd .GetResourcesXObject ();if !_adb {return nil ,nil ;};var _cee []*Image ; 20 | var _gbe error ;_fbgc :=map[*_a .PdfObjectStream ]int {};_ced :=map[*_a .PdfObjectStream ]struct{}{};var _eab int ;for _ ,_dfa :=range _aag .Keys (){_geb ,_fcd :=_a .GetStream (_aag .Get (_dfa ));if !_fcd {continue ;};if _ ,_dc :=_fbgc [_geb ];_dc {continue ; 21 | };_fdc ,_cga :=_a .GetName (_geb .Get ("\u0053u\u0062\u0074\u0079\u0070\u0065"));if !_cga ||_fdc .String ()!="\u0049\u006d\u0061g\u0065"{continue ;};_fcc :=Image {BitsPerComponent :8,Stream :_geb ,Name :string (_dfa )};if _fcc .Colorspace ,_gbe =_age (_geb .PdfObjectDictionary .Get ("\u0043\u006f\u006c\u006f\u0072\u0053\u0070\u0061\u0063\u0065")); 22 | _gbe !=nil {_f .Log .Error ("\u0045\u0072\u0072\u006f\u0072\u0020\u0064\u0065\u0074\u0065r\u006d\u0069\u006e\u0065\u0020\u0063\u006fl\u006f\u0072\u0020\u0073\u0070\u0061\u0063\u0065\u0020\u0025\u0073",_gbe );continue ;};if _efa ,_gee :=_a .GetIntVal (_geb .PdfObjectDictionary .Get ("\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074")); 23 | _gee {_fcc .BitsPerComponent =_efa ;};if _ee ,_dce :=_a .GetIntVal (_geb .PdfObjectDictionary .Get ("\u0057\u0069\u0064t\u0068"));_dce {_fcc .Width =_ee ;};if _bfd ,_ffb :=_a .GetIntVal (_geb .PdfObjectDictionary .Get ("\u0048\u0065\u0069\u0067\u0068\u0074")); 24 | _ffb {_fcc .Height =_bfd ;};if _caf ,_cbd :=_a .GetStream (_geb .Get ("\u0053\u004d\u0061s\u006b"));_cbd {_fcc .SMask =&ImageSMask {Image :&_fcc ,Stream :_caf };_ced [_caf ]=struct{}{};};switch _fcc .Colorspace {case "\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B":_fcc .ColorComponents =3; 25 | case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079":_fcc .ColorComponents =1;case "\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":_fcc .ColorComponents =4;default:_fcc .ColorComponents =-1;};_fbgc [_geb ]=_eab ;_cee =append (_cee ,&_fcc ); 26 | _eab ++;};var _fac []int ;for _ ,_eff :=range _cee {if _eff .SMask !=nil {_fef ,_gge :=_fbgc [_eff .SMask .Stream ];if _gge {_fac =append (_fac ,_fef );};};};_edba :=make ([]*Image ,len (_cee )-len (_fac ));_eab =0;_ggg :for _cd ,_fafc :=range _cee {for _ ,_fbc :=range _fac {if _cd ==_fbc {continue _ggg ; 27 | };};_edba [_eab ]=_fafc ;_eab ++;};return _cee ,nil ;};type Image struct{Name string ;Width int ;Height int ;Colorspace _a .PdfObjectName ;ColorComponents int ;BitsPerComponent int ;SMask *ImageSMask ;Stream *_a .PdfObjectStream ;};func (_de *Catalog )HasMetadata ()bool {_ggf :=_de .Object .Get ("\u004d\u0065\u0074\u0061\u0064\u0061\u0074\u0061"); 28 | return _ggf !=nil ;};func (_bbc *Catalog )SetOutputIntents (outputIntents *OutputIntents ){if _dd :=_bbc .Object .Get ("\u004f\u0075\u0074\u0070\u0075\u0074\u0049\u006e\u0074\u0065\u006e\u0074\u0073");_dd !=nil {for _be ,_cc :=range _bbc ._e .Objects {if _cc ==_dd {if outputIntents ._ga ==_dd {return ; 29 | };_bbc ._e .Objects =append (_bbc ._e .Objects [:_be ],_bbc ._e .Objects [_be +1:]...);break ;};};};_beb :=outputIntents ._ga ;if _beb ==nil {_beb =_a .MakeIndirectObject (outputIntents ._bec );};_bbc .Object .Set ("\u004f\u0075\u0074\u0070\u0075\u0074\u0049\u006e\u0074\u0065\u006e\u0074\u0073",_beb ); 30 | _bbc ._e .Objects =append (_bbc ._e .Objects ,_beb );};func (_ebd Page )FindXObjectForms ()[]*_a .PdfObjectStream {_bbb ,_da :=_ebd .GetResourcesXObject ();if !_da {return nil ;};_fdd :=map[*_a .PdfObjectStream ]struct{}{};var _egaa func (_dfe *_a .PdfObjectDictionary ,_aae map[*_a .PdfObjectStream ]struct{}); 31 | _egaa =func (_acb *_a .PdfObjectDictionary ,_aea map[*_a .PdfObjectStream ]struct{}){for _ ,_dab :=range _acb .Keys (){_aga ,_cba :=_a .GetStream (_acb .Get (_dab ));if !_cba {continue ;};if _ ,_bgb :=_aea [_aga ];_bgb {continue ;};_fgd ,_aaf :=_a .GetName (_aga .Get ("\u0053u\u0062\u0074\u0079\u0070\u0065")); 32 | if !_aaf ||_fgd .String ()!="\u0046\u006f\u0072\u006d"{continue ;};_aea [_aga ]=struct{}{};_feae ,_aaf :=_a .GetDict (_aga .Get ("\u0052e\u0073\u006f\u0075\u0072\u0063\u0065s"));if !_aaf {continue ;};_daf ,_ecef :=_a .GetDict (_feae .Get ("\u0058O\u0062\u006a\u0065\u0063\u0074")); 33 | if _ecef {_egaa (_daf ,_aea );};};};_egaa (_bbb ,_fdd );var _bef []*_a .PdfObjectStream ;for _ab :=range _fdd {_bef =append (_bef ,_ab );};return _bef ;};func (_gc *Catalog )SetVersion (){_gc .Object .Set ("\u0056e\u0072\u0073\u0069\u006f\u006e",_a .MakeName (_c .Sprintf ("\u0025\u0064\u002e%\u0064",_gc ._e .Version .Major ,_gc ._e .Version .Minor ))); 34 | };type OutputIntent struct{Object *_a .PdfObjectDictionary ;};func (_cg *OutputIntents )Get (i int )(OutputIntent ,bool ){if _cg ._bec ==nil {return OutputIntent {},false ;};if i >=_cg ._bec .Len (){return OutputIntent {},false ;};_bc :=_cg ._bec .Get (i ); 35 | _ebf ,_dgd :=_a .GetIndirect (_bc );if !_dgd {_cff ,_gde :=_a .GetDict (_bc );return OutputIntent {Object :_cff },_gde ;};_ebe ,_fbg :=_a .GetDict (_ebf .PdfObject );return OutputIntent {Object :_ebe },_fbg ;};func (_gag *OutputIntents )Add (oi _a .PdfObject )error {_eg ,_fc :=oi .(*_a .PdfObjectDictionary ); 36 | if !_fc {return _d .New ("\u0069\u006e\u0070\u0075\u0074\u0020\u006f\u0075\u0074\u0070\u0075\u0074\u0020\u0069\u006e\u0074\u0065\u006et\u0020\u0073\u0068\u006f\u0075\u006c\u0064 \u0062\u0065\u0020\u0061\u006e\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0064\u0069\u0063\u0074\u0069\u006f\u006e\u0061\u0072\u0079"); 37 | };if _fge ,_faf :=_a .GetStream (_eg .Get ("\u0044\u0065\u0073\u0074\u004f\u0075\u0074\u0070\u0075\u0074\u0050\u0072o\u0066\u0069\u006c\u0065"));_faf {_gag ._agc .Objects =append (_gag ._agc .Objects ,_fge );};_adg ,_dfg :=oi .(*_a .PdfIndirectObject ); 38 | if !_dfg {_adg =_a .MakeIndirectObject (oi );};if _gag ._bec ==nil {_gag ._bec =_a .MakeArray (_adg );}else {_gag ._bec .Append (_adg );};_gag ._agc .Objects =append (_gag ._agc .Objects ,_adg );return nil ;};func (_ddf *Document )GetPages ()([]Page ,bool ){_ecdd ,_edg :=_ddf .FindCatalog (); 39 | if !_edg {return nil ,false ;};return _ecdd .GetPages ();};func (_faa *Document )AddIndirectObject (indirect *_a .PdfIndirectObject ){for _ ,_cfg :=range _faa .Objects {if _cfg ==indirect {return ;};};_faa .Objects =append (_faa .Objects ,indirect );}; 40 | func (_ea *Catalog )GetMetadata ()(*_a .PdfObjectStream ,bool ){return _a .GetStream (_ea .Object .Get ("\u004d\u0065\u0074\u0061\u0064\u0061\u0074\u0061"));};func (_bce *Document )AddStream (stream *_a .PdfObjectStream ){for _ ,_fbb :=range _bce .Objects {if _fbb ==stream {return ; 41 | };};_bce .Objects =append (_bce .Objects ,stream );};func (_gcf *Page )Number ()int {return _gcf ._bf };func (_ec *Catalog )GetMarkInfo ()(*_a .PdfObjectDictionary ,bool ){_cf ,_eb :=_a .GetDict (_ec .Object .Get ("\u004d\u0061\u0072\u006b\u0049\u006e\u0066\u006f")); 42 | return _cf ,_eb ;};func (_ebb *Content )SetData (data []byte )error {_dgde ,_ggef :=_a .MakeStream (data ,_a .NewFlateEncoder ());if _ggef !=nil {return _ggef ;};_edgg ,_aad :=_a .GetArray (_ebb ._eef .Object .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073")); 43 | if !_aad &&_ebb ._deg ==0{_ebb ._eef .Object .Set ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073",_dgde );}else {if _ggef =_edgg .Set (_ebb ._deg ,_dgde );_ggef !=nil {return _ggef ;};};_ebb ._eef ._gfe .Objects =append (_ebb ._eef ._gfe .Objects ,_dgde ); 44 | return nil ;};type Page struct{_bf int ;Object *_a .PdfObjectDictionary ;_gfe *Document ;};type Catalog struct{Object *_a .PdfObjectDictionary ;_e *Document ;};func (_ad *Catalog )SetMetadata (data []byte )error {_gga ,_fb :=_a .MakeStream (data ,nil ); 45 | if _fb !=nil {return _fb ;};_gga .Set ("\u0054\u0079\u0070\u0065",_a .MakeName ("\u004d\u0065\u0074\u0061\u0064\u0061\u0074\u0061"));_gga .Set ("\u0053u\u0062\u0074\u0079\u0070\u0065",_a .MakeName ("\u0058\u004d\u004c"));_ad .Object .Set ("\u004d\u0065\u0074\u0061\u0064\u0061\u0074\u0061",_gga ); 46 | _ad ._e .Objects =append (_ad ._e .Objects ,_gga );return nil ;};type ImageSMask struct{Image *Image ;Stream *_a .PdfObjectStream ;};func (_gb *Catalog )NewOutputIntents ()*OutputIntents {return &OutputIntents {_agc :_gb ._e }};func (_ebg *OutputIntents )Len ()int {return _ebg ._bec .Len ()}; 47 | func (_ece *Catalog )GetOutputIntents ()(*OutputIntents ,bool ){_ecd :=_ece .Object .Get ("\u004f\u0075\u0074\u0070\u0075\u0074\u0049\u006e\u0074\u0065\u006e\u0074\u0073");if _ecd ==nil {return nil ,false ;};_aa ,_ed :=_a .GetIndirect (_ecd );if !_ed {return nil ,false ; 48 | };_bbd ,_af :=_a .GetArray (_aa .PdfObject );if !_af {return nil ,false ;};return &OutputIntents {_ga :_aa ,_bec :_bbd ,_agc :_ece ._e },true ;};type Content struct{Stream *_a .PdfObjectStream ;_deg int ;_eef Page ;};func (_fe *Catalog )GetPages ()([]Page ,bool ){_dg ,_df :=_a .GetDict (_fe .Object .Get ("\u0050\u0061\u0067e\u0073")); 49 | if !_df {return nil ,false ;};_fg ,_gg :=_a .GetArray (_dg .Get ("\u004b\u0069\u0064\u0073"));if !_gg {return nil ,false ;};_ae :=make ([]Page ,_fg .Len ());for _ce ,_ag :=range _fg .Elements (){_ca ,_b :=_a .GetDict (_ag );if !_b {continue ;};_ae [_ce ]=Page {Object :_ca ,_bf :_ce +1,_gfe :_fe ._e }; 50 | };return _ae ,true ;};func (_ade Content )GetData ()([]byte ,error ){_aace ,_efe :=_a .NewEncoderFromStream (_ade .Stream );if _efe !=nil {return nil ,_efe ;};_afe ,_efe :=_aace .DecodeStream (_ade .Stream );if _efe !=nil {return nil ,_efe ;};return _afe ,nil ; 51 | };func (_bb *Catalog )SetMarkInfo (mi _a .PdfObject ){if mi ==nil {_bb .Object .Remove ("\u004d\u0061\u0072\u006b\u0049\u006e\u0066\u006f");return ;};_fa :=_a .MakeIndirectObject (mi );_bb .Object .Set ("\u004d\u0061\u0072\u006b\u0049\u006e\u0066\u006f",_fa ); 52 | _bb ._e .Objects =append (_bb ._e .Objects ,_fa );};func _age (_fbd _a .PdfObject )(_a .PdfObjectName ,error ){var _afgb *_a .PdfObjectName ;var _gcb *_a .PdfObjectArray ;if _gf ,_ff :=_fbd .(*_a .PdfIndirectObject );_ff {if _egf ,_ecf :=_gf .PdfObject .(*_a .PdfObjectArray ); 53 | _ecf {_gcb =_egf ;}else if _eba ,_gdg :=_gf .PdfObject .(*_a .PdfObjectName );_gdg {_afgb =_eba ;};}else if _cgf ,_afd :=_fbd .(*_a .PdfObjectArray );_afd {_gcb =_cgf ;}else if _fafe ,_fea :=_fbd .(*_a .PdfObjectName );_fea {_afgb =_fafe ;};if _afgb !=nil {switch *_afgb {case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079","\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B","\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":return *_afgb ,nil ; 54 | case "\u0050a\u0074\u0074\u0065\u0072\u006e":return *_afgb ,nil ;};};if _gcb !=nil &&_gcb .Len ()> 0{if _aeg ,_cgg :=_gcb .Get (0).(*_a .PdfObjectName );_cgg {switch *_aeg {case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079","\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B","\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":if _gcb .Len ()==1{return *_aeg ,nil ; 55 | };case "\u0043a\u006c\u0047\u0072\u0061\u0079","\u0043\u0061\u006c\u0052\u0047\u0042","\u004c\u0061\u0062":return *_aeg ,nil ;case "\u0049\u0043\u0043\u0042\u0061\u0073\u0065\u0064","\u0050a\u0074\u0074\u0065\u0072\u006e","\u0049n\u0064\u0065\u0078\u0065\u0064":return *_aeg ,nil ; 56 | case "\u0053\u0065\u0070\u0061\u0072\u0061\u0074\u0069\u006f\u006e","\u0044e\u0076\u0069\u0063\u0065\u004e":return *_aeg ,nil ;};};};return "",nil ;};type OutputIntents struct{_bec *_a .PdfObjectArray ;_agc *Document ;_ga *_a .PdfIndirectObject ;}; -------------------------------------------------------------------------------- /model/optimize/tests/tests.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 tests provides integration tests for the UniPDF optimizer. The test requires environment variable 13 | // UNIDOC_OPTIMIZE_TESTDATA to be set for the directory with `.pdf` files, otherwise the test is skipped. 14 | package tests ; -------------------------------------------------------------------------------- /model/sigutil/sigutil.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 sigutil ;import (_b "bytes";_f "crypto";_a "crypto/x509";_g "encoding/asn1";_de "encoding/pem";_d "errors";_fg "fmt";_ec "github.com/unidoc/timestamp";_ea "github.com/unidoc/unipdf/v4/common";_eb "golang.org/x/crypto/ocsp";_da "io";_bg "net/http"; 13 | _c "time";);func _acbg ()*_bg .Client {return &_bg .Client {Timeout :5*_c .Second }}; 14 | 15 | // NewOCSPClient returns a new OCSP client. 16 | func NewOCSPClient ()*OCSPClient {return &OCSPClient {HTTPClient :_acbg (),Hash :_f .SHA1 }}; 17 | 18 | // GetIssuer retrieves the issuer of the provided certificate. 19 | func (_eaa *CertClient )GetIssuer (cert *_a .Certificate )(*_a .Certificate ,error ){for _ ,_ce :=range cert .IssuingCertificateURL {_ecc ,_ac :=_eaa .Get (_ce );if _ac !=nil {_ea .Log .Debug ("\u0057\u0041\u0052\u004e\u003a\u0020\u0063\u006f\u0075\u006c\u0064\u0020\u006e\u006f\u0074 \u0064\u006f\u0077\u006e\u006c\u006f\u0061\u0064\u0020\u0069\u0073\u0073\u0075e\u0072\u0020\u0066\u006f\u0072\u0020\u0063\u0065\u0072\u0074\u0069\u0066ic\u0061\u0074\u0065\u0020\u0025\u0076\u003a\u0020\u0025\u0076",cert .Subject .CommonName ,_ac ); 20 | continue ;};return _ecc ,nil ;};return nil ,_fg .Errorf ("\u0069\u0073\u0073\u0075e\u0072\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063a\u0074e\u0020\u006e\u006f\u0074\u0020\u0066\u006fu\u006e\u0064");}; 21 | 22 | // CRLClient represents a CRL (Certificate revocation list) client. 23 | // It is used to request revocation data from CRL servers. 24 | type CRLClient struct{ 25 | 26 | // HTTPClient is the HTTP client used to make CRL requests. 27 | // By default, an HTTP client with a 5 second timeout per request is used. 28 | HTTPClient *_bg .Client ;}; 29 | 30 | // GetEncodedToken executes the timestamp request and returns the DER encoded 31 | // timestamp token bytes. 32 | func (_acc *TimestampClient )GetEncodedToken (serverURL string ,req *_ec .Request )([]byte ,error ){if serverURL ==""{return nil ,_fg .Errorf ("\u006d\u0075\u0073\u0074\u0020\u0070r\u006f\u0076\u0069\u0064\u0065\u0020\u0074\u0069\u006d\u0065\u0073\u0074\u0061m\u0070\u0020\u0073\u0065\u0072\u0076\u0065r\u0020\u0055\u0052\u004c"); 33 | };if req ==nil {return nil ,_fg .Errorf ("\u0074\u0069\u006de\u0073\u0074\u0061\u006dp\u0020\u0072\u0065\u0071\u0075\u0065\u0073t\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c");};_bb ,_fbf :=req .Marshal ();if _fbf !=nil {return nil ,_fbf ; 34 | };_dcg ,_fbf :=_bg .NewRequest ("\u0050\u004f\u0053\u0054",serverURL ,_b .NewBuffer (_bb ));if _fbf !=nil {return nil ,_fbf ;};_dcg .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","a\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u002f\u0074\u0069\u006d\u0065\u0073t\u0061\u006d\u0070-\u0071u\u0065\u0072\u0079"); 35 | if _acc .BeforeHTTPRequest !=nil {if _acb :=_acc .BeforeHTTPRequest (_dcg );_acb !=nil {return nil ,_acb ;};};_ad :=_acc .HTTPClient ;if _ad ==nil {_ad =_acbg ();};_acf ,_fbf :=_ad .Do (_dcg );if _fbf !=nil {return nil ,_fbf ;};defer _acf .Body .Close (); 36 | _gdef ,_fbf :=_da .ReadAll (_acf .Body );if _fbf !=nil {return nil ,_fbf ;};if _acf .StatusCode !=_bg .StatusOK {return nil ,_fg .Errorf ("\u0075\u006e\u0065x\u0070\u0065\u0063\u0074e\u0064\u0020\u0048\u0054\u0054\u0050\u0020s\u0074\u0061\u0074\u0075\u0073\u0020\u0063\u006f\u0064\u0065\u003a\u0020\u0025\u0064",_acf .StatusCode ); 37 | };var _dab struct{Version _g .RawValue ;Content _g .RawValue ;};if _ ,_fbf =_g .Unmarshal (_gdef ,&_dab );_fbf !=nil {return nil ,_fbf ;};return _dab .Content .FullBytes ,nil ;}; 38 | 39 | // TimestampClient represents a RFC 3161 timestamp client. 40 | // It is used to obtain signed tokens from timestamp authority servers. 41 | type TimestampClient struct{ 42 | 43 | // HTTPClient is the HTTP client used to make timestamp requests. 44 | // By default, an HTTP client with a 5 second timeout per request is used. 45 | HTTPClient *_bg .Client ; 46 | 47 | // Callbacks. 48 | BeforeHTTPRequest func (_gde *_bg .Request )error ;}; 49 | 50 | // Get retrieves the certificate at the specified URL. 51 | func (_df *CertClient )Get (url string )(*_a .Certificate ,error ){if _df .HTTPClient ==nil {_df .HTTPClient =_acbg ();};_dae ,_eg :=_df .HTTPClient .Get (url );if _eg !=nil {return nil ,_eg ;};defer _dae .Body .Close ();_gd ,_eg :=_da .ReadAll (_dae .Body ); 52 | if _eg !=nil {return nil ,_eg ;};if _ebf ,_ :=_de .Decode (_gd );_ebf !=nil {_gd =_ebf .Bytes ;};_fc ,_eg :=_a .ParseCertificate (_gd );if _eg !=nil {return nil ,_eg ;};return _fc ,nil ;}; 53 | 54 | // MakeRequest makes a CRL request to the specified server and returns the 55 | // response. If a server URL is not provided, it is extracted from the certificate. 56 | func (_eba *CRLClient )MakeRequest (serverURL string ,cert *_a .Certificate )([]byte ,error ){if _eba .HTTPClient ==nil {_eba .HTTPClient =_acbg ();};if serverURL ==""{if len (cert .CRLDistributionPoints )==0{return nil ,_d .New ("\u0063e\u0072\u0074i\u0066\u0069\u0063\u0061t\u0065\u0020\u0064o\u0065\u0073\u0020\u006e\u006f\u0074\u0020\u0073\u0070ec\u0069\u0066\u0079 \u0061\u006ey\u0020\u0043\u0052\u004c\u0020\u0073e\u0072\u0076e\u0072\u0073"); 57 | };serverURL =cert .CRLDistributionPoints [0];};_gc ,_dc :=_eba .HTTPClient .Get (serverURL );if _dc !=nil {return nil ,_dc ;};defer _gc .Body .Close ();_dfb ,_dc :=_da .ReadAll (_gc .Body );if _dc !=nil {return nil ,_dc ;};if _gf ,_ :=_de .Decode (_dfb ); 58 | _gf !=nil {_dfb =_gf .Bytes ;};return _dfb ,nil ;}; 59 | 60 | // NewTimestampClient returns a new timestamp client. 61 | func NewTimestampClient ()*TimestampClient {return &TimestampClient {HTTPClient :_acbg ()}}; 62 | 63 | // IsCA returns true if the provided certificate appears to be a CA certificate. 64 | func (_fb *CertClient )IsCA (cert *_a .Certificate )bool {return cert .IsCA &&_b .Equal (cert .RawIssuer ,cert .RawSubject );}; 65 | 66 | // CertClient represents a X.509 certificate client. Its primary purpose 67 | // is to download certificates. 68 | type CertClient struct{ 69 | 70 | // HTTPClient is the HTTP client used to make certificate requests. 71 | // By default, an HTTP client with a 5 second timeout per request is used. 72 | HTTPClient *_bg .Client ;}; 73 | 74 | // NewCRLClient returns a new CRL client. 75 | func NewCRLClient ()*CRLClient {return &CRLClient {HTTPClient :_acbg ()}}; 76 | 77 | // NewTimestampRequest returns a new timestamp request based 78 | // on the specified options. 79 | func NewTimestampRequest (body _da .Reader ,opts *_ec .RequestOptions )(*_ec .Request ,error ){if opts ==nil {opts =&_ec .RequestOptions {};};if opts .Hash ==0{opts .Hash =_f .SHA256 ;};if !opts .Hash .Available (){return nil ,_a .ErrUnsupportedAlgorithm ; 80 | };_dfg :=opts .Hash .New ();if _ ,_dea :=_da .Copy (_dfg ,body );_dea !=nil {return nil ,_dea ;};return &_ec .Request {HashAlgorithm :opts .Hash ,HashedMessage :_dfg .Sum (nil ),Certificates :opts .Certificates ,TSAPolicyOID :opts .TSAPolicyOID ,Nonce :opts .Nonce },nil ; 81 | }; 82 | 83 | // OCSPClient represents a OCSP (Online Certificate Status Protocol) client. 84 | // It is used to request revocation data from OCSP servers. 85 | type OCSPClient struct{ 86 | 87 | // HTTPClient is the HTTP client used to make OCSP requests. 88 | // By default, an HTTP client with a 5 second timeout per request is used. 89 | HTTPClient *_bg .Client ; 90 | 91 | // Hash is the hash function used when constructing the OCSP 92 | // requests. If zero, SHA-1 will be used. 93 | Hash _f .Hash ;}; 94 | 95 | // MakeRequest makes a OCSP request to the specified server and returns 96 | // the parsed and raw responses. If a server URL is not provided, it is 97 | // extracted from the certificate. 98 | func (_ba *OCSPClient )MakeRequest (serverURL string ,cert ,issuer *_a .Certificate )(*_eb .Response ,[]byte ,error ){if _ba .HTTPClient ==nil {_ba .HTTPClient =_acbg ();};if serverURL ==""{if len (cert .OCSPServer )==0{return nil ,nil ,_d .New ("\u0063e\u0072\u0074i\u0066\u0069\u0063a\u0074\u0065\u0020\u0064\u006f\u0065\u0073 \u006e\u006f\u0074\u0020\u0073\u0070e\u0063\u0069\u0066\u0079\u0020\u0061\u006e\u0079\u0020\u004f\u0043S\u0050\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0073"); 99 | };serverURL =cert .OCSPServer [0];};_ae ,_fbd :=_eb .CreateRequest (cert ,issuer ,&_eb .RequestOptions {Hash :_ba .Hash });if _fbd !=nil {return nil ,nil ,_fbd ;};_eaaa ,_fbd :=_ba .HTTPClient .Post (serverURL ,"\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u006fc\u0073\u0070\u002d\u0072\u0065\u0071\u0075\u0065\u0073\u0074",_b .NewReader (_ae )); 100 | if _fbd !=nil {return nil ,nil ,_fbd ;};defer _eaaa .Body .Close ();_daa ,_fbd :=_da .ReadAll (_eaaa .Body );if _fbd !=nil {return nil ,nil ,_fbd ;};if _ag ,_ :=_de .Decode (_daa );_ag !=nil {_daa =_ag .Bytes ;};_ga ,_fbd :=_eb .ParseResponseForCert (_daa ,cert ,issuer ); 101 | if _fbd !=nil {return nil ,nil ,_fbd ;};return _ga ,_daa ,nil ;}; 102 | 103 | // NewCertClient returns a new certificate client. 104 | func NewCertClient ()*CertClient {return &CertClient {HTTPClient :_acbg ()}}; -------------------------------------------------------------------------------- /model/xmputil/pdfaid/pdfaid.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 pdfaid ;import (_b "fmt";_c "github.com/trimmer-io/go-xmp/xmp";_f "github.com/unidoc/unipdf/v4/model/xmputil/pdfaextension";); 13 | 14 | // CanTag implements xmp.Model interface. 15 | func (_abaf *Model )CanTag (tag string )bool {_ ,_dg :=_c .GetNativeField (_abaf ,tag );return _dg ==nil ;};func init (){_c .Register (Namespace ,_c .XmpMetadata );_f .RegisterSchema (Namespace ,&Schema )}; 16 | 17 | // SyncModel implements xmp.Model interface. 18 | func (_aba *Model )SyncModel (d *_c .Document )error {return nil }; 19 | 20 | // MakeModel gets or create sa new model for PDF/A ID namespace. 21 | func MakeModel (d *_c .Document )(*Model ,error ){_ab ,_d :=d .MakeModel (Namespace );if _d !=nil {return nil ,_d ;};return _ab .(*Model ),nil ;};var _ _c .Model =(*Model )(nil ); 22 | 23 | // SyncFromXMP implements xmp.Model interface. 24 | func (_ee *Model )SyncFromXMP (d *_c .Document )error {return nil }; 25 | 26 | // Model is the XMP model for the PdfA metadata. 27 | type Model struct{Part int `xmp:"pdfaid:part"`;Conformance string `xmp:"pdfaid:conformance"`;};var Schema =_f .Schema {NamespaceURI :Namespace .URI ,Prefix :Namespace .Name ,Schema :"\u0050D\u0046/\u0041\u0020\u0049\u0044\u0020\u0053\u0063\u0068\u0065\u006d\u0061",Property :[]_f .Property {{Category :_f .PropertyCategoryInternal ,Description :"\u0050\u0061\u0072\u0074 o\u0066\u0020\u0050\u0044\u0046\u002f\u0041\u0020\u0073\u0074\u0061\u006e\u0064\u0061r\u0064",Name :"\u0070\u0061\u0072\u0074",ValueType :_f .ValueTypeNameInteger },{Category :_f .PropertyCategoryInternal ,Description :"A\u006d\u0065\u006e\u0064\u006d\u0065n\u0074\u0020\u006f\u0066\u0020\u0050\u0044\u0046\u002fA\u0020\u0073\u0074a\u006ed\u0061\u0072\u0064",Name :"\u0061\u006d\u0064",ValueType :_f .ValueTypeNameText },{Category :_f .PropertyCategoryInternal ,Description :"C\u006f\u006e\u0066\u006f\u0072\u006da\u006e\u0063\u0065\u0020\u006c\u0065v\u0065\u006c\u0020\u006f\u0066\u0020\u0050D\u0046\u002f\u0041\u0020\u0073\u0074\u0061\u006e\u0064\u0061r\u0064",Name :"c\u006f\u006e\u0066\u006f\u0072\u006d\u0061\u006e\u0063\u0065",ValueType :_f .ValueTypeNameText }},ValueType :nil }; 28 | 29 | 30 | // Namespaces implements xmp.Model interface. 31 | func (_fe *Model )Namespaces ()_c .NamespaceList {return _c .NamespaceList {Namespace }}; 32 | 33 | // Can implements xmp.Model interface. 34 | func (_da *Model )Can (nsName string )bool {return Namespace .GetName ()==nsName }; 35 | 36 | // SyncToXMP implements xmp.Model interface. 37 | func (_bg *Model )SyncToXMP (d *_c .Document )error {return nil }; 38 | 39 | // SetTag implements xmp.Model interface. 40 | func (_g *Model )SetTag (tag ,value string )error {if _cf :=_c .SetNativeField (_g ,tag ,value );_cf !=nil {return _b .Errorf ("\u0025\u0073\u003a\u0020\u0025\u0076",Namespace .GetName (),_cf );};return nil ;};var Namespace =_c .NewNamespace ("\u0070\u0064\u0066\u0061\u0069\u0064","\u0068\u0074\u0074p\u003a\u002f\u002f\u0077w\u0077\u002e\u0061\u0069\u0069\u006d\u002eo\u0072\u0067\u002f\u0070\u0064\u0066\u0061\u002f\u006e\u0073\u002f\u0069\u0064\u002f",NewModel ); 41 | 42 | 43 | // GetTag implements xmp.Model interface. 44 | func (_de *Model )GetTag (tag string )(string ,error ){_eg ,_bd :=_c .GetNativeField (_de ,tag );if _bd !=nil {return "",_b .Errorf ("\u0025\u0073\u003a\u0020\u0025\u0076",Namespace .GetName (),_bd );};return _eg ,nil ;}; 45 | 46 | // NewModel creates a new model. 47 | func NewModel (name string )_c .Model {return &Model {}}; -------------------------------------------------------------------------------- /pdfutil/pdfutil.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 pdfutil ;import (_c "github.com/unidoc/unipdf/v4/common";_cb "github.com/unidoc/unipdf/v4/contentstream";_f "github.com/unidoc/unipdf/v4/contentstream/draw";_a "github.com/unidoc/unipdf/v4/core";_bf "github.com/unidoc/unipdf/v4/model";); 13 | 14 | // NormalizePage performs the following operations on the passed in page: 15 | // - Normalize the page rotation. 16 | // Rotates the contents of the page according to the Rotate entry, thus 17 | // flattening the rotation. The Rotate entry of the page is set to nil. 18 | // - Normalize the media box. 19 | // If the media box of the page is offsetted (Llx != 0 or Lly != 0), 20 | // the contents of the page are translated to (-Llx, -Lly). After 21 | // normalization, the media box is updated (Llx and Lly are set to 0 and 22 | // Urx and Ury are updated accordingly). 23 | // - Normalize the crop box. 24 | // The crop box of the page is updated based on the previous operations. 25 | // 26 | // After normalization, the page should look the same if openend using a 27 | // PDF viewer. 28 | // NOTE: This function does not normalize annotations, outlines other parts 29 | // that are not part of the basic geometry and page content streams. 30 | func NormalizePage (page *_bf .PdfPage )error {_ae ,_g :=page .GetMediaBox ();if _g !=nil {return _g ;};_e ,_g :=page .GetRotate ();if _g !=nil {_c .Log .Debug ("\u0045\u0052R\u004f\u0052\u003a\u0020\u0025\u0073\u0020\u002d\u0020\u0069\u0067\u006e\u006f\u0072\u0069\u006e\u0067\u0020\u0061\u006e\u0064\u0020\u0061\u0073\u0073\u0075\u006d\u0069\u006e\u0067\u0020\u006e\u006f\u0020\u0072\u006f\u0074\u0061\u0074\u0069\u006f\u006e\u000a",_g .Error ()); 31 | };_ff :=_e %360!=0&&_e %90==0;_ae .Normalize ();_d ,_gf ,_ce ,_fc :=_ae .Llx ,_ae .Lly ,_ae .Width (),_ae .Height ();_gb :=_d !=0||_gf !=0;if !_ff &&!_gb {return nil ;};_ee :=func (_dc ,_fcc ,_fa float64 )_f .BoundingBox {return _f .Path {Points :[]_f .Point {_f .NewPoint (0,0).Rotate (_fa ),_f .NewPoint (_dc ,0).Rotate (_fa ),_f .NewPoint (0,_fcc ).Rotate (_fa ),_f .NewPoint (_dc ,_fcc ).Rotate (_fa )}}.GetBoundingBox (); 32 | };_aa :=_cb .NewContentCreator ();var _cbd float64 ;if _ff {_cbd =-float64 (_e );_aee :=_ee (_ce ,_fc ,_cbd );_aa .Translate ((_aee .Width -_ce )/2+_ce /2,(_aee .Height -_fc )/2+_fc /2);_aa .RotateDeg (_cbd );_aa .Translate (-_ce /2,-_fc /2);_ce ,_fc =_aee .Width ,_aee .Height ; 33 | };if _gb {_aa .Translate (-_d ,-_gf );};_bg :=_aa .Operations ();_de ,_g :=_a .MakeStream (_bg .Bytes (),_a .NewFlateEncoder ());if _g !=nil {return _g ;};_cd :=_a .MakeArray (_de );_cd .Append (page .GetContentStreamObjs ()...);*_ae =_bf .PdfRectangle {Urx :_ce ,Ury :_fc }; 34 | if _fg :=page .CropBox ;_fg !=nil {_fg .Normalize ();_gfc ,_gc ,_gd ,_fe :=_fg .Llx -_d ,_fg .Lly -_gf ,_fg .Width (),_fg .Height ();if _ff {_gdb :=_ee (_gd ,_fe ,_cbd );_gd ,_fe =_gdb .Width ,_gdb .Height ;};*_fg =_bf .PdfRectangle {Llx :_gfc ,Lly :_gc ,Urx :_gfc +_gd ,Ury :_gc +_fe }; 35 | };_c .Log .Debug ("\u0052\u006f\u0074\u0061\u0074\u0065\u003d\u0025\u0066\u00b0\u0020\u004f\u0070\u0073\u003d%\u0071 \u004d\u0065\u0064\u0069\u0061\u0042\u006f\u0078\u003d\u0025\u002e\u0032\u0066",_cbd ,_bg ,_ae );page .Contents =_cd ;page .Rotate =nil ; 36 | return nil ;}; -------------------------------------------------------------------------------- /render/internal/context/context.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 context ;import (_g "errors";_ea "github.com/unidoc/freetype/truetype";_aa "github.com/unidoc/unipdf/v4/core";_ec "github.com/unidoc/unipdf/v4/internal/cmap";_d "github.com/unidoc/unipdf/v4/internal/textencoding";_eb "github.com/unidoc/unipdf/v4/internal/transform"; 13 | _efe "github.com/unidoc/unipdf/v4/model";_gc "golang.org/x/image/font";_gf "image";_b "image/color";_ef "strconv";_a "strings";);func (_ce *TextFont )charcodeToRunesSimple (_ff _d .CharCode )(_d .CharCode ,[]rune ){_fde :=[]_d .CharCode {_ff };if _ce .Font .IsSimple ()&&_ce ._dd !=nil {if _edg :=_ce ._dd .Index (rune (_ff )); 14 | _edg > 0{return _ff ,[]rune {rune (_ff )};};};if _ce ._dd !=nil &&!_ce ._dd .HasCmap ()&&_a .Contains (_ce .Font .Encoder ().String (),"\u0049d\u0065\u006e\u0074\u0069\u0074\u0079-"){if _bef :=_ce ._dd .Index (rune (_ff ));_bef > 0{return _ff ,[]rune {rune (_ff )}; 15 | };};return _ff ,_ce .Font .CharcodesToUnicode (_fde );};const (LineJoinRound LineJoin =iota ;LineJoinBevel ;);func (_ebgb *TextState )ProcTj (data []byte ,ctx Context ){_cg :=_ebgb .Tf .Size ;_gecd :=_ebgb .Th /100.0;_eac :=_ebgb .GlobalScale ;_dga :=_eb .NewMatrix (_cg *_gecd ,0,0,_cg ,0,_ebgb .Ts ); 16 | _edbd :=ctx .Matrix ();_efcc :=_edbd .Clone ().Mult (_ebgb .Tm .Clone ().Mult (_dga )).ScalingFactorY ();_gfd :=_ebgb .Tf .NewFace (_efcc );_bbf :=_ebgb .Tf .BytesToCharcodes (data );for _ ,_facea :=range _bbf {_edde ,_ebgg :=_ebgb .Tf .CharcodeToRunes (_facea ); 17 | _eddf :=string (_ebgg );if _eddf =="\u0000"{continue ;};_cba :=_edbd .Clone ().Mult (_ebgb .Tm .Clone ().Mult (_dga ));_cea :=_cba .ScalingFactorY ();_cba =_cba .Scale (1/_cea ,-1/_cea );if _ebgb .Tr !=TextRenderingModeInvisible {ctx .SetMatrix (_cba ); 18 | ctx .DrawString (_eddf ,_gfd ,0,0);ctx .SetMatrix (_edbd );};_dfa :=0.0;if _eddf =="\u0020"{_dfa =_ebgb .Tw ;};_aba ,_ ,_bbd :=_ebgb .Tf .GetCharMetrics (_edde );if _bbd {_aba =_aba *0.001*_cg ;}else {_aba ,_ =ctx .MeasureString (_eddf ,_gfd );_aba =_aba /_eac ; 19 | };_ecc :=(_aba +_ebgb .Tc +_dfa )*_gecd ;_ebgb .Tm =_ebgb .Tm .Mult (_eb .TranslationMatrix (_ecc ,0));};};func NewTextState ()TextState {return TextState {Th :100,Tm :_eb .IdentityMatrix (),Tlm :_eb .IdentityMatrix ()};};func (_eegd *TextState )ProcTStar (){_eegd .ProcTd (0,-_eegd .Tl )}; 20 | const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ;);const (FillRuleWinding FillRule =iota ;FillRuleEvenOdd ;);type TextRenderingMode int ;func (_ead *TextFont )WithSize (size float64 ,originalFont *_efe .PdfFont )*TextFont {return &TextFont {Font :_ead .Font ,Size :size ,_dd :_ead ._dd ,_gaeg :originalFont }; 21 | };func (_gb *TextFont )NewFace (size float64 )_gc .Face {return _ea .NewFace (_gb ._dd ,&_ea .Options {Size :size });};func (_deba *TextState )ProcTf (font *TextFont ){_deba .Tf =font };func (_gba *TextState )ProcTD (tx ,ty float64 ){_gba .Tl =-ty ;_gba .ProcTd (tx ,ty )}; 22 | func NewTextFont (font *_efe .PdfFont ,size float64 )(*TextFont ,error ){_cd :=font .FontDescriptor ();if _cd ==nil {return nil ,_g .New ("\u0063\u006fu\u006c\u0064\u0020\u006e\u006f\u0074\u0020\u0067\u0065\u0074\u0020\u0066\u006f\u006e\u0074\u0020\u0064\u0065\u0073\u0063\u0072\u0069pt\u006f\u0072"); 23 | };_cad ,_gcd :=_aa .GetStream (_cd .FontFile2 );if !_gcd {return nil ,_g .New ("\u006di\u0073\u0073\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u0020f\u0069\u006c\u0065\u0020\u0073\u0074\u0072\u0065\u0061\u006d");};_ade ,_aed :=_aa .DecodeStream (_cad ); 24 | if _aed !=nil {return nil ,_aed ;};_dbb ,_aed :=_ea .Parse (_ade );if _aed !=nil {return nil ,_aed ;};_beg :=font .FontDescriptor ().FontName .String ();_face :=len (_beg )> 7&&_beg [6]=='+';if _cd .Flags !=nil {_gfgc ,_fc :=_ef .Atoi (_cd .Flags .String ()); 25 | if _fc ==nil &&_gfgc ==32{_face =false ;};};if !_dbb .HasCmap ()&&(!_a .Contains (font .Encoder ().String (),"\u0049d\u0065\u006e\u0074\u0069\u0074\u0079-")||!_face ){return nil ,_g .New ("\u006e\u006f c\u006d\u0061\u0070 \u0061\u006e\u0064\u0020enc\u006fdi\u006e\u0067\u0020\u0069\u0073\u0020\u006eot\u0020\u0069\u0064\u0065\u006e\u0074\u0069t\u0079"); 26 | };return &TextFont {Font :font ,Size :size ,_dd :_dbb },nil ;};func (_ebd *TextState )ProcQ (data []byte ,ctx Context ){_ebd .ProcTStar ();_ebd .ProcTj (data ,ctx )};func (_bdf *TextState )Translate (tx ,ty float64 ){_bdf .Tm =_bdf .Tm .Mult (_eb .TranslationMatrix (tx ,ty )); 27 | };func (_dbf *TextFont )GetCharMetrics (code _d .CharCode )(float64 ,float64 ,bool ){if _bbg ,_dee :=_dbf .Font .GetCharMetrics (code );_dee &&_bbg .Wx !=0{return _bbg .Wx ,_bbg .Wy ,_dee ;};if _dbf ._gaeg ==nil {return 0,0,false ;};_eeg ,_fef :=_dbf ._gaeg .GetCharMetrics (code ); 28 | return _eeg .Wx ,_eeg .Wy ,_fef &&_eeg .Wx !=0;};type Pattern interface{ColorAt (_aac ,_ag int )_b .Color ;};type TextState struct{Tc float64 ;Tw float64 ;Th float64 ;Tl float64 ;Tf *TextFont ;Ts float64 ;Tm _eb .Matrix ;Tlm _eb .Matrix ;Tr TextRenderingMode ; 29 | GlobalScale float64 ;};type Gradient interface{Pattern ;AddColorStop (_db float64 ,_bc _b .Color );};type LineJoin int ;type Context interface{Push ();Pop ();Matrix ()_eb .Matrix ;SetMatrix (_f _eb .Matrix );Translate (_c ,_gd float64 );Scale (_de ,_da float64 ); 30 | Rotate (_bcf float64 );MoveTo (_dg ,_ba float64 );LineTo (_bcd ,_df float64 );CubicTo (_fg ,_gcg ,_ecf ,_ab ,_ad ,_ga float64 );QuadraticTo (_gg ,_fa ,_efd ,_fac float64 );NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();ResetClip ();LineWidth ()float64 ; 31 | SetLineWidth (_bd float64 );SetLineCap (_efc LineCap );SetLineJoin (_dfg LineJoin );SetDash (_deb ...float64 );SetDashOffset (_aaa float64 );Fill ();FillPreserve ();Stroke ();StrokePreserve ();SetRGBA (_eg ,_age ,_adf ,_ac float64 );SetFillRGBA (_fgg ,_gff ,_cc ,_ca float64 ); 32 | SetFillStyle (_fb Pattern );SetFillRule (_ee FillRule );SetStrokeRGBA (_fd ,_ge ,_aad ,_caf float64 );SetStrokeStyle (_ggf Pattern );FillPattern ()Pattern ;StrokePattern ()Pattern ;TextState ()*TextState ;DrawString (_gfg string ,_fe _gc .Face ,_ed ,_ebg float64 ); 33 | MeasureString (_be string ,_gae _gc .Face )(_ebe ,_ae float64 );DrawRectangle (_edb ,_ccb ,_edd ,_gda float64 );DrawImage (_gga _gf .Image ,_aadb ,_fae int );DrawImageAnchored (_ggc _gf .Image ,_dec ,_af int ,_acf ,_bb float64 );Height ()int ;Width ()int ; 34 | };func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_ebf ,_ece :=_efe .NewPdfFontFromTTFFile (filePath );if _ece !=nil {return nil ,_ece ;};return NewTextFont (_ebf ,size );};func (_acfg *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_acfg .Tw =aw ; 35 | _acfg .Tc =ac ;_acfg .ProcQ (data ,ctx );};type FillRule int ;func (_cdf *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_cdf .Tm =_eb .NewMatrix (a ,b ,c ,d ,e ,f );_cdf .Tlm =_cdf .Tm .Clone ();};type TextFont struct{Font *_efe .PdfFont ;Size float64 ; 36 | _dd *_ea .Font ;_gaeg *_efe .PdfFont ;};func (_fcg *TextFont )CharcodeToRunes (charcode _d .CharCode )(_d .CharCode ,[]rune ){_cb :=[]_d .CharCode {charcode };if _fcg ._gaeg ==nil ||_fcg ._gaeg ==_fcg .Font {return _fcg .charcodeToRunesSimple (charcode ); 37 | };_bg :=_fcg ._gaeg .CharcodesToUnicode (_cb );_gcf ,_ :=_fcg .Font .RunesToCharcodeBytes (_bg );_gec :=_fcg .Font .BytesToCharcodes (_gcf );_aaaa :=charcode ;if len (_gec )> 0&&_gec [0]!=0{_aaaa =_gec [0];};if string (_bg )==string (_ec .MissingCodeRune )&&_fcg ._gaeg .BaseFont ()==_fcg .Font .BaseFont (){return _fcg .charcodeToRunesSimple (charcode ); 38 | };return _aaaa ,_bg ;};type LineCap int ;func (_dbe *TextFont )BytesToCharcodes (data []byte )[]_d .CharCode {if _dbe ._gaeg !=nil {return _dbe ._gaeg .BytesToCharcodes (data );};return _dbe .Font .BytesToCharcodes (data );};func (_ebef *TextState )Reset (){_ebef .Tm =_eb .IdentityMatrix (); 39 | _ebef .Tlm =_eb .IdentityMatrix ()};const (TextRenderingModeFill TextRenderingMode =iota ;TextRenderingModeStroke ;TextRenderingModeFillStroke ;TextRenderingModeInvisible ;TextRenderingModeFillClip ;TextRenderingModeStrokeClip ;TextRenderingModeFillStrokeClip ; 40 | TextRenderingModeClip ;);func (_fce *TextState )ProcTd (tx ,ty float64 ){_fce .Tlm .Concat (_eb .TranslationMatrix (tx ,ty ));_fce .Tm =_fce .Tlm .Clone ();}; -------------------------------------------------------------------------------- /sanitize/sanitize.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 sanitize ;import (_b "github.com/unidoc/unipdf/v4/common";_c "github.com/unidoc/unipdf/v4/core";); 13 | 14 | // GetSuspiciousObjects returns a count of each detected suspicious object. 15 | func (_bb *Sanitizer )GetSuspiciousObjects ()map[string ]int {return _bb ._gb }; 16 | 17 | // Optimize optimizes `objects` and returns updated list of objects. 18 | func (_a *Sanitizer )Optimize (objects []_c .PdfObject )([]_c .PdfObject ,error ){return _a .processObjects (objects );}; 19 | 20 | // New returns a new sanitizer object. 21 | func New (opts SanitizationOpts )*Sanitizer {return &Sanitizer {_ba :opts }}; 22 | 23 | // Sanitizer represents a sanitizer object. 24 | // It implements the Optimizer interface to access the objects field from the writer. 25 | type Sanitizer struct{_ba SanitizationOpts ;_gb map[string ]int ;}; 26 | 27 | // SanitizationOpts specifies the objects to be removed during sanitization. 28 | type SanitizationOpts struct{ 29 | 30 | // JavaScript specifies wether JavaScript action should be removed. JavaScript Actions, section 12.6.4.16 of PDF32000_2008 31 | JavaScript bool ; 32 | 33 | // URI specifies if URI actions should be removed. 12.6.4.7 URI Actions, PDF32000_2008. 34 | URI bool ; 35 | 36 | // GoToR removes remote GoTo actions. 12.6.4.3 Remote Go-To Actions, PDF32000_2008. 37 | GoToR bool ; 38 | 39 | // GoTo specifies wether GoTo actions should be removed. 12.6.4.2 Go-To Actions, PDF32000_2008. 40 | GoTo bool ; 41 | 42 | // RenditionJS enables removing of `JS` entry from a Rendition Action. 43 | // The `JS` entry has a value of text string or stream containing a JavaScript script that shall be executed when the action is triggered. 44 | // 12.6.4.13 Rendition Actions Table 214, PDF32000_2008. 45 | RenditionJS bool ; 46 | 47 | // OpenAction removes OpenAction entry from the document catalog. 48 | OpenAction bool ; 49 | 50 | // Launch specifies wether Launch Action should be removed. 51 | // A launch action launches an application or opens or prints a document. 52 | // 12.6.4.5 Launch Actions, PDF32000_2008. 53 | Launch bool ;};func (_gd *Sanitizer )processObjects (_ga []_c .PdfObject )([]_c .PdfObject ,error ){_gg :=[]_c .PdfObject {};_aa :=_gd ._ba ;for _ ,_fa :=range _ga {switch _ac :=_fa .(type ){case *_c .PdfIndirectObject :_e ,_gc :=_c .GetDict (_ac );if _gc {if _fc ,_bd :=_c .GetName (_e .Get ("\u0054\u0079\u0070\u0065")); 54 | _bd &&*_fc =="\u0043a\u0074\u0061\u006c\u006f\u0067"{if _ ,_ec :=_c .GetIndirect (_e .Get ("\u004f\u0070\u0065\u006e\u0041\u0063\u0074\u0069\u006f\u006e"));_ec &&_aa .OpenAction {_e .Remove ("\u004f\u0070\u0065\u006e\u0041\u0063\u0074\u0069\u006f\u006e"); 55 | };}else if _ef ,_gce :=_c .GetName (_e .Get ("\u0053"));_gce {switch *_ef {case "\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074":if _aa .JavaScript {if _fd ,_bc :=_c .GetStream (_e .Get ("\u004a\u0053"));_bc {_gdb :=[]byte {};_ca ,_eb :=_c .MakeStream (_gdb ,nil ); 56 | if _eb ==nil {*_fd =*_ca ;};};_b .Log .Debug ("\u004a\u0061\u0076\u0061\u0073\u0063\u0072\u0069\u0070\u0074\u0020a\u0063\u0074\u0069\u006f\u006e\u0020\u0073\u006b\u0069\u0070p\u0065\u0064\u002e");continue ;};case "\u0055\u0052\u0049":if _aa .URI {_b .Log .Debug ("\u0055\u0052\u0049\u0020ac\u0074\u0069\u006f\u006e\u0020\u0073\u006b\u0069\u0070\u0070\u0065\u0064\u002e"); 57 | continue ;};case "\u0047\u006f\u0054\u006f":if _aa .GoTo {_b .Log .Debug ("G\u004fT\u004f\u0020\u0061\u0063\u0074\u0069\u006f\u006e \u0073\u006b\u0069\u0070pe\u0064\u002e");continue ;};case "\u0047\u006f\u0054o\u0052":if _aa .GoToR {_b .Log .Debug ("R\u0065\u006d\u006f\u0074\u0065\u0020G\u006f\u0054\u004f\u0020\u0061\u0063\u0074\u0069\u006fn\u0020\u0073\u006bi\u0070p\u0065\u0064\u002e"); 58 | continue ;};case "\u004c\u0061\u0075\u006e\u0063\u0068":if _aa .Launch {_b .Log .Debug ("\u004a\u0061\u0076\u0061\u0073\u0063\u0072\u0069\u0070\u0074\u0020a\u0063\u0074\u0069\u006f\u006e\u0020\u0073\u006b\u0069\u0070p\u0065\u0064\u002e");continue ;};case "\u0052e\u006e\u0064\u0069\u0074\u0069\u006fn":if _gcc ,_fb :=_c .GetStream (_e .Get ("\u004a\u0053")); 59 | _fb {_d :=[]byte {};_bdf ,_gdf :=_c .MakeStream (_d ,nil );if _gdf ==nil {*_gcc =*_bdf ;};};};}else if _cag :=_e .Get ("\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074");_cag !=nil &&_aa .JavaScript {continue ;}else if _cg ,_fbb :=_c .GetName (_e .Get ("\u0054\u0079\u0070\u0065")); 60 | _fbb &&*_cg =="\u0041\u006e\u006eo\u0074"&&_aa .JavaScript {if _ab ,_fdb :=_c .GetIndirect (_e .Get ("\u0050\u0061\u0072\u0065\u006e\u0074"));_fdb {if _be ,_ad :=_c .GetDict (_ab .PdfObject );_ad {if _ge ,_fbd :=_c .GetDict (_be .Get ("\u0041\u0041")); 61 | _fbd {_ag ,_bce :=_c .GetIndirect (_ge .Get ("\u004b"));if _bce {if _ebb ,_aad :=_c .GetDict (_ag .PdfObject );_aad {if _fg ,_af :=_c .GetName (_ebb .Get ("\u0053"));_af &&*_fg =="\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"{_ebb .Clear (); 62 | }else if _fac :=_ge .Get ("\u0046");_fac !=nil {if _bg ,_cd :=_c .GetIndirect (_fac );_cd {if _cc ,_bf :=_c .GetDict (_bg .PdfObject );_bf {if _aaf ,_gf :=_c .GetName (_cc .Get ("\u0053"));_gf &&*_aaf =="\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"{_cc .Clear (); 63 | };};};};};};};};};};};case *_c .PdfObjectStream :_b .Log .Debug ("\u0070d\u0066\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0073t\u0072e\u0061m\u0020\u0074\u0079\u0070\u0065\u0020\u0025T",_ac );case *_c .PdfObjectStreams :_b .Log .Debug ("\u0070\u0064\u0066\u0020\u006f\u0062\u006a\u0065\u0063\u0074\u0020s\u0074\u0072\u0065\u0061\u006d\u0073\u0020\u0074\u0079\u0070e\u0020\u0025\u0054",_ac ); 64 | default:_b .Log .Debug ("u\u006e\u006b\u006e\u006fwn\u0020p\u0064\u0066\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0025\u0054",_ac );};_gg =append (_gg ,_fa );};_gd .analyze (_gg );return _gg ,nil ;};func (_bca *Sanitizer )analyze (_gga []_c .PdfObject ){_cf :=map[string ]int {}; 65 | for _ ,_gec :=range _gga {switch _cga :=_gec .(type ){case *_c .PdfIndirectObject :_da ,_fdd :=_c .GetDict (_cga .PdfObject );if _fdd {if _afe ,_abb :=_c .GetName (_da .Get ("\u0054\u0079\u0070\u0065"));_abb &&*_afe =="\u0043a\u0074\u0061\u006c\u006f\u0067"{if _ ,_df :=_c .GetIndirect (_da .Get ("\u004f\u0070\u0065\u006e\u0041\u0063\u0074\u0069\u006f\u006e")); 66 | _df {_cf ["\u004f\u0070\u0065\u006e\u0041\u0063\u0074\u0069\u006f\u006e"]++;};}else if _cb ,_gbd :=_c .GetName (_da .Get ("\u0053"));_gbd {_gbb :=_cb .String ();if _gbb =="\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"||_gbb =="\u0055\u0052\u0049"||_gbb =="\u0047\u006f\u0054\u006f"||_gbb =="\u0047\u006f\u0054o\u0052"||_gbb =="\u004c\u0061\u0075\u006e\u0063\u0068"{_cf [_gbb ]++; 67 | }else if _gbb =="\u0052e\u006e\u0064\u0069\u0074\u0069\u006fn"{if _ ,_fe :=_c .GetStream (_da .Get ("\u004a\u0053"));_fe {_cf [_gbb ]++;};};}else if _ae :=_da .Get ("\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074");_ae !=nil {_cf ["\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"]++; 68 | }else if _beb ,_ce :=_c .GetIndirect (_da .Get ("\u0050\u0061\u0072\u0065\u006e\u0074"));_ce {if _ff ,_acc :=_c .GetDict (_beb .PdfObject );_acc {if _bec ,_fee :=_c .GetDict (_ff .Get ("\u0041\u0041"));_fee {_ceg :=_bec .Get ("\u004b");_gbf ,_cda :=_c .GetIndirect (_ceg ); 69 | if _cda {if _fff ,_cfc :=_c .GetDict (_gbf .PdfObject );_cfc {if _ffb ,_cef :=_c .GetName (_fff .Get ("\u0053"));_cef &&*_ffb =="\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"{_cf ["\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"]++; 70 | }else if _ ,_ece :=_c .GetString (_fff .Get ("\u004a\u0053"));_ece {_cf ["\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"]++;}else {_ffg :=_bec .Get ("\u0046");if _ffg !=nil {_bge ,_gge :=_c .GetIndirect (_ffg );if _gge {if _cad ,_adc :=_c .GetDict (_bge .PdfObject ); 71 | _adc {if _cff ,_eeb :=_c .GetName (_cad .Get ("\u0053"));_eeb {_cfb :=_cff .String ();_cf [_cfb ]++;};};};};};};};};};};};};};_bca ._gb =_cf ;}; -------------------------------------------------------------------------------- /textshaping/textshaping.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 textshaping ;import (_c "github.com/unidoc/garabic";_ad "golang.org/x/text/unicode/bidi";_a "strings";); 13 | 14 | // ArabicShape returns shaped arabic glyphs string. 15 | func ArabicShape (text string )(string ,error ){_de :=_ad .Paragraph {};_de .SetString (text );_b ,_g :=_de .Order ();if _g !=nil {return "",_g ;};for _bc :=0;_bc < _b .NumRuns ();_bc ++{_bd :=_b .Run (_bc );_cd :=_bd .String ();if _bd .Direction ()==_ad .RightToLeft {var (_cf =_c .Shape (_cd ); 16 | _bde =[]rune (_cf );_bf =make ([]rune ,len (_bde )););_af :=0;for _e :=len (_bde )-1;_e >=0;_e --{_bf [_af ]=_bde [_e ];_af ++;};_cd =string (_bf );text =_a .Replace (text ,_a .TrimSpace (_bd .String ()),_cd ,1);};};return text ,nil ;}; -------------------------------------------------------------------------------- /unipdf.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 unipdf is a comprehensive PDF library for Go (golang). The library has advanced capabilities for generating, 13 | // processing and modifying PDFs. UniPDF is written and supported by the owners of the 14 | // FoxyUtils.com website, where the library is used to power many of the PDF services offered. 15 | // 16 | // # Getting More Information 17 | // 18 | // Check out the Getting Started and Example sections, which showcase how to install unipdf and provide numerous 19 | // examples of using unipdf to generate, process or modify PDF files. 20 | // https://unidoc.io/examples/getting_started/ 21 | // 22 | // The GoDoc for unipdf provides a detailed breakdown of the API and documentation for packages, types and methods. 23 | // https://godoc.org/github.com/unidoc/unipdf 24 | // 25 | // # Overview of Major Packages 26 | // 27 | // The API is composed of a few major packages: 28 | // 29 | // - common: Provides common shared types such as Logger and utilities to check 30 | // license validity. 31 | // 32 | // - core: The core package defines the primitive PDF object types and handles 33 | // the file reading I/O and parsing the primitive objects. 34 | // 35 | // - model: The model package builds on the core package, to represent the PDF as 36 | // a structured model of the PDF primitive types. It has a reader and a writer to 37 | // read and process a PDF file based on the structured model. This serves as a basis 38 | // to perform a number of numerous tasks and can be used to work with a PDF in a 39 | // medium to high level interface, although it does require an understanding of the 40 | // PDF format and structure. 41 | // 42 | // - creator: The PDF creator makes it easy to create new PDFs or modify existing 43 | // PDFs. It can also enable loading a template PDF, adding text/images and 44 | // generating an output PDF. It can be used to add text, images, and generate text 45 | // and graphical reports. It is designed with simplicity in mind, with the goal of 46 | // making it easy to create reports without needing any knowledge about the PDF 47 | // format or specifications. 48 | // 49 | // - extractor: Package extractor is used for quickly extracting PDF content 50 | // through a simple interface. Currently offers functionality for extracting textual 51 | // content. 52 | package unipdf ; --------------------------------------------------------------------------------