Hi all,
Initially I created a patch for embedding videos into the pdf. But
some of the good suggestions made me to split it into several different
patches.
I added functionality for creating a FileSpec object from the file path. By
embedding its contents in to the pdf. Please give all your suggestions.
Thanks
--
Regards
Index: poppler-0.16.2/poppler/FileSpec.cc
===================================================================
--- poppler-0.16.2/poppler/FileSpec.cc (revision 14)
+++ poppler-0.16.2/poppler/FileSpec.cc (working copy)
@@ -23,8 +23,25 @@
#include <config.h>
+#include "XRef.h"
#include "FileSpec.h"
+#include "PDFDocEncoding.h"
+const char* getFileNameFromPath (const char *filePath) {
+ const char *filename;
+#ifdef _WIN32
+ filename = strrchr(filePath, '\\');
+#else
+ filename = strrchr(filePath, '/');
+#endif
+
+ if (filename)
+ filename++;
+ else
+ filename = filePath;
+ return filename;
+}
+
GBool getFileSpecName (Object *fileSpec, Object *fileName)
{
if (fileSpec->isString()) {
@@ -138,3 +155,57 @@
return gTrue;
}
+
+static GBool getFileSpecObject(XRef *xref, Stream *stream, const char* fileName, Object *obj) {
+ Object fileSpec, obj1, obj2;
+ int length;
+
+ fileSpec.initDict(xref);
+ fileSpec.dictSet("Type", obj1.initName("Filespec"));
+ fileSpec.dictSet("F", obj1.initString(new GooString(fileName)));
+
+ GooString *name = new GooString(fileName);
+ char *fileNameUTF16 = pdfDocEncodingToUTF16(name, &length);
+ fileSpec.dictSet("UF", obj1.initString(new GooString(fileNameUTF16, length)));
+
+ delete(fileNameUTF16);
+ delete(name);
+
+ obj1.initStream(stream);
+
+ Ref newRef = xref->addIndirectObject(&obj1);
+ obj2.initRef(newRef.num, newRef.gen);
+ obj1.initDict(xref);
+ obj1.dictSet("F", &obj2);
+ fileSpec.dictSet("EF", &obj1);
+
+ Ref ref = xref->addIndirectObject(&fileSpec);
+ obj->initRef(ref.num, ref.gen);
+
+ return gTrue;
+}
+
+GBool createFilespec (XRef *xref, GooString *filePathA, Object *obj) {
+ Object obj1, obj2;
+ FILE *fs;
+ unsigned int size = 0;
+
+ const char *filePath = filePathA->getCString();
+
+ if (!(fs = fopen(filePath, "rb"))) {
+ error(-1, "Couldn't open file '%s'", filePath);
+ obj->initNull();
+ }
+ fseek(fs, 0, SEEK_END);
+ size = ftell(fs);
+
+ // Extract the video name from the file uri
+ const char *filename = getFileNameFromPath(filePath);
+
+ obj1.initDict(xref); // file stream eictionary
+ obj1.dictSet("Length", obj2.initInt(size));
+
+ FileStream *stream = new FileStream(fs, 0, 0, size, &obj1);
+
+ return getFileSpecObject (xref, stream, filename, obj);
+}
Index: poppler-0.16.2/poppler/FileSpec.h
===================================================================
--- poppler-0.16.2/poppler/FileSpec.h (revision 14)
+++ poppler-0.16.2/poppler/FileSpec.h (working copy)
@@ -18,7 +18,9 @@
#include "goo/gtypes.h"
#include "Object.h"
+const char* getFileNameFromPath (const char *filepath);
GBool getFileSpecName (Object *fileSpec, Object *fileName);
GBool getFileSpecNameForPlatform (Object *fileSpec, Object *fileName);
+GBool createFilespec (XRef *xref, GooString *filepath, Object *obj);
#endif /* FILE_SPEC_H */
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler