summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/fpdfdoc_embeddertest.cpp8
-rw-r--r--fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp16
2 files changed, 20 insertions, 4 deletions
diff --git a/fpdfsdk/fpdfdoc_embeddertest.cpp b/fpdfsdk/fpdfdoc_embeddertest.cpp
index 855235858b..2450b6aea6 100644
--- a/fpdfsdk/fpdfdoc_embeddertest.cpp
+++ b/fpdfsdk/fpdfdoc_embeddertest.cpp
@@ -6,6 +6,7 @@
#include "core/fxcrt/include/fx_string.h"
#include "public/fpdf_doc.h"
+#include "public/fpdf_edit.h"
#include "public/fpdfview.h"
#include "testing/embedder_test.h"
#include "testing/fx_string_testhelpers.h"
@@ -138,3 +139,10 @@ TEST_F(FPDFDocEmbeddertest, FindBookmarks_bug420) {
GetFPDFWideString(L"anything");
EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), title.get()));
}
+
+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()));
+}
diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp
index d55183751e..72f67dd271 100644
--- a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp
+++ b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp
@@ -154,6 +154,7 @@ int CPDFXFA_Document::GetPageCount() {
CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) {
if (page_index < 0)
return nullptr;
+
CPDFXFA_Page* pPage = nullptr;
int nCount = m_XFAPageList.GetSize();
if (nCount > 0 && page_index < nCount) {
@@ -166,6 +167,7 @@ CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) {
}
if (pPage)
return pPage;
+
pPage = new CPDFXFA_Page(this, page_index);
if (!pPage->LoadPage()) {
pPage->Release();
@@ -177,13 +179,13 @@ CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) {
CPDFXFA_Page* CPDFXFA_Document::GetPage(CXFA_FFPageView* pPage) {
if (!pPage)
- return NULL;
+ return nullptr;
if (!m_pXFADoc)
- return NULL;
+ return nullptr;
if (m_iDocType != DOCTYPE_DYNAMIC_XFA)
- return NULL;
+ return nullptr;
int nSize = m_XFAPageList.GetSize();
for (int i = 0; i < nSize; i++) {
@@ -194,10 +196,16 @@ CPDFXFA_Page* CPDFXFA_Document::GetPage(CXFA_FFPageView* pPage) {
return pTempPage;
}
- return NULL;
+ return nullptr;
}
void CPDFXFA_Document::DeletePage(int page_index) {
+ // Delete from the document first because, if GetPage was never called for
+ // this |page_index| then |m_XFAPageList| may have size < |page_index| even
+ // if it's a valid page in the document.
+ if (m_pPDFDoc)
+ m_pPDFDoc->DeletePage(page_index);
+
if (page_index < 0 || page_index >= m_XFAPageList.GetSize())
return;