2
* Simple PDF import extension using libpoppler and Cairo's SVG surface.
7
* Copyright (C) 2007 Authors
9
* Released under GNU GPL, read the file 'COPYING' for more information
17
#ifdef HAVE_POPPLER_GLIB
19
#include "pdf-input-cairo.h"
20
#include "extension/system.h"
21
#include "extension/input.h"
24
#include <cairo-svg.h>
25
#include <poppler/glib/poppler.h>
26
#include <poppler/glib/poppler-document.h>
27
#include <poppler/glib/poppler-page.h>
33
static cairo_status_t _write_ustring_cb(void *closure, const unsigned char *data, unsigned int length);
36
PdfInputCairo::open(Inkscape::Extension::Input * mod, const gchar * uri) {
38
printf("Attempting to open using PdfInputCairo\n");
40
gchar* filename_uri = g_filename_to_uri(uri, NULL, NULL);
42
PopplerDocument* document = poppler_document_new_from_file(filename_uri, NULL, NULL);
47
PopplerPage* page = poppler_document_get_page(document, 0);
48
poppler_page_get_size(page, &width, &height);
50
Glib::ustring* output = new Glib::ustring("");
51
cairo_surface_t* surface = cairo_svg_surface_create_for_stream(Inkscape::Extension::Internal::_write_ustring_cb,
52
output, width, height);
53
cairo_t* cr = cairo_create(surface);
55
poppler_page_render(page, cr);
59
cairo_surface_destroy(surface);
61
SPDocument * doc = sp_document_new_from_mem(output->c_str(), output->length(), TRUE);
65
g_object_unref(document);
71
_write_ustring_cb(void *closure, const unsigned char *data, unsigned int length)
73
Glib::ustring* stream = (Glib::ustring*)closure;
74
stream->append((const char*)data, length);
76
return CAIRO_STATUS_SUCCESS;
83
PdfInputCairo::init(void) {
84
Inkscape::Extension::Extension * ext;
86
ext = Inkscape::Extension::build_from_mem(
87
"<inkscape-extension>\n"
88
"<name>PDF Input</name>\n"
89
"<id>org.inkscape.input.pdf</id>\n"
91
"<extension>.pdf</extension>\n"
92
"<mimetype>application/pdf</mimetype>\n"
93
"<filetypename>Adobe PDF (*.pdf)</filetypename>\n"
94
"<filetypetooltip>PDF Document</filetypetooltip>\n"
96
"</inkscape-extension>", new PdfInputCairo());
99
} } } /* namespace Inkscape, Extension, Implementation */
101
#endif /* HAVE_POPPLER_GLIB */
106
c-file-style:"stroustrup"
107
c-file-offsets:((innamespace . 0)(inline-open . 0))
112
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :