1 /* poppler-qt.h: qt interface to poppler 2 * Copyright (C) 2005, Net Integration Technologies, Inc. 3 * Copyright (C) 2005, Tobias Koening <tokoe@kde.org> 4 * Copyright (C) 2005-2007, Albert Astals Cid <aacid@kde.org> 5 * Copyright (C) 2005-2006, Stefan Kebekus <stefan.kebekus@math.uni-koeln.de> 6 * Copyright (C) 2006, Wilfried Huss <Wilfried.Huss@gmx.at> 7 * Copyright (C) 2010 Hib Eris <hib@hiberis.nl> 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2, or (at your option) 12 * any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 22 */ 23 24 #ifndef __POPPLER_QT_H__ 25 #define __POPPLER_QT_H__ 26 27 #include "poppler-link-qt3.h" 28 #include "poppler-page-transition.h" 29 30 #include <qcstring.h> 31 #include <qdatetime.h> 32 #include <qdom.h> 33 #include <qpixmap.h> 34 35 namespace Poppler { 36 37 class Document; 38 class Page; 39 40 /* A rectangle on a page, with coordinates in PDF points. */ 41 class Rectangle 42 { 43 public: 44 Rectangle(double x1 = 0, double y1 = 0, double x2 = 0, double y2 = 0) : m_x1(x1)45 m_x1(x1), m_y1(y1), m_x2(x2), m_y2(y2) {} isNull()46 bool isNull() const { return m_x1 == 0 && m_y1 == 0 && m_x2 == 0 && m_y2 == 0; } 47 48 double m_x1; 49 double m_y1; 50 double m_x2; 51 double m_y2; 52 }; 53 54 class TextBox 55 { 56 public: TextBox(const QString & text,const Rectangle & bBox)57 TextBox(const QString& text, const Rectangle &bBox) : 58 m_text(text), m_bBox(bBox) {}; 59 getText()60 QString getText() const { return m_text; }; getBoundingBox()61 Rectangle getBoundingBox() const { return m_bBox; }; 62 63 private: 64 QString m_text; 65 Rectangle m_bBox; 66 }; 67 68 69 /** 70 Container class for information about a font within a PDF document 71 */ 72 class FontInfoData; 73 class FontInfo { 74 public: 75 enum Type { 76 unknown, 77 Type1, 78 Type1C, 79 Type1COT, 80 Type3, 81 TrueType, 82 TrueTypeOT, 83 CIDType0, 84 CIDType0C, 85 CIDType0COT, 86 CIDTrueType, 87 CIDTrueTypeOT 88 }; 89 90 /** 91 Create a new font information container 92 */ 93 FontInfo( const QString &fontName, const bool isEmbedded, 94 const bool isSubset, Type type ); 95 96 FontInfo(); 97 98 FontInfo( const FontInfo &fi ); 99 100 ~FontInfo(); 101 102 /** 103 The name of the font. Can be QString::null if the font has no name 104 */ 105 const QString &name() const; 106 107 /** 108 Whether the font is embedded in the file, or not 109 110 \return true if the font is embedded 111 */ 112 bool isEmbedded() const; 113 114 /** 115 Whether the font provided is only a subset of the full 116 font or not. This only has meaning if the font is embedded. 117 118 \return true if the font is only a subset 119 */ 120 bool isSubset() const; 121 122 /** 123 The type of font encoding 124 */ 125 Type type() const; 126 127 const QString &typeName() const; 128 129 private: 130 FontInfoData *data; 131 }; 132 133 class PageData; 134 class Page { 135 friend class Document; 136 public: 137 ~Page(); 138 void renderToPixmap(QPixmap **q, int x, int y, int w, int h, double xres, double yres, bool doLinks = false) const; 139 140 /** 141 This is a convenience function that is equivalent to 142 renderToPixmap() with xres and yres set to 72.0. We keep it 143 only for binary compatibility 144 145 \sa renderToImage() 146 */ 147 void renderToPixmap(QPixmap **q, int x, int y, int w, int h, bool doLinks = false) const; 148 149 /** 150 \brief Render the page to a QImage using the Splash renderer 151 152 This method can be used to render the page to a QImage. It 153 uses the "Splash" rendering engine. 154 155 \param xres horizontal resolution of the graphics device, 156 in dots per inch (defaults to 72 dpi) 157 158 \param yres vertical resolution of the graphics device, in 159 dots per inch (defaults to 72 dpi) 160 161 \returns a QImage of the page. 162 163 \sa renderToPixmap() 164 */ 165 QImage renderToImage(double xres = 72.0, double yres = 72.0, bool doLinks = false) const; 166 167 /** 168 * Returns the size of the page in points 169 **/ 170 QSize pageSize() const; 171 172 /** 173 * Returns the text that is inside the Rectangle r 174 * If r is a null Rectangle all text of the page is given 175 **/ 176 QString getText(const Rectangle &r) const; 177 178 QValueList<TextBox*> textList() const; 179 180 /** 181 * Returns the transition of this page 182 **/ 183 PageTransition *getTransition() const; 184 185 enum Orientation { 186 Landscape, 187 Portrait, 188 Seascape, 189 UpsideDown 190 }; 191 192 /** 193 * The orientation of the page 194 **/ 195 Orientation orientation() const; 196 197 /** 198 Gets the links of the page once it has been rendered if doLinks was true 199 */ 200 QValueList<Link*> links() const; 201 202 private: 203 Page(const Document *doc, int index); 204 PageData *data; 205 }; 206 207 class DocumentData; 208 209 class Document { 210 friend class Page; 211 212 public: 213 enum PageMode { 214 UseNone, 215 UseOutlines, 216 UseThumbs, 217 FullScreen, 218 UseOC 219 }; 220 221 static Document *load(const QString & filePath); 222 223 Page *getPage(int index) const; 224 225 int getNumPages() const; 226 227 PageMode getPageMode() const; 228 229 bool unlock(const QCString &password); 230 231 bool isLocked() const; 232 233 QDateTime getDate( const QString & data ) const; 234 QString getInfo( const QString & data ) const; 235 bool isEncrypted() const; 236 bool isLinearized() const; 237 bool okToPrint() const; 238 bool okToChange() const; 239 bool okToCopy() const; 240 bool okToAddNotes() const; 241 double getPDFVersion() const; 242 /** 243 The version of the PDF specification that the document 244 conforms to 245 246 \param major an optional pointer to a variable where store the 247 "major" number of the version 248 \param minor an optional pointer to a variable where store the 249 "minor" number of the version 250 251 \since 0.12 252 */ 253 void getPdfVersion(int *major, int *minor) const; 254 255 bool print(const QString &fileName, QValueList<int> pageList, double hDPI, double vDPI, int rotate); 256 257 // If you are using QPrinter you can get paper size doing 258 // QPrinter dummy(QPrinter::PrinterResolution); 259 // dummy.setFullPage(true); 260 // dummy.setPageSize(thePageSizeYouWant); 261 // QPaintDeviceMetrics metrics(&dummy); 262 // int width = metrics.width(); 263 // int height = metrics.height(); 264 bool print(const QString &fileName, QValueList<int> pageList, double hDPI, double vDPI, int rotate, int paperWidth, int paperHeight); 265 266 /** 267 The fonts within the PDF document. 268 269 \note this can take a very long time to run with a large 270 document. You may wish to use the call below if you have more 271 than say 20 pages 272 */ 273 QValueList<FontInfo> fonts() const; 274 275 /** 276 \overload 277 278 \param numPages the number of pages to scan 279 \param fontList pointer to the list where the font information 280 should be placed 281 282 \return false if the end of the document has been reached 283 */ 284 bool scanForFonts( int numPages, QValueList<FontInfo> *fontList ) const; 285 286 /** 287 Gets the TOC of the Document, it is application responsabiliy to delete 288 it when no longer needed 289 290 * In the tree the tag name is the 'screen' name of the entry. A tag can have 291 * attributes. Here follows the list of tag attributes with meaning: 292 * - Destination: A string description of the referred destination 293 * - DestinationName: A 'named reference' to the viewport that must be converted 294 * using linkDestination( *destination_name* ) 295 * - ExternalFileName: A link to a external filename 296 297 \returns NULL if the Document does not have TOC 298 */ 299 QDomDocument *toc() const; 300 301 LinkDestination *linkDestination( const QString &name ); 302 303 ~Document(); 304 305 private: 306 DocumentData *data; 307 Document(DocumentData *dataA); 308 }; 309 310 } 311 #endif 312