From c1627d04385a02045e7a1a5462f2a632fc529a2e Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 6 Sep 2012 15:30:13 -0400 Subject: Add QPDFWriter::setExtraHeaderText --- libqpdf/QPDFWriter.cc | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'libqpdf/QPDFWriter.cc') diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index 19ab1359..eb08488a 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -195,6 +195,22 @@ QPDFWriter::forcePDFVersion(std::string const& version) this->forced_pdf_version = 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) { @@ -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(); -- cgit v1.2.3-54-g00ecf