mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
For bug 77407
This commit is contained in:
@ -2480,6 +2480,42 @@ bool CPdfEditor::SplitPages(const int* arrPageIndex, unsigned int unLength, PDFD
|
||||
}
|
||||
oAcroForm.free(); oCatalog.free();
|
||||
|
||||
// Переименование полей
|
||||
std::string sPrefix = m_pReader->GetPrefixForm(pPDFDocument);
|
||||
if (!sPrefix.empty())
|
||||
{
|
||||
sPrefix = "_" + sPrefix;
|
||||
std::vector<int> arrRename; // Вектор переименованных полей
|
||||
std::map<int, PdfWriter::CAnnotation*> mAnnots = m_pWriter->GetDocument()->GetAnnots();
|
||||
for (auto it = mAnnots.begin(); it != mAnnots.end(); it++)
|
||||
{
|
||||
PdfWriter::CAnnotation* pAnnot = it->second;
|
||||
if (pAnnot->GetAnnotationType() != PdfWriter::AnnotWidget || it->first < nStartRefID)
|
||||
continue;
|
||||
|
||||
std::vector<int>::iterator it2 = std::find(arrRename.begin(), arrRename.end(), it->first);
|
||||
if (it2 != arrRename.end())
|
||||
continue;
|
||||
|
||||
PdfWriter::CObjectBase* pObjBase = pAnnot->Get("Parent");
|
||||
if (!pObjBase || !ChangeFullNameParent(pObjBase->GetObjId(), sPrefix, arrRename))
|
||||
{
|
||||
pObjBase = pAnnot->Get("T");
|
||||
if (pObjBase && pObjBase->GetType() == PdfWriter::object_type_STRING)
|
||||
{
|
||||
PdfWriter::CStringObject* pStr = (PdfWriter::CStringObject*)pObjBase;
|
||||
pStr->Add(sPrefix.c_str());
|
||||
}
|
||||
else if (pObjBase && pObjBase->GetType() == PdfWriter::object_type_BINARY)
|
||||
{
|
||||
PdfWriter::CBinaryObject* pBin = (PdfWriter::CBinaryObject*)pObjBase;
|
||||
pBin->Add((BYTE*)sPrefix.c_str(), sPrefix.length());
|
||||
}
|
||||
}
|
||||
arrRename.push_back(it->first);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool CPdfEditor::SplitPages(const int* arrPageIndex, unsigned int unLength)
|
||||
@ -2668,7 +2704,7 @@ bool CPdfEditor::ChangeFullNameParent(int nParent, const std::string& sPrefix, s
|
||||
|
||||
return true;
|
||||
}
|
||||
bool CPdfEditor::MergePages(const std::wstring& wsPath, int nMaxID, const std::wstring& wsPrefixForm)
|
||||
bool CPdfEditor::MergePages(const std::wstring& wsPath)
|
||||
{
|
||||
if (m_nMode == Mode::Unknown && !IncrementalUpdates())
|
||||
return false;
|
||||
@ -2680,38 +2716,6 @@ bool CPdfEditor::MergePages(const std::wstring& wsPath, int nMaxID, const std::w
|
||||
if (!bRes)
|
||||
return false;
|
||||
|
||||
// Переименование полей
|
||||
std::string sPrefix = "_" + U_TO_UTF8(wsPrefixForm);
|
||||
std::vector<int> arrRename; // Вектор переименованных полей
|
||||
std::map<int, PdfWriter::CAnnotation*> mAnnots = m_pWriter->GetDocument()->GetAnnots();
|
||||
for (auto it = mAnnots.begin(); it != mAnnots.end(); it++)
|
||||
{
|
||||
PdfWriter::CAnnotation* pAnnot = it->second;
|
||||
if (pAnnot->GetAnnotationType() != PdfWriter::AnnotWidget || it->first < nMaxID)
|
||||
continue;
|
||||
|
||||
std::vector<int>::iterator it2 = std::find(arrRename.begin(), arrRename.end(), it->first);
|
||||
if (it2 != arrRename.end())
|
||||
continue;
|
||||
|
||||
PdfWriter::CObjectBase* pObjBase = pAnnot->Get("Parent");
|
||||
if (!pObjBase || !ChangeFullNameParent(pObjBase->GetObjId(), sPrefix, arrRename))
|
||||
{
|
||||
pObjBase = pAnnot->Get("T");
|
||||
if (pObjBase && pObjBase->GetType() == PdfWriter::object_type_STRING)
|
||||
{
|
||||
PdfWriter::CStringObject* pStr = (PdfWriter::CStringObject*)pObjBase;
|
||||
pStr->Add(sPrefix.c_str());
|
||||
}
|
||||
else if (pObjBase && pObjBase->GetType() == PdfWriter::object_type_BINARY)
|
||||
{
|
||||
PdfWriter::CBinaryObject* pBin = (PdfWriter::CBinaryObject*)pObjBase;
|
||||
pBin->Add((BYTE*)sPrefix.c_str(), sPrefix.length());
|
||||
}
|
||||
}
|
||||
arrRename.push_back(it->first);
|
||||
}
|
||||
|
||||
Outline* pOutlineAdd = pDocument->getOutline();
|
||||
GList* pListAdd = NULL;
|
||||
if (pOutlineAdd)
|
||||
|
||||
@ -105,7 +105,7 @@ public:
|
||||
|
||||
bool SplitPages(const int* arrPageIndex, unsigned int unLength);
|
||||
void AfterSplitPages();
|
||||
bool MergePages(const std::wstring& wsPath, int nMaxID, const std::wstring& wsPrefixForm);
|
||||
bool MergePages(const std::wstring& wsPath);
|
||||
|
||||
private:
|
||||
void GetPageTree(XRef* xref, Object* pPagesRefObj, PdfWriter::CPageTree* pPageParent = NULL);
|
||||
|
||||
@ -147,8 +147,8 @@ bool CPdfFile::MergePages(const std::wstring& wsPath, int nMaxID, const std::wst
|
||||
{
|
||||
if (!m_pInternal->pEditor)
|
||||
return false;
|
||||
if (m_pInternal->pReader->MergePages(wsPath, L"", nMaxID))
|
||||
return m_pInternal->pEditor->MergePages(wsPath, nMaxID, wsPrefixForm);
|
||||
if (m_pInternal->pReader->MergePages(wsPath, L"", nMaxID, U_TO_UTF8(wsPrefixForm)))
|
||||
return m_pInternal->pEditor->MergePages(wsPath);
|
||||
return false;
|
||||
}
|
||||
bool CPdfFile::MovePage(int nPageIndex, int nPos)
|
||||
|
||||
@ -468,6 +468,18 @@ int CPdfReader::GetNumPagesBefore(PDFDoc* _pDoc)
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
std::string CPdfReader::GetPrefixForm(PDFDoc* _pDoc)
|
||||
{
|
||||
for (CPdfReaderContext* pPDFContext : m_vPDFContext)
|
||||
{
|
||||
if (!pPDFContext || !pPDFContext->m_pDocument)
|
||||
continue;
|
||||
PDFDoc* pDoc = pPDFContext->m_pDocument;
|
||||
if (_pDoc == pDoc)
|
||||
return pPDFContext->m_sPrefixForm;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
int CPdfReader::FindRefNum(int nObjID, PDFDoc** _pDoc, int* _nStartRefID)
|
||||
{
|
||||
for (CPdfReaderContext* pPDFContext : m_vPDFContext)
|
||||
|
||||
@ -107,6 +107,7 @@ public:
|
||||
PDFDoc* GetPDFDocument(int PDFIndex);
|
||||
int GetStartRefID(PDFDoc* pDoc);
|
||||
int GetNumPagesBefore(PDFDoc* pDoc);
|
||||
std::string GetPrefixForm(PDFDoc* pDoc);
|
||||
int FindRefNum(int nObjID, PDFDoc** pDoc = NULL, int* nStartRefID = NULL);
|
||||
int GetPageIndex(int nPageIndex, PDFDoc** pDoc = NULL, PdfReader::CPdfFontList** pFontList = NULL, int* nStartRefID = NULL);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user