mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-02 22:50:20 +00:00
Add newline-before-endstream option (fixes #103)
This commit is contained in:
parent
6a7d53ad2b
commit
f37d399d82
@ -1,5 +1,11 @@
|
||||
2017-07-29 Jay Berkenbilt <ejb@ql.org>
|
||||
|
||||
* Add --newline-before-endstream command-line option and
|
||||
setNewlineBeforeEndstream method to QPDFWriter. This forces qpdf
|
||||
to always add a newline before the endstream keyword. It is a
|
||||
necessary but not sufficient condition for PDF/A compliance. Fixes
|
||||
#103.
|
||||
|
||||
* Handle zlib data errors when decoding streams. Fixes #106.
|
||||
|
||||
* Improve handling of files where the "stream" keyword is not
|
||||
|
@ -161,6 +161,11 @@ class QPDFWriter
|
||||
QPDF_DLL
|
||||
void setPreserveUnreferencedObjects(bool);
|
||||
|
||||
// Always write a newline before the endstream keyword. This helps
|
||||
// with PDF/A compliance, though it is not sufficient for it.
|
||||
QPDF_DLL
|
||||
void setNewlineBeforeEndstream(bool);
|
||||
|
||||
// Set the minimum PDF version. If the PDF version of the input
|
||||
// file (or previously set minimum version) is less than the
|
||||
// version passed to this method, the PDF version of the output
|
||||
@ -434,6 +439,7 @@ class QPDFWriter
|
||||
bool qdf_mode;
|
||||
bool precheck_streams;
|
||||
bool preserve_unreferenced_objects;
|
||||
bool newline_before_endstream;
|
||||
bool static_id;
|
||||
bool suppress_original_object_ids;
|
||||
bool direct_stream_lengths;
|
||||
|
@ -59,6 +59,7 @@ QPDFWriter::init()
|
||||
qdf_mode = false;
|
||||
precheck_streams = false;
|
||||
preserve_unreferenced_objects = false;
|
||||
newline_before_endstream = false;
|
||||
static_id = false;
|
||||
suppress_original_object_ids = false;
|
||||
direct_stream_lengths = true;
|
||||
@ -190,6 +191,12 @@ QPDFWriter::setPreserveUnreferencedObjects(bool val)
|
||||
this->preserve_unreferenced_objects = val;
|
||||
}
|
||||
|
||||
void
|
||||
QPDFWriter::setNewlineBeforeEndstream(bool val)
|
||||
{
|
||||
this->newline_before_endstream = val;
|
||||
}
|
||||
|
||||
void
|
||||
QPDFWriter::setMinimumPDFVersion(std::string const& version)
|
||||
{
|
||||
@ -1580,7 +1587,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
|
||||
char last_char = this->pipeline->getLastChar();
|
||||
popPipelineStack();
|
||||
|
||||
if (this->qdf_mode)
|
||||
if (this->qdf_mode || this->newline_before_endstream)
|
||||
{
|
||||
if (last_char != '\n')
|
||||
{
|
||||
|
10
qpdf/qpdf.cc
10
qpdf/qpdf.cc
@ -204,6 +204,7 @@ familiar with the PDF file format or who are PDF developers.\n\
|
||||
--ignore-xref-streams tells qpdf to ignore any cross-reference streams\n\
|
||||
--precheck-streams precheck ability to decode streams\n\
|
||||
--preserve-unreferenced preserve unreferenced objects\n\
|
||||
--newline-before-endstream always put a newline before endstream\n\
|
||||
--qdf turns on \"QDF mode\" (below)\n\
|
||||
--min-version=version sets the minimum PDF version of the output file\n\
|
||||
--force-version=version forces this to be the PDF version of the output file\n\
|
||||
@ -1032,6 +1033,7 @@ int main(int argc, char* argv[])
|
||||
bool qdf_mode = false;
|
||||
bool precheck_streams = false;
|
||||
bool preserve_unreferenced_objects = false;
|
||||
bool newline_before_endstream = false;
|
||||
std::string min_version;
|
||||
std::string force_version;
|
||||
|
||||
@ -1225,6 +1227,10 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
preserve_unreferenced_objects = true;
|
||||
}
|
||||
else if (strcmp(arg, "newline-before-endstream") == 0)
|
||||
{
|
||||
newline_before_endstream = true;
|
||||
}
|
||||
else if (strcmp(arg, "min-version") == 0)
|
||||
{
|
||||
if (parameter == 0)
|
||||
@ -1724,6 +1730,10 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
w.setPreserveUnreferencedObjects(true);
|
||||
}
|
||||
if (newline_before_endstream)
|
||||
{
|
||||
w.setNewlineBeforeEndstream(true);
|
||||
}
|
||||
if (normalize_set)
|
||||
{
|
||||
w.setContentNormalization(normalize);
|
||||
|
@ -206,7 +206,7 @@ $td->runtest("remove page we don't have",
|
||||
show_ntests();
|
||||
# ----------
|
||||
$td->notify("--- Miscellaneous Tests ---");
|
||||
$n_tests += 89;
|
||||
$n_tests += 91;
|
||||
|
||||
$td->runtest("qpdf version",
|
||||
{$td->COMMAND => "qpdf --version"},
|
||||
@ -618,6 +618,16 @@ $td->runtest("split content stream errors",
|
||||
$td->EXIT_STATUS => 3},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
|
||||
$td->runtest("newline before endstream",
|
||||
{$td->COMMAND =>
|
||||
"qpdf --static-id --newline-before-endstream" .
|
||||
" minimal.pdf a.pdf"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
$td->runtest("check output",
|
||||
{$td->FILE => "a.pdf"},
|
||||
{$td->FILE => "newline-before-endstream.pdf"});
|
||||
|
||||
|
||||
show_ntests();
|
||||
# ----------
|
||||
|
BIN
qpdf/qtest/qpdf/newline-before-endstream.pdf
Normal file
BIN
qpdf/qtest/qpdf/newline-before-endstream.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user