Hey, I'm currently writing an application which streams PDF data from the network, then views it using Poppler. Not only is it inconvenient, but in this case, it is also legally dubious to save this data to disk for the purposes of using poppler_document_new_from_file.
As described in bug #9332, a new method which takes a char* argument for the data is required. The attached patch adds this support to the GLib frontend, creating a MemStream and then passing it into a new PDFDoc. Let me know what you think. -Brad -- Brad Taylor http://www.getcoded.net
Index: ChangeLog
===================================================================
RCS file: /cvs/poppler/poppler/ChangeLog,v
retrieving revision 1.449
diff -u -r1.449 ChangeLog
--- ChangeLog 12 Dec 2006 05:23:59 -0000 1.449
+++ ChangeLog 14 Dec 2006 19:43:23 -0000
@@ -1,3 +1,9 @@
+2006-12-14 Brad Taylor <[EMAIL PROTECTED]>
+
+ * poppler/glib/poppler-document.h:
+ * poppler/glib/poppler-document.cc: Add poppler_document_new_from_data
+ to allow loading PDFs out of memory.
+
2006-12-12 Jeff Muizelaar <[EMAIL PROTECTED]>
* poppler/CairoOutputDev.cc: Change a cairo_set_matrix to
Index: glib/poppler-document.cc
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-document.cc,v
retrieving revision 1.37
diff -u -r1.37 poppler-document.cc
--- glib/poppler-document.cc 19 May 2006 22:12:38 -0000 1.37
+++ glib/poppler-document.cc 14 Dec 2006 19:43:24 -0000
@@ -141,6 +141,87 @@
}
/**
+ * poppler_document_new_from_data:
+ * @data: the pdf data contained in a char array
+ * @start: the start position of #data
+ * @length: the length of #data
+ * @password: password to unlock the file with, or %NULL
+ * @error: Return location for an error, or %NULL
+ *
+ * Creates a new #PopplerDocument. If %NULL is returned, then @error will be
+ * set. Possible errors include those in the #POPPLER_ERROR and #G_FILE_ERROR
+ * domains.
+ *
+ * Return value: A newly created #PopplerDocument, or %NULL
+ **/
+PopplerDocument *
+poppler_document_new_from_data (char *data,
+ int start,
+ int length,
+ const char *password,
+ GError **error)
+{
+ PopplerDocument *document;
+ Object obj;
+ PDFDoc *newDoc;
+ MemStream *str;
+ GooString *password_g;
+ int err;
+ char *filename;
+
+ document = (PopplerDocument *) g_object_new (POPPLER_TYPE_DOCUMENT, NULL, NULL);
+
+ if (!globalParams) {
+ globalParams = new GlobalParams("/etc/xpdfrc");
+ }
+
+ // create stream
+ obj.initNull();
+ str = new MemStream(data, start, length, &obj);
+
+ password_g = NULL;
+ if (password != NULL)
+ password_g = new GooString (password);
+
+ newDoc = new PDFDoc(str, password_g, password_g);
+ if (password_g)
+ delete password_g;
+
+ if (!newDoc->isOk()) {
+ err = newDoc->getErrorCode();
+ delete newDoc;
+ if (err == errEncrypted) {
+ g_set_error (error, POPPLER_ERROR,
+ POPPLER_ERROR_ENCRYPTED,
+ "Document is encrypted.");
+ } else {
+ g_set_error (error, G_FILE_ERROR,
+ G_FILE_ERROR_FAILED,
+ "Failed to load document from data (error %d)'\n",
+ err);
+ }
+
+ return NULL;
+ }
+
+ document->doc = newDoc;
+
+#if defined (HAVE_CAIRO)
+ document->output_dev = new CairoOutputDev ();
+#elif defined (HAVE_SPLASH)
+ SplashColor white;
+ white[0] = 255;
+ white[1] = 255;
+ white[2] = 255;
+ document->output_dev = new SplashOutputDev(splashModeRGB8, 4, gFalse, white);
+#endif
+ document->output_dev->startDoc(document->doc->getXRef ());
+
+ return document;
+}
+
+
+/**
* poppler_document_save:
* @document: a #PopplerDocument
* @uri: uri of file to save
Index: glib/poppler-document.h
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-document.h,v
retrieving revision 1.21
diff -u -r1.21 poppler-document.h
--- glib/poppler-document.h 19 May 2006 22:19:21 -0000 1.21
+++ glib/poppler-document.h 14 Dec 2006 19:43:24 -0000
@@ -92,6 +92,11 @@
PopplerDocument *poppler_document_new_from_file (const char *uri,
const char *password,
GError **error);
+PopplerDocument *poppler_document_new_from_data (char *data,
+ int start,
+ int length,
+ const char *password,
+ GError **error);
gboolean poppler_document_save (PopplerDocument *document,
const char *uri,
GError **error);
signature.asc
Description: This is a digitally signed message part
_______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
