11#ifndef INCLUDED_VCL_FILTER_PDFDOCUMENT_HXX
12#define INCLUDED_VCL_FILTER_PDFDOCUMENT_HXX
20#include <rtl/strbuf.hxx>
31template <
class interface_type>
class Reference;
41class PDFTrailerElement;
42class PDFReferenceElement;
44class PDFDictionaryElement;
46class PDFStreamElement;
47class PDFNumberElement;
52 bool m_bVisiting =
false;
53 bool m_bParsing =
false;
61 void setParsing(
bool bParsing) { m_bParsing = bParsing; }
101 void parseIfNecessary();
106 PDFElement* Lookup(
const OString& rDictionaryKey);
108 double GetObjectValue()
const;
109 void SetDictionaryOffset(sal_uInt64 nDictionaryOffset);
110 sal_uInt64 GetDictionaryOffset();
111 void SetDictionaryLength(sal_uInt64 nDictionaryLength);
112 sal_uInt64 GetDictionaryLength();
118 const std::map<OString, PDFElement*>& GetDictionaryItems();
119 const std::vector<PDFReferenceElement*>& GetDictionaryReferences()
const;
125 void SetArrayOffset(sal_uInt64 nArrayOffset);
126 sal_uInt64 GetArrayOffset()
const;
127 void SetArrayLength(sal_uInt64 nArrayLength);
128 sal_uInt64 GetArrayLength()
const;
131 void ParseStoredObjects();
132 std::vector<std::unique_ptr<PDFElement>>& GetStoredElements();
134 void SetStreamBuffer(std::unique_ptr<SvMemoryStream>& pStreamBuffer);
137 void writeString(OStringBuffer& )
override { assert(
false &&
"not implemented"); }
151 const std::vector<PDFElement*>& GetElements()
const;
156 rBuffer.append(
"[ ");
159 rElement->writeString(rBuffer);
173 sal_uInt64 m_nOffset = 0;
182 double LookupNumber(
SvStream& rStream)
const;
185 int GetObjectValue()
const;
186 int GetGenerationValue()
const;
187 sal_uInt64 GetOffset()
const;
192 rBuffer.append(sal_Int32(GetObjectValue()));
194 rBuffer.append(sal_Int32(GetGenerationValue()));
195 rBuffer.append(
" R");
210 sal_uInt64 GetOffset()
const;
215 rBuffer.append(
"stream\n");
216 rBuffer.append(
static_cast<const char*
>(m_aMemory.
GetData()), m_aMemory.
GetSize());
217 rBuffer.append(
"\nendstream\n");
226 sal_uInt64 m_nLocation = 0;
231 void SetValue(
const OString& rValue) { m_aValue = rValue; }
233 sal_uInt64 GetLocation()
const;
234 sal_uInt64
GetLength()
const {
return m_aValue.getLength(); }
239 rBuffer.append(m_aValue);
249 sal_uInt64 m_nLocation = 0;
259 static PDFElement* Lookup(
const std::map<OString, PDFElement*>& rDictionary,
260 const OString& rKey);
261 void SetKeyOffset(
const OString& rKey, sal_uInt64 nOffset);
262 sal_uInt64 GetKeyOffset(
const OString& rKey)
const;
263 void SetKeyValueLength(
const OString& rKey, sal_uInt64 nLength);
264 sal_uInt64 GetKeyValueLength(
const OString& rKey)
const;
265 const std::map<OString, PDFElement*>& GetItems()
const;
269 PDFElement* LookupElement(
const OString& rDictionaryKey);
273 m_aItems.emplace(rKey, pPDFElement);
278 rBuffer.append(
"<< ");
279 for (
auto& rPair : m_aItems)
282 rBuffer.append(rPair.first);
284 rPair.second->writeString(rBuffer);
287 rBuffer.append(
">>");
356 rBuffer.append(m_aValue);
373 rBuffer.append(m_aValue);
382 sal_uInt64 m_nOffset = 0;
391 void SetValue(
double fValue) { m_fValue = fValue; }
393 sal_uInt64 GetLocation()
const;
394 sal_uInt64 GetLength()
const;
396 void writeString(OStringBuffer& rBuffer)
override { rBuffer.append(m_fValue); }
415 sal_uInt64 m_nLocation = 0;
420 sal_uInt64 GetLocation()
const;
447 sal_uInt64 m_nOffset = 0;
452 sal_uInt64 GetOffset()
const;
472 rBuffer.append(m_aValue ?
"true" :
"false");
482 void writeString(OStringBuffer& rBuffer)
override { rBuffer.append(
"null"); }
520 size_t m_nSignaturePage = 0;
523 sal_uInt32 GetNextSignature();
525 sal_Int32 WriteSignatureObject(
const OUString& rDescription,
bool bAdES,
526 sal_uInt64& rLastByteRangeOffset, sal_Int64& rContentOffset);
530 sal_Int32 WriteAnnotObject(
PDFObjectElement const& rFirstPage, sal_Int32 nSignatureId,
531 sal_Int32 nAppearanceId,
550 static OString ReadKeyword(
SvStream& rStream);
551 static size_t FindStartXRef(
SvStream& rStream);
553 void ReadXRefStream(
SvStream& rStream);
554 static void SkipWhitespace(
SvStream& rStream);
556 static void SkipLineBreaks(
SvStream& rStream);
557 size_t GetObjectOffset(
size_t nIndex)
const;
558 const std::vector<std::unique_ptr<PDFElement>>& GetElements()
const;
559 std::vector<PDFObjectElement*> GetPages();
562 void PushBackEOF(
size_t nOffset);
569 std::vector<std::unique_ptr<PDFElement>>& rElements,
580 bool ReadWithPossibleFixup(
SvStream& rStream);
581 void SetSignatureLine(std::vector<sal_Int8>&& rSignatureLine);
582 void SetSignaturePage(
size_t nPage);
584 bool Sign(
const css::uno::Reference<css::security::XCertificate>& xCertificate,
585 const OUString& rDescription,
bool bAdES);
589 std::vector<PDFObjectElement*> GetSignatureWidgets();
591 bool RemoveSignature(
size_t nPosition);
595 sal_Int32 createObject()
override;
597 bool updateObject(sal_Int32 n)
override;
599 bool writeBufferBytes(
const void* pBuffer, sal_uInt64 nBytes)
override;
610 sal_uInt64 m_nOffset = 0;
615 PDFElement* Lookup(
const OString& rDictionaryKey);
616 sal_uInt64 GetLocation()
const;
620 m_pDictionaryElement = pDictionaryElement;
625 void writeString(OStringBuffer& )
override { assert(
false &&
"not implemented"); }
634 : mrElements(rElements)
638 size_t parse(
PDFElement* pParsingElement,
size_t nStartIndex = 0,
int nCurrentDepth = 0);
const sal_Int32 m_nLength
TStyleElements m_aElements
Allows creating, updating and writing PDF objects in a container.
PDFObjectElement * m_pObject
The object that contains this array.
void writeString(OStringBuffer &rBuffer) override
PDFElement * GetElement(size_t nIndex) const
std::vector< PDFElement * > m_aElements
Boolean object: a 'true' or a 'false'.
PDFBooleanElement(bool bValue)
void writeString(OStringBuffer &rBuffer) override
Dictionary object: a set key-value pairs.
void writeString(OStringBuffer &rBuffer) override
std::map< OString, sal_uInt64 > m_aDictionaryKeyOffset
Position after the '/' token.
std::map< OString, sal_uInt64 > m_aDictionaryKeyValueLength
Length of the dictionary key and value, till (before) the next token.
sal_uInt64 GetLocation() const
void insert(OString const &rKey, PDFElement *pPDFElement)
std::map< OString, PDFElement * > m_aItems
Key-value pairs when the dictionary is a nested value.
In-memory representation of an on-disk PDF document.
std::vector< size_t > m_aEOFs
List of EOF offsets we know.
std::map< size_t, PDFObjectElement * > m_aOffsetObjects
Object offset <-> Object pointer map.
std::vector< size_t > m_aTrailerOffsets
Offsets of trailers, from latest to oldest.
PDFDocument & operator=(const PDFDocument &)=delete
PDFDocument(const PDFDocument &)=delete
void checkAndEnableStreamEncryption(sal_Int32) override
SvMemoryStream m_aEditBuffer
All editing takes place in this buffer, if it happens.
std::map< size_t, XRefEntry > m_aXRef
Object ID <-> object offset map.
std::vector< std::unique_ptr< PDFElement > > m_aElements
This vector owns all elements.
std::map< size_t, PDFObjectElement * > m_aIDObjects
Object ID <-> Object pointer map.
std::vector< size_t > m_aStartXRefs
List of xref offsets we know.
std::map< size_t, PDFTrailerElement * > m_aOffsetTrailers
Trailer offset <-> Trailer pointer map.
std::vector< sal_Int8 > m_aSignatureLine
Signature line in PDF format, to be consumed by the next Sign() invocation.
void disableStreamEncryption() override
A byte range in a PDF file.
bool alreadyParsing() const
virtual void writeString(OStringBuffer &rBuffer)=0
void setVisiting(bool bVisiting)
virtual bool Read(SvStream &rStream)=0
bool alreadyVisiting() const
virtual ~PDFElement()=default
void setParsing(bool bParsing)
void writeString(OStringBuffer &) override
End of a dictionary: '>>'.
PDFEndDictionaryElement()
void writeString(OStringBuffer &) override
End of an object: 'endobj' keyword.
void writeString(OStringBuffer &) override
End of a stream: 'endstream' keyword.
void writeString(OStringBuffer &) override
Hex string: in <AABB> form.
void writeString(OStringBuffer &rBuffer) override
Literal string: in (asdf) form.
void writeString(OStringBuffer &rBuffer) override
Name object: a key string.
void writeString(OStringBuffer &rBuffer) override
sal_uInt64 GetLength() const
void SetValue(const OString &rValue)
Null object: the 'null' singleton.
void writeString(OStringBuffer &rBuffer) override
Numbering object: an integer or a real.
void SetValue(double fValue)
void writeString(OStringBuffer &rBuffer) override
Indirect object: something with a unique ID.
PDFArrayElement * m_pArrayElement
The contained direct array, if any.
std::vector< std::unique_ptr< PDFElement > > m_aElements
Elements of an object in an object stream.
sal_uInt64 m_nDictionaryOffset
Position after the '<<' token.
PDFNumberElement * m_pNumberElement
If set, the object contains this number element (outside any dictionary/array).
std::vector< std::unique_ptr< PDFObjectElement > > m_aStoredElements
Objects of an object stream.
PDFDictionaryElement * m_pDictionaryElement
sal_uInt64 m_nDictionaryLength
Length of the dictionary buffer till (before) the '>>' token.
double m_fGenerationValue
std::vector< PDFReferenceElement * > m_aDictionaryReferences
List of all reference elements inside this object's dictionary and nested dictionaries.
std::unique_ptr< SvMemoryStream > m_pStreamBuffer
Uncompressed buffer of an object in an object stream.
sal_uInt64 m_nArrayOffset
Position after the '[' token, if m_pArrayElement is set.
sal_uInt64 m_nArrayLength
Length of the array buffer till (before) the ']' token.
PDFDocument & m_rDoc
The document owning this element.
PDFStreamElement * m_pStreamElement
The stream of this object, used when this is an object stream.
void writeString(OStringBuffer &) override
const std::vector< std::unique_ptr< PDFElement > > & mrElements
PDFObjectParser(std::vector< std::unique_ptr< PDFElement > > const &rElements)
Reference object: something with a unique ID.
void writeString(OStringBuffer &rBuffer) override
PDFNumberElement & m_rObject
The element providing the object number.
Stream object: a byte array with a known length.
SvMemoryStream m_aMemory
The byte array itself.
void writeString(OStringBuffer &rBuffer) override
The trailer singleton is at the end of the doc.
PDFDictionaryElement * m_pDictionaryElement
void writeString(OStringBuffer &) override
void SetDictionary(PDFDictionaryElement *pDictionaryElement)
PDFDictionaryElement * GetDictionary()
An entry in a cross-reference stream.
void SetDirty(bool bDirty)
sal_uInt64 m_nOffset
Non-compressed: The byte offset of the object, starting from the beginning of the file.
void SetOffset(sal_uInt64 nOffset)
XRefEntryType GetType() const
sal_uInt64 GetOffset() const
bool m_bDirty
Are changed as part of an incremental update?.
void SetType(XRefEntryType eType)
std::vector< unsigned char > DecodeHexString(std::string_view rHex)
bool parse(OUString const &uri, SourceProviderScannerData *data)
XRefEntryType
The type column of an entry in a cross-reference stream.
@ COMPRESSED
xref stream "2".
@ NOT_COMPRESSED
xref "n" or xref stream "1".
@ STORED_OBJECT
Same as END_OF_OBJECT, but for object streams (no endobj keyword).
@ EOF_TOKEN
Till the first %EOF token.
@ END_OF_OBJECT
Till the end of the current object.
@ END_OF_STREAM
Full file.