int EmbedderTest::GetPageCount() { int page_count = FPDF_GetPageCount(document_); for (int i = 0; i < page_count; ++i) { (void)FPDFAvail_IsPageAvail(avail_, i, &hints_); } return page_count; }
int EmbedderTest::GetFirstPageNum() { int first_page = FPDFAvail_GetFirstPageNum(document_); (void)FPDFAvail_IsPageAvail(avail_, first_page, &hints_); return first_page; }
bool EmbedderTest::OpenDocument(const std::string& filename, const char* password, bool must_linearize) { std::string file_path; if (!PathService::GetTestFilePath(filename, &file_path)) return false; file_contents_ = GetFileContents(file_path.c_str(), &file_length_); if (!file_contents_) return false; EXPECT_TRUE(!loader_); loader_ = new TestLoader(file_contents_.get(), file_length_); file_access_.m_FileLen = static_cast<unsigned long>(file_length_); file_access_.m_GetBlock = TestLoader::GetBlock; file_access_.m_Param = loader_; file_avail_.version = 1; file_avail_.IsDataAvail = Is_Data_Avail; hints_.version = 1; hints_.AddSegment = Add_Segment; avail_ = FPDFAvail_Create(&file_avail_, &file_access_); if (FPDFAvail_IsLinearized(avail_) == PDF_LINEARIZED) { document_ = FPDFAvail_GetDocument(avail_, password); if (!document_) { return false; } int32_t nRet = PDF_DATA_NOTAVAIL; while (nRet == PDF_DATA_NOTAVAIL) { nRet = FPDFAvail_IsDocAvail(avail_, &hints_); } if (nRet == PDF_DATA_ERROR) { return false; } nRet = FPDFAvail_IsFormAvail(avail_, &hints_); if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) { return false; } int page_count = FPDF_GetPageCount(document_); for (int i = 0; i < page_count; ++i) { nRet = PDF_DATA_NOTAVAIL; while (nRet == PDF_DATA_NOTAVAIL) { nRet = FPDFAvail_IsPageAvail(avail_, i, &hints_); } if (nRet == PDF_DATA_ERROR) { return false; } } } else { if (must_linearize) { return false; } document_ = FPDF_LoadCustomDocument(&file_access_, nullptr); if (!document_) { return false; } } #ifdef PDF_ENABLE_XFA int docType = DOCTYPE_PDF; if (FPDF_HasXFAField(document_, &docType)) { if (docType != DOCTYPE_PDF) (void)FPDF_LoadXFA(document_); } #endif // PDF_ENABLE_XFA (void)FPDF_GetDocPermissions(document_); SetupFormFillEnvironment(); return true; }