Add UndoMergePages

This commit is contained in:
Svetlana Kulikova
2025-04-18 10:20:36 +03:00
parent 8871c785dd
commit 20618403b6
11 changed files with 64 additions and 6 deletions

View File

@ -295,6 +295,12 @@ public:
return ((CPdfFile*)m_pFile)->MergePages(data, size, nMaxID, sPrefixForm);
return false;
}
bool UnmergePages()
{
if (m_nType == 0)
return ((CPdfFile*)m_pFile)->UnmergePages();
return false;
}
BYTE* GetGlyphs(int nPageIndex)
{

View File

@ -53,6 +53,7 @@
"_ScanPage",
"_SplitPages",
"_MergePages",
"_UnmergePages",
"_GetImageBase64",
"_GetImageBase64Len",
"_GetImageBase64Ptr",

View File

@ -176,6 +176,10 @@ CFile.prototype["MergePages"] = function(arrayBuffer, maxID, prefixForm)
{
return this._MergePages(arrayBuffer, maxID, prefixForm);
};
CFile.prototype["UndoMergePages"] = function()
{
return this._UndoMergePages();
};
// INFO DOCUMENT
CFile.prototype.getInfo = function()

View File

@ -162,6 +162,17 @@ CFile.prototype._MergePages = function(buffer, maxID, prefixForm)
return bRes == 1;
};
CFile.prototype._UndoMergePages = function()
{
let bRes = Module["_UnmergePages"](this.nativeFile);
if (bRes == 1)
{
let str = this.stream.pop();
Module["_free"](str);
}
return bRes == 1;
};
// FONTS
CFile.prototype._isNeedCMap = function()
{

View File

@ -185,6 +185,10 @@ WASM_EXPORT int MergePages(CDrawingFile* pFile, BYTE* data, LONG size, int nMaxI
{
return pFile->MergePages(data, size, nMaxID, sPrefixForm) ? 1 : 0;
}
WASM_EXPORT int UnmergePages(CDrawingFile* pFile)
{
return pFile->UnmergePages() ? 1 : 0;
}
WASM_EXPORT void* GetImageBase64(CDrawingFile* pFile, int rId)
{

View File

@ -993,7 +993,7 @@ int main(int argc, char* argv[])
// SPLIT & MERGE
BYTE* pSplitPages = NULL;
if (false)
if (true)
{
std::vector<int> arrPages = { 0 };
for (int i = 0; i < 3; i++)
@ -1010,11 +1010,14 @@ int main(int argc, char* argv[])
if (MergePages(pGrFile, pSplitPages + 4, nLength - 4, 0, "merge") == 0)
RELEASEARRAYOBJECTS(pSplitPages);
if (!UnmergePages(pGrFile))
std::cout << "error" << std::endl;
}
}
}
BYTE* pFileMerge = NULL;
if (true)
if (false)
{
DWORD nFileMergeLen = 0;
if (NSFile::CFileBinary::ReadAllBytes(NSFile::GetProcessDirectory() + L"/test_merge.pdf", &pFileMerge, nFileMergeLen))