diff --git a/Userland/Libraries/LibPDF/Page.cpp b/Userland/Libraries/LibPDF/Page.cpp index efdefc38d4..c8d86cdcf8 100644 --- a/Userland/Libraries/LibPDF/Page.cpp +++ b/Userland/Libraries/LibPDF/Page.cpp @@ -19,13 +19,18 @@ PDFErrorOr Page::page_contents(Document& document) const // "The value may be either a single stream or an array of streams. If the value // is an array, the effect is as if all the streams in the array were concatenated, - // in order, to form a single stream." + // in order, to form a single stream. The division between streams may occur only at + // the boundaries between lexical tokens" if (contents->is()) return TRY(ByteBuffer::copy(contents->cast()->bytes())); + // If one stream ends with (say) a `Q` and the next starts with `q`, that should be + // two distinct tokens. Insert spaces between stream contents to ensure that. ByteBuffer byte_buffer; - for (auto& ref : *contents->cast()) + for (auto& ref : *contents->cast()) { TRY(byte_buffer.try_append(TRY(document.resolve_to(ref))->bytes())); + TRY(byte_buffer.try_append(' ')); + } return byte_buffer; }