11 #ifndef INCLUDED_VCL_FILTER_PDFDOCUMENT_HXX
12 #define INCLUDED_VCL_FILTER_PDFDOCUMENT_HXX
20 #include <rtl/strbuf.hxx>
31 template <
class interface_type>
class Reference;
41 class PDFTrailerElement;
42 class PDFReferenceElement;
44 class PDFDictionaryElement;
45 class PDFArrayElement;
46 class PDFStreamElement;
47 class PDFNumberElement;
52 bool m_bVisiting =
false;
53 bool m_bParsing =
false;
61 void setParsing(
bool bParsing) { m_bParsing = bParsing; }
64 virtual void writeString(OStringBuffer& rBuffer) = 0;
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);
151 const std::vector<PDFElement*>& GetElements()
const;
156 rBuffer.append(
"[ ");
157 for (
auto& rElement : m_aElements)
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;
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(
">>");
335 void SetOffset(sal_uInt64 nOffset) { m_nOffset = nOffset; }
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,
549 static OString ReadKeyword(
SvStream& rStream);
550 static size_t FindStartXRef(
SvStream& rStream);
552 void ReadXRefStream(
SvStream& rStream);
553 static void SkipWhitespace(
SvStream& rStream);
555 static void SkipLineBreaks(
SvStream& rStream);
556 size_t GetObjectOffset(
size_t nIndex)
const;
557 const std::vector<std::unique_ptr<PDFElement>>& GetElements()
const;
558 std::vector<PDFObjectElement*> GetPages();
561 void PushBackEOF(
size_t nOffset);
568 std::vector<std::unique_ptr<PDFElement>>& rElements,
578 void SetSignatureLine(
const std::vector<sal_Int8>& rSignatureLine);
579 void SetSignaturePage(
size_t nPage);
581 bool Sign(
const css::uno::Reference<css::security::XCertificate>& xCertificate,
582 const OUString& rDescription,
bool bAdES);
586 std::vector<PDFObjectElement*> GetSignatureWidgets();
588 bool RemoveSignature(
size_t nPosition);
592 sal_Int32 createObject()
override;
594 bool updateObject(sal_Int32 n)
override;
596 bool writeBuffer(
const void* pBuffer, sal_uInt64 nBytes)
override;
605 sal_uInt64 m_nOffset = 0;
610 PDFElement* Lookup(
const OString& rDictionaryKey);
611 sal_uInt64 GetLocation()
const;
615 m_pDictionaryElement = pDictionaryElement;
629 : mrElements(rElements)
633 size_t parse(
PDFElement* pParsingElement,
size_t nStartIndex = 0,
int nCurrentDepth = 0);
638 #endif // INCLUDED_VCL_FILTER_PDFDOCUMENT_HXX
std::vector< std::unique_ptr< PDFElement > > m_aElements
Elements of an object in an object stream.
const sal_Int32 m_nLength
sal_uInt64 m_nDictionaryOffset
Position after the '<<' token.
std::vector< std::unique_ptr< PDFElement > > m_aElements
This vector owns all elements.
void writeString(OStringBuffer &rBuffer) override
void writeString(OStringBuffer &rBuffer) override
Numbering object: an integer or a real.
Boolean object: a 'true' or a 'false'.
PDFDictionaryElement * m_pDictionaryElement
sal_uInt64 m_nOffset
Non-compressed: The byte offset of the object, starting from the beginning of the file...
SvMemoryStream m_aMemory
The byte array itself.
PDFArrayElement * m_pArrayElement
The contained direct array, if any.
void writeString(OStringBuffer &rBuffer) override
PDFObjectElement * m_pObject
The object that contains this array.
bool m_bDirty
Are changed as part of an incremental update?.
std::vector< std::unique_ptr< PDFObjectElement > > m_aStoredElements
Objects of an object stream.
void SetValue(const OString &rValue)
std::vector< unsigned char > DecodeHexString(const OString &rHex)
PDFBooleanElement(bool bValue)
PDFDocument & m_rDoc
The document owning this element.
bool alreadyParsing() const
sal_uInt64 m_nArrayOffset
Position after the '[' token, if m_pArrayElement is set.
std::map< OString, PDFElement * > m_aItems
Key-value pairs when the dictionary is a nested value.
const std::vector< std::unique_ptr< PDFElement > > & mrElements
void setVisiting(bool bVisiting)
sal_uInt64 GetLocation() const
std::unique_ptr< SvMemoryStream > m_pStreamBuffer
Uncompressed buffer of an object in an object stream.
A byte range in a PDF file.
void writeString(OStringBuffer &rBuffer) override
void SetValue(double fValue)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
In-memory representation of an on-disk PDF document.
sal_uInt64 m_nArrayLength
Length of the array buffer till (before) the ']' token.
xref "f" or xref stream "0".
An entry in a cross-reference stream.
PDFObjectParser(std::vector< std::unique_ptr< PDFElement >> const &rElements)
XRefEntryType GetType() const
std::vector< sal_Int8 > m_aSignatureLine
Signature line in PDF format, to be consumed by the next Sign() invocation.
void writeString(OStringBuffer &) override
void writeString(OStringBuffer &rBuffer) override
xref "n" or xref stream "1".
void writeString(OStringBuffer &) override
PDFElement * GetElement(size_t nIndex) const
std::vector< size_t > m_aTrailerOffsets
Offsets of trailers, from latest to oldest.
PDFNumberElement * m_pNumberElement
If set, the object contains this number element (outside any dictionary/array).
void SetType(XRefEntryType eType)
Same as END_OF_OBJECT, but for object streams (no endobj keyword).
void writeString(OStringBuffer &) override
sal_uInt64 GetOffset() const
std::map< OString, sal_uInt64 > m_aDictionaryKeyOffset
Position after the '/' token.
void writeString(OStringBuffer &rBuffer) override
double m_fGenerationValue
PDFStreamElement * m_pStreamElement
The stream of this object, used when this is an object stream.
PDFDictionaryElement * GetDictionary()
void writeString(OStringBuffer &) override
void writeString(OStringBuffer &rBuffer) override
Indirect object: something with a unique ID.
sal_uInt32 writeString(sal_uInt8 *buffer, const sal_Unicode *v)
PDFNumberElement & m_rObject
The element providing the object number.
std::map< size_t, PDFObjectElement * > m_aOffsetObjects
Object offset <-> Object pointer map.
End of a dictionary: '>>'.
SvMemoryStream m_aEditBuffer
All editing takes place in this buffer, if it happens.
Dictionary object: a set key-value pairs.
std::vector< PDFElement * > m_aElements
std::vector< PDFReferenceElement * > m_aDictionaryReferences
List of all reference elements inside this object's dictionary and nested dictionaries.
void SetDictionary(PDFDictionaryElement *pDictionaryElement)
std::map< OString, sal_uInt64 > m_aDictionaryKeyValueLength
Length of the dictionary key and value, till (before) the next token.
void setParsing(bool bParsing)
Till the end of the current object.
void SetDirty(bool bDirty)
End of an object: 'endobj' keyword.
Null object: the 'null' singleton.
void insert(OString const &rKey, PDFElement *pPDFElement)
std::map< size_t, PDFObjectElement * > m_aIDObjects
Object ID <-> Object pointer map.
void writeString(OStringBuffer &) override
Reference object: something with a unique ID.
std::vector< size_t > m_aEOFs
List of EOF offsets we know.
End of a stream: 'endstream' keyword.
void writeString(OStringBuffer &rBuffer) override
std::map< size_t, PDFTrailerElement * > m_aOffsetTrailers
Trailer offset <-> Trailer pointer map.
void writeString(OStringBuffer &) override
PDFDictionaryElement * m_pDictionaryElement
bool alreadyVisiting() const
Literal string: in (asdf) form.
Name object: a key string.
std::vector< size_t > m_aStartXRefs
List of xref offsets we know.
void SetOffset(sal_uInt64 nOffset)
The trailer singleton is at the end of the doc.
XRefEntryType
The type column of an entry in a cross-reference stream.
Till the first %EOF token.
std::map< size_t, XRefEntry > m_aXRef
Object ID <-> object offset map.
sal_uInt64 m_nDictionaryLength
Length of the dictionary buffer till (before) the '>>' token.
bool parse(OUString const &uri, SourceProviderScannerData *data)
void writeString(OStringBuffer &rBuffer) override
Stream object: a byte array with a known length.
void writeString(OStringBuffer &rBuffer) override
Allows creating, updating and writing PDF objects in a container.