+ if(!globalParams)
+ globalParams = new GlobalParams("");
+
+ msg("<notice> Adding %s to language pack directories", dir);
+
+ int l;
+ FILE*fi = 0;
+ char* config_file = (char*)malloc(strlen(dir) + 1 + sizeof("add-to-xpdfrc") + 1);
+ strcpy(config_file, dir);
+ strcat(config_file, dirseparator());
+ strcat(config_file, "add-to-xpdfrc");
+
+ fi = fopen(config_file, "rb");
+ if(!fi) {
+ msg("<error> Could not open %s", config_file);
+ return;
+ }
+ globalParams->parseFile(new GString(config_file), fi);
+ fclose(fi);
+}
+
+void pdfswf_addfontdir(char*dirname)
+{
+#ifdef HAVE_DIRENT_H
+ msg("<notice> Adding %s to font directories", dirname);
+ lastfontdir = strdup(dirname);
+ DIR*dir = opendir(dirname);
+ if(!dir) {
+ msg("<warning> Couldn't open directory %s\n", dirname);
+ return;
+ }
+ struct dirent*ent;
+ while(1) {
+ ent = readdir (dir);
+ if (!ent)
+ break;
+ int l;
+ char*name = ent->d_name;
+ char type = 0;
+ if(!name) continue;
+ l=strlen(name);
+ if(l<4)
+ continue;
+ if(!strncasecmp(&name[l-4], ".pfa", 4))
+ type=1;
+ if(!strncasecmp(&name[l-4], ".pfb", 4))
+ type=3;
+ if(!strncasecmp(&name[l-4], ".ttf", 4))
+ type=2;
+ if(type)
+ {
+ char*fontname = (char*)malloc(strlen(dirname)+strlen(name)+2);
+ strcpy(fontname, dirname);
+ strcat(fontname, dirseparator());
+ strcat(fontname, name);
+ msg("<verbose> Adding %s to fonts", fontname);
+ pdfswf_addfont(fontname);
+ }
+ }
+ closedir(dir);
+#else
+ msg("<warning> No dirent.h- unable to add font dir %s", dir);
+#endif
+}
+
+
+typedef struct _pdf_doc_internal
+{
+ int protect;
+ PDFDoc*doc;
+ InfoOutputDev*info;
+} pdf_doc_internal_t;
+typedef struct _pdf_page_internal
+{
+} pdf_page_internal_t;
+typedef struct _dev_output_internal
+{
+ SWFOutputDev*outputDev;
+} dev_output_internal_t;
+
+pdf_doc_t* pdf_init(char*filename, char*userPassword)
+{
+ pdf_doc_t*pdf_doc = (pdf_doc_t*)malloc(sizeof(pdf_doc_t));
+ memset(pdf_doc, 0, sizeof(pdf_doc_t));
+ pdf_doc_internal_t*i= (pdf_doc_internal_t*)malloc(sizeof(pdf_doc_internal_t));
+ memset(i, 0, sizeof(pdf_doc_internal_t));
+ pdf_doc->internal = i;
+
+ GString *fileName = new GString(filename);
+ GString *userPW;
+ Object info;
+
+ // read config file
+ if(!globalParams)
+ globalParams = new GlobalParams("");
+
+ // open PDF file
+ if (userPassword && userPassword[0]) {
+ userPW = new GString(userPassword);
+ } else {
+ userPW = NULL;
+ }
+ i->doc = new PDFDoc(fileName, userPW);
+ if (userPW) {
+ delete userPW;
+ }
+ if (!i->doc->isOk()) {
+ return 0;
+ }
+
+ // print doc info
+ i->doc->getDocInfo(&info);
+ if (info.isDict() &&
+ (getScreenLogLevel()>=LOGLEVEL_NOTICE)) {
+ printInfoString(info.getDict(), "Title", "Title: %s\n");
+ printInfoString(info.getDict(), "Subject", "Subject: %s\n");
+ printInfoString(info.getDict(), "Keywords", "Keywords: %s\n");
+ printInfoString(info.getDict(), "Author", "Author: %s\n");
+ printInfoString(info.getDict(), "Creator", "Creator: %s\n");
+ printInfoString(info.getDict(), "Producer", "Producer: %s\n");
+ printInfoDate(info.getDict(), "CreationDate", "CreationDate: %s\n");
+ printInfoDate(info.getDict(), "ModDate", "ModDate: %s\n");
+ printf("Pages: %d\n", i->doc->getNumPages());
+ printf("Linearized: %s\n", i->doc->isLinearized() ? "yes" : "no");
+ printf("Encrypted: ");
+ if (i->doc->isEncrypted()) {
+ printf("yes (print:%s copy:%s change:%s addNotes:%s)\n",
+ i->doc->okToPrint() ? "yes" : "no",
+ i->doc->okToCopy() ? "yes" : "no",
+ i->doc->okToChange() ? "yes" : "no",
+ i->doc->okToAddNotes() ? "yes" : "no");
+ } else {
+ printf("no\n");
+ }
+ }
+ info.free();
+
+ pdf_doc->num_pages = i->doc->getNumPages();
+ i->protect = 0;
+ if (i->doc->isEncrypted()) {
+ if(!i->doc->okToCopy()) {
+ printf("PDF disallows copying.\n");
+ return 0;
+ }
+ if(!i->doc->okToChange() || !i->doc->okToAddNotes())
+ i->protect = 1;
+ }
+
+ InfoOutputDev*io = new InfoOutputDev();
+ int t;
+ for(t=1;t<=pdf_doc->num_pages;t++) {
+ i->doc->displayPage((OutputDev*)io, t, zoom, zoom, /*rotate*/0, /*usemediabox*/true, /*crop*/true, /*doLinks*/(int)1);
+ }
+ i->info = io;
+
+ return pdf_doc;