/** \file * Native PDF import using libpoppler. * * Authors: * miklos erdelyi * * Copyright (C) 2007 Authors * * Released under GNU GPL, read the file 'COPYING' for more information * */ #ifdef HAVE_CONFIG_H # include #endif #ifdef HAVE_POPPLER #include "goo/GooString.h" #include "ErrorCodes.h" #include "GlobalParams.h" #include "PDFDoc.h" #include "Page.h" #include "Catalog.h" #include "pdf-input.h" #include "extension/system.h" #include "extension/input.h" #include "svg-builder.h" #include "pdf-parser.h" #include "document-private.h" namespace Inkscape { namespace Extension { namespace Internal { /** * Parses the first page of the given PDF document using PdfParser. */ SPDocument * PdfInput::open(::Inkscape::Extension::Input * mod, const gchar * uri) { // Initialize the globalParams variable for poppler if (!globalParams) { globalParams = new GlobalParams(); } GooString *filename_goo = new GooString(uri); PDFDoc *pdf_doc = new PDFDoc(filename_goo, NULL, NULL, NULL); // TODO: Could ask for password if (!pdf_doc->isOk()) { int error = pdf_doc->getErrorCode(); delete pdf_doc; if (error == errEncrypted) { g_message("Document is encrypted."); } else { g_message("Failed to load document from data (error %d)", error); } return NULL; } // Get needed page int page_num = 1; Catalog *catalog = pdf_doc->getCatalog(); Page *page = catalog->getPage(page_num); SPDocument *doc = sp_document_new(NULL, TRUE, TRUE); bool saved = sp_document_get_undo_sensitive(doc); sp_document_set_undo_sensitive(doc, false); // No need to undo in this temporary document // Create builder and parser gchar *docname = g_path_get_basename(uri); gchar *dot = g_strrstr(docname, "."); if (dot) { *dot = 0; } SvgBuilder *builder = new SvgBuilder(doc, docname, pdf_doc->getXRef()); PdfParser *pdf_parser = new PdfParser(pdf_doc->getXRef(), builder, page_num-1, page->getRotate(), page->getResourceDict(), page->getCropBox()); // Parse the document structure Object obj; page->getContents(&obj); if (!obj.isNull()) { pdf_parser->parse(&obj); } // Cleanup obj.free(); delete pdf_parser; delete builder; g_free(docname); delete pdf_doc; // Restore undo sp_document_set_undo_sensitive(doc, saved); return doc; } #include "../clear-n_.h" void PdfInput::init(void) { Inkscape::Extension::Extension * ext; /* PDF in */ ext = Inkscape::Extension::build_from_mem( "\n" "PDF Input\n" "org.inkscape.input.pdf\n" "\n" ".pdf\n" "application/pdf\n" "Adobe PDF (*.pdf) [via poppler]\n" "Adobe Portable Document Format\n" "\n" "", new PdfInput()); /* AI in */ ext = Inkscape::Extension::build_from_mem( "\n" "AI Input\n" "org.inkscape.input.ai\n" "\n" ".ai\n" "image/x-adobe-illustrator\n" "Adobe Illustrator (*.ai) [PDF-based]\n" "Open files saved with recent versions of Adobe Illustrator\n" "\n" "", new PdfInput()); } // init } } } /* namespace Inkscape, Extension, Implementation */ #endif /* HAVE_POPPLER */ /* Local Variables: mode:c++ c-file-style:"stroustrup" c-file-offsets:((innamespace . 0)(inline-open . 0)) indent-tabs-mode:nil fill-column:99 End: */ // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :