static jlong nativeCreate(JNIEnv* env, jclass thiz, jint fd, jlong size) { initializeLibraryIfNeeded(); FPDF_FILEACCESS loader; loader.m_FileLen = size; loader.m_Param = reinterpret_cast<void*>(intptr_t(fd)); loader.m_GetBlock = &getBlock; FPDF_DOCUMENT document = FPDF_LoadCustomDocument(&loader, NULL); if (!document) { const long error = FPDF_GetLastError(); switch (error) { case FPDF_ERR_PASSWORD: case FPDF_ERR_SECURITY: { jniThrowExceptionFmt(env, "java/lang/SecurityException", "cannot create document. Error: %ld", error); } break; default: { jniThrowExceptionFmt(env, "java/io/IOException", "cannot create document. Error: %ld", error); } break; } destroyLibraryIfNeeded(); return -1; } return reinterpret_cast<jlong>(document); }
static jlong nativeOpen(JNIEnv* env, jclass thiz, jint fd, jlong size) { initializeLibraryIfNeeded(); FPDF_FILEACCESS loader; loader.m_FileLen = size; loader.m_Param = reinterpret_cast<void*>(intptr_t(fd)); loader.m_GetBlock = &getBlock; FPDF_DOCUMENT document = FPDF_LoadCustomDocument(&loader, NULL); if (!document) { const long error = FPDF_GetLastError(); jniThrowExceptionFmt(env, "java/io/IOException", "cannot create document. Error: %ld", error); destroyLibraryIfNeeded(); return -1; } return reinterpret_cast<jlong>(document); }