Index: /gs2-extensions/pdf-box/trunk/GS_PDFBox_README.txt
===================================================================
--- /gs2-extensions/pdf-box/trunk/GS_PDFBox_README.txt	(revision 32196)
+++ /gs2-extensions/pdf-box/trunk/GS_PDFBox_README.txt	(revision 32197)
@@ -23,14 +23,14 @@
 - check the new version didn't break the stuff for which we specifically settled on version 1.8.2 before
 - grab the pdfbox 2.09 source code
-- introduce the new class GS_PDFToImagesAndText.java to the pdfbox app 2.09 src, based on its PDFToImage.java with added code to extract text based on ExtractText.java
-- rebuild the source, a maven project
-- modify the pdfbox app 2.09 (non source) ext jar file by including the new .class file
-- Now we're possible generating a txtfile for each img file (assuming there was extractable txt), some modifications needed to be made to the generated .item file to ensure these referred to the txt file.
+- introduce the new class PDFBoxToImagesAndText.java (originally added to the pdfbox app 2.09 src locally, now maintained separately with a GS Java package name). The new class is based on Apache PDFBox's PDFToImage.java, with added code to extract text based on Apache PDFBox's ExtractText.java
+- OLD: rebuild the source, a maven project. Then modify the pdfbox app 2.09 (non source) ext jar file by including the new .class file
+- compiling the new java class against the pdfbox-app.jar
+- Now we're possibly generating a txtfile for each img file (assuming there was extractable txt), some modifications needed to be made to the generated .item file to ensure these referred to the txt file.
 - work that remains to be done
 
 
-0. Used to use pdfbox app version 1.8.2, see commit message at http://trac.greenstone.org/changeset/29029/gs2-extensions/pdf-box/trunk/java/lib/java/pdfbox-app.jar
+1. Used to use pdfbox app version 1.8.2, see commit message at http://trac.greenstone.org/changeset/29029/gs2-extensions/pdf-box/trunk/java/lib/java/pdfbox-app.jar
 
-1. Upgrading to pdfbox app 2.0.9 (downloaded from https://pdfbox.apache.org/download.cgi?Preferred=http%3A%2F%2Fwww-us.apache.org%2Fdist%2F):
+2. Upgrading to pdfbox app 2.0.9 (downloaded from https://pdfbox.apache.org/download.cgi?Preferred=http%3A%2F%2Fwww-us.apache.org%2Fdist%2F):
 
 Doesn't work out of the box, such as to extract text from a PDF file.
@@ -50,6 +50,36 @@
 	if ($best_encoding eq "utf_8" ||  $best_encoding =~ /utf_8/) { $best_encoding = "utf8" }
 
+3. To recompile the new PDFBoxToImagesAndText.java code:
 
-2. Need to edit org.apache.pdfbox.tools.PDFToImage (not ExtractImages) as that's the tool that converts a PDF's individual pages to images
+- grab the svn version of the Greenstone pdfbox extension
+- Then from the svn checked out pdfbox folder, run 
+	$pdfbox > javac -cp /path/to/pdfbox/java/lib/java/pdfbox-app.jar -d /path/to/pdfbox/java/build java/src/org/greenstone/pdfbox/PDFBoxToImagesAndText.java
+which will compile against the pdfbox-app.jar in the classpath (-cp_ and output the .class file into the directory denoted by -d
+
+To run, that build folder needs to be on the classpath, besides pdfbox-app.jar itself. See PDFBoxConverter.pm
+
+4. For convenience PDFBoxToImagesAndText.java further no longer generates <PDF filename prefix><sequential number>.img-ext (jpg/gif/png) and matchingly named txt file, but just <sequential number>.img-ext and <sequential number>.txt.
+
+Further, needed to modify GS perllib's util::create_itemfile(), so that it no longer leaves each txtfile="" property empty in the item file if we've generated matching text files for the image files. In the past, util::create_itemfile() only worked with images, but now it's modified to additionally deal with matching text files.
+
+
+5. No need to rename the pdf-box, its containing tarball and its jar to gs-pdf-box. Doing that may have required changes to get nightly builds, releases, diffcol to get them to still work.
+
+However, Dr Bainbridge explained that the solution is to not rename pdfbox-app.jar to gs-pdfbox-app.jar, but have our new custom java file living separately rather than within the pdfbox-app.jar though compiled against it. The java file will have its own greenstone Java package (org.greenstone.pdfbox) and the class file produced from our custom class will then be run from its package by PDFBoxConverter.pm
+
+
+6. I was not sure what the licensing information for pdfbox/java/src/PDFBoxToImagesAndText.java should be in its preamble comment section, since most of the code is a copy or slight modification of the Apache PDFBox app's code. I asked Dr Nichols about the licensing, and he pointed out that Apache's PDFBox pages referred to https://www.apache.org/licenses/LICENSE-2.0
+Dr Nichols drew attention to its section "Redistribution", saying that that should cover things. I've tried to follow the points there, and have therefore included apache's LICENSE.txt and NOTICE.txt files into our pdfbox/java/src and pdfbox/java/src build folders where PDFBoxToImagesAndText.java and PDFBoxToImagesAndText.class, respectively, will live.
+
+------------------
+
+
+EXTRA INFORMATION
+
+Older but useful information, as it covers how to use maven to build the pdfbox-app, and include a new java file to be built into the pdfbox-app and distribute the file within the app.
+
+1. Originally I thought I would need to edit org.apache.pdfbox.tools.PDFToImage (not ExtractImages), as that's the tool that converts a PDF's individual pages to images. Eventually, since there was a new class PDFBoxToImagesAndText.java, Dr Bainbridge explained that this could just be compiled against an exiting pdfbox-app.jar, rather than including it inside the jar and recompiling the pdfbox-app in entirety.
+
+When I was still compiling the pdfbox-app in entirety, with and without my new code included therein, to obtain the basecode and build the app, the steps were:
 
 
@@ -70,5 +100,5 @@
 
 - The source code to edit is at /home/greenstone/gs3-svn-26Mar2018/gs2build/ext/pdfbox-2.0.9/tools/src/main/java/org/apache/pdfbox/tools
-Create GS_PDFToImagesAndText.java based on PDFToImage.java into which to incorporate from ExtractText.java
+Create PDFBoxToImagesAndText.java based on PDFToImage.java into which to incorporate from ExtractText.java
 
 - When built, will get /home/greenstone/gs3-svn-26Mar2018/gs2build/ext/pdfbox-2.0.9/tools/target/classes/org/apache/pdfbox/tools
@@ -76,5 +106,5 @@
 
 
-3. Once the pdfbox-app has been entirely built the first time, want smaller rebuilds.
+2. Once the pdfbox-app has been entirely built the first time, want smaller rebuilds.
 
 Final section of output of full rebuild:
@@ -118,36 +148,5 @@
 	greenstone@bedrock:~/gs3-svn-26Mar2018/gs2build/ext/pdfbox-2.0.9$ mvn clean install -pl tools -am
 
-(This will also compile our new GS_PDFToImagesAndText.java and put its class file GS_PDFToImagesAndText.class into the target dir /home/greenstone/gs3-svn-26Mar2018/gs2build/ext/pdfbox-2.0.9/tools/target/classes/org/apache/pdfbox/tools)
-
-
-4. For convenience GS_PDFToImagesAndText.java further no longer generates <PDF filename prefix><sequential number>.img-ext (jpg/gif/png) and matchingly named txt file, but just <sequential number>.img-ext and <sequential number>.txt.
-
-Further, needed to modify GS perllib's util::create_itemfile(), so that it no longer leaves each txtfile="" property empty in the item file if we've generated matching text files for the image files. In the past, util::create_itemfile() only worked with images, but now it's modified to additionally deal with matching text files.
-
-
-5. Remaining Issues.
-
-a. Build messages (when building lower level PDF conversion commands):
-ImageConverter: "/home/greenstone/gs3-svn-26Mar2018/gs2build/tmp/F143/A9-access-best-practices1.txt" too small, skipping
-Same for: A9-access-best-practices56.txt
-
-
-Lower level PDF conversion commands:
-calling cmd "/usr/bin/perl" -S gsConvert.pl -verbose 2 -pdf_zoom 2 -errlog "/home/greenstone/gs3-svn-26Mar2018/web/sites/localsite/collect/pdftst1/tmp/1528179077/err.log" -output pagedimg_jpg "/home/greenstone/gs3-svn-26Mar2018/web/sites/localsite/collect/pdftst1/tmp/1528179077/A9-access-best-practices.pdf"
-import.pl> 
-
-
-"/usr/bin/perl" -S gsConvert.pl -verbose 2 -pdf_zoom 2 -errlog "/home/greenstone/gs3-svn-26Mar2018/web/sites/localsite/collect/pdftst1/tmp/1528179077/err.log" -output pagedimg_jpg "/home/greenstone/gs3-svn-26Mar2018/web/sites/localsite/collect/pdftst1/import/A9-access-best-practices.pdf"
-
-
-"/usr/bin/perl" -S pdfpstoimg.pl -convert_to jpg "/home/greenstone/gs3-svn-26Mar2018/web/sites/localsite/collect/pdftst1/import/A9-access-best-practices.pdf" "/home/greenstone/gs3-svn-26Mar2018/web/sites/localsite/collect/pdftst1/import/A9-access-best-practices" > "/home/greenstone/gs3-svn-26Mar2018/web/sites/localsite/collect/pdftst1/import/A9-access-best-practices.out" 2> "/home/greenstone/gs3-svn-26Mar2018/web/sites/localsite/collect/pdftst1/import/A9-access-best-practices.err"
-
-
-@@@@ pdfpstoimg.pl::pdfps_to_img(): cmd = "/usr/bin/perl" -S gs-magick.pl convert "/home/greenstone/gs3-svn-26Mar2018/web/sites/localsite/collect/pdftst1/import/A9-access-best-practices.pdf" "/home/greenstone/gs3-svn-26Mar2018/web/sites/localsite/collect/pdftst1/import/A9-access-best-practices/A9-access-best-practices.jpg"
-
-
-b. Have not yet renamed the pdf-box, its containing tarball and its jar to gs-pdf-box yet, since a lot of things foreseen (nightly builds, releases, diffcol) and unforeseen can break due to the name change.
-
-c. Not sure what the licensing information for pdfbox/java/src/GS_PDFToImagesAndText.java should be in its preamble comment section, since most of the code is a copy or slight modification of the Apache PDFBox app's code.
+(This will also compile our new PDFBoxToImagesAndText.java and put its class file PDFBoxToImagesAndText.class into the target dir /home/greenstone/gs3-svn-26Mar2018/gs2build/ext/pdfbox-2.0.9/tools/target/classes/org/apache/pdfbox/tools)
 
 __________________________________________________________
Index: /gs2-extensions/pdf-box/trunk/java/build/LICENSE.txt
===================================================================
--- /gs2-extensions/pdf-box/trunk/java/build/LICENSE.txt	(revision 32197)
+++ /gs2-extensions/pdf-box/trunk/java/build/LICENSE.txt	(revision 32197)
@@ -0,0 +1,344 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+EXTERNAL COMPONENTS
+
+Apache PDFBox includes a number of components with separate copyright notices
+and license terms. Your use of these components is subject to the terms and
+conditions of the following licenses.
+
+Contributions made to the original PDFBox and FontBox projects:
+
+   Copyright (c) 2002-2007, www.pdfbox.org
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+
+   2. Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+
+   3. Neither the name of pdfbox; nor the names of its contributors may be
+      used to endorse or promote products derived from this software without
+      specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+   ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+   OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+   SUCH DAMAGE.
+
+Adobe Font Metrics (AFM) for PDF Core 14 Fonts
+
+   This file and the 14 PostScript(R) AFM files it accompanies may be used,
+   copied, and distributed for any purpose and without charge, with or without
+   modification, provided that all copyright notices are retained; that the
+   AFM files are not distributed without this file; that all modifications
+   to this file or any of the AFM files are prominently noted in the modified
+   file(s); and that this paragraph is not modified. Adobe Systems has no
+   responsibility or obligation to support the use of the AFM files. 
+
+CMaps for PDF Fonts (http://opensource.adobe.com/wiki/display/cmap/Downloads)
+
+   Copyright 1990-2009 Adobe Systems Incorporated.
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+
+   Redistributions of source code must retain the above copyright notice,
+   this list of conditions and the following disclaimer.
+
+   Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution. 
+
+   Neither the name of Adobe Systems Incorporated nor the names of its
+   contributors may be used to endorse or promote products derived from this
+   software without specific prior written permission. 
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+   THE POSSIBILITY OF SUCH DAMAGE.
+
+PaDaF PDF/A preflight (http://sourceforge.net/projects/padaf)
+
+  Copyright 2010 Atos Worldline SAS
+ 
+  Licensed by Atos Worldline SAS under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  Atos Worldline SAS licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+ 
+       http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+OSXAdapter
+
+  Version: 2.0
+  
+  Disclaimer: IMPORTANT:  This Apple software is supplied to you by 
+  Apple Inc. ("Apple") in consideration of your agreement to the
+  following terms, and your use, installation, modification or
+  redistribution of this Apple software constitutes acceptance of these
+  terms.  If you do not agree with these terms, please do not use,
+  install, modify or redistribute this Apple software.
+  
+  In consideration of your agreement to abide by the following terms, and
+  subject to these terms, Apple grants you a personal, non-exclusive
+  license, under Apple's copyrights in this original Apple software (the
+  "Apple Software"), to use, reproduce, modify and redistribute the Apple
+  Software, with or without modifications, in source and/or binary forms;
+  provided that if you redistribute the Apple Software in its entirety and
+  without modifications, you must retain this notice and the following
+  text and disclaimers in all such redistributions of the Apple Software. 
+  Neither the name, trademarks, service marks or logos of Apple Inc. 
+  may be used to endorse or promote products derived from the Apple
+  Software without specific prior written permission from Apple.  Except
+  as expressly stated in this notice, no other rights or licenses, express
+  or implied, are granted by Apple herein, including but not limited to
+  any patent rights that may be infringed by your derivative works or by
+  other works in which the Apple Software may be incorporated.
+  
+  The Apple Software is provided by Apple on an "AS IS" basis.  APPLE
+  MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+  THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
+  FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
+  OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
+  
+  IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
+  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
+  MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
+  AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
+  STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
+  POSSIBILITY OF SUCH DAMAGE.
+  
+  Copyright (C) 2003-2007 Apple, Inc., All Rights Reserved
Index: /gs2-extensions/pdf-box/trunk/java/build/NOTICE.txt
===================================================================
--- /gs2-extensions/pdf-box/trunk/java/build/NOTICE.txt	(revision 32197)
+++ /gs2-extensions/pdf-box/trunk/java/build/NOTICE.txt	(revision 32197)
@@ -0,0 +1,22 @@
+Apache PDFBox
+Copyright 2014 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+Based on source code originally developed in the PDFBox and 
+FontBox projects.
+
+Copyright (c) 2002-2007, www.pdfbox.org
+
+Based on source code originally developed in the PaDaF project.
+Copyright (c) 2010 Atos Worldline SAS
+
+Includes the Adobe Glyph List
+Copyright 1997, 1998, 2002, 2007, 2010 Adobe Systems Incorporated.
+
+Includes the Zapf Dingbats Glyph List
+Copyright 2002, 2010 Adobe Systems Incorporated.
+
+Includes OSXAdapter
+Copyright (C) 2003-2007 Apple, Inc., All Rights Reserved
Index: /gs2-extensions/pdf-box/trunk/java/perllib/plugins/PDFBoxConverter.pm
===================================================================
--- /gs2-extensions/pdf-box/trunk/java/perllib/plugins/PDFBoxConverter.pm	(revision 32196)
+++ /gs2-extensions/pdf-box/trunk/java/perllib/plugins/PDFBoxConverter.pm	(revision 32197)
@@ -131,7 +131,10 @@
 	$self->{'pdfbox_launch_cmd'} = $launch_cmd;
 	#$self->{'pdfbox_img_launch_cmd'} = "java -cp \"$pbajar\" org.apache.pdfbox.tools.PDFToImage"; # pdfbox 2.09 cmd for converting each PDF page to an image (gif, jpg, png)
-	# Now: use this cmd to launch our new custom PDFBox class (GS_PDFToImagesAndText.java) to convert each PDF page into an image (gif, jpg, png)
+	# Now: use this cmd to launch our new custom PDFBox class (PDFBoxToImagesAndText.java) to convert each PDF page into an image (gif, jpg, png)
 	# AND its extracted text. An item file is still generated, but this time referring to txtfiles too, not just the images. Result: searchable paged output.
-	$self->{'pdfbox_img_launch_cmd'} = "java -cp \"$pbajar\" org.apache.pdfbox.tools.GS_PDFToImagesAndText"; 
+	# Our new custom class PDFBoxToImagesAndText.java lives in the new build folder, so add that to the classpath for the launch cmd
+	my $pdfbox_build = &FileUtils::filenameConcatenate($gextpb_home,"build");
+	my $classpath = &util::pathname_cat($pbajar,$pdfbox_build);	
+	$self->{'pdfbox_img_launch_cmd'} = "java -cp \"$classpath\" org.greenstone.pdfbox.PDFBoxToImagesAndText";
     }
     else {       
Index: 2-extensions/pdf-box/trunk/java/src/GS_PDFToImagesAndText.java
===================================================================
--- /gs2-extensions/pdf-box/trunk/java/src/GS_PDFToImagesAndText.java	(revision 32196)
+++ 	(revision )
@@ -1,414 +1,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.tools;
-
-import java.awt.HeadlessException;
-import java.awt.Toolkit;
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import org.apache.pdfbox.io.IOUtils;
-
-import javax.imageio.ImageIO;
-
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.common.PDRectangle;
-import org.apache.pdfbox.rendering.ImageType;
-import org.apache.pdfbox.rendering.PDFRenderer;
-import org.apache.pdfbox.tools.imageio.ImageIOUtil;
-
-import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
-import org.apache.pdfbox.text.PDFTextStripper;
-
-/**
- * This class is based on PDFToImage.java which converts
- * the pages of a PDF document to images.
- * This class should convert the pages to images and 
- * extract the text of each page. That part of the code
- * to be taken from ExtractText.java
- *
- * Built on Apache PDFBox's PDFToImage.java with minor modifications.
- * ak19
- */
-public final class GS_PDFToImagesAndText
-{
-    private static final String PASSWORD = "-password";
-    private static final String ENCODING = "-encoding";
-    private static final String START_PAGE = "-startPage";
-    private static final String END_PAGE = "-endPage";
-    private static final String PAGE = "-page";
-    private static final String IMAGE_TYPE = "-imageType";
-    private static final String FORMAT = "-format";
-    private static final String OUTPUT_PREFIX = "-outputPrefix";
-    private static final String PREFIX = "-prefix";
-    private static final String COLOR = "-color";
-    private static final String RESOLUTION = "-resolution";
-    private static final String DPI = "-dpi";
-    private static final String CROPBOX = "-cropbox";
-    private static final String TIME = "-time";
-
-    private static final String STD_ENCODING = "UTF-8";
-
-    /**
-     * private constructor.
-    */
-    private GS_PDFToImagesAndText()
-    {
-        //static class
-    }
-
-    /**
-     * Infamous main method.
-     *
-     * @param args Command line arguments, should be one and a reference to a file.
-     *
-     * @throws IOException If there is an error parsing the document.
-     */
-    public static void main( String[] args ) throws IOException
-    {
-        try
-        {
-            // force KCMS (faster than LCMS) if available
-            Class.forName("sun.java2d.cmm.kcms.KcmsServiceProvider");
-            System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider");
-        }
-        catch (ClassNotFoundException e)
-        {
-            // do nothing
-        }
-
-        // suppress the Dock icon on OS X
-        System.setProperty("apple.awt.UIElement", "true");
-
-        String password = "";
-	String encoding = STD_ENCODING;
-        String pdfFile = null;
-        String outputPrefix = null;
-        String imageFormat = "jpg";
-        int startPage = 1;
-        int endPage = Integer.MAX_VALUE;
-        String color = "rgb";
-        int dpi;
-        float cropBoxLowerLeftX = 0;
-        float cropBoxLowerLeftY = 0;
-        float cropBoxUpperRightX = 0;
-        float cropBoxUpperRightY = 0;
-        boolean showTime = false;
-        try
-        {
-            dpi = Toolkit.getDefaultToolkit().getScreenResolution();
-        }
-        catch( HeadlessException e )
-        {
-            dpi = 96;
-        }
-        for( int i = 0; i < args.length; i++ )
-        {
-            if( args[i].equals( PASSWORD ) )
-            {
-                i++;
-                if( i >= args.length )
-                {
-                    usage();
-                }
-                password = args[i];
-            }
-            else if( args[i].equals( ENCODING ) )
-            {
-                i++;
-                if( i >= args.length )
-                {
-                    usage();
-                }
-                encoding = args[i];
-            }
-            else if( args[i].equals( START_PAGE ) )
-            {
-                i++;
-                if( i >= args.length )
-                {
-                    usage();
-                }
-                startPage = Integer.parseInt( args[i] );
-            }
-            else if( args[i].equals( END_PAGE ) )
-            {
-                i++;
-                if( i >= args.length )
-                {
-                    usage();
-                }
-                endPage = Integer.parseInt( args[i] );
-            }
-            else if( args[i].equals( PAGE ) )
-            {
-                i++;
-                if( i >= args.length )
-                {
-                    usage();
-                }
-                startPage = Integer.parseInt( args[i] );
-                endPage = Integer.parseInt( args[i] );
-            }
-            else if( args[i].equals(IMAGE_TYPE) || args[i].equals(FORMAT) )
-            {
-                i++;
-                imageFormat = args[i];
-            }
-            else if( args[i].equals( OUTPUT_PREFIX ) || args[i].equals( PREFIX ) )
-            {
-                i++;
-                outputPrefix = args[i];
-            }
-            else if( args[i].equals( COLOR ) )
-            {
-                i++;
-                color = args[i];
-            }
-            else if( args[i].equals( RESOLUTION ) || args[i].equals( DPI ) )
-            {
-                i++;
-                dpi = Integer.parseInt(args[i]);
-            }
-            else if( args[i].equals( CROPBOX ) )
-            {
-                i++;
-                cropBoxLowerLeftX = Float.valueOf(args[i]);
-                i++;
-                cropBoxLowerLeftY = Float.valueOf(args[i]);
-                i++;
-                cropBoxUpperRightX = Float.valueOf(args[i]);
-                i++;
-                cropBoxUpperRightY = Float.valueOf(args[i]);
-            }
-            else if( args[i].equals( TIME ) )
-            {
-                showTime = true;
-            }
-            else
-            {
-                if( pdfFile == null )
-                {
-                    pdfFile = args[i];
-                }
-            }
-        }
-        if( pdfFile == null )
-        {
-            usage();
-        }
-        else
-        {
-            if(outputPrefix == null)
-            {
-                outputPrefix = pdfFile.substring( 0, pdfFile.lastIndexOf( '.' ));
-            }
-
-            PDDocument document = null;
-            try
-            {
-		boolean extractingTextAllowed = true;		
-		//String outputFile = null;
-
-		/*startProcessing("Loading PDF "+pdfFile);
-		if( outputFile == null && pdfFile.length() >4 )
-                {
-                    outputFile = new File( pdfFile.substring( 0, pdfFile.length() -4 ) + ext ).getAbsolutePath();
-                }*/
-
-                document = PDDocument.load(new File(pdfFile), password);
-
-		AccessPermission ap = document.getCurrentAccessPermission();
-                if( ! ap.canExtractContent() )
-                {
-                    //throw new IOException( "You do not have permission to extract text" );
-		    System.err.println( "*** You do not have permission to extract text" ); // still extract the pages as images then?
-		    extractingTextAllowed = false;
-                }
-		//stopProcessing("Time for loading: ", startTime);
-
-		// don't extract to HTML in this class, just extract to txt
-		PDFTextStripper stripper = new PDFTextStripper();            
-                //stripper.setSortByPosition( sort );
-                //stripper.setShouldSeparateByBeads( separateBeads );
-		stripper.setShouldSeparateByBeads( true );
-                
-
-                ImageType imageType = null;
-                if ("bilevel".equalsIgnoreCase(color))
-                {
-                    imageType = ImageType.BINARY;
-                }
-                else if ("gray".equalsIgnoreCase(color))
-                {
-                    imageType = ImageType.GRAY;
-                }
-                else if ("rgb".equalsIgnoreCase(color))
-                {
-                    imageType = ImageType.RGB;
-                }
-                else if ("rgba".equalsIgnoreCase(color))
-                {
-                    imageType = ImageType.ARGB;
-                }
-                
-                if (imageType == null)
-                {
-                    System.err.println( "Error: Invalid color." );
-                    System.exit( 2 );
-                }
-
-                //if a CropBox has been specified, update the CropBox:
-                //changeCropBoxes(PDDocument document,float a, float b, float c,float d)
-                if ( cropBoxLowerLeftX!=0 || cropBoxLowerLeftY!=0
-                        || cropBoxUpperRightX!=0 || cropBoxUpperRightY!=0 )
-                {
-                    changeCropBox(document,
-                            cropBoxLowerLeftX, cropBoxLowerLeftY,
-                            cropBoxUpperRightX, cropBoxUpperRightY);
-                }
-
-                long startTime = System.nanoTime();
-		
-                // render the pages
-                boolean success = true;
-                endPage = Math.min(endPage, document.getNumberOfPages());
-                PDFRenderer renderer = new PDFRenderer(document);
-                for (int i = startPage - 1; i < endPage; i++)
-                {
-                    // turn page into image
-                    BufferedImage image = renderer.renderImageWithDPI(i, dpi, imageType);
-                    int lastSlash = outputPrefix.lastIndexOf(File.separator);
-                    outputPrefix = outputPrefix.substring(0, lastSlash+1); // include the folder (/) but not the filename prefix
-                    String fileName = outputPrefix + (i + 1) + ".";
-                    success &= ImageIOUtil.writeImage(image, fileName+imageFormat, dpi);
-
-
-                    // image version of page done, now extract text from current page
-                    if(extractingTextAllowed) {
-			    Writer output = null;	
-			    try {
-				    output = new OutputStreamWriter( new FileOutputStream( fileName+"txt" ), encoding );
-				    stripper.setStartPage( i+1 );
-				    stripper.setEndPage( i+1 );
-				
-				    //if (debug)
-				    //{
-				    	System.err.println("Writing to "+fileName);
-				    //}
-
-				    // Extract text for main document, the specified pages
-				    stripper.writeText( document, output );
-			    } catch (Exception ex) {
-				System.err.println( "*** Unable to create txt file " + fileName + "txt. Exception: " + ex.getMessage());
-			    } finally {
-		            	IOUtils.closeQuietly(output);
-			    }
-                    }
-                }
-
-		// GS NOTE: We just extracted text for (each page of) the main document, but
-		// we're not additionally extracting text for any "embedded PDFs" as is done in ExtractText.java
-
-                // performance stats
-                long endTime = System.nanoTime();
-                long duration = endTime - startTime;
-                int count = 1 + endPage - startPage;
-                if (showTime)
-                {
-                    System.err.printf("Rendered %d page%s in %dms\n", count, count == 1 ? "" : "s",
-                                      duration / 1000000);
-                }
-
-                if (!success)
-                {
-                    System.err.println( "Error: no writer found for image format '"
-                            + imageFormat + "'" );
-                    System.exit(1);
-                }
-            }
-            finally
-            {
-                if( document != null )
-                {
-                    document.close();
-                }
-            }
-        }
-    }
-
-    /**
-     * This will print the usage requirements and exit.
-     */
-    private static void usage()
-    {
-        String message = "Usage: java -jar pdfbox-app-x.y.z.jar GS_PDFToImagesAndText [options] <inputfile>\n"
-            + "\nOptions:\n"
-            + "  -password  <password>            : Password to decrypt document\n"
-            + "  -encoding  <output encoding> : UTF-8 (default) or ISO-8859-1, UTF-16BE, UTF-16LE, etc.\n"
-            + "  -format <string>                 : Image format: " + getImageFormats() + "\n"
-            + "  -prefix <string>                 : Filename prefix for image files\n"
-            + "  -page <number>                   : The only page to extract (1-based)\n"
-            + "  -startPage <int>                 : The first page to start extraction (1-based)\n"
-            + "  -endPage <int>                   : The last page to extract(inclusive)\n"
-            + "  -color <int>                     : The color depth (valid: bilevel, gray, rgb, rgba)\n"
-            + "  -dpi <int>                       : The DPI of the output image\n"
-            + "  -cropbox <int> <int> <int> <int> : The page area to export\n"
-            + "  -time                            : Prints timing information to stdout\n"
-            + "  <inputfile>                      : The PDF document to use\n";
-        
-        System.err.println(message);
-        System.exit( 1 );
-    }
-
-    private static String getImageFormats()
-    {
-        StringBuilder retval = new StringBuilder();
-        String[] formats = ImageIO.getReaderFormatNames();
-        for( int i = 0; i < formats.length; i++ )
-        {
-           if (formats[i].equalsIgnoreCase(formats[i]))
-           {
-               retval.append( formats[i] );
-               if( i + 1 < formats.length )
-               {
-                   retval.append( ", " );
-               }
-           }
-        }
-        return retval.toString();
-    }
-
-    private static void changeCropBox(PDDocument document, float a, float b, float c, float d)
-    {
-        for (PDPage page : document.getPages())
-        {
-            System.out.println("resizing page");
-            PDRectangle rectangle = new PDRectangle();
-            rectangle.setLowerLeftX(a);
-            rectangle.setLowerLeftY(b);
-            rectangle.setUpperRightX(c);
-            rectangle.setUpperRightY(d);
-            page.setCropBox(rectangle);
-
-        }
-    }
-}
Index: /gs2-extensions/pdf-box/trunk/java/src/LICENSE.txt
===================================================================
--- /gs2-extensions/pdf-box/trunk/java/src/LICENSE.txt	(revision 32197)
+++ /gs2-extensions/pdf-box/trunk/java/src/LICENSE.txt	(revision 32197)
@@ -0,0 +1,344 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+EXTERNAL COMPONENTS
+
+Apache PDFBox includes a number of components with separate copyright notices
+and license terms. Your use of these components is subject to the terms and
+conditions of the following licenses.
+
+Contributions made to the original PDFBox and FontBox projects:
+
+   Copyright (c) 2002-2007, www.pdfbox.org
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+
+   2. Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+
+   3. Neither the name of pdfbox; nor the names of its contributors may be
+      used to endorse or promote products derived from this software without
+      specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+   ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+   OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+   SUCH DAMAGE.
+
+Adobe Font Metrics (AFM) for PDF Core 14 Fonts
+
+   This file and the 14 PostScript(R) AFM files it accompanies may be used,
+   copied, and distributed for any purpose and without charge, with or without
+   modification, provided that all copyright notices are retained; that the
+   AFM files are not distributed without this file; that all modifications
+   to this file or any of the AFM files are prominently noted in the modified
+   file(s); and that this paragraph is not modified. Adobe Systems has no
+   responsibility or obligation to support the use of the AFM files. 
+
+CMaps for PDF Fonts (http://opensource.adobe.com/wiki/display/cmap/Downloads)
+
+   Copyright 1990-2009 Adobe Systems Incorporated.
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+
+   Redistributions of source code must retain the above copyright notice,
+   this list of conditions and the following disclaimer.
+
+   Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution. 
+
+   Neither the name of Adobe Systems Incorporated nor the names of its
+   contributors may be used to endorse or promote products derived from this
+   software without specific prior written permission. 
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+   THE POSSIBILITY OF SUCH DAMAGE.
+
+PaDaF PDF/A preflight (http://sourceforge.net/projects/padaf)
+
+  Copyright 2010 Atos Worldline SAS
+ 
+  Licensed by Atos Worldline SAS under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  Atos Worldline SAS licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+ 
+       http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+OSXAdapter
+
+  Version: 2.0
+  
+  Disclaimer: IMPORTANT:  This Apple software is supplied to you by 
+  Apple Inc. ("Apple") in consideration of your agreement to the
+  following terms, and your use, installation, modification or
+  redistribution of this Apple software constitutes acceptance of these
+  terms.  If you do not agree with these terms, please do not use,
+  install, modify or redistribute this Apple software.
+  
+  In consideration of your agreement to abide by the following terms, and
+  subject to these terms, Apple grants you a personal, non-exclusive
+  license, under Apple's copyrights in this original Apple software (the
+  "Apple Software"), to use, reproduce, modify and redistribute the Apple
+  Software, with or without modifications, in source and/or binary forms;
+  provided that if you redistribute the Apple Software in its entirety and
+  without modifications, you must retain this notice and the following
+  text and disclaimers in all such redistributions of the Apple Software. 
+  Neither the name, trademarks, service marks or logos of Apple Inc. 
+  may be used to endorse or promote products derived from the Apple
+  Software without specific prior written permission from Apple.  Except
+  as expressly stated in this notice, no other rights or licenses, express
+  or implied, are granted by Apple herein, including but not limited to
+  any patent rights that may be infringed by your derivative works or by
+  other works in which the Apple Software may be incorporated.
+  
+  The Apple Software is provided by Apple on an "AS IS" basis.  APPLE
+  MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+  THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
+  FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
+  OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
+  
+  IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
+  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
+  MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
+  AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
+  STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
+  POSSIBILITY OF SUCH DAMAGE.
+  
+  Copyright (C) 2003-2007 Apple, Inc., All Rights Reserved
Index: /gs2-extensions/pdf-box/trunk/java/src/NOTICE.txt
===================================================================
--- /gs2-extensions/pdf-box/trunk/java/src/NOTICE.txt	(revision 32197)
+++ /gs2-extensions/pdf-box/trunk/java/src/NOTICE.txt	(revision 32197)
@@ -0,0 +1,22 @@
+Apache PDFBox
+Copyright 2014 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+Based on source code originally developed in the PDFBox and 
+FontBox projects.
+
+Copyright (c) 2002-2007, www.pdfbox.org
+
+Based on source code originally developed in the PaDaF project.
+Copyright (c) 2010 Atos Worldline SAS
+
+Includes the Adobe Glyph List
+Copyright 1997, 1998, 2002, 2007, 2010 Adobe Systems Incorporated.
+
+Includes the Zapf Dingbats Glyph List
+Copyright 2002, 2010 Adobe Systems Incorporated.
+
+Includes OSXAdapter
+Copyright (C) 2003-2007 Apple, Inc., All Rights Reserved
Index: /gs2-extensions/pdf-box/trunk/java/src/org/greenstone/pdfbox/PDFBoxToImagesAndText.java
===================================================================
--- /gs2-extensions/pdf-box/trunk/java/src/org/greenstone/pdfbox/PDFBoxToImagesAndText.java	(revision 32197)
+++ /gs2-extensions/pdf-box/trunk/java/src/org/greenstone/pdfbox/PDFBoxToImagesAndText.java	(revision 32197)
@@ -0,0 +1,445 @@
+/**********************************************************************
+ *
+ * PDFBoxToImagesAndText.java based on Apache PDFBoxÂ®'s PDFToImage.java
+ * with further code spliced in from its ExtractImages.java with some
+ * minor modifications.
+ *
+ * The code in this file is therefore under the same Apache License
+ * version 2.0 as Apache's PDFBox.
+ *
+ * Copyright 2018 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the Apache License version 2.0.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the Apache License version 2.0
+ * along with this file; if not, refer to
+ * https://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * The following comment is from the original file,
+ * PDFBox's PDFToImage.java
+ * 
+ *********************************************************************/
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.greenstone.pdfbox;
+
+import java.awt.HeadlessException;
+import java.awt.Toolkit;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import org.apache.pdfbox.io.IOUtils;
+
+import javax.imageio.ImageIO;
+
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.apache.pdfbox.rendering.ImageType;
+import org.apache.pdfbox.rendering.PDFRenderer;
+import org.apache.pdfbox.tools.imageio.ImageIOUtil;
+
+import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
+import org.apache.pdfbox.text.PDFTextStripper;
+
+/**
+ * This class is based on PDFToImage.java which converts
+ * the pages of a PDF document to images.
+ * This class should convert the pages to images and 
+ * extract the text of each page. That part of the code
+ * to be taken from ExtractText.java
+ *
+ * Built on Apache PDFBox's PDFToImage.java with minor modifications.
+ * ak19
+ */
+public final class PDFBoxToImagesAndText
+{
+    private static final String PASSWORD = "-password";
+    private static final String ENCODING = "-encoding";
+    private static final String START_PAGE = "-startPage";
+    private static final String END_PAGE = "-endPage";
+    private static final String PAGE = "-page";
+    private static final String IMAGE_TYPE = "-imageType";
+    private static final String FORMAT = "-format";
+    private static final String OUTPUT_PREFIX = "-outputPrefix";
+    private static final String PREFIX = "-prefix";
+    private static final String COLOR = "-color";
+    private static final String RESOLUTION = "-resolution";
+    private static final String DPI = "-dpi";
+    private static final String CROPBOX = "-cropbox";
+    private static final String TIME = "-time";
+
+    private static final String STD_ENCODING = "UTF-8";
+
+    /**
+     * private constructor.
+    */
+    private PDFBoxToImagesAndText()
+    {
+        //static class
+    }
+
+    /**
+     * Infamous main method.
+     *
+     * @param args Command line arguments, should be one and a reference to a file.
+     *
+     * @throws IOException If there is an error parsing the document.
+     */
+    public static void main( String[] args ) throws IOException
+    {
+        try
+        {
+            // force KCMS (faster than LCMS) if available
+            Class.forName("sun.java2d.cmm.kcms.KcmsServiceProvider");
+            System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider");
+        }
+        catch (ClassNotFoundException e)
+        {
+            // do nothing
+        }
+
+        // suppress the Dock icon on OS X
+        System.setProperty("apple.awt.UIElement", "true");
+
+        String password = "";
+	String encoding = STD_ENCODING;
+        String pdfFile = null;
+        String outputPrefix = null;
+        String imageFormat = "jpg";
+        int startPage = 1;
+        int endPage = Integer.MAX_VALUE;
+        String color = "rgb";
+        int dpi;
+        float cropBoxLowerLeftX = 0;
+        float cropBoxLowerLeftY = 0;
+        float cropBoxUpperRightX = 0;
+        float cropBoxUpperRightY = 0;
+        boolean showTime = false;
+        try
+        {
+            dpi = Toolkit.getDefaultToolkit().getScreenResolution();
+        }
+        catch( HeadlessException e )
+        {
+            dpi = 96;
+        }
+        for( int i = 0; i < args.length; i++ )
+        {
+            if( args[i].equals( PASSWORD ) )
+            {
+                i++;
+                if( i >= args.length )
+                {
+                    usage();
+                }
+                password = args[i];
+            }
+            else if( args[i].equals( ENCODING ) )
+            {
+                i++;
+                if( i >= args.length )
+                {
+                    usage();
+                }
+                encoding = args[i];
+            }
+            else if( args[i].equals( START_PAGE ) )
+            {
+                i++;
+                if( i >= args.length )
+                {
+                    usage();
+                }
+                startPage = Integer.parseInt( args[i] );
+            }
+            else if( args[i].equals( END_PAGE ) )
+            {
+                i++;
+                if( i >= args.length )
+                {
+                    usage();
+                }
+                endPage = Integer.parseInt( args[i] );
+            }
+            else if( args[i].equals( PAGE ) )
+            {
+                i++;
+                if( i >= args.length )
+                {
+                    usage();
+                }
+                startPage = Integer.parseInt( args[i] );
+                endPage = Integer.parseInt( args[i] );
+            }
+            else if( args[i].equals(IMAGE_TYPE) || args[i].equals(FORMAT) )
+            {
+                i++;
+                imageFormat = args[i];
+            }
+            else if( args[i].equals( OUTPUT_PREFIX ) || args[i].equals( PREFIX ) )
+            {
+                i++;
+                outputPrefix = args[i];
+            }
+            else if( args[i].equals( COLOR ) )
+            {
+                i++;
+                color = args[i];
+            }
+            else if( args[i].equals( RESOLUTION ) || args[i].equals( DPI ) )
+            {
+                i++;
+                dpi = Integer.parseInt(args[i]);
+            }
+            else if( args[i].equals( CROPBOX ) )
+            {
+                i++;
+                cropBoxLowerLeftX = Float.valueOf(args[i]);
+                i++;
+                cropBoxLowerLeftY = Float.valueOf(args[i]);
+                i++;
+                cropBoxUpperRightX = Float.valueOf(args[i]);
+                i++;
+                cropBoxUpperRightY = Float.valueOf(args[i]);
+            }
+            else if( args[i].equals( TIME ) )
+            {
+                showTime = true;
+            }
+            else
+            {
+                if( pdfFile == null )
+                {
+                    pdfFile = args[i];
+                }
+            }
+        }
+        if( pdfFile == null )
+        {
+            usage();
+        }
+        else
+        {
+            if(outputPrefix == null)
+            {
+                outputPrefix = pdfFile.substring( 0, pdfFile.lastIndexOf( '.' ));
+            }
+
+            PDDocument document = null;
+            try
+            {
+		boolean extractingTextAllowed = true;		
+		//String outputFile = null;
+
+		/*startProcessing("Loading PDF "+pdfFile);
+		if( outputFile == null && pdfFile.length() >4 )
+                {
+                    outputFile = new File( pdfFile.substring( 0, pdfFile.length() -4 ) + ext ).getAbsolutePath();
+                }*/
+
+                document = PDDocument.load(new File(pdfFile), password);
+
+		AccessPermission ap = document.getCurrentAccessPermission();
+                if( ! ap.canExtractContent() )
+                {
+                    //throw new IOException( "You do not have permission to extract text" );
+		    System.err.println( "*** You do not have permission to extract text" ); // still extract the pages as images then?
+		    extractingTextAllowed = false;
+                }
+		//stopProcessing("Time for loading: ", startTime);
+
+		// don't extract to HTML in this class, just extract to txt
+		PDFTextStripper stripper = new PDFTextStripper();            
+                //stripper.setSortByPosition( sort );
+                //stripper.setShouldSeparateByBeads( separateBeads );
+		stripper.setShouldSeparateByBeads( true );
+                
+
+                ImageType imageType = null;
+                if ("bilevel".equalsIgnoreCase(color))
+                {
+                    imageType = ImageType.BINARY;
+                }
+                else if ("gray".equalsIgnoreCase(color))
+                {
+                    imageType = ImageType.GRAY;
+                }
+                else if ("rgb".equalsIgnoreCase(color))
+                {
+                    imageType = ImageType.RGB;
+                }
+                else if ("rgba".equalsIgnoreCase(color))
+                {
+                    imageType = ImageType.ARGB;
+                }
+                
+                if (imageType == null)
+                {
+                    System.err.println( "Error: Invalid color." );
+                    System.exit( 2 );
+                }
+
+                //if a CropBox has been specified, update the CropBox:
+                //changeCropBoxes(PDDocument document,float a, float b, float c,float d)
+                if ( cropBoxLowerLeftX!=0 || cropBoxLowerLeftY!=0
+                        || cropBoxUpperRightX!=0 || cropBoxUpperRightY!=0 )
+                {
+                    changeCropBox(document,
+                            cropBoxLowerLeftX, cropBoxLowerLeftY,
+                            cropBoxUpperRightX, cropBoxUpperRightY);
+                }
+
+                long startTime = System.nanoTime();
+		
+                // render the pages
+                boolean success = true;
+                endPage = Math.min(endPage, document.getNumberOfPages());
+                PDFRenderer renderer = new PDFRenderer(document);
+                for (int i = startPage - 1; i < endPage; i++)
+                {
+                    // turn page into image
+                    BufferedImage image = renderer.renderImageWithDPI(i, dpi, imageType);
+                    int lastSlash = outputPrefix.lastIndexOf(File.separator);
+                    outputPrefix = outputPrefix.substring(0, lastSlash+1); // include the folder (/) but not the filename prefix
+                    String fileName = outputPrefix + (i + 1) + ".";
+                    success &= ImageIOUtil.writeImage(image, fileName+imageFormat, dpi);
+
+
+                    // image version of page done, now extract text from current page
+                    if(extractingTextAllowed) {
+			    Writer output = null;	
+			    try {
+				    output = new OutputStreamWriter( new FileOutputStream( fileName+"txt" ), encoding );
+				    stripper.setStartPage( i+1 );
+				    stripper.setEndPage( i+1 );
+				
+				    //if (debug)
+				    //{
+				    	System.err.println("Writing to "+fileName);
+				    //}
+
+				    // Extract text for main document, the specified pages
+				    stripper.writeText( document, output );
+			    } catch (Exception ex) {
+				System.err.println( "*** Unable to create txt file " + fileName + "txt. Exception: " + ex.getMessage());
+			    } finally {
+		            	IOUtils.closeQuietly(output);
+			    }
+                    }
+                }
+
+		// GS NOTE: We just extracted text for (each page of) the main document, but
+		// we're not additionally extracting text for any "embedded PDFs" as is done in ExtractText.java
+
+                // performance stats
+                long endTime = System.nanoTime();
+                long duration = endTime - startTime;
+                int count = 1 + endPage - startPage;
+                if (showTime)
+                {
+                    System.err.printf("Rendered %d page%s in %dms\n", count, count == 1 ? "" : "s",
+                                      duration / 1000000);
+                }
+
+                if (!success)
+                {
+                    System.err.println( "Error: no writer found for image format '"
+                            + imageFormat + "'" );
+                    System.exit(1);
+                }
+            }
+            finally
+            {
+                if( document != null )
+                {
+                    document.close();
+                }
+            }
+        }
+    }
+
+    /**
+     * This will print the usage requirements and exit.
+     */
+    private static void usage()
+    {
+        String message = "Usage: java -jar pdfbox-app-x.y.z.jar PDFBoxToImagesAndText [options] <inputfile>\n"
+            + "\nOptions:\n"
+            + "  -password  <password>            : Password to decrypt document\n"
+            + "  -encoding  <output encoding> : UTF-8 (default) or ISO-8859-1, UTF-16BE, UTF-16LE, etc.\n"
+            + "  -format <string>                 : Image format: " + getImageFormats() + "\n"
+            + "  -prefix <string>                 : Filename prefix for image files\n"
+            + "  -page <number>                   : The only page to extract (1-based)\n"
+            + "  -startPage <int>                 : The first page to start extraction (1-based)\n"
+            + "  -endPage <int>                   : The last page to extract(inclusive)\n"
+            + "  -color <int>                     : The color depth (valid: bilevel, gray, rgb, rgba)\n"
+            + "  -dpi <int>                       : The DPI of the output image\n"
+            + "  -cropbox <int> <int> <int> <int> : The page area to export\n"
+            + "  -time                            : Prints timing information to stdout\n"
+            + "  <inputfile>                      : The PDF document to use\n";
+        
+        System.err.println(message);
+        System.exit( 1 );
+    }
+
+    private static String getImageFormats()
+    {
+        StringBuilder retval = new StringBuilder();
+        String[] formats = ImageIO.getReaderFormatNames();
+        for( int i = 0; i < formats.length; i++ )
+        {
+           if (formats[i].equalsIgnoreCase(formats[i]))
+           {
+               retval.append( formats[i] );
+               if( i + 1 < formats.length )
+               {
+                   retval.append( ", " );
+               }
+           }
+        }
+        return retval.toString();
+    }
+
+    private static void changeCropBox(PDDocument document, float a, float b, float c, float d)
+    {
+        for (PDPage page : document.getPages())
+        {
+            System.out.println("resizing page");
+            PDRectangle rectangle = new PDRectangle();
+            rectangle.setLowerLeftX(a);
+            rectangle.setLowerLeftY(b);
+            rectangle.setUpperRightX(c);
+            rectangle.setUpperRightY(d);
+            page.setCropBox(rectangle);
+
+        }
+    }
+}
