fz_stream * fz_open_file(fz_context *ctx, const char *name) { #ifdef _WIN32 char *s = (char*)name; wchar_t *wname, *d; int c, fd; /* SumatraPDF: prefer ANSI to UTF-8 for consistency with remaining API */ fd = open(name, O_BINARY | O_RDONLY, 0); if (fd == -1) { d = wname = fz_malloc(ctx, (strlen(name)+1) * sizeof(wchar_t)); while (*s) { s += fz_chartorune(&c, s); *d++ = c; } *d = 0; fd = _wopen(wname, O_BINARY | O_RDONLY, 0); fz_free(ctx, wname); } #else int fd = open(name, O_BINARY | O_RDONLY, 0); #endif if (fd == -1) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open %s", name); return fz_open_fd(ctx, fd); }
fz_stream * fz_open_file_w(fz_context *ctx, const wchar_t *name) { int fd = _wopen(name, O_BINARY | O_RDONLY, 0); if (fd == -1) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file %ls", name); return fz_open_fd(ctx, fd); }
fz_stream * fz_open_file_w(fz_context *ctx, const wchar_t *name) { int fd = _wopen(name, O_BINARY | O_RDONLY, 0); if (fd == -1) return NULL; return fz_open_fd(ctx, fd); }
fz_stream * fz_open_file(fz_context *ctx, const char *name) { int fd = open(name, O_BINARY | O_RDONLY, 0); if (fd == -1) fz_throw(ctx, "cannot open %s", name); return fz_open_fd(ctx, fd); }
static void pdfapp_open_xps(pdfapp_t *app, char *filename, int fd) { fz_error error; fz_stream *file; file = fz_open_fd(fd); error = xps_open_stream(&app->xps, file); if (error) pdfapp_error(app, fz_rethrow(error, "cannot open document '%s'", filename)); fz_close(file); app->doctitle = filename; app->pagecount = xps_count_pages(app->xps); }
fz_stream * fz_open_file(fz_context *ctx, const char *name) { #ifdef _WIN32 char *s = (char*)name; wchar_t *wname, *d; int c, fd; d = wname = fz_malloc(ctx, (strlen(name)+1) * sizeof(wchar_t)); while (*s) { s += fz_chartorune(&c, s); *d++ = c; } *d = 0; fd = _wopen(wname, O_BINARY | O_RDONLY, 0); fz_free(ctx, wname); #else int fd = open(name, O_BINARY | O_RDONLY, 0); #endif if (fd == -1) fz_throw(ctx, "cannot open %s", name); return fz_open_fd(ctx, fd); }
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) { #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; }