LibreOffice Module vcl (master) 1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
vcl::filter::PDFDocument Class Referencefinal

In-memory representation of an on-disk PDF document. More...

#include <pdfdocument.hxx>

Inheritance diagram for vcl::filter::PDFDocument:
[legend]
Collaboration diagram for vcl::filter::PDFDocument:
[legend]

Public Member Functions

 PDFDocument ()
 
virtual ~PDFDocument ()
 
PDFDocumentoperator= (const PDFDocument &)=delete
 
 PDFDocument (const PDFDocument &)=delete
 
High-level functions, to be used by others.
bool Read (SvStream &rStream)
 Read elements from the start of the stream till its end. More...
 
bool ReadWithPossibleFixup (SvStream &rStream)
 Calls Read() first and if it fails it tries to fixup and then retry. More...
 
void SetSignatureLine (std::vector< sal_Int8 > &&rSignatureLine)
 
void SetSignaturePage (size_t nPage)
 
bool Sign (const css::uno::Reference< css::security::XCertificate > &xCertificate, const OUString &rDescription, bool bAdES)
 Sign the read document with xCertificate in the edit buffer. More...
 
bool Write (SvStream &rStream)
 Serializes the contents of the edit buffer. More...
 
std::vector< PDFObjectElement * > GetSignatureWidgets ()
 Get a list of signatures embedded into this document. More...
 
bool RemoveSignature (size_t nPosition)
 Remove the nth signature from read document in the edit buffer. More...
 
sal_Int32 createObject () override
 See vcl::PDFObjectContainer::createObject(). More...
 
bool updateObject (sal_Int32 n) override
 See vcl::PDFObjectContainer::updateObject(). More...
 
bool writeBufferBytes (const void *pBuffer, sal_uInt64 nBytes) override
 See vcl::PDFObjectContainer::writeBuffer(). More...
 
void checkAndEnableStreamEncryption (sal_Int32) override
 
void disableStreamEncryption () override
 
- Public Member Functions inherited from vcl::PDFObjectContainer
virtual sal_Int32 createObject ()=0
 
virtual bool updateObject (sal_Int32 n)=0
 
virtual bool writeBufferBytes (const void *pBuffer, sal_uInt64 nBytes)=0
 
bool writeBuffer (std::string_view aBuffer)
 
virtual void checkAndEnableStreamEncryption (sal_Int32 nObject)=0
 
virtual void disableStreamEncryption ()=0
 

Private Member Functions

sal_uInt32 GetNextSignature ()
 Suggest a minimal, yet free signature ID to use for the next signature. More...
 
sal_Int32 WriteSignatureObject (const OUString &rDescription, bool bAdES, sal_uInt64 &rLastByteRangeOffset, sal_Int64 &rContentOffset)
 Write the signature object as part of signing. More...
 
sal_Int32 WriteAppearanceObject (tools::Rectangle &rSignatureRectangle)
 Write the appearance object as part of signing. More...
 
sal_Int32 WriteAnnotObject (PDFObjectElement const &rFirstPage, sal_Int32 nSignatureId, sal_Int32 nAppearanceId, const tools::Rectangle &rSignatureRectangle)
 Write the annot object as part of signing. More...
 
bool WritePageObject (PDFObjectElement &rFirstPage, sal_Int32 nAnnotId)
 Write the updated Page object as part of signing. More...
 
bool WriteCatalogObject (sal_Int32 nAnnotId, PDFReferenceElement *&pRoot)
 Write the updated Catalog object as part of signing. More...
 
void WriteXRef (sal_uInt64 nXRefOffset, PDFReferenceElement const *pRoot)
 Write the updated cross-references as part of signing. More...
 

Private Attributes

std::vector< std::unique_ptr< PDFElement > > m_aElements
 This vector owns all elements. More...
 
std::map< size_t, XRefEntrym_aXRef
 Object ID <-> object offset map. More...
 
std::map< size_t, PDFObjectElement * > m_aOffsetObjects
 Object offset <-> Object pointer map. More...
 
std::map< size_t, PDFObjectElement * > m_aIDObjects
 Object ID <-> Object pointer map. More...
 
std::vector< size_t > m_aStartXRefs
 List of xref offsets we know. More...
 
std::vector< size_t > m_aTrailerOffsets
 Offsets of trailers, from latest to oldest. More...
 
std::map< size_t, PDFTrailerElement * > m_aOffsetTrailers
 Trailer offset <-> Trailer pointer map. More...
 
std::vector< size_t > m_aEOFs
 List of EOF offsets we know. More...
 
PDFTrailerElementm_pTrailer = nullptr
 
PDFObjectElementm_pXRefStream = nullptr
 When m_pTrailer is nullptr, this can still have a dictionary. More...
 
SvMemoryStream m_aEditBuffer
 All editing takes place in this buffer, if it happens. More...
 
std::vector< sal_Int8m_aSignatureLine
 Signature line in PDF format, to be consumed by the next Sign() invocation. More...
 
size_t m_nSignaturePage = 0
 0-based page number where m_aSignatureLine should be placed. More...
 

Low-level functions, to be used by PDFElement subclasses.

void ReadXRef (SvStream &rStream)
 
void ReadXRefStream (SvStream &rStream)
 
size_t GetObjectOffset (size_t nIndex) const
 
const std::vector< std::unique_ptr< PDFElement > > & GetElements () const
 
std::vector< PDFObjectElement * > GetPages ()
 
PDFObjectElementGetCatalog ()
 
void PushBackEOF (size_t nOffset)
 Remember the end location of an EOF token. More...
 
PDFObjectElementLookupObject (size_t nObjectNumber)
 Look up object based on object number, possibly by parsing object streams. More...
 
SvMemoryStreamGetEditBuffer ()
 Access to the input document, even after the input stream is gone. More...
 
bool Tokenize (SvStream &rStream, TokenizeMode eMode, std::vector< std::unique_ptr< PDFElement > > &rElements, PDFObjectElement *pObjectElement)
 Tokenize elements from current offset. More...
 
void SetIDObject (size_t nID, PDFObjectElement *pObject)
 Register an object (owned directly or indirectly by m_aElements) as a provider for a given ID. More...
 
static std::vector< unsigned char > DecodeHexString (PDFHexStringElement const *pElement)
 Decode a hex dump. More...
 
static OUString DecodeHexStringUTF16BE (PDFHexStringElement const &rElement)
 
static OString ReadKeyword (SvStream &rStream)
 
static size_t FindStartXRef (SvStream &rStream)
 
static void SkipWhitespace (SvStream &rStream)
 
static void SkipLineBreaks (SvStream &rStream)
 Instead of all whitespace, just skip CR and NL characters. More...
 

Additional Inherited Members

- Protected Member Functions inherited from vcl::PDFObjectContainer
 ~PDFObjectContainer () noexcept=default
 

Detailed Description

In-memory representation of an on-disk PDF document.

The PDF element list is not meant to be saved back to disk, but some elements remember their source offset / length, and based on that it's possible to modify the input file.

Definition at line 492 of file pdfdocument.hxx.

Constructor & Destructor Documentation

◆ PDFDocument() [1/2]

vcl::filter::PDFDocument::PDFDocument ( )
default

◆ ~PDFDocument()

vcl::filter::PDFDocument::~PDFDocument ( )
virtualdefault

◆ PDFDocument() [2/2]

vcl::filter::PDFDocument::PDFDocument ( const PDFDocument )
delete

References DecodeHexString(), Read, Sign, and Write.

Member Function Documentation

◆ checkAndEnableStreamEncryption()

void vcl::filter::PDFDocument::checkAndEnableStreamEncryption ( sal_Int32  )
inlineoverridevirtual

Implements vcl::PDFObjectContainer.

Definition at line 600 of file pdfdocument.hxx.

◆ createObject()

sal_Int32 vcl::filter::PDFDocument::createObject ( )
overridevirtual

See vcl::PDFObjectContainer::createObject().

Implements vcl::PDFObjectContainer.

Definition at line 70 of file pdfdocument.cxx.

References m_aXRef.

◆ DecodeHexString()

std::vector< unsigned char > vcl::filter::PDFDocument::DecodeHexString ( PDFHexStringElement const *  pElement)
static

Decode a hex dump.

Definition at line 2077 of file pdfdocument.cxx.

References svl::crypto::DecodeHexString(), and vcl::filter::PDFHexStringElement::GetValue().

Referenced by DecodeHexStringUTF16BE().

◆ DecodeHexStringUTF16BE()

OUString vcl::filter::PDFDocument::DecodeHexStringUTF16BE ( PDFHexStringElement const &  rElement)
static

Definition at line 2082 of file pdfdocument.cxx.

References DecodeHexString(), and i.

◆ disableStreamEncryption()

void vcl::filter::PDFDocument::disableStreamEncryption ( )
inlineoverridevirtual

Implements vcl::PDFObjectContainer.

Definition at line 601 of file pdfdocument.hxx.

◆ FindStartXRef()

size_t vcl::filter::PDFDocument::FindStartXRef ( SvStream rStream)
static

◆ GetCatalog()

PDFObjectElement * vcl::filter::PDFDocument::GetCatalog ( )

◆ GetEditBuffer()

SvMemoryStream & vcl::filter::PDFDocument::GetEditBuffer ( )

Access to the input document, even after the input stream is gone.

Definition at line 2740 of file pdfdocument.cxx.

References m_aEditBuffer.

Referenced by vcl::PDFObjectCopier::copyExternalResources(), vcl::filter::PDFObjectElement::ParseStoredObjects(), and vcl::PDFWriterImpl::writeReferenceXObject().

◆ GetElements()

const std::vector< std::unique_ptr< PDFElement > > & vcl::filter::PDFDocument::GetElements ( ) const

◆ GetNextSignature()

sal_uInt32 vcl::filter::PDFDocument::GetNextSignature ( )
private

Suggest a minimal, yet free signature ID to use for the next signature.

Definition at line 105 of file pdfdocument.cxx.

References GetSignatureWidgets(), vcl::filter::PDFLiteralStringElement::GetValue(), and o3tl::toUInt32().

Referenced by WriteAnnotObject().

◆ GetObjectOffset()

size_t vcl::filter::PDFDocument::GetObjectOffset ( size_t  nIndex) const

◆ GetPages()

std::vector< PDFObjectElement * > vcl::filter::PDFDocument::GetPages ( )

◆ GetSignatureWidgets()

std::vector< PDFObjectElement * > vcl::filter::PDFDocument::GetSignatureWidgets ( )

Get a list of signatures embedded into this document.

Definition at line 2026 of file pdfdocument.cxx.

References GetPages(), vcl::filter::PDFObjectElement::Lookup(), and vcl::filter::PDFObjectElement::LookupObject().

Referenced by GetNextSignature(), and RemoveSignature().

◆ LookupObject()

PDFObjectElement * vcl::filter::PDFDocument::LookupObject ( size_t  nObjectNumber)

Look up object based on object number, possibly by parsing object streams.

Definition at line 2729 of file pdfdocument.cxx.

References m_aIDObjects, and SAL_WARN.

Referenced by vcl::filter::PDFReferenceElement::LookupObject().

◆ operator=()

PDFDocument & vcl::filter::PDFDocument::operator= ( const PDFDocument )
delete

◆ PushBackEOF()

void vcl::filter::PDFDocument::PushBackEOF ( size_t  nOffset)

Remember the end location of an EOF token.

Definition at line 2024 of file pdfdocument.cxx.

References m_aEOFs.

Referenced by vcl::filter::PDFCommentElement::Read().

◆ Read()

bool vcl::filter::PDFDocument::Read ( SvStream rStream)

◆ ReadKeyword()

OString vcl::filter::PDFDocument::ReadKeyword ( SvStream rStream)
static

◆ ReadWithPossibleFixup()

bool vcl::filter::PDFDocument::ReadWithPossibleFixup ( SvStream rStream)

Calls Read() first and if it fails it tries to fixup and then retry.

Definition at line 1347 of file pdfdocument.cxx.

References vcl::pdf::convertToHighestSupported(), Read(), and SvStream::Seek().

◆ ReadXRef()

void vcl::filter::PDFDocument::ReadXRef ( SvStream rStream)

◆ ReadXRefStream()

void vcl::filter::PDFDocument::ReadXRefStream ( SvStream rStream)

◆ RemoveSignature()

bool vcl::filter::PDFDocument::RemoveSignature ( size_t  nPosition)

Remove the nth signature from read document in the edit buffer.

Definition at line 45 of file pdfdocument.cxx.

References GetSignatureWidgets(), SvStream::good(), m_aEditBuffer, m_aEOFs, SAL_WARN, SvStream::Seek(), SvStream::SetStreamSize(), and SvStream::Tell().

◆ SetIDObject()

void vcl::filter::PDFDocument::SetIDObject ( size_t  nID,
PDFObjectElement pObject 
)

Register an object (owned directly or indirectly by m_aElements) as a provider for a given ID.

Definition at line 1342 of file pdfdocument.cxx.

References m_aIDObjects, and pObject.

Referenced by vcl::filter::PDFObjectElement::ParseStoredObjects().

◆ SetSignatureLine()

void vcl::filter::PDFDocument::SetSignatureLine ( std::vector< sal_Int8 > &&  rSignatureLine)

Definition at line 98 of file pdfdocument.cxx.

References m_aSignatureLine.

◆ SetSignaturePage()

void vcl::filter::PDFDocument::SetSignaturePage ( size_t  nPage)

Definition at line 103 of file pdfdocument.cxx.

References m_nSignaturePage.

◆ Sign()

bool vcl::filter::PDFDocument::Sign ( const css::uno::Reference< css::security::XCertificate > &  xCertificate,
const OUString &  rDescription,
bool  bAdES 
)

◆ SkipLineBreaks()

void vcl::filter::PDFDocument::SkipLineBreaks ( SvStream rStream)
static

Instead of all whitespace, just skip CR and NL characters.

Definition at line 1876 of file pdfdocument.cxx.

References ch, SvStream::eof(), SvStream::ReadChar(), and SvStream::SeekRel().

Referenced by Tokenize().

◆ SkipWhitespace()

void vcl::filter::PDFDocument::SkipWhitespace ( SvStream rStream)
static

◆ Tokenize()

bool vcl::filter::PDFDocument::Tokenize ( SvStream rStream,
TokenizeMode  eMode,
std::vector< std::unique_ptr< PDFElement > > &  rElements,
PDFObjectElement pObjectElement 
)

◆ updateObject()

bool vcl::filter::PDFDocument::updateObject ( sal_Int32  n)
overridevirtual

◆ Write()

bool vcl::filter::PDFDocument::Write ( SvStream rStream)

Serializes the contents of the edit buffer.

Definition at line 959 of file pdfdocument.cxx.

References SvStream::good(), m_aEditBuffer, SvStream::Seek(), and SvStream::WriteStream().

◆ WriteAnnotObject()

sal_Int32 vcl::filter::PDFDocument::WriteAnnotObject ( PDFObjectElement const &  rFirstPage,
sal_Int32  nSignatureId,
sal_Int32  nAppearanceId,
const tools::Rectangle rSignatureRectangle 
)
private

◆ WriteAppearanceObject()

sal_Int32 vcl::filter::PDFDocument::WriteAppearanceObject ( tools::Rectangle rSignatureRectangle)
private

◆ writeBufferBytes()

bool vcl::filter::PDFDocument::writeBufferBytes ( const void *  pBuffer,
sal_uInt64  nBytes 
)
overridevirtual

◆ WriteCatalogObject()

bool vcl::filter::PDFDocument::WriteCatalogObject ( sal_Int32  nAnnotId,
PDFReferenceElement *&  pRoot 
)
private

◆ WritePageObject()

bool vcl::filter::PDFDocument::WritePageObject ( PDFObjectElement rFirstPage,
sal_Int32  nAnnotId 
)
private

◆ WriteSignatureObject()

sal_Int32 vcl::filter::PDFDocument::WriteSignatureObject ( const OUString &  rDescription,
bool  bAdES,
sal_uInt64 &  rLastByteRangeOffset,
sal_Int64 &  rContentOffset 
)
private

◆ WriteXRef()

void vcl::filter::PDFDocument::WriteXRef ( sal_uInt64  nXRefOffset,
PDFReferenceElement const *  pRoot 
)
private

Member Data Documentation

◆ m_aEditBuffer

SvMemoryStream vcl::filter::PDFDocument::m_aEditBuffer
private

◆ m_aElements

std::vector<std::unique_ptr<PDFElement> > vcl::filter::PDFDocument::m_aElements
private

This vector owns all elements.

Definition at line 495 of file pdfdocument.hxx.

Referenced by GetElements(), Read(), and ReadXRefStream().

◆ m_aEOFs

std::vector<size_t> vcl::filter::PDFDocument::m_aEOFs
private

List of EOF offsets we know.

Definition at line 509 of file pdfdocument.hxx.

Referenced by PushBackEOF(), Read(), RemoveSignature(), and Tokenize().

◆ m_aIDObjects

std::map<size_t, PDFObjectElement*> vcl::filter::PDFDocument::m_aIDObjects
private

Object ID <-> Object pointer map.

Definition at line 501 of file pdfdocument.hxx.

Referenced by LookupObject(), Read(), SetIDObject(), and Tokenize().

◆ m_aOffsetObjects

std::map<size_t, PDFObjectElement*> vcl::filter::PDFDocument::m_aOffsetObjects
private

Object offset <-> Object pointer map.

Definition at line 499 of file pdfdocument.hxx.

Referenced by Read(), and Tokenize().

◆ m_aOffsetTrailers

std::map<size_t, PDFTrailerElement*> vcl::filter::PDFDocument::m_aOffsetTrailers
private

Trailer offset <-> Trailer pointer map.

Definition at line 507 of file pdfdocument.hxx.

Referenced by GetCatalog(), and Tokenize().

◆ m_aSignatureLine

std::vector<sal_Int8> vcl::filter::PDFDocument::m_aSignatureLine
private

Signature line in PDF format, to be consumed by the next Sign() invocation.

Definition at line 517 of file pdfdocument.hxx.

Referenced by SetSignatureLine(), and WriteAppearanceObject().

◆ m_aStartXRefs

std::vector<size_t> vcl::filter::PDFDocument::m_aStartXRefs
private

List of xref offsets we know.

Definition at line 503 of file pdfdocument.hxx.

Referenced by Read(), Tokenize(), and WriteXRef().

◆ m_aTrailerOffsets

std::vector<size_t> vcl::filter::PDFDocument::m_aTrailerOffsets
private

Offsets of trailers, from latest to oldest.

Definition at line 505 of file pdfdocument.hxx.

Referenced by GetCatalog(), and Read().

◆ m_aXRef

std::map<size_t, XRefEntry> vcl::filter::PDFDocument::m_aXRef
private

◆ m_nSignaturePage

size_t vcl::filter::PDFDocument::m_nSignaturePage = 0
private

0-based page number where m_aSignatureLine should be placed.

Definition at line 520 of file pdfdocument.hxx.

Referenced by SetSignaturePage(), and Sign().

◆ m_pTrailer

PDFTrailerElement* vcl::filter::PDFDocument::m_pTrailer = nullptr
private

Definition at line 510 of file pdfdocument.hxx.

Referenced by Read(), Tokenize(), WriteCatalogObject(), and WriteXRef().

◆ m_pXRefStream

PDFObjectElement* vcl::filter::PDFDocument::m_pXRefStream = nullptr
private

When m_pTrailer is nullptr, this can still have a dictionary.

Definition at line 512 of file pdfdocument.hxx.

Referenced by GetCatalog(), Read(), ReadXRefStream(), Tokenize(), WriteCatalogObject(), and WriteXRef().


The documentation for this class was generated from the following files: