source: wkhtmltox/trunk/fuentes/src/lib/pdf_c_bindings.cc @ 51

Last change on this file since 51 was 51, checked in by mabarracus, 4 years ago

wip

File size: 28.4 KB
Line 
1// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2// vi:set ts=4 sts=4 sw=4 noet :
3//
4// Copyright 2010 wkhtmltopdf authors
5//
6// This file is part of wkhtmltopdf.
7//
8// wkhtmltopdf is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Lesser General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12//
13// wkhtmltopdf is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public License
19// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
20
21
22/**
23 * \file pdf.h
24 * \brief Provides C bindings for pdf conversion
25 */
26#include "pdf_c_bindings_p.hh"
27#include "utilities.hh"
28#include <QApplication>
29#include <QWebFrame>
30
31#include <QHash>
32
33#include "dllbegin.inc"
34/**
35 * \page pagesettings Setting
36 * Settings can be supplied to PDF and image c-bindings using utf-8 encoded strings.
37 * This is done by relatively simple reflection on the CropSettings, HeaderFooter, Margin,
38 * ImageGlobal, PdfGlobal, PdfObject, Size, and TableOfContent classes.
39 *
40 * - The \ref wkhtmltopdf_global_settings corresponds to the PdfGlobal class and is documented in \ref pagePdfGlobal.
41 * - The \ref wkhtmltopdf_object_settings corresponds to the PdfGlobal class and is documented in \ref pagePdfObject.
42 * - The \ref wkhtmltopdf_image_settings corresponds to the ImageGlobal class and is documented in \ref pageImageGlobal.
43 *
44 * \section pageWeb Web page specific settings
45 * The following web page specific settings apply
46 * - \b web.background Should we print the background? Must be either "true" or "false".
47 * - \b web.loadImages Should we load images? Must be either "true" or "false".
48 * - \b web.enableJavascript Should we enable javascript? Must be either "true" or "false".
49 * - \b web.enableIntelligentShrinking Should we enable intelligent shrinkng to fit more content
50 *      on one page? Must be either "true" or "false". Has no effect for wkhtmltoimage.
51 * - \b web.minimumFontSize The minimum font size allowed. E.g. "9"
52 * - \b web.printMediaType Should the content be printed using the print media type instead
53 *      of the screen media type. Must be either "true" or "false". Has no effect for wkhtmltoimage.
54 * - \b web.defaultEncoding What encoding should we guess content is using if they do not
55 *      specify it properly? E.g. "utf-8"
56 * - \b web.userStyleSheet Url er path to a user specified style sheet.
57 * - \b web.enablePlugins Should we enable NS plugins, must be either "true" or "false".
58 *      Enabling this will have limited success.
59 *
60 * \section pageLoad Object Specific loading settings
61 * The following settings apply for object loading.
62 * - \b load.username The user name to use when loging into a website, E.g. "bart"
63 * - \b load.password The password to used when logging into a website, E.g. "elbarto"
64 * - \b load.jsdelay The mount of time in milliseconds to wait after a page has done loading until
65 *      it is actually printed. E.g. "1200". We will wait this amount of time or until, javascript
66 *      calls window.print().
67 * - \b load.zoomFactor How much should we zoom in on the content? E.g. "2.2".
68 * - \b load.customHeaders TODO
69 * - \b load.repertCustomHeaders Should the custom headers be sent all elements loaded instead of
70 *       only the main page? Must be either "true" or "false".
71 * - \b load.cookies TODO
72 * - \b load.post TODO
73 * - \b load.blockLocalFileAccess Disallow local and piped files to access other local files. Must
74 *      be either "true" or "false".
75 * - \b load.stopSlowScript Stop slow running javascript. Must be either "true" or "false".
76 * - \b load.debugJavascript Forward javascript warnings and errors to the warning callback.
77 *      Must be either "true" or "false".
78 * - \b load.loadErrorHandling How should we handle obejcts that fail to load. Must be one of:
79 *      - "abort" Abort the convertion process
80 *      - "skip" Do not add the object to the final output
81 *      - "ignore" Try to add the object to the final output.
82 * - \b load.proxy String describing what proxy to use when loading the object.
83 * - \b load.runScript TODO
84 *
85 * \section pageHeaderFooter Header and footer settings
86 * The same settings can be applied for headers and footers, here there are explained in
87 * terms of the header.
88 * - \b header.fontSize The font size to use for the header, e.g. "13"
89 * - \b header.fontName The name of the font to use for the header. e.g. "times"
90 * - \b header.left The string to print in the left part of the header, note that some sequences
91 *      are replaced in this string, see the wkhtmltopdf manual.
92 * - \b header.center The text to print in the center part of the header.
93 * - \b header.right The text to print in the right part of the header.
94 * - \b header.line Whether a line should be printed under the header (either "true" or "false").
95 * - \b header.spacing The amount of space to put between the header and the content, e.g. "1.8". Be
96 *      aware that if this is too large the header will be printed outside the pdf document. This
97 *      can be corrected with the margin.top setting.
98 * - \b header.htmlUrl Url for a HTML document to use for the header.
99 *
100 * \section pagePdfGlobal Pdf global settings
101 * The \ref wkhtmltopdf_global_settings structure contains the following settings:
102 * - \b size.paperSize  The paper size of the output document, e.g. "A4".
103 * - \b size.width The with of the output document, e.g.  "4cm".
104 * - \b size.height The height of the output document, e.g. "12in".
105 * - \b orientation The orientation of the output document, must be either "Landscape" or "Portrait".
106 * - \b colorMode Should the output be printed in color or gray scale, must be either "Color" or "Grayscale"
107 * - \b resolution Most likely has no effect.
108 * - \b dpi What dpi should we use when printing, e.g. "80".
109 * - \b pageOffset A number that is added to all page numbers when printing headers, footers and table of content.
110 * - \b copies How many copies should we print?. e.g. "2".
111 * - \b collate Should the copies be collated? Must be either "true" or "false".
112 * - \b outline Should a outline (table of content in the sidebar) be generated and put into the PDF? Must be either "true" or false".
113
114 * - \b outlineDepth The maximal depth of the outline, e.g. "4".
115 * - \b dumpOutline If not set to the empty string a XML representation of the outline is dumped to this file.
116 * - \b out The path of the output file, if "-" output is sent to stdout, if empty the output is stored in a buffer.
117 * - \b documentTitle The title of the PDF document.
118 * - \b useCompression Should we use loss less compression when creating the pdf file? Must be either "true" or "false".
119 * - \b margin.top Size of the top margin, e.g. "2cm"
120 * - \b margin.bottom Size of the bottom margin, e.g. "2cm"
121 * - \b margin.left Size of the left margin, e.g. "2cm"
122 * - \b margin.right Size of the right margin, e.g. "2cm"
123 * - \b imageDPI The maximal DPI to use for images in the pdf document.
124 * - \b imageQuality The jpeg compression factor to use when producing the pdf document, e.g. "92".
125 * - \b load.cookieJar Path of file used to load and store cookies.
126 *
127 * \section pagePdfObject Pdf object settings
128 * The \ref wkhtmltopdf_object_settings structure contains the following settings:
129 * - \b toc.useDottedLines Should we use a dotted line when creating a table of content?
130 *      Must be either "true" or "false".
131 * - \b toc.captionText The caption to use when creating a table of content.
132 * - \b toc.forwardLinks Should we create links from the table of content into the actual content?
133 *      Must be either "true or "false.
134 * - \b toc.backLinks Should we link back from the content to this table of content.
135 * - \b toc.indentation The indentation used for every table of content level, e.g. "2em".
136 * - \b toc.fontScale How much should we scale down the font for every toc level? E.g. "0.8"
137 * - \b page The URL or path of the web page to convert, if "-" input is read from stdin.
138 * - \b header.* Header specific settings see \ref pageHeaderFooter.
139 * - \b footer.* Footer specific settings see \ref pageHeaderFooter.
140 * - \b useExternalLinks Should external links in the HTML document be converted into
141 *      external pdf links? Must be either "true" or "false.
142 * - \b useLocalLinks Should internal links in the HTML document be converted into pdf
143 *      references? Must be either "true" or "false"
144 * - \b replacements TODO
145 * - \b produceForms Should we turn HTML forms into PDF forms? Must be either "true" or file".
146 * - \b load.* Page specific settings related to loading content, see \ref pageLoad.
147 * - \b web.* See \ref pageWeb.
148 * - \b includeInOutline Should the sections from this document be included in the outline and table of content?
149 * - \b pagesCount Should we count the pages of this document, in the counter used for TOC, headers and footers?
150 * - \b tocXsl If not empty this object is a table of content object, "page" is ignored and this xsl style
151 *      sheet is used to convert the outline XML into a table of content.
152 */
153
154/**
155 * \struct wkhtmltopdf_global_settings
156 * \brief A struct holding global settings
157 *
158 * See also \ref pagePdfGlobal
159 */
160
161/**
162 * \struct wkhtmltopdf_object_settings
163 * \brief A struct holding object settings
164 *
165 * See also \ref pagePdfObject
166 */
167
168/**
169 * \struct wkhtmltopdf_converter
170 * \brief A struct holding information related to a conversion process
171 */
172
173/**
174 * \typedef wkhtmltopdf_str_callback
175 * \brief Function pointer type used for the error and warning callbacks
176 *
177 * \param converter The converter that issued the callback
178 * \param str A utf8 encoded string containing the error or warning message.
179 *
180 * \sa wkhtmltopdf_set_error_callback, wkhtmltopdf_set_warning_callback
181 */
182
183/**
184 * \typedef wkhtmltopdf_int_callback
185 * \brief Function pointer type used for the progress_changed and finished callbacks
186 *
187 * For the progress_changed callback the value indicated the progress
188 * within the current phase in percent. For the finished callback the value
189 * if 1 if the conversion has successful and 0 otherwise.
190 *
191 * \param converter The converter that issued the callback
192 * \param val The integer value
193 *
194 * \sa wkhtmltopdf_set_progress_changed, wkhtmltopdf_set_finished_callback
195 */
196
197/**
198 * \typedef wkhtmltopdf_void_callback
199 * \brief Function pointer type used for the phase_changed callback
200 *
201 * \param converter The converter that issued the callback
202 *
203 * \sa wkhtmltopdf_set_phase_changed_callback
204 */
205
206
207using namespace wkhtmltopdf;
208QApplication * a = 0;
209int usage = 0;
210
211void MyPdfConverter::warning(const QString & message) {
212        if (warning_cb) (warning_cb)(reinterpret_cast<wkhtmltopdf_converter*>(this), message.toUtf8().constData());
213}
214
215void MyPdfConverter::error(const QString & message) {
216        if (error_cb) (error_cb)(reinterpret_cast<wkhtmltopdf_converter*>(this), message.toUtf8().constData());
217}
218
219void MyPdfConverter::phaseChanged() {
220        if (phase_changed) (phase_changed)(reinterpret_cast<wkhtmltopdf_converter*>(this));
221}
222
223void MyPdfConverter::progressChanged(int progress) {
224        if (progress_changed) (progress_changed)(reinterpret_cast<wkhtmltopdf_converter*>(this), progress);
225}
226
227void MyPdfConverter::finished(bool ok) {
228        if (finished_cb) (finished_cb)(reinterpret_cast<wkhtmltopdf_converter*>(this), ok);
229}
230
231MyPdfConverter::MyPdfConverter(settings::PdfGlobal * gs):
232        warning_cb(0), error_cb(0), phase_changed(0), progress_changed(0), finished_cb(0),
233        converter(*gs), globalSettings(gs) {
234
235    connect(&converter, SIGNAL(warning(const QString &)), this, SLOT(warning(const QString &)));
236        connect(&converter, SIGNAL(error(const QString &)), this, SLOT(error(const QString &)));
237        connect(&converter, SIGNAL(phaseChanged()), this, SLOT(phaseChanged()));
238        connect(&converter, SIGNAL(progressChanged(int)), this, SLOT(progressChanged(int)));
239        connect(&converter, SIGNAL(finished(bool)), this, SLOT(finished(bool)));
240}
241
242MyPdfConverter::~MyPdfConverter() {
243        delete globalSettings;
244        for (size_t i=0; i < objectSettings.size(); ++i)
245                delete objectSettings[i];
246        objectSettings.clear();
247}
248
249
250/**
251 * \brief Check if the library is build against the wkhtmltopdf version of QT
252 *
253 * \return 1 if the library was build against the wkhtmltopdf version of QT and 0 otherwise
254 */
255CAPI(int) wkhtmltopdf_extended_qt() {
256#ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
257        return 1;
258#else
259        return 0;
260#endif
261}
262
263#define STRINGIZEE(a) # a
264#define STRINGIZE(a) STRINGIZEE(a)
265
266/**
267 * \brief Return the version of wkhtmltopdf
268 * Example: 0.12.1-development. The string is utf8 encoded and is owned by wkhtmltopdf.
269 *
270 * \return Qt version
271 */
272CAPI(const char *) wkhtmltopdf_version() {
273        return STRINGIZE(FULL_VERSION);
274}
275
276/**
277 * \brief Setup wkhtmltopdf
278 *
279 * Must be called before any other functions.
280 *
281 * \param use_graphics Should we use a graphics system
282 * \returns 1 on success and 0 otherwise
283 *
284 * \sa wkhtmltopdf_deinit
285 */
286CAPI(int) wkhtmltopdf_init(int use_graphics) {
287        ++usage;
288
289        if (qApp == 0) {
290                char x[256];
291                strcpy(x, "wkhtmltox");
292                char * arg[] = {x, 0};
293                int aa = 1;
294
295                bool ug = true;
296#if defined(Q_OS_UNIX) || defined(Q_OS_MAC)
297#ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
298                ug = use_graphics;
299                if (!ug) QApplication::setGraphicsSystem("raster");
300#else
301                Q_UNUSED(use_graphics);
302#endif
303#else
304                Q_UNUSED(use_graphics);
305#endif
306                a = new QApplication(aa, arg, ug);
307                MyLooksStyle * style = new MyLooksStyle();
308                a->setStyle(style);
309        }
310        return 1;
311}
312
313/**
314 * \brief Deinit wkhtmltopdf
315 *
316 * Free up resources used by wkhtmltopdf, when this has been called no other
317 * wkhtmltopdf function can be called.
318 *
319 * \returns 1 on success and 0 otherwise
320 *
321 * \sa wkhtmltopdf_init
322 */
323CAPI(int) wkhtmltopdf_deinit() {
324        --usage;
325        if (usage != 0) return 1;
326        if (a != 0) delete a;
327        return 1;
328}
329
330/**
331 * \brief Create a new global settings object for pdf conversion
332 *
333 * Create a new global settings object for pdf conversion, settings can be altered with
334 * \ref wkhtmltopdf_set_global_setting, and inspected with \ref wkhtmltopdf_get_global_setting.
335 * Once the desired settings have been set a converter object can be created using \reg wkhtmltopdf_create_converter.
336 *
337 * \returns A wkhtmltopdf global settings object
338 */
339CAPI(wkhtmltopdf_global_settings *) wkhtmltopdf_create_global_settings() {
340        return reinterpret_cast<wkhtmltopdf_global_settings *>(new settings::PdfGlobal());
341}
342
343/**
344 * \brief Destroy a global settings  object
345 *
346 * Normally one would not need to call this since ownership of the
347 * settings object is transfarred to the converter.
348 */
349CAPI(void) wkhtmltopdf_destroy_global_settings(wkhtmltopdf_global_settings * obj) {
350        delete reinterpret_cast<settings::PdfGlobal *>(obj);
351}
352
353/**
354 * \brief Alter a setting in a global settings object
355 *
356 * \sa \ref pagePdfGlobal, wkhtmltopdf_create_global_settings, wkhtmltopdf_get_global_setting
357 *
358 * \param settings The settings object to change
359 * \param name The name of the setting
360 * \param value The new value for the setting
361 * \returns 1 if the setting was updated successfully and 0 otherwise.
362 */
363CAPI(int) wkhtmltopdf_set_global_setting(wkhtmltopdf_global_settings * settings, const char * name, const char * value) {
364        return reinterpret_cast<settings::PdfGlobal *>(settings)->set(name, value);
365}
366
367/**
368 * \brief Retrieve a setting in a global settings object
369 *
370 * \sa \ref pagesettings, wkhtmltopdf_create_global_settings, wkhtmltopdf_set_global_setting
371 *
372 * \param settings The settings object to inspect
373 * \param name The name of the setting to read
374 * \param value A buffer of length at least \a vs, where the value is stored.
375 * \param vs The length of \a value
376 * \returns 1 If the the setting exists and was read successfully and 0 otherwise
377 */
378CAPI(int) wkhtmltopdf_get_global_setting(wkhtmltopdf_global_settings * settings, const char * name, char * value, int vs) {
379        QString res = reinterpret_cast<settings::PdfGlobal *>(settings)->get(name);
380        if (res.isNull()) return 0;
381        qstrncpy(value, res.toUtf8().constData(), vs);
382        return 1;
383}
384
385/**
386 * \brief Create an object used to store object settings
387 *
388 * Create a new Object settings object for pdf conversion, settings can be altered with
389 * \ref wkhtmltopdf_set_object_setting, and inspected with \ref wkhtmltopdf_get_object_setting.
390 * Once the desired settings have been set the object can be added to a converter
391 * by calling wkhtmltopdf_add_resource.
392 *
393 * \returns an object settings instance
394 */
395CAPI(wkhtmltopdf_object_settings *) wkhtmltopdf_create_object_settings() {
396        return reinterpret_cast<wkhtmltopdf_object_settings *>(new settings::PdfObject());
397}
398
399/**
400 * \brief Destroy a global settings  object
401 *
402 * Normally one would not need to call this since ownership of the
403 * settings object is transfarred to the converter.
404 */
405CAPI(void) wkhtmltopdf_destroy_object_settings(wkhtmltopdf_object_settings * obj) {
406        delete reinterpret_cast<settings::PdfObject *>(obj);
407}
408
409
410/**
411 * \brief Alter a setting in a object settings object
412 *
413 * \sa \ref pagesettings, wkhtmltopdf_create_object_settings, wkhtmltopdf_get_object_setting
414 *
415 * \param settings The settings object to change
416 * \param name The name of the setting
417 * \param value The new value for the setting
418 * \returns 1 if the setting was updated successfully and 0 otherwise.
419 */
420CAPI(int) wkhtmltopdf_set_object_setting(wkhtmltopdf_object_settings * settings, const char * name, const char * value) {
421        return reinterpret_cast<settings::PdfObject *>(settings)->set(name, value);
422}
423
424/**
425 * \brief Retrieve a setting in a global settings object
426 *
427 * \sa \ref pagesettings, wkhtmltopdf_create_global_settings, wkhtmltopdf_set_global_setting
428 *
429 * \param settings The settings object to inspect
430 * \param name The name of the setting to read
431 * \param value A buffer of length at least \a vs, where the value is stored.
432 * \param vs The length of \a value
433 * \returns 1 If the the setting exists and was read successfully and 0 otherwise
434 */
435CAPI(int) wkhtmltopdf_get_object_setting(wkhtmltopdf_object_settings * settings, const char * name, char * value, int vs) {
436        QString res = reinterpret_cast<settings::PdfObject *>(settings)->get(name);
437        if (res.isNull()) return 0;
438        qstrncpy(value, res.toUtf8().constData(), vs);
439        return 1;
440}
441
442/**
443 * \brief Create a wkhtmltopdf converter object
444 *
445 * The converter object is used to convert one or more objects(web sides) into a single pdf.
446 * Once a settings object has been parsed, it may no longer be accessed, and will eventually be freed.
447 * The returned converter object must be freed by calling \ref wkhtmltopdf_destroy_converter
448 *
449 * \param settings The global settings to use during conversion.
450 * \returns A wkhtmltopdf converter object
451 */
452CAPI(wkhtmltopdf_converter *) wkhtmltopdf_create_converter(wkhtmltopdf_global_settings * settings) {
453
454        return reinterpret_cast<wkhtmltopdf_converter *>(
455                new MyPdfConverter(reinterpret_cast<settings::PdfGlobal *>(settings)));
456}
457
458/**
459 * \brief Destroy a wkhtmltopdf converter object
460 *
461 * An object must be destroyed to free up its memory, once it has been destroyed it may no longer
462 * be accessed.
463 *
464 * \param settings The converter object to destroy
465 */
466CAPI(void) wkhtmltopdf_destroy_converter(wkhtmltopdf_converter * converter) {
467        reinterpret_cast<MyPdfConverter *>(converter)->deleteLater();
468}
469
470/**
471 * \brief Set the function that should be called when an errors occurs during conversion
472 *
473 * \param converter The converter object on which errors we want the callback to be called
474 * \param cb The function to call when an error occurs
475 */
476CAPI(void) wkhtmltopdf_set_warning_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_str_callback cb) {
477        reinterpret_cast<MyPdfConverter *>(converter)->warning_cb = cb;
478}
479
480/**
481 * \brief Set the function that should be called when an warning message is issued during conversion
482 *
483 * \param converter The converter object on which warnings we want the callback to be called
484 * \param cb The function to call when warning message is issued
485 *
486 */
487CAPI(void) wkhtmltopdf_set_error_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_str_callback cb) {
488        reinterpret_cast<MyPdfConverter *>(converter)->error_cb = cb;
489}
490
491/**
492 * \brief Set the function that should be called whenever conversion changes phase
493 *
494 * The number of the new phase can be found by calling \ref wkhtmltopdf_current_phase
495 *
496 * \param converter The converter which phase change events to call back from
497 * \param cb The function to call when phases change
498 *
499 * \sa wkhtmltopdf_current_phase, wkhtmltopdf_phase_count, wkhtmltopdf_phase_description
500 */
501CAPI(void) wkhtmltopdf_set_phase_changed_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_void_callback cb) {
502        reinterpret_cast<MyPdfConverter *>(converter)->phase_changed = cb;
503}
504
505/**
506 * \brief Set the function that should be called when progress have been done during conversion.
507 *
508 * The progress in percent within the current phase is given as an integer to the callback function.
509 *
510 * \param converter The converter which progress events to call back from
511 * \param cb The function to call when progress has occurred.
512 *
513 * \sa wkhtmltopdf_progress_description
514 */
515CAPI(void) wkhtmltopdf_set_progress_changed_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_int_callback cb) {
516        reinterpret_cast<MyPdfConverter *>(converter)->progress_changed = cb;
517}
518
519/**
520 * \brief Set the function that should be called once the conversion has finished.
521 *
522
523 * \param converter The converter which finish events to call back from
524 * \param cb The function to call when the conversion has finished has occurred.
525 *
526 * \sa wkhtmltopdf_convert
527 */
528CAPI(void) wkhtmltopdf_set_finished_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_int_callback cb) {
529        reinterpret_cast<MyPdfConverter *>(converter)->finished_cb = cb;
530}
531
532//CAPI(void) wkhtmltopdf_begin_conversion(wkhtmltopdf_converter * converter) {
533//      reinterpret_cast<MyPdfConverter *>(converter)->converter.beginConvertion();
534//}
535
536/**
537 * \brief Convert the input objects into a pdf document
538 *
539 * This is the main method for the conversion process, during conversion progress information
540 * warning, and errors are reported using the supplied call backs. Once the conversion is done
541 * the output pdf (or ps) file will be placed at the location of the "out" setting supplied in
542 * the global settings object during construction of the converter. If this setting is not supplied
543 * or set to the empty string, the output can be retrieved using the \ref wkhtmltopdf_get_output
544 * function.
545 *
546 * \paragm converter The converter to perform the conversion on.
547 *
548 * \returns 1 on success and 0 otherwise
549 */
550CAPI(int) wkhtmltopdf_convert(wkhtmltopdf_converter * converter) {
551        return reinterpret_cast<MyPdfConverter *>(converter)->converter.convert();
552}
553
554//CAPI(void) wkhtmltopdf_cancel(wkhtmltopdf_converter * converter) {
555//      reinterpret_cast<MyPdfConverter *>(converter)->converter.cancel();
556//}
557
558/**
559 * \brief add an object (web page to convert)
560 *
561 * Add the object described by the supplied object settings to the list of objects (web pages to convert),
562 * objects are placed in the output pdf in the order of addition. Once the object has been added, the
563 * supplied settings may no longer be accessed, it Wit eventually be freed by wkhtmltopdf.
564 * If a none NULL and none empty utf8 encoded string is supplied to data, this HTML content will be converted
565 * instead of the content located at  "page" setting of the supplied object settings instance.
566 *
567 * \param converter The converter to add the object to
568 * \param settings The setting describing the object to add
569 * \param data HTML content of the object to convert or NULL
570 */
571CAPI(void) wkhtmltopdf_add_object(wkhtmltopdf_converter * converter, wkhtmltopdf_object_settings * settings, const char * data) {
572        QString str= QString::fromUtf8(data);
573        reinterpret_cast<MyPdfConverter *>(converter)->converter.addResource(
574                *reinterpret_cast<settings::PdfObject *>(settings), &str);
575        reinterpret_cast<MyPdfConverter *>(converter)->objectSettings.push_back(reinterpret_cast<settings::PdfObject *>(settings));
576}
577
578/**
579 * \brief Get the number of the current conversion phase
580 *
581 * Conversion is done in a number of named phases, this
582 * function will retrieve the number of the current conversion phase,
583 * which will be a number between 0 and wkhtmltopdf_phase_count(converter)-1.
584 *
585 * The description (name) of any phase can be retrieved by calling the
586 * \ref wkhtmltopdf_phase_description method.
587 *
588 * \param converter The converter to find the current phase of
589 * \returns The current phase of the supplied converter
590 */
591CAPI(int) wkhtmltopdf_current_phase(wkhtmltopdf_converter * converter) {
592        return reinterpret_cast<MyPdfConverter *>(converter)->converter.currentPhase();
593}
594
595/**
596 * \brief Get the total number of phases the conversion process will go trough
597 *
598 * \param converter The converter to query
599 * \returns The total number of phases in the conversion process
600 *
601 * \sa wkhtmltopdf_current_phase, wkhtmltopdf_phase_description
602 */
603CAPI(int) wkhtmltopdf_phase_count(wkhtmltopdf_converter * converter) {
604        return reinterpret_cast<MyPdfConverter *>(converter)->converter.phaseCount();
605}
606
607
608/**
609 * \brief Return a short utf8 description of a conversion phase
610 *
611 * \param converter The converter to query
612 * \param phase The number of the conversion step of which we want a description
613 * \returns A description of the conversion phase
614 *
615 * \sa wkhtmltopdf_current_phase, wkhtmltopdf_phase_description
616 */
617CAPI(const char *) wkhtmltopdf_phase_description(wkhtmltopdf_converter * converter, int phase) {
618  MyPdfConverter* conv = reinterpret_cast<MyPdfConverter *>(converter);
619        QString pd = conv->converter.phaseDescription(phase);
620        if (!conv->utf8StringCache.contains(pd))
621        {
622                return conv->utf8StringCache.insert(pd, pd.toUtf8()).value().constData();
623        }
624        else
625                return conv->utf8StringCache[pd].constData();
626}
627
628/**
629 * \brief Return a short utf8 string indicating progress within a phase
630 *
631 * Will typically return a string like "40%"
632 *
633 * \param converter The converter to query
634 * \returns A string containing a progress indication
635 *
636 * \sa wkhtmltopdf_set_progress_changed_callback
637 */
638CAPI(const char *) wkhtmltopdf_progress_string(wkhtmltopdf_converter * converter) {
639  MyPdfConverter* conv = reinterpret_cast<MyPdfConverter *>(converter);
640        QString ps = conv->converter.progressString();
641        if (!conv->utf8StringCache.contains(ps))
642                return conv->utf8StringCache.insert(ps, ps.toUtf8()).value().constData();
643        else
644                return conv->utf8StringCache[ps].constData();
645}
646
647/**
648 * \brief Return the largest HTTP error code encountered during conversion
649 *
650 * Return the largest HTTP code greater then or equal to 300 encountered during loading
651 * of any of the supplied objects, if no such error code is found 0 is returned.
652 * This function will only return a useful result after \ref wkhtmltopdf_convert has been called.
653 *
654 * \param converter The converter to query
655 * \returns The HTTP error code.
656 */
657CAPI(int) wkhtmltopdf_http_error_code(wkhtmltopdf_converter * converter) {
658        return reinterpret_cast<MyPdfConverter *>(converter)->converter.httpErrorCode();
659}
660
661/**
662 * \brief Get the output document generated during conversion.
663 *
664 * If no "out" location was specified in the global settings object, the binary
665 * output (pdf document) of the convection process will be stored in a buffer.
666 *
667 * \param converter The converter to query
668 * \param d A pointer to a pointer that will be made to point to the output data
669 * \returns The length of the output data
670 */
671CAPI(long) wkhtmltopdf_get_output(wkhtmltopdf_converter * converter, const unsigned char ** d) {
672        const QByteArray & out = reinterpret_cast<MyPdfConverter *>(converter)->converter.output();
673        *d = (const unsigned char*)out.constData();
674        return out.size();
675}
676
677//  LocalWords:  eval progn stroustrup innamespace sts sw noet wkhtmltopdf DLL
678//  LocalWords:  ifdef WKHTMLTOX UNDEF undef endif pdf dllbegin namespace const
679//  LocalWords:  QString cb bool ok globalSettings phaseChanged progressChanged
680//  LocalWords:  objectSettings utf CropSettings HeaderFooter ImageGlobal dpi sa
681//  LocalWords:  PdfGlobal PdfObject TableOfContent pagePdfGlobal pagePdfObject
682//  LocalWords:  pageImageGlobal pageGlobalLoad paperSize colorMode Grayscale
683//  LocalWords:  pageOffset outlineDepth dumpOutline stdout pageLoad pageWeb aa
684//  LocalWords:  includeInOutline pagesCount tocXsl xsl struct typedef str CAPI
685//  LocalWords:  param STRINGIZEE STRINGIZE deinit qApp strcpy wkhtmltox arg ug
686//  LocalWords:  WS MACX MyLooksStyle setStyle isNull qstrncpy MyPdfConverter
687//  LocalWords:  beginConvertion paragm addResource currentPhase phaseCount
688//  LocalWords:  urrent http httpErrorCode QByteArray constData
Note: See TracBrowser for help on using the repository browser.