mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Add nMaxID
This commit is contained in:
@ -289,10 +289,10 @@ public:
|
||||
return ((CPdfFile*)m_pFile)->SplitPages(arrPageIndex, nLength);
|
||||
return NULL;
|
||||
}
|
||||
bool MergePages(BYTE* data, LONG size)
|
||||
bool MergePages(BYTE* data, LONG size, int nMaxID)
|
||||
{
|
||||
if (m_nType == 0)
|
||||
return ((CPdfFile*)m_pFile)->MergePages(data, size);
|
||||
return ((CPdfFile*)m_pFile)->MergePages(data, size, nMaxID);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -172,9 +172,9 @@ CFile.prototype["SplitPages"] = function(arrPageIndex)
|
||||
Module["_free"](ptr);
|
||||
return buffer;
|
||||
};
|
||||
CFile.prototype["MergePages"] = function(arrayBuffer)
|
||||
CFile.prototype["MergePages"] = function(arrayBuffer, maxID)
|
||||
{
|
||||
return this._MergePages(arrayBuffer);
|
||||
return this._MergePages(arrayBuffer, maxID);
|
||||
};
|
||||
|
||||
// INFO DOCUMENT
|
||||
@ -221,8 +221,8 @@ CFile.prototype.getPagesInfo = function()
|
||||
let reader = ptr.getReader();
|
||||
if (!reader) return [];
|
||||
|
||||
// skip StartID
|
||||
reader.readInt();
|
||||
// change StartID
|
||||
this.StartID = reader.readInt();
|
||||
|
||||
let _pages = [];
|
||||
let nPages = reader.readInt();
|
||||
|
||||
@ -181,9 +181,9 @@ WASM_EXPORT BYTE* SplitPages(CDrawingFile* pFile, int* arrPageIndex, int nLength
|
||||
{
|
||||
return pFile->SplitPages(arrPageIndex, nLength);
|
||||
}
|
||||
WASM_EXPORT int MergePages(CDrawingFile* pFile, BYTE* data, LONG size)
|
||||
WASM_EXPORT int MergePages(CDrawingFile* pFile, BYTE* data, LONG size, int nMaxID)
|
||||
{
|
||||
return pFile->MergePages(data, size) ? 1 : 0;
|
||||
return pFile->MergePages(data, size, nMaxID) ? 1 : 0;
|
||||
}
|
||||
|
||||
WASM_EXPORT void* GetImageBase64(CDrawingFile* pFile, int rId)
|
||||
|
||||
@ -1002,7 +1002,7 @@ int main(int argc, char* argv[])
|
||||
oFile.WriteFile(pSplitPages + 4, nLength - 4);
|
||||
oFile.CloseFile();
|
||||
|
||||
if (MergePages(pGrFile, pSplitPages + 4, nLength - 4) == 0)
|
||||
if (MergePages(pGrFile, pSplitPages + 4, nLength - 4, 0) == 0)
|
||||
RELEASEARRAYOBJECTS(pSplitPages);
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,16 +213,22 @@ namespace NSOnlineOfficeBinToPdf
|
||||
}
|
||||
case AddCommandType::MergePages:
|
||||
{
|
||||
std::wstring wsPath = oReader.ReadString();
|
||||
std::wstring wsPassword = oReader.ReadString();
|
||||
std::wstring wsPath = NSFile::CFileBinary::CreateTempFileWithUniqueName(pPdf->GetTempDirectory(), L"PDF");
|
||||
int nLength = oReader.ReadInt();
|
||||
int* pPageIndex = NULL;
|
||||
if (nLength > 0)
|
||||
pPageIndex = new int[nLength];
|
||||
for (int i = 0; i < nLength; ++i)
|
||||
pPageIndex[i] = oReader.ReadInt();
|
||||
pPdf->MergePages(wsPath, wsPassword, pPageIndex, nLength);
|
||||
RELEASEARRAYOBJECTS(pPageIndex);
|
||||
BYTE* pFile = oReader.GetCurrentBuffer();
|
||||
oReader.Skip(nLength);
|
||||
if (!wsPath.empty())
|
||||
{
|
||||
NSFile::CFileBinary oFile;
|
||||
if (oFile.CreateFileW(wsPath))
|
||||
oFile.WriteFile(pFile, nLength);
|
||||
oFile.CloseFile();
|
||||
}
|
||||
|
||||
int nMaxID = oReader.ReadInt();
|
||||
std::wstring wsPrefix = oReader.ReadString();
|
||||
pPdf->MergePages(wsPath, nMaxID, wsPrefix);
|
||||
RELEASEARRAYOBJECTS(pFile);
|
||||
break;
|
||||
}
|
||||
case AddCommandType::WidgetInfo:
|
||||
|
||||
@ -1997,13 +1997,13 @@ void CreateOutlines(PDFDoc* pdfDoc, PdfWriter::CDocument* pDoc, OutlineItem* pOu
|
||||
}
|
||||
pOutlineItem->close();
|
||||
}
|
||||
bool CPdfEditor::MergePages(const std::wstring& wsPath, const int* arrPageIndex, unsigned int unLength)
|
||||
bool CPdfEditor::MergePages(const std::wstring& wsPath, const std::wstring& wsPrefixForm)
|
||||
{
|
||||
if (m_nMode != Mode::WriteAppend && !IncrementalUpdates())
|
||||
return false;
|
||||
PDFDoc* pDocument = m_pReader->GetLastPDFDocument();
|
||||
int nStartRefID = m_pReader->GetStartRefID(pDocument);
|
||||
bool bRes = SplitPages(arrPageIndex, unLength, pDocument, nStartRefID);
|
||||
bool bRes = SplitPages(NULL, 0, pDocument, nStartRefID);
|
||||
if (!bRes)
|
||||
return false;
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@ public:
|
||||
bool IsBase14(const std::wstring& wsFontName, bool& bBold, bool& bItalic, std::wstring& wsFontPath);
|
||||
|
||||
BYTE* SplitPages(const int* arrPageIndex, unsigned int unLength);
|
||||
bool MergePages(const std::wstring& wsPath, const int* arrPageIndex, unsigned int unLength);
|
||||
bool MergePages(const std::wstring& wsPath, const std::wstring& wsPrefixForm);
|
||||
|
||||
private:
|
||||
void GetPageTree(XRef* xref, Object* pPagesRefObj, PdfWriter::CPageTree* pPageParent = NULL);
|
||||
|
||||
@ -135,12 +135,12 @@ bool CPdfFile::AddPage(int nPageIndex)
|
||||
return false;
|
||||
return m_pInternal->pEditor->AddPage(nPageIndex);
|
||||
}
|
||||
bool CPdfFile::MergePages(const std::wstring& wsPath, const std::wstring& wsPassword, const int* arrPageIndex, unsigned int unLength)
|
||||
bool CPdfFile::MergePages(const std::wstring& wsPath, int nMaxID, const std::wstring& wsPrefixForm)
|
||||
{
|
||||
if (!m_pInternal->pEditor)
|
||||
return false;
|
||||
if (m_pInternal->pReader->MergePages(wsPath, wsPassword))
|
||||
return m_pInternal->pEditor->MergePages(wsPath, arrPageIndex, unLength);
|
||||
if (m_pInternal->pReader->MergePages(wsPath, L"", nMaxID))
|
||||
return m_pInternal->pEditor->MergePages(wsPath, wsPrefixForm);
|
||||
return false;
|
||||
}
|
||||
bool CPdfFile::MovePage(int nPageIndex, int nPos)
|
||||
@ -336,11 +336,11 @@ void CPdfFile::GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, do
|
||||
else
|
||||
m_pInternal->pReader->GetPageInfo(nPageIndex, pdWidth, pdHeight, pdDpiX, pdDpiY);
|
||||
}
|
||||
bool CPdfFile::MergePages(BYTE* data, DWORD length)
|
||||
bool CPdfFile::MergePages(BYTE* data, DWORD length, int nMaxID)
|
||||
{
|
||||
if (!m_pInternal->pReader)
|
||||
return false;
|
||||
return m_pInternal->pReader->MergePages(data, length) && (m_pInternal->pReader->GetError() == 0);
|
||||
return m_pInternal->pReader->MergePages(data, length, L"", nMaxID) && (m_pInternal->pReader->GetError() == 0);
|
||||
}
|
||||
int CPdfFile::GetRotate(int nPageIndex)
|
||||
{
|
||||
|
||||
@ -97,7 +97,7 @@ public:
|
||||
bool DeletePage(int nPageIndex);
|
||||
bool AddPage (int nPageIndex);
|
||||
bool MovePage (int nPageIndex, int nPos);
|
||||
bool MergePages(const std::wstring& wsPath, const std::wstring& wsPassword = L"", const int* arrPageIndex = NULL, unsigned int unLength = 0);
|
||||
bool MergePages(const std::wstring& wsPath, int nMaxID = 0, const std::wstring& wsPrefixForm = L"");
|
||||
HRESULT ChangePassword(const std::wstring& wsPath, const std::wstring& wsPassword = L"");
|
||||
|
||||
// --- READER ---
|
||||
@ -127,7 +127,7 @@ public:
|
||||
virtual BYTE* GetLinks(int nPageIndex);
|
||||
|
||||
bool ValidMetaData();
|
||||
bool MergePages(BYTE* data, DWORD length);
|
||||
bool MergePages(BYTE* data, DWORD length, int nMaxID = 0);
|
||||
int GetRotate(int nPageIndex);
|
||||
int GetMaxRefID();
|
||||
BYTE* GetWidgets();
|
||||
|
||||
@ -414,45 +414,37 @@ void CPdfReader::SetParams(COfficeDrawingPageParams* pParams)
|
||||
|
||||
int CPdfReader::GetStartRefID(PDFDoc* _pDoc)
|
||||
{
|
||||
int nStartRefID = 0;
|
||||
for (CPdfReaderContext* pPDFContext : m_vPDFContext)
|
||||
{
|
||||
if (!pPDFContext || !pPDFContext->m_pDocument)
|
||||
continue;
|
||||
PDFDoc* pDoc = pPDFContext->m_pDocument;
|
||||
if (_pDoc == pDoc)
|
||||
return nStartRefID;
|
||||
nStartRefID += pDoc->getXRef()->getNumObjects();
|
||||
return pPDFContext->m_nStartID;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
int CPdfReader::FindRefNum(int nObjID, PDFDoc** _pDoc, int* _nStartRefID)
|
||||
{
|
||||
int nStartRefID = 0;
|
||||
for (CPdfReaderContext* pPDFContext : m_vPDFContext)
|
||||
{
|
||||
if (!pPDFContext || !pPDFContext->m_pDocument)
|
||||
continue;
|
||||
PDFDoc* pDoc = pPDFContext->m_pDocument;
|
||||
|
||||
int nLastRefID = pDoc->getXRef()->getNumObjects();
|
||||
if (nObjID < nStartRefID + nLastRefID)
|
||||
if (nObjID < pPDFContext->m_nStartID + pDoc->getXRef()->getNumObjects())
|
||||
{
|
||||
if (_pDoc)
|
||||
*_pDoc = pDoc;
|
||||
if (_nStartRefID)
|
||||
*_nStartRefID = nStartRefID;
|
||||
return nObjID - nStartRefID;
|
||||
*_nStartRefID = pPDFContext->m_nStartID;
|
||||
return nObjID - pPDFContext->m_nStartID;
|
||||
}
|
||||
nStartRefID += nLastRefID;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
int CPdfReader::GetPageIndex(int nAbsPageIndex, PDFDoc** _pDoc, PdfReader::CPdfFontList** pFontList, int* nStartRefID)
|
||||
{
|
||||
int nTotalPages = 0;
|
||||
if (nStartRefID)
|
||||
*nStartRefID = 0;
|
||||
for (CPdfReaderContext* pPDFContext : m_vPDFContext)
|
||||
{
|
||||
if (!pPDFContext || !pPDFContext->m_pDocument)
|
||||
@ -466,10 +458,10 @@ int CPdfReader::GetPageIndex(int nAbsPageIndex, PDFDoc** _pDoc, PdfReader::CPdfF
|
||||
*_pDoc = pDoc;
|
||||
if (pFontList)
|
||||
*pFontList = pPDFContext->m_pFontList;
|
||||
if (nStartRefID)
|
||||
*nStartRefID = pPDFContext->m_nStartID;
|
||||
return nAbsPageIndex - nTotalPages + 1;
|
||||
}
|
||||
if (nStartRefID)
|
||||
*nStartRefID += pDoc->getXRef()->getNumObjects();
|
||||
nTotalPages += nPages;
|
||||
}
|
||||
return -1;
|
||||
@ -527,14 +519,9 @@ int CPdfReader::GetRotate(int _nPageIndex)
|
||||
}
|
||||
int CPdfReader::GetMaxRefID()
|
||||
{
|
||||
int nSumRefID = 0;
|
||||
for (CPdfReaderContext* pPDFContext : m_vPDFContext)
|
||||
{
|
||||
if (!pPDFContext || !pPDFContext->m_pDocument || !pPDFContext->m_pDocument->getXRef())
|
||||
continue;
|
||||
nSumRefID += pPDFContext->m_pDocument->getXRef()->getNumObjects();
|
||||
}
|
||||
return nSumRefID;
|
||||
if (!m_vPDFContext.empty())
|
||||
return m_vPDFContext.back()->m_nStartID + m_vPDFContext.back()->m_pDocument->getXRef()->getNumObjects();
|
||||
return 0;
|
||||
}
|
||||
int CPdfReader::GetNumPages()
|
||||
{
|
||||
@ -578,7 +565,7 @@ bool CPdfReader::ValidMetaData()
|
||||
oID.free(); oID2.free();
|
||||
return bRes;
|
||||
}
|
||||
bool CPdfReader::MergePages(BYTE* pData, DWORD nLength, const std::wstring& wsPassword)
|
||||
bool CPdfReader::MergePages(BYTE* pData, DWORD nLength, const std::wstring& wsPassword, int nMaxID)
|
||||
{
|
||||
if (m_eError)
|
||||
return false;
|
||||
@ -591,8 +578,12 @@ bool CPdfReader::MergePages(BYTE* pData, DWORD nLength, const std::wstring& wsPa
|
||||
// будет освобожден в деструкторе PDFDoc
|
||||
BaseStream *str = new MemStream((char*)pData, 0, nLength, &obj);
|
||||
CPdfReaderContext* pContext = new CPdfReaderContext();
|
||||
pContext->m_pDocument = new PDFDoc(str, NULL, NULL);
|
||||
pContext->m_pDocument = new PDFDoc(str, owner_pswd, user_pswd);
|
||||
pContext->m_pFontList = new PdfReader::CPdfFontList();
|
||||
if (nMaxID != 0)
|
||||
pContext->m_nStartID = nMaxID;
|
||||
else if (!m_vPDFContext.empty())
|
||||
pContext->m_nStartID = m_vPDFContext.back()->m_nStartID + m_vPDFContext.back()->m_pDocument->getXRef()->getNumObjects();
|
||||
PDFDoc* pDoc = pContext->m_pDocument;
|
||||
m_vPDFContext.push_back(pContext);
|
||||
|
||||
@ -612,7 +603,7 @@ bool CPdfReader::MergePages(BYTE* pData, DWORD nLength, const std::wstring& wsPa
|
||||
|
||||
return true;
|
||||
}
|
||||
bool CPdfReader::MergePages(const std::wstring& wsFile, const std::wstring& wsPassword)
|
||||
bool CPdfReader::MergePages(const std::wstring& wsFile, const std::wstring& wsPassword, int nMaxID)
|
||||
{
|
||||
if (m_eError)
|
||||
return false;
|
||||
@ -624,6 +615,10 @@ bool CPdfReader::MergePages(const std::wstring& wsFile, const std::wstring& wsPa
|
||||
CPdfReaderContext* pContext = new CPdfReaderContext();
|
||||
pContext->m_pDocument = new PDFDoc((char*)sPathUtf8.c_str(), owner_pswd, user_pswd);
|
||||
pContext->m_pFontList = new PdfReader::CPdfFontList();
|
||||
if (nMaxID != 0)
|
||||
pContext->m_nStartID = nMaxID;
|
||||
if (!m_vPDFContext.empty())
|
||||
pContext->m_nStartID = m_vPDFContext.back()->m_nStartID + m_vPDFContext.back()->m_pDocument->getXRef()->getNumObjects();
|
||||
PDFDoc* pDoc = pContext->m_pDocument;
|
||||
m_vPDFContext.push_back(pContext);
|
||||
|
||||
@ -1137,7 +1132,6 @@ BYTE* CPdfReader::GetWidgets()
|
||||
oRes.SkipLen();
|
||||
|
||||
int nStartPage = 0;
|
||||
int nStartRefID = 0;
|
||||
for (CPdfReaderContext* pPDFContext : m_vPDFContext)
|
||||
{
|
||||
PDFDoc* pDoc = pPDFContext->m_pDocument;
|
||||
@ -1146,16 +1140,14 @@ BYTE* CPdfReader::GetWidgets()
|
||||
if (!pDoc->getCatalog()->getForm() || !pDoc->getXRef())
|
||||
{
|
||||
nStartPage += pDoc->getNumPages();
|
||||
nStartRefID += pDoc->getXRef()->getNumObjects();
|
||||
continue;
|
||||
}
|
||||
|
||||
PdfReader::CAnnots* pAnnots = new PdfReader::CAnnots(pDoc, m_pFontManager, pPDFContext->m_pFontList, nStartPage, nStartRefID);
|
||||
PdfReader::CAnnots* pAnnots = new PdfReader::CAnnots(pDoc, m_pFontManager, pPDFContext->m_pFontList, nStartPage, pPDFContext->m_nStartID);
|
||||
if (pAnnots)
|
||||
pAnnots->ToWASM(oRes);
|
||||
RELEASEOBJECT(pAnnots);
|
||||
nStartPage += pDoc->getNumPages();
|
||||
nStartRefID += pDoc->getXRef()->getNumObjects();
|
||||
}
|
||||
|
||||
oRes.WriteLen();
|
||||
@ -1733,7 +1725,6 @@ BYTE* CPdfReader::GetAnnots(int _nPageIndex)
|
||||
else
|
||||
{
|
||||
int nStartPage = 0;
|
||||
int nStartRefID = 0;
|
||||
for (CPdfReaderContext* pPDFContext : m_vPDFContext)
|
||||
{
|
||||
PDFDoc* pDoc = pPDFContext->m_pDocument;
|
||||
@ -1744,11 +1735,10 @@ BYTE* CPdfReader::GetAnnots(int _nPageIndex)
|
||||
oRes.AddInt(nAnnots);
|
||||
|
||||
for (int nPage = 1, nPages = pDoc->getNumPages(); nPage <= nPages; ++nPage)
|
||||
nAnnots += GetPageAnnots(pDoc, m_pFontManager, pPDFContext->m_pFontList, oRes, nPage, nStartPage, nStartRefID);
|
||||
nAnnots += GetPageAnnots(pDoc, m_pFontManager, pPDFContext->m_pFontList, oRes, nPage, nStartPage, pPDFContext->m_nStartID);
|
||||
|
||||
oRes.AddInt(nAnnots, nPosAnnots);
|
||||
nStartPage += pDoc->getNumPages();
|
||||
nStartRefID += pDoc->getXRef()->getNumObjects();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -45,9 +45,10 @@ struct CPdfReaderContext
|
||||
{
|
||||
PDFDoc* m_pDocument;
|
||||
PdfReader::CPdfFontList* m_pFontList;
|
||||
unsigned int m_nStartID;
|
||||
|
||||
CPdfReaderContext() : m_pDocument(NULL), m_pFontList(NULL) {}
|
||||
CPdfReaderContext(PDFDoc* pDocument, PdfReader::CPdfFontList* pFontList) : m_pDocument(pDocument), m_pFontList(pFontList) {}
|
||||
CPdfReaderContext() : m_pDocument(NULL), m_pFontList(NULL), m_nStartID(0) {}
|
||||
CPdfReaderContext(PDFDoc* pDocument, PdfReader::CPdfFontList* pFontList, unsigned int nStartID) : m_pDocument(pDocument), m_pFontList(pFontList), m_nStartID(nStartID) {}
|
||||
~CPdfReaderContext();
|
||||
};
|
||||
|
||||
@ -76,8 +77,8 @@ public:
|
||||
int GetMaxRefID();
|
||||
int GetNumPages();
|
||||
bool ValidMetaData();
|
||||
bool MergePages(BYTE* pData, DWORD nLength, const std::wstring& wsPassword = L"");
|
||||
bool MergePages(const std::wstring& wsFile, const std::wstring& wsPassword = L"");
|
||||
bool MergePages(BYTE* pData, DWORD nLength, const std::wstring& wsPassword = L"", int nMaxID = 0);
|
||||
bool MergePages(const std::wstring& wsFile, const std::wstring& wsPassword = L"", int nMaxID = 0);
|
||||
void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY);
|
||||
void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
|
||||
std::wstring GetInfo();
|
||||
|
||||
Reference in New Issue
Block a user