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

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

#include <pdfdocument.hxx>

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

Public Member Functions

 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 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...
 

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 ()
 Write the appearance object as part of signing. More...
 
sal_Int32 WriteAnnotObject (PDFObjectElement const &rFirstPage, sal_Int32 nSignatureId, sal_Int32 nAppearanceId)
 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...
 

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 ()
 
std::vector< PDFObjectElement * > GetPages ()
 
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 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...
 

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 343 of file pdfdocument.hxx.

Constructor & Destructor Documentation

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

Member Function Documentation

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

Decode a hex dump.

Definition at line 1958 of file pdfdocument.cxx.

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

size_t vcl::filter::PDFDocument::FindStartXRef ( SvStream rStream)
static
SvMemoryStream & vcl::filter::PDFDocument::GetEditBuffer ( )

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

Definition at line 2816 of file pdfdocument.cxx.

References m_aEditBuffer.

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

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

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

Definition at line 150 of file pdfdocument.cxx.

References vcl::filter::PDFLiteralStringElement::GetValue().

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

Definition at line 1802 of file pdfdocument.cxx.

References SAL_WARN.

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

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

Get a list of signatures embedded into this document.

Definition at line 1907 of file pdfdocument.cxx.

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

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

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

Definition at line 2805 of file pdfdocument.cxx.

References m_aIDObjects, and SAL_WARN.

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

PDFDocument& vcl::filter::PDFDocument::operator= ( const PDFDocument )
delete
void vcl::filter::PDFDocument::PushBackEOF ( size_t  nOffset)

Remember the end location of an EOF token.

Definition at line 1905 of file pdfdocument.cxx.

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

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

Read elements from the start of the stream till its end.

Definition at line 1266 of file pdfdocument.cxx.

References vcl::filter::PDFNumberElement::GetValue(), SvStream::ReadBytes(), SAL_INFO, SAL_WARN, and SvStream::Seek().

Referenced by vcl::PDFWriterImpl::writeReferenceXObject().

OString vcl::filter::PDFDocument::ReadKeyword ( SvStream rStream)
static
void vcl::filter::PDFDocument::ReadXRef ( SvStream rStream)
void vcl::filter::PDFDocument::ReadXRefStream ( SvStream rStream)
bool vcl::filter::PDFDocument::RemoveSignature ( size_t  nPosition)

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

Definition at line 125 of file pdfdocument.cxx.

References SAL_WARN.

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 1261 of file pdfdocument.cxx.

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

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

Sign the read document with xCertificate in the edit buffer.

Definition at line 788 of file pdfdocument.cxx.

References svl::crypto::Signing::AddDataRange(), vcl::filter::MAX_SIGNATURE_CONTENT_LENGTH, SAL_WARN, svl::crypto::Signing::Sign(), and STREAM_SEEK_TO_END.

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

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

Definition at line 1784 of file pdfdocument.cxx.

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

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

Serializes the contents of the edit buffer.

Definition at line 880 of file pdfdocument.cxx.

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

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

Write the annot object as part of signing.

Definition at line 247 of file pdfdocument.cxx.

References vcl::filter::PDFObjectElement::GetObjectValue(), vcl::filter::XRefEntry::SetDirty(), and vcl::filter::XRefEntry::SetOffset().

sal_Int32 vcl::filter::PDFDocument::WriteAppearanceObject ( )
private

Write the appearance object as part of signing.

Definition at line 230 of file pdfdocument.cxx.

References vcl::filter::XRefEntry::SetDirty(), and vcl::filter::XRefEntry::SetOffset().

bool vcl::filter::PDFDocument::WriteCatalogObject ( sal_Int32  nAnnotId,
PDFReferenceElement *&  pRoot 
)
private
bool vcl::filter::PDFDocument::WritePageObject ( PDFObjectElement rFirstPage,
sal_Int32  nAnnotId 
)
private
sal_Int32 vcl::filter::PDFDocument::WriteSignatureObject ( const OUString &  rDescription,
bool  bAdES,
sal_uInt64 &  rLastByteRangeOffset,
sal_Int64 &  rContentOffset 
)
private
void vcl::filter::PDFDocument::WriteXRef ( sal_uInt64  nXRefOffset,
PDFReferenceElement const *  pRoot 
)
private

Member Data Documentation

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

All editing takes place in this buffer, if it happens.

Definition at line 365 of file pdfdocument.hxx.

Referenced by GetEditBuffer().

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

This vector owns all elements.

Definition at line 346 of file pdfdocument.hxx.

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

List of EOF offsets we know.

Definition at line 360 of file pdfdocument.hxx.

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

Object ID <-> Object pointer map.

Definition at line 352 of file pdfdocument.hxx.

Referenced by LookupObject().

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

Object offset <-> Object pointer map.

Definition at line 350 of file pdfdocument.hxx.

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

Trailer offset <-> Trailer pointer map.

Definition at line 358 of file pdfdocument.hxx.

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

List of xref offsets we know.

Definition at line 354 of file pdfdocument.hxx.

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

Offsets of trailers, from latest to oldest.

Definition at line 356 of file pdfdocument.hxx.

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

Object ID <-> object offset map.

Definition at line 348 of file pdfdocument.hxx.

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

Definition at line 361 of file pdfdocument.hxx.

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

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

Definition at line 363 of file pdfdocument.hxx.


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