diff -Nru libsejda-java-3.2.38/bintray-deploy.json libsejda-java-3.2.66/bintray-deploy.json --- libsejda-java-3.2.38/bintray-deploy.json 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/bintray-deploy.json 1970-01-01 00:00:00.000000000 +0000 @@ -1,68 +0,0 @@ -{ - "package": - { - "name": "sejda", - "repo": "maven", - "subject": "sejdapdf", - "desc": "An extendible and configurable PDF manipulation layer library. A ready to use java library to perform PDF documents manipulation without having to deal with the low level API. Sejda offers many \"ready to go\" manipulations implemented using the SAMBox but it can be extended to use other implementations.", - "website_url": "www.sejda.org", - "issue_tracker_url": "https://github.com/torakiki/sejda/issues", - "vcs_url": "hhttps://github.com/torakiki/sejda", - "licenses": - ["AGPL-V3"], - "public_download_numbers": false, - "public_stats": false - }, - - "version": - { - "name": "${project.version}", - "desc": "Sejda version ${project.version}", - "released": "${timestamp}", - "vcs_tag": "${project.version}", - "gpgSign": false - }, - - "files": - [ - { - "includePattern": "sejda-console/target/(.*)\\.(jar|asc|md5|pom)", - "excludePattern": "sejda-console/target/assembled/.*", - "uploadPattern": "org/sejda/sejda-console/${project.version}/$1.$2" - }, - { - "includePattern": "sejda-conversion/target/(.*)\\.(jar|asc|md5|pom)", - "uploadPattern": "org/sejda/sejda-conversion/${project.version}/$1.$2" - }, - { - "includePattern": "sejda-core/target/(.*)\\.(jar|asc|md5|pom)", - "uploadPattern": "org/sejda/sejda-core/${project.version}/$1.$2" - }, - { - "includePattern": "sejda-fonts/target/(.*)\\.(jar|asc|md5|pom)", - "uploadPattern": "org/sejda/sejda-fonts/${project.version}/$1.$2" - }, - { - "includePattern": "sejda-image-writers/target/(.*)\\.(jar|asc|md5|pom)", - "uploadPattern": "org/sejda/sejda-image-writers/${project.version}/$1.$2" - }, - { - "includePattern": "sejda-model/target/(.*)\\.(jar|asc|md5|pom)", - "uploadPattern": "org/sejda/sejda-model/${project.version}/$1.$2" - }, - { - "includePattern": "sejda-optional-fonts/target/(.*)\\.(jar|asc|md5|pom)", - "uploadPattern": "org/sejda/sejda-optional-fonts/${project.version}/$1.$2" - }, - { - "includePattern": "sejda-sambox/target/(.*)\\.(jar|asc|md5|pom)", - "uploadPattern": "org/sejda/sejda-sambox/${project.version}/$1.$2" - }, - { - "includePattern": "target/(.*)\\.(asc|md5|pom)", - "uploadPattern": "org/sejda/sejda-parent/${project.version}/$1.$2" - } - ], - - "publish": true -} \ No newline at end of file diff -Nru libsejda-java-3.2.38/debian/changelog libsejda-java-3.2.66/debian/changelog --- libsejda-java-3.2.38/debian/changelog 2017-11-26 21:20:26.000000000 +0000 +++ libsejda-java-3.2.66/debian/changelog 2019-02-27 12:51:08.000000000 +0000 @@ -1,3 +1,24 @@ +libsejda-java (3.2.66-1~18.04) bionic; urgency=medium + + * Backport for OpenJDK 11 (dependency of pdfsam). LP: #1814133. + + -- Matthias Klose Wed, 27 Feb 2019 13:51:08 +0100 + +libsejda-java (3.2.66-1) unstable; urgency=medium + + * New upstream version 3.2.66. + + -- Markus Koschany Sat, 22 Dec 2018 12:32:07 +0100 + +libsejda-java (3.2.56-1) unstable; urgency=medium + + * New upstream version 3.2.56. + * Build-depend on libcommons-csv-java. + * Declare compliance with Debian Policy 4.2.1. + * Switch to compat level 11. + + -- Markus Koschany Fri, 12 Oct 2018 13:11:13 +0200 + libsejda-java (3.2.38-1) unstable; urgency=medium * New upstream version 3.2.38. diff -Nru libsejda-java-3.2.38/debian/compat libsejda-java-3.2.66/debian/compat --- libsejda-java-3.2.38/debian/compat 2017-11-26 21:20:26.000000000 +0000 +++ libsejda-java-3.2.66/debian/compat 2018-12-22 11:32:07.000000000 +0000 @@ -1 +1 @@ -10 +11 diff -Nru libsejda-java-3.2.38/debian/control libsejda-java-3.2.66/debian/control --- libsejda-java-3.2.38/debian/control 2017-11-26 21:20:26.000000000 +0000 +++ libsejda-java-3.2.66/debian/control 2018-12-22 11:32:07.000000000 +0000 @@ -5,26 +5,27 @@ Uploaders: Markus Koschany Build-Depends: - debhelper (>= 10), + debhelper (>= 11), default-jdk, default-jdk-doc, junit4, libapache-poi-java, libbcmail-java, libbcprov-java, + libcommons-csv-java, libcommons-io-java, libcommons-lang3-java, libgeronimo-validation-1.0-spec-java, libimgscalr-java, libmaven-javadoc-plugin-java, libmetadata-extractor-java (>= 2.10.1), - libsambox-java (>= 1.1.16), + libsambox-java (>= 1.1.41), libsejda-java, libslf4j-java, libtwelvemonkeys-java, libxmlgraphics-commons-java, maven-debian-helper (>= 2.1) -Standards-Version: 4.1.1 +Standards-Version: 4.2.1 Vcs-Git: https://anonscm.debian.org/git/pkg-java/libsejda-java.git Vcs-Browser: https://anonscm.debian.org/git/pkg-java/libsejda-java.git Homepage: http://sejda.org/ diff -Nru libsejda-java-3.2.38/debian/copyright libsejda-java-3.2.66/debian/copyright --- libsejda-java-3.2.38/debian/copyright 2017-11-26 21:20:26.000000000 +0000 +++ libsejda-java-3.2.66/debian/copyright 2018-12-22 11:32:07.000000000 +0000 @@ -3,7 +3,7 @@ Source: https://github.com/torakiki/sejda Files: * -Copyright: 2010-2016, Andrea Vacondio (andrea.vacondio@gmail.com) +Copyright: 2010-2018, Andrea Vacondio (andrea.vacondio@gmail.com) 2010-2016, Eduard Weissmann (edi.weissmann@gmail.com) License: AGPL-3+ @@ -28,7 +28,7 @@ License: OFL-1.1 Files: debian/* -Copyright: 2017, Markus Koschany +Copyright: 2017-2018, Markus Koschany License: AGPL-3+ License: LGPL-2.1+ diff -Nru libsejda-java-3.2.38/pom.xml libsejda-java-3.2.66/pom.xml --- libsejda-java-3.2.38/pom.xml 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/pom.xml 2018-12-03 16:42:31.000000000 +0000 @@ -6,7 +6,7 @@ sejda-parent pom sejda - 3.2.38 + 3.2.66 An extendible and configurable PDF manipulation layer library. A ready to use java library to perform PDF documents manipulation without having to deal with the low level API. Sejda offers many "ready to go" manipulations implemented using the SAMBox but it can be extended to use other implementations. @@ -32,7 +32,7 @@ scm:git:git@github.com:torakiki/sejda.git scm:git:git@github.com:torakiki/sejda.git scm:git:git@github.com:torakiki/sejda.git - v3.2.38 + v3.2.66 @@ -94,7 +94,6 @@ org.apache.maven.plugins maven-gpg-plugin - 1.6 sign-artifacts @@ -108,7 +107,6 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.7 true ossrh @@ -121,80 +119,87 @@ - travis - - - env.TRAVIS - true - - + private-release + + + sejda-pro-snapshot + http://mvn.sejda.com/artifactory/libs-snapshot + + + sejda-pro + http://mvn.sejda.com/artifactory/libs-release + + - maven-resources-plugin - 3.0.1 + org.apache.maven.plugins + maven-release-plugin + 2.5.2 + + v@{project.version} + clean install + true + true + - copy-resources - validate - copy-resources + perform - ${project.basedir}/target/bintray - - - ${project.basedir} - - bintray-deploy.json - - true - - + true org.apache.maven.plugins - maven-javadoc-plugin - 2.10.4 - - true - -Xdoclint:none - + maven-gpg-plugin - attach-javadocs + sign-artifacts + verify - jar + sign + + + + + + travis + + + env.TRAVIS + true + + + + - net.ju-n.maven.plugins - checksum-maven-plugin - 1.3 + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.4 + + true + -Xdoclint:none + - verify + attach-javadocs - artifacts + jar - - - MD5 - - false - org.apache.maven.plugins maven-gpg-plugin - 1.6 ${env.GPG_PASSPHRASE} @@ -208,7 +213,16 @@ - + + org.sonatype.plugins + nexus-staging-maven-plugin + true + + ossrh + https://oss.sonatype.org/ + true + + @@ -228,6 +242,11 @@ 3.0.2 + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + org.sonatype.plugins nexus-staging-maven-plugin 1.6.8 @@ -298,10 +317,10 @@ - - - - + + + + ossrh https://oss.sonatype.org/service/local/staging/deploy/maven2/ @@ -312,18 +331,19 @@ 4.12 1.7.25 3.5 - 2.5 + 2.6 1.0.0.GA 1.10.19 1.2.2 2.9.1 4.2.0.Final 1.3 - 1.1.19 + 1.1.46 1.56 3.3.1 3.15 3.2.1 + 1.5 UTF-8 ${maven.build.timestamp} @@ -377,6 +397,11 @@ poi-ooxml ${apache.poi.version} + + org.apache.commons + commons-csv + ${apache.commons.csv.version} + diff -Nru libsejda-java-3.2.38/sejda-console/.classpath libsejda-java-3.2.66/sejda-console/.classpath --- libsejda-java-3.2.38/sejda-console/.classpath 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-console/.classpath 2018-12-03 16:42:31.000000000 +0000 @@ -15,11 +15,13 @@ + + diff -Nru libsejda-java-3.2.38/sejda-console/pom.xml libsejda-java-3.2.66/sejda-console/pom.xml --- libsejda-java-3.2.38/sejda-console/pom.xml 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-console/pom.xml 2018-12-03 16:42:31.000000000 +0000 @@ -10,7 +10,7 @@ org.sejda sejda-parent - 3.2.38 + 3.2.66 ../pom.xml @@ -183,6 +183,13 @@ + + + + org.sejda.cli + + + diff -Nru libsejda-java-3.2.38/sejda-console/src/main/config/LICENSE.txt libsejda-java-3.2.66/sejda-console/src/main/config/LICENSE.txt --- libsejda-java-3.2.38/sejda-console/src/main/config/LICENSE.txt 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-console/src/main/config/LICENSE.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,661 +0,0 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - Version 3, 19 November 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU Affero General Public License is a free, copyleft license for -software and other kinds of works, specifically designed to ensure -cooperation with the community in the case of network server software. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -our General Public Licenses are intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - Developers that use our General Public Licenses protect your rights -with two steps: (1) assert copyright on the software, and (2) offer -you this License which gives you legal permission to copy, distribute -and/or modify the software. - - A secondary benefit of defending all users' freedom is that -improvements made in alternate versions of the program, if they -receive widespread use, become available for other developers to -incorporate. Many developers of free software are heartened and -encouraged by the resulting cooperation. However, in the case of -software used on network servers, this result may fail to come about. -The GNU General Public License permits making a modified version and -letting the public access it on a server without ever releasing its -source code to the public. - - The GNU Affero General Public License is designed specifically to -ensure that, in such cases, the modified source code becomes available -to the community. It requires the operator of a network server to -provide the source code of the modified version running there to the -users of that server. Therefore, public use of a modified version, on -a publicly accessible server, gives the public access to the source -code of the modified version. - - An older license, called the Affero General Public License and -published by Affero, was designed to accomplish similar goals. This is -a different license, not a version of the Affero GPL, but Affero has -released a new version of the Affero GPL which permits relicensing under -this license. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU Affero General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Remote Network Interaction; Use with the GNU General Public License. - - Notwithstanding any other provision of this License, if you modify the -Program, your modified version must prominently offer all users -interacting with it remotely through a computer network (if your version -supports such interaction) an opportunity to receive the Corresponding -Source of your version by providing access to the Corresponding Source -from a network server at no charge, through some standard or customary -means of facilitating copying of software. This Corresponding Source -shall include the Corresponding Source for any work covered by version 3 -of the GNU General Public License that is incorporated pursuant to the -following paragraph. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the work with which it is combined will remain governed by version -3 of the GNU General Public License. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU Affero General Public License from time to time. Such new versions -will be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU Affero General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU Affero General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU Affero General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If your software can interact with users remotely through a computer -network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its -interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different -solutions will be better for different programs; see section 13 for the -specific requirements. - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU AGPL, see -. diff -Nru libsejda-java-3.2.38/sejda-console/src/main/config/SEJDA_LICENSE.txt libsejda-java-3.2.66/sejda-console/src/main/config/SEJDA_LICENSE.txt --- libsejda-java-3.2.38/sejda-console/src/main/config/SEJDA_LICENSE.txt 1970-01-01 00:00:00.000000000 +0000 +++ libsejda-java-3.2.66/sejda-console/src/main/config/SEJDA_LICENSE.txt 2018-12-03 16:42:31.000000000 +0000 @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff -Nru libsejda-java-3.2.38/sejda-console/src/main/java/org/sejda/cli/Main.java libsejda-java-3.2.66/sejda-console/src/main/java/org/sejda/cli/Main.java --- libsejda-java-3.2.38/sejda-console/src/main/java/org/sejda/cli/Main.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-console/src/main/java/org/sejda/cli/Main.java 2018-12-03 16:42:31.000000000 +0000 @@ -46,7 +46,7 @@ SLF4JBridgeHandler.install(); Map customs = new HashMap<>(); customs.put(CustomizableProps.APP_NAME, "Sejda Console"); - customs.put(CustomizableProps.LICENSE_PATH, "/LICENSE.txt"); + customs.put(CustomizableProps.LICENSE_PATH, "/SEJDA_LICENSE.txt"); new SejdaConsole(args, getTaskExecutionAdapter(), customs).execute(); } diff -Nru libsejda-java-3.2.38/sejda-console/src/main/java/org/sejda/cli/SejdaConsole.java libsejda-java-3.2.66/sejda-console/src/main/java/org/sejda/cli/SejdaConsole.java --- libsejda-java-3.2.38/sejda-console/src/main/java/org/sejda/cli/SejdaConsole.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-console/src/main/java/org/sejda/cli/SejdaConsole.java 2018-12-03 16:42:31.000000000 +0000 @@ -22,7 +22,6 @@ import static java.util.Optional.ofNullable; import java.io.BufferedReader; -import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; @@ -150,7 +149,7 @@ info.append(l); info.append(System.lineSeparator()); }); - } catch (IOException e) { + } catch (Exception e) { LOG.error("An error occurred while reading license information, please refer to http://www.sejda.org", e); } LOG.info(info.toString()); diff -Nru libsejda-java-3.2.38/sejda-console/src/test/java/org/sejda/cli/CommandLineTestBuilder.java libsejda-java-3.2.66/sejda-console/src/test/java/org/sejda/cli/CommandLineTestBuilder.java --- libsejda-java-3.2.38/sejda-console/src/test/java/org/sejda/cli/CommandLineTestBuilder.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-console/src/test/java/org/sejda/cli/CommandLineTestBuilder.java 2018-12-03 16:42:31.000000000 +0000 @@ -33,6 +33,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.io.output.NullOutputStream; import org.apache.commons.lang3.mutable.MutableBoolean; import org.mockito.ArgumentCaptor; import org.sejda.cli.util.OnceWithMessage; @@ -190,7 +191,7 @@ } public T invokeSejdaConsole() { - return (T) new CommandLineExecuteTestHelper(true) + return new CommandLineExecuteTestHelper(true) .invokeConsoleAndReturnTaskParameters(this.toCommandLineString()); } } @@ -210,7 +211,7 @@ CommandLineExecuteTestHelper(boolean useMockTaskExecutionService) { this(useMockTaskExecutionService, new HashMap<>()); customs.put(CustomizableProps.APP_NAME, "Sejda Console"); - customs.put(CustomizableProps.LICENSE_PATH, "/sejda-console/LICENSE.txt"); + customs.put(CustomizableProps.LICENSE_PATH, "/sejda-console/SEJDA_LICENSE.txt"); } CommandLineExecuteTestHelper(boolean useMockTaskExecutionService, Map customs) { @@ -286,12 +287,13 @@ } catch (SejdaRuntimeException e) { // no-op } catch (Exception e) { - throw new SejdaRuntimeException("An unexpected exception occured while executing the console", e); + throw new SejdaRuntimeException("An unexpected exception occurred while executing the console", e); } } private void prepareSystemOutCapture() { - newSystemOut = new SystemOutRecordingStream(System.out); + //newSystemOut = new SystemOutRecordingStream(System.out); + newSystemOut = new SystemOutRecordingStream(new NullOutputStream()); System.setOut(new PrintStream(newSystemOut)); } diff -Nru libsejda-java-3.2.38/sejda-console/src/test/java/org/sejda/cli/GeneralConsoleOptionsTest.java libsejda-java-3.2.66/sejda-console/src/test/java/org/sejda/cli/GeneralConsoleOptionsTest.java --- libsejda-java-3.2.38/sejda-console/src/test/java/org/sejda/cli/GeneralConsoleOptionsTest.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-console/src/test/java/org/sejda/cli/GeneralConsoleOptionsTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -78,7 +78,7 @@ public void testExecuteVersion() { Map customs = new HashMap<>(); customs.put(CustomizableProps.APP_NAME, "Sejda Console"); - customs.put(CustomizableProps.LICENSE_PATH, "/LICENSE.txt"); + customs.put(CustomizableProps.LICENSE_PATH, "/SEJDA_LICENSE.txt"); new CommandLineExecuteTestHelper(false, customs).assertConsoleOutputContains("--version", "Sejda Console (Version " + Sejda.VERSION + ")"); } @@ -87,8 +87,8 @@ public void testExecuteLicense() throws IOException { Map customs = new HashMap<>(); customs.put(CustomizableProps.APP_NAME, "Sejda Console"); - customs.put(CustomizableProps.LICENSE_PATH, "/LICENSE.txt"); - try (InputStream resource = getClass().getResourceAsStream("/LICENSE.txt")) { + customs.put(CustomizableProps.LICENSE_PATH, "/SEJDA_LICENSE.txt"); + try (InputStream resource = getClass().getResourceAsStream("/SEJDA_LICENSE.txt")) { new CommandLineExecuteTestHelper(false, customs).assertConsoleOutputContains("--license", new BufferedReader(new InputStreamReader(resource, StandardCharsets.UTF_8)).lines() .map(StringUtils::trim).toArray(String[]::new)); diff -Nru libsejda-java-3.2.38/sejda-console/src/test/resources/LICENSE.txt libsejda-java-3.2.66/sejda-console/src/test/resources/LICENSE.txt --- libsejda-java-3.2.38/sejda-console/src/test/resources/LICENSE.txt 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-console/src/test/resources/LICENSE.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,661 +0,0 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - Version 3, 19 November 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU Affero General Public License is a free, copyleft license for -software and other kinds of works, specifically designed to ensure -cooperation with the community in the case of network server software. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -our General Public Licenses are intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - Developers that use our General Public Licenses protect your rights -with two steps: (1) assert copyright on the software, and (2) offer -you this License which gives you legal permission to copy, distribute -and/or modify the software. - - A secondary benefit of defending all users' freedom is that -improvements made in alternate versions of the program, if they -receive widespread use, become available for other developers to -incorporate. Many developers of free software are heartened and -encouraged by the resulting cooperation. However, in the case of -software used on network servers, this result may fail to come about. -The GNU General Public License permits making a modified version and -letting the public access it on a server without ever releasing its -source code to the public. - - The GNU Affero General Public License is designed specifically to -ensure that, in such cases, the modified source code becomes available -to the community. It requires the operator of a network server to -provide the source code of the modified version running there to the -users of that server. Therefore, public use of a modified version, on -a publicly accessible server, gives the public access to the source -code of the modified version. - - An older license, called the Affero General Public License and -published by Affero, was designed to accomplish similar goals. This is -a different license, not a version of the Affero GPL, but Affero has -released a new version of the Affero GPL which permits relicensing under -this license. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU Affero General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Remote Network Interaction; Use with the GNU General Public License. - - Notwithstanding any other provision of this License, if you modify the -Program, your modified version must prominently offer all users -interacting with it remotely through a computer network (if your version -supports such interaction) an opportunity to receive the Corresponding -Source of your version by providing access to the Corresponding Source -from a network server at no charge, through some standard or customary -means of facilitating copying of software. This Corresponding Source -shall include the Corresponding Source for any work covered by version 3 -of the GNU General Public License that is incorporated pursuant to the -following paragraph. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the work with which it is combined will remain governed by version -3 of the GNU General Public License. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU Affero General Public License from time to time. Such new versions -will be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU Affero General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU Affero General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU Affero General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If your software can interact with users remotely through a computer -network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its -interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different -solutions will be better for different programs; see section 13 for the -specific requirements. - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU AGPL, see -. diff -Nru libsejda-java-3.2.38/sejda-console/src/test/resources/SEJDA_LICENSE.txt libsejda-java-3.2.66/sejda-console/src/test/resources/SEJDA_LICENSE.txt --- libsejda-java-3.2.38/sejda-console/src/test/resources/SEJDA_LICENSE.txt 1970-01-01 00:00:00.000000000 +0000 +++ libsejda-java-3.2.66/sejda-console/src/test/resources/SEJDA_LICENSE.txt 2018-12-03 16:42:31.000000000 +0000 @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff -Nru libsejda-java-3.2.38/sejda-console/src/test/shell/commands.txt libsejda-java-3.2.66/sejda-console/src/test/shell/commands.txt --- libsejda-java-3.2.38/sejda-console/src/test/shell/commands.txt 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-console/src/test/shell/commands.txt 2018-12-03 16:42:31.000000000 +0000 @@ -90,7 +90,8 @@ target/assembled/bin/sejda-console setmetadata -f /tmp/sejda-smoketest/meta.pdf -o /tmp/sejda-smoketest/meta2.pdf -a "Torakiki" -t "Test the title" -s "What a subject" --overwrite -v 1.5 target/assembled/bin/sejda-console setmetadata -f /tmp/sejda-smoketest/meta.pdf -o /tmp/sejda-smoketest/meta2.pdf -a "Torakiki" -t "Test the title" -s "What a subject" -k "" --overwrite -v 1.5 target/assembled/bin/sejda-console setviewerpreferences -h -target/assembled/bin/sejda-console setviewerpreferences -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -p view_ --hideMenu --hideToolbar --displayDocTitle +target/assembled/bin/sejda-console setviewerpreferences -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -p view_ --hideMenu --hideToolbar --displayDocTitle +target/assembled/bin/sejda-console setviewerpreferences -f ../sejda-core/src/test/resources/pdf/short-test-file.pdf -o /tmp/sejda-smoketest/ -m outlines target/assembled/bin/sejda-console setviewerpreferences -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -p view_ --hideMenu --hideToolbar --displayDocTitle -v 1.6 -j overwrite target/assembled/bin/sejda-console setviewerpreferences -f ../sejda-core/src/test/resources/pdf/large_test.pdf -o /tmp/sejda-smoketest/ -p view_ --hideMenu --hideToolbar --displayDocTitle -v 1.7 -j overwrite target/assembled/bin/sejda-console setheaderfooter -h diff -Nru libsejda-java-3.2.38/sejda-console/src/test/shell/smoke-tests.sh libsejda-java-3.2.66/sejda-console/src/test/shell/smoke-tests.sh --- libsejda-java-3.2.38/sejda-console/src/test/shell/smoke-tests.sh 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-console/src/test/shell/smoke-tests.sh 2018-12-03 16:42:31.000000000 +0000 @@ -28,7 +28,7 @@ while read cmd; do # echo "RUNNING: $cmd" if eval "$cmd"; then - # echo "PASSED: $cmd" + echo "PASSED: $cmd" else echo "FAILED: $cmd" return 1 diff -Nru libsejda-java-3.2.38/sejda-conversion/pom.xml libsejda-java-3.2.66/sejda-conversion/pom.xml --- libsejda-java-3.2.38/sejda-conversion/pom.xml 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-conversion/pom.xml 2018-12-03 16:42:31.000000000 +0000 @@ -10,10 +10,26 @@ org.sejda sejda-parent - 3.2.38 + 3.2.66 ../pom.xml - + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.sejda.conversion + + + + + + + org.sejda diff -Nru libsejda-java-3.2.38/sejda-conversion/src/main/java/org/sejda/conversion/PdfFileSourceListAdapter.java libsejda-java-3.2.66/sejda-conversion/src/main/java/org/sejda/conversion/PdfFileSourceListAdapter.java --- libsejda-java-3.2.38/sejda-conversion/src/main/java/org/sejda/conversion/PdfFileSourceListAdapter.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-conversion/src/main/java/org/sejda/conversion/PdfFileSourceListAdapter.java 2018-12-03 16:42:31.000000000 +0000 @@ -43,6 +43,7 @@ import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; +import org.sejda.common.XMLUtils; import org.sejda.conversion.exception.ConversionException; import org.sejda.model.exception.SejdaRuntimeException; import org.sejda.model.input.PdfFileSource; @@ -245,9 +246,11 @@ protected List doParseFileNames(File file) throws IOException, SAXException, ParserConfigurationException, XPathException { - DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilderFactory domFactory = XMLUtils.getDocumentBuilderFactory(); domFactory.setNamespaceAware(true); + DocumentBuilder builder = domFactory.newDocumentBuilder(); + builder.setErrorHandler(XMLUtils.ERROR_HANDLER); Document doc = builder.parse(file); List result = new ArrayList<>(); diff -Nru libsejda-java-3.2.38/sejda-core/pom.xml libsejda-java-3.2.66/sejda-core/pom.xml --- libsejda-java-3.2.38/sejda-core/pom.xml 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-core/pom.xml 2018-12-03 16:42:31.000000000 +0000 @@ -5,7 +5,7 @@ org.sejda sejda-parent - 3.2.38 + 3.2.66 ../pom.xml @@ -41,6 +41,13 @@ + + + + org.sejda.core + + + @@ -78,6 +85,11 @@ test + org.apache.commons + commons-csv + test + + org.apache.poi poi-ooxml test diff -Nru libsejda-java-3.2.38/sejda-core/src/main/java/org/sejda/core/context/XmlConfigurationStrategy.java libsejda-java-3.2.66/sejda-core/src/main/java/org/sejda/core/context/XmlConfigurationStrategy.java --- libsejda-java-3.2.38/sejda-core/src/main/java/org/sejda/core/context/XmlConfigurationStrategy.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-core/src/main/java/org/sejda/core/context/XmlConfigurationStrategy.java 2018-12-03 16:42:31.000000000 +0000 @@ -41,6 +41,7 @@ import javax.xml.xpath.XPathFactory; import org.apache.commons.io.IOUtils; +import org.sejda.common.XMLUtils; import org.sejda.core.Sejda; import org.sejda.core.notification.strategy.AsyncNotificationStrategy; import org.sejda.core.notification.strategy.NotificationStrategy; @@ -92,10 +93,12 @@ } private void initializeFromInputStream(InputStream input) throws ConfigurationException { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { + DocumentBuilderFactory factory = XMLUtils.getDocumentBuilderFactory(); initializeSchemaValidation(factory); + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setErrorHandler(XMLUtils.ERROR_HANDLER); Document document = builder.parse(input); notificationStrategy = getNotificationStrategy(document); diff -Nru libsejda-java-3.2.38/sejda-core/src/main/java/org/sejda/core/support/prefix/NameGenerator.java libsejda-java-3.2.66/sejda-core/src/main/java/org/sejda/core/support/prefix/NameGenerator.java --- libsejda-java-3.2.38/sejda-core/src/main/java/org/sejda/core/support/prefix/NameGenerator.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-core/src/main/java/org/sejda/core/support/prefix/NameGenerator.java 2018-12-03 16:42:31.000000000 +0000 @@ -29,6 +29,9 @@ import org.sejda.core.support.prefix.model.NameGenerationRequest; import org.sejda.core.support.prefix.processor.PrefixTypesChain; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + /** * Component used to generate the output name for a manipulation given the input prefix (if any); * @@ -63,15 +66,50 @@ } String result = toSafeFilename(prefixTypesChain.process(prefix, preProcessRequest(request))); - if (result.length() > 255) { - String baseName = getBaseName(result); - String ext = getExtension(result); - return baseName.substring(0, 254 - ext.length()) + "." + ext; + String osName = System.getProperty("os.name").toLowerCase(); + if(osName.contains("win") || osName.contains("mac")) { + // char based max length + result = shortenFilenameCharLength(result, 255); + } else { + // bytes based max length + result = shortenFilenameBytesLength(result, 255, StandardCharsets.UTF_8); } return result; } + static String shortenFilenameCharLength(String input, int maxCharLength) { + if (input.length() > 255) { + String baseName = getBaseName(input); + String ext = getExtension(input); + + baseName = baseName.substring(0, 254 - ext.length()); + return String.format("%s.%s", baseName, ext); + } else { + return input; + } + } + + static String shortenFilenameBytesLength(String input, int maxBytesLength, Charset charset) { + if(input.getBytes(charset).length > maxBytesLength) { + String baseName = getBaseName(input); + String ext = getExtension(input); + + // drop last char from basename, try again + baseName = baseName.substring(0, baseName.length() - 1); + String shorterFilename = String.format("%s.%s", baseName, ext); + + while(shorterFilename.getBytes(charset).length > maxBytesLength) { + baseName = baseName.substring(0, baseName.length() - 1); + shorterFilename = String.format("%s.%s", baseName, ext); + } + + return shorterFilename; + } else { + return input; + } + } + /** * pre process the request ensuring a not null request is returned * diff -Nru libsejda-java-3.2.38/sejda-core/src/main/java/org/sejda/core/support/util/StringUtils.java libsejda-java-3.2.66/sejda-core/src/main/java/org/sejda/core/support/util/StringUtils.java --- libsejda-java-3.2.38/sejda-core/src/main/java/org/sejda/core/support/util/StringUtils.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-core/src/main/java/org/sejda/core/support/util/StringUtils.java 2018-12-03 16:42:31.000000000 +0000 @@ -61,4 +61,8 @@ return result; } + + public static String normalizeLineEndings(String in) { + return in.replaceAll("\\r\\n", "\n"); + } } diff -Nru libsejda-java-3.2.38/sejda-core/src/test/java/org/sejda/core/service/BaseTaskTest.java libsejda-java-3.2.66/sejda-core/src/test/java/org/sejda/core/service/BaseTaskTest.java --- libsejda-java-3.2.38/sejda-core/src/test/java/org/sejda/core/service/BaseTaskTest.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-core/src/test/java/org/sejda/core/service/BaseTaskTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -19,15 +19,21 @@ package org.sejda.core.service; import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sejda.util.RequireUtils.requireNotBlank; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.junit.After; @@ -36,7 +42,6 @@ import org.sejda.TestUtils; import org.sejda.core.context.DefaultSejdaContext; import org.sejda.core.context.SejdaContext; -import org.sejda.core.support.util.StringUtils; import org.sejda.model.exception.TaskException; import org.sejda.model.exception.TaskIOException; import org.sejda.model.input.FileSource; @@ -49,16 +54,7 @@ import org.sejda.sambox.cos.COSName; import org.sejda.sambox.pdmodel.PDDocument; import org.sejda.sambox.pdmodel.PDPage; -import org.sejda.sambox.pdmodel.common.PDRectangle; import org.sejda.sambox.pdmodel.graphics.image.PDImageXObject; -import org.sejda.sambox.text.PDFTextStripperByArea; - -import java.awt.*; -import java.io.*; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.function.Consumer; /** * @author Andrea Vacondio @@ -151,6 +147,16 @@ return PdfStreamSource.newInstanceNoPassword(getClass().getClassLoader().getResourceAsStream(path), name); } + public PdfFileSource customInput(PDDocument doc, String name) { + try { + File tmp = org.sejda.core.support.io.IOUtils.createTemporaryBufferWithName(name); + doc.writeTo(tmp); + return PdfFileSource.newInstanceNoPassword(tmp); + } catch (TaskIOException | IOException e) { + throw new RuntimeException(e); + } + } + public PdfStreamSource customEncryptedInput(String path, String password) { return PdfStreamSource.newInstanceWithPassword(getClass().getClassLoader().getResourceAsStream(path), randomAlphanumeric(16) + ".pdf", password); @@ -190,6 +196,11 @@ org.sejda.core.service.TestUtils.assertPageText(page, text); } + public void assertPageTextExactLines(PDPage page, String text) { + org.sejda.core.service.TestUtils.assertPageTextExactLines(page, text); + } + + public void assertPageTextContains(PDPage page, String text) { org.sejda.core.service.TestUtils.assertPageTextContains(page, text); } diff -Nru libsejda-java-3.2.38/sejda-core/src/test/java/org/sejda/core/service/EncryptTaskTest.java libsejda-java-3.2.66/sejda-core/src/test/java/org/sejda/core/service/EncryptTaskTest.java --- libsejda-java-3.2.38/sejda-core/src/test/java/org/sejda/core/service/EncryptTaskTest.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-core/src/test/java/org/sejda/core/service/EncryptTaskTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -91,6 +91,18 @@ } @Test + public void aes256WithUserPassword() throws IOException { + setUpParameters(PdfEncryption.AES_ENC_256); + parameters.setUserPassword("1234"); + testContext.directoryOutputTo(parameters); + execute(parameters); + testContext.assertTaskCompleted("1234"); + testContext.assertCreator().forEachPdfOutput(d -> { + assertTrue(d.isEncrypted()); + }); + } + + @Test public void enablingPrintDegraded() throws IOException { setUpParameters(PdfEncryption.STANDARD_ENC_128); parameters.setOwnerPassword("test"); diff -Nru libsejda-java-3.2.38/sejda-core/src/test/java/org/sejda/core/service/PdfToExcelTaskTest.java libsejda-java-3.2.66/sejda-core/src/test/java/org/sejda/core/service/PdfToExcelTaskTest.java --- libsejda-java-3.2.38/sejda-core/src/test/java/org/sejda/core/service/PdfToExcelTaskTest.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-core/src/test/java/org/sejda/core/service/PdfToExcelTaskTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -21,13 +21,18 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import java.io.File; import java.io.FileInputStream; +import java.io.FileReader; import java.io.IOException; import java.io.InputStream; +import java.io.Reader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVRecord; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.Row; @@ -43,8 +48,9 @@ @Ignore public abstract class PdfToExcelTaskTest extends BaseTaskTest { + @Test - public void testConversion() throws IOException { + public void testExcelConversion() throws IOException { PdfToExcelParameters params = getParams(); execute(params); @@ -71,6 +77,47 @@ } @Test + public void testCsvConversion() throws IOException { + PdfToExcelParameters params = getParams(); + params.setOutputPrefix("[BASENAME]_[FILENUMBER]"); + params.setCsvFormat(true); + execute(params); + + testContext.assertTaskCompleted(); + testContext.assertOutputSize(2) + .assertOutputContainsFilenames("tabular-data_1.csv", "tabular-data_2.csv") + .forRawOutput("tabular-data_1.csv", p -> { + try { + List> contents = parseCsv(p.toFile()); + + assertThat(contents.size(), is(37)); + + assertThat(contents.get(0), is(Arrays.asList("OrderDate", "Region", "Rep", "Item", "Units", "Unit Cost", "Total"))); + assertThat(contents.get(10), is(Arrays.asList("6/8/15", "East", "Jones", "Binder", "60", "8.99", "539.40"))); + assertThat(contents.get(13), is(Arrays.asList("7/29/15", "East", "Parent", "Binder", "81", "19.99", "1,619.19"))); + + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + + private List> parseCsv(File file) throws IOException { + List> results = new ArrayList<>(); + Reader in = new FileReader(file); + Iterable records = CSVFormat.DEFAULT.parse(in); + for (CSVRecord record : records) { + List row = new ArrayList<>(); + for(String s: record){ + row.add(s); + } + results.add(row); + } + + return results; + } + + @Test public void testMergedTables() throws IOException { PdfToExcelParameters params = getParams(); params.setMergeTablesSpanningMultiplePages(true); @@ -182,7 +229,7 @@ table.addRows(new TopLeftRectangularBox(42, 552, 336, 11)); parameters.addTable(1, table); - + table = new Table(); table.addColumns(new TopLeftRectangularBox(42, 39, 54, 111)); @@ -201,7 +248,7 @@ table.addRows(new TopLeftRectangularBox(42, 110, 336, 11)); table.addRows(new TopLeftRectangularBox(42, 124, 336, 11)); table.addRows(new TopLeftRectangularBox(42, 139, 336, 11)); - + parameters.addTable(2, table); testContext.directoryOutputTo(parameters); diff -Nru libsejda-java-3.2.38/sejda-core/src/test/java/org/sejda/core/service/ResizePagesTaskTest.java libsejda-java-3.2.66/sejda-core/src/test/java/org/sejda/core/service/ResizePagesTaskTest.java --- libsejda-java-3.2.38/sejda-core/src/test/java/org/sejda/core/service/ResizePagesTaskTest.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-core/src/test/java/org/sejda/core/service/ResizePagesTaskTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -25,6 +25,7 @@ import org.junit.Ignore; import org.junit.Test; +import org.sejda.model.input.PdfSource; import org.sejda.model.output.ExistingOutputPolicy; import org.sejda.model.parameter.PageSize; import org.sejda.model.parameter.ResizePagesParameters; @@ -45,15 +46,7 @@ @Test public void addUniformMargins() throws IOException { - ResizePagesParameters parameters = new ResizePagesParameters(); - parameters.addSource(regularInput()); - parameters.setMargins(new Margins(1, 1, 1, 1)); - parameters.addPageRange(new PageRange(1, 3)); - parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); - - testContext.pdfOutputTo(parameters); - execute(parameters); - testContext.assertTaskCompleted(); + executeAddMargins(new Margins(1, 1, 1, 1), new PageRange(1, 3), regularInput()); // number of pages does not change testContext.assertPages(11).forEachPdfOutput(d -> { @@ -83,15 +76,7 @@ @Test public void addMargins() throws IOException { - ResizePagesParameters parameters = new ResizePagesParameters(); - parameters.addSource(regularInput()); - parameters.setMargins(new Margins(0, 0, 2, 5)); - parameters.addPageRange(new PageRange(1, 3)); - parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); - - testContext.pdfOutputTo(parameters); - execute(parameters); - testContext.assertTaskCompleted(); + executeAddMargins(new Margins(0, 0, 2, 5), new PageRange(1, 3), regularInput()); // number of pages does not change testContext.assertPages(11).forEachPdfOutput(d -> { @@ -120,13 +105,7 @@ @Test public void landscape() throws IOException { - ResizePagesParameters parameters = new ResizePagesParameters(); - parameters.addSource(customInput("pdf/landscape.pdf")); - parameters.addSource(customInput("pdf/landscape_by_rotation.pdf")); - parameters.setPageSize(PageSize.A5); - testContext.directoryOutputTo(parameters); - execute(parameters); - testContext.assertTaskCompleted(); + executeChangeOfPageSize(PageSize.A5, customInput("pdf/landscape.pdf"), customInput("pdf/landscape_by_rotation.pdf")); testContext.forEachPdfOutput(d -> { PDPage page = d.getPage(0); @@ -138,18 +117,12 @@ @Test public void potrait() throws IOException { // A4 to A3 - ResizePagesParameters parameters = new ResizePagesParameters(); - parameters.addSource(customInput("pdf/potrait.pdf")); - parameters.addSource(customInput("pdf/potrait.pdf")); - parameters.setPageSize(PageSize.A3); - testContext.directoryOutputTo(parameters); - execute(parameters); - testContext.assertTaskCompleted(); + executeChangeOfPageSize(PageSize.A3, customInput("pdf/potrait.pdf"), customInput("pdf/potrait_by_rotation.pdf")); testContext.forEachPdfOutput(d -> { PDPage page = d.getPage(0); - assertEqualsRect(new PDRectangle(0, 0, 842, 1192), page.getCropBox().rotate(page.getRotation())); - assertEqualsRect(new PDRectangle(0, 0, 842, 1192), page.getMediaBox().rotate(page.getRotation())); + assertEqualsRect(PDRectangle.A3, page.getCropBox().rotate(page.getRotation())); + assertEqualsRect(PDRectangle.A3, page.getMediaBox().rotate(page.getRotation())); }); } @@ -157,19 +130,12 @@ @Test public void annotationsRectangleAndQuadPoints() throws IOException { - - ResizePagesParameters parameters = new ResizePagesParameters(); - parameters.addSource(customInput("pdf/highlighted-potrait.pdf")); - parameters.setPageSize(annotPageSize); - parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); - testContext.pdfOutputTo(parameters); - execute(parameters); - testContext.assertTaskCompleted(); + executeChangeOfPageSize(annotPageSize, customInput("pdf/highlighted-potrait.pdf")); testContext.forPdfOutput(d -> { d.getPage(0).getAnnotations().forEach(a -> { - assertEqualsRect(new PDRectangle(117, 1588, 110, 26), a.getRectangle()); - assertArrayEquals(new float[] { 117, 1614, 226, 1614, 117, 1588, 226, 1588 }, + assertEqualsRect(new PDRectangle(117, 1584, 110, 26), a.getRectangle()); + assertArrayEquals(new float[]{118, 1611, 227, 1611, 118, 1584, 227, 1584}, a.getCOSObject().getDictionaryObject(COSName.QUADPOINTS, COSArray.class).toFloatArray(), 1); }); @@ -178,19 +144,12 @@ @Test public void annotationsCallout() throws IOException { - - ResizePagesParameters parameters = new ResizePagesParameters(); - parameters.addSource(customInput("pdf/callout-potrait.pdf")); - parameters.setPageSize(annotPageSize); - parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); - testContext.pdfOutputTo(parameters); - execute(parameters); - testContext.assertTaskCompleted(); + executeChangeOfPageSize(annotPageSize, customInput("pdf/callout-potrait.pdf")); testContext.forPdfOutput(d -> { d.getPage(0).getAnnotations().forEach(a -> { - assertEqualsRect(new PDRectangle(259, 1496, 496, 104), a.getRectangle()); - assertArrayEquals(new float[] { 259, 1596, 507, 1510, 533, 1511 }, + assertEqualsRect(new PDRectangle(259, 1492, 496, 104), a.getRectangle()); + assertArrayEquals(new float[] { 260, 1592, 508, 1507, 533, 1507 }, a.getCOSObject().getDictionaryObject(COSName.CL, COSArray.class).toFloatArray(), 1); }); @@ -199,21 +158,14 @@ @Test public void annotationsPolygon() throws IOException { - - ResizePagesParameters parameters = new ResizePagesParameters(); - parameters.addSource(customInput("pdf/polygon-potrait.pdf")); - parameters.setPageSize(annotPageSize); - parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); - testContext.pdfOutputTo(parameters); - execute(parameters); - testContext.assertTaskCompleted(); + executeChangeOfPageSize(annotPageSize, customInput("pdf/polygon-potrait.pdf")); testContext.forPdfOutput(d -> { d.getPage(0).getAnnotations().forEach(a -> { if (a.getSubtype().equals("Polygon")) { assertEqualsRect(new PDRectangle(431, 1218, 391, 351), a.getRectangle()); assertArrayEquals( - new float[] { 454, 1503, 607, 1567, 799, 1523, 820, 1339, 576, 1221, 433, 1294, 454, 1503 }, + new float[]{454, 1499, 607, 1563, 798, 1519, 819, 1335, 575, 1218, 434, 1290, 454, 1499}, a.getCOSObject().getDictionaryObject(COSName.VERTICES, COSArray.class).toFloatArray(), 1); } }); @@ -223,20 +175,13 @@ @Test public void annotationsLine() throws IOException { - - ResizePagesParameters parameters = new ResizePagesParameters(); - parameters.addSource(customInput("pdf/line-potrait_by_rotation.pdf")); - parameters.setPageSize(annotPageSize); - parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); - testContext.pdfOutputTo(parameters); - execute(parameters); - testContext.assertTaskCompleted(); + executeChangeOfPageSize(annotPageSize, customInput("pdf/line-potrait_by_rotation.pdf")); testContext.forPdfOutput(d -> { d.getPage(0).getAnnotations().forEach(a -> { if (a.getSubtype().equals("Line")) { assertEqualsRect(new PDRectangle(1584, 884, 49, 220), a.getRectangle()); - assertArrayEquals(new float[] { 1600, 1092, 1609, 897 }, + assertArrayEquals(new float[]{1598, 1089, 1606, 895}, a.getCOSObject().getDictionaryObject(COSName.L, COSArray.class).toFloatArray(), 1); } }); @@ -246,16 +191,7 @@ @Test public void resize_MultipleSizedPages_MixingLandscapePortrait() throws IOException { - ResizePagesParameters parameters = new ResizePagesParameters(); - parameters.addSource(customInput("pdf/multiple-sized-pages.pdf")); - parameters.setPageSize(PageSize.A5); - parameters.addPageRange(new PageRange(1, 2)); - - testContext.directoryOutputTo(parameters); - - execute(parameters); - - testContext.assertTaskCompleted(); + executeChangeOfPageSize(PageSize.A5, new PageRange(1, 2), customInput("pdf/multiple-sized-pages.pdf")); // number of pages does not change testContext.assertPages(3).forEachPdfOutput(d -> { @@ -276,7 +212,8 @@ page = d.getPage(2); - // page has unchanged size + // page has unchanged size, + // because it was not included in the page selection expected = new PDRectangle(0f, 0f, 841f, 1190f); assertEqualsRect(expected, page.getMediaBox()); assertEqualsRect(expected, page.getCropBox()); @@ -285,15 +222,7 @@ @Test public void resize_allLandscape() throws IOException { - ResizePagesParameters parameters = new ResizePagesParameters(); - parameters.addSource(customInput("pdf/multiple-sized-pages-all-landscape.pdf")); - parameters.setPageSize(PageSize.A5); - - testContext.directoryOutputTo(parameters); - - execute(parameters); - - testContext.assertTaskCompleted(); + executeChangeOfPageSize(PageSize.A5, customInput("pdf/multiple-sized-pages-all-landscape.pdf")); // number of pages does not change testContext.assertPages(2).forEachPdfOutput(d -> { @@ -301,14 +230,13 @@ // page has new size // was A4 landscape, expect A5 landscape - PDRectangle expected = PDRectangle.A5.rotate(90); + PDRectangle expected = PDRectangle.A5.rotate(); assertEqualsRect(expected, page.getMediaBox()); assertEqualsRect(expected, page.getCropBox()); page = d.getPage(1); // page has new size // was A3 landscape, expect A5 landscape - expected = PDRectangle.A5.rotate(90); assertEqualsRect(expected, page.getMediaBox()); assertEqualsRect(expected, page.getCropBox()); }); @@ -316,15 +244,7 @@ @Test public void noPageSelection() throws IOException { - ResizePagesParameters parameters = new ResizePagesParameters(); - parameters.addSource(customInput("pdf/test-pdf.pdf")); - parameters.setPageSize(PageSize.A5); - - testContext.directoryOutputTo(parameters); - - execute(parameters); - - testContext.assertTaskCompleted(); + executeChangeOfPageSize(PageSize.A5, customInput("pdf/test-pdf.pdf")); testContext.forEachPdfOutput(d -> { // all pages have new size of A5 @@ -354,6 +274,59 @@ }); } + @Test + public void resizeChangingAspectRatio() throws IOException { + executeChangeOfPageSize(PageSize.LEGAL, customInput("pdf/test-pdf.pdf")); + + testContext.forEachPdfOutput(d -> { + PDPage page = d.getPage(0); + assertEqualsRect(PDRectangle.LEGAL, page.getMediaBox()); + assertEqualsRect(PDRectangle.LEGAL, page.getCropBox()); + }); + } + + private void executeChangeOfPageSize(PageSize desiredPageSize, PdfSource... inputs) throws IOException { + executeChangeOfPageSize(desiredPageSize, null, inputs); + } + + private void executeChangeOfPageSize(PageSize desiredPageSize, PageRange pageRange, PdfSource... inputs) throws IOException { + ResizePagesParameters parameters = new ResizePagesParameters(); + for(PdfSource input: inputs) { + parameters.addSource(input); + } + + parameters.setPageSize(desiredPageSize); + if(pageRange != null) { + parameters.addPageRange(pageRange); + } + + parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); + testContext.directoryOutputTo(parameters); + + execute(parameters); + + testContext.assertTaskCompleted(); + } + + private void executeAddMargins(Margins margins, PageRange pageRange, PdfSource... inputs) throws IOException { + ResizePagesParameters parameters = new ResizePagesParameters(); + for(PdfSource input: inputs) { + parameters.addSource(input); + } + + parameters.setMargins(margins); + if(pageRange != null) { + parameters.addPageRange(pageRange); + } + + parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); + testContext.directoryOutputTo(parameters); + + execute(parameters); + + testContext.assertTaskCompleted(); + } + private String extractText(PDPage page, Rectangle rect) { try { PDFTextStripperByArea stripper = new PDFTextStripperByArea(); diff -Nru libsejda-java-3.2.38/sejda-core/src/test/java/org/sejda/core/service/TaskTestContext.java libsejda-java-3.2.66/sejda-core/src/test/java/org/sejda/core/service/TaskTestContext.java --- libsejda-java-3.2.38/sejda-core/src/test/java/org/sejda/core/service/TaskTestContext.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-core/src/test/java/org/sejda/core/service/TaskTestContext.java 2018-12-03 16:42:31.000000000 +0000 @@ -412,6 +412,14 @@ return this; } + public TaskTestContext forRawOutput(String filename, Consumer consumer) throws IOException { + requireMultipleOutputs(); + File file = new File(fileOutput, filename); + assertTrue(file.exists()); + consumer.accept(file.toPath()); + return this; + } + private void requireMultipleOutputs() { assertNotNull(fileOutput); assertTrue("Expected an output directory", fileOutput.isDirectory()); diff -Nru libsejda-java-3.2.38/sejda-core/src/test/java/org/sejda/core/service/TestUtils.java libsejda-java-3.2.66/sejda-core/src/test/java/org/sejda/core/service/TestUtils.java --- libsejda-java-3.2.38/sejda-core/src/test/java/org/sejda/core/service/TestUtils.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-core/src/test/java/org/sejda/core/service/TestUtils.java 2018-12-03 16:42:31.000000000 +0000 @@ -19,9 +19,11 @@ import org.sejda.core.support.util.StringUtils; import org.sejda.sambox.pdmodel.PDPage; +import org.sejda.sambox.pdmodel.common.PDPageLabelRange; +import org.sejda.sambox.pdmodel.common.PDPageLabels; import org.sejda.sambox.pdmodel.common.PDRectangle; import org.sejda.sambox.pdmodel.interactive.annotation.PDAnnotationLink; -import org.sejda.sambox.pdmodel.interactive.documentnavigation.destination.PDPageFitWidthDestination; +import org.sejda.sambox.pdmodel.interactive.documentnavigation.destination.PDPageDestination; import org.sejda.sambox.text.PDFTextStripperByArea; import java.awt.*; @@ -30,11 +32,14 @@ import java.util.List; import java.util.function.Consumer; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; +import static org.sejda.core.support.util.StringUtils.normalizeLineEndings; public class TestUtils { @@ -68,6 +73,12 @@ }); } + public static void assertPageTextExactLines(PDPage page, String text) { + withPageText(page, pageText -> { + assertEquals(normalizeLineEndings(text), normalizeLineEndings(pageText)); + }); + } + public static void assertPageTextContains(PDPage page, String text) { withPageText(page, pageText -> { pageText = StringUtils.normalizeWhitespace(pageText); @@ -109,7 +120,27 @@ } public static void assertPageDestination(PDAnnotationLink link, PDPage expectedPage) throws IOException { - PDPage actualPage = ((PDPageFitWidthDestination)link.getDestination()).getPage(); + PDPage actualPage = ((PDPageDestination)link.getDestination()).getPage(); assertEquals(expectedPage, actualPage); } + + public static void assertPageLabelIndexesAre(PDPageLabels labels, Integer... expected) { + assertThat(labels.getLabels().keySet(), is(new HashSet<>(Arrays.asList(expected)))); + } + + public static void assertPageLabelRangeIs(PDPageLabels labels, int startPage, PDPageLabelRange expected) { + PDPageLabelRange actual = labels.getPageLabelRange(startPage); + assertNotNull("No page label range found at index: " + startPage + ". "+ labels.getLabels().keySet(), actual); + assertThat("Difference at index: " + startPage, actual.getCOSObject().toString(), is(expected.getCOSObject().toString())); + } + + public static void assertPageLabelRangeIsDefault(PDPageLabels labels, int startPage) { + PDPageLabelRange defaultLabel = new PDPageLabelRange(); + defaultLabel.setStyle(PDPageLabelRange.STYLE_DECIMAL); + assertPageLabelRangeIs(labels, startPage, defaultLabel); + } + + public static void assertPageLabelRangeIs(PDPageLabels labels, int startPage, String style) { + assertPageLabelRangeIs(labels, startPage, new PDPageLabelRange(style, null, null)); + } } diff -Nru libsejda-java-3.2.38/sejda-core/src/test/java/org/sejda/core/support/prefix/NameGeneratorTest.java libsejda-java-3.2.66/sejda-core/src/test/java/org/sejda/core/support/prefix/NameGeneratorTest.java --- libsejda-java-3.2.38/sejda-core/src/test/java/org/sejda/core/support/prefix/NameGeneratorTest.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-core/src/test/java/org/sejda/core/support/prefix/NameGeneratorTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -22,14 +22,18 @@ import static org.apache.commons.lang3.StringUtils.repeat; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.core.StringEndsWith.endsWith; import static org.hamcrest.core.StringStartsWith.startsWith; import static org.junit.Assert.assertEquals; import static org.sejda.core.support.prefix.NameGenerator.nameGenerator; import static org.sejda.core.support.prefix.model.NameGenerationRequest.nameRequest; +import static org.hamcrest.Matchers.is; import org.junit.Test; +import java.nio.charset.StandardCharsets; + /** * Test unit for the NameGenerator * @@ -86,6 +90,14 @@ } @Test + public void testMaxFilenameSizeUnicode() { + String generatedFilename = nameGenerator("compressed_").generate(nameRequest("pdf").originalName(repeat("aว", 300))); + assertThat(generatedFilename.length(), is(lessThan(256))); + assertThat(generatedFilename, endsWith(".pdf")); + assertThat(generatedFilename, startsWith("compressed_aวaว")); + } + + @Test public void testMaxFilenameSizeSanitized() { String generatedFilename = nameGenerator("B|LA_[TEXT]").generate(nameRequest("pdf").text(repeat('a', 300))); assertEquals(255, generatedFilename.length()); @@ -105,4 +117,27 @@ .generate(nameRequest("pdf").page(99).originalName("My file 6-04-2015 $1234-56")); assertEquals(generatedFilename, "99-My file 6-04-2015 $1234-56.pdf"); } + + // convenience method, don't pass charset and len all the time + private String shortenFilenameBytesLength(String input) { + return NameGenerator.shortenFilenameBytesLength(input, 255, StandardCharsets.UTF_8); + } + + private String largeFilename = repeat("aว", 300) + ".pdf"; + + @Test + public void shortenFilenameBytesLength() { + String shorter = shortenFilenameBytesLength(largeFilename); + assertThat(shorter, endsWith("aวaวa.pdf")); + assertThat(shorter, startsWith("aวaว")); + assertThat(shorter.getBytes(StandardCharsets.UTF_8).length, is(253)); + } + + @Test + public void shortenFilenameCharLength() { + String shorter = NameGenerator.shortenFilenameCharLength(largeFilename, 255); + assertThat(shorter, endsWith("aวaวa.pdf")); + assertThat(shorter, startsWith("aวaว")); + assertThat(shorter.length(), is(255)); + } } Binary files /tmp/tmpB8LYXY/GH8aWaPdwo/libsejda-java-3.2.38/sejda-core/src/test/resources/pdf/2-up_fonts.pdf and /tmp/tmpB8LYXY/OcKMSoYXhW/libsejda-java-3.2.66/sejda-core/src/test/resources/pdf/2-up_fonts.pdf differ Binary files /tmp/tmpB8LYXY/GH8aWaPdwo/libsejda-java-3.2.38/sejda-core/src/test/resources/pdf/forms/test_form_with_calc.pdf and /tmp/tmpB8LYXY/OcKMSoYXhW/libsejda-java-3.2.66/sejda-core/src/test/resources/pdf/forms/test_form_with_calc.pdf differ Binary files /tmp/tmpB8LYXY/GH8aWaPdwo/libsejda-java-3.2.38/sejda-core/src/test/resources/pdf/test_file_landscape_rotated.pdf and /tmp/tmpB8LYXY/OcKMSoYXhW/libsejda-java-3.2.66/sejda-core/src/test/resources/pdf/test_file_landscape_rotated.pdf differ diff -Nru libsejda-java-3.2.38/sejda-distribution/pom.xml libsejda-java-3.2.66/sejda-distribution/pom.xml --- libsejda-java-3.2.38/sejda-distribution/pom.xml 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-distribution/pom.xml 2018-12-03 16:42:31.000000000 +0000 @@ -10,7 +10,7 @@ org.sejda sejda-parent - 3.2.38 + 3.2.66 ../pom.xml diff -Nru libsejda-java-3.2.38/sejda-docs/pom.xml libsejda-java-3.2.66/sejda-docs/pom.xml --- libsejda-java-3.2.38/sejda-docs/pom.xml 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-docs/pom.xml 2018-12-03 16:42:31.000000000 +0000 @@ -5,7 +5,7 @@ org.sejda sejda-parent - 3.2.38 + 3.2.66 ../pom.xml Binary files /tmp/tmpB8LYXY/GH8aWaPdwo/libsejda-java-3.2.38/sejda-fonts/fonts/sans/NotoKufiArabic-Regular.ttf and /tmp/tmpB8LYXY/OcKMSoYXhW/libsejda-java-3.2.66/sejda-fonts/fonts/sans/NotoKufiArabic-Regular.ttf differ diff -Nru libsejda-java-3.2.38/sejda-fonts/fonts/sans/README.txt libsejda-java-3.2.66/sejda-fonts/fonts/sans/README.txt --- libsejda-java-3.2.38/sejda-fonts/fonts/sans/README.txt 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-fonts/fonts/sans/README.txt 2018-12-03 16:42:31.000000000 +0000 @@ -12,7 +12,6 @@ # list to maximize the amount of meta data retained in the final merged font. 'NotoSans-Regular.ttf', 'NotoSansBengali-Regular.ttf', - 'NotoKufiArabic-Regular.ttf', 'NotoNaskhArabic-Regular.ttf', 'NotoSansBengali-Regular.ttf', 'NotoSansDevanagari-Regular.ttf', diff -Nru libsejda-java-3.2.38/sejda-fonts/pom.xml libsejda-java-3.2.66/sejda-fonts/pom.xml --- libsejda-java-3.2.38/sejda-fonts/pom.xml 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-fonts/pom.xml 2018-12-03 16:42:31.000000000 +0000 @@ -10,10 +10,26 @@ org.sejda sejda-parent - 3.2.38 + 3.2.66 ../pom.xml - + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.sejda.fonts + + + + + + + org.sejda Binary files /tmp/tmpB8LYXY/GH8aWaPdwo/libsejda-java-3.2.38/sejda-fonts/src/main/resources/fonts/sans/NotoSansMerged-Regular.ttf and /tmp/tmpB8LYXY/OcKMSoYXhW/libsejda-java-3.2.66/sejda-fonts/src/main/resources/fonts/sans/NotoSansMerged-Regular.ttf differ diff -Nru libsejda-java-3.2.38/sejda-image-writers/pom.xml libsejda-java-3.2.66/sejda-image-writers/pom.xml --- libsejda-java-3.2.38/sejda-image-writers/pom.xml 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-image-writers/pom.xml 2018-12-03 16:42:31.000000000 +0000 @@ -6,7 +6,7 @@ org.sejda sejda-parent - 3.2.38 + 3.2.66 ../pom.xml @@ -14,7 +14,23 @@ jar sejda image writers - + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.sejda.core.writer + + + + + + + org.sejda diff -Nru libsejda-java-3.2.38/sejda-model/pom.xml libsejda-java-3.2.66/sejda-model/pom.xml --- libsejda-java-3.2.38/sejda-model/pom.xml 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-model/pom.xml 2018-12-03 16:42:31.000000000 +0000 @@ -6,7 +6,7 @@ org.sejda sejda-parent - 3.2.38 + 3.2.66 ../pom.xml @@ -26,6 +26,13 @@ + + + + org.sejda.model + + + diff -Nru libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/common/XMLUtils.java libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/common/XMLUtils.java --- libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/common/XMLUtils.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/common/XMLUtils.java 2018-12-03 16:42:31.000000000 +0000 @@ -20,7 +20,15 @@ package org.sejda.common; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.w3c.dom.Node; +import org.xml.sax.ErrorHandler; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; /** * Provides some utility methods to deal with xml. @@ -29,6 +37,9 @@ * */ public final class XMLUtils { + + private static final Logger LOG = LoggerFactory.getLogger(XMLUtils.class); + private XMLUtils() { // hide } @@ -70,4 +81,31 @@ } return defaultValue; } + + public static final DocumentBuilderFactory getDocumentBuilderFactory() throws ParserConfigurationException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + + factory.setValidating(true); + factory.setFeature("http://xml.org/sax/features/validation", true); + + return factory; + } + + public static final ErrorHandler ERROR_HANDLER = new ErrorHandler() { + + @Override + public void warning(SAXParseException e) throws SAXException { + // noop + } + + @Override + public void error(SAXParseException e) throws SAXException { + LOG.debug(e.getMessage()); + } + + @Override + public void fatalError(SAXParseException e) throws SAXException { + throw e; + } + }; } diff -Nru libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/model/outline/CatalogPageLabelsPolicy.java libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/model/outline/CatalogPageLabelsPolicy.java --- libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/model/outline/CatalogPageLabelsPolicy.java 1970-01-01 00:00:00.000000000 +0000 +++ libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/model/outline/CatalogPageLabelsPolicy.java 2018-12-03 16:42:31.000000000 +0000 @@ -0,0 +1,41 @@ +/* + * Copyright 2018 by Eduard Weissmann (edi.weissmann@gmail.com). + * + * This file is part of the Sejda source code + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.sejda.model.outline; + +import org.sejda.common.FriendlyNamed; + +/** + * Different ways to handle PageLabels found in the DocumentCatalog when processing documents + * + */ +public enum CatalogPageLabelsPolicy implements FriendlyNamed { + DISCARD("discard"), + RETAIN("retain"); + + private String displayName; + + private CatalogPageLabelsPolicy(String displayName) { + this.displayName = displayName; + } + + @Override + public String getFriendlyName() { + return displayName; + } +} diff -Nru libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/model/parameter/excel/PdfToExcelParameters.java libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/model/parameter/excel/PdfToExcelParameters.java --- libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/model/parameter/excel/PdfToExcelParameters.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/model/parameter/excel/PdfToExcelParameters.java 2018-12-03 16:42:31.000000000 +0000 @@ -27,6 +27,7 @@ public class PdfToExcelParameters extends MultiplePdfSourceMultipleOutputParameters { private Map> tables = new HashMap<>(); private boolean mergeTablesSpanningMultiplePages = false; + private boolean csvFormat = false; public void addTable(int pageNumber, Table table) { if(!this.tables.containsKey(pageNumber)) { @@ -59,6 +60,14 @@ this.mergeTablesSpanningMultiplePages = mergeTablesSpanningMultiplePages; } + public boolean isCsvFormat() { + return csvFormat; + } + + public void setCsvFormat(boolean csvFormat) { + this.csvFormat = csvFormat; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -71,6 +80,7 @@ .appendSuper(super.equals(that)) .append(tables, that.tables) .append(mergeTablesSpanningMultiplePages, that.mergeTablesSpanningMultiplePages) + .append(csvFormat, that.csvFormat) .isEquals(); } @@ -80,6 +90,7 @@ .appendSuper(super.hashCode()) .append(tables) .append(mergeTablesSpanningMultiplePages) + .append(csvFormat) .toHashCode(); } } diff -Nru libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/model/parameter/image/PdfToMultipleTiffParameters.java libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/model/parameter/image/PdfToMultipleTiffParameters.java --- libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/model/parameter/image/PdfToMultipleTiffParameters.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/model/parameter/image/PdfToMultipleTiffParameters.java 2018-12-03 16:42:31.000000000 +0000 @@ -39,7 +39,12 @@ private TiffCompressionType compressionType = TiffCompressionType.NONE; public PdfToMultipleTiffParameters(ImageColorType outputImageColorType) { + this(outputImageColorType, TiffCompressionType.NONE); + } + + public PdfToMultipleTiffParameters(ImageColorType outputImageColorType, TiffCompressionType compressionType) { super(outputImageColorType); + this.compressionType = compressionType; } @Override diff -Nru libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/model/parameter/MergeParameters.java libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/model/parameter/MergeParameters.java --- libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/model/parameter/MergeParameters.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/model/parameter/MergeParameters.java 2018-12-03 16:42:31.000000000 +0000 @@ -33,6 +33,7 @@ import org.apache.commons.lang3.builder.HashCodeBuilder; import org.sejda.model.input.MergeInput; import org.sejda.model.input.PdfMergeInput; +import org.sejda.model.outline.CatalogPageLabelsPolicy; import org.sejda.model.outline.OutlinePolicy; import org.sejda.model.output.SingleTaskOutput; import org.sejda.model.parameter.base.AbstractPdfOutputParameters; @@ -59,6 +60,8 @@ private OutlinePolicy outlinePolicy = OutlinePolicy.RETAIN; @NotNull private AcroFormPolicy acroFormPolicy = AcroFormPolicy.MERGE_RENAMING_EXISTING_FIELDS; + @NotNull + private CatalogPageLabelsPolicy catalogPageLabelsPolicy = CatalogPageLabelsPolicy.DISCARD; @Valid @NotNull private SingleTaskOutput output; @@ -67,6 +70,7 @@ private boolean filenameFooter = false; /* Makes all pages same width as the first page */ private boolean normalizePageSizes = false; + private boolean firstInputCoverTitle = false; @Override public SingleTaskOutput getOutput() { @@ -168,11 +172,28 @@ this.normalizePageSizes = normalizePageSizes; } + public CatalogPageLabelsPolicy getCatalogPageLabelsPolicy() { + return catalogPageLabelsPolicy; + } + + public void setCatalogPageLabelsPolicy(CatalogPageLabelsPolicy catalogPageLabelsPolicy) { + this.catalogPageLabelsPolicy = catalogPageLabelsPolicy; + } + + public boolean isFirstInputCoverTitle() { + return firstInputCoverTitle; + } + + public void setFirstInputCoverTitle(boolean firstInputCoverTitle) { + this.firstInputCoverTitle = firstInputCoverTitle; + } + @Override public int hashCode() { return new HashCodeBuilder().appendSuper(super.hashCode()).append(inputList).append(acroFormPolicy) .append(blankPageIfOdd).append(outlinePolicy).append(tocPolicy).append(output).append(filenameFooter) - .append(normalizePageSizes).toHashCode(); + .append(normalizePageSizes).append(catalogPageLabelsPolicy).append(firstInputCoverTitle) + .toHashCode(); } @Override @@ -188,6 +209,9 @@ .append(acroFormPolicy, params.getAcroFormPolicy()).append(blankPageIfOdd, params.isBlankPageIfOdd()) .append(outlinePolicy, params.getOutlinePolicy()).append(tocPolicy, params.getTableOfContentsPolicy()) .append(output, params.getOutput()).append(filenameFooter, params.isFilenameFooter()) - .append(normalizePageSizes, params.isNormalizePageSizes()).isEquals(); + .append(normalizePageSizes, params.isNormalizePageSizes()) + .append(catalogPageLabelsPolicy, params.catalogPageLabelsPolicy) + .append(firstInputCoverTitle, params.firstInputCoverTitle) + .isEquals(); } } diff -Nru libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/model/parameter/PageSize.java libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/model/parameter/PageSize.java --- libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/model/parameter/PageSize.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/model/parameter/PageSize.java 2018-12-03 16:42:31.000000000 +0000 @@ -34,11 +34,16 @@ private static final float POINTS_PER_MM = 1 / (10 * 2.54f) * POINTS_PER_INCH; /** A rectangle the size of U.S. Letter, 8.5" x 11". */ - public static final PageSize LETTER = new PageSize(8.5f * POINTS_PER_INCH, - 11f * POINTS_PER_INCH, "Letter"); + public static final PageSize LETTER = new PageSize(8.5f * POINTS_PER_INCH, 11f * POINTS_PER_INCH, "Letter"); /** A rectangle the size of U.S. Legal, 8.5" x 14". */ - public static final PageSize LEGAL = new PageSize(8.5f * POINTS_PER_INCH, - 14f * POINTS_PER_INCH, "Legal"); + public static final PageSize LEGAL = new PageSize(8.5f * POINTS_PER_INCH, 14f * POINTS_PER_INCH, "Legal"); + /** A rectangle the size of U.S. Ledger, 11" x 17". */ + public static final PageSize LEDGER = new PageSize(11f * POINTS_PER_INCH,17f * POINTS_PER_INCH, "Ledger"); + /** A rectangle the size of U.S. Tabloid, 17" x 11". */ + public static final PageSize TABLOID = new PageSize(17f * POINTS_PER_INCH,11f * POINTS_PER_INCH, "Tabloid"); + /** A rectangle the size of U.S. Executive, 7.25" x 10.55". */ + public static final PageSize EXECUTIVE = new PageSize(7.25f * POINTS_PER_INCH,10.55f * POINTS_PER_INCH, "Executive"); + /** A rectangle the size of A0 Paper. */ public static final PageSize A0 = new PageSize(841 * POINTS_PER_MM, 1189 * POINTS_PER_MM, "A0"); diff -Nru libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/model/RectangularBox.java libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/model/RectangularBox.java --- libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/model/RectangularBox.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/model/RectangularBox.java 2018-12-03 16:42:31.000000000 +0000 @@ -25,7 +25,6 @@ import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; import org.sejda.model.rotation.Rotation; -import org.sejda.model.validation.constraint.NotNegativeCoordinates; import org.sejda.model.validation.constraint.ValidCoordinates; /** @@ -35,7 +34,6 @@ * */ @ValidCoordinates -@NotNegativeCoordinates public final class RectangularBox { private int bottom; @@ -43,7 +41,14 @@ private int top; private int right; - private RectangularBox(int bottom, int left, int top, int right) { + public RectangularBox(int bottom, int left, int top, int right) { + if (top <= bottom) { + throw new IllegalArgumentException("Top must be greater then bottom."); + } + if (right <= left) { + throw new IllegalArgumentException("Right must be greater then left."); + } + this.bottom = bottom; this.left = left; this.top = top; @@ -130,25 +135,9 @@ * if one of the arguments is negative, top is lower then bottom or right is lower then left. */ public static RectangularBox newInstance(int bottom, int left, int top, int right) { - assertNotNegative(bottom); - assertNotNegative(left); - assertNotNegative(top); - assertNotNegative(right); - if (top <= bottom) { - throw new IllegalArgumentException("Top must be greter then bottom."); - } - if (right <= left) { - throw new IllegalArgumentException("Right must be greter then left."); - } return new RectangularBox(bottom, left, top, right); } - private static void assertNotNegative(int value) { - if (value < 0) { - throw new IllegalArgumentException(String.format("Found negative value %d", value)); - } - } - /** * static factory method creating a new instance of the {@link RectangularBox} from two points. * diff -Nru libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/model/scale/Margins.java libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/model/scale/Margins.java --- libsejda-java-3.2.38/sejda-model/src/main/java/org/sejda/model/scale/Margins.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-model/src/main/java/org/sejda/model/scale/Margins.java 2018-12-03 16:42:31.000000000 +0000 @@ -54,6 +54,14 @@ return 72 * inches; } + public static double pointsToInches(double points) { + return points / 72; + } + + public Margins rotate() { + return new Margins(left, top, right, bottom); + } + @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("top", top).append("right", right) diff -Nru libsejda-java-3.2.38/sejda-model/src/test/java/org/sejda/model/RectangularBoxTest.java libsejda-java-3.2.66/sejda-model/src/test/java/org/sejda/model/RectangularBoxTest.java --- libsejda-java-3.2.38/sejda-model/src/test/java/org/sejda/model/RectangularBoxTest.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-model/src/test/java/org/sejda/model/RectangularBoxTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -34,26 +34,6 @@ public class RectangularBoxTest { @Test(expected = IllegalArgumentException.class) - public void testNegativeTop() { - RectangularBox.newInstance(10, 0, -1, 10); - } - - @Test(expected = IllegalArgumentException.class) - public void testNegativeBottom() { - RectangularBox.newInstance(-10, 0, 10, 10); - } - - @Test(expected = IllegalArgumentException.class) - public void testNegativeLeft() { - RectangularBox.newInstance(0, -1, 10, 10); - } - - @Test(expected = IllegalArgumentException.class) - public void testNegativeRight() { - RectangularBox.newInstance(0, 0, 10, -1); - } - - @Test(expected = IllegalArgumentException.class) public void testLeftGreaterRight() { RectangularBox.newInstance(0, 11, 10, 10); } diff -Nru libsejda-java-3.2.38/sejda-ocr/pom.xml libsejda-java-3.2.66/sejda-ocr/pom.xml --- libsejda-java-3.2.38/sejda-ocr/pom.xml 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-ocr/pom.xml 2018-12-03 16:42:31.000000000 +0000 @@ -6,7 +6,7 @@ org.sejda sejda-parent - 3.2.38 + 3.2.66 ../pom.xml @@ -15,6 +15,22 @@ sejda ocr + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.sejda.impl.sambox.ocr + + + + + + + org.sejda @@ -35,7 +51,7 @@ org.sejda sambox ${sambox.version} - + com.twelvemonkeys.imageio imageio-core diff -Nru libsejda-java-3.2.38/sejda-optional-fonts/pom.xml libsejda-java-3.2.66/sejda-optional-fonts/pom.xml --- libsejda-java-3.2.38/sejda-optional-fonts/pom.xml 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-optional-fonts/pom.xml 2018-12-03 16:42:31.000000000 +0000 @@ -10,10 +10,26 @@ org.sejda sejda-parent - 3.2.38 + 3.2.66 ../pom.xml + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.sejda.fonts.optional + + + + + + + org.sejda diff -Nru libsejda-java-3.2.38/sejda-sambox/pom.xml libsejda-java-3.2.66/sejda-sambox/pom.xml --- libsejda-java-3.2.38/sejda-sambox/pom.xml 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/pom.xml 2018-12-03 16:42:31.000000000 +0000 @@ -6,7 +6,7 @@ org.sejda sejda-parent - 3.2.38 + 3.2.66 ../pom.xml @@ -15,6 +15,22 @@ sejda sambox + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.sejda.impl.sambox + + + + + + + org.sejda @@ -84,6 +100,10 @@ commons-io + org.apache.commons + commons-csv + + org.apache.poi poi-ooxml diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/CombineReorderTask.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/CombineReorderTask.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/CombineReorderTask.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/CombineReorderTask.java 2018-12-03 16:42:31.000000000 +0000 @@ -64,7 +64,7 @@ private List documents = new ArrayList<>(); private Map documentNames = new HashMap<>(); private AcroFormsMerger acroFormsMerger; - private LookupTable pagesLookup = new LookupTable<>(); + private Map> pagesLookup = new HashMap<>(); private OutlineMerger outlineMerger; @Override @@ -95,6 +95,7 @@ PDDocumentHandler sourceDocumentHandler = input.open(sourceOpener); documents.add(sourceDocumentHandler); documentNames.put(sourceDocumentHandler, input.getName()); + pagesLookup.put(sourceDocumentHandler, new LookupTable<>()); } int currentStep = 0; @@ -117,10 +118,11 @@ destinationDocument.addBlankPage(mediaBox); } else { try { - PDPage page = documents.get(filePage.getFileIndex()).getPage(pageNum); + PDDocumentHandler documentHandler = documents.get(filePage.getFileIndex()); + PDPage page = documentHandler.getPage(pageNum); PDPage newPage = destinationDocument.importPage(page); lastPage = newPage; - pagesLookup.addLookupEntry(page, newPage); + pagesLookup.get(documentHandler).addLookupEntry(page, newPage); rotator.rotate(i + 1, filePage.getRotation()); } catch (PageNotFoundException e) { executionContext().assertTaskIsLenient(e); @@ -133,10 +135,11 @@ } for (PDDocumentHandler document : documents) { - outlineMerger.updateOutline(document.getUnderlyingPDDocument(), documentNames.get(document), pagesLookup); + LookupTable lookupTable = pagesLookup.get(document); + outlineMerger.updateOutline(document.getUnderlyingPDDocument(), documentNames.get(document), lookupTable); LookupTable annotationsLookup = new AnnotationsDistiller(document.getUnderlyingPDDocument()) - .retainRelevantAnnotations(pagesLookup); + .retainRelevantAnnotations(lookupTable); clipSignatures(annotationsLookup.values()); acroFormsMerger.mergeForm(document.getUnderlyingPDDocument().getDocumentCatalog().getAcroForm(), diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/AcroFormsMerger.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/AcroFormsMerger.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/AcroFormsMerger.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/AcroFormsMerger.java 2018-12-03 16:42:31.000000000 +0000 @@ -32,8 +32,9 @@ import static org.sejda.sambox.cos.COSName.BORDER; import static org.sejda.sambox.cos.COSName.BS; import static org.sejda.sambox.cos.COSName.C; +import static org.sejda.sambox.cos.COSName.CA; +import static org.sejda.sambox.cos.COSName.CA_NS; import static org.sejda.sambox.cos.COSName.CONTENTS; -import static org.sejda.sambox.cos.COSName.DA; import static org.sejda.sambox.cos.COSName.DATAPREP; import static org.sejda.sambox.cos.COSName.DS; import static org.sejda.sambox.cos.COSName.DV; @@ -43,6 +44,7 @@ import static org.sejda.sambox.cos.COSName.H; import static org.sejda.sambox.cos.COSName.I; import static org.sejda.sambox.cos.COSName.KIDS; +import static org.sejda.sambox.cos.COSName.LANG; import static org.sejda.sambox.cos.COSName.LOCK; import static org.sejda.sambox.cos.COSName.M; import static org.sejda.sambox.cos.COSName.MAX_LEN; @@ -81,12 +83,18 @@ import org.sejda.impl.sambox.util.AcroFormUtils; import org.sejda.impl.sambox.util.FontUtils; import org.sejda.model.pdf.form.AcroFormPolicy; +import org.sejda.sambox.cos.COSArray; import org.sejda.sambox.cos.COSName; import org.sejda.sambox.pdmodel.PDDocument; import org.sejda.sambox.pdmodel.font.PDFont; import org.sejda.sambox.pdmodel.interactive.annotation.PDAnnotation; import org.sejda.sambox.pdmodel.interactive.annotation.PDAnnotationWidget; -import org.sejda.sambox.pdmodel.interactive.form.*; +import org.sejda.sambox.pdmodel.interactive.form.PDAcroForm; +import org.sejda.sambox.pdmodel.interactive.form.PDField; +import org.sejda.sambox.pdmodel.interactive.form.PDFieldFactory; +import org.sejda.sambox.pdmodel.interactive.form.PDNonTerminalField; +import org.sejda.sambox.pdmodel.interactive.form.PDTerminalField; +import org.sejda.sambox.pdmodel.interactive.form.PDVariableText; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -98,11 +106,12 @@ public class AcroFormsMerger { private static final Logger LOG = LoggerFactory.getLogger(AcroFormsMerger.class); - private static final COSName[] FIELD_KEYS = { FT, PARENT, KIDS, T, TU, TM, FF, V, DV, DA, Q, DS, RV, OPT, MAX_LEN, - TI, I, LOCK, SV, DATAPREP }; + // when we separate field and widget items, we keep /AA in both, Acrobat Reader seems to work correctly only if that's the case + private static final COSName[] FIELD_KEYS = { FT, PARENT, KIDS, T, TU, TM, FF, V, DV, Q, DS, RV, OPT, MAX_LEN, TI, + I, LOCK, SV, DATAPREP }; private static final COSName[] WIDGET_KEYS = { TYPE, SUBTYPE, RECT, CONTENTS, P, NM, M, F, AP, AS, BORDER, C, - STRUCT_PARENT, OC, AF, BM, H, MK, A, BS, PMD }; + STRUCT_PARENT, OC, AF, CA, CA_NS, LANG, BM, H, MK, A, BS, PMD }; private AcroFormPolicy policy; private PDAcroForm form; @@ -215,7 +224,14 @@ * @param annotations */ private void removeFieldKeysFromWidgets(Collection annotations) { - annotations.stream().map(PDAnnotation::getCOSObject).forEach(a -> a.removeItems(FIELD_KEYS)); + annotations.stream().map(PDAnnotation::getCOSObject).forEach(a -> { + a.removeItems(FIELD_KEYS); + // if multiple kids we preserve their /DA even if Widget shouldn't have DA according to specs because if there is one Acrobat honors it. + // if only one kid then /DA is in the field. see for a live example PDFBOX-3687 + if (annotations.size() == 1) { + a.removeItem(COSName.DA); + } + }); LOG.trace("Removed fields keys from widget annotations"); } @@ -266,6 +282,21 @@ } } }); + + mergeCalculationOrder(originalForm, fieldsLookup); + } + + private void mergeCalculationOrder(PDAcroForm originalForm, LookupTable fieldsLookup) { + List co = originalForm.getCalculationOrder().stream().map(fieldsLookup::lookup) + .filter(Objects::nonNull).collect(toList()); + if (nonNull(co) && co.size() > 0) { + COSArray formCo = ofNullable(this.form.getCOSObject().getDictionaryObject(COSName.CO, COSArray.class)) + .orElseGet(COSArray::new); + for (PDField field : co) { + formCo.add(field); + } + this.form.setCalculationOrder(formCo); + } } /** @@ -286,7 +317,7 @@ for (PDField field : form.getFieldTree()) { fields.add(field); - if(field instanceof PDVariableText) { + if (field instanceof PDVariableText) { ensureValueCanBeDisplayed((PDVariableText) field); } } @@ -301,10 +332,11 @@ */ private void ensureValueCanBeDisplayed(PDVariableText field) { String value = field.getValueAsString(); - if(!FontUtils.canDisplay(value, field.getAppearanceFont())) { + if (!FontUtils.canDisplay(value, field.getAppearanceFont())) { PDFont fallbackFont = FontUtils.findFontFor(form.getDocument(), value); field.setAppearanceOverrideFont(fallbackFont); - LOG.debug("Form field can't render (in appearances) it's value '%', will use font % for better support", value, fallbackFont); + LOG.debug("Form field can't render (in appearances) it's value '{}', will use font {} for better support", + value, fallbackFont); } } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/AnnotationsDistiller.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/AnnotationsDistiller.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/AnnotationsDistiller.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/AnnotationsDistiller.java 2018-12-03 16:42:31.000000000 +0000 @@ -25,7 +25,7 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import org.sejda.common.LookupTable; @@ -77,9 +77,12 @@ LOG.debug("Filtering annotations"); for (PDPage page : relevantPages.keys()) { try { - Set keptAnnotations = new HashSet<>(); + Set keptAnnotations = new LinkedHashSet<>(); for (PDAnnotation annotation : page.getAnnotations()) { - if (!annotationsLookup.hasLookupFor(annotation)) { + PDAnnotation mapped = annotationsLookup.lookup(annotation); + if (nonNull(mapped)) { + keptAnnotations.add(mapped); + } else { if (annotation instanceof PDAnnotationLink) { processLinkAnnotation(relevantPages, keptAnnotations, (PDAnnotationLink) annotation); } else { diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/CatalogPageLabelsMerger.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/CatalogPageLabelsMerger.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/CatalogPageLabelsMerger.java 1970-01-01 00:00:00.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/CatalogPageLabelsMerger.java 2018-12-03 16:42:31.000000000 +0000 @@ -0,0 +1,120 @@ +/* + * Copyright 2018 by Eduard Weissmann (edi.weissmann@gmail.com). + * + * This file is part of the Sejda source code + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.sejda.impl.sambox.component; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.sejda.impl.sambox.util.PageLabelUtils; +import org.sejda.model.outline.CatalogPageLabelsPolicy; +import org.sejda.sambox.pdmodel.PDDocument; +import org.sejda.sambox.pdmodel.common.PDPageLabelRange; +import org.sejda.sambox.pdmodel.common.PDPageLabels; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Merges multiple /Catalog /PageLabels definitions, from multiple docs, into one. + */ +public class CatalogPageLabelsMerger { + + private static final Logger LOG = LoggerFactory.getLogger(CatalogPageLabelsMerger.class); + + private int totalPages = 0; + private PDPageLabels mergedPageLabels = new PDPageLabels(); + private final CatalogPageLabelsPolicy policy; + + public CatalogPageLabelsMerger(CatalogPageLabelsPolicy policy) { + this.policy = policy; + + if (policy == CatalogPageLabelsPolicy.DISCARD) { + mergedPageLabels = null; + } + } + + public void add(PDDocument doc, Set pagesToImport) { + if (policy == CatalogPageLabelsPolicy.DISCARD) { + return; + } + + try { + PDPageLabels docLabels = doc.getDocumentCatalog().getPageLabels(); + if (docLabels == null) { + docLabels = new PDPageLabels(); + } + + if (pagesToImport.size() < doc.getNumberOfPages()) { + // not all pages are being imported + // first update doc's page labels and remove pages not being imported + List pagesToRemove = computePagesToRemove(doc, pagesToImport); + docLabels = PageLabelUtils.removePages(docLabels, pagesToRemove, doc.getNumberOfPages()); + } + + for (Map.Entry entry : docLabels.getLabels().entrySet()) { + PDPageLabelRange range = entry.getValue(); + + // the page index in the original doc + int pageIndex = entry.getKey(); + // new page index: old page index + number of pages we merged so far (from other docs) + int newPageIndex = pageIndex + totalPages; + + // Hmm, handle start (logicalPage)? This would probably be wrong for Intro (romans) + Chapter 1 (arabic) + // but might be right for Chapter 1 (arabic) + Chapter 2 (arabic) + // not sure what to do, defer for later + // if(range.hasStart()) { + // range.setStart(range.getStart() + totalPages); + // } + + mergedPageLabels.setLabelItem(newPageIndex, range); + } + + } catch (Exception ex) { + LOG.warn("An error occurred retrieving /PageLabels of document {}, will not be merged", doc); + } finally { + // always advance the total number of pages + totalPages += pagesToImport.size(); + } + } + + private static List computePagesToRemove(PDDocument doc, Set pagesToImport) { + if (doc.getNumberOfPages() == pagesToImport.size()) { + return new ArrayList<>(); + } + + List pagesToRemove = new ArrayList<>(); + for (int i = 1; i <= doc.getNumberOfPages(); i++) { + if (!pagesToImport.contains(i)) { + pagesToRemove.add(i); + } + } + + return pagesToRemove; + } + + public boolean hasPageLabels() { + return mergedPageLabels != null; + } + + public PDPageLabels getMergedPageLabels() { + return mergedPageLabels; + } +} diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/ContentStreamProcessor.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/ContentStreamProcessor.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/ContentStreamProcessor.java 1970-01-01 00:00:00.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/ContentStreamProcessor.java 2018-12-03 16:42:31.000000000 +0000 @@ -0,0 +1,78 @@ +/* + * Created on 27 dic 2017 + * Copyright 2017 by Andrea Vacondio (andrea.vacondio@gmail.com). + * This file is part of Sejda. + * + * Sejda is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Sejda is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Sejda. If not, see . + */ +package org.sejda.impl.sambox.component; + +import static java.util.Optional.ofNullable; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +import org.sejda.sambox.contentstream.PDFStreamEngine; +import org.sejda.sambox.cos.COSNull; +import org.sejda.sambox.pdmodel.PDPage; +import org.sejda.sambox.pdmodel.interactive.annotation.PDAnnotation; +import org.sejda.sambox.pdmodel.interactive.annotation.PDAppearanceEntry; +import org.sejda.sambox.pdmodel.interactive.annotation.PDAppearanceStream; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Component that parses the page content steam and the page annotations appearance streams + * + * @author Andrea Vacondio + * + */ +public class ContentStreamProcessor extends PDFStreamEngine implements Consumer { + + private static final Logger LOG = LoggerFactory.getLogger(ContentStreamProcessor.class); + + private void processAnnotation(PDAnnotation annotation) throws IOException { + // we want to parse all states for all the appearance streams (N, D, R), not just the normal + List appreaceEntries = ofNullable(annotation.getAppearance()) + .map(d -> d.getCOSObject().getValues()).filter(Objects::nonNull).orElse(Collections.emptyList()) + .stream().map(a -> a.getCOSObject()).filter(a -> !(a instanceof COSNull)).map(PDAppearanceEntry::new) + .collect(Collectors.toList()); + for (PDAppearanceEntry entry : appreaceEntries) { + if (entry.isStream()) { + processStream(entry.getAppearanceStream()); + } else { + for (PDAppearanceStream stream : entry.getSubDictionary().values()) { + // TODO investigate this case with named dictionary + processStream(stream); + } + } + } + } + + @Override + public void accept(PDPage page) { + try { + this.processPage(page); + for (PDAnnotation annotation : page.getAnnotations()) { + processAnnotation(annotation); + } + } catch (IOException e) { + LOG.warn("Failed parse page, skipping and continuing with next.", e); + } + } +} diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/DefaultPdfSourceOpener.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/DefaultPdfSourceOpener.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/DefaultPdfSourceOpener.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/DefaultPdfSourceOpener.java 2018-12-03 16:42:31.000000000 +0000 @@ -38,7 +38,7 @@ */ public class DefaultPdfSourceOpener implements PdfSourceOpener { - private static final String WRONG_PWD_MESSAGE = "Unable to open the document due to a wrong password."; + private static final String WRONG_PWD_MESSAGE = "Unable to open '%s' due to a wrong password."; private static final String ERROR_MESSAGE = "An error occurred opening the source: %s."; @Override @@ -49,7 +49,7 @@ source.getPassword()); return new PDDocumentHandler(document); } catch (InvalidPasswordException ipe) { - throw new TaskWrongPasswordException(WRONG_PWD_MESSAGE, ipe); + throw new TaskWrongPasswordException(String.format(WRONG_PWD_MESSAGE, source.getSource()), ipe); } catch (IOException e) { throw new TaskIOException(String.format(ERROR_MESSAGE, source), e); } @@ -62,7 +62,7 @@ source.getPassword()); return new PDDocumentHandler(document); } catch (InvalidPasswordException ipe) { - throw new TaskWrongPasswordException(WRONG_PWD_MESSAGE, ipe); + throw new TaskWrongPasswordException(String.format(WRONG_PWD_MESSAGE, source.getSource().getName()), ipe); } catch (IOException e) { throw new TaskIOException(String.format(ERROR_MESSAGE, source), e); } @@ -75,7 +75,7 @@ source.getPassword()); return new PDDocumentHandler(document); } catch (InvalidPasswordException ipe) { - throw new TaskWrongPasswordException(WRONG_PWD_MESSAGE, ipe); + throw new TaskWrongPasswordException(String.format(WRONG_PWD_MESSAGE, source.getSource()), ipe); } catch (IOException e) { throw new TaskIOException(String.format(ERROR_MESSAGE, source), e); } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/excel/DataTable.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/excel/DataTable.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/excel/DataTable.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/excel/DataTable.java 2018-12-03 16:42:31.000000000 +0000 @@ -18,10 +18,7 @@ */ package org.sejda.impl.sambox.component.excel; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.TreeSet; +import java.util.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,6 +38,10 @@ this.pageNumbers.addAll(pageNumbers); } + public void addRow(String... dataRow) { + addRow(Arrays.asList(dataRow)); + } + public void addRow(List dataRow) { data.add(dataRow); } @@ -110,4 +111,58 @@ return sb.toString(); } + + public boolean hasData() { + return this.data.size() > 0; + } + + public int getColumnsCount() { + int result = 0; + for(List row: data) { + result = Math.max(row.size(), result); + } + + return result; + } + + public int getRowsCount() { + return data.size(); + } + + public List getColumn(int c) { + List result = new ArrayList<>(getRowsCount()); + for(List row: data) { + result.add(getOrEmpty(row, c)); + } + return result; + } + + public DataTable mergeColumns(int c1, int c2) { + DataTable result = new DataTable(getPageNumbers()); + for(List row: data) { + List newRow = new ArrayList<>(row.size() - 1); + for(int c = 0; c < row.size(); c++) { + if(c == c2) { + // noop, continue + } else if(c == c1) { + String newValue = new StringBuilder().append(getOrEmpty(row, c1)).append(" ") + .append(getOrEmpty(row, c2)).toString().trim(); + newRow.add(newValue); + } else { + newRow.add(getOrEmpty(row, c)); + + } + } + result.addRow(newRow); + } + return result; + } + + private static String getOrEmpty(List list, int index) { + if(list.size() <= index) { + return ""; + } else { + return list.get(index); + } + } } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/excel/DataTableUtils.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/excel/DataTableUtils.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/excel/DataTableUtils.java 1970-01-01 00:00:00.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/excel/DataTableUtils.java 2018-12-03 16:42:31.000000000 +0000 @@ -0,0 +1,113 @@ +/* + * Copyright 2018 by Eduard Weissmann (edi.weissmann@gmail.com). + * + * This file is part of the Sejda source code + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.sejda.impl.sambox.component.excel; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +public class DataTableUtils { + + private static final Logger LOG = LoggerFactory.getLogger(DataTableUtils.class); + + private DataTableUtils() { + } + + public static List mergeTablesSpanningMultiplePages(List dataTables) { + List results = new ArrayList<>(); + DataTable current = null; + + for (DataTable dt : dataTables) { + if (current != null) { + if (current.hasSameColumnsAs(dt)) { + current = current.mergeWith(dt); + } else { + results.add(current); + current = dt; + } + } else { + current = dt; + } + } + + if (current != null) { + results.add(current); + } + + return results; + } + + public static List mergeComplementaryColumns(List dataTables) { + List results = new ArrayList<>(); + for(DataTable dt: dataTables) { + results.add(mergeComplementaryColumns(dt)); + } + return results; + } + + static DataTable mergeComplementaryColumns(DataTable dataTable) { + DataTable result = dataTable; + boolean again = true; + while(again) { + again = false; + for (int c = 0; c < result.getColumnsCount() - 1; c++) { + List column1 = result.getColumn(c); + List column2 = result.getColumn(c + 1); + if (areComplementary(column1, column2)) { + LOG.debug("Merging complementary columns {} and {}", c, c + 1); + result = result.mergeColumns(c, c + 1); + again = true; + break; + } + } + } + return result; + } + + /** + * Complementary columns are columns which can be merged like a zipper: left column is missing values where right + * column has them, and vice versa. + * + * Eg: + * + * , Header + * A1, + * , B2 + * , B3 + * A4, + */ + static boolean areComplementary(List column1, List column2) { + if(column1.size() != column2.size()) { + return false; + } + + for(int i = 0; i < column1.size(); i++) { + String v1 = column1.get(i); + String v2 = column2.get(i); + + if(!v1.trim().isEmpty() && !v2.trim().isEmpty()) { + return false; + } + } + + return true; + } +} diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/FilenameFooterWriter.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/FilenameFooterWriter.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/FilenameFooterWriter.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/FilenameFooterWriter.java 2018-12-03 16:42:31.000000000 +0000 @@ -44,12 +44,14 @@ private boolean addFooter = false; private PageTextWriter writer; + private PDDocument document; private static PDFont FONT = PDType1Font.HELVETICA; private static double FONT_SIZE = 10; public FilenameFooterWriter(boolean addFooter, PDDocument document) { this.writer = new PageTextWriter(document); + this.document = document; this.addFooter = addFooter; } @@ -76,7 +78,11 @@ return writer.getStringWidth(text, FONT, (float) FONT_SIZE); } - private String truncateIfRequired(String text, double maxWidth) throws TaskIOException { + private String truncateIfRequired(String original, double maxWidth) throws TaskIOException { + // check if all characters are supported by the fonts available + // replace any bad characters with # + String text = FontUtils.replaceUnsupportedCharacters(original, document, "#"); + if (stringWidth(text) <= maxWidth) { return text; } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/image/ExifHelper.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/image/ExifHelper.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/image/ExifHelper.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/image/ExifHelper.java 2018-12-03 16:42:31.000000000 +0000 @@ -18,19 +18,19 @@ */ package org.sejda.impl.sambox.component.image; +import java.io.IOException; + +import org.sejda.model.input.FileSource; +import org.sejda.model.input.Source; +import org.sejda.model.input.SourceDispatcher; +import org.sejda.model.input.StreamSource; + import com.drew.imaging.ImageMetadataReader; import com.drew.imaging.ImageProcessingException; import com.drew.metadata.Directory; import com.drew.metadata.Metadata; import com.drew.metadata.MetadataException; import com.drew.metadata.exif.ExifIFD0Directory; -import org.sejda.model.exception.TaskIOException; -import org.sejda.model.input.FileSource; -import org.sejda.model.input.Source; -import org.sejda.model.input.SourceDispatcher; -import org.sejda.model.input.StreamSource; - -import java.io.IOException; /** * Reads exif orientation of an image and determines if the image should be rotated or not. @@ -42,7 +42,7 @@ try { return imageSource.dispatch(new SourceDispatcher() { @Override - public Integer dispatch(FileSource source) throws TaskIOException { + public Integer dispatch(FileSource source) { try { int orientation = readExifOrientation(ImageMetadataReader.readMetadata(source.getSource())); return getRotation(orientation); @@ -52,7 +52,7 @@ } @Override - public Integer dispatch(StreamSource source) throws TaskIOException { + public Integer dispatch(StreamSource source) { try { int orientation = readExifOrientation(ImageMetadataReader.readMetadata(source.getSource())); return getRotation(orientation); @@ -61,7 +61,7 @@ } } }); - } catch(Exception e) { + } catch(Throwable e) { return 0; } } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/optimization/ResourcesHitter.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/optimization/ResourcesHitter.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/optimization/ResourcesHitter.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/optimization/ResourcesHitter.java 2018-12-03 16:42:31.000000000 +0000 @@ -18,8 +18,6 @@ */ package org.sejda.impl.sambox.component.optimization; -import static java.util.Objects.isNull; -import static java.util.Optional.of; import static java.util.Optional.ofNullable; import java.io.IOException; @@ -28,29 +26,23 @@ import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.function.Consumer; import java.util.stream.Collectors; +import org.sejda.impl.sambox.component.ContentStreamProcessor; import org.sejda.impl.sambox.component.ReadOnlyFilteredCOSStream; -import org.sejda.sambox.contentstream.PDFStreamEngine; import org.sejda.sambox.contentstream.operator.MissingOperandException; import org.sejda.sambox.contentstream.operator.Operator; import org.sejda.sambox.contentstream.operator.OperatorProcessor; import org.sejda.sambox.cos.COSBase; import org.sejda.sambox.cos.COSDictionary; import org.sejda.sambox.cos.COSName; -import org.sejda.sambox.cos.COSNull; import org.sejda.sambox.cos.COSStream; import org.sejda.sambox.pdmodel.MissingResourceException; -import org.sejda.sambox.pdmodel.PDPage; import org.sejda.sambox.pdmodel.font.PDType3CharProc; import org.sejda.sambox.pdmodel.font.PDType3Font; import org.sejda.sambox.pdmodel.graphics.PDXObject; import org.sejda.sambox.pdmodel.graphics.form.PDFormXObject; import org.sejda.sambox.pdmodel.graphics.form.PDTransparencyGroup; -import org.sejda.sambox.pdmodel.interactive.annotation.PDAnnotation; -import org.sejda.sambox.pdmodel.interactive.annotation.PDAppearanceEntry; -import org.sejda.sambox.pdmodel.interactive.annotation.PDAppearanceStream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,16 +54,16 @@ * @author Andrea Vacondio * */ -public class ResourcesHitter extends PDFStreamEngine implements Consumer { +public class ResourcesHitter extends ContentStreamProcessor { private static final Logger LOG = LoggerFactory.getLogger(ResourcesHitter.class); public ResourcesHitter() { - addOperator(new XObjectOperator()); - addOperator(new FontHitterOperator()); + addOperator(new XObjectHitterOperator()); + addOperator(new FontsHitterOperator()); } - private class XObjectOperator extends OperatorProcessor { + public static class XObjectHitterOperator extends OperatorProcessor { @Override public void process(Operator operator, List operands) throws IOException { if (operands.isEmpty()) { @@ -115,7 +107,14 @@ } } - private class FontHitterOperator extends OperatorProcessor { + /** + * Tf operator that wraps a font dictionary with an {@link InUseFontDictionary} and puts it back to the resource dictionary so that we can later identify fonts that are + * actually used + * + * @author Andrea Vacondio + * + */ + public static class FontsHitterOperator extends OperatorProcessor { @Override public void process(Operator operator, List operands) throws IOException { if (operands.size() < 2) { @@ -128,23 +127,21 @@ .map(r -> r.getCOSObject().getDictionaryObject(COSName.FONT, COSDictionary.class)) .filter(Objects::nonNull); - COSBase existing = fonts.map(d -> d.getDictionaryObject(fontName)).orElseThrow( - () -> new MissingResourceException("Missing font resource: " + fontName.getName())); + COSDictionary fontDictionary = fonts.map(d -> d.getDictionaryObject(fontName, COSDictionary.class)) + .orElseThrow(() -> new MissingResourceException( + "Font resource '" + fontName.getName() + "' missing or unexpected type")); - if (!(existing instanceof InUseFontDictionary)) { - COSDictionary fontDictionary = of(existing).filter(e -> e instanceof COSDictionary) - .map(e -> (COSDictionary) e) - .orElseThrow(() -> new IllegalArgumentException("Font resource unexpected type")); + if (!(fontDictionary instanceof InUseFontDictionary)) { LOG.trace("Hit font with name {}", fontName.getName()); // we wrap the existing so we can identify it later as "in use" and already processed fonts.get().setItem(fontName, new InUseFontDictionary(fontDictionary)); - // type 3 fonts glyphs are content stream and they may refer to named resource. If the font resource dictionary is not present - // the page resource dictionary is used instead so we have to make sure those resource are hit - if (COSName.TYPE3.equals(fontDictionary.getCOSName(COSName.SUBTYPE)) - && isNull(fontDictionary.getItem(COSName.RESOURCES))) { - LOG.trace("Found type3 font with no resource dictionary {}", fontName.getName()); + // type 3 fonts glyphs are content stream and they may refer to named resource. + // If the font resource dictionary is not present the page resource dictionary is used instead AND + // we cannot exclude the font resource is an indirect ref to the page resource dictionary + // => so we have to make sure those resource are hit + if (COSName.TYPE3.equals(fontDictionary.getCOSName(COSName.SUBTYPE))) { PDType3Font font = new PDType3Font(fontDictionary); Collection glyphStreams = ofNullable( fontDictionary.getDictionaryObject(COSName.CHAR_PROCS, COSDictionary.class)) @@ -153,8 +150,9 @@ List pdStreams = glyphStreams.stream().map(COSBase::getCOSObject) .filter(s -> s instanceof COSStream).map(s -> (COSStream) s) .map(s -> new PDType3CharProc(font, s)).collect(Collectors.toList()); + LOG.trace("Found type3 font {} with {} streams to parse", fontName.getName(), pdStreams.size()); for (PDType3CharProc glyph : pdStreams) { - processStream(glyph); + getContext().processStream(glyph); } } } @@ -166,34 +164,4 @@ return "Tf"; } } - - private void processAnnotation(PDAnnotation annotation) throws IOException { - List appreaceEntries = ofNullable(annotation.getAppearance()) - .map(d -> d.getCOSObject().getValues()).filter(Objects::nonNull).orElse(Collections.emptyList()) - .stream().map(a -> a.getCOSObject()).filter(a -> !(a instanceof COSNull)).map(PDAppearanceEntry::new) - .collect(Collectors.toList()); - for (PDAppearanceEntry entry : appreaceEntries) { - if (entry.isStream()) { - processStream(entry.getAppearanceStream()); - } else { - for (PDAppearanceStream stream : entry.getSubDictionary().values()) { - // TODO investigate this case with named dictionary - processStream(stream); - } - } - } - } - - @Override - public void accept(PDPage page) { - try { - this.processPage(page); - for (PDAnnotation annotation : page.getAnnotations()) { - processAnnotation(annotation); - } - } catch (IOException e) { - LOG.warn("Failed parse page, skipping and continuing with next.", e); - } - } - } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/OutlineDistiller.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/OutlineDistiller.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/OutlineDistiller.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/OutlineDistiller.java 2018-12-03 16:42:31.000000000 +0000 @@ -75,9 +75,13 @@ if (node.hasChildren()) { final PDOutlineItem clone = new PDOutlineItem(); for (PDOutlineItem current : node.children()) { - cloneNode(current, pagesLookup).ifPresent(clonedChild -> { - clone.addLast(clonedChild); - }); + if(current.equals(node)) { + LOG.warn("Outline item has a child pointing to the parent, skipping at cloning"); + } else { + cloneNode(current, pagesLookup).ifPresent(clonedChild -> { + clone.addLast(clonedChild); + }); + } } Optional pageDestination = toPageDestination(node, document.getDocumentCatalog()); Optional destinationPage = pageDestination.map(PDPageDestination::getPage) diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PageImageWriter.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PageImageWriter.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PageImageWriter.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PageImageWriter.java 2018-12-03 16:42:31.000000000 +0000 @@ -105,7 +105,7 @@ public PDImageXObject dispatch(FileSource source) throws TaskIOException { try { return createFromFile(source.getSource().getPath()); - } catch (IOException e) { + } catch (Exception e) { throw new TaskIOException("An error occurred creating PDImageXObject from file source: " + imageSource.getName(), e); } } @@ -119,7 +119,7 @@ org.apache.commons.io.IOUtils.copyLarge(source.getSource(), fos); } return createFromFile(tmp.getPath()); - } catch (IOException e) { + } catch (Exception e) { throw new TaskIOException("An error occurred creating PDImageXObject from file source: " + imageSource.getName(), e); } } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PageTextWriter.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PageTextWriter.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PageTextWriter.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PageTextWriter.java 2018-12-03 16:42:31.000000000 +0000 @@ -253,4 +253,9 @@ transform.scale(1, -1); return transform.transform(position, null); } + + public static void writeHeader(PDDocument doc, PDPage page, String text) throws TaskIOException { + PageTextWriter writer = new PageTextWriter(doc); + writer.write(page, HorizontalAlign.CENTER, VerticalAlign.TOP, text, FontUtils.HELVETICA, 10d, Color.black); + } } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PDDocumentHandler.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PDDocumentHandler.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PDDocumentHandler.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PDDocumentHandler.java 2018-12-03 16:42:31.000000000 +0000 @@ -39,6 +39,10 @@ import org.sejda.model.exception.TaskException; import org.sejda.model.exception.TaskIOException; import org.sejda.model.image.ImageColorType; +import org.sejda.sambox.contentstream.PDContentStream; +import org.sejda.sambox.pdmodel.*; +import org.sejda.sambox.pdmodel.graphics.PDXObject; +import org.sejda.sambox.rendering.ImageType; import org.sejda.model.pdf.PdfVersion; import org.sejda.model.pdf.label.PdfPageLabel; import org.sejda.model.pdf.viewerpreference.PdfPageLayout; @@ -47,13 +51,6 @@ import org.sejda.sambox.cos.COSName; import org.sejda.sambox.encryption.StandardSecurity; import org.sejda.sambox.output.WriteOption; -import org.sejda.sambox.pdmodel.PDDocument; -import org.sejda.sambox.pdmodel.PDDocumentCatalog; -import org.sejda.sambox.pdmodel.PDDocumentInformation; -import org.sejda.sambox.pdmodel.PDPage; -import org.sejda.sambox.pdmodel.PDPageTree; -import org.sejda.sambox.pdmodel.PageLayout; -import org.sejda.sambox.pdmodel.PageMode; import org.sejda.sambox.pdmodel.common.PDRectangle; import org.sejda.sambox.pdmodel.font.PDFont; import org.sejda.sambox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline; @@ -357,13 +354,23 @@ public BufferedImage renderImage(int pageNumber, int dpi, ImageColorType type) throws TaskException { try { PDFRenderer pdfRenderer = new PDFRenderer(document); - return pdfRenderer.renderImageWithDPI(pageNumber - 1, dpi, type.getBufferedImageType()); + return pdfRenderer.renderImageWithDPI(pageNumber - 1, dpi, toSamboxImageType(type)); } catch (IOException ex) { LOG.error("Failed to render page " + pageNumber, ex); throw new TaskException("Failed to render page " + pageNumber, ex); } } + private ImageType toSamboxImageType(ImageColorType colorType) { + for(ImageType type: ImageType.values()) { + if(type.toBufferedImageType() == colorType.getBufferedImageType()) { + return type; + } + } + + throw new RuntimeException("Could not find a suitable image type for color type:" + colorType); + } + public void setDocumentOutline(PDDocumentOutline outline) { document.getDocumentCatalog().setDocumentOutline(outline); } @@ -413,17 +420,46 @@ return result; } - public PDFont findFont(String searchedName) { - for (PDPage page : document.getPages()) { - for (COSName fontName : page.getResources().getFontNames()) { - try { - PDFont font = page.getResources().getFont(fontName); - if (font != null && font.getName() != null && searchedName.equalsIgnoreCase(font.getName())) { + private PDFont findFont(PDResources resources, String searchedName, int level) { + // prevent stackoverflow by limiting how deep we go searching + if(level > 15) { + return null; + } + + for (COSName fontName : resources.getFontNames()) { + try { + PDFont font = resources.getFont(fontName); + if (font != null && font.getName() != null && searchedName.equalsIgnoreCase(font.getName())) { + return font; + } + } catch (Exception e) { + LOG.warn("Failure while searching font in resources", e); + } + } + + for (COSName objectName: resources.getXObjectNames()) { + try { + PDXObject pdxObject = resources.getXObject(objectName); + if(pdxObject instanceof PDContentStream) { + PDResources res = ((PDContentStream)pdxObject).getResources(); + PDFont font = findFont(res, searchedName, level + 1); + if(font != null) { return font; } - } catch (IOException e) { - LOG.warn("Failed to load font from resources: {}", fontName); } + } catch (Exception e) { + LOG.warn("Failure while searching font in XObject", e); + } + } + + return null; + } + + public PDFont findFont(String searchedName) { + for (PDPage page : document.getPages()) { + PDFont font = findFont(page.getResources(), searchedName, 1); + if(font != null) { + return font; } } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PdfScaler.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PdfScaler.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PdfScaler.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/PdfScaler.java 2018-12-03 16:42:31.000000000 +0000 @@ -82,12 +82,18 @@ public void scalePages(PDDocument doc, Iterable pages, PDRectangle targetBox) throws TaskIOException { for (PDPage page : pages) { PDRectangle cropBox = page.getCropBox().rotate(page.getRotation()); - double scale = getScalingFactor(targetBox, cropBox); + double scale = getScalingFactorMatchWidth(targetBox, cropBox); LOG.debug("Scaling page from {} to {}, factor of {}", cropBox, targetBox, scale); scale(doc, page, scale); } } + public void changePageSize(PDDocument doc, Iterable pages, PDRectangle desiredPageSize) throws TaskIOException { + for (PDPage page : pages) { + changePageSize(doc, page, desiredPageSize); + } + } + public void scale(PDDocument doc, double scale) throws TaskIOException { scale(doc, doc.getPages(), scale); } @@ -102,6 +108,54 @@ } } + public void changePageSize(PDDocument doc, PDPage page, PDRectangle desiredPageSize) throws TaskIOException { + PDRectangle currentPageSize = page.getCropBox().rotate(page.getRotation()); + LOG.debug("Current page size: {}", currentPageSize); + LOG.debug("Desired page size: {}", desiredPageSize); + + // first we scale the page to fit the new desired size + double scale = getScalingFactorMatchWidthOrHeight(desiredPageSize, currentPageSize); + doScale(doc, Collections.singletonList(page), scale); + + // if the aspect ratio for the current size and new desired size are the same -> we are done + // otherwise, we need to add margins to reach the desired size + + PDRectangle scaledPageSize = page.getCropBox().rotate(page.getRotation()); + //LOG.debug("Scaled by {}", scale); + + PDRectangle normalizedScaledPageSize = scaledPageSize; + boolean mismatchingOrientation = isLandscape(scaledPageSize) != isLandscape(desiredPageSize); + if(mismatchingOrientation) { + normalizedScaledPageSize = scaledPageSize.rotate(); + } + + //LOG.debug("Scaled page size: {}", normalizedScaledPageSize); + //LOG.debug("Desired page size: {}", desiredPageSize); + + double widthDiff = desiredPageSize.getWidth() - normalizedScaledPageSize.getWidth(); + double heightDiff = desiredPageSize.getHeight() - normalizedScaledPageSize.getHeight(); + + //LOG.debug("Differences are widthDiff: {} heightDiff: {}", widthDiff, heightDiff); + + if(widthDiff < 1) widthDiff = 0; + if(heightDiff < 1) heightDiff = 0; + + if(widthDiff > 0 || heightDiff > 0) { + // Margins are in inches, not points + double top = Margins.pointsToInches(heightDiff) / 2; + double left = Margins.pointsToInches(widthDiff) / 2; + Margins margins = new Margins(top, left, top, left); + if(mismatchingOrientation) { + margins = margins.rotate(); + } + margin(doc, Collections.singleton(page), margins); + } + + PDRectangle finalPageSize = page.getCropBox().rotate(page.getRotation()); + //LOG.debug("Final page size: {}", finalPageSize); + //LOG.debug("Desired page size: {}", desiredPageSize); + } + private void doScale(PDDocument doc, Iterable pages, double scale) throws TaskIOException { Set processedAnnots = new HashSet<>(); for (PDPage page : pages) { @@ -167,14 +221,10 @@ /** * Adds the given margin all around the pages - * - * @param doc - * @param pages - * @param margin - * @throws TaskIOException */ public static void margin(PDDocument doc, Iterable pages, Margins margins) throws TaskIOException { if (nonNull(margins)) { + Set processedAnnots = new HashSet<>(); for (PDPage page : pages) { try (PDPageContentStream contentStream = new PDPageContentStream(doc, page, AppendMode.PREPEND, true)) { page.setCropBox(addMargins(page.getCropBox().rotate(page.getRotation()), margins) @@ -193,6 +243,8 @@ // realign the content contentStream.transform(matrix); + transformAnnotations(page, matrix, processedAnnots); + } catch (IOException e) { throw new TaskIOException("An error occurred adding margins to the page.", e); } @@ -252,7 +304,11 @@ page.getMediaBox().transform(getMatrix(scale, page.getMediaBox(), page.getMediaBox())).getBounds2D())); } - private double getScalingFactor(PDRectangle targetBox, PDRectangle pageBox) { + /** + * Calculates the factor that pageBox can be scaled with to fit targetBox's **width** without overflow. + * For some pages this could mean that pageBox scaled will be taller than the targetBox. + */ + private double getScalingFactorMatchWidth(PDRectangle targetBox, PDRectangle pageBox) { // if both target and page boxes have same orientation (landscape, portrait) // the scaling factor is targetWidth / pageWidth if(isLandscape(targetBox) == isLandscape(pageBox)) { @@ -264,6 +320,27 @@ } } + /** + * Calculates the factor that pageBox can be scaled with to fit targetBox without overflow. + * Ensures both height and width will not overflow targetBox. + */ + private double getScalingFactorMatchWidthOrHeight(PDRectangle targetBox, PDRectangle pageBox) { + // if the boxes have different orientations + // we want to normalize first rotating the target 90 and then calculate scaling factors + // so landscape is scaled to a landscape + PDRectangle normalizedOrientationTargetBox = targetBox; + if(isLandscape(targetBox) != isLandscape(pageBox)) { + normalizedOrientationTargetBox = targetBox.rotate(); + } + + float widthFactor = normalizedOrientationTargetBox.getWidth() / pageBox.getWidth(); + float heightFactor = normalizedOrientationTargetBox.getHeight() / pageBox.getHeight(); + + float factor = Math.min(widthFactor, heightFactor); + //LOG.debug("Factor: {} for normalizedOrientationTargetBox: {} pageBox: {}", factor, normalizedOrientationTargetBox, pageBox); + return factor; + } + private boolean isLandscape(PDRectangle box) { return box.getWidth() > box.getHeight(); } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/ReadOnlyFilteredCOSStream.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/ReadOnlyFilteredCOSStream.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/ReadOnlyFilteredCOSStream.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/ReadOnlyFilteredCOSStream.java 2018-12-03 16:42:31.000000000 +0000 @@ -116,8 +116,8 @@ } @Override - public void addCompression() { - // do nothing, it's already supposed to be compressed + public boolean addCompression() { + return false; } @Override diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/TableOfContentsCreator.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/TableOfContentsCreator.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/TableOfContentsCreator.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/component/TableOfContentsCreator.java 2018-12-03 16:42:31.000000000 +0000 @@ -45,7 +45,7 @@ import org.sejda.sambox.pdmodel.font.PDType1Font; import org.sejda.sambox.pdmodel.interactive.annotation.PDAnnotation; import org.sejda.sambox.pdmodel.interactive.annotation.PDAnnotationLink; -import org.sejda.sambox.pdmodel.interactive.documentnavigation.destination.PDPageFitWidthDestination; +import org.sejda.sambox.pdmodel.interactive.documentnavigation.destination.PDPageXYZDestination; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,7 +101,7 @@ } private PDAnnotationLink linkAnnotationFor(PDPage importedPage) { - PDPageFitWidthDestination pageDest = new PDPageFitWidthDestination(); + PDPageXYZDestination pageDest = new PDPageXYZDestination(); pageDest.setPage(importedPage); PDAnnotationLink link = new PDAnnotationLink(); link.setDestination(pageDest); @@ -113,19 +113,26 @@ * Generates a ToC and prepend it to the given document */ public void addToC() throws TaskException { + addToC(0); + } + + /** + * Generates a ToC and inserts it in the doc at before the given page number + */ + public void addToC(int beforePageNumber) throws TaskException { try { PDPageTree pagesTree = document.getPages(); ofNullable(generateToC()).filter(l -> !l.isEmpty()).ifPresent(t -> { int toCPagesCount = t.size(); t.descendingIterator().forEachRemaining(p -> { if (pagesTree.getCount() > 0) { - pagesTree.insertBefore(p, pagesTree.get(0)); + pagesTree.insertBefore(p, pagesTree.get(beforePageNumber)); } else { pagesTree.add(p); } }); if (params.isBlankPageIfOdd() && toCPagesCount % 2 == 1) { - PDPage lastTocPage = pagesTree.get(toCPagesCount - 1); + PDPage lastTocPage = pagesTree.get(beforePageNumber + toCPagesCount - 1); PDPage blankPage = new PDPage(lastTocPage.getMediaBox()); pagesTree.insertAfter(blankPage, lastTocPage); } @@ -181,8 +188,9 @@ } } - String pageString = SEPARATOR + Long.toString(i.page + tocNumberOfPages); - float x2 = getPageNumberX(separatorWidth, i.page + tocNumberOfPages); + long pageNumber = i.page + tocNumberOfPages; + String pageString = SEPARATOR + Long.toString(pageNumber); + float x2 = getPageNumberX(separatorWidth, pageNumber); writeText(page, pageString, x2, y); // make the item clickable and link to the page number diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/MergeTask.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/MergeTask.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/MergeTask.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/MergeTask.java 2018-12-03 16:42:31.000000000 +0000 @@ -34,14 +34,7 @@ import org.sejda.core.support.io.IOUtils; import org.sejda.core.support.io.OutputWriters; import org.sejda.core.support.io.SingleOutputWriter; -import org.sejda.impl.sambox.component.AcroFormsMerger; -import org.sejda.impl.sambox.component.AnnotationsDistiller; -import org.sejda.impl.sambox.component.DefaultPdfSourceOpener; -import org.sejda.impl.sambox.component.FilenameFooterWriter; -import org.sejda.impl.sambox.component.OutlineMerger; -import org.sejda.impl.sambox.component.PDDocumentHandler; -import org.sejda.impl.sambox.component.PdfScaler; -import org.sejda.impl.sambox.component.TableOfContentsCreator; +import org.sejda.impl.sambox.component.*; import org.sejda.impl.sambox.component.image.ImagesToPdfDocumentConverter; import org.sejda.model.exception.TaskException; import org.sejda.model.input.*; @@ -73,11 +66,14 @@ private PDDocumentHandler destinationDocument; private Queue toClose = new LinkedList<>(); private OutlineMerger outlineMerger; + private CatalogPageLabelsMerger catalogPageLabelsMerger; private AcroFormsMerger acroFormsMerger; private TableOfContentsCreator tocCreator; private FilenameFooterWriter footerWriter; private PDRectangle currentPageSize = PDRectangle.A4; private long pagesCounter = 0; + private long inputsCounter = 0; + private int firstInputNumberOfPages = 0; @Override public void before(MergeParameters parameters, TaskExecutionContext executionContext) throws TaskException { @@ -104,21 +100,28 @@ this.tocCreator = new TableOfContentsCreator(parameters, this.destinationDocument.getUnderlyingPDDocument()); this.footerWriter = new FilenameFooterWriter(parameters.isFilenameFooter(), this.destinationDocument.getUnderlyingPDDocument()); + this.catalogPageLabelsMerger = new CatalogPageLabelsMerger(parameters.getCatalogPageLabelsPolicy()); convertImageMergeInputToPdf(parameters); for (PdfMergeInput input : parameters.getPdfInputList()) { + inputsCounter++; LOG.debug("Opening {}", input.getSource()); PDDocumentHandler sourceDocumentHandler = input.getSource().open(sourceOpener); toClose.add(sourceDocumentHandler); + if(inputsCounter == 1) { + firstInputNumberOfPages = sourceDocumentHandler.getNumberOfPages(); + } + LOG.debug("Adding pages"); LookupTable pagesLookup = new LookupTable<>(); - long relativeCounter = 0; - for (Integer currentPage : input.getPages(sourceDocumentHandler.getNumberOfPages())) { + long relativePagesCounter = 0; + Set pagesToImport = input.getPages(sourceDocumentHandler.getNumberOfPages()); + for (Integer currentPage : pagesToImport) { executionContext().assertTaskNotCancelled(); pagesCounter++; - relativeCounter++; + relativePagesCounter++; try { PDPage page = sourceDocumentHandler.getPage(currentPage); // we keep rotation into account @@ -129,20 +132,29 @@ pagesLookup.addLookupEntry(page, importedPage); String sourceBaseName = FilenameUtils.getBaseName(input.getSource().getName()); + // processing the first page of the source - if (tocCreator.shouldGenerateToC() && relativeCounter == 1) { - tocCreator.pageSizeIfNotSet(currentPageSize); - if (ToCPolicy.DOC_TITLES == parameters.getTableOfContentsPolicy()) { - sourceBaseName = ofNullable( - sourceDocumentHandler.getUnderlyingPDDocument().getDocumentInformation()) - .map(i -> i.getTitle()).filter(StringUtils::isNotBlank) - .orElse(sourceBaseName); + if (tocCreator.shouldGenerateToC() && relativePagesCounter == 1) { + if(parameters.isFirstInputCoverTitle() && inputsCounter == 1) { + // skip the cover/title document, don't add it to the ToC + } else { + tocCreator.pageSizeIfNotSet(currentPageSize); + if (ToCPolicy.DOC_TITLES == parameters.getTableOfContentsPolicy()) { + sourceBaseName = ofNullable( + sourceDocumentHandler.getUnderlyingPDDocument().getDocumentInformation()) + .map(i -> i.getTitle()).filter(StringUtils::isNotBlank) + .orElse(sourceBaseName); + } + tocCreator.appendItem(sourceBaseName, pagesCounter, importedPage); } - tocCreator.appendItem(sourceBaseName, pagesCounter, importedPage); } - this.footerWriter.addFooter(importedPage, sourceBaseName, - pagesCounter + tocCreator.tocNumberOfPages()); + long currentPageNumber = pagesCounter + tocCreator.tocNumberOfPages(); + if(parameters.isFirstInputCoverTitle() && inputsCounter == 1) { + // the toc will be added after the cover/title pages + currentPageNumber = pagesCounter; + } + this.footerWriter.addFooter(importedPage, sourceBaseName, currentPageNumber); LOG.trace("Added imported page"); } catch (PageNotFoundException e) { executionContext().assertTaskIsLenient(e); @@ -150,7 +162,7 @@ .taskWarning(String.format("Page %d was skipped, could not be processed", currentPage), e); } } - relativeCounter = 0; + relativePagesCounter = 0; outlineMerger.updateOutline(sourceDocumentHandler.getUnderlyingPDDocument(), input.getSource().getName(), pagesLookup); @@ -166,6 +178,9 @@ if (parameters.isBlankPageIfOdd()) { ofNullable(destinationDocument.addBlankPageIfOdd(currentPageSize)).ifPresent(p -> pagesCounter++); } + + catalogPageLabelsMerger.add(sourceDocumentHandler.getUnderlyingPDDocument(), pagesToImport); + notifyEvent(executionContext().notifiableTaskMetadata()).stepsCompleted(++currentStep).outOf(totalSteps); } @@ -187,7 +202,17 @@ if (tocCreator.hasToc()) { LOG.debug("Adding generated ToC"); - tocCreator.addToC(); + int beforePageNumber = 0; + if(parameters.isFirstInputCoverTitle()) { + // add ToC after the cover/title pages + beforePageNumber = firstInputNumberOfPages; + } + tocCreator.addToC(beforePageNumber); + } + + if(catalogPageLabelsMerger.hasPageLabels()) { + LOG.debug("Adding merged /Catalog /PageLabels"); + destinationDocument.getUnderlyingPDDocument().getDocumentCatalog().setPageLabels(catalogPageLabelsMerger.getMergedPageLabels()); } destinationDocument.savePDDocument(tmpFile); diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/PdfToExcelTask.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/PdfToExcelTask.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/PdfToExcelTask.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/PdfToExcelTask.java 2018-12-03 16:42:31.000000000 +0000 @@ -18,6 +18,8 @@ */ package org.sejda.impl.sambox; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVPrinter; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; @@ -28,6 +30,7 @@ import org.sejda.impl.sambox.component.PDDocumentHandler; import org.sejda.impl.sambox.component.PdfTextExtractorByArea; import org.sejda.impl.sambox.component.excel.DataTable; +import org.sejda.impl.sambox.component.excel.DataTableUtils; import org.sejda.model.TopLeftRectangularBox; import org.sejda.model.exception.TaskException; import org.sejda.model.input.PdfSource; @@ -41,9 +44,7 @@ import org.slf4j.LoggerFactory; import java.awt.*; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; +import java.io.*; import java.util.ArrayList; import java.util.List; @@ -72,6 +73,7 @@ @Override public void execute(PdfToExcelParameters parameters) throws TaskException { int currentStep = 0; + int fileOutputNumber = 0; int totalSteps = parameters.getSourceList().size(); for (PdfSource source : parameters.getSourceList()) { executionContext().assertTaskNotCancelled(); @@ -81,9 +83,6 @@ LOG.debug("Opening {}", source); sourceDocumentHandler = source.open(documentLoader); - File tmpFile = createTemporaryBuffer(".xlsx"); - LOG.debug("Created output temporary buffer {}", tmpFile); - this.destinationDocument = new PDDocumentHandler(); destinationDocument.setVersionOnPDDocument(parameters.getVersion()); destinationDocument.initialiseBasedOn(sourceDocumentHandler.getUnderlyingPDDocument()); @@ -130,7 +129,9 @@ dataTable.addRow(rowData); rowData = new ArrayList<>(); } + } + if (dataTable.hasData()) { all.add(dataTable); } @@ -139,13 +140,29 @@ } if (parameters.isMergeTablesSpanningMultiplePages()) { - all = mergeTablesSpanningMultiplePages(all); + all = DataTableUtils.mergeTablesSpanningMultiplePages(all); } - writeExcelFile(all, tmpFile); - String outName = nameGenerator(parameters.getOutputPrefix()) - .generate(nameRequest("xlsx").originalName(source.getName()).fileNumber(currentStep)); - outputWriter.addOutput(file(tmpFile).name(outName)); + all = DataTableUtils.mergeComplementaryColumns(all); + + if (parameters.isCsvFormat()) { + List tmpFiles = writeCsvFiles(all); + for (File tmpFile : tmpFiles) { + fileOutputNumber++; + String outName = nameGenerator(parameters.getOutputPrefix()) + .generate(nameRequest("csv").originalName(source.getName()).fileNumber(fileOutputNumber)); + + outputWriter.addOutput(file(tmpFile).name(outName)); + } + + } else { + File tmpFile = writeExcelFile(all); + fileOutputNumber++; + + String outName = nameGenerator(parameters.getOutputPrefix()) + .generate(nameRequest("xlsx").originalName(source.getName()).fileNumber(fileOutputNumber)); + outputWriter.addOutput(file(tmpFile).name(outName)); + } notifyEvent(executionContext().notifiableTaskMetadata()).stepsCompleted(currentStep).outOf(totalSteps); @@ -156,45 +173,61 @@ LOG.debug("Input documents cropped and written to {}", parameters.getOutput()); } - private List mergeTablesSpanningMultiplePages(List dataTables) { - List results = new ArrayList<>(); - DataTable current = null; - - for (DataTable dt : dataTables) { - if (current != null) { - if (current.hasSameColumnsAs(dt)) { - current = current.mergeWith(dt); - } else { - results.add(current); - current = dt; - } - } else { - current = dt; - } - } - if (current != null) { - results.add(current); + + private List writeCsvFiles(List dataTables) throws TaskException { + List results = new ArrayList<>(); + + for (int t = 0; t < dataTables.size(); t++) { +// LOG.debug("Writing data table " + t); + DataTable dataTable = dataTables.get(t); + results.add(writeCsvFile(dataTable)); } return results; } - private void writeExcelFile(List dataTables, File tmpFile) throws TaskException { - LOG.debug("Writing data to excel file"); + private File writeCsvFile(DataTable dataTable) throws TaskException { + File tmpFile = createTemporaryBuffer(".csv"); + LOG.debug("Created output temporary buffer {}, writing csv data", tmpFile); + + long start = System.currentTimeMillis(); + + List> data = dataTable.getData(); + try (CSVPrinter csvPrinter = new CSVPrinter(new BufferedWriter(new FileWriter(tmpFile)), CSVFormat.DEFAULT)) { + for (int r = 0; r < data.size(); r++) { + List dataRow = data.get(r); +// LOG.debug("Writing row " + r + " of " + dataRow.size() + " values"); + csvPrinter.printRecord(dataRow); + } + + csvPrinter.flush(); + + LOG.debug("Done writing data to csv file, took {} seconds", (System.currentTimeMillis() - start) / 1000); + } catch (IOException ioe) { + throw new TaskException("Could not save .csv file", ioe); + } + + return tmpFile; + } + + private File writeExcelFile(List dataTables) throws TaskException { + File tmpFile = createTemporaryBuffer(".xlsx"); + LOG.debug("Created output temporary buffer {}, writing excel data", tmpFile); + long start = System.currentTimeMillis(); Workbook wb = new XSSFWorkbook(); try (FileOutputStream fileOut = new FileOutputStream(tmpFile)) { for (int t = 0; t < dataTables.size(); t++) { - LOG.debug("Writing data table " + t); +// LOG.debug("Writing data table " + t); DataTable dataTable = dataTables.get(t); List> data = dataTable.getData(); Sheet sheet = wb.createSheet(String.format("Table %d (%s)", t + 1, dataTable.getPagesAsString())); for (int r = 0; r < data.size(); r++) { List dataRow = data.get(r); - LOG.debug("Writing row " + r + " of " + dataRow.size() + " values"); +// LOG.debug("Writing row " + r + " of " + dataRow.size() + " values"); Row row = sheet.createRow(r); @@ -210,6 +243,7 @@ } wb.write(fileOut); LOG.debug("Done writing data to excel file, took {} seconds", (System.currentTimeMillis() - start) / 1000); + return tmpFile; } catch (IOException ioe) { throw new TaskException("Could not save .xlsx file", ioe); } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/ResizePagesTask.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/ResizePagesTask.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/ResizePagesTask.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/ResizePagesTask.java 2018-12-03 16:42:31.000000000 +0000 @@ -101,20 +101,21 @@ } } - + // we either apply margins or change the page size if (nonNull(parameters.getMargins())) { + LOG.debug("Adding margins of {} (inches) to {} pages", parameters.getMargins(), pages.size()); PdfScaler.margin(documentHandler.getUnderlyingPDDocument(), pages, parameters.getMargins()); - } + } else { - PageSize pageSize = parameters.getPageSize(); - if(pageSize != null) { - PDRectangle targetBox = new PDRectangle(pageSize.getWidth(), pageSize.getHeight()); + PageSize pageSize = parameters.getPageSize(); + if (pageSize != null) { + PDRectangle desiredPageSize = new PDRectangle(pageSize.getWidth(), pageSize.getHeight()); + LOG.debug("Resizing {} pages to match {}", pages.size(), desiredPageSize); - LOG.debug("Resizing {} pages to match {}", pages.size(), targetBox); - - PdfScaler scaler = new PdfScaler(ScaleType.PAGE); - scaler.scalePages(documentHandler.getUnderlyingPDDocument(), pages, targetBox); + PdfScaler scaler = new PdfScaler(ScaleType.PAGE); + scaler.changePageSize(documentHandler.getUnderlyingPDDocument(), pages, desiredPageSize); + } } documentHandler.setVersionOnPDDocument(parameters.getVersion()); diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/util/FontUtils.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/util/FontUtils.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/util/FontUtils.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/util/FontUtils.java 2018-12-03 16:42:31.000000000 +0000 @@ -27,7 +27,15 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.regex.Pattern; import org.apache.commons.io.IOUtils; @@ -108,7 +116,8 @@ if (!canDisplay(text, font)) { PDFont fallback = findFontFor(document, text); String fallbackName = fallback == null ? null : fallback.getName(); - LOG.debug("Text '{}' cannot be written with font {}, using fallback {}", text, font.getName(), fallbackName); + LOG.debug("Text '{}' cannot be written with font {}, using fallback {}", text, font.getName(), + fallbackName); return fallback; } return font; @@ -396,10 +405,11 @@ } /** - * Wraps the given text on multiple lines, if it does not fit within the given maxWidth - * It will try to determine if all text can be written with given font and find a fallback for parts that are not supported. + * Wraps the given text on multiple lines, if it does not fit within the given maxWidth It will try to determine if all text can be written with given font and find a fallback + * for parts that are not supported. */ - public static List wrapLines(String rawLabel, PDFont font, float fontSize, double maxWidth, PDDocument document) throws TaskIOException { + public static List wrapLines(String rawLabel, PDFont font, float fontSize, double maxWidth, + PDDocument document) throws TaskIOException { List lines = new ArrayList<>(); String label = org.sejda.core.support.util.StringUtils.normalizeWhitespace(rawLabel); @@ -415,7 +425,7 @@ String resolvedLabel = stringAndFont.getText(); String[] words = visualToLogical(resolvedLabel).split("(?<=\\b)"); - for(String word: words) { + for (String word : words) { double textWidth = getSimpleStringWidth(word, resolvedFont, fontSize); if (textWidth > maxWidth || word.length() > 10) { @@ -456,7 +466,7 @@ } } - if(!currentString.toString().isEmpty()) { + if (!currentString.toString().isEmpty()) { lines.add(currentString.toString().trim()); } @@ -464,8 +474,7 @@ } /** - * Calculates the width of the string using the given font. - * Does not try to find out if the text can actually be written with the given font and find fallback + * Calculates the width of the string using the given font. Does not try to find out if the text can actually be written with the given font and find fallback */ public static double getSimpleStringWidth(String text, PDFont font, double fontSize) throws IOException { double textWidth = font.getStringWidth(text) / 1000 * fontSize; @@ -483,8 +492,7 @@ /** * Supports writing labels which require multiple fonts (eg: mixing thai and english words) Returns a list of text with associated font. */ - public static List resolveFonts(String label, PDFont font, PDDocument document) - throws TaskIOException { + public static List resolveFonts(String label, PDFont font, PDDocument document) { PDFont currentFont = font; StringBuilder currentString = new StringBuilder(); @@ -508,7 +516,7 @@ f = FontUtils.getStandardType1Font(StandardType1Font.HELVETICA); } - if(f != currentFont) { + if (f != currentFont) { // end current string, before space if (currentString.length() > 0) { result.add(new TextWithFont(currentString.toString(), currentFont)); @@ -533,16 +541,20 @@ } } + result.add(new TextWithFont(currentString.toString(), currentFont)); + for (TextWithFont each : result) { LOG.trace("Will write '{}' with {}", each.getText(), each.getFont()); } - result.add(new TextWithFont(currentString.toString(), currentFont)); - return result; } - public static String removeUnsupportedCharacters(String text, PDDocument doc) throws TaskIOException { + public static String removeUnsupportedCharacters(String text, PDDocument doc) { + return replaceUnsupportedCharacters(text, doc, ""); + } + + public static String replaceUnsupportedCharacters(String text, PDDocument doc, String replacement) { List resolved = resolveFonts(text, HELVETICA, doc); Set unsupported = new HashSet<>(); resolved.forEach(tf -> { @@ -553,7 +565,7 @@ String result = text; for (String s : unsupported) { - result = result.replaceAll(Pattern.quote(s), ""); + result = result.replaceAll(Pattern.quote(s), replacement); } return result; diff -Nru libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/util/PageLabelUtils.java libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/util/PageLabelUtils.java --- libsejda-java-3.2.38/sejda-sambox/src/main/java/org/sejda/impl/sambox/util/PageLabelUtils.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/main/java/org/sejda/impl/sambox/util/PageLabelUtils.java 2018-12-03 16:42:31.000000000 +0000 @@ -18,9 +18,7 @@ */ package org.sejda.impl.sambox.util; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; import org.sejda.model.pdf.label.PdfLabelNumberingStyle; @@ -81,4 +79,49 @@ } return retLabels; } + + // TODO: understand how logicalPage should be affected + public static PDPageLabels removePages(PDPageLabels pageLabels, List pagesToRemove, int totalPages) { + Map labels = new TreeMap<>(pageLabels.getLabels()); + + List pagesToRemoveSortedLastFirst = new ArrayList<>(pagesToRemove); + pagesToRemoveSortedLastFirst.sort(Collections.reverseOrder()); + + // go backwards from last to first + // why? otherwise pagesToRemove would need to be shifted -1 after each page removal + for(int pageToRemove : pagesToRemoveSortedLastFirst) { + // make a copy to avoid ConcurrentModificationException + Map updatedLabels = new TreeMap<>(); + // pagesToRemove are 1-based, indices 0-based + int pageIndex = pageToRemove - 1; + + for(int key : labels.keySet()) { + if(key <= pageIndex) { + // just copy over as is + updatedLabels.put(key, labels.get(key)); + } else if(key > pageIndex) { + // shift index - 1 + int prevKey = key - 1; + if (prevKey >= 0) { + updatedLabels.put(prevKey, labels.get(key)); + } + } + } + + // overwrite + labels = updatedLabels; + } + + // calculate the new page total + int newTotalPages = totalPages - pagesToRemove.size(); + + PDPageLabels result = new PDPageLabels(); + for(int index: labels.keySet()) { + // exclude the last label range, if index is larger that new total page num + if(index < newTotalPages) { + result.setLabelItem(index, labels.get(index)); + } + } + return result; + } } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/AcroFormsMergerTest.java libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/AcroFormsMergerTest.java --- libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/AcroFormsMergerTest.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/AcroFormsMergerTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -113,6 +113,8 @@ assertNotNull(document.getDocumentCatalog().getAcroForm()); victim.mergeForm(document.getDocumentCatalog().getAcroForm(), annotationsLookup); assertFalse(victim.getForm().getFields().isEmpty()); + assertTrue(victim.getForm().getCalculationOrder().isEmpty()); + assertNull(victim.getForm().getCOSObject().getItem(COSName.CO)); } @Test @@ -227,7 +229,7 @@ assertEquals(4, victim.getForm().getFields().size()); for (PDField field : victim.getForm().getFieldTree()) { if (field.isTerminal()) { - //System.out.println(field.getFullyQualifiedName() + " " + field.getWidgets().size() + " " + field.getClass().getSimpleName()); + // System.out.println(field.getFullyQualifiedName() + " " + field.getWidgets().size() + " " + field.getClass().getSimpleName()); if (field.getFullyQualifiedName().startsWith("Choice_Caption_")) { assertEquals(4, field.getWidgets().size()); } else { @@ -299,4 +301,46 @@ assertTrue(form.isSignaturesExist()); } + @Test + public void calculationOrderIsKept() throws IOException { + PDDocument destination = new PDDocument(); + AcroFormsMerger victim = new AcroFormsMerger(AcroFormPolicy.MERGE, destination); + assertNotNull(document.getDocumentCatalog().getAcroForm()); + mapping.clear(); + + try (PDDocument anotherDoc = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom( + getClass().getClassLoader().getResourceAsStream("pdf/forms/test_form_with_calc.pdf")))) { + mapping.addLookupEntry(anotherDoc.getPage(0), new PDPage()); + annotationsLookup = new AnnotationsDistiller(anotherDoc).retainRelevantAnnotations(mapping); + victim.mergeForm(anotherDoc.getDocumentCatalog().getAcroForm(), annotationsLookup); + + assertEquals(2, victim.getForm().getFields().size()); + assertEquals(1, victim.getForm().getCalculationOrder().size()); + } + } + + @Test + public void mergeRnamingSameCalculationOrderIsMerged() throws IOException { + PDDocument destination = new PDDocument(); + AcroFormsMerger victim = new AcroFormsMerger(AcroFormPolicy.MERGE_RENAMING_EXISTING_FIELDS, destination); + assertNotNull(document.getDocumentCatalog().getAcroForm()); + assertNotNull(document.getDocumentCatalog().getAcroForm()); + mapping.clear(); + + PDDocument doc = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom( + getClass().getClassLoader().getResourceAsStream("pdf/forms/test_form_with_calc.pdf"))); + mapping.addLookupEntry(doc.getPage(0), new PDPage()); + annotationsLookup = new AnnotationsDistiller(doc).retainRelevantAnnotations(mapping); + victim.mergeForm(doc.getDocumentCatalog().getAcroForm(), annotationsLookup); + mapping.clear(); + + PDDocument anotherDoc = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom( + getClass().getClassLoader().getResourceAsStream("pdf/forms/test_form_with_calc.pdf"))); + mapping.addLookupEntry(anotherDoc.getPage(0), new PDPage()); + annotationsLookup = new AnnotationsDistiller(anotherDoc).retainRelevantAnnotations(mapping); + victim.mergeForm(anotherDoc.getDocumentCatalog().getAcroForm(), annotationsLookup); + + assertEquals(4, victim.getForm().getFields().size()); + assertEquals(2, victim.getForm().getCalculationOrder().size()); + } } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/AnnotationsDistillerTest.java libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/AnnotationsDistillerTest.java --- libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/AnnotationsDistillerTest.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/AnnotationsDistillerTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -21,10 +21,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.sejda.sambox.pdmodel.interactive.annotation.PDAnnotationSquareCircle.SUB_TYPE_SQUARE; import java.io.IOException; import java.util.Arrays; @@ -32,6 +34,7 @@ import java.util.List; import java.util.stream.Collectors; +import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; import org.sejda.common.LookupTable; @@ -44,9 +47,11 @@ import org.sejda.sambox.pdmodel.interactive.action.PDActionGoTo; import org.sejda.sambox.pdmodel.interactive.action.PDActionJavaScript; import org.sejda.sambox.pdmodel.interactive.annotation.PDAnnotation; +import org.sejda.sambox.pdmodel.interactive.annotation.PDAnnotationLine; import org.sejda.sambox.pdmodel.interactive.annotation.PDAnnotationLink; import org.sejda.sambox.pdmodel.interactive.annotation.PDAnnotationMarkup; import org.sejda.sambox.pdmodel.interactive.annotation.PDAnnotationPopup; +import org.sejda.sambox.pdmodel.interactive.annotation.PDAnnotationSquareCircle; import org.sejda.sambox.pdmodel.interactive.annotation.PDAnnotationText; import org.sejda.sambox.pdmodel.interactive.documentnavigation.destination.PDNamedDestination; import org.sejda.sambox.pdmodel.interactive.documentnavigation.destination.PDPageDestination; @@ -76,6 +81,33 @@ } @Test + public void orderIsKept() { + PDAnnotationSquareCircle one = new PDAnnotationSquareCircle(SUB_TYPE_SQUARE); + one.setAnnotationName("one"); + PDAnnotationText two = new PDAnnotationText(); + two.setAnnotationName("two"); + PDAnnotationLine three = new PDAnnotationLine(); + three.setAnnotationName("three"); + PDAnnotationSquareCircle four = new PDAnnotationSquareCircle(SUB_TYPE_SQUARE); + four.setAnnotationName("four"); + PDAnnotationLine five = new PDAnnotationLine(); + five.setAnnotationName("five"); + PDAnnotationSquareCircle six = new PDAnnotationSquareCircle(SUB_TYPE_SQUARE); + six.setAnnotationName("six"); + + List annotations = Arrays.asList(one, two, three, four, five, six); + oldPage.setAnnotations(annotations); + PDDocument doc = new PDDocument(); + doc.addPage(oldPage); + new AnnotationsDistiller(doc).retainRelevantAnnotations(lookup); + List annots = newPage.getAnnotations(); + assertEquals(6, annots.size()); + assertThat(annots.stream().map(PDAnnotation::getAnnotationName).collect(Collectors.toList()), + Matchers.contains(annotations.stream().map(PDAnnotation::getAnnotationName) + .map(d -> Matchers.equalTo(d)).collect(Collectors.toList()))); + } + + @Test public void noLinks() { List annotations = Arrays.asList(new PDAnnotationText()); oldPage.setAnnotations(annotations); @@ -344,6 +376,26 @@ assertEquals(1, parent.size()); assertTrue(annotations.contains(parent.get(0))); } + } + @Test + public void pagesHaveTheSameAnnotations() { + PDAnnotationLink annotation = new PDAnnotationLink(); + PDPageDestination dest = new PDPageFitDestination(); + dest.setPage(oldPage); + annotation.setDestination(dest); + + PDPage secondOld = new PDPage(); + PDPage secondNew = new PDPage(); + lookup.addLookupEntry(secondOld, secondNew); + List annotations = Arrays.asList(annotation, new PDAnnotationText()); + oldPage.setAnnotations(annotations); + secondOld.setAnnotations(annotations); + PDDocument doc = new PDDocument(); + doc.addPage(oldPage); + doc.addPage(secondOld); + new AnnotationsDistiller(doc).retainRelevantAnnotations(lookup); + assertEquals(oldPage.getAnnotations().size(), newPage.getAnnotations().size()); + assertEquals(secondOld.getAnnotations().size(), secondNew.getAnnotations().size()); } } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/CatalogPageLabelsMergerTest.java libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/CatalogPageLabelsMergerTest.java --- libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/CatalogPageLabelsMergerTest.java 1970-01-01 00:00:00.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/CatalogPageLabelsMergerTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -0,0 +1,205 @@ +/* + * Copyright 2018 by Eduard Weissmann (edi.weissmann@gmail.com). + * + * This file is part of the Sejda source code + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.sejda.impl.sambox.component; + +import org.junit.Test; +import org.sejda.model.outline.CatalogPageLabelsPolicy; +import org.sejda.sambox.pdmodel.PDDocument; +import org.sejda.sambox.pdmodel.common.PDPageLabels; + +import java.util.*; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.sejda.core.service.TestUtils.*; + +public class CatalogPageLabelsMergerTest { + + @Test + public void policyDiscard() { + PDDocument doc1 = new DocBuilder().withPages(2).get(); + PDDocument doc2 = new DocBuilder().withPages(3).get(); + + CatalogPageLabelsMerger merger = new CatalogPageLabelsMerger(CatalogPageLabelsPolicy.DISCARD); + merger.add(doc1, all(doc1)); + merger.add(doc2, all(doc2)); + + assertFalse(merger.hasPageLabels()); + assertNull(merger.getMergedPageLabels()); + } + + @Test + public void mergeDocsWithoutLabels() { + PDDocument doc1 = new DocBuilder().withPages(2).get(); + PDDocument doc2 = new DocBuilder().withPages(3).get(); + + CatalogPageLabelsMerger merger = new CatalogPageLabelsMerger(CatalogPageLabelsPolicy.RETAIN); + merger.add(doc1, all(doc1)); + merger.add(doc2, all(doc2)); + + PDPageLabels mergedLabels = merger.getMergedPageLabels(); + + assertPageLabelIndexesAre(mergedLabels, 0, 2); + assertPageLabelRangeIsDefault(mergedLabels, 0); + assertPageLabelRangeIsDefault(mergedLabels, 2); + } + + @Test + public void mergeDocsWithLabels() { + PDDocument doc1 = new DocBuilder().withPages(2) + .withPageLabelRange(0, "r") + .get(); + PDDocument doc2 = new DocBuilder().withPages(4) + .withPageLabelRange(0, "D") + .get(); + + CatalogPageLabelsMerger merger = new CatalogPageLabelsMerger(CatalogPageLabelsPolicy.RETAIN); + merger.add(doc1, all(doc1)); + merger.add(doc2, all(doc2)); + + PDPageLabels mergedLabels = merger.getMergedPageLabels(); + assertPageLabelIndexesAre(mergedLabels, 0, 2); + assertPageLabelRangeIs(mergedLabels, 0,"r"); + assertPageLabelRangeIs(mergedLabels, 2, "D"); + } + + @Test + public void mergeDocsOneWithLabels() { + PDDocument doc1 = new DocBuilder().withPages(2).get(); + PDDocument doc2 = new DocBuilder().withPages(4) + .withPageLabelRange(0, "r") + .withPageLabelRange(2, "D") + .get(); + + CatalogPageLabelsMerger merger = new CatalogPageLabelsMerger(CatalogPageLabelsPolicy.RETAIN); + merger.add(doc1, all(doc1)); + merger.add(doc2, all(doc2)); + + PDPageLabels mergedLabels = merger.getMergedPageLabels(); + assertPageLabelIndexesAre(mergedLabels, 0, 2, 4); + assertPageLabelRangeIsDefault(mergedLabels, 0); + assertPageLabelRangeIs(mergedLabels, 2, "r"); + assertPageLabelRangeIs(mergedLabels, 4, "D"); + } + + @Test + public void mergeDocsSubsetOfPagesFromDoc1() { + PDDocument doc1 = new DocBuilder().withPages(5) + .withPageLabelRange(0, "r") + .get(); + PDDocument doc2 = new DocBuilder().withPages(4) + .withPageLabelRange(0, "D") + .get(); + + CatalogPageLabelsMerger merger = new CatalogPageLabelsMerger(CatalogPageLabelsPolicy.RETAIN); + merger.add(doc1, allBut(doc1, 2)); + merger.add(doc2, all(doc2)); + + PDPageLabels mergedLabels = merger.getMergedPageLabels(); + + assertPageLabelIndexesAre(mergedLabels, 0, 4); + assertPageLabelRangeIs(mergedLabels, 0, "r"); + assertPageLabelRangeIs(mergedLabels, 4, "D"); + } + + @Test + public void mergeDocsSubsetOfPagesFromDoc2() { + PDDocument doc1 = new DocBuilder().withPages(5) + .withPageLabelRange(0, "r") + .get(); + PDDocument doc2 = new DocBuilder().withPages(4) + .withPageLabelRange(0, "D") + .get(); + + CatalogPageLabelsMerger merger = new CatalogPageLabelsMerger(CatalogPageLabelsPolicy.RETAIN); + merger.add(doc1, all(doc1)); + merger.add(doc2, allBut(doc2, 1, 2, 3)); + + PDPageLabels mergedLabels = merger.getMergedPageLabels(); + + assertPageLabelIndexesAre(mergedLabels, 0, 5); + assertPageLabelRangeIs(mergedLabels, 0, "r"); + assertPageLabelRangeIs(mergedLabels, 5, "D"); + } + + @Test + public void mergeDocsSubsetOfPagesFromDocWithComplexLabeling() { + PDDocument doc1 = new DocBuilder().withPages(2) + .withPageLabelRange(0, "r") + .get(); + PDDocument doc2 = new DocBuilder().withPages(5) + .withPageLabelRange(0, "D") // these are getting all removed + .withPageLabelRange(3, "A") + .get(); + + CatalogPageLabelsMerger merger = new CatalogPageLabelsMerger(CatalogPageLabelsPolicy.RETAIN); + merger.add(doc1, all(doc1)); + merger.add(doc2, allBut(doc2, 1, 2, 3)); + + PDPageLabels mergedLabels = merger.getMergedPageLabels(); + + assertPageLabelIndexesAre(mergedLabels, 0, 2); + assertPageLabelRangeIs(mergedLabels, 0, "r"); + assertPageLabelRangeIs(mergedLabels, 2, "A"); + } + + @Test + public void mergeDocsSubsetOfPagesFromDocWithComplexLabeling2() { + PDDocument doc1 = new DocBuilder().withPages(2) + .withPageLabelRange(0, "r") + .get(); + PDDocument doc2 = new DocBuilder().withPages(5) + .withPageLabelRange(0, "D") // these are getting partly removed + .withPageLabelRange(3, "A") + .get(); + + CatalogPageLabelsMerger merger = new CatalogPageLabelsMerger(CatalogPageLabelsPolicy.RETAIN); + merger.add(doc1, all(doc1)); + merger.add(doc2, allBut(doc2, 2, 3)); + + PDPageLabels mergedLabels = merger.getMergedPageLabels(); + + assertPageLabelIndexesAre(mergedLabels, 0, 2, 3); + assertPageLabelRangeIs(mergedLabels, 0, "r"); + assertPageLabelRangeIs(mergedLabels, 2, "D"); + assertPageLabelRangeIs(mergedLabels, 3, "A"); + } + + private static Set all(PDDocument doc) { + Set pages = new TreeSet<>(); + for(int i = 1; i <= doc.getNumberOfPages(); i++){ + pages.add(i); + } + return pages; + } + + private static Set allBut(PDDocument doc, Integer... exceptPages) { + Set pages = new TreeSet<>(); + Collection except = Arrays.asList(exceptPages); + + for(int i = 1; i <= doc.getNumberOfPages(); i++){ + if(except.contains(i)) { + continue; + } + pages.add(i); + } + return pages; + } +} \ No newline at end of file diff -Nru libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/DefaultPdfSourceOpenerTest.java libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/DefaultPdfSourceOpenerTest.java --- libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/DefaultPdfSourceOpenerTest.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/DefaultPdfSourceOpenerTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -18,13 +18,19 @@ */ package org.sejda.impl.sambox.component; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; import org.junit.Test; +import org.sejda.core.support.io.IOUtils; import org.sejda.model.exception.TaskIOException; import org.sejda.model.exception.TaskWrongPasswordException; +import org.sejda.model.input.PdfFileSource; import org.sejda.model.input.PdfStreamSource; +import java.io.*; + /** * @author Andrea Vacondio * @@ -51,10 +57,25 @@ "test"))); } - @Test(expected = TaskWrongPasswordException.class) - public void openDocumentWrongPassword() throws TaskIOException { - new DefaultPdfSourceOpener().open(PdfStreamSource.newInstanceNoPassword( - getClass().getClassLoader().getResourceAsStream("pdf/encrypted_AES128_user_pwd.pdf"), "my source")); + @Test + public void openDocumentWrongPassword() throws TaskIOException, IOException { + try { + File tmp = IOUtils.createTemporaryBufferWithName("dumbo.pdf"); + OutputStream out = new FileOutputStream(tmp); + InputStream in = getClass().getClassLoader().getResourceAsStream("pdf/encrypted_AES128_user_pwd.pdf"); + + try { + org.apache.commons.io.IOUtils.copy(in, out); + } finally { + org.apache.commons.io.IOUtils.closeQuietly(out); + org.apache.commons.io.IOUtils.closeQuietly(in); + } + + new DefaultPdfSourceOpener().open(PdfFileSource.newInstanceWithPassword(tmp, "my source")); + fail("Exception expected"); + } catch (TaskWrongPasswordException e) { + assertEquals("Unable to open 'dumbo.pdf' due to a wrong password.", e.getMessage()); + } } @Test(expected = TaskIOException.class) diff -Nru libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/DocBuilder.java libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/DocBuilder.java --- libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/DocBuilder.java 1970-01-01 00:00:00.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/DocBuilder.java 2018-12-03 16:42:31.000000000 +0000 @@ -0,0 +1,72 @@ +/* + * Copyright 2018 by Eduard Weissmann (edi.weissmann@gmail.com). + * + * This file is part of the Sejda source code + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.sejda.impl.sambox.component; + +import org.sejda.sambox.pdmodel.PDDocument; +import org.sejda.sambox.pdmodel.PDPage; +import org.sejda.sambox.pdmodel.common.PDPageLabelRange; +import org.sejda.sambox.pdmodel.common.PDPageLabels; + +import java.io.IOException; + +/** + * Build a doc on the fly (and test with it) + */ +public class DocBuilder { + private PDDocument doc = new PDDocument(); + + public PDDocument get() { + return doc; + } + + public DocBuilder withPages(int numOfPages) { + for(int i = 0; i < numOfPages; i++) { + PDPage page = new PDPage(); + doc.addPage(page); + } + + return this; + } + + public DocBuilder withPageLabelRange(int index, String style) { + return withPageLabelRange(index, style, null, null); + } + + public DocBuilder withPageLabelRange(int index, String style, String prefix) { + return withPageLabelRange(index, style, prefix, null); + } + + + public DocBuilder withPageLabelRange(int index, String style, String prefix, Integer start) { + try { + PDPageLabels labels = doc.getDocumentCatalog().getPageLabels(); + if (labels == null) { + labels = new PDPageLabels(); + } + + labels.setLabelItem(index, new PDPageLabelRange(style, prefix, start)); + doc.getDocumentCatalog().setPageLabels(labels); + return this; + + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff -Nru libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/excel/DataTableTest.java libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/excel/DataTableTest.java --- libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/excel/DataTableTest.java 1970-01-01 00:00:00.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/excel/DataTableTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -0,0 +1,87 @@ +/* + * Copyright 2018 by Eduard Weissmann (edi.weissmann@gmail.com). + * + * This file is part of the Sejda source code + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.sejda.impl.sambox.component.excel; + +import org.junit.Test; + +import java.util.Arrays; + +import static org.junit.Assert.*; +import static org.hamcrest.CoreMatchers.*; + +public class DataTableTest { + + private static final DataTable dt = new DataTable(1); + static { + dt.addRow("Vehicle type", "", "Brand"); + dt.addRow("Car", "Audi", ""); + dt.addRow("Car", "Mercedes", ""); + dt.addRow("Truck", "Volvo", ""); + dt.addRow("Truck", "DAF", ""); + } + + @Test + public void getColumnCount() { + assertThat(dt.getColumnsCount(), is(3)); + } + + @Test + public void getColumn() { + assertThat(dt.getColumn(1), is(Arrays.asList("", "Audi", "Mercedes", "Volvo", "DAF"))); + } + + @Test + public void getRowsCount() { + assertThat(dt.getRowsCount(), is(5)); + } + + @Test + public void mergeColumns() { + DataTable merged = dt.mergeColumns(1, 2); + assertThat(merged.getRowsCount(), is(5)); + assertThat(merged.getColumnsCount(), is(2)); + assertThat(merged.getColumn(0), is(Arrays.asList("Vehicle type", "Car", "Car", "Truck", "Truck"))); + assertThat(merged.getColumn(1), is(Arrays.asList("Brand", "Audi", "Mercedes", "Volvo", "DAF"))); + } + + @Test + public void getColumnWhenUnevenRowLength() { + DataTable dt = new DataTable(1); + dt.addRow("HeadA", "HeadB", "HeadC"); + dt.addRow("A1", "B1", "C1"); + dt.addRow("A2", "B2"); + dt.addRow("A3"); + dt.addRow("A4", "B4", "C4"); + assertThat(dt.getColumn(1), is(Arrays.asList("HeadB", "B1", "B2", "", "B4"))); + assertThat(dt.getColumn(2), is(Arrays.asList("HeadC", "C1", "", "", "C4"))); + } + + @Test + public void mergeColumnsWhenUnevenRowLength() { + DataTable dt = new DataTable(1); + dt.addRow("HeadA", "HeadB", "HeadC"); + dt.addRow("A1", "B1", "C1"); + dt.addRow("A2", "B2"); + dt.addRow("A3"); + dt.addRow("A4", "B4", "C4"); + + DataTable merged = dt.mergeColumns(1, 2); + assertThat(merged.getColumn(1), is(Arrays.asList("HeadB HeadC", "B1 C1", "B2", "", "B4 C4"))); + } +} \ No newline at end of file diff -Nru libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/excel/DataTableUtilsTest.java libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/excel/DataTableUtilsTest.java --- libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/excel/DataTableUtilsTest.java 1970-01-01 00:00:00.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/excel/DataTableUtilsTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -0,0 +1,76 @@ +/* + * Copyright 2018 by Eduard Weissmann (edi.weissmann@gmail.com). + * + * This file is part of the Sejda source code + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.sejda.impl.sambox.component.excel; + +import org.junit.Test; + +import java.util.Arrays; + +import static org.junit.Assert.*; +import static org.hamcrest.CoreMatchers.*; + +public class DataTableUtilsTest { + + @Test + public void mergeComplementaryColumns() { + DataTable dt = new DataTable(1); + dt.addRow("Vehicle type", "", "Brand"); + dt.addRow("Car", "Audi", ""); + dt.addRow("Car", "Mercedes", ""); + dt.addRow("Truck", "Volvo", ""); + dt.addRow("Truck", "DAF", ""); + + DataTable merged = DataTableUtils.mergeComplementaryColumns(dt); + assertThat(merged.getColumnsCount(), is(2)); + assertThat(merged.getRowsCount(), is(5)); + assertThat(merged.getColumn(0), is(Arrays.asList("Vehicle type", "Car", "Car", "Truck", "Truck"))); + assertThat(merged.getColumn(1), is(Arrays.asList("Brand", "Audi", "Mercedes", "Volvo", "DAF"))); + + assertThat(dt.getColumnsCount(), is(3)); + } + + @Test + public void areComplementary() { + assertThat(DataTableUtils.areComplementary( + Arrays.asList("Header", "", " "), + Arrays.asList("", "Value1", "Value2") + ), is(true)); + + assertThat(DataTableUtils.areComplementary( + Arrays.asList("Header1", "ValueA", ""), + Arrays.asList("Header2", "", "Value2") + ), is(false)); + } + + @Test + public void mergeComplementaryColumnsThatNeedsMultiplePasses() { + DataTable dt = new DataTable(1); + dt.addRow("H1", " ", "H2", " ", "H4"); + dt.addRow("A1", "B1", " ", "D1", " "); + dt.addRow("A2", "B2", " ", " ", "E2"); + dt.addRow("A3"); + + DataTable merged = DataTableUtils.mergeComplementaryColumns(dt); + assertThat(merged.getColumnsCount(), is(3)); + assertThat(merged.getColumn(0), is(Arrays.asList("H1", "A1", "A2", "A3"))); + assertThat(merged.getColumn(1), is(Arrays.asList("H2", "B1", "B2", ""))); + assertThat(merged.getColumn(2), is(Arrays.asList("H4", "D1", "E2", ""))); + + } +} \ No newline at end of file diff -Nru libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/FilenameFooterWriterTest.java libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/FilenameFooterWriterTest.java --- libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/FilenameFooterWriterTest.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/FilenameFooterWriterTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -24,6 +24,7 @@ import org.junit.Test; import org.sejda.model.exception.TaskException; +import org.sejda.model.exception.TaskIOException; import org.sejda.sambox.pdmodel.PDDocument; import org.sejda.sambox.pdmodel.PDPage; @@ -50,7 +51,7 @@ PDPage page = new PDPage(); doc.addPage(page); new FilenameFooterWriter(true, doc).addFooter(page, "My very long title that will not fit on the page and needs to be truncated so that it will not overflow and cover the page number and generally look not so nice", 20); - assertThat(new PdfTextExtractorByArea().extractFooterText(page).trim(), is("My very long title that will not fit on the page and needs to be truncated so that it will not overflow and cover the page num 20")); + assertPageFooterText(page,"My very long title that will not fit on the page and needs to be truncated so that it will not overflow and cover the page num 20"); } @Test @@ -61,4 +62,20 @@ new FilenameFooterWriter(false, doc).addFooter(page, "My Footer", 20); assertThat(new PdfTextExtractorByArea().extractFooterText(page).trim(), isEmptyOrNullString()); } + + @Test + public void write_filename_contains_bad_characters() throws TaskException { + PDDocument doc = new PDDocument(); + PDPage page = new PDPage(); + doc.addPage(page); + String withBadCharacter = "This is a bad \uF021character"; + FilenameFooterWriter writer = new FilenameFooterWriter(true, doc); + writer.addFooter(page, withBadCharacter, 1); + + assertPageFooterText(page, "This is a bad #character 1"); + } + + private void assertPageFooterText(PDPage page, String expectedText) throws TaskIOException { + assertThat(new PdfTextExtractorByArea().extractFooterText(page).trim(), is(expectedText)); + } } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/PDDocumentHandlerTest.java libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/PDDocumentHandlerTest.java --- libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/PDDocumentHandlerTest.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/PDDocumentHandlerTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -30,6 +30,7 @@ import org.sejda.sambox.pdmodel.PageLayout; import org.sejda.sambox.pdmodel.PageMode; import org.sejda.sambox.pdmodel.common.PDRectangle; +import org.sejda.sambox.pdmodel.font.PDFont; import org.sejda.sambox.pdmodel.interactive.pagenavigation.PDThreadBead; import static org.junit.Assert.*; @@ -107,6 +108,13 @@ } } + @Test + public void findFont_xform_resources() throws IOException { + PDDocument doc = testDoc("pdf/2-up_fonts.pdf"); + PDFont font = new PDDocumentHandler(doc).findFont("arialmt"); + assertNotNull(font); + } + private PDDocument testDoc(String resourceName) throws IOException { return PDFParser.parse(SeekableSources .inMemorySeekableSourceFrom(getClass().getClassLoader().getResourceAsStream(resourceName))); diff -Nru libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/TableOfContentsCreatorTest.java libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/TableOfContentsCreatorTest.java --- libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/TableOfContentsCreatorTest.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/component/TableOfContentsCreatorTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -19,6 +19,7 @@ package org.sejda.impl.sambox.component; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; @@ -45,6 +46,7 @@ /** * @author Andrea Vacondio + * @author Edi Weissmann * */ public class TableOfContentsCreatorTest { @@ -309,7 +311,7 @@ victim.pageSizeIfNotSet(PDRectangle.A4); victim.addToC(); - TestUtils.assertPageTextExact(doc.getPage(0), + TestUtils.assertPageTextExactLines(doc.getPage(0), "This is item 1 1\n" + "This is item 2 that has a very long name and should not be\n" + "truncated so that the version is visible at the end v7.pdf 10\n" + @@ -364,7 +366,7 @@ victim.pageSizeIfNotSet(PDRectangle.A4); victim.addToC(); - TestUtils.assertPageTextExact(doc.getPage(0), + TestUtils.assertPageTextExactLines(doc.getPage(0), "This_is_a_file_that_has_a_very_long_name_and_should_not_be_tr-\n" + "uncated_so_that_the_version_is_visible_at_the_end_v7.pdf 10\n"); } @@ -379,7 +381,37 @@ victim.pageSizeIfNotSet(PDRectangle.A4); victim.addToC(); - // the junk letters are because of 'No Unicode mapping for CID+64 (64) in font NotoSansArmenian-Regular' - TestUtils.assertPageTextExact(doc.getPage(0), "Item multiple fonts @1E5P7F 10\n"); + TestUtils.assertPageTextExactLines(doc.getPage(0), "Item multiple fonts հայերէն 10\n"); + } + + @Test + public void test_Toc_Add_At_Specific_Page() throws TaskException { + MergeParameters params = new MergeParameters(); + params.setTableOfContentsPolicy(ToCPolicy.FILE_NAMES); + params.setBlankPageIfOdd(true); + + PDDocument doc = new PDDocument(); + PDPage pageA = new PDPage(), pageB = new PDPage(); + doc.addPage(pageA); doc.addPage(pageB); + + PageTextWriter.writeHeader(doc, pageA, "PageA"); + PageTextWriter.writeHeader(doc, pageB, "PageB"); + + TableOfContentsCreator victim = new TableOfContentsCreator(params, doc); + victim.appendItem("This is an item", 2, pageB); + victim.pageSizeIfNotSet(PDRectangle.A4); + + victim.addToC(1); + + assertThat(doc.getNumberOfPages(), is(4)); // one extra for blank page if odd + + // blank page pageA + TestUtils.assertPageTextExactLines(doc.getPage(0), "PageA\n"); + // toc + TestUtils.assertPageTextExactLines(doc.getPage(1), "This is an item 2\n"); + // extra blank page if odd + TestUtils.assertPageTextExactLines(doc.getPage(2), ""); + // blank page pageB + TestUtils.assertPageTextExactLines(doc.getPage(3), "PageB\n"); } } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/MergeSamboxTaskTest.java libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/MergeSamboxTaskTest.java --- libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/MergeSamboxTaskTest.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/MergeSamboxTaskTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -20,11 +20,9 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; +import static org.sejda.core.service.TestUtils.assertPageLabelIndexesAre; +import static org.sejda.core.service.TestUtils.assertPageLabelRangeIs; import java.awt.Rectangle; import java.io.IOException; @@ -39,10 +37,12 @@ import org.sejda.core.TestListenerFactory.TestListenerFailed; import org.sejda.core.notification.context.ThreadLocalNotificationContext; import org.sejda.core.service.BaseTaskTest; +import org.sejda.impl.sambox.component.DocBuilder; import org.sejda.impl.sambox.component.PdfTextExtractorByArea; import org.sejda.model.exception.TaskIOException; import org.sejda.model.input.ImageMergeInput; import org.sejda.model.input.PdfMergeInput; +import org.sejda.model.outline.CatalogPageLabelsPolicy; import org.sejda.model.outline.OutlinePolicy; import org.sejda.model.output.ExistingOutputPolicy; import org.sejda.model.parameter.MergeParameters; @@ -53,6 +53,8 @@ import org.sejda.model.toc.ToCPolicy; import org.sejda.sambox.pdmodel.PDDocument; import org.sejda.sambox.pdmodel.PDPage; +import org.sejda.sambox.pdmodel.common.PDPageLabelRange; +import org.sejda.sambox.pdmodel.common.PDPageLabels; import org.sejda.sambox.pdmodel.common.PDRectangle; import org.sejda.sambox.text.PDFTextStripperByArea; @@ -571,6 +573,101 @@ }); } + @Test + public void mergeKeepingPageLabels() throws IOException { + MergeParameters parameters = new MergeParameters(); + parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); + PDDocument doc1 = new DocBuilder().withPages(2) + .withPageLabelRange(0, "r", "Intro:") + .get(); + PDDocument doc2 = new DocBuilder().withPages(3) + .withPageLabelRange(0, "D") + .get(); + parameters.addInput(new PdfMergeInput(customInput(doc1, "doc1.pdf"))); + parameters.addInput(new PdfMergeInput(customInput(doc2, "doc2.pdf"))); + parameters.setCatalogPageLabelsPolicy(CatalogPageLabelsPolicy.RETAIN); + testContext.pdfOutputTo(parameters); + execute(parameters); + + testContext.assertTaskCompleted(); + testContext.assertPages(5).forEachPdfOutput(d -> { + try { + PDPageLabels mergedLabels = d.getDocumentCatalog().getPageLabels(); + assertPageLabelIndexesAre(mergedLabels, 0, 2); + assertPageLabelRangeIs(mergedLabels, 0, new PDPageLabelRange("r", "Intro:", null)); + assertPageLabelRangeIs(mergedLabels, 2, new PDPageLabelRange("D", null, null)); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } + + @Test + public void mergeDiscardingPageLabels() throws IOException { + MergeParameters parameters = new MergeParameters(); + parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); + + PDDocument doc1 = new DocBuilder().withPages(2) + .withPageLabelRange(0, "r", "Intro:") + .get(); + PDDocument doc2 = new DocBuilder().withPages(3) + .withPageLabelRange(0, "D") + .get(); + + parameters.addInput(new PdfMergeInput(customInput(doc1, "doc1.pdf"))); + parameters.addInput(new PdfMergeInput(customInput(doc2, "doc2.pdf"))); + + parameters.setCatalogPageLabelsPolicy(CatalogPageLabelsPolicy.DISCARD); + + testContext.pdfOutputTo(parameters); + execute(parameters); + + testContext.assertTaskCompleted(); + testContext.assertPages(5).forEachPdfOutput(d -> { + try { + assertNull(d.getDocumentCatalog().getPageLabels()); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } + + @Test + public void withCoverPage() throws IOException { + List inputs = new ArrayList(); + inputs.add(new PdfMergeInput(shortInput())); // 4 pages, cover/title doc + inputs.add(new PdfMergeInput(regularInput())); // 11 pages + inputs.add(new PdfMergeInput(customInput("pdf/attachments_as_annots.pdf", "attachments_as_annots.pdf"))); // 3 pages + + MergeParameters parameters = setUpParameters(inputs); + parameters.setTableOfContentsPolicy(ToCPolicy.FILE_NAMES); + parameters.setFilenameFooter(true); + parameters.setFirstInputCoverTitle(true); + + testContext.pdfOutputTo(parameters); + + execute(parameters); + + testContext.assertTaskCompleted(); + testContext.assertPages(19).forEachPdfOutput(d -> { + // first 4 pages are the cover/title doc - short input + assertFooterHasText(d.getPage(0), "short-test-file 1"); + assertFooterHasText(d.getPage(3), "short-test-file 4"); + + // the TOC + assertFooterHasText(d.getPage(4), ""); + assertPageTextExactLines(d.getPage(4), "test-file 6\nattachments_as_annots 17\n"); + + // next 11 pages are the regular input + assertFooterHasText(d.getPage(5), "test-file 6"); + assertFooterHasText(d.getPage(15), "test-file 16"); + + // next 3 pages are attachments_as_annots doc + assertFooterHasText(d.getPage(16), "attachments_as_annots 17"); + assertFooterHasText(d.getPage(18), "attachments_as_annots 19"); + }); + } + private float widthOfCropBox(PDPage page) { return page.getCropBox().rotate(page.getRotation()).getWidth(); } diff -Nru libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/util/FontUtilsTest.java libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/util/FontUtilsTest.java --- libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/util/FontUtilsTest.java 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/util/FontUtilsTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -303,7 +303,7 @@ } @Test - public void wrapping_Lines() throws TaskIOException, IOException { + public void wrapping_Lines() throws TaskIOException { PDDocument doc = new PDDocument(); List lines = FontUtils.wrapLines("This is a long line that cannot fit on a single line and could be wrapped", HELVETICA, 10, 191, doc); assertThat(lines, is(Arrays.asList( @@ -313,7 +313,7 @@ } @Test - public void wrapping_Lines_Without_Word_Break() throws TaskIOException, IOException { + public void wrapping_Lines_Without_Word_Break() throws TaskIOException { PDDocument doc = new PDDocument(); List lines = FontUtils.wrapLines("This_is_a_long_line_that_cannot_fit_on_a_single_line_and_could_be_wrapped", HELVETICA, 10, 191, doc); assertThat(lines, is(Arrays.asList( @@ -323,7 +323,7 @@ } @Test - public void wrapping_Lines_Without_Word_Break_Or_Other_Delimiters() throws TaskIOException, IOException { + public void wrapping_Lines_Without_Word_Break_Or_Other_Delimiters() throws TaskIOException { PDDocument doc = new PDDocument(); List lines = FontUtils.wrapLines("Thisisalonglinethatcannotfitonasinglelineandcouldbewrapped", HELVETICA, 10, 191, doc); assertThat(lines, is(Arrays.asList( @@ -333,7 +333,7 @@ } @Test - public void wrapping_Lines_Words_Mixed_With_Super_Long_Words() throws TaskIOException, IOException { + public void wrapping_Lines_Words_Mixed_With_Super_Long_Words() throws TaskIOException { PDDocument doc = new PDDocument(); List lines = FontUtils.wrapLines("This is a long linethatcannotfitonasinglelineandcouldbe wrapped", HELVETICA, 10, 191, doc); assertThat(lines, is(Arrays.asList( diff -Nru libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/util/PageLabelUtilsTest.java libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/util/PageLabelUtilsTest.java --- libsejda-java-3.2.38/sejda-sambox/src/test/java/org/sejda/impl/sambox/util/PageLabelUtilsTest.java 1970-01-01 00:00:00.000000000 +0000 +++ libsejda-java-3.2.66/sejda-sambox/src/test/java/org/sejda/impl/sambox/util/PageLabelUtilsTest.java 2018-12-03 16:42:31.000000000 +0000 @@ -0,0 +1,124 @@ +/* + * Copyright 2018 by Eduard Weissmann (edi.weissmann@gmail.com). + * + * This file is part of the Sejda source code + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.sejda.impl.sambox.util; + +import org.junit.Test; +import org.sejda.impl.sambox.component.DocBuilder; +import org.sejda.sambox.pdmodel.PDDocument; +import org.sejda.sambox.pdmodel.common.PDPageLabels; + +import java.io.IOException; +import java.util.List; +import java.util.function.Consumer; + +import static java.util.Arrays.asList; +import static org.sejda.core.service.TestUtils.assertPageLabelIndexesAre; +import static org.sejda.core.service.TestUtils.assertPageLabelRangeIs; + +public class PageLabelUtilsTest { + + @Test + public void removeFirstPage() throws IOException { + PDDocument doc = new DocBuilder().withPages(10) + .withPageLabelRange(0, "r") + .withPageLabelRange(2, "D") + .get(); + + removePages(doc, asList(1), result -> { + assertPageLabelIndexesAre(result, 0, 1); + assertPageLabelRangeIs(result, 0, "r"); + assertPageLabelRangeIs(result, 1, "D"); + }); + } + + @Test + public void removeFirstPages() throws IOException { + PDDocument doc = new DocBuilder().withPages(10) + .withPageLabelRange(0, "r") + .withPageLabelRange(2, "D") + .get(); + + removePages(doc, asList(1, 2), result -> { + assertPageLabelIndexesAre(result, 0); + assertPageLabelRangeIs(result, 0, "D"); + }); + } + + @Test + public void removeMiddlePage() throws IOException { + PDDocument doc = new DocBuilder().withPages(10) + .withPageLabelRange(0, "r") + .withPageLabelRange(2, "D") + .get(); + + removePages(doc, asList(2), result -> { + assertPageLabelIndexesAre(result, 0, 1); + assertPageLabelRangeIs(result, 0, "r"); + assertPageLabelRangeIs(result, 1, "D"); + }); + } + + @Test + public void removeMiddlePages() throws IOException { + PDDocument doc = new DocBuilder().withPages(10) + .withPageLabelRange(0, "r") + .withPageLabelRange(2, "D") + .withPageLabelRange(4, "A") + .get(); + + removePages(doc, asList(3, 4, 5), result -> { + assertPageLabelIndexesAre(result, 0, 2); + assertPageLabelRangeIs(result, 0, "r"); + assertPageLabelRangeIs(result, 2, "A"); + }); + } + + @Test + public void removeLastPage() throws IOException { + PDDocument doc = new DocBuilder().withPages(10) + .withPageLabelRange(0, "r") + .withPageLabelRange(2, "D") + .get(); + + removePages(doc, asList(10), result -> { + assertPageLabelIndexesAre(result, 0, 2); + assertPageLabelRangeIs(result, 0, "r"); + assertPageLabelRangeIs(result, 2, "D"); + }); + } + + @Test + public void removeLastPages() throws IOException { + PDDocument doc = new DocBuilder().withPages(5) + .withPageLabelRange(0, "r") + .withPageLabelRange(2, "D") + .get(); + + removePages(doc, asList(3, 4, 5), result -> { + assertPageLabelIndexesAre(result, 0); + assertPageLabelRangeIs(result, 0, "r"); + }); + } + + private void removePages(PDDocument doc, List pages, Consumer consumer) throws IOException { + PDPageLabels result = PageLabelUtils.removePages(doc.getDocumentCatalog().getPageLabels(), pages, doc.getNumberOfPages()); + consumer.accept(result); + } +} \ No newline at end of file diff -Nru libsejda-java-3.2.38/.travis.settings.xml libsejda-java-3.2.66/.travis.settings.xml --- libsejda-java-3.2.38/.travis.settings.xml 1970-01-01 00:00:00.000000000 +0000 +++ libsejda-java-3.2.66/.travis.settings.xml 2018-12-03 16:42:31.000000000 +0000 @@ -0,0 +1,9 @@ + + + + ossrh + ${env.OSSRH_USER} + ${env.OSSRH_PWD} + + + \ No newline at end of file diff -Nru libsejda-java-3.2.38/.travis.yml libsejda-java-3.2.66/.travis.yml --- libsejda-java-3.2.38/.travis.yml 2017-11-15 14:41:17.000000000 +0000 +++ libsejda-java-3.2.66/.travis.yml 2018-12-03 16:42:31.000000000 +0000 @@ -15,10 +15,13 @@ apt: packages: - oracle-java8-installer -#GPG_PASSPHRASE env: global: - secure: YqXA0mY5JW3EwtKQjWLMD7Q4dpHVoIpfgYjG2D1D2X67KfekN6h5NaQWCQsPV0AJvznbF/bWoNjUGscncukA2MW/Fz1kXmnnuFmsFQNQAYBCilO5L8/MPWd0UFmHNJQYq5NGw9ajduB46E8K3URMPzseZsZo6IPalJ9i1VKF/Cg= + #GPG_PASSPHRASE + - secure: "YqXA0mY5JW3EwtKQjWLMD7Q4dpHVoIpfgYjG2D1D2X67KfekN6h5NaQWCQsPV0AJvznbF/bWoNjUGscncukA2MW/Fz1kXmnnuFmsFQNQAYBCilO5L8/MPWd0UFmHNJQYq5NGw9ajduB46E8K3URMPzseZsZo6IPalJ9i1VKF/Cg=" + #OSSRH credentials + - secure: "OQKwWq4cDk7jaVHAnjv9TC1ZuJ40k2q4rpN+do5zdu4506hvWZbv42J7adJlHQifAfGuu4dRnj7tZrG98RZLU4PZSA9hOdJOmzT4BE/8zJCYU06RAgOgry+KpR6TE+2cl+6h+MQslwBEylWaGj7GbrKGQWiBjfNZsPdhATZboNM=" + - secure: "Jh3PnqzzGjfboV8W++lYcp2zAyI7EhH+9nli/eLcKoS1whqcs6pdHAIkEwNpWQj3oAWLapFuL7/dR/dtlzXjggF9myVhl6io5W8+JDezGlow95QojIqlcQ8R0dmcN27wX8VSUtUuQlScHRBFvvNyxmp7pk1Q9fRykZWm2ui9ygo=" deploy: - provider: releases skip_cleanup: true @@ -31,11 +34,9 @@ - sejda-console/target/*.deb - sejda-console/target/*.zip - sejda-distribution/target/*.zip - - provider: bintray - file: "target/bintray/bintray-deploy.json" - user: "sejdapdf" - key: - secure: dLhy8d+Dra+0tVMnm/JPkhQvvIYBq/6EMS3E8TNHmkoYJmF5bUvWJZdopLn7E+HEG9n4KGaELA37NHdJsxkYMQIV0A5kF0MvrMVKf9ls9MKNT4lNDtub+FP3GxCRdZJvJBPnX9ND1y1dcXj7/c+3BadXTT2r2yZeulERD+uMiGg= + - provider: script + script: "mvn deploy --settings .travis.settings.xml" + skip_cleanup: true on: tags: true notifications: