Commit bb89382f936fa373eb7ec6708d83e5713cada644

Authored by Jay Berkenbilt
1 parent dd1aca55

Allow --show-object=trailer

ChangeLog
1 1 2018-12-21 Jay Berkenbilt <ejb@ql.org>
2 2  
  3 + * Allow --show-object=trailer for showing the document trailer.
  4 +
3 5 * You can now use eval $(qpdf --completion-bash) to enable bash
4 6 completion for qpdf. It's not perfect, but it works pretty well.
5 7  
... ...
qpdf/qpdf.cc
... ... @@ -112,6 +112,7 @@ struct Options
112 112 check_linearization(false),
113 113 show_linearization(false),
114 114 show_xref(false),
  115 + show_trailer(false),
115 116 show_obj(0),
116 117 show_gen(0),
117 118 show_raw_stream_data(false),
... ... @@ -185,6 +186,7 @@ struct Options
185 186 bool check_linearization;
186 187 bool show_linearization;
187 188 bool show_xref;
  189 + bool show_trailer;
188 190 int show_obj;
189 191 int show_gen;
190 192 bool show_raw_stream_data;
... ... @@ -511,7 +513,7 @@ ArgParser::initOptionTable()
511 513 (*t)["show-linearization"] = oe_bare(&ArgParser::argShowLinearization);
512 514 (*t)["show-xref"] = oe_bare(&ArgParser::argShowXref);
513 515 (*t)["show-object"] = oe_requiredParameter(
514   - &ArgParser::argShowObject, "obj[,gen]");
  516 + &ArgParser::argShowObject, "trailer|obj[,gen]");
515 517 (*t)["raw-stream-data"] = oe_bare(&ArgParser::argRawStreamData);
516 518 (*t)["filtered-stream-data"] = oe_bare(&ArgParser::argFilteredStreamData);
517 519 (*t)["show-npages"] = oe_bare(&ArgParser::argShowNpages);
... ... @@ -929,14 +931,21 @@ ArgParser::argShowXref()
929 931 void
930 932 ArgParser::argShowObject(char* parameter)
931 933 {
932   - char* obj = parameter;
933   - char* gen = obj;
934   - if ((gen = strchr(obj, ',')) != 0)
  934 + if (strcmp(parameter, "trailer") == 0)
935 935 {
936   - *gen++ = 0;
937   - o.show_gen = QUtil::string_to_int(gen);
  936 + o.show_trailer = true;
  937 + }
  938 + else
  939 + {
  940 + char* obj = parameter;
  941 + char* gen = obj;
  942 + if ((gen = strchr(obj, ',')) != 0)
  943 + {
  944 + *gen++ = 0;
  945 + o.show_gen = QUtil::string_to_int(gen);
  946 + }
  947 + o.show_obj = QUtil::string_to_int(obj);
938 948 }
939   - o.show_obj = QUtil::string_to_int(obj);
940 949 o.require_outfile = false;
941 950 }
942 951  
... ... @@ -1453,7 +1462,8 @@ automated test suites for software that uses the qpdf library.\n\
1453 1462 --check-linearization check file integrity and linearization status\n\
1454 1463 --show-linearization check and show all linearization data\n\
1455 1464 --show-xref show the contents of the cross-reference table\n\
1456   ---show-object=obj[,gen] show the contents of the given object\n\
  1465 +--show-object=trailer|obj[,gen]\n\
  1466 + show the contents of the given object\n\
1457 1467 --raw-stream-data show raw stream data instead of object contents\n\
1458 1468 --filtered-stream-data show filtered stream data instead of object contents\n\
1459 1469 --show-npages print the number of pages in the file\n\
... ... @@ -2374,7 +2384,15 @@ static void do_check(QPDF&amp; pdf, Options&amp; o, int&amp; exit_code)
2374 2384  
2375 2385 static void do_show_obj(QPDF& pdf, Options& o, int& exit_code)
2376 2386 {
2377   - QPDFObjectHandle obj = pdf.getObjectByID(o.show_obj, o.show_gen);
  2387 + QPDFObjectHandle obj;
  2388 + if (o.show_trailer)
  2389 + {
  2390 + obj = pdf.getTrailer();
  2391 + }
  2392 + else
  2393 + {
  2394 + obj = pdf.getObjectByID(o.show_obj, o.show_gen);
  2395 + }
2378 2396 if (obj.isStream())
2379 2397 {
2380 2398 if (o.show_raw_stream_data || o.show_filtered_stream_data)
... ... @@ -2676,7 +2694,7 @@ static void do_inspection(QPDF&amp; pdf, Options&amp; o)
2676 2694 {
2677 2695 pdf.showXRefTable();
2678 2696 }
2679   - if (o.show_obj > 0)
  2697 + if ((o.show_obj > 0) || o.show_trailer)
2680 2698 {
2681 2699 do_show_obj(pdf, o, exit_code);
2682 2700 }
... ...
qpdf/qtest/qpdf.test
... ... @@ -2048,7 +2048,7 @@ $td-&gt;runtest(&quot;stream detected&quot;,
2048 2048 show_ntests();
2049 2049 # ----------
2050 2050 $td->notify("--- Extraction Tests ---");
2051   -$n_tests += 11;
  2051 +$n_tests += 12;
2052 2052  
2053 2053 $td->runtest("show xref",
2054 2054 {$td->COMMAND => "qpdf encrypted-with-images.pdf" .
... ... @@ -2122,6 +2122,12 @@ $td-&gt;runtest(&quot;show-xref-by-id-filtered&quot;,
2122 2122 {$td->FILE => "show-xref-by-id-filtered.out",
2123 2123 $td->EXIT_STATUS => 0});
2124 2124  
  2125 +$td->runtest("show trailer",
  2126 + {$td->COMMAND => "qpdf minimal.pdf --show-object=trailer"},
  2127 + {$td->FILE => "show-trailer.out",
  2128 + $td->EXIT_STATUS => 0},
  2129 + $td->NORMALIZE_NEWLINES);
  2130 +
2125 2131 show_ntests();
2126 2132 # ----------
2127 2133 $td->notify("--- Clear-text Metadata Tests ---");
... ...
qpdf/qtest/qpdf/show-trailer.out 0 → 100644
  1 +<< /Root 1 0 R /Size 7 >>
... ...