diff options
author | Jay Berkenbilt <ejb@ql.org> | 2012-09-06 21:30:13 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2012-09-06 21:31:12 +0200 |
commit | c1627d04385a02045e7a1a5462f2a632fc529a2e (patch) | |
tree | 5d0943df09ae6548932c12654a42d66095ee3b1f /libqpdf | |
parent | fc4c82a9501d13a398682c308fc24c4427cfd77e (diff) | |
download | qpdf-c1627d04385a02045e7a1a5462f2a632fc529a2e.tar.zst |
Add QPDFWriter::setExtraHeaderText
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/QPDFWriter.cc | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index 19ab1359..eb08488a 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -196,6 +196,22 @@ QPDFWriter::forcePDFVersion(std::string const& version) } void +QPDFWriter::setExtraHeaderText(std::string const& text) +{ + this->extra_header_text = text; + if ((this->extra_header_text.length() > 0) && + (*(this->extra_header_text.rbegin()) != '\n')) + { + QTC::TC("qpdf", "QPDFWriter extra header text add newline"); + this->extra_header_text += "\n"; + } + else + { + QTC::TC("qpdf", "QPDFWriter extra header text no newline"); + } +} + +void QPDFWriter::setStaticID(bool val) { this->static_id = val; @@ -1832,6 +1848,12 @@ QPDFWriter::writeHeader() // it really should be treated as binary. writeString("\n%\xbf\xf7\xa2\xfe\n"); writeStringQDF("%QDF-1.0\n\n"); + + // Note: do not write extra header text here. Linearized PDFs + // must include the entire linearization parameter dictionary + // within the first 1024 characters of the PDF file, so for + // linearized files, we have to write extra header text after the + // linearization parameter dictionary. } void @@ -2189,7 +2211,9 @@ QPDFWriter::writeLinearized() // space to write real dictionary. 200 characters is enough // space if all numerical values in the parameter dictionary // that contain offsets are 20 digits long plus a few extra - // characters for safety. + // characters for safety. The entire linearization parameter + // dictionary must appear within the first 1024 characters of + // the file. qpdf_offset_t pos = this->pipeline->getCount(); openObject(lindict_id); @@ -2225,6 +2249,10 @@ QPDFWriter::writeLinearized() writePad(spaces); writeString("\n"); + // If the user supplied any additional header text, write it + // here after the linearization parameter dictionary. + writeString(this->extra_header_text); + // Part 3: first page cross reference table and trailer. qpdf_offset_t first_xref_offset = this->pipeline->getCount(); @@ -2396,6 +2424,7 @@ QPDFWriter::writeStandard() // Start writing writeHeader(); + writeString(this->extra_header_text); // Put root first on queue. QPDFObjectHandle trailer = pdf.getTrailer(); |