From e898a9bb99b4e9783977e11e02a19742a2d57fec Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Sat, 11 Oct 2025 16:04:17 +0300 Subject: [PATCH] Fix bug 77224 --- PdfFile/PdfEditor.cpp | 12 ++++++++---- PdfFile/PdfWriter.cpp | 15 +++++++++------ PdfFile/SrcWriter/Document.cpp | 15 +++++++++------ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/PdfFile/PdfEditor.cpp b/PdfFile/PdfEditor.cpp index 58a14fb3d3..545bf15812 100644 --- a/PdfFile/PdfEditor.cpp +++ b/PdfFile/PdfEditor.cpp @@ -1464,6 +1464,7 @@ void CPdfEditor::Close() return; } + // m_nMode == Mode::WriteAppend PDFDoc* pPDFDocument = m_pReader->GetPDFDocument(0); PdfWriter::CDocument* pDoc = m_pWriter->GetDocument(); XRef* xref = pPDFDocument->getXRef(); @@ -2766,13 +2767,13 @@ bool CPdfEditor::DeletePage(int nPageIndex) PdfWriter::CDocument* pDoc = m_pWriter->GetDocument(); PdfWriter::CPage* pPage = pDoc->GetPage(nPageIndex); int nObjID = m_mObjManager.FindObj(pPage); - if (nObjID > 0) + bool bRes = pDoc->DeletePage(nPageIndex); + if (bRes && nObjID > 0) { m_mObjManager.RemoveObj(nObjID); pDoc->RemoveObj(pPage); } - - return pDoc->DeletePage(nPageIndex); + return bRes; } bool CPdfEditor::AddPage(int nPageIndex) { @@ -2837,6 +2838,9 @@ bool CPdfEditor::EditAnnot(int _nPageIndex, int nID) if (pDoc->GetAnnot(nID)) return true; + if (m_nMode == Mode::Split || m_nMode == Mode::WriteNew) + return false; + XRef* xref = pPDFDocument->getXRef(); Ref* pPageRef = pPDFDocument->getCatalog()->getPageRef(nPageIndex); if (!xref || !pPageRef || pPageRef->num == 0) @@ -3122,7 +3126,7 @@ bool CPdfEditor::DeleteAnnot(int nID, Object* oAnnots) pDoc->RemoveObj(pObj); return true; } - if (m_nMode == Mode::Split) + if (m_nMode == Mode::Split || m_nMode == Mode::WriteNew) return true; PDFDoc* pPDFDocument = NULL; diff --git a/PdfFile/PdfWriter.cpp b/PdfFile/PdfWriter.cpp index b504dfa2c1..3b655cbe7e 100644 --- a/PdfFile/PdfWriter.cpp +++ b/PdfFile/PdfWriter.cpp @@ -3075,14 +3075,17 @@ HRESULT CPdfWriter::EditWidgetParents(NSFonts::IApplicationFonts* pAppFonts, CWi bool bReplase = false; int nID = pP->GetObjId(); - for (int i = 0; i < pKids->GetCount(); ++i) + if (nID > 0) { - PdfWriter::CObjectBase* pKid = pKids->Get(i); - if (pKid->GetObjId() == nID) + for (int i = 0; i < pKids->GetCount(); ++i) { - pKids->Insert(pKid, pP, true); - bReplase = true; - break; + PdfWriter::CObjectBase* pKid = pKids->Get(i); + if (pKid->GetObjId() == nID) + { + pKids->Insert(pKid, pP, true); + bReplase = true; + break; + } } } if (!bReplase) diff --git a/PdfFile/SrcWriter/Document.cpp b/PdfFile/SrcWriter/Document.cpp index 8bec261142..380120fcc8 100644 --- a/PdfFile/SrcWriter/Document.cpp +++ b/PdfFile/SrcWriter/Document.cpp @@ -1646,14 +1646,17 @@ namespace PdfWriter } bool bReplase = false; int nID = pWidget->GetObjId(); - for (int i = 0; i < pKids->GetCount(); ++i) + if (nID > 0) { - CObjectBase* pKid = pKids->Get(i); - if (pKid->GetObjId() == nID) + for (int i = 0; i < pKids->GetCount(); ++i) { - pKids->Insert(pKid, pWidget, true); - bReplase = true; - break; + CObjectBase* pKid = pKids->Get(i); + if (pKid->GetObjId() == nID) + { + pKids->Insert(pKid, pWidget, true); + bReplase = true; + break; + } } } if (!bReplase)