diff --git a/pdfcompare.php b/bin/pdfcompare.php
similarity index 50%
rename from pdfcompare.php
rename to bin/pdfcompare.php
index 1aa9d72..42c9a89 100644
--- a/pdfcompare.php
+++ b/bin/pdfcompare.php
@@ -19,35 +19,33 @@
along with this program. If not, see .
*/
+use ddn\sapp\AlmostOriginalLogger;
use ddn\sapp\PDFDoc;
-use function ddn\sapp\helpers\p_debug_var;
-use function ddn\sapp\helpers\p_debug;
-use ddn\sapp\pdfvalue\PDFValueObject;
-
-require_once('vendor/autoload.php');
-
-if ($argc !== 3)
- fwrite(STDERR, sprintf("usage: %s ", $argv[0]));
-else {
- if (!file_exists($argv[1])) {
- fwrite(STDERR, "failed to open file " . $argv[1]);
- die();
- }
- if (!file_exists($argv[2])) {
- fwrite(STDERR, "failed to open file " . $argv[2]);
- die();
- }
-
- $doc1 = PDFDoc::from_string(file_get_contents($argv[1]));
- if ($doc1 === false)
- fwrite(STDERR, "failed to parse file " . $argv[1]);
-
- $doc2 = PDFDoc::from_string(file_get_contents($argv[2]));
- if ($doc2 === false)
- fwrite(STDERR, "failed to parse file " . $argv[2]);
-
- $differences = $doc1->compare($doc2);
- foreach ($differences as $oid => $obj) {
- print($obj->to_pdf_entry());
- }
+
+require_once __DIR__ . '/../vendor/autoload.php';
+
+if ($argc !== 3) {
+ fwrite(STDERR, sprintf('usage: %s ', $argv[0]));
+ exit(1);
+}
+
+if (! file_exists($argv[1])) {
+ fwrite(STDERR, 'failed to open file ' . $argv[1]);
+ exit(1);
+}
+
+if (! file_exists($argv[2])) {
+ fwrite(STDERR, 'failed to open file ' . $argv[2]);
+ exit(1);
+}
+
+$doc1 = PDFDoc::from_string(file_get_contents($argv[1]));
+$doc1->setLogger(new AlmostOriginalLogger());
+
+$doc2 = PDFDoc::from_string(file_get_contents($argv[2]));
+$doc2->setLogger(new AlmostOriginalLogger());
+
+$differences = $doc1->compare($doc2);
+foreach ($differences as $obj) {
+ print $obj->to_pdf_entry();
}
diff --git a/bin/pdfdeflate.php b/bin/pdfdeflate.php
new file mode 100644
index 0000000..ab6f23e
--- /dev/null
+++ b/bin/pdfdeflate.php
@@ -0,0 +1,82 @@
+.
+*/
+
+use ddn\sapp\AlmostOriginalLogger;
+use ddn\sapp\PDFDoc;
+
+require_once __DIR__ . '/../vendor/autoload.php';
+
+if ($argc < 2 || $argc > 3) {
+ fwrite(STDERR, sprintf('usage: %s [oid]', $argv[0]));
+ exit(1);
+}
+
+if (! file_exists($argv[1])) {
+ fwrite(STDERR, 'failed to open file ' . $argv[1]);
+ exit(1);
+}
+
+$doc = PDFDoc::from_string(file_get_contents($argv[1]));
+$doc->setLogger(new AlmostOriginalLogger());
+
+$toid = null;
+if ($argc === 3) {
+ $toid = (int) $argv[2];
+}
+
+foreach ($doc->get_object_iterator() as $oid => $object) {
+ if ($toid !== null && $oid !== $toid) {
+ continue;
+ }
+
+ if ($object === false) {
+ continue;
+ }
+
+ if ($object['Filter'] === '/FlateDecode' && $object['Subtype'] !== '/Image') {
+ $stream = $object->get_stream(false);
+ if ($stream !== false) {
+ unset($object['Filter']);
+ $object->set_stream($stream, false);
+ $doc->add_object($object);
+ }
+ }
+
+ // Not needed because we are rebuilding the document
+ if ($object['Type'] === '/ObjStm') {
+ $object->set_stream('', false);
+ $doc->add_object($object);
+ }
+
+ // Do not want images to be uncompressed
+ if ($object['Subtype'] === '/Image') {
+ $object->set_stream('');
+ $doc->add_object($object);
+ }
+
+ if ($toid !== null) {
+ print $object->get_stream(false);
+ }
+}
+
+if ($toid === null) {
+ echo $doc->to_pdf_file_s(true);
+}
diff --git a/pdfrebuild.php b/bin/pdfrebuild.php
similarity index 60%
rename from pdfrebuild.php
rename to bin/pdfrebuild.php
index 609828f..a5eb57d 100644
--- a/pdfrebuild.php
+++ b/bin/pdfrebuild.php
@@ -19,25 +19,25 @@
along with this program. If not, see .
*/
+use ddn\sapp\AlmostOriginalLogger;
use ddn\sapp\PDFDoc;
-require_once('vendor/autoload.php');
-
-if (($argc < 2) || ($argc > 3))
- fwrite(STDERR, sprintf("usage: %s [