From c22babf3c4c3db536895fd18fbf820aeff5b4bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Fri, 23 Dec 2022 16:55:47 +0100 Subject: [PATCH] Update Length when setting new data in stream --- src/uPDFTypes.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/uPDFTypes.cpp b/src/uPDFTypes.cpp index ccd2dd0..8f9b5e3 100644 --- a/src/uPDFTypes.cpp +++ b/src/uPDFTypes.cpp @@ -73,7 +73,9 @@ namespace uPDFParser for(it = _value.begin(); it!=_value.end(); it++) { - if (res.size() > 1) + if (res.size() > 1 && + (*it)->type() != DataType::TYPE::INTEGER && + (*it)->type() != DataType::TYPE::REAL) res += " "; res += (*it)->str(); } @@ -103,8 +105,12 @@ namespace uPDFParser std::string Stream::str() { - std::string res = "stream\n"; + std::string res = "stream"; const char* streamData = (const char*)data(); // Force reading if not in memory + if (_dataLength && + streamData[0] != '\n' && + streamData[0] != '\r') + res += "\n"; res += std::string(streamData, _dataLength); // Be sure there is a final line return if (_dataLength && @@ -141,7 +147,10 @@ namespace uPDFParser { if (_data && freeData) delete[] _data; - + + dict.deleteKey("Length"); + dict.addData("Length", new Integer(dataLength)); + this->_data = data; this->_dataLength = dataLength; this->freeData = freeData;