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); }
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_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); }