aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qtest
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2020-12-26 17:13:00 +0100
committerJay Berkenbilt <ejb@ql.org>2020-12-28 19:03:04 +0100
commitd4d7630cf544dc295202382026658b55bf49f76b (patch)
tree2a5796a99c99f0ee3d27db7f412923e697dd8781 /examples/qtest
parentac042d16cfe6efd1ff3295e1507558a2f87ec73f (diff)
downloadqpdf-d4d7630cf544dc295202382026658b55bf49f76b.tar.zst
Add pdf-custom-filter example
Diffstat (limited to 'examples/qtest')
-rw-r--r--examples/qtest/custom-filter.test47
-rw-r--r--examples/qtest/custom-filter/generalized.pdfbin0 -> 2091 bytes
-rw-r--r--examples/qtest/custom-filter/input.pdf149
-rw-r--r--examples/qtest/custom-filter/specialized.pdfbin0 -> 1750 bytes
4 files changed, 196 insertions, 0 deletions
diff --git a/examples/qtest/custom-filter.test b/examples/qtest/custom-filter.test
new file mode 100644
index 00000000..e674ea66
--- /dev/null
+++ b/examples/qtest/custom-filter.test
@@ -0,0 +1,47 @@
+#!/usr/bin/env perl
+require 5.008;
+use warnings;
+use strict;
+
+chdir("custom-filter") or die "chdir testdir failed: $!\n";
+
+require TestDriver;
+
+cleanup();
+
+my $td = new TestDriver('custom-filter');
+
+# The file input.pdf contains two streams, whose contents appear
+# uncompressed with explanatory text. They are marked with the keys
+# that pdf-custom-filter uses to decide 1) to re-encode using the
+# fictitious /XORDecode filter, and 2) whether to protect the stream
+# to prevent decoding using the custom filter even when decoding
+# specialized filters is requested.
+
+$td->runtest("custom filter, decode generalized",
+ {$td->COMMAND => "pdf-custom-filter input.pdf a.pdf"},
+ {$td->STRING => "pdf-custom-filter: new file written to a.pdf\n",
+ $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
+$td->runtest("check output",
+ {$td->FILE => "a.pdf"},
+ {$td->FILE => "generalized.pdf"});
+
+$td->runtest("custom filter, decode specialized",
+ {$td->COMMAND =>
+ "pdf-custom-filter --decode-specialized input.pdf a.pdf"},
+ {$td->STRING => "pdf-custom-filter: new file written to a.pdf\n",
+ $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
+$td->runtest("check output",
+ {$td->FILE => "a.pdf"},
+ {$td->FILE => "specialized.pdf"});
+
+cleanup();
+
+$td->report(4);
+
+sub cleanup
+{
+ unlink "a.pdf";
+}
diff --git a/examples/qtest/custom-filter/generalized.pdf b/examples/qtest/custom-filter/generalized.pdf
new file mode 100644
index 00000000..ca99f1fc
--- /dev/null
+++ b/examples/qtest/custom-filter/generalized.pdf
Binary files differ
diff --git a/examples/qtest/custom-filter/input.pdf b/examples/qtest/custom-filter/input.pdf
new file mode 100644
index 00000000..fc06786f
--- /dev/null
+++ b/examples/qtest/custom-filter/input.pdf
@@ -0,0 +1,149 @@
+%PDF-1.3
+%¿÷¢þ
+%QDF-1.0
+
+%% Original object ID: 1 0
+1 0 obj
+<<
+ /Pages 2 0 R
+ /Type /Catalog
+>>
+endobj
+
+%% Original object ID: 2 0
+2 0 obj
+<<
+ /Count 1
+ /Kids [
+ 3 0 R
+ ]
+ /Type /Pages
+>>
+endobj
+
+%% Page 1
+%% Original object ID: 3 0
+3 0 obj
+<<
+ /Contents 4 0 R
+ /MediaBox [
+ 0
+ 0
+ 612
+ 792
+ ]
+ /Parent 2 0 R
+ /Resources <<
+ /Font <<
+ /F1 6 0 R
+ >>
+ /ProcSet 7 0 R
+ >>
+ /Type /Page
+>>
+endobj
+
+%% Contents for page 1
+%% Original object ID: 4 0
+4 0 obj
+<<
+ /Length 5 0 R
+>>
+stream
+BT
+ /F1 24 Tf
+ 72 720 Td
+ (Potato) Tj
+ET
+endstream
+endobj
+
+5 0 obj
+44
+endobj
+
+%% Original object ID: 6 0
+6 0 obj
+<<
+ /BaseFont /Helvetica
+ /Encoding /WinAnsiEncoding
+ /Name /F1
+ /Subtype /Type1
+ /Type /Font
+>>
+endobj
+
+%% Original object ID: 5 0
+7 0 obj
+[
+ /PDF
+ /Text
+]
+endobj
+
+8 0 obj
+<<
+ /Length 9 0 R
+ /DoXOR true
+>>
+stream
+
+This stream has /DoXOR true. When processed with pdf-custom-filter
+without the --decode-specialized option, the stream will appear in the
+output encoded with the fictitious /XORDecode filter, and its
+/DecodeParms will contain a reference to the key stream. When
+processed with pdf-custom-filter with the --decode-specialized option,
+it will appear in the output as a regular stream with /FlateDecode,
+but the /OrigLength key will still have been added.
+
+endstream
+endobj
+
+9 0 obj
+455
+endobj
+
+10 0 obj
+<<
+ /Length 11 0 R
+ /DoXOR true
+ /ProtectXOR true
+>>
+stream
+
+This stream has /DoXOR true and /ProtectXOR true. When processed with
+pdf-custom-filter with or without the --decode-specialized option, the
+stream will appear in the output encoded with the fictitious
+/XORDecode filter, and its /DecodeParms will contain a reference to
+the key stream.
+
+endstream
+endobj
+
+11 0 obj
+288
+endobj
+
+xref
+0 12
+0000000000 65535 f
+0000000052 00000 n
+0000000133 00000 n
+0000000242 00000 n
+0000000484 00000 n
+0000000583 00000 n
+0000000629 00000 n
+0000000774 00000 n
+0000000809 00000 n
+0000001333 00000 n
+0000001353 00000 n
+0000001731 00000 n
+trailer <<
+ /Root 1 0 R
+ /Size 12
+ /Example [ 8 0 R 10 0 R ]
+ /ID [<01f4bb169ae6e6b5f27505733e9abf42><01f4bb169ae6e6b5f27505733e9abf42>]
+>>
+startxref
+1752
+%%EOF
diff --git a/examples/qtest/custom-filter/specialized.pdf b/examples/qtest/custom-filter/specialized.pdf
new file mode 100644
index 00000000..f8c8cdde
--- /dev/null
+++ b/examples/qtest/custom-filter/specialized.pdf
Binary files differ