Commit bb89382f936fa373eb7ec6708d83e5713cada644

Authored by Jay Berkenbilt
1 parent dd1aca55

Allow --show-object=trailer

ChangeLog
1 2018-12-21 Jay Berkenbilt <ejb@ql.org> 1 2018-12-21 Jay Berkenbilt <ejb@ql.org>
2 2
  3 + * Allow --show-object=trailer for showing the document trailer.
  4 +
3 * You can now use eval $(qpdf --completion-bash) to enable bash 5 * You can now use eval $(qpdf --completion-bash) to enable bash
4 completion for qpdf. It's not perfect, but it works pretty well. 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,6 +112,7 @@ struct Options
112 check_linearization(false), 112 check_linearization(false),
113 show_linearization(false), 113 show_linearization(false),
114 show_xref(false), 114 show_xref(false),
  115 + show_trailer(false),
115 show_obj(0), 116 show_obj(0),
116 show_gen(0), 117 show_gen(0),
117 show_raw_stream_data(false), 118 show_raw_stream_data(false),
@@ -185,6 +186,7 @@ struct Options @@ -185,6 +186,7 @@ struct Options
185 bool check_linearization; 186 bool check_linearization;
186 bool show_linearization; 187 bool show_linearization;
187 bool show_xref; 188 bool show_xref;
  189 + bool show_trailer;
188 int show_obj; 190 int show_obj;
189 int show_gen; 191 int show_gen;
190 bool show_raw_stream_data; 192 bool show_raw_stream_data;
@@ -511,7 +513,7 @@ ArgParser::initOptionTable() @@ -511,7 +513,7 @@ ArgParser::initOptionTable()
511 (*t)["show-linearization"] = oe_bare(&ArgParser::argShowLinearization); 513 (*t)["show-linearization"] = oe_bare(&ArgParser::argShowLinearization);
512 (*t)["show-xref"] = oe_bare(&ArgParser::argShowXref); 514 (*t)["show-xref"] = oe_bare(&ArgParser::argShowXref);
513 (*t)["show-object"] = oe_requiredParameter( 515 (*t)["show-object"] = oe_requiredParameter(
514 - &ArgParser::argShowObject, "obj[,gen]"); 516 + &ArgParser::argShowObject, "trailer|obj[,gen]");
515 (*t)["raw-stream-data"] = oe_bare(&ArgParser::argRawStreamData); 517 (*t)["raw-stream-data"] = oe_bare(&ArgParser::argRawStreamData);
516 (*t)["filtered-stream-data"] = oe_bare(&ArgParser::argFilteredStreamData); 518 (*t)["filtered-stream-data"] = oe_bare(&ArgParser::argFilteredStreamData);
517 (*t)["show-npages"] = oe_bare(&ArgParser::argShowNpages); 519 (*t)["show-npages"] = oe_bare(&ArgParser::argShowNpages);
@@ -929,14 +931,21 @@ ArgParser::argShowXref() @@ -929,14 +931,21 @@ ArgParser::argShowXref()
929 void 931 void
930 ArgParser::argShowObject(char* parameter) 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 o.require_outfile = false; 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,7 +1462,8 @@ automated test suites for software that uses the qpdf library.\n\
1453 --check-linearization check file integrity and linearization status\n\ 1462 --check-linearization check file integrity and linearization status\n\
1454 --show-linearization check and show all linearization data\n\ 1463 --show-linearization check and show all linearization data\n\
1455 --show-xref show the contents of the cross-reference table\n\ 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 --raw-stream-data show raw stream data instead of object contents\n\ 1467 --raw-stream-data show raw stream data instead of object contents\n\
1458 --filtered-stream-data show filtered stream data instead of object contents\n\ 1468 --filtered-stream-data show filtered stream data instead of object contents\n\
1459 --show-npages print the number of pages in the file\n\ 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,7 +2384,15 @@ static void do_check(QPDF&amp; pdf, Options&amp; o, int&amp; exit_code)
2374 2384
2375 static void do_show_obj(QPDF& pdf, Options& o, int& exit_code) 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 if (obj.isStream()) 2396 if (obj.isStream())
2379 { 2397 {
2380 if (o.show_raw_stream_data || o.show_filtered_stream_data) 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,7 +2694,7 @@ static void do_inspection(QPDF&amp; pdf, Options&amp; o)
2676 { 2694 {
2677 pdf.showXRefTable(); 2695 pdf.showXRefTable();
2678 } 2696 }
2679 - if (o.show_obj > 0) 2697 + if ((o.show_obj > 0) || o.show_trailer)
2680 { 2698 {
2681 do_show_obj(pdf, o, exit_code); 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,7 +2048,7 @@ $td-&gt;runtest(&quot;stream detected&quot;,
2048 show_ntests(); 2048 show_ntests();
2049 # ---------- 2049 # ----------
2050 $td->notify("--- Extraction Tests ---"); 2050 $td->notify("--- Extraction Tests ---");
2051 -$n_tests += 11; 2051 +$n_tests += 12;
2052 2052
2053 $td->runtest("show xref", 2053 $td->runtest("show xref",
2054 {$td->COMMAND => "qpdf encrypted-with-images.pdf" . 2054 {$td->COMMAND => "qpdf encrypted-with-images.pdf" .
@@ -2122,6 +2122,12 @@ $td-&gt;runtest(&quot;show-xref-by-id-filtered&quot;, @@ -2122,6 +2122,12 @@ $td-&gt;runtest(&quot;show-xref-by-id-filtered&quot;,
2122 {$td->FILE => "show-xref-by-id-filtered.out", 2122 {$td->FILE => "show-xref-by-id-filtered.out",
2123 $td->EXIT_STATUS => 0}); 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 show_ntests(); 2131 show_ntests();
2126 # ---------- 2132 # ----------
2127 $td->notify("--- Clear-text Metadata Tests ---"); 2133 $td->notify("--- Clear-text Metadata Tests ---");
qpdf/qtest/qpdf/show-trailer.out 0 → 100644
  1 +<< /Root 1 0 R /Size 7 >>