#include <Doc.hh>
Collaboration diagram for pdf::CDoc:
the PDF document class. it represents a PDF document. it contains a list of pages and document-wide resources such as fonts, images or cross references.
note that a PDF document is not the same as the PDF file. the file is just a place to store the content of the document. the document is the logical container of all logical objects in the document.
clients of this class will create an object, and add contents to it, e.g. :
CDoc doc ; doc.AddPage( page ) ; // ... adding more contents ofstream fstr( "output.pdf" ) ; fstr << doc ;
Since version 0.0.2, you can add PDF document information to the document:
CDocInfo info( "My Document", "Nestal Wan", "Testing", "libpdf++", "libpdf++", "libpdf++" ) ; doc.Info( info ) ;
See the CDocInfo class for details.
|
default constructor will create an empty document.
00050 : m_default_page_info( 594.0f, 828.0f ) 00051 { 00052 assert( IsValid( ) ) ; 00053 } |
|
nothing special. just free all resources.
00058 { 00059 assert( IsValid( ) ) ; 00060 } |
|
insert a page to the document. the page is passed by value such that further modification of "page" will not affect the document.
00102 { 00103 assert( IsValid( ) ) ; 00104 m_pages.push_back( page ) ; 00105 } |
|
add a font to the document. a font must be added to document before it can be used.
00073 { 00074 assert( font != 0 ) ; 00075 assert( IsValid( ) ) ; 00076 00077 m_res_dict.AddFont( font ) ; 00078 } |
|
add an xobject to the document. an xobject is an object that can appear in a page but is not stored inside the page object. an xobject must be added to the document before it can appear in the page.
00089 { 00090 assert( xobj != 0 ) ; 00091 assert( IsValid( ) ) ; 00092 00093 m_res_dict.AddXObj( xobj ) ; 00094 } |
|
write the document to an output. note that ihe ostream cannot be an unredirected standard output because CDoc relies on tellp() internally. tellg() will always return -1 for cout. use a ofstream instead.
00138 { 00139 assert( IsValid( ) ) ; 00140 assert( !m_pages.empty( ) ) ; // the document should have pages to write 00141 00142 using namespace std ; 00143 using namespace core ; 00144 00145 // the resulting PDF file 00146 CFile pdf ; 00147 00148 // first write the page tree object 00149 CObjRef page_tree = WritePageTree( pdf ) ; 00150 00151 // create the catalog object 00152 CDictionary *catalog = new CDictionary ; 00153 catalog->AddPair( "Type", "Catalog" ) ; 00154 catalog->AddPair( CName( "Pages" ), page_tree.Dup( ) ) ; 00155 00156 // add catalog to file 00157 CObjRef cata_ref = pdf.AddObj( catalog ) ; 00158 00159 // write document info 00160 if ( !m_doc_info.Empty( ) ) 00161 { 00162 CDictionary *info_dict = new CDictionary ; 00163 m_doc_info.Write( info_dict ) ; 00164 00165 CObjRef ref = pdf.AddObj( info_dict ) ; 00166 00167 return pdf.Write( os, cata_ref, &ref ) ; 00168 } 00169 else 00170 return pdf.Write( os, cata_ref, 0 ) ; 00171 } |
|
this function grants access to the added pages in the document.
|
|
same as the non-constant version, except it returns a constant reference.
|
|
change the document information. if the document info is "empty", the document info will not be written to the PDF file.
00220 { 00221 assert( IsValid( ) ) ; 00222 m_doc_info = doc_info ; 00223 } |
|
get the document information.
00228 { 00229 assert( IsValid( ) ) ; 00230 return m_doc_info ; 00231 } |
|
write the page tree. the page tree is a dictionary that contain the list of pages. it also contain all global resources like fonts and PDF xobjects.
00178 { 00179 assert( IsValid( ) ) ; 00180 00181 using namespace core ; 00182 using namespace std ; 00183 00184 CDictionary *page_tree = new CDictionary ; 00185 page_tree->AddPair( CName( "Type" ), new CName( "Pages" ) ) ; 00186 00187 CObjRef page_tree_ref = file.AddObj( page_tree ) ; 00188 CArray *page_array = new CArray ; 00189 00190 // write all page objects 00191 typedef vector<page::CPage>::const_iterator iterator ; 00192 for ( iterator i = m_pages.begin( ) ; i != m_pages.end( ) ; ++i ) 00193 { 00194 // write the page to the PDF file 00195 CObjRef ref = i->Write( page_tree_ref, m_default_page_info, file ) ; 00196 00197 // save the page's reference 00198 page_array->push_back( ref.Dup( ) ) ; 00199 } 00200 00201 // order should not be important 00202 page_tree->AddPair( CName( "Count" ), new CNumber( m_pages.size( ) ) ) ; 00203 page_tree->AddPair( CName( "Kids" ), page_array ) ; 00204 00205 // write resource 00206 page_tree->AddPair( CName( "Resources" ), m_res_dict.Write( file ) ) ; 00207 00208 // use default page info as info of the page tree object 00209 m_default_page_info.Write( page_tree, page::CInfo( ) ) ; 00210 00211 return page_tree_ref ; 00212 } |
|
the pages in this documents.
|
|
resource dictionary of the page tree of the document. the resources stored inside this dictionary is available to all pages in the document. |
|
default page settings. it will be applied when a new page is created
|
|
document info. this includes misc info like author, subject, keyword etc. if the doc info is "empty", it will not be writen to the PDF file. |