OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGeoPdfInfo.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: Mingjie Su
8 //
9 // Description: Ogr Info object.
10 //
11 //----------------------------------------------------------------------------
12 // $Id: ossimGeoPdfInfo.cpp 20935 2012-05-18 14:19:30Z dburken $
13 #include <iostream>
14 #include <iomanip>
15 #include <sstream>
16 #include <cstring> // for memset
17 
18 //PoDoFo includes
19 #include <podofo/doc/PdfMemDocument.h>
20 #include <podofo/base/PdfString.h>
22 
23 //ossim includes
24 #include <ossim/base/ossimTrace.h>
26 
27 #include "ossimGeoPdfInfo.h"
28 
29 // Static trace for debugging
30 static ossimTrace traceDebug("ossimGeoPdfInfo:debug");
31 static ossimTrace traceDump("ossimGeoPdfInfo:dump"); // This will dump offsets.
32 
34  : ossimInfoBase(),
35  theFile(),
36  m_PdfMemDocument(NULL)
37 {
38 }
39 
41 {
42  if (m_PdfMemDocument != NULL)
43  {
44  delete m_PdfMemDocument;
45  m_PdfMemDocument = 0;
46  }
47 }
48 
50 {
51  theFile = file;
52  if (isOpen())
53  {
54  PoDoFo::PdfError::EnableDebug(false); //do not print out debug info
55  m_PdfMemDocument = new PoDoFo::PdfMemDocument(theFile.c_str());
56 
57  if (m_PdfMemDocument == NULL)
58  {
59  return false;
60  }
61  return true;
62  }
63  return false;
64 }
65 
66 bool ossimGeoPdfInfo::open(std::shared_ptr<ossim::istream>& str,
67  const std::string& connectionString)
68 {
69  return false;
70 }
71 
73 {
74  ossimString ext = theFile.ext().downcase();
75 
76  if(ext == "pdf")
77  {
78  return true;
79  }
80  else
81  {
82  return false;
83  }
84 }
85 
87 {
88  static const char MODULE[] = "ossimGeoPdfInfo::print";
89 
90  int count = m_PdfMemDocument->GetPageCount();
91  PoDoFo::PdfString author = m_PdfMemDocument->GetInfo()->GetAuthor();
92  PoDoFo::PdfString creator = m_PdfMemDocument->GetInfo()->GetCreator();
93  PoDoFo::PdfString title = m_PdfMemDocument->GetInfo()->GetTitle();
94  PoDoFo::PdfString subject = m_PdfMemDocument->GetInfo()->GetSubject();
95  PoDoFo::PdfString keywords = m_PdfMemDocument->GetInfo()->GetKeywords();
96  PoDoFo::PdfString producer = m_PdfMemDocument->GetInfo()->GetProducer();
97 
98 
99  ossimString createDate;
100  ossimString modifyDate;
101  PoDoFo::PdfObject* obj = m_PdfMemDocument->GetInfo()->GetObject();
102  if (obj->IsDictionary())
103  {
104  PoDoFo::PdfDictionary pdfDictionary = obj->GetDictionary();
105 
106  PoDoFo::TKeyMap keyMap = pdfDictionary.GetKeys();
107  PoDoFo::TKeyMap::iterator it = keyMap.begin();
108  while (it != keyMap.end())
109  {
110  ossimString refName = ossimString(it->first.GetName());
111  PoDoFo::PdfObject* refObj = it->second;
112 
113  std::string objStr;
114  refObj->ToString(objStr);
115 
116  if (refName == "CreationDate")
117  {
118  createDate = ossimString(objStr);
119  createDate = createDate.substitute("(", "", true).trim();
120  createDate = createDate.substitute(")", "", true).trim();
121  createDate = createDate.substitute("D:", "", true).trim();
122  }
123  else if (refName == "ModDate")
124  {
125  modifyDate = ossimString(objStr);
126  modifyDate = modifyDate.substitute("(", "", true).trim();
127  modifyDate = modifyDate.substitute(")", "", true).trim();
128  modifyDate = modifyDate.substitute("D:", "", true).trim();
129  }
130  it++;
131  }
132  }
133 
134  try
135  {
136  m_PdfMemDocument->FreeObjectMemory(obj);
137  }
138  catch (...)
139  {
140  }
141 
142  ossimString authorStr = author.GetString();
143  ossimString creatorStr = creator.GetString();
144  ossimString titleStr = title.GetString();
145  ossimString producerStr = producer.GetString();
146  ossimString subjectStr = subject.GetString();
147  ossimString keywordsStr = keywords.GetString();
148 
149  ossimString prefix = "geopdf.";
150 
151  out << prefix << "pagecount: "
152  << ossimString::toString(count).c_str() << "\n";
153 
154  if (!authorStr.empty())
155  {
156  out << prefix << "author: "
157  << authorStr.c_str() << "\n";
158  }
159 
160  if (!creatorStr.empty())
161  {
162  out << prefix << "creator: "
163  << creatorStr.c_str() << "\n";
164  }
165 
166  if (!titleStr.empty())
167  {
168  out << prefix << "title: "
169  << titleStr.c_str() << "\n";
170  }
171 
172  if (!producerStr.empty())
173  {
174  out << prefix << "producer: "
175  << producerStr.c_str() << "\n";
176  }
177 
178  if (!subjectStr.empty())
179  {
180  out << prefix << "subject: "
181  << subjectStr.c_str() << "\n";
182  }
183 
184  if (!keywordsStr.empty())
185  {
186  out << prefix << "keywords: "
187  << keywordsStr.c_str() << "\n";
188  }
189 
190  if (!createDate.empty())
191  {
192  out << prefix << "creationdate: "
193  << createDate.c_str() << "\n";
194  }
195 
196  if (!modifyDate.empty())
197  {
198  out << prefix << "modificationdate: "
199  << modifyDate.c_str() << "\n";
200  }
201 
202  if (traceDebug())
203  {
205  << MODULE << " DEBUG Entered...\n";
206  }
207  return out;
208 }
ossimString substitute(const ossimString &searchKey, const ossimString &replacementValue, bool replaceAll=false) const
Substitutes searchKey string with replacementValue and returns a string.
virtual std::ostream & print(std::ostream &out) const
Print method.
static ossimString toString(bool aValue)
Numeric to string methods.
virtual bool open(const ossimFilename &file)
open method.
Info Base.
Definition: ossimInfoBase.h:32
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
ossimGeoPdfInfo()
default constructor
ossimFilename theFile
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool empty() const
Definition: ossimString.h:411
ossimString ext() const
virtual ~ossimGeoPdfInfo()
virtual destructor
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
PoDoFo::PdfMemDocument * m_PdfMemDocument
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23