static void event_cb(fz_context *ctx, pdf_document *doc, pdf_doc_event *event, void *data) { pdfapp_t *app = (pdfapp_t *)data; switch (event->type) { case PDF_DOCUMENT_EVENT_ALERT: { pdf_alert_event *alert = pdf_access_alert_event(ctx, event); winalert(app, alert); } break; case PDF_DOCUMENT_EVENT_PRINT: winprint(app); break; case PDF_DOCUMENT_EVENT_EXEC_MENU_ITEM: { const char *item = pdf_access_exec_menu_item_event(ctx, event); if (!strcmp(item, "Print")) winprint(app); else pdfapp_warn(app, "The document attempted to execute menu item: %s. (Not supported)", item); } break; case PDF_DOCUMENT_EVENT_EXEC_DIALOG: pdfapp_warn(app, "The document attempted to open a dialog box. (Not supported)"); break; case PDF_DOCUMENT_EVENT_LAUNCH_URL: { pdf_launch_url_event *launch_url = pdf_access_launch_url_event(ctx, event); pdfapp_warn(app, "The document attempted to open url: %s. (Not supported by app)", launch_url->url); } break; case PDF_DOCUMENT_EVENT_MAIL_DOC: { pdf_mail_doc_event *mail_doc = pdf_access_mail_doc_event(ctx, event); pdfapp_warn(app, "The document attempted to mail the document%s%s%s%s%s%s%s%s (Not supported)", mail_doc->to[0]?", To: ":"", mail_doc->to, mail_doc->cc[0]?", Cc: ":"", mail_doc->cc, mail_doc->bcc[0]?", Bcc: ":"", mail_doc->bcc, mail_doc->subject[0]?", Subject: ":"", mail_doc->subject); } break; } }
void pdfapp_open_progressive(pdfapp_t *app, char *filename, int reload, int bps) { fz_context *ctx = app->ctx; char *password = ""; fz_try(ctx) { fz_register_document_handlers(ctx); #ifdef HAVE_CURL if (!strncmp(filename, "http://", 7)) { app->stream = fz_stream_from_curl(ctx, filename, pdfapp_more_data, app); while (1) { fz_try(ctx) { fz_seek(ctx, app->stream, 0, SEEK_SET); app->doc = fz_open_document_with_stream(ctx, filename, app->stream); } fz_catch(ctx) { if (fz_caught(ctx) == FZ_ERROR_TRYLATER) { pdfapp_warn(app, "not enough data to open yet"); continue; } fz_rethrow(ctx); } break; } } else #endif if (bps == 0)
static void pdfapp_searchbackward(pdfapp_t *app, enum panning *panto) { int matchlen; int test; int len; int startpage; wincursor(app, WAIT); startpage = app->pageno; do { len = textlen(app->page_text); if (app->hit >= 0) test = app->hit - 1; else test = len; while (test >= 0) { matchlen = match(app->search, app->page_text, test); if (matchlen) { app->hit = test; app->hitlen = matchlen; wincursor(app, HAND); winrepaint(app); return; } test--; } app->pageno--; if (app->pageno < 1) app->pageno = app->pagecount; pdfapp_showpage(app, 1, 0, 0); *panto = PAN_TO_BOTTOM; } while (app->pageno != startpage); if (app->pageno == startpage) { pdfapp_warn(app, "String '%s' not found.", app->search); winrepaintsearch(app); } else winrepaint(app); wincursor(app, HAND); }
static void pdfapp_searchforward(pdfapp_t *app, enum panning *panto) { int matchlen; int test; int len; int startpage; wincursor(app, WAIT); startpage = app->pageno; do { len = textlen(app->page_text); if (app->hit >= 0) test = app->hit + strlen(app->search); else test = 0; while (test < len) { matchlen = match(app->search, app->page_text, test); if (matchlen) { app->hit = test; app->hitlen = matchlen; wincursor(app, HAND); winrepaint(app); return; } test++; } app->pageno++; if (app->pageno > app->pagecount) app->pageno = 1; pdfapp_showpage(app, 1, 0, 0); *panto = PAN_TO_TOP; } while (app->pageno != startpage); if (app->pageno == startpage) { pdfapp_warn(app, "String '%s' not found.", app->search); winrepaintsearch(app); } else winrepaint(app); wincursor(app, HAND); }
static void pdfapp_open_pdf(pdfapp_t *app, char *filename, int fd) { fz_error error; fz_stream *file; char *password = ""; fz_obj *obj; fz_obj *info; /* * Open PDF and load xref table */ file = fz_open_fd(fd); error = pdf_open_xref_with_stream(&app->xref, file, NULL); if (error) pdfapp_error(app, fz_rethrow(error, "cannot open document '%s'", filename)); fz_close(file); /* * Handle encrypted PDF files */ if (pdf_needs_password(app->xref)) { int okay = pdf_authenticate_password(app->xref, password); while (!okay) { password = winpassword(app, filename); if (!password) exit(1); okay = pdf_authenticate_password(app->xref, password); if (!okay) pdfapp_warn(app, "Invalid password."); } } /* * Load meta information */ app->outline = pdf_load_outline(app->xref); app->doctitle = filename; if (strrchr(app->doctitle, '\\')) app->doctitle = strrchr(app->doctitle, '\\') + 1; if (strrchr(app->doctitle, '/')) app->doctitle = strrchr(app->doctitle, '/') + 1; info = fz_dict_gets(app->xref->trailer, "Info"); if (info) { obj = fz_dict_gets(info, "Title"); if (obj) app->doctitle = pdf_to_utf8(obj); } /* * Start at first page */ error = pdf_load_page_tree(app->xref); if (error) pdfapp_error(app, fz_rethrow(error, "cannot load page tree")); app->pagecount = pdf_count_pages(app->xref); }
void pdfapp_open(pdfapp_t *app, char *filename) { fz_error *error; fz_obj *obj; char *password = ""; /* * Open PDF and load xref table */ app->filename = filename; error = pdf_newxref(&app->xref); if (error) pdfapp_error(app, error); error = pdf_loadxref(app->xref, filename); if (error) { if (!strncmp(error->msg, "ioerror", 7)) pdfapp_error(app, error); pdfapp_warn(app, "There was a problem with file \"%s\".\n" "It may be corrupted, or generated by broken software.\n\n" "%s\n\nTrying to continue anyway...", filename, error->msg); error = pdf_repairxref(app->xref, filename); if (error) pdfapp_error(app, error); } /* * Handle encrypted PDF files */ error = pdf_decryptxref(app->xref); if (error) pdfapp_error(app, error); if (app->xref->crypt) { error = pdf_setpassword(app->xref->crypt, password); while (error) { fz_droperror(error); password = winpassword(app, filename); if (!password) exit(1); error = pdf_setpassword(app->xref->crypt, password); if (error) pdfapp_warn(app, "Invalid password."); } } /* * Load page tree */ error = pdf_loadpagetree(&app->pages, app->xref); if (error) pdfapp_error(app, error); /* * Load meta information * TODO: move this into mupdf library */ obj = fz_dictgets(app->xref->trailer, "Root"); if (!obj) pdfapp_error(app, fz_throw("syntaxerror: missing Root object")); error = pdf_loadindirect(&app->xref->root, app->xref, obj); if (error) pdfapp_error(app, error); obj = fz_dictgets(app->xref->trailer, "Info"); if (obj) { error = pdf_loadindirect(&app->xref->info, app->xref, obj); if (error) pdfapp_error(app, error); } error = pdf_loadnametrees(app->xref); if (error) pdfapp_error(app, error); error = pdf_loadoutline(&app->outline, app->xref); if (error) pdfapp_error(app, error); app->doctitle = filename; if (strrchr(app->doctitle, '\\')) app->doctitle = strrchr(app->doctitle, '\\') + 1; if (strrchr(app->doctitle, '/')) app->doctitle = strrchr(app->doctitle, '/') + 1; if (app->xref->info) { obj = fz_dictgets(app->xref->info, "Title"); if (obj) { error = pdf_toutf8(&app->doctitle, obj); if (error) pdfapp_error(app, error); } } /* * Start at first page */ app->shrinkwrap = 1; if (app->pageno < 1) app->pageno = 1; if (app->zoom <= 0.0) app->zoom = 1.0; app->rotate = 0; app->panx = 0; app->pany = 0; pdfapp_showpage(app, 1, 1); }
void pdfapp_open(pdfapp_t *app, char *filename) { #if 0 fz_error error; fz_obj *obj; char *password = ""; #else fz_error error; fz_stream *file; char *password = ""; fz_obj *obj; fz_obj *info; int fd; fd = open(filename, O_BINARY | O_RDONLY, 0666); if (fd < 0) fprintf(stderr, "error, file %s does not exist\n", filename); #endif /* * Open PDF and load xref table */ app->filename = filename; #if 0 app->xref = pdf_newxref(); error = pdf_loadxref(app->xref, filename); if (error) { fz_catch(error, "trying to air"); error = pdf_repairxref(app->xref, filename); if (error) pdfapp_error(app, error); } error = pdf_decryptxref(app->xref); if (error) pdfapp_error(app, error); #else file = fz_open_fd(fd); error = pdf_open_xref_with_stream(&app->xref, file, NULL); if (error) pdfapp_error(app, fz_rethrow(error, "cannot open document '%s'", filename)); fz_close(file); #endif /* * Handle encrypted PDF files */ if (pdf_needs_password(app->xref)) { int okay = pdf_authenticate_password(app->xref, password); while (!okay) { //password = winpassword(app, filename); if (!password) exit(1); okay = pdf_authenticate_password(app->xref, password); if (!okay) pdfapp_warn(app, "Invalid password."); } } /* * Load meta information * TODO: move this into mupdf library */ #if 0 obj = fz_dictgets(app->xref->trailer, "Root"); app->xref->root = fz_resolveindirect(obj); if (!app->xref->root) pdfapp_error(app, fz_throw("syntaxerror: missing Root object")); fz_keepobj(app->xref->root); obj = fz_dictgets(app->xref->trailer, "Info"); app->xref->info = fz_resolveindirect(obj); if (!app->xref->info) pdfapp_warn(app, "Could not load PDF meta information."); if (app->xref->info) fz_keepobj(app->xref->info); /*app->outline = pdf_loadoutline(app->xref);*/ app->doctitle = filename; if (strrchr(app->doctitle, '\\')) app->doctitle = strrchr(app->doctitle, '\\') + 1; if (strrchr(app->doctitle, '/')) app->doctitle = strrchr(app->doctitle, '/') + 1; if (app->xref->info) { obj = fz_dictgets(app->xref->info, "Title"); if (obj) { app->doctitle = pdf_toutf8(obj); } } #else app->outline = pdf_load_outline(app->xref); app->doctitle = filename; if (strrchr(app->doctitle, '\\')) app->doctitle = strrchr(app->doctitle, '\\') + 1; if (strrchr(app->doctitle, '/')) app->doctitle = strrchr(app->doctitle, '/') + 1; info = fz_dict_gets(app->xref->trailer, "Info"); if (info) { obj = fz_dict_gets(info, "Title"); if (obj) app->doctitle = pdf_to_utf8(obj); } #endif /* * Start at first page */ #if 0 app->pagecount = pdf_getpagecount(app->xref); #else error = pdf_load_page_tree(app->xref); if (error) pdfapp_error(app, fz_rethrow(error, "cannot load page tree")); app->pagecount = pdf_count_pages(app->xref); #endif app->rotate = 0; }
void pdfapp_open(pdfapp_t *app, char *filename) { fz_obj *obj; fz_obj *info; char *password = ""; /* * Open PDF and load xref table */ app->filename = filename; app->xref = pdf_openxref(filename); if (!app->xref) pdfapp_error(app, -1); /* * Handle encrypted PDF files */ if (pdf_needspassword(app->xref)) { int okay = pdf_authenticatepassword(app->xref, password); while (!okay) { password = winpassword(app, filename); if (!password) exit(1); okay = pdf_authenticatepassword(app->xref, password); if (!okay) pdfapp_warn(app, "Invalid password."); } } /* * Load meta information */ app->outline = pdf_loadoutline(app->xref); app->doctitle = filename; if (strrchr(app->doctitle, '\\')) app->doctitle = strrchr(app->doctitle, '\\') + 1; if (strrchr(app->doctitle, '/')) app->doctitle = strrchr(app->doctitle, '/') + 1; info = fz_dictgets(app->xref->trailer, "Info"); if (info) { obj = fz_dictgets(info, "Title"); if (obj) app->doctitle = pdf_toutf8(obj); } /* * Start at first page */ app->pagecount = pdf_getpagecount(app->xref); app->shrinkwrap = 1; if (app->pageno < 1) app->pageno = 1; if (app->zoom < 0.1) app->zoom = 0.1; if (app->zoom > 3.0) app->zoom = 3.0; app->rotate = 0; app->panx = 0; app->pany = 0; //code change by kakai //highlight color settings kno_setHighlightColor(app, 0x00ffff00); //code change by kakai pdfapp_showpage(app, 1, 1); }