$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
pdf/get_header.hh
1 // Copyright (C) 2013, 2014 EPITA Research and Development Laboratory (LRDE).
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_IO_PDF_GET_HEADER_HH
27 # define MLN_IO_PDF_GET_HEADER_HH
28 
32 
33 # include <iostream>
34 # include <fstream>
35 
36 #include <poppler/cpp/poppler-document.h>
37 
38 # include <mln/core/concept/image.hh>
39 # include <mln/core/routine/initialize.hh>
40 # include <mln/core/box_runstart_piter.hh>
41 # include <mln/core/pixel.hh>
42 # include <mln/data/memcpy_.hh>
43 # include <mln/util/array.hh>
44 
45 namespace mln
46 {
47 
48  namespace io
49  {
50 
51  namespace pdf
52  {
53 
58  struct pdf_header
59  {
60  pdf_header(const poppler::document *doc);
61 
67  bool is_locked;
68  std::vector<char> metadata;
69  };
70 
71 
76  pdf_header get_header(const std::string& filename);
77 
78 
79 # ifndef MLN_INCLUDE_ONLY
80 
81  // Begin of pdf_header implementation.
82 
83  pdf_header::pdf_header(const poppler::document *doc)
84  {
85  page_count = doc->pages();
86  doc->get_pdf_version(&pdf_version_major, 0);
87  doc->get_pdf_version(0, &pdf_version_minor);
88  is_encrypted = doc->is_encrypted();
89  is_linearized = doc->is_linearized();
90  is_locked = doc->is_locked();
91  metadata = doc->metadata().to_utf8();
92  }
93 
94  // End of pdf_header implementation.
95 
96 
97 
98  inline
99  pdf_header get_header(const std::string& filename)
100  {
101  mln_trace("mln::io::pdf::get_header");
102 
103  // Load document
104  poppler::document *pdf = poppler::document::load_from_file(filename);
105  if (pdf == 0)
106  {
107  std::cerr << "Error: Cannot load PDF " << filename << std::endl;
108  abort();
109  }
110 
111  // Initialize structure with pdf information.
112  pdf_header header(pdf);
113 
114  // Clear pdf document.
115  delete pdf;
116 
117  return header;
118  }
119 
120 
121 # endif // ! MLN_INCLUDE_ONLY
122 
123  } // end of namespace mln::io::pdf
124 
125  } // end of namespace mln::io
126 
127 } // end of namespace mln
128 
129 #endif // ! MLN_IO_PDF_GET_HEADER_HH
130