]> _ Git - fluidbook_tools.git/commitdiff
wip #4666 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 15 Sep 2021 16:37:05 +0000 (18:37 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 15 Sep 2021 16:37:05 +0000 (18:37 +0200)
.gitignore
.idea/artifacts/fwstk.xml [new file with mode: 0644]
.idea/deployment.xml
.idea/fluidbook_tools.iml
.idea/misc.xml
resources/tools/fwstk/src/com/fluidbook/fwstk/Main.java
src/PDF/Document.php

index d85eee5599d52395129d6250bf4c392d9389c427..1e01c5e615f76c16c9535719c09904adc871f28a 100644 (file)
@@ -23,3 +23,5 @@ Homestead.json
 /.vagrant
 .phpunit.result.cache
 
+resources/tools/fwstk/bin
+resources/tools/fwstk/out
diff --git a/.idea/artifacts/fwstk.xml b/.idea/artifacts/fwstk.xml
new file mode 100644 (file)
index 0000000..d3548ed
--- /dev/null
@@ -0,0 +1,21 @@
+<component name="ArtifactManager">
+  <artifact type="jar" name="fwstk">
+    <output-path>$PROJECT_DIR$/resources/tools/fwstk/out/artifacts/fwstk_jar</output-path>
+    <root id="archive" name="fwstk.jar">
+      <element id="file-copy" path="$PROJECT_DIR$/resources/tools/fwstk/lib/avalon-framework-4.1.4.jar" />
+      <element id="file-copy" path="$PROJECT_DIR$/resources/tools/fwstk/lib/bcmail-jdk16-146.jar" />
+      <element id="module-output" name="fluidbook_tools" />
+      <element id="file-copy" path="$PROJECT_DIR$/resources/tools/fwstk/lib/bcprov-jdk16-146.jar" />
+      <element id="file-copy" path="$PROJECT_DIR$/resources/tools/fwstk/lib/commons-lang3-3.10.jar" />
+      <element id="file-copy" path="$PROJECT_DIR$/resources/tools/fwstk/lib/commons-io-2.6.jar" />
+      <element id="file-copy" path="$PROJECT_DIR$/resources/tools/fwstk/lib/commons-logging-1.2.jar" />
+      <element id="file-copy" path="$PROJECT_DIR$/resources/tools/fwstk/lib/commons-text-1.8.jar" />
+      <element id="file-copy" path="$PROJECT_DIR$/resources/tools/fwstk/lib/fontbox-1.8.16.jar" />
+      <element id="file-copy" path="$PROJECT_DIR$/resources/tools/fwstk/lib/jempbox-1.8.16.jar" />
+      <element id="file-copy" path="$PROJECT_DIR$/resources/tools/fwstk/lib/pdfbox-1.8.16.jar" />
+      <element id="directory" name="META-INF">
+        <element id="file-copy" path="$PROJECT_DIR$/resources/tools/fwstk/MANIFEST.MF" />
+      </element>
+    </root>
+  </artifact>
+</component>
\ No newline at end of file
index a03963bb735ea3f2d9586fd214ca8e5367cf1a46..5e83037009ca9c239088a81640f8c8282272c4ca 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
-  <component name="PublishConfigData" autoUpload="Always" serverName="odl.cube" remoteFilesAllowedToDisappearOnAutoupload="false">
+  <component name="PublishConfigData" autoUpload="Always" serverName="odl.cube" remoteFilesAllowedToDisappearOnAutoupload="false" autoUploadExternalChanges="true">
     <serverData>
       <paths name="apps.fluidbook.com">
         <serverdata>
index c30c3f674adb421057fa93d34b47589bb9c0edfc..192d0126cb4992f567481b79c0834c9c6a23827d 100644 (file)
@@ -1,8 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <module type="JAVA_MODULE" version="4">
-  <component name="NewModuleRootManager" inherit-compiler-output="true">
+  <component name="NewModuleRootManager">
+    <output url="file://$MODULE_DIR$/resources/tools/fwstk/bin" />
+    <output-test url="file://$MODULE_DIR$/out/test/fluidbook_tools" />
     <exclude-output />
     <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/resources/tools/fwstk/project_resources" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/resources/tools/fwstk/src" isTestSource="false" />
       <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="Fluidbook\Tools\" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/brick/math" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/debug" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/maximebf/debugbar" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/laravel-debugbar" />
+      <excludeFolder url="file://$MODULE_DIR$/resources/tools/fwstk/bin" />
+      <excludeFolder url="file://$MODULE_DIR$/resources/tools/fwstk/out" />
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="module-library" exported="">
+      <library>
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/resources/tools/fwstk/lib/avalon-framework-4.1.4.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/resources/tools/fwstk/lib/bcmail-jdk16-146.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/resources/tools/fwstk/lib/bcprov-jdk16-146.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/resources/tools/fwstk/lib/commons-io-2.6.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/resources/tools/fwstk/lib/commons-lang3-3.10.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/resources/tools/fwstk/lib/commons-logging-1.2.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/resources/tools/fwstk/lib/commons-text-1.8.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/resources/tools/fwstk/lib/fontbox-1.8.16.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/resources/tools/fwstk/lib/jempbox-1.8.16.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/resources/tools/fwstk/lib/pdfbox-1.8.16.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
   </component>
 </module>
\ No newline at end of file
index b658e95a34610ea9e0f9538c2169bd1c5cf93c12..ff9d5a0175db081a6a47d5c3aff62bb4885cbb31 100644 (file)
@@ -3,7 +3,7 @@
   <component name="AhkProjectSettings">
     <option name="defaultAhkSdk" value="AutoHotkey" />
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_6">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK17" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/out" />
   </component>
 </project>
\ No newline at end of file
index 4c3ffc598f1c569537ebe28da3f39ec22c9801d4..56ae470861536b65216eb85b23ad8fdd09e6c8c1 100644 (file)
@@ -11,6 +11,8 @@ import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.List;
 
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.text.StringEscapeUtils;
 import org.apache.pdfbox.exceptions.COSVisitorException;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDDocumentInformation;
@@ -44,16 +46,16 @@ import org.apache.pdfbox.util.PDFImageWriter;
 
 public class Main {
 
-    private static String version = "0.93";
-    private static String date = "20110904";
+    private static String version = "0.94";
+    private static String date = "20210915";
     static int threads = 1;
     static String input = "";
     static Float linkOffsetX = 0.0f;
     static Float linkOffsetY = 0.0f;
 
     public static void main(String[] args) throws IOException,
-            COSVisitorException, ClassNotFoundException, NullPointerException,
-            InterruptedException {
+        COSVisitorException, ClassNotFoundException, NullPointerException,
+        InterruptedException {
 
         if (args.length < 0) {
             printUsage();
@@ -91,7 +93,7 @@ public class Main {
                     printVersion();
                     return;
                 } else if (args[i].trim().compareTo("-h") == 0
-                        || args[i].trim().compareTo("--help") == 0) {
+                    || args[i].trim().compareTo("--help") == 0) {
                     printUsage();
                     return;
                 } else if (args[i].trim().compareTo("--trim") == 0) {
@@ -242,10 +244,10 @@ public class Main {
             stripper.process(nextPage, i);
             Page layout = stripper.getLayout();
             BufferedWriter out
-                    = new BufferedWriter(
-                    new OutputStreamWriter(
-                            new FileOutputStream(layoutOutput.replace("%d", ""
-                                    + i)), "UTF-8"));
+                = new BufferedWriter(
+                new OutputStreamWriter(
+                    new FileOutputStream(layoutOutput.replace("%d", ""
+                        + i)), "UTF-8"));
             out.write(layout.asJSON());
             out.close();
         }
@@ -253,10 +255,11 @@ public class Main {
 
     private static Boolean getInfos(PDDocument doc) throws IOException, COSVisitorException {
         ArrayList<String> res = new ArrayList<>();
+        res.add("Parsed by FWSTK: \t\t\t" + Main.version + " (" + Main.date + ")");
         // General informations
         String[] fields = {"Author", "Title", "CreationDate", "Creator",
-                "Keywords", "ModificationDate", "Producer", "Subject",
-                "Trapped", "Version"};
+            "Keywords", "ModificationDate", "Producer", "Subject",
+            "Trapped", "Version"};
         PDDocumentInformation infos = doc.getDocumentInformation();
         for (String k : fields) {
             String v = infos.getCustomMetadataValue(k);
@@ -268,6 +271,7 @@ public class Main {
         List<PDPage> list = doc.getDocumentCatalog().getAllPages();
         int pages = list.size();
 
+
         res.add("Pages:\t\t\t" + pages);
         Boolean changes = false;
         for (int i = 0; i < pages; i++) {
@@ -299,47 +303,47 @@ public class Main {
 
             // Size
             if (page.getRotation() != null
-                    && (page.getRotation() == 90 || page.getRotation() == 270)) {
+                && (page.getRotation() == 90 || page.getRotation() == 270)) {
                 res.add("Page " + numero + " size:\t\t"
-                        + Math.abs(cropBox.getHeight()) + " pts x "
-                        + Math.abs(cropBox.getWidth()) + " pts");
+                    + Math.abs(cropBox.getHeight()) + " pts x "
+                    + Math.abs(cropBox.getWidth()) + " pts");
                 // Boxes
                 res.add("Page " + numero + " CropBox:\t"
-                        + cropBox.getLowerLeftY() + "\t"
-                        + cropBox.getUpperRightX() + "\t"
-                        + cropBox.getUpperRightY() + "\t"
-                        + cropBox.getLowerLeftX() + "\t");
+                    + cropBox.getLowerLeftY() + "\t"
+                    + cropBox.getUpperRightX() + "\t"
+                    + cropBox.getUpperRightY() + "\t"
+                    + cropBox.getLowerLeftX() + "\t");
                 res.add("Page " + numero + " MediaBox:\t"
-                        + mediaBox.getLowerLeftY() + "\t"
-                        + mediaBox.getUpperRightX() + "\t"
-                        + mediaBox.getUpperRightY() + "\t"
-                        + mediaBox.getLowerLeftX() + "\t");
+                    + mediaBox.getLowerLeftY() + "\t"
+                    + mediaBox.getUpperRightX() + "\t"
+                    + mediaBox.getUpperRightY() + "\t"
+                    + mediaBox.getLowerLeftX() + "\t");
                 res.add("Page " + numero + " TrimBox:\t"
-                        + trimBox.getLowerLeftY() + "\t"
-                        + trimBox.getUpperRightX() + "\t"
-                        + trimBox.getUpperRightY() + "\t"
-                        + trimBox.getLowerLeftX() + "\t");
+                    + trimBox.getLowerLeftY() + "\t"
+                    + trimBox.getUpperRightX() + "\t"
+                    + trimBox.getUpperRightY() + "\t"
+                    + trimBox.getLowerLeftX() + "\t");
             } else {
 
                 res.add("Page " + numero + " size:\t\t"
-                        + Math.abs(cropBox.getWidth()) + " pts x "
-                        + Math.abs(cropBox.getHeight()) + " pts");
+                    + Math.abs(cropBox.getWidth()) + " pts x "
+                    + Math.abs(cropBox.getHeight()) + " pts");
                 // Boxes
                 res.add("Page " + numero + " CropBox:\t"
-                        + cropBox.getLowerLeftX() + "\t"
-                        + cropBox.getUpperRightY() + "\t"
-                        + cropBox.getUpperRightX() + "\t"
-                        + cropBox.getLowerLeftY() + "\t");
+                    + cropBox.getLowerLeftX() + "\t"
+                    + cropBox.getUpperRightY() + "\t"
+                    + cropBox.getUpperRightX() + "\t"
+                    + cropBox.getLowerLeftY() + "\t");
                 res.add("Page " + numero + " MediaBox:\t"
-                        + mediaBox.getLowerLeftX() + "\t"
-                        + mediaBox.getUpperRightY() + "\t"
-                        + mediaBox.getUpperRightX() + "\t"
-                        + mediaBox.getLowerLeftY() + "\t");
+                    + mediaBox.getLowerLeftX() + "\t"
+                    + mediaBox.getUpperRightY() + "\t"
+                    + mediaBox.getUpperRightX() + "\t"
+                    + mediaBox.getLowerLeftY() + "\t");
                 res.add("Page " + numero + " TrimBox:\t"
-                        + trimBox.getLowerLeftX() + "\t"
-                        + trimBox.getUpperRightY() + "\t"
-                        + trimBox.getUpperRightX() + "\t"
-                        + trimBox.getLowerLeftY() + "\t");
+                    + trimBox.getLowerLeftX() + "\t"
+                    + trimBox.getUpperRightY() + "\t"
+                    + trimBox.getUpperRightX() + "\t"
+                    + trimBox.getLowerLeftY() + "\t");
             }
         }
 
@@ -356,7 +360,7 @@ public class Main {
         }
 
         for (String s : res) {
-            System.out.println(s);
+            System.out.println(StringUtils.trim(s));
         }
 
         return changes;
@@ -392,17 +396,17 @@ public class Main {
             }
         }
         res.add("NumberSectionsDelimiters:\t\t"
-                + delimiters.substring(0, delimiters.length() - 1));
+            + delimiters.substring(0, delimiters.length() - 1));
     }
 
     private static void addBookmark(PDDocument doc, ArrayList<String> res,
                                     PDOutlineNode bookmark, int level) throws IOException {
         PDOutlineItem current = bookmark.getFirstChild();
         while (current != null) {
-            res.add("BookmarkTitle:\t\t" + current.getTitle().trim());
+            res.add("BookmarkTitle:\t\t" + StringEscapeUtils.escapeHtml4(current.getTitle()));
             res.add("BookmarkLevel:\t\t" + level);
             res.add("BookmarkPage:\t\t"
-                    + getPageFromAction(doc, current.getAction()));
+                + getPageFromAction(doc, current.getAction()));
             addBookmark(doc, res, current, level + 1);
             current = current.getNextSibling();
         }
@@ -410,10 +414,10 @@ public class Main {
 
     private static void cutDocument(PDDocument doc, String input,
                                     String output, String cutmode) throws COSVisitorException,
-            IOException {
+        IOException {
 
         System.out.println("Cut document of " + doc.getNumberOfPages()
-                + " with mode " + cutmode);
+            + " with mode " + cutmode);
 
         ArrayList<PDDocument> copies = duplicatePages(doc, input, cutmode);
         cutPages(doc, cutmode);
@@ -464,8 +468,8 @@ public class Main {
             newbox.move(decalage, 0f);
 
             System.out.println("Set cropbox of page " + page + " from "
-                    + pdfPage.getCropBox() + " to " + newbox + " (offset : "
-                    + decalage + ")");
+                + pdfPage.getCropBox() + " to " + newbox + " (offset : "
+                + decalage + ")");
 
             pdfPage.setCropBox(newbox);
             pdfPage.setMediaBox(newbox);
@@ -519,7 +523,7 @@ public class Main {
                 continue;
             }
             System.out.println("Duplicate page " + page + " :: cursor is at "
-                    + cursor);
+                + cursor);
             // Duplicate page
             for (int j = 0; j < duplicateTime; j++) {
                 List<PDPage> l = copies.get(j).getDocumentCatalog().getAllPages();
@@ -541,7 +545,7 @@ public class Main {
 
     private void extractTexts(PDDocument doc, String textsOutput, String method,
                               Integer[] pages, String ignoredSeparators, String input) throws IOException, ClassNotFoundException,
-            NullPointerException, InterruptedException {
+        NullPointerException, InterruptedException {
 
         long s = Calendar.getInstance().getTimeInMillis();
 
@@ -551,7 +555,7 @@ public class Main {
         PDDocument d;
 
         int totalThreads = Math.max(1,
-                Math.min(Math.round(pages.length / 50.0f), Main.threads));
+            Math.min(Math.round(pages.length / 50.0f), Main.threads));
 
         System.out.println("Total threads " + totalThreads);
 
@@ -577,13 +581,13 @@ public class Main {
         }
 
         System.out.println("Extraction des textes with " + method + " : "
-                + ((Calendar.getInstance().getTimeInMillis() - s) / 1000)
-                + "s");
+            + ((Calendar.getInstance().getTimeInMillis() - s) / 1000)
+            + "s");
     }
 
     public static void updateCropBox(PDDocument doc, String output,
                                      String refbox, Integer[] pages, String defined) throws IOException,
-            COSVisitorException {
+        COSVisitorException {
         System.out.println("updateCropBox");
         if (!"".equals(defined)) {
             updateCropBoxDefined(doc, defined);
@@ -596,7 +600,7 @@ public class Main {
     }
 
     private static void updateCropBoxDefined(PDDocument doc, String defined)
-            throws IOException, COSVisitorException {
+        throws IOException, COSVisitorException {
         String[] e = defined.split("*");
         for (int i = 0; i < e.length; i++) {
             String[] e1 = e[i].split(",");
@@ -674,7 +678,7 @@ public class Main {
     }
 
     public static void saveLinks(String file, ArrayList<Link> listLinks)
-            throws IOException {
+        throws IOException {
         FileIO out = new FileIO(file);
         out.open("w");
         out.output.writeBytes(Link.header());
@@ -745,7 +749,7 @@ public class Main {
     }
 
     public static ArrayList<Link> extractLinksOfPage(PDDocument doc, int pageNumber, PDPage p)
-            throws IOException {
+        throws IOException {
         System.out.println(pageNumber);
         ArrayList<Link> listLinks = new ArrayList<>();
         Link myLink;
@@ -804,7 +808,7 @@ public class Main {
                 System.out.println(link.getRectangle().getHeight());
                 myLink.rect = link.getRectangle();
                 if (myLink.rect.getWidth() == 0.0
-                        || myLink.rect.getHeight() == 0.0) {
+                    || myLink.rect.getHeight() == 0.0) {
                     System.out.println("Skip link :: surface == 0");
                     continue;
                 }
index 7f1d39a999db1ee2ad531642aba8ad836f9c47cf..96d6691521079a5a8db550ddd7507d5ae5d78e38 100644 (file)
@@ -89,7 +89,6 @@ class Document
         $lines = Text::explodeNewLines($infos);
         $bookmark_id = -1;
 
-
         foreach ($lines as $line) {
             $line = trim($line);
             [$k, $v] = explode(':', $line);
@@ -98,7 +97,7 @@ class Document
 
             if ($k === 'BookmarkTitle') {
                 $bookmark_id++;
-                $this->chapters[$bookmark_id] = array('label' => str_replace('&#13;', '', $v));
+                $this->chapters[$bookmark_id] = array('label' => html_entity_decode($v));
             } elseif ($k === 'BookmarkLevel') {
                 $this->chapters[$bookmark_id]['level'] = (int)$v - 1;
             } elseif ($k === 'BookmarkPage') {