csPDFiumWordsPages csPDFiumDocument::wordsPages(const int firstIndex, const int count) const { if( isEmpty() ) { return csPDFiumWordsPages(); } CSPDFIUM_DOCIMPL(); const int pageCount = FPDF_GetPageCount(impl->document); if( firstIndex < 0 || firstIndex >= pageCount ) { csPDFiumWordsPages(); } const int lastIndex = count <= 0 ? pageCount-1 : qBound(0, firstIndex+count-1, pageCount-1); csPDFiumWordsPages result; for(int index = firstIndex; index <= lastIndex; index++) { const FPDF_PAGE page = FPDF_LoadPage(impl->document, index); if( page == NULL ) { continue; } const csPDFiumWordsPage wordsPage(index, util::extractWords(page)); if( !wordsPage.second.isEmpty() ) { result.push_back(wordsPage); } FPDF_ClosePage(page); } return result; }
csPDFiumTextPages csPDFiumDocument::textPages(const int first, const int count) const { if( isEmpty() ) { return csPDFiumTextPages(); } CSPDFIUM_DOCIMPL(); const int pageCount = FPDF_GetPageCount(impl->document); if( first < 0 || first >= pageCount ) { return csPDFiumTextPages(); } const int last = count <= 0 ? pageCount-1 : qBound(0, first+count-1, pageCount-1); csPDFiumTextPages results; for(int pageNo = first; pageNo <= last; pageNo++) { const FPDF_PAGE page = FPDF_LoadPage(impl->document, pageNo); if( page == NULL ) { continue; } const QMatrix ctm = util::getPageCTM(page); results.push_back(csPDFiumTextPage(pageNo, util::extractTexts(page, ctm))); FPDF_ClosePage(page); } return results; }
pdfshow::pdfshow(QWidget *parent) : QWidget(parent) { //get instance of current program (self) HINSTANCE hInst= GetModuleHandle (0); FPDF_InitLibrary(hInst); setAttribute(Qt::WA_PaintOnScreen,true); // 首先,加载文档(没有指定的密码) pdf_doc = FPDF_LoadDocument("./manual/usermanual.pdf", NULL); if (pdf_doc == NULL)// error handling { printf("加载pdf文档错误\n"); } // 现在加载首页(页面索引为0) pdf_page = FPDF_LoadPage(pdf_doc, 0); iPageNum = FPDF_GetPageCount(pdf_doc); if (pdf_page == NULL) { printf("加载pdf页面错误\n"); } page_width = FPDF_GetPageWidth(pdf_page); page_height = FPDF_GetPageHeight(pdf_page); FPDF_ClosePage(pdf_page); }
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; }
// See bug 465. TEST_F(FPDFViewEmbeddertest, EmptyDocument) { EXPECT_TRUE(CreateEmptyDocument()); { int version = 42; EXPECT_FALSE(FPDF_GetFileVersion(document(), &version)); EXPECT_EQ(0, version); } { #ifndef PDF_ENABLE_XFA const unsigned long kExpected = 0; #else const unsigned long kExpected = static_cast<uint32_t>(-1); #endif EXPECT_EQ(kExpected, FPDF_GetDocPermissions(document())); } EXPECT_EQ(-1, FPDF_GetSecurityHandlerRevision(document())); EXPECT_EQ(0, FPDF_GetPageCount(document())); EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document())); EXPECT_EQ(1, FPDF_VIEWERREF_GetNumCopies(document())); EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document())); char buf[100]; EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", nullptr, 0)); EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", buf, sizeof(buf))); EXPECT_EQ(0u, FPDF_CountNamedDests(document())); }
csPDFiumTextPage csPDFiumDocument::textPage(const int no) const { if( isEmpty() ) { return csPDFiumTextPage(); } CSPDFIUM_DOCIMPL(); if( no < 0 || no >= FPDF_GetPageCount(impl->document) ) { return csPDFiumTextPage(); } const FPDF_PAGE page = FPDF_LoadPage(impl->document, no); if( page == NULL ) { return csPDFiumTextPage(); } const QMatrix ctm = util::getPageCTM(page); const csPDFiumTextPage result(no, util::extractTexts(page, ctm)); FPDF_ClosePage(page); return result; }
csPDFiumPage csPDFiumDocument::page(const int no) const { if( isEmpty() ) { return csPDFiumPage(); } CSPDFIUM_DOCIMPL(); if( no < 0 || no >= FPDF_GetPageCount(impl->document) ) { return csPDFiumPage(); } csPDFiumPageImpl *pimpl = new csPDFiumPageImpl(); if( pimpl == 0 ) { return csPDFiumPage(); } pimpl->page = FPDF_LoadPage(impl->document, no); if( pimpl->page == NULL ) { delete pimpl; return csPDFiumPage(); } pimpl->ctm = util::getPageCTM(pimpl->page); pimpl->doc = impl; pimpl->no = no; csPDFiumPage page; page.impl = QSharedPointer<csPDFiumPageImpl>(pimpl); return page; }
Int32 PdfEditor::NativeRemovePage( /* [in] */ Int64 documentPtr, /* [in] */ Int32 pageIndex) { FPDF_DOCUMENT document = reinterpret_cast<FPDF_DOCUMENT>(documentPtr); FPDFPage_Delete(document, pageIndex); return FPDF_GetPageCount(document); }
int csPDFiumDocument::pageCount() const { if( isEmpty() ) { return -1; } CSPDFIUM_DOCIMPL(); return FPDF_GetPageCount(impl->document); }
void wxPDFViewPages::SetDocument(FPDF_DOCUMENT doc) { m_doc = doc; clear(); if (!doc) return; int pageCount = FPDF_GetPageCount(m_doc); reserve(pageCount); for (int i = 0; i < pageCount; ++i) push_back(wxPDFViewPage(this, i)); }
DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, int page_index) { if (document == NULL) return NULL; if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) return NULL; CPDF_Document* pDoc = (CPDF_Document*)document; if (pDoc == NULL) return NULL; CPDF_Dictionary* pDict = pDoc->GetPage(page_index); if (pDict == NULL) return NULL; CPDF_Page* pPage = new CPDF_Page; pPage->Load(pDoc, pDict); pPage->ParseContent(); return pPage; }
TEST_F(FPDFDocEmbedderTest, GetPageLabels) { EXPECT_TRUE(OpenDocument("page_labels.pdf")); EXPECT_EQ(7, FPDF_GetPageCount(document())); // We do not request labels, when use FPDFAvail_IsXXXAvail. // Flush all data, to allow read labels. SetWholeFileAvailable(); unsigned short buf[128]; EXPECT_EQ(0u, FPDF_GetPageLabel(document(), -2, buf, sizeof(buf))); EXPECT_EQ(0u, FPDF_GetPageLabel(document(), -1, buf, sizeof(buf))); const wchar_t kExpectedPageLabel0[] = L"i"; ASSERT_EQ(4u, FPDF_GetPageLabel(document(), 0, buf, sizeof(buf))); EXPECT_EQ(WideString(kExpectedPageLabel0), WideString::FromUTF16LE(buf, FXSYS_len(kExpectedPageLabel0))); const wchar_t kExpectedPageLabel1[] = L"ii"; ASSERT_EQ(6u, FPDF_GetPageLabel(document(), 1, buf, sizeof(buf))); EXPECT_EQ(WideString(kExpectedPageLabel1), WideString::FromUTF16LE(buf, FXSYS_len(kExpectedPageLabel1))); const wchar_t kExpectedPageLabel2[] = L"1"; ASSERT_EQ(4u, FPDF_GetPageLabel(document(), 2, buf, sizeof(buf))); EXPECT_EQ(WideString(kExpectedPageLabel2), WideString::FromUTF16LE(buf, FXSYS_len(kExpectedPageLabel2))); const wchar_t kExpectedPageLabel3[] = L"2"; ASSERT_EQ(4u, FPDF_GetPageLabel(document(), 3, buf, sizeof(buf))); EXPECT_EQ(WideString(kExpectedPageLabel3), WideString::FromUTF16LE(buf, FXSYS_len(kExpectedPageLabel3))); const wchar_t kExpectedPageLabel4[] = L"zzA"; ASSERT_EQ(8u, FPDF_GetPageLabel(document(), 4, buf, sizeof(buf))); EXPECT_EQ(WideString(kExpectedPageLabel4), WideString::FromUTF16LE(buf, FXSYS_len(kExpectedPageLabel4))); const wchar_t kExpectedPageLabel5[] = L"zzB"; ASSERT_EQ(8u, FPDF_GetPageLabel(document(), 5, buf, sizeof(buf))); EXPECT_EQ(WideString(kExpectedPageLabel5), WideString::FromUTF16LE(buf, FXSYS_len(kExpectedPageLabel5))); const wchar_t kExpectedPageLabel6[] = L""; ASSERT_EQ(2u, FPDF_GetPageLabel(document(), 6, buf, sizeof(buf))); EXPECT_EQ(WideString(kExpectedPageLabel6), WideString::FromUTF16LE(buf, FXSYS_len(kExpectedPageLabel6))); ASSERT_EQ(0u, FPDF_GetPageLabel(document(), 7, buf, sizeof(buf))); ASSERT_EQ(0u, FPDF_GetPageLabel(document(), 8, buf, sizeof(buf))); }
DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, int page_index) { if (document == NULL) return NULL; if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) return NULL; // CPDF_Parser* pParser = (CPDF_Parser*)document; CPDF_Document* pDoc = (CPDF_Document*)document; if (pDoc == NULL) return NULL; CPDF_Dictionary* pDict = pDoc->GetPage(page_index); if (pDict == NULL) return NULL; CPDF_Page* pPage = FX_NEW CPDF_Page; pPage->Load(pDoc, pDict); try { pPage->ParseContent(); } catch (...) { delete pPage; return NULL; } // CheckUnSupportError(pDoc, 0); return pPage; }
TEST_F(FPDFDocEmbedderTest, NoPageLabels) { EXPECT_TRUE(OpenDocument("about_blank.pdf")); EXPECT_EQ(1, FPDF_GetPageCount(document())); ASSERT_EQ(0u, FPDF_GetPageLabel(document(), 0, nullptr, 0)); }
TEST_F(FPDFDocEmbedderTest, DeletePage) { EXPECT_TRUE(OpenDocument("hello_world.pdf")); EXPECT_EQ(1, FPDF_GetPageCount(document())); FPDFPage_Delete(document(), 0); EXPECT_EQ(0, FPDF_GetPageCount(document())); }
int _tmain(int argc, _TCHAR* argv[]) { // Before we can do anything, we need to unlock the DLL // NOTE: If you are evaluating FOXIT READER SDK, you don’t need unlock the DLL, // then evaluation marks will be shown with all rendered pages. FPDF_UnlockDLL("license_id", "unlock_code"); // first, load the document (no password specified) pdf_doc = FPDF_LoadDocument("testdoc.pdf", NULL); // error handling if (pdf_doc == NULL) { fprintf(stderr, "ERROR - doc\n"); exit(1); } // Open the out file fopen_s(&out, "test.spl", "wb"); // Send the StartDoc header wchar_t* dname = L"desktop.ini - Editor"; wchar_t* prn = L"c:\\output.prn"; { if (wcsnlen(dname, 255) == 255) ErrorExit(L"dname too long"); if (wcsnlen(prn, 255) == 255) ErrorExit(L"prn too long"); SPL_HEADER spl; spl.SIGNATURE=SPLMETA_SIGNATURE; spl.nSize=(DWORD)sizeof(spl)+wcslen(dname)*2+wcslen(prn)*2+4; // +4, because \0\0 is after dname and prn spl.offDocumentName=(DWORD)sizeof(spl); spl.offPort=(DWORD)sizeof(spl)+wcslen(dname)*2+2; // +2 because \0\0 is after dname fwrite(&spl, sizeof(spl), 1, out); fwrite(dname, wcslen(dname)*2, 1, out); fwrite("\0\0", 2, 1, out); fwrite(prn, wcslen(prn)*2, 1, out); fwrite("\0\0", 2, 1, out); } // Load the first page and calculate the bbox // based on the printer margins pdf_page = FPDF_LoadPage(pdf_doc, 0); if (pdf_page == NULL) ErrorExit(L"FPDF_LoadPage"); double page_width, page_height; page_width = FPDF_GetPageWidth(pdf_page); page_height = FPDF_GetPageHeight(pdf_page); #ifdef EXT_PRINT #ifdef EXT_PRNDLG PRINTDLG pd; HWND hwnd = NULL; // Initialize PRINTDLG ZeroMemory(&pd, sizeof(pd)); pd.lStructSize = sizeof(pd); pd.hwndOwner = hwnd; pd.hDevMode = NULL; // Don't forget to free or store hDevMode pd.hDevNames = NULL; // Don't forget to free or store hDevNames pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC; pd.nCopies = 1; pd.nFromPage = 0xFFFF; pd.nToPage = 0xFFFF; pd.nMinPage = 1; pd.nMaxPage = 0xFFFF; if (PrintDlg(&pd) != TRUE) ErrorExit(L"PrintDialog\n"); hDC = pd.hDC; #else wchar_t* printer=L"FF"; if (!OpenPrinter(printer, &hPrinter, NULL)) ErrorExit(L"OpenPrinter\n"); DWORD dwNeeded = DocumentProperties(NULL, hPrinter, printer, NULL, NULL, 0); lpDevMode = (LPDEVMODE)malloc(dwNeeded); DocumentProperties(NULL, hPrinter, printer, lpDevMode, NULL, DM_OUT_BUFFER); /* Try to set a higher print quality */ lpDevMode->dmPrintQuality=1200; lpDevMode->dmFields|=DM_PRINTQUALITY; DocumentProperties(NULL, hPrinter, printer, lpDevMode, lpDevMode, DM_IN_BUFFER | DM_OUT_BUFFER); #ifdef EXT_PRNOPTS DocumentProperties(NULL, hPrinter, printer, lpDevMode, lpDevMode, DM_IN_BUFFER | DM_PROMPT | DM_OUT_BUFFER); #endif hDC = CreateDC(L"WINEPS.DRV", printer, NULL, lpDevMode); ClosePrinter(&hPrinter); #endif #else hDC = CreateDC(L"WINEPS.DRV", L"FF", NULL, lpDevMode); #endif #ifdef PRINT DOCINFO doc_info; doc_info.cbSize=sizeof(DOCINFO)+12; doc_info.lpszDocName=dname; doc_info.lpszOutput=prn; doc_info.lpszDatatype=NULL; doc_info.fwType=0; // Start a printer job StartDoc(hDC, &doc_info); #endif // get number of pixels per inch (horizontally and vertically) logpixelsx = GetDeviceCaps(hDC, LOGPIXELSX); logpixelsy = GetDeviceCaps(hDC, LOGPIXELSY); // convert points into pixels size_x = (int)page_width / 72 * logpixelsx; size_y = (int)page_height / 72 * logpixelsy; DWORD p_width =GetDeviceCaps(hDC, HORZSIZE)*100; DWORD p_height=GetDeviceCaps(hDC, VERTSIZE)*100; SetRect( &rect, 0, 0, p_width, p_height ); #ifdef DEBUG //fprintf(stderr, "x=%u, y=%u, pw=%u, ph=%u,sx=%u,sy=%u,lpx=%u,lpy=%u,size_x=%u,size_y=%u\n",x,y,page_width,page_height,sx,sy,logpixelsx,logpixelsy,size_x,size_y); #endif // now load the pages one after another for (i=0; i < FPDF_GetPageCount(pdf_doc); i++) { #ifdef DEBUG fprintf(stderr, "Load page %d/%d\n", i, FPDF_GetPageCount(pdf_doc)); #endif // Load the next page pdf_page = FPDF_LoadPage(pdf_doc, i); if (pdf_page == NULL) ErrorExit(L"FPDF_LoadPage"); fbuf=NULL; #ifdef DEBUG sprintf_s(buf, 255, "test-%d.emf", i); //fbuf=buf; #endif // Create a metafile to render to hMeta = CreateEnhMetaFileA(hDC, fbuf, &rect, "SPLFilter.exe\0Created by Fabian\0\0"); if (hMeta == NULL) ErrorExit(L"CreateEnhMetaFileA"); // Call FPDF_RenderPage function to render the whole page FPDF_RenderPage(hMeta, pdf_page, 0, 0, size_x, size_y, 0, 0); #ifdef PRINT // Start a new printing page StartPage(hDC); FPDF_RenderPage(hDC, pdf_page, 0, 0, size_x, size_y, 0, 0); EndPage(hDC); #endif // Close PDF page FPDF_ClosePage(pdf_page); efile=CloseEnhMetaFile(hMeta); if (efile == NULL) ErrorExit(L"CloseEnhMetaFile"); // Write EMF data - via enumeration, because we want to embed fonts later EnumEnhMetaFile(hDC, efile, enum_it, NULL, &rect); // Write EndPage() record { SMR_EOPAGE smr_eopage; smr_eopage.smrext.smr.iType=SRT_EXT_EOPAGE_VECTOR; smr_eopage.smrext.smr.nSize=sizeof(smr_eopage)-sizeof(smr_eopage.smrext.smr); /* FIXME: Need to calcualte low and high correctly */ smr_eopage.smrext.DistanceLow=bufSize+smr_eopage.smrext.smr.nSize; smr_eopage.smrext.DistanceHigh=0; fwrite(&smr_eopage, sizeof(smr_eopage), 1, out); } DeleteEnhMetaFile(efile); } #ifdef PRINT EndDoc(hDC); #endif fclose(out); out=NULL; DeleteDC(hDC); FPDF_CloseDocument(pdf_doc); #ifdef DEBUG fprintf(stderr, "SPLFilter: Conversion successful!\n"); #endif exit(0); }
static jint nativeRemovePage(JNIEnv* env, jclass thiz, jlong documentPtr, jint pageIndex) { FPDF_DOCUMENT document = reinterpret_cast<FPDF_DOCUMENT>(documentPtr); FPDFPage_Delete(document, pageIndex); return FPDF_GetPageCount(document); }
Int32 PdfEditor::NativeGetPageCount( /* [in] */ Int64 documentPtr) { FPDF_DOCUMENT document = reinterpret_cast<FPDF_DOCUMENT>(documentPtr); return FPDF_GetPageCount(document); }
static jint nativeGetPageCount(JNIEnv* env, jclass thiz, jlong documentPtr) { FPDF_DOCUMENT document = reinterpret_cast<FPDF_DOCUMENT>(documentPtr); return FPDF_GetPageCount(document); }
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; }