Fix nStartRefID

This commit is contained in:
Svetlana Kulikova
2025-03-18 12:35:52 +03:00
parent 49da36637d
commit df0528c69f
3 changed files with 25 additions and 25 deletions

View File

@ -1192,19 +1192,17 @@ CFile.prototype["getInteractiveFormsInfo"] = function()
let reader = ptr.getReader();
if (!reader) return {};
let arrRes = [];
let res = {};
while (reader.isValid())
{
let res = {};
let k = reader.readInt();
if (k > 0)
if (k > 0 && res["CO"] == undefined)
res["CO"] = [];
for (let i = 0; i < k; ++i)
res["CO"].push(reader.readInt());
k = reader.readInt();
if (k > 0)
if (k > 0 && res["Parents"] == undefined)
res["Parents"] = [];
for (let i = 0; i < k; ++i)
{
@ -1243,8 +1241,9 @@ CFile.prototype["getInteractiveFormsInfo"] = function()
res["Parents"].push(rec);
}
res["Fields"] = [];
k = reader.readInt();
if (k > 0 && res["Fields"] == undefined)
res["Fields"] = [];
for (let q = 0; reader.isValid() && q < k; ++q)
{
let rec = {};
@ -1258,12 +1257,10 @@ CFile.prototype["getInteractiveFormsInfo"] = function()
res["Fields"].push(rec);
}
arrRes.push(res);
}
ptr.free();
return arrRes;
return res;
};
// optional nWidget - rec["AP"]["i"]
@ -1382,10 +1379,9 @@ CFile.prototype["getAnnotationsInfo"] = function(pageIndex)
if (!reader) return [];
let arrRes = [];
let res = [];
while (reader.isValid())
{
let res = [];
let n = reader.readInt();
for (let i = 0; i < n; ++i)
{
@ -1403,11 +1399,10 @@ CFile.prototype["getAnnotationsInfo"] = function(pageIndex)
readAnnotType(reader, rec, reader.readDouble, reader.readDouble2, reader.readString);
res.push(rec);
}
arrRes.push(res);
}
ptr.free();
return arrRes;
return res;
};
// optional nAnnot ...
// optional sView ...

View File

@ -956,19 +956,22 @@ int main(int argc, char* argv[])
BYTE* pSplitPages = NULL;
if (true)
{
std::vector<int> arrPages = { 0, 1 };
pSplitPages = SplitPages(pGrFile, arrPages.data(), arrPages.size());
if (pSplitPages)
std::vector<int> arrPages = { 0 };
for (int i = 0; i < 3; i++)
{
int nLength = READ_INT(pSplitPages);
pSplitPages = SplitPages(pGrFile, arrPages.data(), arrPages.size());
if (pSplitPages)
{
int nLength = READ_INT(pSplitPages);
NSFile::CFileBinary oFile;
if (oFile.CreateFileW(NSFile::GetProcessDirectory() + L"/test2.pdf"))
oFile.WriteFile(pSplitPages + 4, nLength - 4);
oFile.CloseFile();
NSFile::CFileBinary oFile;
if (oFile.CreateFileW(NSFile::GetProcessDirectory() + L"/test" + std::to_wstring(i) + L".pdf"))
oFile.WriteFile(pSplitPages + 4, nLength - 4);
oFile.CloseFile();
if (MergePages(pGrFile, pSplitPages + 4, nLength - 4) == 0)
RELEASEARRAYOBJECTS(pSplitPages);
if (MergePages(pGrFile, pSplitPages + 4, nLength - 4) == 0)
RELEASEARRAYOBJECTS(pSplitPages);
}
}
}

View File

@ -415,7 +415,8 @@ void CPdfReader::SetParams(COfficeDrawingPageParams* pParams)
int CPdfReader::GetPageIndex(int nAbsPageIndex, PDFDoc** _pDoc, PdfReader::CPdfFontList** pFontList, int* nStartRefID)
{
int nTotalPages = 0;
nStartRefID = 0;
if (nStartRefID)
*nStartRefID = 0;
for (CPdfReaderContext* pPDFContext : m_vPDFContext)
{
if (!pPDFContext || !pPDFContext->m_pDocument)
@ -431,7 +432,8 @@ int CPdfReader::GetPageIndex(int nAbsPageIndex, PDFDoc** _pDoc, PdfReader::CPdfF
*pFontList = pPDFContext->m_pFontList;
return nAbsPageIndex - nTotalPages + 1;
}
nStartRefID += pDoc->getXRef()->getNumObjects();
if (nStartRefID)
*nStartRefID += pDoc->getXRef()->getNumObjects();
nTotalPages += nPages;
}
return -1;